Example #1
0
 internal override void Walk(EmitContext ec)
 {
     if (ec.Emitting)
     {
         ec.EmitGetGlobal(ec.id2name(vid));
     }
 }
Example #2
0
 internal override void Walk(EmitContext ec)
 {
     val.Walk(ec);
     if (ec.Emitting)
     {
         ec.EmitDup();
         ec.EmitSetGlobal(ec.id2name(vid));
     }
 }
Example #3
0
        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);
            }
        }
Example #4
0
        private Variable GetAndCreateVariable(uint vid, bool create)
        {
            Variable v = vars[vid] as Variable;

            if (v == null)
            {
                if (IsBlock)
                {
                    Variable dv = GetMethodScope().vars[vid] as Variable;
                    if (dv != null)
                    {
                        if (create)
                        {
                            dv.IsDynamic    = true;
                            dv.closure_slot = GetMethodScope().CreateClosureSlot();
                        }
                        else if (!dv.IsDynamic)
                        {
                            throw new Exception("bug: missing dynamic data for dynamic var: " + context.id2name(vid));
                        }
                        return(dv);
                    }
                }
                if (create)
                {
                    v         = new Variable();
                    vars[vid] = v;
                    return(v);
                }
                else
                {
                    throw new Exception("Local not found: " + context.id2name(vid));
                }
            }
            return(v);
        }
Example #5
0
        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);
            }
        }
Example #6
0
 internal override void Walk(EmitContext ec)
 {
     if(ec.Emitting)
         ec.EmitGetGlobal(ec.id2name(vid));
 }
Example #7
0
 internal override void Walk(EmitContext ec)
 {
     val.Walk(ec);
     if(ec.Emitting) {
         ec.EmitDup();
         ec.EmitSetGlobal(ec.id2name(vid));
     }
 }