-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcommon.js
68 lines (68 loc) · 2.2 KB
/
common.js
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
var m = {};
// TODO common m.types should be a dict, array annoying
var def={};
argv=process.argv.forEach(function(v) {
var d=v.match(/-D(.+)/);
if(d) { def[d[1]]=1; }
});
m.types = [
// 0 type#
// 1 type code
// 2 english name
// 3 c type
// 4 var args type
// 5 formatter
// 6 has repr func in xxl.c
// 7 max
// 8 container?
[0,"l","list","VP","VP","%p",true,"0",true],
[1,"t","tag","tag_t","long long","%llld",true,"LONG_LONG_MAX",false],
[2,"c","char","char","int","%c",true,"SCHAR_MAX",false],
[3,"b","byte","int8_t","int","%d",false,"SCHAR_MAX",false],
[4,"i","int","int","int","%d",false,"INT_MAX",false],
[5,"j","long","__int64_t","int","%ld",false,"LONG_MAX",false],
(('OCTA' in def) ?
[6,"o","octa","__int128_t","int","%llld",true,"LONG_LONG_MAX",false] :
[6,"o","octa","__int64_t","int","%ld",true,"LONG_MAX",false]
)
,
[7,"f","float","double","double","%0.5f",false,"DBL_MAX",false],/* TODO custom printf for octowords */
[8,"d","dict","VP","VP","%p",true,"0",true],// a dict is a general list with two items [keys,vals]
[9,"a","table","VP","VP","%p",true,"0",true],// a table is a dict whose vectors happen to contain more than 1 value (usually)
[10,"1","f1","unaryFunc*","unaryFunc*","%p",false,"0",false],
[11,"2","f2","binaryFunc*","binaryFunc*","%p",false,"0",false],
[12,"p","proj","Proj","Proj","%p",true,"0",false],
[13,"x","ctx","VP","VP","%p",true,"0",true],// a context is a list [scope0,scope1,..scopen,[code]]
];
m.dontcast = ["l", "d", "a", "1", "2", "p", "x"]; // TODO should be flag on m.types
m.each = function each(a,f) {
var acc=[];for(var i in a) acc.push(f(a[i])); return acc;
}
m.eachr = function eachr(f,a) {
return function(b) {
var acc=[];
for(var i in a) {
acc.push(f(b,a[i]));
}
return acc;
}
}
m.exhaust = function exhaust(f,a) {
var last='';
while(1) {
a=f(a); if(a==last)return last; last=a;
}
}
m.prelude = '// Autogenerated file; see corresponding .js\n';
m.projl = function projl(f,a) {
return function(b) { return f(a,b); }
}
m.projr = function projr(f,a) {
return function(b) { return f(b,a); }
}
m.repl = function repl(str,v) {
//console.log('repl',str,v);
for(var j in v)
str=str.replace('{{'+j+'}}',v[j]); return str;
}
module.exports=m;