protected override void GenRightVal(CompileContext compileContext)
 {
     ((ExpressionNode) base.Children[1]).GenTyped(compileContext, JSType.Number);
     compileContext.gen.EmitCallV( CompileContext.fnc_Utilities_JSToInt32);
     compileContext.gen.Emit(OpCodes.Ldc_I4_S, 0x1f);
     compileContext.gen.Emit(OpCodes.And);
 }
 internal override void GenCode(CompileContext compileContext)
 {
     ExpressionNode Constructor = (ExpressionNode) base.Children[0];
     CommonTree args = null;
     LocalBuilder lfnc = compileContext.gen.DeclareLocal(typeof(JSValue));
     int ArgCount = 0;
     if (this.ChildCount > 1)
     {
         args = (CommonTree) base.Children[1];
         ArgCount = args.ChildCount;
     }
     Constructor.GenCode(compileContext);
     compileContext.gen.Emit(OpCodes.Stloc, lfnc.LocalIndex);
     compileContext.gen.Emit(OpCodes.Ldloc, lfnc.LocalIndex);
     compileContext.gen.EmitCallV( CompileContext.fnc_Utilities_JSFunctionCast);
     compileContext.gen.Emit(OpCodes.Ldarg_0);
     compileContext.gen.Emit(OpCodes.Ldloc, lfnc.LocalIndex);
     compileContext.gen.Emit(OpCodes.Ldc_I4, ArgCount);
     compileContext.gen.Emit(OpCodes.Newarr, typeof(JSValue));
     int i = 0;
     if (ArgCount != 0)
     {
         foreach (ExpressionNode arg in args.Children)
         {
             compileContext.gen.Emit(OpCodes.Dup);
             compileContext.gen.Emit(OpCodes.Ldc_I4, i++);
             arg.GenCode(compileContext);
             compileContext.gen.Emit(OpCodes.Stelem_Ref);
         }
     }
     compileContext.gen.Emit(OpCodes.Newobj, CompileContext.JSArgs_ctor);
     compileContext.gen.EmitCallV( CompileContext.mi_JSFunctionBase_Construct);
 }
 protected override void ApplyOp(CompileContext compileContext)
 {
     compileContext.gen.Emit(OpCodes.Shr_Un);
     compileContext.gen.Emit(OpCodes.Conv_R_Un);
     compileContext.gen.Emit(OpCodes.Conv_R8);
     compileContext.gen.Emit(OpCodes.Newobj, CompileContext.JSNumber_ctor);
 }
 internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
 {
     Label lblTop = compileContext.gen.DefineLabel();
     base.continuedest = compileContext.gen.DefineLabel();
     Label lblBody = compileContext.gen.DefineLabel();
     StatementNode A = (((CommonTree) base.Children[0]).ChildCount != 0) ? ((StatementNode) ((CommonTree) base.Children[0]).Children[0]) : null;
     if(A != null)
         foreach (baseNode n in A.EnumerateAll())
             if (n is InNode) throw new JSRuntimeException("SyntaxError", "Invalid for/in");
     ExpressionNode B = (((CommonTree) base.Children[1]).ChildCount != 0) ? ((ExpressionNode) ((CommonTree) base.Children[1]).Children[0]) : null;
     StatementNode C = (((CommonTree) base.Children[2]).ChildCount != 0) ? ((StatementNode) ((CommonTree) base.Children[2]).Children[0]) : null;
     StatementNode D = (StatementNode) ((CommonTree) base.Children[3]);
     bool _track = compileContext.TrackImplicitReturnValue;
     if (A != null)
     {
         compileContext.TrackImplicitReturnValue = false;
         A.GenCode(compileContext);
         compileContext.TrackImplicitReturnValue = _track;
     }
     compileContext.gen.MarkLabel(lblTop);
     if (B != null)
     {
         B.GenLazyEval(compileContext, lblBody, base.breakdest);
     }
     compileContext.gen.MarkLabel(lblBody);
     D.GenCode(compileContext);
     compileContext.gen.MarkLabel(base.continuedest);
     if (C != null)
     {
         compileContext.TrackImplicitReturnValue = false;
         C.GenCode(compileContext);
         compileContext.TrackImplicitReturnValue = _track;
     }
     compileContext.gen.Emit(OpCodes.Br, lblTop);
 }
 internal override void GenCode(CompileContext compileContext)
 {
     int RealChildCount = this.ChildCount;
     if ((RealChildCount != 0) && (((baseNode) base.Children[RealChildCount - 1]).ChildCount == 0))
     {
         RealChildCount--;
     }
     compileContext.gen.Emit(OpCodes.Ldc_I4, RealChildCount);
     compileContext.gen.Emit(OpCodes.Newarr, typeof(JSValue));
     for (int i = 0; i < RealChildCount; i++)
     {
         compileContext.gen.Emit(OpCodes.Dup);
         compileContext.gen.Emit(OpCodes.Ldc_I4, i);
         baseNode n = (baseNode) base.Children[i];
         if (n.ChildCount == 0)
         {
             compileContext.gen.EmitCallV( CompileContext.mi_JSUndefined_Instance);
         }
         else
         {
             ((ExpressionNode) n.Children[0]).GenCode(compileContext);
         }
         compileContext.gen.Emit(OpCodes.Stelem_Ref);
     }
     compileContext.gen.Emit(OpCodes.Newobj, CompileContext.JSArray_ctor);
 }
 internal virtual void GenDupeBaseCode(CompileContext compileContext)
 {
     if (this.LeftTree != null)
     {
         compileContext.gen.Emit(OpCodes.Dup);
     }
 }
 internal override void GenLazyEval(CompileContext compileContext, Label lblTrue, Label lblFalse)
 {
     Label lblPartTwo = compileContext.gen.DefineLabel();
     ((ExpressionNode) base.Children[0]).GenLazyEval(compileContext, lblTrue, lblPartTwo);
     compileContext.gen.MarkLabel(lblPartTwo);
     ((ExpressionNode) base.Children[1]).GenLazyEval(compileContext, lblTrue, lblFalse);
 }
 internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
 {
     CommonTree t = this;
     while (t != null)
     {
         if (t is TopStatementList)
         {
             break;
         }
         t = t.parent;
     }
     if (((TopStatementList) t).Parent == null)
     {
         throw new JSRuntimeException("SyntaxError", "return not in a function");
     }
     if (this.ChildCount == 0)
     {
         compileContext.gen.EmitCallV( CompileContext.mi_JSUndefined_Instance);
     }
     else if (!bGenDebug)
     {
         ((ExpressionNode) base.Children[0]).GenCode(compileContext);
     }
     else
     {
         LocalBuilder l = compileContext.gen.DeclareLocal(typeof(JSValue));
         base.GenDebugWrap(compileContext, delegate (CompileContext x) {
             ((ExpressionNode) this.Children[0]).GenCode(compileContext);
             compileContext.gen.Emit(OpCodes.Stloc, l.LocalIndex);
         });
         compileContext.gen.Emit(OpCodes.Ldloc, l.LocalIndex);
     }
     compileContext.gen.Emit(OpCodes.Stloc, compileContext.fncData.return_local);
     base.GenInterStatementBreak(compileContext, compileContext.fncData.return_label);
 }
 public override void GenTyped(CompileContext compileContext)
 {
     JSType TreeType = this.TreeType;
     ((ExpressionNode) base.Children[0]).GenTyped(compileContext, TreeType);
     ((ExpressionNode) base.Children[1]).GenTyped(compileContext, TreeType);
     this.GenTypedOp(compileContext);
 }
 internal virtual void GenBaseCode(CompileContext compileContext)
 {
     if (this.LeftTree != null)
     {
         this.LeftTree.GenCode(compileContext);
     }
 }
 public override void GenTyped(CompileContext compileContext)
 {
     ((ExpressionNode) base.Children[0]).GenTyped(compileContext, JSType.Number);
     compileContext.gen.EmitCallV( CompileContext.fnc_Utilities_JSToInt32);
     compileContext.gen.Emit(OpCodes.Not);
     compileContext.gen.Emit(OpCodes.Conv_R8);
 }
 internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
 {
     Label lblTop = compileContext.gen.DefineLabel();
     Label lblCond = base.continuedest = compileContext.gen.DefineLabel();
     compileContext.gen.MarkLabel(lblTop);
     ((StatementNode) base.Children[0]).GenCode(compileContext);
     compileContext.gen.MarkLabel(lblCond);
     ((ExpressionNode) base.Children[1]).GenLazyEval(compileContext, lblTop, base.breakdest);
 }
