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); }
protected void ReturnArray(CodeGenContext context) { // Ruby.Eval.Return(array, caller); array.GenCode(context); context.ldloc(0); context.call(Runtime.Eval.Return); }
internal override void GenCode0(CodeGenContext context) { PERWAPI.CILLabel elseLabel = context.NewLabel(); PERWAPI.CILLabel endLabel = context.NewLabel(); // if (Eval.Test(cond)) cond.GenCode(context); context.call(Runtime.Eval.Test); context.brfalse(elseLabel); body.GenCode(context); context.br(endLabel); context.CodeLabel(elseLabel); _else.GenCode(context); context.CodeLabel(endLabel); }
internal override void GenCode0(CodeGenContext context) { PERWAPI.CILLabel elseLabel = context.NewLabel(); PERWAPI.CILLabel endLabel = context.NewLabel(); // if (Eval.Test(cond)) context.newLine(cond.location); cond.GenCode(context); context.call(Runtime.Eval.Test); context.brfalse(elseLabel); if (body != null) { context.newStartPoint(body.location); body.GenCode(context); } else context.ldnull(); if (context.Reachable()) context.br(endLabel); context.CodeLabel(elseLabel); if (_else != null) { context.newStartPoint(_else.location); _else.GenCode(context); } else context.ldnull(); context.CodeLabel(endLabel); context.newEndPoint(location); }
public void GenSimple(CodeGenContext context) { // Eval.ivar_get(recv, vid) context.ldarg("recv"); context.ldstr(vid); context.call(Runtime.Eval.ivar_get); }
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 GenCode0(CodeGenContext context) { CodeGenContext Begin = context.CreateMethod(FileClass(), MethAttr.PublicStatic, "Begin" + (seq++), PrimitiveType.Object, new Param(ParamAttr.Default, "recv", PrimitiveType.Object), new Param(ParamAttr.Default, "caller", Runtime.FrameRef)); Begin.startMethod(this.location); AddScopeLocals(Begin); AddScopeBody(Begin); Begin.ReleaseLocal(0, true); Begin.Close(); // Begin(recv, caller); context.ldarg("recv"); context.ldloc(0); context.call(Begin.Method); context.pop(); }
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 void GenCode(CodeGenContext context, PERWAPI.CILLabel endLabel, int RescueTemp, int exception) { for (RESCUE_CLAUSE clause = this; clause != null; clause = clause.next) { PERWAPI.CILLabel nextClause = context.NewLabel(); PERWAPI.CILLabel thisClause = context.NewLabel(); context.ldc_i4(0); LOCAL exceptionCaught = context.StoreInLocal("caught", PERWAPI.PrimitiveType.Boolean, this.location); for (Node type = clause.types; type != null; type = type.nd_next) { PERWAPI.CILLabel label1 = context.NewLabel(); // Precompute each separately to avoid computing a list of types type.GenCode0(context); LOCAL tt = context.StoreInLocal("type", PERWAPI.PrimitiveType.Object, type.location); new METHOD_CALL(tt, ID.intern(Tokens.tEQQ), new AST.LOCAL(exception, type.location), type.location).GenCode(context); context.ReleaseLocal(tt.local, true); context.call(Runtime.Eval.Test); context.brfalse(label1); context.PushTrue(); context.stloc(exceptionCaught.local); context.CodeLabel(label1); } context.ldloc(exceptionCaught.local); context.brtrue(thisClause); context.ReleaseLocal(exceptionCaught.local, true); context.br(nextClause); context.CodeLabel(thisClause); if (clause.var != null) { clause.var.Assign(context, new AST.LOCAL(exception, clause.var.location)); context.pop(); } if (clause.body != null) clause.body.GenCode(context); else context.ldnull(); if (context.Reachable()) context.stloc(RescueTemp); // reset $! //Eval.ruby_errinfo.value = null; context.ldsfld(Runtime.Eval.ruby_errinfo); context.ldnull(); context.stfld(Runtime.global_variable.value); context.Goto(endLabel); context.CodeLabel(nextClause); } }
public override void GenSimple(CodeGenContext context) { // frame.GetDynamic("vid"); context.ldloc(0); context.ldstr(Name); context.call(Runtime.Frame.GetDynamic); }
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 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); }
internal override void GenCode0(CodeGenContext context) { context.newLine(location); context.ldstr(lhs.ToString()); context.ldstr(rhs.ToString()); context.call(Runtime.Variables.alias_variable); }
internal override void GenCode0(CodeGenContext context) { bool scope_created, super_created; CodeGenContext newContext = new CodeGenContext(context); // scope and super must be evaluated in surrounding scope and passed to Init method ISimple scope = PushScope(context, out scope_created); ISimple super = PushSuper(context, out super_created); string basename = ID.ToDotNetName(name.vid); // BBTAG: try and get the superclass PERWAPI.Class superClass = Runtime.ObjectRef; bool superClassFound = false; PERWAPI.Method superClassConstructor0 = null; PERWAPI.Method superClassConstructor1 = Runtime.Object.ctor; if (this is CLASS) { superClass = ((CLASS)this).GetSuperClassRef(newContext); if (superClass != null) { superClassFound = true; superClassConstructor0 = superClass.GetMethodDesc(".ctor", new Type[0]); if (superClassConstructor0 is MethodDef) superClassConstructor0 = ((MethodDef)superClassConstructor0).MakeRefOf(); superClassConstructor1 = superClass.GetMethodDesc(".ctor", new Type[] { Runtime.ClassRef }); if (superClassConstructor1 is MethodDef) superClassConstructor1 = ((MethodDef)superClassConstructor1).MakeRefOf(); } else superClass = Runtime.ObjectRef; } //public class MyClass: Object { // check if this class has already been created in a referenced DLL // FIXME: this won't work for nested classes PERWAPI.Class classRef = ClassSkeleton.FindPERWAPIClass(null, name, context.peFiles); bool defineInteropClass = (classRef == null); // if it seems like an extension of a ruby builtin class, don't generate an interop class // FIXME: this won't work for nested classes if (Ruby.Runtime.BuiltinClasses.IsBuiltinClass(basename)) { Compiler.InteropWarning(basename + " is a Ruby built-in class, interop class not generated"); defineInteropClass = false; } //ClassDef interopClass = newContext.CreateNestedClass(CurrentInteropClass(), basename, Runtime.ObjectRef); // BBTAG ClassDef interopClass = null; if (defineInteropClass) { if (superClass is PERWAPI.ClassDef) interopClass = newContext.CreateNestedClass(CurrentInteropClass(), basename, ((PERWAPI.ClassDef)superClass).MakeRefOf()); // BBTAG else interopClass = newContext.CreateNestedClass(CurrentInteropClass(), basename, superClass); // BBTAG interopClasses.Push(interopClass); classRef = interopClass; } //context.classes[classname] = interopClass; // BBTAG: create skeleton for this class ClassSkeleton skeleton; if (context.currentSkeleton.nestedClasses.ContainsKey(basename)) skeleton = context.currentSkeleton.nestedClasses[basename]; else skeleton = new ClassSkeleton(basename, classRef); skeleton.lexicalParent = context.currentSkeleton; newContext.currentSkeleton = skeleton; skeleton.lexicalParent.nestedClasses[basename] = skeleton; if (!superClassFound && this is AST.CLASS && ((AST.CLASS)this).super_class != null && defineInteropClass) { // do not add to post pass list if supertype is a built-in Ruby class //List<string> qualifiedSuperClass = ClassSkeleton.ConstNodeToClassList(((AST.CLASS)this).super_class); //if (!(qualifiedSuperClass.Count == 1 && Ruby.Runtime.BuiltinClasses.IsBuiltinClass(qualifiedSuperClass[0]))) newContext.postPassList.Add(new ClassSkeletonPostPass(skeleton, interopClass, ((AST.CLASS)this).super_class)); } // public static Class classname; int seqNo = 0; internal_name = basename; while (FileClass().GetField(internal_name) != null) internal_name = basename + (seqNo++); // Define singleton in file class so that it gets initialized by .cctor singletonField = FileClass().AddField(PERWAPI.FieldAttr.PublicStatic, internal_name, Runtime.ClassRef); newContext.CurrentRubyClass = singletonField; // public MyClass() : base(singleton) { }; CodeGenContext class_constructor = null; if (defineInteropClass) { if (interopClass.GetMethod(".ctor", new Type[0]) == null) { CodeGenContext class_constructor0 = newContext.CreateConstructor(interopClass); class_constructor0.ldarg(0); if (superClassConstructor0 != null) class_constructor0.call(superClassConstructor0); else { class_constructor0.ldsfld(singletonField); class_constructor0.call(superClassConstructor1); } class_constructor0.ret(); class_constructor0.Close(); } // public MyClass(Class klass) : base(klass) { }; MethodDef ctor = interopClass.GetMethod(".ctor", new Type[] { Runtime.ClassRef }); //CodeGenContext class_constructor; if (ctor == null) { class_constructor = newContext.CreateConstructor(interopClass, new Param(ParamAttr.Default, "klass", Runtime.ClassRef)); class_constructor.ldarg(0); class_constructor.ldarg("klass"); class_constructor.call(superClassConstructor1); class_constructor.ret(); class_constructor.Close(); } else { class_constructor = new CodeGenContext(); class_constructor.Method = ctor; } } // internal static void Init_fullname(object scope, object super, object recv, Frame caller) { CodeGenContext Init = newContext.CreateMethod(FileClass(), MethAttr.PublicStatic, "Init_" + internal_name, PrimitiveType.Object, new Param(ParamAttr.Default, "scope", PrimitiveType.Object), new Param(ParamAttr.Default, "super", PrimitiveType.Object), new Param(ParamAttr.Default, "recv", PrimitiveType.Object), new Param(ParamAttr.Default, "caller", Runtime.FrameRef)); skeleton.initMethod = Init.Method; Init.startMethod(this.location); AddScopeLocals(Init); // singleton = scope.define_???(...) DefineClass(Init, singletonField); // recv = singleton; Init.ldsfld(singletonField); Init.starg("recv"); // Fixme: should be conditional // singleton.define_allocator(allocator); if (defineInteropClass) { FieldDef allocator = DefineAllocator(newContext, class_constructor.Method); if (allocator != null) { Init.ldsfld(singletonField); Init.ldsfld(allocator); Init.call(Runtime.Class.define_alloc_func); } } AddScopeBody(Init); Init.ReleaseLocal(0, true); Init.Close(); if (defineInteropClass) interopClasses.Pop(); // --------------------- Return to old Context ---------------------------- context.newLine(location); // Init(scope, super, recv, caller); scope.GenSimple(context); super.GenSimple(context); context.ldarg("recv"); context.ldloc(0); context.call(Init.Method); context.ReleaseLocal(super, super_created); context.ReleaseLocal(scope, scope_created); }
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); }
internal override void DefineClass(CodeGenContext context, PERWAPI.FieldDef singleton) { // Class.singleton_class(caller, super) context.ldloc(0); context.ldarg("super"); context.call(Runtime.Class.singleton_class); context.stsfld(singleton); }
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); }
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); }
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); } }
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); }
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 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); }
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); }
private void RHSAsArray(CodeGenContext context) { // Array.Store(rhs); rhs.GenCode(context); context.call(Runtime.Array.Store); }
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); }
internal override void Defined(CodeGenContext context) { // Variables.gvar_defined(vid); context.ldstr(vid.ToString()); context.call(Runtime.Variables.gvar_defined); }
internal override void GenCode0(CodeGenContext context) { int receiverLocal = 0; // singleton_class(caller, receiver).define_method(...); context.newStartPoint(location); if (!(receiver is AST.CALL)) { context.ldloc(0); receiver.GenCode(context); } else { receiver.GenCode(context); receiverLocal = context.CreateLocal("receiverLocal", PrimitiveType.Object); context.stloc(receiverLocal); context.ldloc(0); context.ldloc(receiverLocal); } context.call(Runtime.Class.singleton_class); DefineMethod(context); if (receiver is AST.CALL) context.ReleaseLocal(receiverLocal, true); }
public void GenSimple(CodeGenContext context) { // Variables.gvar_get(vid, caller); context.ldstr(vid.ToString()); context.ldloc(0); context.call(Runtime.Variables.gvar_get); }
internal override void GenCode0(CodeGenContext context) { base.GenCode0(context); context.call(Runtime.Program.End); }
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); }