Esempio n. 1
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());
        }
Esempio n. 2
0
   internal override void Defined(CodeGenContext context)
 {
     context.PushTrue();
     context.box(PrimitiveType.Boolean);
 }
Esempio n. 3
0
          internal override void Defined(CodeGenContext context)
        {
            PERWAPI.CILLabel undefined_label = context.NewLabel();
            PERWAPI.CILLabel end_label = context.NewLabel();

            for (Node arg = parameters; arg != null; arg = arg.nd_next)
            {
                arg.Defined(context);
                context.brfalse(undefined_label);
            }

            if (array != null)
            {
                array.Defined(context);
                context.brfalse(undefined_label);
            }

            if (hashlist != null)
            {
                hashlist.Defined(context);
                context.brfalse(undefined_label);
            }

            if (block != null)
            {
                block.Defined(context);
                context.brfalse(undefined_label);
            }

            context.PushTrue();
            context.box(PrimitiveType.Boolean);

            if (!IsEmpty)
            {
                context.br(end_label);

                context.CodeLabel(undefined_label);
                context.PushFalse();
                context.box(PrimitiveType.Boolean);

                context.CodeLabel(end_label);
            }
        }
Esempio n. 4
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));
            }
        }
Esempio n. 5
0
 public void GenSimple(CodeGenContext context)
 {
     context.PushTrue();
     context.box(PrimitiveType.Boolean);
 }