Beispiel #13
0
 public override void GenTyped(CompileContext compileContext)
 {
     LocalBuilder l = compileContext.gen.DeclareLocal(typeof(string));
     ((ExpressionNode) base.Children[0]).GenTyped(compileContext, JSType.String);
     compileContext.gen.Emit(OpCodes.Stloc, l.LocalIndex);
     ((ExpressionNode) base.Children[1]).GenCode(compileContext);
     compileContext.gen.Emit(OpCodes.Ldloc, l.LocalIndex);
     compileContext.gen.EmitCallV( CompileContext.mi_JSValue_HasProperty_in);
 }
 public override void GenTyped(CompileContext compileContext)
 {
     LocalBuilder l = compileContext.gen.DeclareLocal(typeof(JSValue));
     ((ExpressionNode) base.Children[0]).GenCode(compileContext);
     compileContext.gen.Emit(OpCodes.Stloc, l.LocalIndex);
     ((ExpressionNode) base.Children[1]).GenCode(compileContext);
     compileContext.gen.EmitCallV( CompileContext.fnc_Utilities_JSFunctionCast);
     compileContext.gen.Emit(OpCodes.Ldloc, l.LocalIndex);
     compileContext.gen.EmitCallV( CompileContext.mi_JSFunctionBase_HasInstance);
 }
 internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
 {
     if (this.ChildCount != 0)
     {
         foreach (StatementNode n in base.Children)
         {
             n.GenCode(compileContext);
         }
     }
 }
 internal override void GenCode(CompileContext compileContext)
 {
     Label lblSkip = compileContext.gen.DefineLabel();
     ((ExpressionNode) base.Children[0]).GenCode(compileContext);
     compileContext.gen.Emit(OpCodes.Dup);
     compileContext.gen.EmitCallV( CompileContext.mi_JSValue_BoolValue);
     compileContext.gen.Emit(OpCodes.Brtrue, lblSkip);
     compileContext.gen.Emit(OpCodes.Pop);
     ((ExpressionNode) base.Children[1]).GenCode(compileContext);
     compileContext.gen.MarkLabel(lblSkip);
 }
 internal void GenTyped(CompileContext compileContext, JSType aJType)
 {
     if (this.TreeType == aJType)
     {
         this.GenTyped(compileContext);
     }
     else
     {
         this.GenTypedBase(compileContext, aJType);
     }
 }
 internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
 {
     if (bGenDebug)
     {
         base.GenDebugWrap(compileContext, new Action<CompileContext>(this.GenStatementCode));
     }
     else
     {
         this.GenStatementCode(compileContext);
     }
 }
