Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        public static IWorker wrap(double value)
        {
            Client_Rational o = new Client_Rational(value);
            NObject obj = new NObject();
            WorkerBuilder builder = new WorkerBuilder(
            Bridge.stdn_Rat, obj, new IWorker[]{} );

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

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

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

            IWorker rv = builder.compile();
            rv.nativeObject = value;
            obj.rootWorker = rv;
            return rv;
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
0
        //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();
        }
Ejemplo n.º 6
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;
        }