internal override void Assign(CodeGenContext context, Node rhs)
        {
            // object value = rhs;
            bool created;
            ISimple value = context.PreCompute(rhs, "rhs", out created);

            // thisblock.localsN.SetDynamic("vid", value);
            context.ldarg(0);
            context.ldfld(block.frameFields[depth - 1]);
            context.ldstr(Name);
            value.GenSimple(context);
            context.call(Runtime.Frame.SetDynamic);

            value.GenSimple(context);

            context.ReleaseLocal(value, created);
        }
        internal override void GenCode0(CodeGenContext context)
        {
            bool created;
            ISimple left = context.PreCompute(lhs, "lhs", out created);

            new COND((Node)left, rhs, (Node)left, location).GenCode(context);

            context.ReleaseLocal(left, created);
        }
 private ISimple PushScope(CodeGenContext context, out bool created)
 {
     if (name != null && name.scope != null)
         return context.PreCompute(name.scope, "scope", out created);
     else
     {
         created = false;
         if (context.CurrentRubyClass != null)
             return new StaticField(context.CurrentRubyClass, name.location);
         else
             return new StaticField(Runtime.Init.rb_cObject, name.location);
     }
 }
        internal override void Assign(CodeGenContext context, Node rhs)
        {
            // Fixme: make sure CurrentRubyClass is not a singleton (see cvar_cbase)

            // object value = rhs;
            bool created;
            ISimple value = context.PreCompute(rhs, "rhs", out created);

            // Ruby.Variables.cvar_set(caller, ruby_cref, "vid", value);
            context.ldloc(0);
            context.ruby_cbase(parent_scope);
            context.ldstr(vid.ToString());
            value.GenSimple(context);
            context.call(Runtime.Variables.cvar_set);

            context.ReleaseLocal(value, created);
        }
        internal override void Assign(CodeGenContext context, Node rhs)
        {
            bool value_created;
            ISimple value;

            if (qualified) // Fixme: scope == null???
            {
                // object where = scope;
                bool where_created;
                ISimple where = context.PreCompute(scope, "scope", out where_created);
            
                // object value = rhs;
                value = context.PreCompute(rhs, "rhs", out value_created);

                context.ldloc(0);
                where.GenSimple(context);

                context.ReleaseLocal(where, where_created);
            }
            else
            {
                // object value = rhs;
                value = context.PreCompute(rhs, "rhs", out value_created);

                context.ldloc(0);
                context.ruby_cbase(parent_scope);
            }

            context.ldstr(vid.ToString());
            value.GenSimple(context);
            context.call(Runtime.Eval.set_const);

            context.ReleaseLocal(value, value_created);
        }
        internal override void Assign(CodeGenContext context, Node rhs)
        {
            // object value = rhs;
            bool created;
            ISimple value = context.PreCompute(rhs, "rhs", out created);

            // Eval.ivar_set(caller, recv, "vid", rhs);
            context.ldloc(0);
            context.ldarg("recv");
            context.ldstr(vid);
            value.GenSimple(context);
            context.call(Runtime.Eval.ivar_set);

            context.ReleaseLocal(value, created);
        }
        internal override void Assign(CodeGenContext context, Node rhs)
        {
            bool created;
            ISimple value = context.PreCompute(rhs, "rhs", out created);

            //Ruby.Variables.gvar_set(vid, rhs, caller);
            context.ldstr(vid.ToString());
            value.GenSimple(context);
            context.ldloc(0);
            context.call(Runtime.Variables.gvar_set);

            context.ReleaseLocal(value, created);
        }
        internal override void Assign(CodeGenContext context, Node rhs)
        {
            // object value = rhs;
            bool created;
            ISimple value = context.PreCompute(rhs, "rhs", out created);

            // thisblock.localsN.vid = value;
            context.ldarg(0);
            context.ldfld(block.frameFields[depth - 1]);
            value.GenSimple(context);
            context.stfld(field);

            value.GenSimple(context);

            context.ReleaseLocal(value, created);
        }