Beispiel #19
0
 protected override void GenTypedOp(CompileContext compileContext)
 {
     if (this.TreeType == JSType.String)
     {
         compileContext.gen.EmitCallV( CompileContext.fnc_Sys_String_Concat);
     }
     else
     {
         compileContext.gen.Emit(OpCodes.Add);
     }
 }
 public override void GenTyped(CompileContext compileContext)
 {
     ((ExpressionNode) base.Children[0]).GenTyped(compileContext, JSType.Number);
     compileContext.gen.EmitCallV( CompileContext.fnc_Utilities_JSToUInt32);
     ((ExpressionNode) base.Children[1]).GenTyped(compileContext, JSType.Number);
     compileContext.gen.EmitCallV( CompileContext.fnc_Utilities_JSToInt32);
     compileContext.gen.Emit(OpCodes.Ldc_I4_S, 0x1f);
     compileContext.gen.Emit(OpCodes.And);
     compileContext.gen.Emit(OpCodes.Shr_Un);
     compileContext.gen.Emit(OpCodes.Conv_R_Un);
     compileContext.gen.Emit(OpCodes.Conv_R8);
 }
Beispiel #21
0
 internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
 {
     StatementNode dest = this.FindContinueDest();
     if ((this.lbl != null) && ((dest == null) || !dest.AllowContinue))
     {
         throw new JSRuntimeException("SyntaxError", "label not found");
     }
     if ((dest == null) || (0 != 0))
     {
         throw new JSRuntimeException("SyntaxError", "continue must be inside loop");
     }
     base.GenInterStatementBreak(compileContext, dest.continuedest, dest);
 }
 internal override void GenCode(CompileContext compileContext)
 {
     Label lblTrue = compileContext.gen.DefineLabel();
     Label lblFalse = compileContext.gen.DefineLabel();
     Label lblEnd = compileContext.gen.DefineLabel();
     ((ExpressionNode) base.Children[0]).GenLazyEval(compileContext, lblTrue, lblFalse);
     compileContext.gen.MarkLabel(lblFalse);
     ((ExpressionNode) base.Children[2]).GenCode(compileContext);
     compileContext.gen.Emit(OpCodes.Br, lblEnd);
     compileContext.gen.MarkLabel(lblTrue);
     ((ExpressionNode) base.Children[1]).GenCode(compileContext);
     compileContext.gen.MarkLabel(lblEnd);
 }
