public static IWorker wrap(IInterface face)
        {
            Client_Interface o = new Client_Interface(face);
            NObject obj = new NObject();
            WorkerBuilder builder = new WorkerBuilder(
            Bridge.stdn_Interface, obj, new IWorker[]{} );

            builder.addMethod(
            new Identifier("equals?"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Interface),
                        new Identifier("value"),
                        null )
                },
                new NType(Bridge.stdn_Interface),
                delegate(IScope args) {
                    return Bridge.toClientBoolean(
                        o.equals(
                            Bridge.toNativeInterface(
                                GE.evalIdent(args, "value"))));
                },
                null ));

            IWorker rv = builder.compile();
            rv.nativeObject = face;
            obj.rootWorker = rv;
            return rv;
        }
        public static IWorker wrap(IFunction func)
        {
            Client_Function o = new Client_Function(func);
            NObject obj = new NObject();
            WorkerBuilder builder = new WorkerBuilder(
            func.face, obj, new IWorker[]{} );

            builder.addCallee(func);

            builder.addPropertyGetter(
            new Identifier("parameterCount"),
            delegate(){ return Bridge.toClientInteger(o.parameterCount); });

            builder.addMethod(new Identifier("call"), func);

            IWorker rv = builder.compile();
            rv.nativeObject = func;
            obj.rootWorker = rv;
            return rv;
        }
 public static IWorker wrap(ISieve sieve)
 {
     IList<Property> props = new List<Property>();
     foreach( Identifier name in sieve.visibleScidentreNames )
     props.Add(new Property(name, false, new NType()));
     IInterface face = new Interface(
     new IInterface[]{},
     new Callee[]{},
     new Breeder[]{},
     props,
     new Method[]{});
     NObject o = new NObject();
     WorkerBuilder b = new WorkerBuilder(face, o, new IWorker[]{});
     foreach( Identifier name in sieve.visibleScidentreNames ) {
     //The same 'name' variable is used through each iteration.
     //If the delegate refers to 'name', it will always get the value that 'name' refered to last.
     Identifier name2 = name;
     b.addPropertyGetter( name, delegate() {
         return GE.evalIdent(sieve, name2);
     });
     }
     return b.compile();
 }
Esempio n. 4
0
        public IWorker compile()
        {
            //xxx is this the best place for this?
            //it would probably be best to replace this with more general
            //code that automatically creates workers for empty interfaces
            if( _childWorkers.Count == 0 && _face != Bridge.stdn_Object ) {
            WorkerBuilder builder = new WorkerBuilder(
                Bridge.stdn_Object, _owner, new IWorker[]{});
            _childWorkers = new List<IWorker>(_childWorkers);
            _childWorkers.Add(builder.compile());
            }

            return new Worker(this);
        }
        public static IWorker wrap(long value)
        {
            Client_Integer o = new Client_Integer(value);
            NObject obj = new NObject();
            WorkerBuilder builder = new WorkerBuilder(
            Bridge.stdn_Int, obj, new IWorker[]{});

            builder.addBreeder(
            Bridge.stdn_String,
            delegate(){ return Bridge.toClientString(value.ToString()); });

            builder.addMethod(
            new Identifier("add"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Int),
                        new Identifier("value"),
                        null )
                },
                new NType(Bridge.stdn_Int),
                delegate(IScope args) {
                    return Bridge.toClientInteger(
                            o.add(
                                Bridge.toNativeInteger(
                                    GE.evalIdent(args, "value"))));
                },
                null ));

            builder.addMethod(
            new Identifier("lessThan?"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Int),
                        new Identifier("value"),
                        null )
                },
                new NType(Bridge.stdn_Bool),
                delegate(IScope args) {
                    return Bridge.toClientBoolean(
                            o.lessThan(
                                Bridge.toNativeInteger(
                                    GE.evalIdent(args, "value"))));
                },
                null ));

            IWorker rv = builder.compile();
            rv.nativeObject = value;
            obj.rootWorker = rv;
            return rv;
        }
        //xxx automate wrapping
        public static IWorker wrap(INode_Expression body, IScope scope)
        {
            Client_Generator o = new Client_Generator(body, scope);
            IObject obj = new NObject();
            WorkerBuilder builder = new WorkerBuilder(
            Bridge.stdn_Generator, obj, new IWorker[]{} );

            builder.addMethod(
            new Identifier("yield"),
            new Function_Native(
                new ParameterImpl[]{},
                Bridge.stdn_Nullable_any,
                delegate(IScope args) {
                    return o.@yield();
                },
                null ));

            return builder.compile();
        }