Beispiel #9
0
        private void CopyOptionalFormals(CodeGenContext context, Scope scope)
        {
            for (ASSIGNMENT opt = (ASSIGNMENT)optional; opt != null; opt = (ASSIGNMENT)opt.nd_next)
            {
                PERWAPI.CILLabel runout_label = context.NewLabel();
                PERWAPI.CILLabel end_label = context.NewLabel();

                string name = ID.ToDotNetName(((VAR)(opt.lhs)).vid);
                Node defaultValue = opt.rhs;

  

                // if (args.RunOut()) goto RunOut
                context.ldarg("args");
                context.callvirt(Runtime.ArgList.RunOut);
                context.brtrue(runout_label);

                // locals.name = args.GetNext();
                context.ldloc(0);
                context.ldarg("args");
                context.callvirt(Runtime.ArgList.GetNext);
                context.br(end_label);

                // RunOut:
                context.CodeLabel(runout_label);

                // object def = defaultValue;
                bool created;
                ISimple def = context.PreCompute(defaultValue, "default", out created);

                // locals.name = defaultValue
                context.ldloc(0);
                def.GenSimple(context);

                context.ReleaseLocal(def, created);

                context.CodeLabel(end_label);

                // locals.name = ...
                context.stfld(scope.GetFrameField(name));
            }
        }
Beispiel #10
0
        internal override void GenCode0(CodeGenContext context)
        {
            bool start_created, finish_created;
            ISimple start = context.PreCompute(beg, "beg", out start_created);
            ISimple finish = context.PreCompute(end, "end", out finish_created);

            start.GenSimple(context);
            finish.GenSimple(context);
            context.PushTrue();
            context.newobj(Runtime.Range.ctor);

            context.ReleaseLocal(start, start_created);
            context.ReleaseLocal(finish, finish_created);
        }
 protected override ISimple PushSuper(CodeGenContext context, out bool created)
 {
     return context.PreCompute(singleton, "super", out created); // pass singleton as super
 }
 protected override ISimple PushSuper(CodeGenContext context, out bool created)
 {
     if (super_class != null)
         return context.PreCompute(super_class, "super", out created);
     else
     {
         created = false;
         return new NIL(location);
     }
 }
Beispiel #13
0
        internal override ISimple GenArgList(CodeGenContext context, out bool created)
        {
            bool single = true;

            // ArgList arglist = new ArgList();
            context.newobj(Runtime.ArgList.ctor);
            int arglist = context.StoreInTemp("arglist", Runtime.ArgListRef, location);

            int added = 0;
            for (Node arg = parameters; arg != null; arg = arg.nd_next)
            {
                //object argument = arg;
                bool argument_created;
                ISimple argument = context.PreCompute0(arg, "arg", out argument_created);

                // arglist.Add(argument);
                context.ldloc(arglist);
                argument.GenSimple(context);
                context.callvirt(Runtime.ArgList.Add);
                added++;

                context.ReleaseLocal(argument, argument_created);
            }

            if (added != 1)
                single = false;

            if (hashlist != null)
            {
                // object hash = hashlist;
                bool hash_created;
                ISimple hash = context.PreCompute(new HASH(hashlist, hashlist.location), "hashlist", out hash_created);

                // arglist.Add(hash);
                context.ldloc(arglist);
                hash.GenSimple(context);
                context.callvirt(Runtime.ArgList.Add);
                single = false;

                context.ReleaseLocal(hash, hash_created);
            }

            if (array != null)
            {
                // object list = array;
                bool list_created;
                ISimple list = context.PreCompute(array, "array", out list_created);

                // arglist.AddArray(list, caller);
                context.ldloc(arglist);
                list.GenSimple(context);
                context.ldloc(0);
                context.callvirt(Runtime.ArgList.AddArray);
                single = false;

                context.ReleaseLocal(list, list_created);
            }

            if (block != null)
            {
                // object b = block;
                bool b_created;
                ISimple b = context.PreCompute(block, "block", Runtime.ProcRef, out b_created);

                // arglist.block = b;
                context.ldloc(arglist);
                b.GenSimple(context);
                context.stfld(Runtime.ArgList.block);

                context.ReleaseLocal(b, b_created);
            }

            if (single)
            {
                context.ldloc(arglist);
                context.PushTrue();
                context.stfld(Runtime.ArgList.single_arg);
            }

            created = true;
            return new LOCAL(arglist, location);
        }
