internal RCMethod Compile(RNode main) { EmitScope es = CreateMethodScope("main"); PushScope(es); state = EmitState.RESOLVING; main.Walk(this); state = EmitState.EMITTING; EmitScopeInitializer(); main.Walk(this); Type main_type = CloseScope(es); if (save) { assembly_builder.Save(filename); } // Call constructor object method = main_type.InvokeMember(null, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.CreateInstance, null, null, new object[] {} ); return((RCMethod)method); }
internal Type block; // Generated type of the block attached to the call // ( argsarr -- argsarr ) internal static void EmitStoreArg(EmitContext ec, int i, RNode val) { ec.EmitDup(); // arr ec.EmitInt(i); // idx val.Walk(ec); // val ec.EmitArrayStore(); }
internal override void Walk(EmitContext ec) { string name = ec.id2name(mid); if (ec.Resolving) { scope = ec.CreateMethodScope(name); } ec.PushScope(scope); if (ec.Emitting) { ec.EmitScopeInitializer(); } RNScope sc = (RNScope)defn; RNode n = sc.next; RNArgs args = (RNArgs)n.head; RNode body = n.next; int argc = args.cnt; for (int i = 0; i < argc; i++) { // First two locals in table are $~ and $_ uint vid = sc.tbl[i + 2]; WalkArg(ec, i, vid); } // Methods can have no body if (body != null) { body.Walk(ec); } if (ec.Emitting) { Type t = ec.CloseScope(scope); ec.EmitDefine(name, t); ec.EmitNil(); // Return value } else { ec.PopScope(scope); } }
internal override void Walk(EmitContext ec) { // Linear scan of linked list for O(1) stack space for (RNode n = this; n != null;) { if (n is RNBlock) { RNode current = n.head; current.Walk(ec); n = n.next; if (ec.Emitting && n != null) { // Discard previous result, block returns last value generated ec.EmitDiscard(); } } else { throw new NotSupportedException("bug: not supported block tail: " + n.GetType().Name); } } }
internal Type block; // Generated type of the block attached to the call // ( argsarr -- argsarr ) internal static void EmitStoreArg(EmitContext ec, int i, RNode val) { ec.EmitDup(); // arr ec.EmitInt(i); // idx val.Walk(ec); // val ec.EmitArrayStore(); }
internal RCMethod Compile(RNode main) { EmitScope es = CreateMethodScope("main"); PushScope(es); state = EmitState.RESOLVING; main.Walk(this); state = EmitState.EMITTING; EmitScopeInitializer(); main.Walk(this); Type main_type = CloseScope(es); if(save) { assembly_builder.Save(filename); } // Call constructor object method = main_type.InvokeMember(null, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.CreateInstance, null, null, new object[] {} ); return (RCMethod)method; }