Esempio n. 7
0
        //worker
        public static IWorker evaluate(Node_Worker node, IScope scope, IObject owner)
        {
            IList<IWorker> children = new List<IWorker>();
            foreach( Node_Worker child in node.childWorkers )
            children.Add(evaluate(child, scope, owner));

            WorkerBuilder builder = new WorkerBuilder(
            Bridge.toNativeInterface(Executor.executeAny(node.face, scope)),
            owner,
            children );
            foreach( Node_MemberImplementation nmi in node.memberImplementations ) {
            Node_MemberType type = nmi.memberType;
            if( type.value == MemberType.GETTER )
                builder.addPropertyGetter(
                    nmi.name.value, Executor.executeAny(nmi.function, scope));
            if( type.value == MemberType.SETTER )
                builder.addPropertySetter(
                    nmi.name.value,
                    Executor.executeAny(nmi.function, scope));
            }
            return builder.compile();
        }
Esempio n. 8
0
        public static IWorker wrap(IList<uint> codePoints)
        {
            Client_String o = new Client_String(codePoints);
            NObject obj = new NObject();
            WorkerBuilder builder = new WorkerBuilder(
            Bridge.stdn_String, obj, new IWorker[]{});

            builder.addBreeder(
            Bridge.stdn_String,
            delegate(){ return wrap(codePoints); });

            builder.addPropertyGetter(
            new Identifier("length"),
            delegate(){ return Bridge.toClientInteger(o.length); });

            builder.addMethod(
            new Identifier("concat"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_String),
                        new Identifier("value"),
                        null )
                },
                new NType(Bridge.stdn_String),
                delegate(IScope args) {
                    return wrap(
                        o.concat(
                            unwrap(
                                GE.evalIdent(args, "value"))));
                },
                null ));

            builder.addMethod(
            new Identifier("concat!"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_String),
                        new Identifier("value"),
                        null )
                },
                null,
                delegate(IScope args) {
                    o.concat0(
                        unwrap(
                            GE.evalIdent(args, "value")));
                    return wrap(o._codePoints);
                },
                null ));

            builder.addMethod(
            new Identifier("substring"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Int),
                        new Identifier("start"),
                        null )
                },
                new NType(Bridge.stdn_String),
                delegate(IScope args) {
                    return wrap(
                            o.substring(
                                Bridge.toNativeInteger(
                                    GE.evalIdent(args, "start"))));
                },
                null ));

            builder.addMethod(
            new Identifier("substring"),
            new Function_Native(
                new ParameterImpl[]{
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Int),
                        new Identifier("start"),
                        null ),
                    new ParameterImpl(
                        Direction.IN,
                        new NType(Bridge.stdn_Int),
                        new Identifier("limit"),
                        null )
                },
                new NType(Bridge.stdn_String),
                delegate(IScope args) {
                    return wrap(
                            o.substring(
                                Bridge.toNativeInteger(
                                    GE.evalIdent(args, "start")),
                                Bridge.toNativeInteger(
                                    GE.evalIdent(args, "limit"))));
                },
                null ));

            IWorker rv = builder.compile();
            rv.nativeObject = codePoints;
            obj.rootWorker = rv;
            return rv;
        }