Beispiel #1
0
        internal override void GenCode0(CodeGenContext context)
        {
            // String.Concat(String.Concat(arg1, arg2), args, ...);

            head.GenCode0(context);

            if (head.nd_next != null)
            {
                int first = context.StoreInTemp("head", Runtime.StringRef, head.location);

                for (Node n = head.nd_next; n != null; n = n.nd_next)
                {
                    n.GenCode0(context);
                    int second = context.StoreInTemp("tail", Runtime.StringRef, n.location);

                    context.ldloc(first);
                    context.ldloc(second);
                    context.callvirt(Runtime.String.Concat);
                    context.stloc(first);

                    context.ReleaseLocal(second, true);
                }

                context.ldloc(first);

                context.ReleaseLocal(first, true);
            }
        }
Beispiel #2
0
        internal override void GenCode0(CodeGenContext context)
        {
            bool created;
            ISimple list = GenArgList(context, out created);
            list.GenSimple(context);
            context.callvirt(Runtime.ArgList.ToRubyObject);

            context.ReleaseLocal(list, created);
        }
Beispiel #3
0
        internal override void GenCode0(CodeGenContext context)
        {
            if (args != null)
            {
                bool created;
                ISimple list = args.GenArgList(context, out created);
                list.GenSimple(context);
                context.callvirt(Runtime.ArgList.ToRubyArray);

                context.ReleaseLocal(list, created);
            }
            else
                context.newobj(Runtime.Array.ctor);
        }
 internal override void GenCode0(CodeGenContext context)
 {
     // ruby_class.undef_method(mid);
     context.newLine(location);
     context.ruby_class(parent_scope);
     context.ldstr(mid.ToString());
     context.callvirt(Runtime.Class.undef_method);
     context.ldnull();
 }
        internal override void Assign(CodeGenContext context, Node rhs)
        {
            // Gen right hand sides
            ListGen mrhs;
            if (rhs is ListGen && !(rhs is MultipleRHS))
                mrhs = (ListGen)rhs;
            else
                mrhs = new ARGS(null, null, rhs, null, location, true);

            bool created;
            ISimple list = mrhs.GenArgList(context, out created);
            list.GenSimple(context);
            context.callvirt(Runtime.ArgList.CheckSingleRHS);
            int array = context.StoreInTemp("mrhs", Runtime.ArgListRef, location);

            context.ReleaseLocal(list, created);

            // Gen assignments to left hand sides
            for (LVALUE l = elements; l != null; l = (LVALUE)l.nd_next)
            {
                l.Assign(context, new MultipleRHS(array, l.location));
                context.pop();
            }

            context.ldloc(array);
            context.callvirt(Runtime.ArgList.ToRubyArray);

            context.ReleaseLocal(array, true);
        }
        private void GetRestRHS(CodeGenContext context)
        {
            // rhs.GetRest();
            bool created;
            ISimple list = ((ListGen)rhs).GenArgList(context, out created);
            list.GenSimple(context);
            context.callvirt(Runtime.ArgList.GetRest);

            context.ReleaseLocal(list, created);
        }
 internal override void GenCode0(CodeGenContext context)
 {
     // arglist.GetNext(array);
     context.ldloc(arglist);
     context.callvirt(Runtime.ArgList.GetNext);
 }
Beispiel #8
0
 internal override void GenCode0(CodeGenContext context)
 {
     // new Regexp(pattern, options);
     if (pattern is VALUE)
         context.ldstr(((VALUE)pattern).value.ToString());
     else
     {
         pattern.GenCode(context);
         context.callvirt(Runtime.String.ToString);
     }
     context.ldc_i4(options);
     context.newobj(Runtime.Regexp.ctor);
 }
        // 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 #10
0
        private void CopyRestFormals(CodeGenContext context, Scope scope)
        {
            if (rest != null)
            {
                string name = ID.ToDotNetName(rest.vid);

                // locals.name = args.GetRest();
                context.ldloc(0);
                context.ldarg("args");
                context.callvirt(Runtime.ArgList.GetRest);
                context.stfld(scope.GetFrameField(name));
            }
        }
