- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlambda.js
More file actions
Latest commit
executable file
·127 lines (108 loc) · 2.14 KB
/
Copy pathlambda.js
File metadata and controls
executable file
·127 lines (108 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env node
"use strict";
constlambda=require(".");
constyargs=require("yargs");
constfs=require("fs");
constpath=require("path");
consthelper=path.join(__dirname,"helper.txt");
constopts={
algo: {
alias: "a",
desc: "Select algorithm",
string: true
},
debug: {
alias: "d",
desc: "Evaluate step by step",
boolean: true
},
exec: {
alias: "e",
desc: "Process m4(1) macros",
boolean: true
},
file: {
alias: "f",
desc: "Read term from file",
boolean: true
},
inet: {
alias: "i",
desc: "Show interaction net",
boolean: true
},
limit: {
alias: "l",
desc: "Limit interactions",
number: true
},
macros: {
alias: "m",
desc: "Read macros from file",
string: true
},
perf: {
alias: "p",
desc: "Print benchmarks",
boolean: true
},
stats: {
alias: "s",
desc: "Save statistics to file",
string: true
},
term: {
alias: "t",
desc: "Output expanded term",
boolean: true
}
};
constargv=yargs
.usage("Usage: $0 [options] (<term> | -f <file>)")
.options(opts)
.demandCommand(1,1)
.help()
.alias("help","h")
.version()
.alias("version","v")
.strict()
.wrap(50)
.argv;
constmacros=argv.macros ? argv.macros : helper;
constcomb=fs.readFileSync(macros,"utf8");
letinput=argv._[0];
if(argv.file)
input=fs.readFileSync(input,"utf8");
input=comb.concat(input);
if(argv.exec){
constexec=require("child_process").execSync;
input=exec("m4",{
encoding: "utf8",
input: input
});
}
if(argv.debug){
leteqn;
lambda.prepare(input,argv.algo);
while(eqn=lambda.debug1())
console.info(eqn);
}elseif(argv.inet){
constinet=lambda.mlc2in(input,argv.algo);
process.stdout.write(inet);
}else{
constoutput=lambda(input,argv.algo,argv.limit);
conststats=JSON.stringify(output.stats,null,"\t");
consttotal=output.total;
constbeta=output.beta;
constredtime=output.redtime;
if(argv.term)
console.warn(output.term);
if(argv.perf)
console.warn(`${total}(${beta}), ${redtime} ms`);
if(argv.stats)
fs.writeFileSync(argv.stats,stats+"\n");
if(output.nf)
console.info(output.nf);
else
process.exit(1);
}