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);
        }
Beispiel #2
0
        public void GenSimple(CodeGenContext context)
        {
            if (value is string)// T_STRING,
            {
                context.ldstr((string)(value));
                context.newobj(Runtime.String.ctor);
                return;
            }
            if (value is int)   // T_FIXNUM
            {
                context.ldc_i4((int)(value));
                context.box(PrimitiveType.Int32);
                return;
            }
            if (value is double)// T_FLOAT
            {
                context.ldc_r8((double)(value));
                context.newobj(Runtime.Float.ctor);
                return;
            }
            if (value is ID)    // T_SYMBOL
            {
                context.ldstr(((ID)value).ToString());
                context.newobj(Runtime.Symbol.ctor);
                return;
            }
            if (value is BigNum)
            {
                BigNum num = (BigNum) value;
                context.ldc_i4(num.sign);
                context.ldstr(num.ToString());
                context.ldc_i4(num.bas);
                context.newobj(Runtime.Bignum.ctor);
                return;
            }

            throw new System.NotImplementedException("VALUE " + value.GetType().ToString());
        }
 internal override void Defined(CodeGenContext context)
 {
     // Variables.gvar_defined(vid);
     context.ldstr(vid.ToString());
     context.call(Runtime.Variables.gvar_defined);
 }
Beispiel #4
0
        internal override void GenCall0(CodeGenContext context)
        {
            // Ruby.Eval.Call???(self, frame, method_id, arguments);
            self.GenSimple(context);
            context.ldloc(0);
            context.ldstr(method_id.ToString());
            if (args.ShortAndSimple())
            {
                foreach (ISimple arg in fixed_arguments)
                    arg.GenSimple(context);

                if (IsPublic)
                    context.call(Runtime.Eval.Call("Public", fixed_arguments.Count-1));
                else
                    context.call(Runtime.Eval.Call("Private", fixed_arguments.Count-1));
            }
            else
            {
                arguments.GenSimple(context);
                if (IsPublic)
                    context.call(Runtime.Eval.CallPublicA);
                else
                    context.call(Runtime.Eval.CallPrivateA);
            }
        }
   internal override void Defined(CodeGenContext context)
 {
     // Fixme: make sure CurrentRubyClass is not a singleton (see cvar_cbase)
     // Ruby.Variables.cvar_defined(ruby_cref, "vid");
     context.ruby_cbase(parent_scope);
     context.ldstr(vid.ToString());
     context.call(Runtime.Variables.cvar_defined);
 }
 public void GenSimple(CodeGenContext context)
 {
     // Fixme: make sure CurrentRubyClass is not a singleton (see cvar_cbase)
     // Ruby.Variables.cvar_get(caller, ruby_cref, "vid");
     context.ldloc(0);
     context.ruby_cbase(parent_scope);
     context.ldstr(vid.ToString());
     context.call(Runtime.Variables.cvar_get);
 }
        internal override void GenCode0(CodeGenContext context)
        {
            if (qualified)
                if (scope != null)
                    scope.GenCode(context);
                else
                    context.ldsfld(Ruby.Compiler.Runtime.Init.rb_cObject);
            else
                context.ruby_cbase(parent_scope);

            context.ldstr(vid.ToString());
            context.ldloc(0);
            context.call(Runtime.Eval.get_const);
        }
        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 Defined(CodeGenContext context)
 {
     // Eval.ivar_defined(recv, vid)
     context.ldarg("recv");
     context.ldstr(vid);
     context.call(Runtime.Eval.ivar_defined);
 }
 internal override void DefineClass(CodeGenContext context, PERWAPI.FieldDef singleton)
 {
     // Class.define_module(scope, name.vid, caller);
     context.ldarg("scope");
     context.ldstr(name.vid.ToString());
     context.ldloc(0);
     context.call(Runtime.Class.rb_define_module);
     context.stsfld(singleton);
 }
Beispiel #11
0
 internal override void GenCode0(CodeGenContext context)
 {
     if (id is string)
         context.ldstr((string)id);
     else if (id is VALUE && ((VALUE)id).value is string)
         context.ldstr((string)((VALUE)id).value);
     else
     {
         ((Node)id).GenCode(context);
         context.ldfld(Runtime.String.value);
     }
         
     context.newobj(Runtime.Symbol.ctor);
 }
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 MethodDefined(CodeGenContext context)
 {
     // Eval.FindSuperMethod(last_class, thisFrame, currentMethod)
     context.LastClass(parent_scope, false);
     context.ldloc(0);
     context.ldstr(ParentMethodName(context));
     context.call(Runtime.Eval.FindSuperMethod);
 }