Beispiel #23
0
 internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
 {
     StatementNode dest = this.FindBreakDest();
     if ((this.lbl != null) && (dest == null))
     {
         throw new JSRuntimeException("SyntaxError", "label not found");
     }
     if (dest == null)
     {
         throw new JSRuntimeException("SyntaxError", "unlabeled break must be inside loop or switch");
     }
     base.GenInterStatementBreak(compileContext, dest.breakdest, dest);
 }
 internal override void GenCode(CompileContext compileContext)
 {
     int i = 0;
     while (true)
     {
         ((ExpressionNode) base.Children[i]).GenCode(compileContext);
         if (++i == this.ChildCount)
         {
             return;
         }
         compileContext.gen.Emit(OpCodes.Pop);
     }
 }
 private void GenStatementCode(CompileContext compileContext)
 {
     functionExpressionNode fnc = (functionExpressionNode) base.Children[0];
     string fncName = fnc.Name;
     compileContext.gen.Emit(OpCodes.Ldarg_0);
     compileContext.gen.Emit(OpCodes.Ldstr, fncName);
     compileContext.gen.EmitCallV( CompileContext.mi_CreateMutableBinding);
     compileContext.gen.Emit(OpCodes.Ldarg_0);
     compileContext.gen.Emit(OpCodes.Ldstr, fncName);
     compileContext.gen.Emit(OpCodes.Ldarg_0);
     fnc.GenFunctionRef(compileContext);
     compileContext.gen.EmitCallV( CompileContext.mi_GetFunctionReference);
     compileContext.gen.EmitCallV( CompileContext.mi_SetVarBinding);
 }
Beispiel #26
0
 public override void GenTyped(CompileContext compileContext)
 {
     TermBuilderNode TB = base.Children[0] as TermBuilderNode;
     if (!((TB == null) || (TB is ThisRef)))
     {
         TB.GenBaseCode(compileContext);
         TB.GenRefCode(compileContext);
         compileContext.gen.EmitCallV( CompileContext.mi_JSBase_GetBindingType);
     }
     else
     {
         ((ExpressionNode) base.Children[0]).GenCode(compileContext);
         compileContext.gen.EmitCallV( CompileContext.mi_JSValue_TypeOf);
     }
 }
 private void GenStatementCode(CompileContext compileContext)
 {
     if (compileContext.TrackImplicitReturnValue)
     {
         compileContext.gen.Emit(OpCodes.Ldarg_0);
     }
     ((ExpressionNode) base.Children[0]).GenCode(compileContext);
     if (compileContext.TrackImplicitReturnValue)
     {
         compileContext.gen.EmitCallV( CompileContext.mi_Set_Returnval);
     }
     else
     {
         compileContext.gen.Emit(OpCodes.Pop);
     }
 }
 internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
 {
     compileContext.gen.Emit(OpCodes.Ldarg, 0);
     ((ExpressionNode) base.Children[0]).GenCode(compileContext);
     compileContext.gen.EmitCallV( CompileContext.mi_JSScope_CreateWithScope);
     compileContext.gen.Emit(OpCodes.Starg, 0);
     Label InternalTry = compileContext.gen.BeginExceptionBlock();
     base.TryCatchLevels++;
     ((StatementNode) base.Children[1]).GenCode(compileContext);
     base.TryCatchLevels--;
     compileContext.gen.BeginFinallyBlock();
     compileContext.gen.Emit(OpCodes.Ldarg_0);
     compileContext.gen.EmitCallV( CompileContext.mi_JSContext_Parent);
     compileContext.gen.Emit(OpCodes.Starg, 0);
     compileContext.gen.EndExceptionBlock();
 }
Beispiel #29
0
 public override void GenTyped(CompileContext compileContext)
 {
     ExpressionNode Source = (ExpressionNode) base.Children[0];
     TermBuilderNode TBSource = Source as TermBuilderNode;
     if ((TBSource == null) || (TBSource is ThisRef))
     {
         compileContext.gen.Emit(OpCodes.Ldc_I4_1);
     }
     else
     {
         TBSource.GenBaseCode(compileContext);
         TBSource.GenRefCode(compileContext);
         compileContext.gen.Emit(OpCodes.Ldc_I4_0);
         compileContext.gen.EmitCallV( CompileContext.mi_JSBase_DeleteProperty);
     }
 }
 internal override void GenCode(CompileContext compileContext)
 {
     TermBuilderNode DestVar = base.Children[0] as TermBuilderNode;
     if (DestVar == null)
     {
         throw new JSRuntimeException("SyntaxError", string.Concat(new object[] { "line ", base.token.Line, ":", base.token.CharPositionInLine, " Invalid assignment" }));
     }
     ((ExpressionNode) base.Children[1]).GenCode(compileContext);
     LocalBuilder loc = compileContext.gen.DeclareLocal(typeof(JSValue));
     compileContext.gen.Emit(OpCodes.Stloc, loc.LocalIndex);
     DestVar.GenBaseCode(compileContext);
     DestVar.GenRefCode(compileContext);
     compileContext.gen.Emit(OpCodes.Ldloc, loc.LocalIndex);
     DestVar.GenAssignCode(compileContext);
     compileContext.gen.Emit(OpCodes.Ldloc, loc.LocalIndex);
 }