internal override void Emit(EmitContext ec) { ILGenerator ig = ec.ig; if (exp != null) { exp.Emit(ec); } ig.Emit(OpCodes.Ldarg_0); ig.Emit(OpCodes.Ldfld, typeof(ScriptObject).GetField("engine")); ig.Emit(OpCodes.Call, typeof(With).GetMethod("JScriptWith")); ig.Emit(OpCodes.Pop); ig.BeginExceptionBlock(); if (stm != null) { stm.Emit(ec); } ig.BeginFinallyBlock(); ig.Emit(OpCodes.Ldarg_0); ig.Emit(OpCodes.Ldfld, typeof(ScriptObject).GetField("engine")); ig.Emit(OpCodes.Call, typeof(VsaEngine).GetMethod("PopScriptObject")); ig.Emit(OpCodes.Pop); ig.EndExceptionBlock(); }
internal override void Emit(EmitContext ec) { ILGenerator ig = ec.ig; ig.BeginExceptionBlock(); if (guarded_block != null) { guarded_block.Emit(ec); } if (catch_blocks != null && catch_blocks.Count > 0) { foreach (Catch c in catch_blocks) { c.Emit(ec); } } if (finally_block != null) { ig.BeginFinallyBlock(); finally_block.Emit(ec); } ig.EndExceptionBlock(); }
internal override void Emit(EmitContext ec) { if (exp != null) { exp.Emit(ec); } ILGenerator ig = ec.ig; Label init_default = ig.DefineLabel(); Label end_of_default = ig.DefineLabel(); Label old_end = ec.LoopEnd; ec.LoopEnd = ig.DefineLabel(); LocalBuilder loc = ig.DeclareLocal(typeof(object)); ig.Emit(OpCodes.Stloc, loc); foreach (Clause c in case_clauses) { ig.Emit(OpCodes.Ldloc, loc); c.EmitConditional(ec); } /* emit conditionals from clauses that come after the default clause */ if (sec_case_clauses != null && sec_case_clauses.Count > 0) { foreach (Clause c in sec_case_clauses) { ig.Emit(OpCodes.Ldloc, loc); c.EmitConditional(ec); } } ig.Emit(OpCodes.Br, init_default); /* emit the stms from case_clauses */ foreach (Clause c in case_clauses) { ig.MarkLabel(c.matched_block); c.EmitStms(ec); } ig.MarkLabel(init_default); foreach (AST ast in default_clauses) { ast.Emit(ec); } ig.MarkLabel(end_of_default); if (sec_case_clauses != null && sec_case_clauses.Count > 0) { foreach (Clause c in sec_case_clauses) { ig.MarkLabel(c.matched_block); c.EmitStms(ec); } } ig.MarkLabel(ec.LoopEnd); ec.LoopEnd = old_end; }
internal override void Emit(EmitContext ec) { ILGenerator ig = ec.ig; Type t = typeof(object); bool in_function = InFunction; if (in_function) { local_builder = ig.DeclareLocal(t); } else { field_info = ec.type_builder.DefineField(mangle_id(id), t, FieldAttributes.Public | FieldAttributes.Static); } ig.BeginCatchBlock(typeof(Exception)); CodeGenerator.load_engine(in_function, ig); ig.Emit(OpCodes.Call, typeof(Try).GetMethod("JScriptExceptionValue")); if (in_function) { ig.Emit(OpCodes.Stloc, local_builder); } else { ig.Emit(OpCodes.Stsfld, field_info); } stms.Emit(ec); }
internal override void Emit(EmitContext ec) { ILGenerator ig = ec.ig; Label old_begin = ec.LoopBegin; Label old_end = ec.LoopEnd; Label body_label = ig.DefineLabel(); ec.LoopBegin = ig.DefineLabel(); ec.LoopEnd = ig.DefineLabel(); ig.MarkLabel(body_label); if (stm != null) { stm.Emit(ec); } ig.MarkLabel(ec.LoopBegin); if (parent.GetType() == typeof(Labelled)) { ig.MarkLabel((parent as Labelled).InitAddrs); } CodeGenerator.fall_false(ec, exp, body_label); ig.MarkLabel(ec.LoopEnd); ec.LoopBegin = old_begin; ec.LoopEnd = old_end; }
internal override void Emit(EmitContext ec) { ILGenerator ig = ec.ig; Label lbl = ig.DefineLabel(); LocalBuilder loc = null; if (expression != null) { expression.Emit(ec); loc = ig.DeclareLocal(typeof(object)); if (exp_returns_void) { ig.Emit(OpCodes.Ldnull); } ig.Emit(OpCodes.Stloc, loc); } ig.Emit(OpCodes.Br, lbl); ig.MarkLabel(lbl); if (loc != null) { ig.Emit(OpCodes.Ldloc, loc); } }
internal override void Emit(EmitContext ec) { ILGenerator ig = ec.ig; expression.Emit(ec); ig.Emit(OpCodes.Call, typeof(Throw).GetMethod("JScriptThrow")); ig.Emit(OpCodes.Throw); }
static void emit_default_case(EmitContext ec, AST ast, OpCode op, Label lbl) { ast.Emit(ec); if (need_convert_to_boolean(ast)) { emit_to_boolean(ast, ec.ig, 0); } ec.ig.Emit(op, lbl); }
internal void EmitConditional(EmitContext ec) { if (exp != null) { exp.Emit(ec); } ILGenerator ig = ec.ig; matched_block = ig.DefineLabel(); ig.Emit(OpCodes.Call, typeof(StrictEquality).GetMethod("JScriptStrictEquals")); ig.Emit(OpCodes.Brtrue, matched_block); }
internal override void Emit(EmitContext ec) { ILGenerator ig = ec.ig; if (parent == null || (parent.GetType() != typeof(FunctionDeclaration) && parent.GetType() != typeof(FunctionExpression))) { if (val != null) { val.Emit(ec); CodeGenerator.EmitBox(ig, val); ig.Emit(OpCodes.Stsfld, field_info); } } else { if (val != null) { val.Emit(ec); CodeGenerator.EmitBox(ig, val); ig.Emit(OpCodes.Stloc, local_builder); } } }
internal override void Emit(EmitContext ec) { ILGenerator ig = ec.ig; init_addrs = ig.DefineLabel(); end_addrs = ig.DefineLabel(); if (!IsLoop(stm)) { ig.MarkLabel(init_addrs); } stm.Emit(ec); ig.MarkLabel(end_addrs); }
static void ft_binary_recursion(EmitContext ec, AST ast, Label lbl) { ILGenerator ig = ec.ig; if (ast is Binary) { Binary b = ast as Binary; switch (b.op) { case JSToken.LogicalOr: Label ftLb = ig.DefineLabel(); fall_false(ec, b.left, ftLb); fall_true(ec, b.right, lbl); ig.MarkLabel(ftLb); break; case JSToken.LogicalAnd: fall_true(ec, b.left, lbl); fall_true(ec, b.right, lbl); break; case JSToken.LessThan: ig.Emit(OpCodes.Ldc_I4_0); ig.Emit(OpCodes.Conv_R8); ig.Emit(OpCodes.Blt, lbl); break; default: ast.Emit(ec); ig.Emit(OpCodes.Ldc_I4_1); ig.Emit(OpCodes.Call, typeof(Convert).GetMethod("ToBoolean", new Type [] { typeof(object), typeof(bool) })); ig.Emit(OpCodes.Brfalse, lbl); break; } } }
internal override void Emit(EmitContext ec) { ec.ig.Emit(OpCodes.Ldstr, property_name); exp.Emit(ec); CodeGenerator.EmitBox(ec.ig, exp); }
static void ft_binary_recursion(EmitContext ec, AST ast, Label lbl) { ILGenerator ig = ec.ig; if (ast is Binary) { Binary b = ast as Binary; switch (b.op) { case JSToken.LogicalOr: Label ftLb = ig.DefineLabel (); fall_false (ec, b.left, ftLb); fall_true (ec, b.right, lbl); ig.MarkLabel (ftLb); break; case JSToken.LogicalAnd: fall_true (ec, b.left, lbl); fall_true (ec, b.right, lbl); break; case JSToken.LessThan: ig.Emit (OpCodes.Ldc_I4_0); ig.Emit (OpCodes.Conv_R8); ig.Emit (OpCodes.Blt, lbl); break; default: ast.Emit (ec); ig.Emit (OpCodes.Ldc_I4_1); ig.Emit (OpCodes.Call, typeof (Convert).GetMethod ("ToBoolean", new Type [] {typeof (object), typeof (bool)})); ig.Emit (OpCodes.Brfalse, lbl); break; } } }
static void emit_default_case(EmitContext ec, AST ast, OpCode op, Label lbl) { ast.Emit (ec); if (need_convert_to_boolean (ast)) emit_to_boolean (ast, ec.ig, 0); ec.ig.Emit (op, lbl); }
private void emit_non_numeric_unary(EmitContext ec, AST operand, byte oper) { ILGenerator ig = ec.ig; Type unary_type = typeof (NumericUnary); LocalBuilder unary_builder = ig.DeclareLocal (unary_type); ig.Emit (OpCodes.Ldc_I4_S, oper); ig.Emit (OpCodes.Newobj, unary_type.GetConstructor (new Type [] { typeof (int) })); ig.Emit (OpCodes.Stloc, unary_builder); ig.Emit (OpCodes.Ldloc, unary_builder); operand.Emit (ec); ig.Emit (OpCodes.Call, unary_type.GetMethod ("EvaluateUnary")); }
internal override void Emit(EmitContext ec) { AST tmp; ILGenerator ig = ec.ig; Label old_begin = ec.LoopBegin; Label old_end = ec.LoopEnd; Label back = ig.DefineLabel(); Label forward = ig.DefineLabel(); /* emit init expr */ tmp = exprs [0]; if (tmp != null) { tmp.Emit(ec); } ec.LoopBegin = ig.DefineLabel(); ec.LoopEnd = ig.DefineLabel(); ig.MarkLabel(back); ig.MarkLabel(ec.LoopBegin); /* emit condition */ tmp = exprs [1]; if (tmp != null) { tmp.Emit(ec); } if (tmp != null && tmp is Expression) { ArrayList t = ((Expression)tmp).exprs; AST a = (AST)t [t.Count - 1]; if (a is Equality) { ig.Emit(OpCodes.Brfalse, forward); } else if (a is Relational) { Relational rel = (Relational)a; ig.Emit(OpCodes.Ldc_I4_0); ig.Emit(OpCodes.Conv_R8); if (rel.op == JSToken.GreaterThan) { ig.Emit(OpCodes.Ble, forward); } else { ig.Emit(OpCodes.Bge, forward); } } } /* emit stms */ if (stms != null) { stms.Emit(ec); } if (parent.GetType() == typeof(Labelled)) { ig.MarkLabel((parent as Labelled).InitAddrs); } tmp = exprs [2]; /* emit increment */ if (tmp != null) { tmp.Emit(ec); } ig.Emit(OpCodes.Br, back); ig.MarkLabel(forward); ig.MarkLabel(ec.LoopEnd); ec.LoopBegin = old_begin; ec.LoopEnd = old_end; }