예제 #1
0
		public NetStream( Stream stream, Context context ) {
			// have to set this stuff up to satisfy IObj. not sure why yet
			Context = context;
			
			// IronJS objects set up the following also, not sure if we
			// really need this stuff though
			// Prototype = context.ObjectConstructor.Object_prototype;
			// Class = ObjClass.Array;
			
			this.stream = stream;
			this.SetOwnProperty( "addListener", new Action<string, IFunction>( addListener ) );
		}
예제 #2
0
파일: Program.cs 프로젝트: dtdimi/IronJS
        //TODO: fix pretty-print of AST tree for all nodes
        static void Main(string[] args)
        {
            var context = new Context();
            var astBuilder = new Compiler.AstGenerator();
            var etGenerator = new Compiler.EtGenerator();
            var astNodes = astBuilder.Build("Testing.js", Encoding.UTF8);
            var compiled = etGenerator.Build(astNodes, context);
            var globals = Scope.CreateGlobal(context);

            context.SetupGlobals(globals);

            globals.Global(
                "println",
                typeof(HelperFunctions).GetMethod("PrintLine")
            );

            compiled(globals);
        }
예제 #3
0
        public Action<Scope> Build(List<Ast.Node> astNodes, Context context)
        {
            // Context we're compiling this code for
            Context = context;

            // Holds the uncompiled tuples of Expression<LambdaType> and List<string> of parameter
            LambdaTuples = new List<LambdaTuple>();

            // Function table
            FuncTableExpr =
                Et.Parameter(
                    typeof(FunctionTable),
                    "#functbl"
                );

            // Global function scope
            FunctionScope = new FunctionScope();

            // Store the frame expr for global frame
            GlobalScopeExpr = Et.Parameter(typeof(Scope), "#globals");

            // Stores all global expressions
            var globalExprs = new List<Et>();

            // Store our "true" globals expression
            globalExprs.Add(
                Et.Assign(
                    GlobalScopeExpr,
                    FunctionScope.ScopeExpr
                )
            );

            // Walk each global node
            foreach (var node in astNodes)
                globalExprs.Add(node.Walk(this));

            return Et.Lambda<Action<Scope>>(
                Et.Block(
                    new[] { FuncTableExpr, GlobalScopeExpr },

                    // Create instance of our functable
                    Et.Assign(
                        FuncTableExpr,
                        FunctionTable.EtNew()
                    ),

                    // Push functions into functable
                    LambdaTuples.Count > 0
                      ? (Et) Et.Block(
                            LambdaTuples.Select(x =>
                                FunctionTable.EtPush(
                                    FuncTableExpr,
                                    AstUtils.SimpleNewHelper(
                                        Lambda.Ctor1Arg,
                                        x.V1,
                                        Et.Constant(x.V2.ToArray())
                                    )
                                )
                            )
                        )
                      : (Et) AstUtils.Empty(), // hack

                    // Execute global scope
                    Et.Block(globalExprs)
                ),
                FunctionScope.ScopeExpr
            ).Compile();
        }
예제 #4
0
 internal static Et EtCreateFunction(Context context, Et scope, Et lambda)
 {
     return Et.Call(
         Et.Constant(context),
         MiCreateFunction,
         scope,
         lambda
     );
 }
예제 #5
0
		public NetServer( UserFunction callback, Context context ) {
			// have to set this stuff up. not sure why yet
			Context = context;
			Prototype = context.ObjectConstructor.Object_prototype;
			Class = ObjClass.Array;

			Console.WriteLine( "creating NetServer" );
			this.SetOwnProperty( "listen", new Action<object, string>( listen ) );
			this.addListener( "connection", callback );
		}