Example #1
0
        public void CgDataValue(ParseTreeNode node, ref CgContext ctx)
        {
            // DataValue is transient
            // DataValue = [tilde |] string | number | character | identifier

            // Note that ~ is handled by the caller since, by this point, it's
            // too late to do anything.
            if (node.Term.Name == "string")
            {
                var s = EvalString(node, ref ctx);
                foreach (var ch in s)
                    ctx.Write(new Code(ch));
            }
            else
            {
                ctx.Write(EvalLiteralWord(node, ref ctx));
            }
        }
Example #2
0
        public void CgExtInstruction(ParseTreeNode node, ref CgContext ctx)
        {
            var op = node.ChildNodes[0];
            var arg = node.ChildNodes[1];

            Instruction instr = new Instruction();
            Code? tail;

            instr.BasicOpcode = BasicOpcode.Ext;
            instr.ExtOpcode = op.ChildNodes[0].Token.Text.ToExtOpcode();
            instr.ArgA = CgArgument(arg, ref ctx, out tail, shortForm: false);

            ctx.Write(new Code(instr));
            if (tail.HasValue) ctx.Write(tail.Value);
        }
Example #3
0
        public void CgData(ParseTreeNode node, ref CgContext ctx)
        {
            var args = node.ChildNodes[1];

            var i = 0;
            foreach (var arg in args.ChildNodes)
            {
                if (arg.Term.Name == "DataLength")
                    ctx.Write(new Code(CountDataWords(args, i + 1, ref ctx)));

                else
                    CgDataValue(arg, ref ctx);

                ++i;
            }
        }
Example #4
0
        public void CgBasicInstruction(ParseTreeNode node, ref CgContext ctx)
        {
            var op = node.ChildNodes[0].ChildNodes[0];
            var argB = node.ChildNodes[1];
            var argA = node.ChildNodes[2];

            Instruction instr = new Instruction();
            Code? tailA, tailB;

            instr.BasicOpcode = op.Term.Name.ToBasicOpcode();
            instr.ArgA = CgArgument(argA, ref ctx, out tailA, shortForm: false);
            instr.ArgB = CgArgument(argB, ref ctx, out tailB, shortForm: true);

            ctx.Write(new Code(instr));
            if (tailA.HasValue) ctx.Write(tailA.Value);
            if (tailB.HasValue) ctx.Write(tailB.Value);
        }