load("standard_hats.js"); load("compiler.js"); Program.prototype.input_callback = null; Program.prototype.output_callback = null; Program.prototype.run = function(mainargs) { var standard_hats = make_standard_hats(); for (var h in standard_hats) { this.hats[h] = standard_hats[h]; this.ids[standard_hats[h].hatid] = standard_hats[h]; } this.hats['stdio'].input_callback = this.input_callback; this.hats['stdio'].output_callback = this.output_callback; var main = this.hats['main']; main.push(mainargs.length); while (main.suspended_contexts.length > 0) { if (mainargs.length > 0) main.push(mainargs.shift()); else throw 'not enough arguments passed to main'; } var results = []; try { while (1) results.push(main.pop()); } catch (e) { // ... } return results; } /* t = "hat fac: \n" t+= " in @->[[horn->@1]->pred]->[[if<-\\fac]<-\\nop]->[apply<-pred]->[mul<-@1]->@\n" t+= " out @->[horn->if]->[if<-1]->@\n" t+= "hat fib: \n" t+= " init 1->@<-1\n" t+= " out [@->@1]->[[[[horn->add]->@]<-@1]->@]->add->@\n" t+= "hat main:\n" t+= " in @<-fib" p = new Program(t); p.parse_thyself(); p.compile(); print(p.run([])); */