Beispiel #11
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 #12
0
        private void CopyNormalFormals(CodeGenContext context, Scope scope)
        {
            PERWAPI.CILLabel OKLabel = context.NewLabel();

            if (min_args > 0)
            {
                // if (args.Length < min_args)
                context.ldarg("args");
                context.callvirt(Runtime.ArgList.get_Length);
                int length = context.StoreInTemp("length", PrimitiveType.Int32, location);
                context.ldloc(length);
                context.ldc_i4(min_args);
                context.bge(OKLabel);

                //context.Inst(Op.clt);
                //context.brfalse(OKLabel);

                // context.Branch(BranchOp.bge, OKLabel);

                // throw new ArgumentError(string.Format("wrong number of arguments ({0} for {1})", args.Length, arity).raise(caller);
                // FIXME: next line needs a String
                context.ldstr("wrong number of arguments ({0} for {1})");
                context.ldloc(length);
                context.box(PrimitiveType.Int32);
                context.ldc_i4(min_args);
                context.box(PrimitiveType.Int32);
                context.call(Runtime.SystemString.Format);
                context.newobj(Runtime.ArgumentError.ctor);
                context.ldloc(0);
                context.callvirt(Runtime.Exception.raise);
                context.throwOp();

                context.ReleaseLocal(length, true);

                // OKLabel:
                context.CodeLabel(OKLabel);
            }

            // Copy parameters to locals
            for (Node f = normal; f != null; f = f.nd_next)
            {
                string name = ID.ToDotNetName(((VAR)f).vid);

                // local.f = args.GetNext();
                context.ldloc(0);
                context.ldarg("args");
                context.callvirt(Runtime.ArgList.GetNext);
                context.stfld(scope.GetFrameField(name));
            }
        }
Beispiel #13
0
 internal override void GenCall0(CodeGenContext context)
 {
     // block.yield(caller, arguments)            
     LoadBlock(context);
     context.ldloc(0); // caller
     arguments.GenSimple(context);
     context.callvirt(Runtime.Proc.yield);
 }
Beispiel #14
0
        internal override void GenCode0(CodeGenContext context)
        {
            // hash = new Hash();
            context.newobj(Runtime.Hash.ctor);
            int hash = context.StoreInTemp("hash", Runtime.HashRef, location);

            Node entry = elements;
            while (entry != null)
            {
                bool key_created, value_created;

                ISimple key = context.PreCompute0(entry, "key", out key_created);
                entry = entry.nd_next;
                ISimple value = context.PreCompute0(entry, "value", out value_created);
                entry = entry.nd_next;

                // hash.Add(key, value);
                context.ldloc(hash);
                key.GenSimple(context);
                value.GenSimple(context);
                context.callvirt(Runtime.Hash.Add);

                context.ReleaseLocal(key, key_created);
                context.ReleaseLocal(value, value_created);
            }

            context.ldloc(hash);

            context.ReleaseLocal(hash, true);
        }
Beispiel #15
0
        internal override void GenCode0(CodeGenContext context)
        {
            context.ldloc(0);
            context.call(Runtime.Frame.get_Tilde);
            PERWAPI.CILLabel label1 = context.NewLabel();
            context.brfalse(label1);
            context.ldloc(0);
            context.call(Runtime.Frame.get_Tilde);
            context.ldloc(0);

            switch (ch)
            {
                case '&':
                    context.callvirt(Runtime.Match.last_match);
                    break;
                case '`':
                    context.callvirt(Runtime.Match.match_pre);
                    break;               
                case '\'':
                    context.callvirt(Runtime.Match.match_post);
                    break;                
                case '+':
                    context.callvirt(Runtime.Match.match_last);
                    break;
                default:
                    throw new NotImplementedException("BACK_REF $" + ch);
            }
            PERWAPI.CILLabel label2 = context.NewLabel();
            context.br(label2);
            context.CodeLabel(label1);
            context.ldnull();
            context.CodeLabel(label2);
        }
Beispiel #16
0
 internal override void Defined(CodeGenContext context)
 {
     CILLabel endLabel = context.NewLabel();
 
     context.ldloc(0);
     context.call(Runtime.Frame.get_Tilde);
     context.dup();
     context.brfalse(endLabel);
     context.ldc_i4(nth);
     context.callvirt(Runtime.Match.defined_nth);
     context.CodeLabel(endLabel);
 }
Beispiel #17
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 #18
0
 internal void DefineMethod(CodeGenContext context)
 {
     // ... .define_method("MyMethod", MyMethod.singleton, arity, caller);
     context.ldstr(method_id.ToString());
     context.ldsfld(GenerateClassForMethod(context));
     context.ldc_i4(formals.arity);
     context.ldloc(0);
     context.callvirt(Runtime.Class.define_method);
     context.ldnull();
 }
Beispiel #19
0
        internal void GenCode(CodeGenContext context, PERWAPI.CILLabel endLabel)
        {
            PERWAPI.CILLabel elseLabel = context.NewLabel();

            context.newLine(comparison.location);
            // if (comparision.ToRubyArray().includes(true, caller))
            bool created;
            ISimple list = comparison.GenArgList(context, out created);
            list.GenSimple(context);
            context.ReleaseLocal(list, created);
            context.callvirt(Runtime.ArgList.ToRubyArray);
            new TRUE(comparison.location).GenCode(context);
            context.ldloc(0);
            context.callvirt(Runtime.Array.includes);
            context.brfalse(elseLabel);

            if (body != null)
            {
                context.newStartPoint(body.location);
                body.GenCode(context);
            }
            else
                context.ldnull();

            context.br(endLabel);
            context.CodeLabel(elseLabel);
        }