goodguide-gibbon 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/goodguide/gibbon.rb +14 -8
- data/lib/goodguide/gibbon/version.rb +1 -1
- data/vendor/gibbon/lib/gibbon.browser.dev.js +738 -77
- data/vendor/gibbon/lib/gibbon.browser.js +737 -76
- data/vendor/gibbon/package.json +2 -1
- metadata +14 -9
@@ -121,6 +121,22 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
|
|
121
121
|
function success(stream, i, result) { return result; }
|
122
122
|
};
|
123
123
|
|
124
|
+
function furthestFailure(onFailure, myI, myExpected) {
|
125
|
+
return function(stream, yourI, yourExpected) {
|
126
|
+
if (myI > yourI) return onFailure(stream, myI, myExpected);
|
127
|
+
else return onFailure.apply(this, arguments);
|
128
|
+
};
|
129
|
+
}
|
130
|
+
|
131
|
+
function furthestFailureSuccess(onSuccess, myFurthestFailureI, myFurthestExpected) {
|
132
|
+
return function(stream, i, result, yourFurthestFailureI, yourFurthestExpected) {
|
133
|
+
if (myFurthestFailureI > yourFurthestFailureI) {
|
134
|
+
return onSuccess(stream, i, result, myFurthestFailureI, myFurthestExpected);
|
135
|
+
}
|
136
|
+
else return onSuccess.apply(this, arguments);
|
137
|
+
};
|
138
|
+
}
|
139
|
+
|
124
140
|
// -*- primitive combinators -*- //
|
125
141
|
_.or = function(alternative) {
|
126
142
|
var self = this;
|
@@ -128,8 +144,10 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
|
|
128
144
|
return Parser(function(stream, i, onSuccess, onFailure) {
|
129
145
|
return self._(stream, i, onSuccess, failure);
|
130
146
|
|
131
|
-
function failure(stream, newI) {
|
132
|
-
|
147
|
+
function failure(stream, newI, expected) {
|
148
|
+
var altSuccess = furthestFailureSuccess(onSuccess, newI, expected);
|
149
|
+
var altFailure = furthestFailure(onFailure, newI, expected);
|
150
|
+
return alternative._(stream, i, altSuccess, altFailure);
|
133
151
|
}
|
134
152
|
});
|
135
153
|
};
|
@@ -140,9 +158,11 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
|
|
140
158
|
return Parser(function(stream, i, onSuccess, onFailure) {
|
141
159
|
return self._(stream, i, success, onFailure);
|
142
160
|
|
143
|
-
function success(stream, newI, result) {
|
161
|
+
function success(stream, newI, result, furthestFailureI, furthestExpected) {
|
144
162
|
var nextParser = (next instanceof Parser ? next : next(result));
|
145
|
-
|
163
|
+
var nextSuccess = furthestFailureSuccess(onSuccess, furthestFailureI, furthestExpected);
|
164
|
+
var nextFailure = furthestFailure(onFailure, furthestFailureI, furthestExpected);
|
165
|
+
return nextParser._(stream, newI, nextSuccess, nextFailure);
|
146
166
|
}
|
147
167
|
});
|
148
168
|
};
|
@@ -167,15 +187,22 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
|
|
167
187
|
return Parser(function(stream, i, onSuccess, onFailure) {
|
168
188
|
var xs = [];
|
169
189
|
while (self._(stream, i, success, failure));
|
170
|
-
|
190
|
+
var furthestFailureI, furthestExpected;
|
191
|
+
return onSuccess(stream, i, xs, furthestFailureI, furthestExpected);
|
171
192
|
|
172
|
-
function success(stream, newI, x) {
|
193
|
+
function success(stream, newI, x, successFurthestFailureI, successFurthestExpected) {
|
173
194
|
i = newI;
|
174
195
|
xs.push(x);
|
196
|
+
furthestFailureI = successFurthestFailureI;
|
197
|
+
furthestExpected = successFurthestExpected;
|
175
198
|
return true;
|
176
199
|
}
|
177
200
|
|
178
|
-
function failure() {
|
201
|
+
function failure(stream, newI, expected) {
|
202
|
+
if (!(furthestFailureI > newI)) {
|
203
|
+
furthestFailureI = newI;
|
204
|
+
furthestExpected = expected;
|
205
|
+
}
|
179
206
|
return false;
|
180
207
|
}
|
181
208
|
});
|
@@ -208,32 +235,32 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
|
|
208
235
|
return Parser(function(stream, i, onSuccess, onFailure) {
|
209
236
|
var xs = [];
|
210
237
|
var result = true;
|
211
|
-
var
|
238
|
+
var furthestFailureI, furthestExpected;
|
212
239
|
|
213
240
|
for (var times = 0; times < min; times += 1) {
|
214
|
-
result = self._(stream, i, success,
|
215
|
-
if (!result) return onFailure(stream,
|
241
|
+
result = self._(stream, i, success, failure);
|
242
|
+
if (!result) return onFailure(stream, furthestFailureI, furthestExpected);
|
216
243
|
}
|
217
244
|
|
218
245
|
for (; times < max && result; times += 1) {
|
219
|
-
result = self._(stream, i, success,
|
246
|
+
result = self._(stream, i, success, failure);
|
220
247
|
}
|
221
248
|
|
222
|
-
return onSuccess(stream, i, xs);
|
249
|
+
return onSuccess(stream, i, xs, furthestFailureI, furthestExpected);
|
223
250
|
|
224
|
-
function success(stream, newI, x) {
|
225
|
-
xs.push(x);
|
251
|
+
function success(stream, newI, x, successFurthestFailureI, successFurthestExpected) {
|
226
252
|
i = newI;
|
253
|
+
xs.push(x);
|
254
|
+
furthestFailureI = successFurthestFailureI;
|
255
|
+
furthestExpected = successFurthestExpected;
|
227
256
|
return true;
|
228
257
|
}
|
229
258
|
|
230
|
-
function
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
function secondFailure(stream, newI, msg) {
|
259
|
+
function failure(stream, newI, expected) {
|
260
|
+
if (!(furthestFailureI > newI)) {
|
261
|
+
furthestFailureI = newI;
|
262
|
+
furthestExpected = expected;
|
263
|
+
}
|
237
264
|
return false;
|
238
265
|
}
|
239
266
|
});
|
@@ -268,7 +295,7 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
|
|
268
295
|
var head = stream.slice(i, i+len);
|
269
296
|
|
270
297
|
if (head === str) {
|
271
|
-
return onSuccess(stream, i+len, head);
|
298
|
+
return onSuccess(stream, i+len, head, -1);
|
272
299
|
}
|
273
300
|
else {
|
274
301
|
return onFailure(stream, i, expected);
|
@@ -286,7 +313,7 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
|
|
286
313
|
|
287
314
|
if (match) {
|
288
315
|
var result = match[0];
|
289
|
-
return onSuccess(stream, i+result.length, result);
|
316
|
+
return onSuccess(stream, i+result.length, result, -1);
|
290
317
|
}
|
291
318
|
else {
|
292
319
|
return onFailure(stream, i, expected);
|
@@ -316,17 +343,17 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
|
|
316
343
|
var any = Parsimmon.any = Parser(function(stream, i, onSuccess, onFailure) {
|
317
344
|
if (i >= stream.length) return onFailure(stream, i, 'any character');
|
318
345
|
|
319
|
-
return onSuccess(stream, i+1, stream.charAt(i));
|
346
|
+
return onSuccess(stream, i+1, stream.charAt(i), -1);
|
320
347
|
});
|
321
348
|
|
322
349
|
var all = Parsimmon.all = Parser(function(stream, i, onSuccess, onFailure) {
|
323
|
-
return onSuccess(stream, stream.length, stream.slice(i));
|
350
|
+
return onSuccess(stream, stream.length, stream.slice(i), -1);
|
324
351
|
});
|
325
352
|
|
326
353
|
var eof = Parsimmon.eof = Parser(function(stream, i, onSuccess, onFailure) {
|
327
354
|
if (i < stream.length) return onFailure(stream, i, 'EOF');
|
328
355
|
|
329
|
-
return onSuccess(stream, i, '');
|
356
|
+
return onSuccess(stream, i, '', -1);
|
330
357
|
});
|
331
358
|
});
|
332
359
|
return Parsimmon;
|
@@ -856,7 +883,7 @@ Gibbon.AST = AST = (function(_super) {
|
|
856
883
|
block: ['flow'],
|
857
884
|
list: ['elements', 'squish'],
|
858
885
|
defaulted: ['body', 'alternative'],
|
859
|
-
query: ['type', '
|
886
|
+
query: ['type', 'args'],
|
860
887
|
func: ['name', 'args'],
|
861
888
|
pair: ['first', 'second'],
|
862
889
|
flow: ['head', 'tail'],
|
@@ -891,11 +918,12 @@ Gibbon.AST = AST = (function(_super) {
|
|
891
918
|
string: function(s) {
|
892
919
|
return "'" + s + "'";
|
893
920
|
},
|
894
|
-
query: function(query,
|
921
|
+
query: function(query, args) {
|
895
922
|
if (query === 'access') {
|
896
|
-
|
923
|
+
return "@" + args[0];
|
924
|
+
} else {
|
925
|
+
return "." + query + " " + (args.join(' '));
|
897
926
|
}
|
898
|
-
return "@" + query + "(" + name + ")";
|
899
927
|
},
|
900
928
|
subst: function(flow) {
|
901
929
|
return "(" + (flow.inspect()) + ")";
|
@@ -1076,11 +1104,12 @@ parse = Gibbon.parse = (function() {
|
|
1076
1104
|
return AST.string(s);
|
1077
1105
|
});
|
1078
1106
|
accessorExpr = accessor.map(function(name) {
|
1079
|
-
|
1107
|
+
debugger;
|
1108
|
+
return AST.query('access', [name]);
|
1080
1109
|
});
|
1081
1110
|
queryExpr = query.then(function(q) {
|
1082
|
-
return name.map(function(
|
1083
|
-
return AST.query(q,
|
1111
|
+
return name.many().map(function(args) {
|
1112
|
+
return AST.query(q, args);
|
1084
1113
|
});
|
1085
1114
|
});
|
1086
1115
|
numericExpr = percentExpr.or(decimalExpr.or(fractionExpr.or(integerExpr)));
|
@@ -1375,7 +1404,7 @@ Gibbon.TypeExpr = TypeExpr = (function(_super) {
|
|
1375
1404
|
return "%" + name;
|
1376
1405
|
},
|
1377
1406
|
query: function(input, _, query) {
|
1378
|
-
return "
|
1407
|
+
return "" + (input.inspect()) + "[" + (query.inspect()) + "]";
|
1379
1408
|
},
|
1380
1409
|
destructure: function(constraint, name, argnum) {
|
1381
1410
|
return "" + (constraint.inspect()) + "/" + name + "[" + argnum + "]";
|
@@ -1605,7 +1634,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1605
1634
|
Scope.prototype.lookup = function(nativeId, query, cb) {
|
1606
1635
|
var lexical;
|
1607
1636
|
if (query.type === 'access' && nativeId === this.context.globalID) {
|
1608
|
-
lexical = this.lexicalLookup(query.
|
1637
|
+
lexical = this.lexicalLookup(query.args[0]);
|
1609
1638
|
if (lexical) {
|
1610
1639
|
return cb(lexical);
|
1611
1640
|
} else {
|
@@ -1714,7 +1743,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1714
1743
|
},
|
1715
1744
|
subst: function(subFlow) {
|
1716
1745
|
push(TypeExpr.expr(flow), TypeExpr.expr(subFlow));
|
1717
|
-
return _this.analyzeFlow(
|
1746
|
+
return _this.analyzeFlow(subFlow, global, push);
|
1718
1747
|
},
|
1719
1748
|
list: function(elements) {
|
1720
1749
|
var el, expected, rest, _i, _len, _results;
|
@@ -1930,6 +1959,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1930
1959
|
return Semantic.flow(flowType(this), toSemanticTree(head), tail && toSemanticTree(tail));
|
1931
1960
|
},
|
1932
1961
|
query: function(type, name) {
|
1962
|
+
var _this = this;
|
1933
1963
|
|
1934
1964
|
return semanticAccessors.get(this);
|
1935
1965
|
},
|
@@ -1951,6 +1981,9 @@ analyze = Gibbon.analyze = (function() {
|
|
1951
1981
|
block: function(flow) {
|
1952
1982
|
return Semantic.block(toSemanticTree(flow));
|
1953
1983
|
},
|
1984
|
+
subst: function(subFlow) {
|
1985
|
+
return toSemanticTree(subFlow);
|
1986
|
+
},
|
1954
1987
|
list: function(elements, squish) {
|
1955
1988
|
var e;
|
1956
1989
|
return Semantic.list((function() {
|
@@ -2104,9 +2137,10 @@ analyze = Gibbon.analyze = (function() {
|
|
2104
2137
|
|
2105
2138
|
return contMap(initialCrumbs, solveEntry, function() {
|
2106
2139
|
if (errors.length === 0) {
|
2107
|
-
|
2140
|
+
return finish(null, semantics);
|
2141
|
+
} else {
|
2142
|
+
return finish(errors);
|
2108
2143
|
}
|
2109
|
-
return finish(errors, semantics);
|
2110
2144
|
});
|
2111
2145
|
};
|
2112
2146
|
})();
|
@@ -2329,33 +2363,10 @@ Value = Gibbon.Value = Value = (function(_super) {
|
|
2329
2363
|
})(Union);
|
2330
2364
|
|
2331
2365
|
Promise = (function() {
|
2332
|
-
function Promise(
|
2333
|
-
this.
|
2366
|
+
function Promise(force) {
|
2367
|
+
this.force = force;
|
2334
2368
|
}
|
2335
2369
|
|
2336
|
-
Promise.prototype.force = function(failure, success) {
|
2337
|
-
var onFailure, onSuccess,
|
2338
|
-
_this = this;
|
2339
|
-
if (this.result === true) {
|
2340
|
-
return success(this.value, this.dependencies);
|
2341
|
-
}
|
2342
|
-
if (this.result === false) {
|
2343
|
-
return failure(this.value);
|
2344
|
-
}
|
2345
|
-
onSuccess = function(val, deps) {
|
2346
|
-
_this.result = true;
|
2347
|
-
_this.value = val;
|
2348
|
-
_this.dependencies = deps;
|
2349
|
-
return success(val, deps);
|
2350
|
-
};
|
2351
|
-
onFailure = function(fail) {
|
2352
|
-
_this.result = false;
|
2353
|
-
_this.value = fail;
|
2354
|
-
return failure(fail);
|
2355
|
-
};
|
2356
|
-
return this.fn.call(null, onFailure, onSuccess);
|
2357
|
-
};
|
2358
|
-
|
2359
2370
|
Promise.prototype.then = function(fn) {
|
2360
2371
|
var _this = this;
|
2361
2372
|
return new Promise(function(fail, cb) {
|
@@ -2716,15 +2727,486 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2716
2727
|
};
|
2717
2728
|
})();
|
2718
2729
|
// Generated by CoffeeScript 1.6.3
|
2730
|
+
var IR, _ref,
|
2731
|
+
__hasProp = {}.hasOwnProperty,
|
2732
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
2733
|
+
|
2734
|
+
Gibbon.IR = IR = (function(_super) {
|
2735
|
+
var nameGen;
|
2736
|
+
|
2737
|
+
__extends(IR, _super);
|
2738
|
+
|
2739
|
+
function IR() {
|
2740
|
+
_ref = IR.__super__.constructor.apply(this, arguments);
|
2741
|
+
return _ref;
|
2742
|
+
}
|
2743
|
+
|
2744
|
+
IR.types({
|
2745
|
+
global: [],
|
2746
|
+
constant: ['value'],
|
2747
|
+
variable: ['name'],
|
2748
|
+
branch: ['cond', 'ifTrue', 'ifFalse'],
|
2749
|
+
bind: ['name', 'value', 'expr'],
|
2750
|
+
delist: ['expr', 'index'],
|
2751
|
+
depair: ['expr', 'key'],
|
2752
|
+
list: ['elements'],
|
2753
|
+
foldList: ['list', 'out', 'arg', 'accumArg', 'idxArg', 'body'],
|
2754
|
+
mapList: ['list', 'arg', 'idxArg', 'body'],
|
2755
|
+
zipLists: ['first', 'second'],
|
2756
|
+
filterList: ['list', 'arg', 'body'],
|
2757
|
+
squishList: ['list'],
|
2758
|
+
len: ['list'],
|
2759
|
+
pair: ['first', 'second'],
|
2760
|
+
block: ['name', 'body'],
|
2761
|
+
app: ['block', 'arg'],
|
2762
|
+
query: ['expr', 'annotations'],
|
2763
|
+
localQuery: ['expr', 'key'],
|
2764
|
+
fail: ['message'],
|
2765
|
+
binop: ['op', 'lhs', 'rhs'],
|
2766
|
+
extern: ['name', 'value'],
|
2767
|
+
rescue: ['expr', 'default']
|
2768
|
+
});
|
2769
|
+
|
2770
|
+
IR.makeVariable = function(name) {
|
2771
|
+
return IR.variable(nameGen(name));
|
2772
|
+
};
|
2773
|
+
|
2774
|
+
IR.prototype.branch = function(ifTrue, ifFalse) {
|
2775
|
+
return IR.branch(this, ifTrue, ifFalse);
|
2776
|
+
};
|
2777
|
+
|
2778
|
+
IR.prototype.delist = function(index) {
|
2779
|
+
return IR.delist(this, index);
|
2780
|
+
};
|
2781
|
+
|
2782
|
+
IR.prototype.depair = function(key) {
|
2783
|
+
return IR.depair(this, key);
|
2784
|
+
};
|
2785
|
+
|
2786
|
+
IR.prototype.query = function(annotations) {
|
2787
|
+
return IR.query(this, annotations);
|
2788
|
+
};
|
2789
|
+
|
2790
|
+
IR.prototype.localQuery = function(key) {
|
2791
|
+
return IR.localQuery(this, key);
|
2792
|
+
};
|
2793
|
+
|
2794
|
+
IR.prototype.binop = function(op, other) {
|
2795
|
+
return IR.binop(op, this, other);
|
2796
|
+
};
|
2797
|
+
|
2798
|
+
IR.prototype.extern = function(name) {
|
2799
|
+
return IR.extern(name, this);
|
2800
|
+
};
|
2801
|
+
|
2802
|
+
IR.prototype.app = function(arg) {
|
2803
|
+
return IR.app(this, arg);
|
2804
|
+
};
|
2805
|
+
|
2806
|
+
IR.prototype.squish = function() {
|
2807
|
+
return IR.squishList(this);
|
2808
|
+
};
|
2809
|
+
|
2810
|
+
IR.prototype.len = function() {
|
2811
|
+
return IR.len(this);
|
2812
|
+
};
|
2813
|
+
|
2814
|
+
IR.prototype.seq = function(name, f) {
|
2815
|
+
name = nameGen(name);
|
2816
|
+
return IR.bind(name, this, f(IR.variable(name)));
|
2817
|
+
};
|
2818
|
+
|
2819
|
+
IR.prototype.mapList = function(f) {
|
2820
|
+
var elName, ixName;
|
2821
|
+
elName = nameGen('el');
|
2822
|
+
ixName = nameGen('i');
|
2823
|
+
return IR.mapList(this, elName, ixName, f(IR.variable(elName), IR.variable(ixName)));
|
2824
|
+
};
|
2825
|
+
|
2826
|
+
IR.prototype.foldList = function(init, f) {
|
2827
|
+
var accumName, body, elName, ixName;
|
2828
|
+
elName = nameGen('el');
|
2829
|
+
ixName = nameGen('i');
|
2830
|
+
accumName = nameGen('next');
|
2831
|
+
body = f(IR.variable(elName), IR.variable(accumName), IR.variable(ixName));
|
2832
|
+
return IR.foldList(this, init, elName, accumName, ixName, body);
|
2833
|
+
};
|
2834
|
+
|
2835
|
+
IR.prototype.zipList = function(other) {
|
2836
|
+
return IR.zipLists(this, other);
|
2837
|
+
};
|
2838
|
+
|
2839
|
+
IR.prototype.filterList = function(f) {
|
2840
|
+
var name;
|
2841
|
+
name = nameGen('el');
|
2842
|
+
return IR.filterList(this, name, f(IR.variable(name)));
|
2843
|
+
};
|
2844
|
+
|
2845
|
+
IR.prototype.subtrees = function() {
|
2846
|
+
var double, single;
|
2847
|
+
single = function(x) {
|
2848
|
+
return [x];
|
2849
|
+
};
|
2850
|
+
double = function(x, y) {
|
2851
|
+
return [x, y];
|
2852
|
+
};
|
2853
|
+
return this.cases({
|
2854
|
+
branch: function(c, t, f) {
|
2855
|
+
return [c, t, f];
|
2856
|
+
},
|
2857
|
+
bind: function(n, v, e) {
|
2858
|
+
return [v, e];
|
2859
|
+
},
|
2860
|
+
delist: single,
|
2861
|
+
depair: single,
|
2862
|
+
list: function(e) {
|
2863
|
+
return e;
|
2864
|
+
},
|
2865
|
+
foldList: function(l, o, a, aa, ia, b) {
|
2866
|
+
return [l, o, b];
|
2867
|
+
},
|
2868
|
+
mapList: function(l, a, ia, b) {
|
2869
|
+
return [l, b];
|
2870
|
+
},
|
2871
|
+
zipLists: double,
|
2872
|
+
len: single,
|
2873
|
+
pair: double,
|
2874
|
+
block: function(n, b) {
|
2875
|
+
return [b];
|
2876
|
+
},
|
2877
|
+
app: double,
|
2878
|
+
query: single,
|
2879
|
+
localQuery: single,
|
2880
|
+
binop: function(op, l, r) {
|
2881
|
+
return [l, r];
|
2882
|
+
},
|
2883
|
+
extern: function(n, v) {
|
2884
|
+
return [v];
|
2885
|
+
},
|
2886
|
+
rescue: double,
|
2887
|
+
other: function() {
|
2888
|
+
return [];
|
2889
|
+
}
|
2890
|
+
});
|
2891
|
+
};
|
2892
|
+
|
2893
|
+
IR.prototype.map = function(f) {
|
2894
|
+
return this.cases({
|
2895
|
+
branch: function(c, tr, fa) {
|
2896
|
+
return IR.branch(f(c), f(tr), f(fa));
|
2897
|
+
},
|
2898
|
+
bind: function(n, v, e) {
|
2899
|
+
return IR.bind(n, f(v), f(e));
|
2900
|
+
},
|
2901
|
+
delist: function(e, i) {
|
2902
|
+
return IR.delist(f(e), i);
|
2903
|
+
},
|
2904
|
+
depair: function(e, k) {
|
2905
|
+
return IR.depair(f(e), k);
|
2906
|
+
},
|
2907
|
+
list: function(els) {
|
2908
|
+
var e;
|
2909
|
+
return IR.list((function() {
|
2910
|
+
var _i, _len, _results;
|
2911
|
+
_results = [];
|
2912
|
+
for (_i = 0, _len = els.length; _i < _len; _i++) {
|
2913
|
+
e = els[_i];
|
2914
|
+
_results.push(f(e));
|
2915
|
+
}
|
2916
|
+
return _results;
|
2917
|
+
})());
|
2918
|
+
},
|
2919
|
+
foldList: function(l, o, a, i, aa, b) {
|
2920
|
+
return IR.foldList(f(l), f(o), a, i, aa, f(b));
|
2921
|
+
},
|
2922
|
+
mapList: function(l, a, i, b) {
|
2923
|
+
return IR.mapList(f(l), i, a, f(b));
|
2924
|
+
},
|
2925
|
+
zipLists: function(l, r) {
|
2926
|
+
return IR.zipLists(f(l), f(r));
|
2927
|
+
},
|
2928
|
+
len: function(l) {
|
2929
|
+
return IR.len(f(l));
|
2930
|
+
},
|
2931
|
+
pair: function(x, y) {
|
2932
|
+
return IR.pair(f(x), f(y));
|
2933
|
+
},
|
2934
|
+
block: function(n, b) {
|
2935
|
+
return IR.block(n, f(b));
|
2936
|
+
},
|
2937
|
+
app: function(b, a) {
|
2938
|
+
return IR.app(f(b), f(a));
|
2939
|
+
},
|
2940
|
+
query: function(e, a) {
|
2941
|
+
return IR.query(f(e), a);
|
2942
|
+
},
|
2943
|
+
localQuery: function(e, k) {
|
2944
|
+
return IR.localQuery(f(e), k);
|
2945
|
+
},
|
2946
|
+
binop: function(o, l, r) {
|
2947
|
+
return IR.binop(o, f(l), f(r));
|
2948
|
+
},
|
2949
|
+
extern: function(n, v) {
|
2950
|
+
return IR.extern(n, f(v));
|
2951
|
+
},
|
2952
|
+
other: function() {
|
2953
|
+
return this;
|
2954
|
+
}
|
2955
|
+
});
|
2956
|
+
};
|
2957
|
+
|
2958
|
+
IR.prototype.replace = function(expr, other) {
|
2959
|
+
if (this.equals(expr)) {
|
2960
|
+
return other;
|
2961
|
+
}
|
2962
|
+
return this.map(function(x) {
|
2963
|
+
return x.replace(expr, other);
|
2964
|
+
});
|
2965
|
+
};
|
2966
|
+
|
2967
|
+
IR.prototype.subst = function(varName, expr) {
|
2968
|
+
if (this._tag === 'variable' && this.name === varName) {
|
2969
|
+
return expr;
|
2970
|
+
}
|
2971
|
+
return this.map(function(x) {
|
2972
|
+
return x.subst(varName, expr);
|
2973
|
+
});
|
2974
|
+
};
|
2975
|
+
|
2976
|
+
IR.prototype.equals = function(other) {
|
2977
|
+
if (this._tag !== other._tag) {
|
2978
|
+
return false;
|
2979
|
+
}
|
2980
|
+
return this.cases({
|
2981
|
+
branch: function(cond, ifTrue, ifFalse) {
|
2982
|
+
return cond.equals(other.cond) && ifTrue.equals(other.ifTrue) && ifFalse.equals(other.ifFalse);
|
2983
|
+
},
|
2984
|
+
bind: function(name, val, expr) {
|
2985
|
+
if (!val.equals(other.value)) {
|
2986
|
+
return false;
|
2987
|
+
}
|
2988
|
+
return expr.equals(other.replace(IR.variable(other.name), IR.variable(name)));
|
2989
|
+
},
|
2990
|
+
variable: function(name) {
|
2991
|
+
return name === other.name;
|
2992
|
+
},
|
2993
|
+
delist: function(expr, index) {
|
2994
|
+
return expr.equals(other.expr) && index.equals(other.index);
|
2995
|
+
},
|
2996
|
+
depair: function(expr, key) {
|
2997
|
+
return expr.equals(other.expr) && key.equals(other.key);
|
2998
|
+
},
|
2999
|
+
list: function(els) {
|
3000
|
+
var el, i, _i, _len;
|
3001
|
+
for (i = _i = 0, _len = els.length; _i < _len; i = ++_i) {
|
3002
|
+
el = els[i];
|
3003
|
+
if (!el.equals(other.elements[i])) {
|
3004
|
+
return false;
|
3005
|
+
}
|
3006
|
+
}
|
3007
|
+
return true;
|
3008
|
+
},
|
3009
|
+
pair: function(x, y) {
|
3010
|
+
return x.equals(other.first) && y.equals(other.second);
|
3011
|
+
},
|
3012
|
+
query: function(expr, annotations) {
|
3013
|
+
return JSON.stringify(annotations) === JSON.stringify(other.annotations) && expr.equals(other.expr);
|
3014
|
+
},
|
3015
|
+
localQuery: function(expr, key) {
|
3016
|
+
return key === other.key && expr.equals(other.expr);
|
3017
|
+
}
|
3018
|
+
});
|
3019
|
+
};
|
3020
|
+
|
3021
|
+
nameGen = (function() {
|
3022
|
+
var count;
|
3023
|
+
count = 0;
|
3024
|
+
return function(name) {
|
3025
|
+
return "" + name + (count += 1);
|
3026
|
+
};
|
3027
|
+
})();
|
3028
|
+
|
3029
|
+
IR.prototype.inspect = function(indent) {
|
3030
|
+
if (indent == null) {
|
3031
|
+
indent = 0;
|
3032
|
+
}
|
3033
|
+
return this.cases({
|
3034
|
+
global: function() {
|
3035
|
+
return '$';
|
3036
|
+
},
|
3037
|
+
branch: function(cond, ifTrue, ifFalse) {
|
3038
|
+
return "(IF " + (cond.inspect()) + " " + (ifTrue.inspect()) + " " + (ifFalse.inspect()) + ")";
|
3039
|
+
},
|
3040
|
+
bind: function(name, val, expr) {
|
3041
|
+
return "(" + name + "=" + (val.inspect()) + " " + (expr.inspect()) + ")";
|
3042
|
+
},
|
3043
|
+
variable: function(name) {
|
3044
|
+
return name;
|
3045
|
+
},
|
3046
|
+
delist: function(e, i) {
|
3047
|
+
return "([" + i + "] " + (e.inspect()) + ")";
|
3048
|
+
},
|
3049
|
+
depair: function(e, k) {
|
3050
|
+
return "([" + k + "] " + (e.inspect()) + ")";
|
3051
|
+
},
|
3052
|
+
list: function(els) {
|
3053
|
+
var e;
|
3054
|
+
return "(LIST " + (((function() {
|
3055
|
+
var _i, _len, _results;
|
3056
|
+
_results = [];
|
3057
|
+
for (_i = 0, _len = els.length; _i < _len; _i++) {
|
3058
|
+
e = els[_i];
|
3059
|
+
_results.push(e.inspect());
|
3060
|
+
}
|
3061
|
+
return _results;
|
3062
|
+
})()).join(' ')) + ")";
|
3063
|
+
},
|
3064
|
+
len: function(e) {
|
3065
|
+
return "(LEN " + (e.inspect()) + ")";
|
3066
|
+
},
|
3067
|
+
mapList: function(list, arg, i, body) {
|
3068
|
+
return "(MAP " + (list.inspect()) + " " + arg + " " + i + " " + (body.inspect()) + ")";
|
3069
|
+
},
|
3070
|
+
foldList: function(list, out, arg, next, i, body) {
|
3071
|
+
return "(FOLDR " + (list.inspect()) + " " + (out.inspect()) + " " + arg + " " + next + " " + i + " " + (body.inspect()) + ")";
|
3072
|
+
},
|
3073
|
+
zipLists: function(x, y) {
|
3074
|
+
return "(ZIP " + (x.inspect()) + " " + (y.inspect()) + ")";
|
3075
|
+
},
|
3076
|
+
pair: function(x, y) {
|
3077
|
+
return "(PAIR " + (x.inspect()) + " " + (y.inspect()) + ")";
|
3078
|
+
},
|
3079
|
+
query: function(e, a) {
|
3080
|
+
return "(QUERY " + (JSON.stringify(a)) + " " + (e.inspect()) + ")";
|
3081
|
+
},
|
3082
|
+
block: function(a, e) {
|
3083
|
+
return "(LAMBDA " + a + " " + (e.inspect()) + ")";
|
3084
|
+
},
|
3085
|
+
app: function(b, a) {
|
3086
|
+
return "(APPLY " + (b.inspect()) + " " + (a.inspect()) + ")";
|
3087
|
+
},
|
3088
|
+
localQuery: function(k) {
|
3089
|
+
return "(@" + k + " " + (e.inspect()) + ")";
|
3090
|
+
},
|
3091
|
+
fail: function(m) {
|
3092
|
+
return "(FAIL " + m + ")";
|
3093
|
+
},
|
3094
|
+
binop: function(op, l, r) {
|
3095
|
+
return "(`" + op + "` " + (l.inspect()) + " " + (r.inspect()) + ")";
|
3096
|
+
},
|
3097
|
+
extern: function(name, val) {
|
3098
|
+
return "(`" + name + "` " + (val.inspect()) + ")";
|
3099
|
+
},
|
3100
|
+
rescue: function(e, d) {
|
3101
|
+
return "(RESCUE " + (e.inspect()) + " " + (d.inspect()) + ")";
|
3102
|
+
},
|
3103
|
+
constant: function(v) {
|
3104
|
+
return '' + v;
|
3105
|
+
}
|
3106
|
+
});
|
3107
|
+
};
|
3108
|
+
|
3109
|
+
return IR;
|
3110
|
+
|
3111
|
+
})(Union);
|
3112
|
+
|
3113
|
+
Gibbon.compile = (function() {
|
3114
|
+
var compile;
|
3115
|
+
compile = function(semantic, input, context) {
|
3116
|
+
if (input == null) {
|
3117
|
+
input = IR.global();
|
3118
|
+
}
|
3119
|
+
if (context == null) {
|
3120
|
+
context = input;
|
3121
|
+
}
|
3122
|
+
return semantic.cases({
|
3123
|
+
definition: function(_, flow) {
|
3124
|
+
return compile(flow, input, context);
|
3125
|
+
},
|
3126
|
+
flow: function(_, head, tail) {
|
3127
|
+
if (tail) {
|
3128
|
+
return compile(head, compile(tail, input, context), context);
|
3129
|
+
} else {
|
3130
|
+
return compile(head, input, context);
|
3131
|
+
}
|
3132
|
+
},
|
3133
|
+
query: function(annotations) {
|
3134
|
+
return input.query(annotations);
|
3135
|
+
},
|
3136
|
+
localAccessor: function(key) {
|
3137
|
+
return input.localQuery(key);
|
3138
|
+
},
|
3139
|
+
func: function(name, args) {
|
3140
|
+
var arg, argTypes, compArgs;
|
3141
|
+
compArgs = (function() {
|
3142
|
+
var _i, _len, _results;
|
3143
|
+
_results = [];
|
3144
|
+
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
3145
|
+
arg = args[_i];
|
3146
|
+
_results.push(compile(arg, context));
|
3147
|
+
}
|
3148
|
+
return _results;
|
3149
|
+
})();
|
3150
|
+
argTypes = (function() {
|
3151
|
+
var _i, _len, _results;
|
3152
|
+
_results = [];
|
3153
|
+
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
3154
|
+
arg = args[_i];
|
3155
|
+
_results.push(arg.type);
|
3156
|
+
}
|
3157
|
+
return _results;
|
3158
|
+
})();
|
3159
|
+
return stdlib[name].compile(input, compArgs, this.type, argTypes);
|
3160
|
+
},
|
3161
|
+
literal: function(syntax) {
|
3162
|
+
return IR.constant(syntax.value);
|
3163
|
+
},
|
3164
|
+
list: function(elements) {
|
3165
|
+
var e;
|
3166
|
+
return IR.list((function() {
|
3167
|
+
var _i, _len, _results;
|
3168
|
+
_results = [];
|
3169
|
+
for (_i = 0, _len = elements.length; _i < _len; _i++) {
|
3170
|
+
e = elements[_i];
|
3171
|
+
_results.push(compile(e, context));
|
3172
|
+
}
|
3173
|
+
return _results;
|
3174
|
+
})());
|
3175
|
+
},
|
3176
|
+
pair: function(x, y) {
|
3177
|
+
return IR.pair(compile(x, context), compile(y, context));
|
3178
|
+
},
|
3179
|
+
block: function(body) {
|
3180
|
+
var arg;
|
3181
|
+
arg = IR.makeVariable('arg');
|
3182
|
+
return IR.block(arg.name, compile(body, arg, arg));
|
3183
|
+
},
|
3184
|
+
defaulted: function(body, alternative) {
|
3185
|
+
return IR.rescue(compile(body, context), compile(alternative, context));
|
3186
|
+
}
|
3187
|
+
});
|
3188
|
+
};
|
3189
|
+
return function(semantics) {
|
3190
|
+
var out;
|
3191
|
+
out = new Hash;
|
3192
|
+
semantics.each(function(k, v) {
|
3193
|
+
return out.set(k, compile(v));
|
3194
|
+
});
|
3195
|
+
return out;
|
3196
|
+
};
|
3197
|
+
})();
|
3198
|
+
// Generated by CoffeeScript 1.6.3
|
2719
3199
|
var stdlib;
|
2720
3200
|
|
2721
3201
|
stdlib = Gibbon.stdlib = (function() {
|
2722
|
-
var allBooleans, anyBooleans, combine, iter, unit, vFalse, vTrue;
|
3202
|
+
var allBooleans, anyBooleans, combine, compEquals, iFalse, iTrue, iter, unit, vFalse, vTrue;
|
2723
3203
|
unit = Promise.unit;
|
2724
3204
|
iter = Promise.iter;
|
2725
3205
|
combine = Promise.combine;
|
2726
3206
|
vTrue = Value.boolean(true);
|
2727
3207
|
vFalse = Value.boolean(false);
|
3208
|
+
iTrue = IR.constant(true);
|
3209
|
+
iFalse = IR.constant(false);
|
2728
3210
|
anyBooleans = function(promises) {
|
2729
3211
|
var out, step;
|
2730
3212
|
step = function(cond, next) {
|
@@ -2753,6 +3235,35 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2753
3235
|
};
|
2754
3236
|
return iter(promises, step, out);
|
2755
3237
|
};
|
3238
|
+
compEquals = function(x, y, type) {
|
3239
|
+
var direct;
|
3240
|
+
direct = function() {
|
3241
|
+
return x.binop('===', y);
|
3242
|
+
};
|
3243
|
+
return type.cases({
|
3244
|
+
entity: direct,
|
3245
|
+
numeric: direct,
|
3246
|
+
string: direct,
|
3247
|
+
bool: direct,
|
3248
|
+
block: function() {
|
3249
|
+
return iFalse;
|
3250
|
+
},
|
3251
|
+
pair: function() {
|
3252
|
+
var eqx, eqy;
|
3253
|
+
eqx = compEquals(input.depair('first'), input.depair('second'), type.first);
|
3254
|
+
eqy = compEquals(input.depair('first'), input.depair('second'), type.first);
|
3255
|
+
return eqx.branch(eqy, iFalse);
|
3256
|
+
},
|
3257
|
+
list: function() {
|
3258
|
+
var eqEls, eqLength;
|
3259
|
+
eqLength = compEquals(x.len(), y.len(), Type.numeric());
|
3260
|
+
eqEls = x.zipList(y).foldList(iTrue, function(pair) {
|
3261
|
+
return compEquals(pair.depair('first'), pair.depair('second'), type.of);
|
3262
|
+
});
|
3263
|
+
return eqLength.branch(eqEls, iFalse);
|
3264
|
+
}
|
3265
|
+
});
|
3266
|
+
};
|
2756
3267
|
return {
|
2757
3268
|
"case": {
|
2758
3269
|
type: parse.type('case [bool : %b] = % -> %b'),
|
@@ -2773,6 +3284,13 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2773
3284
|
};
|
2774
3285
|
return iter(list.elements, step, out);
|
2775
3286
|
});
|
3287
|
+
},
|
3288
|
+
compile: function(_, _arg) {
|
3289
|
+
var alts;
|
3290
|
+
alts = _arg[0];
|
3291
|
+
return alts.foldList(IR.fail('non-exhaustive cases'), function(el, next) {
|
3292
|
+
return el.depair('first').branch(el.depair('second'), next);
|
3293
|
+
});
|
2776
3294
|
}
|
2777
3295
|
},
|
2778
3296
|
"case-eq": {
|
@@ -2798,12 +3316,36 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2798
3316
|
};
|
2799
3317
|
return iter(list.elements, step, out);
|
2800
3318
|
});
|
3319
|
+
},
|
3320
|
+
compile: function(input, _arg, _, _arg1) {
|
3321
|
+
var alts, argType, eqType;
|
3322
|
+
alts = _arg[0];
|
3323
|
+
argType = _arg1[0];
|
3324
|
+
eqType = argType.of.first;
|
3325
|
+
return alts.foldList(IR.fail('non-exhaustive cases'), function(el, next) {
|
3326
|
+
var first, second;
|
3327
|
+
first = el.depair('first');
|
3328
|
+
second = el.depair('second');
|
3329
|
+
return compEquals(input, first, eqType).branch(second, next);
|
3330
|
+
});
|
2801
3331
|
}
|
2802
3332
|
},
|
2803
3333
|
"case-eq-default": {
|
2804
3334
|
type: parse.type('case-eq-default %b [%a : %b] = %a -> %b'),
|
2805
3335
|
impl: function(evalInput, evalDefault, evalList) {
|
2806
3336
|
return stdlib['case-eq'].impl(evalInput, evalList).or(evalDefault);
|
3337
|
+
},
|
3338
|
+
compile: function(input, _arg, _, _arg1) {
|
3339
|
+
var alts, argType, default_, eqType;
|
3340
|
+
default_ = _arg[0], alts = _arg[1];
|
3341
|
+
argType = _arg1[0];
|
3342
|
+
eqType = argType.of.first;
|
3343
|
+
return alts.foldList(default_, function(el, next) {
|
3344
|
+
var first, second;
|
3345
|
+
first = el.depair('first');
|
3346
|
+
second = el.depair('second');
|
3347
|
+
return compEquals(input, first, eqType).branch(second, next);
|
3348
|
+
});
|
2807
3349
|
}
|
2808
3350
|
},
|
2809
3351
|
"any-true?": {
|
@@ -2812,6 +3354,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2812
3354
|
return evalList.then(function(list) {
|
2813
3355
|
return anyBooleans(list.elements);
|
2814
3356
|
});
|
3357
|
+
},
|
3358
|
+
compile: function(list) {
|
3359
|
+
return list.foldList(iFalse, function(el, next) {
|
3360
|
+
return el.branch(iTrue, next);
|
3361
|
+
});
|
2815
3362
|
}
|
2816
3363
|
},
|
2817
3364
|
"all-true?": {
|
@@ -2820,6 +3367,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2820
3367
|
return evalList.then(function(list) {
|
2821
3368
|
return allBooleans(list.elements);
|
2822
3369
|
});
|
3370
|
+
},
|
3371
|
+
compile: function(list) {
|
3372
|
+
return list.foldList(iTrue, function(el, next) {
|
3373
|
+
return el.branch(next, iFalse);
|
3374
|
+
});
|
2823
3375
|
}
|
2824
3376
|
},
|
2825
3377
|
"any?": {
|
@@ -2840,6 +3392,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2840
3392
|
return _results;
|
2841
3393
|
})());
|
2842
3394
|
});
|
3395
|
+
},
|
3396
|
+
compile: function(list, block) {
|
3397
|
+
return list.foldList(iFalse, function(el, next) {
|
3398
|
+
return block.app(el).branch(iTrue, next);
|
3399
|
+
});
|
2843
3400
|
}
|
2844
3401
|
},
|
2845
3402
|
"all?": {
|
@@ -2860,6 +3417,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2860
3417
|
return _results;
|
2861
3418
|
})());
|
2862
3419
|
});
|
3420
|
+
},
|
3421
|
+
compile: function(list, block) {
|
3422
|
+
return list.foldList(iTrue, function(el, next) {
|
3423
|
+
return block.app(el).branch(next, iFalse);
|
3424
|
+
});
|
2863
3425
|
}
|
2864
3426
|
},
|
2865
3427
|
"include?": {
|
@@ -2883,6 +3445,13 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2883
3445
|
})();
|
2884
3446
|
return anyBooleans(booleans);
|
2885
3447
|
});
|
3448
|
+
},
|
3449
|
+
compile: function(list, needle, _, _arg) {
|
3450
|
+
var listType;
|
3451
|
+
listType = _arg[0];
|
3452
|
+
return list.foldList(iFalse, function(el, next) {
|
3453
|
+
return compEquals(el, needle, listType.of).branch(iTrue, next);
|
3454
|
+
});
|
2886
3455
|
}
|
2887
3456
|
},
|
2888
3457
|
"empty?": {
|
@@ -2891,6 +3460,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2891
3460
|
return evalList.map(function(list) {
|
2892
3461
|
return Value.boolean(list.length === 0);
|
2893
3462
|
});
|
3463
|
+
},
|
3464
|
+
compile: function(list) {
|
3465
|
+
return list.foldList(iTrue, function() {
|
3466
|
+
return iFalse;
|
3467
|
+
});
|
2894
3468
|
}
|
2895
3469
|
},
|
2896
3470
|
weight: {
|
@@ -2925,6 +3499,18 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2925
3499
|
});
|
2926
3500
|
});
|
2927
3501
|
});
|
3502
|
+
},
|
3503
|
+
compile: function(_, weights) {
|
3504
|
+
var ratio;
|
3505
|
+
return ratio = weights.foldList(IR.pair(IR.constant(0), IR.constant(0)), function(el, next) {
|
3506
|
+
var denominator, numerator, value, weight, weighted;
|
3507
|
+
value = el.depair('first');
|
3508
|
+
weight = el.depair('second');
|
3509
|
+
numerator = next.depair('first');
|
3510
|
+
denominator = next.depair('second');
|
3511
|
+
weighted = value.binop('*', weight);
|
3512
|
+
return IR.pair(numerator.binop('+', weighted), denominator.binop('+', weight));
|
3513
|
+
});
|
2928
3514
|
}
|
2929
3515
|
},
|
2930
3516
|
filter: {
|
@@ -2957,6 +3543,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2957
3543
|
});
|
2958
3544
|
});
|
2959
3545
|
});
|
3546
|
+
},
|
3547
|
+
compile: function(input, block) {
|
3548
|
+
return input.filterList(function(el) {
|
3549
|
+
return block.app(el);
|
3550
|
+
});
|
2960
3551
|
}
|
2961
3552
|
},
|
2962
3553
|
scale: {
|
@@ -3003,6 +3594,13 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3003
3594
|
})());
|
3004
3595
|
});
|
3005
3596
|
});
|
3597
|
+
},
|
3598
|
+
compile: function(list, _arg) {
|
3599
|
+
var block;
|
3600
|
+
block = _arg[0];
|
3601
|
+
return list.mapList(function(el) {
|
3602
|
+
return block.app(el);
|
3603
|
+
});
|
3006
3604
|
}
|
3007
3605
|
},
|
3008
3606
|
count: {
|
@@ -3027,6 +3625,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3027
3625
|
return unit(Value.number(out));
|
3028
3626
|
});
|
3029
3627
|
});
|
3628
|
+
},
|
3629
|
+
compile: function(list) {
|
3630
|
+
return list.foldList(IR.constant(0), function(el, next) {
|
3631
|
+
return el.binop('+', next);
|
3632
|
+
});
|
3030
3633
|
}
|
3031
3634
|
},
|
3032
3635
|
"case-sum": {
|
@@ -3034,20 +3637,22 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3034
3637
|
impl: function(_, evalList) {
|
3035
3638
|
return evalList.then(function(list) {
|
3036
3639
|
return combine(list.elements).then(function(elements) {
|
3037
|
-
var
|
3640
|
+
var first, numbers, second;
|
3038
3641
|
numbers = (function() {
|
3039
|
-
var _i, _len, _results;
|
3642
|
+
var _i, _len, _ref, _results;
|
3040
3643
|
_results = [];
|
3041
3644
|
for (_i = 0, _len = elements.length; _i < _len; _i++) {
|
3042
|
-
|
3043
|
-
_results.push(
|
3044
|
-
|
3045
|
-
|
3046
|
-
|
3047
|
-
|
3048
|
-
return v
|
3645
|
+
_ref = elements[_i], first = _ref.first, second = _ref.second;
|
3646
|
+
_results.push((function(first, second) {
|
3647
|
+
return first.then(function(cond) {
|
3648
|
+
if (!cond.value) {
|
3649
|
+
return unit(0);
|
3650
|
+
}
|
3651
|
+
return second.map(function(v) {
|
3652
|
+
return v.value;
|
3653
|
+
});
|
3049
3654
|
});
|
3050
|
-
}));
|
3655
|
+
})(first, second));
|
3051
3656
|
}
|
3052
3657
|
return _results;
|
3053
3658
|
})();
|
@@ -3062,6 +3667,16 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3062
3667
|
});
|
3063
3668
|
});
|
3064
3669
|
});
|
3670
|
+
},
|
3671
|
+
compile: function(_, _arg) {
|
3672
|
+
var list;
|
3673
|
+
list = _arg[0];
|
3674
|
+
return list.foldList(IR.constant(0), function(el, next) {
|
3675
|
+
var cond, val;
|
3676
|
+
cond = el.depair('first');
|
3677
|
+
val = el.depair('second');
|
3678
|
+
return cond.branch(val.binop('+', next), next);
|
3679
|
+
});
|
3065
3680
|
}
|
3066
3681
|
},
|
3067
3682
|
first: {
|
@@ -3070,6 +3685,9 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3070
3685
|
return list.then(function(val) {
|
3071
3686
|
return val.elements[0];
|
3072
3687
|
});
|
3688
|
+
},
|
3689
|
+
compile: function(list) {
|
3690
|
+
return list.delist(0);
|
3073
3691
|
}
|
3074
3692
|
},
|
3075
3693
|
squish: {
|
@@ -3103,6 +3721,13 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3103
3721
|
})());
|
3104
3722
|
});
|
3105
3723
|
});
|
3724
|
+
},
|
3725
|
+
compile: function(list) {
|
3726
|
+
return list.filterList(function(el) {
|
3727
|
+
return IR.rescue(el.seq('v', function(_) {
|
3728
|
+
return iTrue;
|
3729
|
+
}), iFalse);
|
3730
|
+
});
|
3106
3731
|
}
|
3107
3732
|
},
|
3108
3733
|
add: {
|
@@ -3113,6 +3738,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3113
3738
|
lhs = _arg[0], rhs = _arg[1];
|
3114
3739
|
return Value.number(lhs.value + rhs.value);
|
3115
3740
|
});
|
3741
|
+
},
|
3742
|
+
compile: function(input, _arg) {
|
3743
|
+
var num;
|
3744
|
+
num = _arg[0];
|
3745
|
+
return input.binop('+', num);
|
3116
3746
|
}
|
3117
3747
|
},
|
3118
3748
|
sub: {
|
@@ -3123,18 +3753,29 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3123
3753
|
lhs = _arg[0], rhs = _arg[1];
|
3124
3754
|
return Value.number(lhs.value - rhs.value);
|
3125
3755
|
});
|
3756
|
+
},
|
3757
|
+
compile: function(input, _arg) {
|
3758
|
+
var num;
|
3759
|
+
num = _arg[0];
|
3760
|
+
return input.binop('+', num.extern('-'));
|
3126
3761
|
}
|
3127
3762
|
},
|
3128
3763
|
id: {
|
3129
3764
|
type: parse.type('id = %a -> %a'),
|
3130
3765
|
impl: function(x) {
|
3131
3766
|
return x;
|
3767
|
+
},
|
3768
|
+
compile: function(input) {
|
3769
|
+
return input;
|
3132
3770
|
}
|
3133
3771
|
},
|
3134
3772
|
"else": {
|
3135
3773
|
type: parse.type('else = % -> bool'),
|
3136
3774
|
impl: function(_) {
|
3137
3775
|
return unit(vTrue);
|
3776
|
+
},
|
3777
|
+
compile: function(_) {
|
3778
|
+
return iTrue;
|
3138
3779
|
}
|
3139
3780
|
},
|
3140
3781
|
not: {
|
@@ -3143,6 +3784,9 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3143
3784
|
return evalBool.map(function(bool) {
|
3144
3785
|
return Value.boolean(!bool.value);
|
3145
3786
|
});
|
3787
|
+
},
|
3788
|
+
compile: function(input) {
|
3789
|
+
return input.extern('!');
|
3146
3790
|
}
|
3147
3791
|
},
|
3148
3792
|
gt: {
|
@@ -3153,6 +3797,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3153
3797
|
lhs = _arg[0], rhs = _arg[1];
|
3154
3798
|
return Value.boolean(lhs.value > rhs.value);
|
3155
3799
|
});
|
3800
|
+
},
|
3801
|
+
compile: function(input, _arg) {
|
3802
|
+
var num;
|
3803
|
+
num = _arg[0];
|
3804
|
+
return input.binop('>', num);
|
3156
3805
|
}
|
3157
3806
|
},
|
3158
3807
|
lt: {
|
@@ -3163,6 +3812,11 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3163
3812
|
lhs = _arg[0], rhs = _arg[1];
|
3164
3813
|
return Value.boolean(lhs.value < rhs.value);
|
3165
3814
|
});
|
3815
|
+
},
|
3816
|
+
compile: function(input, _arg) {
|
3817
|
+
var num;
|
3818
|
+
num = _arg[0];
|
3819
|
+
return input.binop('<', num);
|
3166
3820
|
}
|
3167
3821
|
},
|
3168
3822
|
eq: {
|
@@ -3173,6 +3827,12 @@ stdlib = Gibbon.stdlib = (function() {
|
|
3173
3827
|
lhs = _arg[0], rhs = _arg[1];
|
3174
3828
|
return lhs.equals(rhs);
|
3175
3829
|
});
|
3830
|
+
},
|
3831
|
+
compile: function(input, _arg, _, _arg1) {
|
3832
|
+
var obj, objType;
|
3833
|
+
obj = _arg[0];
|
3834
|
+
objType = _arg1[0];
|
3835
|
+
return compEquals(input, obj, objType);
|
3176
3836
|
}
|
3177
3837
|
}
|
3178
3838
|
};
|
@@ -3232,11 +3892,12 @@ Gibbon.jsonConsumer = (function() {
|
|
3232
3892
|
};
|
3233
3893
|
return {
|
3234
3894
|
analyzeQuery: function(id, query, t, callback) {
|
3895
|
+
debugger;
|
3235
3896
|
switch (query.type) {
|
3236
3897
|
case 'access':
|
3237
|
-
return getType(id, query.
|
3898
|
+
return getType(id, query.args[0], t, callback);
|
3238
3899
|
case 'on':
|
3239
|
-
return analyzeList(id, query.
|
3900
|
+
return analyzeList(id, query.args[0], t, callback);
|
3240
3901
|
default:
|
3241
3902
|
return callback(new Error("unknown query `" + query.type + "'"));
|
3242
3903
|
}
|