Beispiel #1
0
        // utility function to create a code segment for nested calls
        public ByteCode Compile()
        {
            var e = new Emitter();

            Emit(e);
            return(e.GetCode());
        }
Beispiel #2
0
        // create code segment wrapped for fold
        public ByteCode Compile(Symbol op, TypedValue seed, CallInfo callinfo)
        {
            var e = new Emitter();

            e.Out(Opcodes.LDAGG, seed);
            Emit(e);
            e.OutCall(op, 0, callinfo);
            return(e.GetCode());
        }
Beispiel #3
0
        // create code segment wrapped for fold and deffunc, called via Invoke
        public ByteCode Compile(Symbol invop, string opname, TypedValue seed)
        {
            var e = new Emitter();

            e.OutName(Opcodes.LDCATR, opname);
            e.Out(Opcodes.LDACCBLK);
            e.OutLoad(NumberValue.Create(-1));
            e.Out(Opcodes.LDAGG, seed);
            Emit(e);
            e.OutCall(invop, 2); // no choice but two args
            return(e.GetCode());
        }
Beispiel #4
0
        ///============================================================================================
        ///
        /// Emit and execute
        ///

        ByteCode Emit(AstStatement statement)
        {
            Logger.Assert(statement.DataType != null);
            Logger.WriteLine(4, "|{0}", statement); // nopad
            var emitter = new Emitter();

            statement.Emit(emitter);
            if (statement.DataType.IsVariable)
            {
                //if (statement.DataType != DataTypes.Void) {
                emitter.OutCall(Symbols.FindIdent("pp"));
                emitter.OutCall(Symbols.FindIdent("write"));
            }
            // statement will have left value on stack (even if void)
            if (!(statement is AstTypedef))
            {
                emitter.Out(Opcodes.EOS);
            }
            var code = emitter.GetCode();

            return(code);
        }