示例#1
0
    internal override void GenCode(CompileContext compileContext)
    {
        LocalBuilder    locVal;
        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, " syntax error" }));
        }
        if (DestVar.HasBase)
        {
            LocalBuilder locBase = compileContext.gen.DeclareLocal(typeof(JSValue));
            locVal = compileContext.gen.DeclareLocal(typeof(JSValue));
            DestVar.GenBaseCode(compileContext);
            compileContext.gen.Emit(OpCodes.Stloc, locBase.LocalIndex);
            compileContext.gen.Emit(OpCodes.Ldloc, locBase.LocalIndex);
            DestVar.GenFetchCode(compileContext);
            compileContext.gen.EmitCallV(CompileContext.mi_JSValue_ToPrimitive);
            compileContext.gen.Emit(OpCodes.Stloc, locVal.LocalIndex);
            compileContext.gen.Emit(OpCodes.Ldloc, locBase.LocalIndex);
            DestVar.GenRefCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, locVal.LocalIndex);
            compileContext.gen.EmitCallV(CompileContext.mi_JSValue_NumberValue);
            compileContext.gen.Emit(OpCodes.Ldc_R8, (double)1.0);
            compileContext.gen.Emit(this._op);
            compileContext.gen.Emit(OpCodes.Newobj, CompileContext.JSNumber_ctor);
            DestVar.GenAssignCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, locVal.LocalIndex);
        }
        else
        {
            locVal = compileContext.gen.DeclareLocal(typeof(JSValue));
            DestVar.GenFetchCode(compileContext);
            compileContext.gen.EmitCallV(CompileContext.mi_JSValue_ToPrimitive);
            compileContext.gen.Emit(OpCodes.Stloc, locVal.LocalIndex);
            DestVar.GenRefCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, locVal.LocalIndex);
            compileContext.gen.EmitCallV(CompileContext.mi_JSValue_NumberValue);
            compileContext.gen.Emit(OpCodes.Ldc_R8, (double)1.0);
            compileContext.gen.Emit(this._op);
            compileContext.gen.Emit(OpCodes.Newobj, CompileContext.JSNumber_ctor);
            DestVar.GenAssignCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, locVal.LocalIndex);
        }
    }
示例#2
0
    internal override void GenCode(CompileContext compileContext)
    {
        LocalBuilder    locVal;
        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" }));
        }
        if (DestVar.HasBase)
        {
            LocalBuilder locBase = compileContext.gen.DeclareLocal(typeof(JSValue));
            locVal = compileContext.gen.DeclareLocal(typeof(JSValue));
            DestVar.GenBaseCode(compileContext);
            compileContext.gen.Emit(OpCodes.Stloc, locBase.LocalIndex);
            compileContext.gen.Emit(OpCodes.Ldloc, locBase.LocalIndex);
            DestVar.GenFetchCode(compileContext);
            this.ProcessLeftVal(compileContext);
            this.GenRightVal(compileContext);
            this.ApplyOp(compileContext);
            compileContext.gen.Emit(OpCodes.Stloc, locVal.LocalIndex);
            compileContext.gen.Emit(OpCodes.Ldloc, locBase.LocalIndex);
            DestVar.GenRefCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, locVal.LocalIndex);
            DestVar.GenAssignCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, locVal.LocalIndex);
        }
        else
        {
            locVal = compileContext.gen.DeclareLocal(typeof(JSValue));
            DestVar.GenFetchCode(compileContext);
            this.ProcessLeftVal(compileContext);
            this.GenRightVal(compileContext);
            this.ApplyOp(compileContext);
            compileContext.gen.Emit(OpCodes.Stloc, locVal.LocalIndex);
            DestVar.GenRefCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, locVal.LocalIndex);
            DestVar.GenAssignCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, locVal.LocalIndex);
        }
    }
示例#3
0
    internal override void GenCode(CompileContext compileContext)
    {
        CommonTree      args     = (CommonTree)base.Children[0];
        ExpressionNode  Source   = (ExpressionNode)base.Children[1];
        TermBuilderNode TBSource = Source as TermBuilderNode;
        LocalBuilder    lThisObj = compileContext.gen.DeclareLocal(typeof(JSValue));
        LocalBuilder    lFncObj  = compileContext.gen.DeclareLocal(typeof(JSValue));

        if ((TBSource != null) && TBSource.HasBase)
        {
            TBSource.GenBaseCode(compileContext);
            compileContext.gen.Emit(OpCodes.Stloc, lThisObj.LocalIndex);
            compileContext.gen.Emit(OpCodes.Ldloc, lThisObj.LocalIndex);
            TBSource.GenFetchCode(compileContext);
            compileContext.gen.Emit(OpCodes.Stloc, lFncObj.LocalIndex);
            compileContext.gen.Emit(OpCodes.Ldloc, lFncObj.LocalIndex);
            compileContext.gen.EmitCallV(CompileContext.fnc_Utilities_JSFunctionCast);
            compileContext.gen.Emit(OpCodes.Ldarg_0);
            compileContext.gen.Emit(OpCodes.Ldloc, lThisObj.LocalIndex);
        }
        else if (TBSource is IdentifierNode)
        {
            compileContext.gen.Emit(OpCodes.Ldarg_0);
            compileContext.gen.Emit(OpCodes.Ldstr, ((IdentifierNode)TBSource).Value);
            compileContext.gen.Emit(OpCodes.Ldloca, lThisObj.LocalIndex);
            compileContext.gen.EmitCallV(CompileContext.mi_GetFunctionWithThis);
            compileContext.gen.Emit(OpCodes.Stloc, lFncObj.LocalIndex);
            compileContext.gen.Emit(OpCodes.Ldloc, lFncObj.LocalIndex);
            compileContext.gen.EmitCallV(CompileContext.fnc_Utilities_JSFunctionCast);
            compileContext.gen.Emit(OpCodes.Ldarg_0);
            compileContext.gen.Emit(OpCodes.Ldloc, lThisObj.LocalIndex);
        }
        else
        {
            Source.GenCode(compileContext);
            compileContext.gen.Emit(OpCodes.Stloc, lFncObj.LocalIndex);
            compileContext.gen.Emit(OpCodes.Ldloc, lFncObj.LocalIndex);
            compileContext.gen.EmitCallV(CompileContext.fnc_Utilities_JSFunctionCast);
            compileContext.gen.Emit(OpCodes.Ldarg_0);
            compileContext.gen.Emit(OpCodes.Ldarg_0);
            compileContext.gen.EmitCallV(CompileContext.mi_ImplicitThis);
        }
        compileContext.gen.Emit(OpCodes.Ldloc, lFncObj.LocalIndex);
        compileContext.gen.Emit(OpCodes.Ldc_I4, args.ChildCount);
        compileContext.gen.Emit(OpCodes.Newarr, typeof(JSValue));
        int i = 0;

        if (args.ChildCount != 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);
        if (this.IsDirectEval)
        {
            compileContext.gen.EmitCallV(CompileContext.fnc_Utilities_DirectEvalCall);
        }
        else
        {
            compileContext.gen.EmitCallV(CompileContext.mi_JSFunctionBase_Call);
        }
    }