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(); }
//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(); }
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; }