UNPKG

genish.js

Version:
53 lines (36 loc) 997 B
'use strict' let gen = require('./gen.js') const proto = { basename:'process', gen() { let out, inputs = gen.getInputs( this ) gen.closures.add({ [''+this.funcname] : this.func }) out = ` var ${this.name} = gen['${this.funcname}'](` inputs.forEach( (v,i,arr ) => { out += arr[ i ] if( i < arr.length - 1 ) out += ',' }) out += ')\n' gen.memo[ this.name ] = this.name return [this.name, out] return out } } module.exports = (...args) => { const process = {}// Object.create( proto ) const id = gen.getUID() process.name = 'process' + id process.func = new Function( ...args ) //gen.globals[ process.name ] = process.func process.call = function( ...args ) { const output = Object.create( proto ) output.funcname = process.name output.func = process.func output.name = 'process_out_' + id output.process = process output.inputs = args return output } return process }