2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / CodeGenerator.cs
index 096f44a1b11268c9b9e643a5e1161b46e199394f..e3ae60d76ea4793122c97e23b68e603da8dd8192 100644 (file)
@@ -338,7 +338,6 @@ namespace Microsoft.JScript {
 
                internal static void fall_true (EmitContext ec, AST ast, Label lbl)
                {
-                       ILGenerator ig = ec.ig;
                        Type type = ast.GetType ();
 
                        if (type == typeof (Expression)) {  
@@ -407,7 +406,6 @@ namespace Microsoft.JScript {
                        
                internal static void fall_false (EmitContext ec, AST ast, Label lbl)
                {
-                       ILGenerator ig = ec.ig;
                        Type type = ast.GetType ();
 
                        if (type == typeof (Expression)) {  
@@ -461,5 +459,22 @@ namespace Microsoft.JScript {
                        } else 
                                return false;
                }
+               
+               //
+               // Loads a current VsaEngine
+               //
+               internal static void load_engine (AST parent, ILGenerator ig)
+               {
+                       //
+                       // If we are in a function declaration at global level,
+                       // we must load the engine associated to the current 'JScript N' instance,
+                       // otherwise pick up the engine at second place in method's signature.
+                       //
+                       if (parent == null ||  parent.GetType () == typeof (ScriptBlock)) {
+                               ig.Emit (OpCodes.Ldarg_0);
+                               ig.Emit (OpCodes.Ldfld, typeof (ScriptObject).GetField ("engine"));
+                       } else if (parent != null &&  parent.GetType () == typeof (FunctionDeclaration )) 
+                               ig.Emit (OpCodes.Ldarg_1);
+               }
        }
 }