示例#1
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);
        }
    }
示例#2
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);
        }
    }
示例#3
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);
        }
    }
示例#4
0
    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);
    }
示例#5
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);
        }
    }
示例#6
0
    internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
    {
        string          varName;
        MethodInfo      UndefInst      = typeof(JSUndefined).GetMethod("get_Instance", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, new Type[0], null);
        MethodInfo      SetRet         = typeof(JSContext).GetMethod("set_ReturnValue", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(JSValue) }, null);
        ConstructorInfo ObjCtor        = typeof(JSObject).GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
        MethodInfo      EnumerateProps = typeof(JSValue).GetMethod("EnumeratePropNames", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
        MethodInfo      GetEnumerator  = typeof(IEnumerable <>).MakeGenericType(new Type[] { typeof(string) }).GetMethod("GetEnumerator", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
        MethodInfo      get_Current    = typeof(IEnumerator <>).MakeGenericType(new Type[] { typeof(string) }).GetMethod("get_Current", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
        MethodInfo      get_Item       = typeof(JSValue).GetMethod("get_Item", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string) }, null);
        MethodInfo      MoveNext       = typeof(IEnumerator).GetMethod("MoveNext", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
        MethodInfo      Dispose        = typeof(IDisposable).GetMethod("Dispose", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
        MethodInfo      grv            = typeof(JSContext).GetMethod("get_ReturnValue", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
        LocalBuilder    lObj           = compileContext.gen.DeclareLocal(typeof(JSValue));
        LocalBuilder    lItem          = compileContext.gen.DeclareLocal(typeof(string));
        LocalBuilder    enumerator     = compileContext.gen.DeclareLocal(typeof(IEnumerator <>).MakeGenericType(new Type[] { typeof(string) }));

        base.continuedest = compileContext.gen.DefineLabel();
        Label lblIterate     = compileContext.gen.DefineLabel();
        Label lblSkipDispose = compileContext.gen.DefineLabel();

        if (base.Children[0] is VarDeclStatement)
        {
            varName = ((VarDeclStatement)base.Children[0]).varNames[0];
            compileContext.gen.Emit(OpCodes.Ldarg_0);
            compileContext.gen.Emit(OpCodes.Ldstr, varName);
            compileContext.gen.EmitCallV(CompileContext.mi_CreateMutableBinding);
        }
        ((ExpressionNode)base.Children[1]).GenCode(compileContext);
        compileContext.gen.Emit(OpCodes.Stloc, lObj.LocalIndex);
        compileContext.gen.Emit(OpCodes.Ldloc, lObj.LocalIndex);
        compileContext.gen.EmitCallV(EnumerateProps);
        compileContext.gen.EmitCallV(GetEnumerator);
        compileContext.gen.Emit(OpCodes.Stloc, enumerator.LocalIndex);
        compileContext.gen.BeginExceptionBlock();
        base.TryCatchLevels++;
        compileContext.gen.Emit(OpCodes.Br, base.continuedest);
        compileContext.gen.MarkLabel(lblIterate);
        compileContext.gen.Emit(OpCodes.Ldloc, enumerator.LocalIndex);
        compileContext.gen.EmitCallV(get_Current);
        compileContext.gen.Emit(OpCodes.Stloc, lItem.LocalIndex);
        if (base.Children[0] is TermBuilderNode)
        {
            TermBuilderNode DestVar = (TermBuilderNode)base.Children[0];
            DestVar.GenBaseCode(compileContext);
            DestVar.GenRefCode(compileContext);
            compileContext.gen.Emit(OpCodes.Ldloc, lItem.LocalIndex);
            compileContext.gen.Emit(OpCodes.Newobj, CompileContext.JSString_ctor);
            DestVar.GenAssignCode(compileContext);
        }
        else if (base.Children[0] is VarDeclStatement)
        {
            varName = ((VarDeclStatement)base.Children[0]).varNames[0];
            compileContext.gen.Emit(OpCodes.Ldarg_0);
            compileContext.gen.Emit(OpCodes.Ldstr, varName);
            compileContext.gen.Emit(OpCodes.Ldloc, lItem.LocalIndex);
            compileContext.gen.Emit(OpCodes.Newobj, CompileContext.JSString_ctor);
            compileContext.gen.EmitCallV(CompileContext.mi_SetMutableBinding);
        }
        ((StatementNode)base.Children[2]).GenCode(compileContext);
        compileContext.gen.MarkLabel(base.continuedest);
        compileContext.gen.Emit(OpCodes.Ldloc, enumerator.LocalIndex);
        compileContext.gen.EmitCallV(MoveNext);
        compileContext.gen.Emit(OpCodes.Brtrue, lblIterate);
        compileContext.gen.Emit(OpCodes.Leave, base.breakdest);
        base.TryCatchLevels--;
        compileContext.gen.BeginFinallyBlock();
        compileContext.gen.Emit(OpCodes.Ldloc, enumerator.LocalIndex);
        compileContext.gen.Emit(OpCodes.Ldnull);
        compileContext.gen.Emit(OpCodes.Ceq);
        compileContext.gen.Emit(OpCodes.Brtrue, lblSkipDispose);
        compileContext.gen.Emit(OpCodes.Ldloc, enumerator.LocalIndex);
        compileContext.gen.EmitCallV(Dispose);
        compileContext.gen.MarkLabel(lblSkipDispose);
        compileContext.gen.Emit(OpCodes.Endfinally);
        compileContext.gen.EndExceptionBlock();
    }
示例#7
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);
        }
    }