AjTalk.Language.Block.CompileConstant C# (CSharp) Method

CompileConstant() public method

public CompileConstant ( object obj ) : byte
obj object
return byte
        public byte CompileConstant(object obj)
        {
            int p = this.constants.IndexOf(obj);

            if (p >= 0)
            {
                return (byte)p;
            }

            this.constants.Add(obj);

            return (byte)(this.constants.Count - 1);
        }

Usage Example

Example #1
0
        public void DecompileNamedPrimitive()
        {
            Block block = new Block();
            block.CompileByteCode(ByteCode.NamedPrimitive, block.CompileConstant("do"), block.CompileConstant("mod"));
            BlockDecompiler decompiler = new BlockDecompiler(block);

            var result = decompiler.Decompile();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("NamedPrimitive \"do\" \"mod\"", result[0]);
        }