Beispiel #14
0
        internal override List<ISimple> GenFixedArgs(CodeGenContext context, out List<bool> created)
        {
            List<ISimple> fixed_args = new List<ISimple>();
            created = new List<bool>();

            if (block != null)
            {
                bool b_created;
                fixed_args.Add(context.PreCompute(block, "block", Runtime.ProcRef, out b_created));
                created.Add(b_created);
            }
            else
            {
                fixed_args.Add(new AST.NIL(location));
                created.Add(false);
            }

            for (Node arg = parameters; arg != null; arg = arg.nd_next)
            {
                //object argument = arg;
                bool argument_created;
                fixed_args.Add(context.PreCompute0(arg, "arg", out argument_created));
                created.Add(argument_created);
            }

            return fixed_args;
        }
Beispiel #15
0
        internal void AssignOp(CodeGenContext context, string op, Node rhs)
        {
            // object a = array;
            bool a_created;
            ISimple a = context.PreCompute(array, "array", out a_created);

            // ArgList index = args;
            bool index_created;
            index = args.GenArgList(context, out index_created);

            // access <=> a[index];
            ARRAY_ACCESS access = new ARRAY_ACCESS((Node)a, new ProxyList(Index, location), location);

            // access1 = (access2 op rhs);
            access.Assign(context, METHOD_CALL.Create(access, op, rhs, location));

            context.ReleaseLocal(a, a_created);
            context.ReleaseLocal(index, index_created);
        }
Beispiel #16
0
        internal override void Assign(CodeGenContext context, Node rhs)
        {
            // object value = rhs;
            bool created;
            ISimple value = context.PreCompute(rhs, "rhs", out created);

            // locals.field = value
            context.ldloc(0);
            value.GenSimple(context);
            context.stfld(field);

            GenCode0(context);

            context.ReleaseLocal(value, created);
        }
Beispiel #17
0
        // append rhs to args array
        private ISimple ArgsPlusRHS(CodeGenContext context, out bool created)
        {
            // ArgList temp = args;
            ISimple temp = args.GenArgList(context, out created);

            // object value = rhs;
            bool value_created;
            ISimple value = context.PreCompute(rhs, "rhs", out value_created);

            // temp.Add(value);
            temp.GenSimple(context);
            value.GenSimple(context);
            context.callvirt(Runtime.ArgList.Add);

            context.ReleaseLocal(value, value_created);

            return temp;
        }
Beispiel #18
0
        internal override void GenCode0(CodeGenContext context)
        {
            if (Scanner.is_identchar(method_id[0]))
                context.newLine(location);
            
            SetLine(context);
            
            bool self_created, arguments_created = false;

            if (isVarAccess)
            {
                context.ldloc(0);
                context.call(Runtime.Frame.SetCallStatusVCall);
            }
            else
            {
                context.ldloc(0);
                context.call(Runtime.Frame.SetCallStatusNone);
            }

            // object self = receiver;
            self = context.PreCompute(receiver, "receiver", out self_created);

            if (args.ShortAndSimple())
                fixed_arguments = args.GenFixedArgs(context, out fixed_created);
            else
                arguments = args.GenArgList(context, out arguments_created);


            GenCall(context);

            context.ReleaseLocal(self, self_created);

            if (args.ShortAndSimple())
                for (int i = 0; i < fixed_created.Count; i++)
                    context.ReleaseLocal(fixed_arguments[i], fixed_created[i]);
            else
                context.ReleaseLocal(arguments, arguments_created);
        }