Beispiel #14
0
 internal override void GenCall0(CodeGenContext context)
 {
     //Ruby.Eval.CallSuperA(last_class, caller, self, methodId, args);
     context.LastClass(parent_scope, false);
     context.ldloc(0);
     new SELF(location).GenCode(context);
     context.ldstr(ParentMethodName(context));
     arguments.GenSimple(context);
     context.call(Runtime.Eval.CallSuperA);
 }
Beispiel #15
0
 internal override void MethodDefined(CodeGenContext context)
 {
     // Eval.Find???Method(receiver, thisFrame, method_id)
     receiver.GenCode(context);
     context.ldloc(0);
     context.ldstr(method_id.ToString());
     if (IsPublic)
         context.call(Runtime.Eval.FindPublicMethod);
     else
         context.call(Runtime.Eval.FindPrivateMethod);
 }
Beispiel #16
0
 public void GenSimple(CodeGenContext context)
 {
     // Variables.gvar_get(vid, caller);
     context.ldstr(vid.ToString());
     context.ldloc(0);
     context.call(Runtime.Variables.gvar_get);
 }
Beispiel #17
0
        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);
        }
Beispiel #18
0
 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();
 }
Beispiel #19
0
 public void GenSimple(CodeGenContext context)
 {
     // Eval.ivar_get(recv, vid)
     context.ldarg("recv");
     context.ldstr(vid);
     context.call(Runtime.Eval.ivar_get);
 }
Beispiel #20
0
 internal override void GenCode0(CodeGenContext context)
 {
     // Eval.alias(ruby_class, lhs, rhs, myFrame);
     context.newLine(location);
     context.ruby_class(parent_scope);
     context.ldstr(lhs.ToString());
     context.ldstr(rhs.ToString());
     context.ldloc(0);
     context.call(Runtime.Eval.alias);
 }
Beispiel #21
0
         internal override void Defined(CodeGenContext context)
        {
            if (qualified)
                if (scope != null)
                {
                    // object result;
                    int result = context.CreateLocal("result", PrimitiveType.Object);
                    PERWAPI.CILLabel endLabel = context.NewLabel();
                    // try {
                    context.StartBlock(Clause.Try);
                    {
                        // result = Eval.const_defined(scope, vid, caller);
                        scope.GenCode(context);
                        context.ldstr(vid.ToString());
                        context.ldloc(0);
                        context.call(Runtime.Eval.const_defined);
                        context.stloc(result);
                        context.leave(endLabel);
                    }
                    TryBlock block = context.EndTryBlock();
                    // catch (System.Exception) {
                    context.StartBlock(Clause.Catch);
                    {
                        // result = null;
                        context.ldnull();
                        context.stloc(result);
                        context.leave(endLabel);
                    }
                    context.EndCatchBlock(Runtime.SystemExceptionRef, block);

                    context.CodeLabel(endLabel);
                    context.ldloc(result);
                    context.ReleaseLocal(result, true);
                }
                else
                {
                    context.ldsfld(Ruby.Compiler.Runtime.Init.rb_cObject);
                    context.ldstr(vid.ToString());
                    context.ldloc(0);
                    context.call(Runtime.Eval.const_defined);
                }
            else
            {
                context.ruby_cbase(parent_scope);
                context.ldstr(vid.ToString());
                context.ldloc(0);
                context.call(Runtime.Eval.const_defined);
            }
        }
Beispiel #22
0
 internal override void GenCode0(CodeGenContext context)
 {
     context.newLine(location);
     context.ldstr(lhs.ToString());
     context.ldstr(rhs.ToString());
     context.call(Runtime.Variables.alias_variable);
 }
Beispiel #23
0
        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);
        }
Beispiel #24
0
 public override void GenSimple(CodeGenContext context)
 {
     // frame.GetDynamic("vid");
     context.ldloc(0);
     context.ldstr(Name);
     context.call(Runtime.Frame.GetDynamic);
 }
Beispiel #25
0
        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);
        }
Beispiel #26
0
 public override void GenSimple(CodeGenContext context)
 {
     // thisblock.localsN.GetDynamic("vid");
     context.ldarg(0);
     context.ldfld(block.frameFields[depth - 1]);
     context.ldstr(Name);
     context.call(Runtime.Frame.GetDynamic);
 }
Beispiel #27
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 #28
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);
 }