goodguide-gibbon 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/goodguide/gibbon/version.rb +1 -1
- data/lib/goodguide/gibbon.rb +2 -0
- data/vendor/gibbon/lib/gibbon.browser.dev.js +106 -52
- data/vendor/gibbon/lib/gibbon.browser.js +106 -52
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ade669c4d8c8e8cf9dc4f03f5e383e9f0341d8d9
|
4
|
+
data.tar.gz: c385c96569b2f9301590e6052a1076c44f0f4e2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd0d2352b67e3ea169bee3951c0856893c5fd4383593939f047adf196803ccd6171dd52abc3e1d488d2f805cf3987d7772eb314a6226eaf9a0b393dff33cd8fa
|
7
|
+
data.tar.gz: e447692892c3cc072396c2d09cdab4159697f1797639c7f0a84a065528404f33a582a483f12502b93310d63b1f985236efa40f5ddbd8ae6b4b4cc035ff1e9467
|
data/lib/goodguide/gibbon.rb
CHANGED
@@ -936,10 +936,11 @@ Gibbon.ObjHash = ObjHash = (function(_super) {
|
|
936
936
|
};
|
937
937
|
|
938
938
|
ObjHash.prototype.set = function(k, v) {
|
939
|
-
|
939
|
+
this[k.hash()] = {
|
940
940
|
key: k,
|
941
941
|
value: v
|
942
942
|
};
|
943
|
+
return v;
|
943
944
|
};
|
944
945
|
|
945
946
|
ObjHash.prototype.has = function(k) {
|
@@ -2612,7 +2613,14 @@ Gibbon.Core = Core = (function(_super) {
|
|
2612
2613
|
|
2613
2614
|
Core.prototype.depair = function(key) {
|
2614
2615
|
if (key) {
|
2615
|
-
return
|
2616
|
+
return this.cases({
|
2617
|
+
pair: function() {
|
2618
|
+
return this[key];
|
2619
|
+
},
|
2620
|
+
other: function() {
|
2621
|
+
return Core.depair(this, key);
|
2622
|
+
}
|
2623
|
+
});
|
2616
2624
|
} else {
|
2617
2625
|
return [this.depair('first'), this.depair('second')];
|
2618
2626
|
}
|
@@ -2639,7 +2647,14 @@ Gibbon.Core = Core = (function(_super) {
|
|
2639
2647
|
};
|
2640
2648
|
|
2641
2649
|
Core.prototype.len = function() {
|
2642
|
-
return
|
2650
|
+
return this.cases({
|
2651
|
+
list: function(els) {
|
2652
|
+
return Core.constant(els.length);
|
2653
|
+
},
|
2654
|
+
other: function() {
|
2655
|
+
return Core.len(this);
|
2656
|
+
}
|
2657
|
+
});
|
2643
2658
|
};
|
2644
2659
|
|
2645
2660
|
Core.prototype.rescue = function(alt) {
|
@@ -2802,6 +2817,7 @@ Gibbon.Core = Core = (function(_super) {
|
|
2802
2817
|
},
|
2803
2818
|
delist: single,
|
2804
2819
|
depair: single,
|
2820
|
+
squishList: single,
|
2805
2821
|
list: function(e) {
|
2806
2822
|
return e;
|
2807
2823
|
},
|
@@ -3257,11 +3273,22 @@ Gibbon.translate = (function() {
|
|
3257
3273
|
})();
|
3258
3274
|
|
3259
3275
|
Gibbon.optimize = (function() {
|
3260
|
-
var insertBindings, partialEval;
|
3276
|
+
var insertBindings, partialEval, uncachedPartialEval;
|
3261
3277
|
partialEval = function(expr) {
|
3278
|
+
var cache, recurse, result;
|
3279
|
+
cache = new ObjHash;
|
3280
|
+
result = (recurse = function(expr) {
|
3281
|
+
return cache.cache(expr, function() {
|
3282
|
+
return uncachedPartialEval(expr, recurse);
|
3283
|
+
});
|
3284
|
+
})(expr);
|
3285
|
+
DEBUG.log("evaled to: " + (result.inspect()));
|
3286
|
+
return result;
|
3287
|
+
};
|
3288
|
+
uncachedPartialEval = function(expr, recurse) {
|
3262
3289
|
return expr.cases({
|
3263
3290
|
depair: function(expr, key) {
|
3264
|
-
return
|
3291
|
+
return recurse(expr).cases({
|
3265
3292
|
pair: function() {
|
3266
3293
|
DEBUG.log("inlining lookup " + key + " of " + (this.inspect()));
|
3267
3294
|
return this[key];
|
@@ -3272,7 +3299,7 @@ Gibbon.optimize = (function() {
|
|
3272
3299
|
});
|
3273
3300
|
},
|
3274
3301
|
delist: function(expr, index) {
|
3275
|
-
return
|
3302
|
+
return recurse(expr).cases({
|
3276
3303
|
list: function(els) {
|
3277
3304
|
DEBUG.log("inlining lookup " + index + " of " + (this.inspect()));
|
3278
3305
|
return els[index];
|
@@ -3284,10 +3311,10 @@ Gibbon.optimize = (function() {
|
|
3284
3311
|
},
|
3285
3312
|
branch: function(cond, ifTrue, ifFalse) {
|
3286
3313
|
var abort;
|
3287
|
-
cond =
|
3314
|
+
cond = recurse(cond);
|
3288
3315
|
abort = function() {
|
3289
|
-
ifTrue =
|
3290
|
-
ifFalse =
|
3316
|
+
ifTrue = recurse(ifTrue);
|
3317
|
+
ifFalse = recurse(ifFalse);
|
3291
3318
|
if (ifTrue.equals(ifFalse)) {
|
3292
3319
|
DEBUG.log("eliminating condition in equivalent branches: " + (this.inspect()));
|
3293
3320
|
return ifTrue;
|
@@ -3298,20 +3325,21 @@ Gibbon.optimize = (function() {
|
|
3298
3325
|
constant: function(value) {
|
3299
3326
|
if (value) {
|
3300
3327
|
DEBUG.log("eliminating dead false branch " + (ifFalse.inspect()));
|
3301
|
-
return
|
3328
|
+
return recurse(ifTrue);
|
3302
3329
|
} else {
|
3303
3330
|
DEBUG.log("eliminating dead true branch " + (ifTrue.inspect()));
|
3304
|
-
return
|
3331
|
+
return recurse(ifFalse);
|
3305
3332
|
}
|
3306
3333
|
},
|
3307
3334
|
branch: function(innerCond, innerTrue, innerFalse) {
|
3335
|
+
debugger;
|
3308
3336
|
DEBUG.log("flattening nested branch " + (this.inspect()));
|
3309
|
-
return
|
3337
|
+
return recurse(innerCond.branch(innerTrue.branch(ifTrue, ifFalse), innerFalse.branch(ifTrue, ifFalse)));
|
3310
3338
|
},
|
3311
3339
|
op1: function(name, arg) {
|
3312
3340
|
if (name === '!') {
|
3313
3341
|
DEBUG.log("eliminating if negation in condition " + (this.inspect()));
|
3314
|
-
return
|
3342
|
+
return recurse(arg.branch(ifFalse, ifTrue));
|
3315
3343
|
} else {
|
3316
3344
|
return abort();
|
3317
3345
|
}
|
@@ -3320,57 +3348,53 @@ Gibbon.optimize = (function() {
|
|
3320
3348
|
});
|
3321
3349
|
},
|
3322
3350
|
app: function(block, arg) {
|
3323
|
-
return
|
3351
|
+
return recurse(block).cases({
|
3324
3352
|
block: function(argName, body) {
|
3325
3353
|
DEBUG.log("inlining application of " + (this.inspect()) + " to " + (arg.inspect()));
|
3326
|
-
return
|
3354
|
+
return recurse(body.subst(argName, arg));
|
3327
3355
|
},
|
3328
3356
|
other: function() {
|
3329
|
-
return this.app(
|
3357
|
+
return this.app(recurse(arg));
|
3330
3358
|
}
|
3331
3359
|
});
|
3332
3360
|
},
|
3333
3361
|
mapList: function(list, arg, ixName, body) {
|
3334
|
-
return list.cases({
|
3362
|
+
return recurse(list).cases({
|
3335
3363
|
list: function(elements) {
|
3336
|
-
var el, i, mapped
|
3364
|
+
var el, i, mapped;
|
3337
3365
|
DEBUG.log("inlining MAP");
|
3338
|
-
for (i = _i = 0, _len = elements.length; _i < _len; i = ++_i) {
|
3339
|
-
el = elements[i];
|
3340
|
-
DEBUG.log(("subst " + arg + "=" + (el.inspect()) + " ") + ("" + ixName + "=" + i + " " + (body.inspect())));
|
3341
|
-
partialEval(body.subst(arg, el).subst(ixName, Core.constant(i)));
|
3342
|
-
}
|
3343
3366
|
mapped = (function() {
|
3344
|
-
var
|
3367
|
+
var _i, _len, _results;
|
3345
3368
|
_results = [];
|
3346
|
-
for (
|
3347
|
-
el = elements[
|
3348
|
-
|
3369
|
+
for (i = _i = 0, _len = elements.length; _i < _len; i = ++_i) {
|
3370
|
+
el = elements[i];
|
3371
|
+
DEBUG.log(("subst " + arg + "=" + (el.inspect()) + " ") + ("" + ixName + "=" + i + " " + (body.inspect())));
|
3372
|
+
_results.push(recurse(body.subst(arg, el).subst(ixName, Core.constant(i))));
|
3349
3373
|
}
|
3350
3374
|
return _results;
|
3351
3375
|
})();
|
3352
|
-
return
|
3376
|
+
return recurse(Core.list(mapped));
|
3353
3377
|
},
|
3354
3378
|
mapList: function(innerList, innerArg, innerIdxArg, innerBody) {
|
3355
3379
|
var newBody;
|
3356
3380
|
DEBUG.log("fusing MAP of " + (this.inspect()));
|
3357
3381
|
newBody = body.subst(arg, innerBody).subst(ixName, Core.variable(innerIdxArg));
|
3358
|
-
return Core.mapList(innerList, innerArg, innerIdxArg, newBody);
|
3382
|
+
return recurse(Core.mapList(innerList, innerArg, innerIdxArg, newBody));
|
3359
3383
|
},
|
3360
3384
|
other: function() {
|
3361
|
-
return Core.mapList(
|
3385
|
+
return Core.mapList(recurse(this), arg, ixName, recurse(body));
|
3362
3386
|
}
|
3363
3387
|
});
|
3364
3388
|
},
|
3365
3389
|
foldList: function(list, out, arg, accum, ixName, body) {
|
3366
|
-
return
|
3390
|
+
return recurse(list).cases({
|
3367
3391
|
list: function(elements) {
|
3368
3392
|
var _loop;
|
3369
3393
|
DEBUG.log("inlining FOLDR");
|
3370
|
-
return
|
3394
|
+
return recurse((_loop = function(i) {
|
3371
3395
|
var next;
|
3372
3396
|
if (i >= elements.length) {
|
3373
|
-
return
|
3397
|
+
return recurse(out);
|
3374
3398
|
}
|
3375
3399
|
next = _loop(i + 1);
|
3376
3400
|
DEBUG.log(("subst " + arg + "=" + (elements[i].inspect()) + " ") + ("" + accum + "=" + (next.inspect()) + " ") + ("" + ixName + "=i " + (body.inspect())));
|
@@ -3384,23 +3408,23 @@ Gibbon.optimize = (function() {
|
|
3384
3408
|
return Core.foldList(innerList, out, innerArg, accum, innerIdxArg, newBody);
|
3385
3409
|
},
|
3386
3410
|
other: function() {
|
3387
|
-
return Core.foldList(this,
|
3411
|
+
return Core.foldList(this, recurse(out), arg, accum, ixName, recurse(body));
|
3388
3412
|
}
|
3389
3413
|
});
|
3390
3414
|
},
|
3391
3415
|
len: function(list) {
|
3392
|
-
return
|
3416
|
+
return recurse(list).cases({
|
3393
3417
|
list: function(elements) {
|
3394
3418
|
DEBUG.log("optimizing out len from " + (this.inspect()));
|
3395
3419
|
return Core.constant(elements.length);
|
3396
3420
|
},
|
3397
3421
|
mapList: function(list) {
|
3398
3422
|
DEBUG.log("optimizing MAP out of len");
|
3399
|
-
return
|
3423
|
+
return recurse(list.len());
|
3400
3424
|
},
|
3401
3425
|
zipLists: function(l, r) {
|
3402
3426
|
DEBUG.log("optimizing ZIP out of len");
|
3403
|
-
return
|
3427
|
+
return recurse(l.len());
|
3404
3428
|
},
|
3405
3429
|
other: function() {
|
3406
3430
|
return this.len();
|
@@ -3409,8 +3433,8 @@ Gibbon.optimize = (function() {
|
|
3409
3433
|
},
|
3410
3434
|
zipLists: function(l, r) {
|
3411
3435
|
var e, elements, i;
|
3412
|
-
l =
|
3413
|
-
r =
|
3436
|
+
l = recurse(l);
|
3437
|
+
r = recurse(r);
|
3414
3438
|
if (!(l._tag === 'list' && r._tag === 'list')) {
|
3415
3439
|
return Core.zipLists(l, r);
|
3416
3440
|
}
|
@@ -3423,10 +3447,10 @@ Gibbon.optimize = (function() {
|
|
3423
3447
|
}
|
3424
3448
|
return _results;
|
3425
3449
|
})();
|
3426
|
-
return
|
3450
|
+
return recurse(Core.list(elements));
|
3427
3451
|
},
|
3428
3452
|
op1: function(op, arg) {
|
3429
|
-
return
|
3453
|
+
return recurse(arg).cases({
|
3430
3454
|
constant: function(value) {
|
3431
3455
|
return Core.constant(applyOp1(op, value));
|
3432
3456
|
},
|
@@ -3437,8 +3461,8 @@ Gibbon.optimize = (function() {
|
|
3437
3461
|
},
|
3438
3462
|
op2: function(op, left, right) {
|
3439
3463
|
var checkConst, checkIdent, identFold, l, r, _ref10;
|
3440
|
-
left =
|
3441
|
-
right =
|
3464
|
+
left = recurse(left);
|
3465
|
+
right = recurse(right);
|
3442
3466
|
checkConst = function(val, f) {
|
3443
3467
|
return val._tag === 'constant' && f(val.value);
|
3444
3468
|
};
|
@@ -3474,19 +3498,19 @@ Gibbon.optimize = (function() {
|
|
3474
3498
|
return Core.constant(applyOp2(op, left.value, right.value));
|
3475
3499
|
},
|
3476
3500
|
rescue: function(expr, default_) {
|
3477
|
-
expr =
|
3501
|
+
expr = recurse(expr);
|
3478
3502
|
if (expr.alwaysSucceeds()) {
|
3479
3503
|
DEBUG.log("eliminating dead default branch of " + (this.inspect()));
|
3480
3504
|
return expr;
|
3481
3505
|
} else if (expr.alwaysFails()) {
|
3482
3506
|
DEBUG.log("eliminating dead main branch of " + (this.inspect()));
|
3483
|
-
return
|
3507
|
+
return recurse(default_);
|
3484
3508
|
} else {
|
3485
|
-
return Core.rescue(expr,
|
3509
|
+
return Core.rescue(expr, recurse(default_));
|
3486
3510
|
}
|
3487
3511
|
},
|
3488
3512
|
other: function() {
|
3489
|
-
return this.map(
|
3513
|
+
return this.map(recurse);
|
3490
3514
|
}
|
3491
3515
|
});
|
3492
3516
|
};
|
@@ -3498,7 +3522,7 @@ Gibbon.optimize = (function() {
|
|
3498
3522
|
}).reverse();
|
3499
3523
|
};
|
3500
3524
|
genSubstitutions = function(expr) {
|
3501
|
-
var newTrace, occurrences, queue, sub, substitutions, trace, _i, _len, _ref10, _ref11;
|
3525
|
+
var newTrace, occurrences, queue, sub, substitutions, trace, _i, _len, _ref10, _ref11, _ref12;
|
3502
3526
|
occurrences = new ObjHash;
|
3503
3527
|
substitutions = new Hash;
|
3504
3528
|
queue = [[expr, List.empty()]];
|
@@ -3512,9 +3536,12 @@ Gibbon.optimize = (function() {
|
|
3512
3536
|
} else {
|
3513
3537
|
occurrences.set(expr, [makeCrumbs(trace)]);
|
3514
3538
|
newTrace = trace.cons(expr);
|
3515
|
-
_ref11 = expr.
|
3516
|
-
|
3517
|
-
|
3539
|
+
if ((_ref11 = expr._tag) === 'rescue' || _ref11 === 'squishList') {
|
3540
|
+
continue;
|
3541
|
+
}
|
3542
|
+
_ref12 = expr.subtrees();
|
3543
|
+
for (_i = 0, _len = _ref12.length; _i < _len; _i++) {
|
3544
|
+
sub = _ref12[_i];
|
3518
3545
|
queue.push([sub, newTrace]);
|
3519
3546
|
}
|
3520
3547
|
}
|
@@ -3583,7 +3610,20 @@ Gibbon.optimize = (function() {
|
|
3583
3610
|
return Core.variable(names[i]);
|
3584
3611
|
}
|
3585
3612
|
}
|
3586
|
-
return boundExpr.
|
3613
|
+
return boundExpr.cases({
|
3614
|
+
rescue: function(expr, default_) {
|
3615
|
+
return Core.rescue(insertBindings(expr), insertBindings(default_));
|
3616
|
+
},
|
3617
|
+
squishList: function(list) {
|
3618
|
+
if (list._tag !== 'list') {
|
3619
|
+
throw 'invalid squish';
|
3620
|
+
}
|
3621
|
+
return Core.squishList(list.map(insertBindings));
|
3622
|
+
},
|
3623
|
+
other: function() {
|
3624
|
+
return this.map(recurseInner);
|
3625
|
+
}
|
3626
|
+
});
|
3587
3627
|
})(expr);
|
3588
3628
|
for (i = _i = 0, _len = bindableExprs.length; _i < _len; i = ++_i) {
|
3589
3629
|
bindable = bindableExprs[i];
|
@@ -5571,6 +5611,20 @@ stdlib = Gibbon.stdlib = (function() {
|
|
5571
5611
|
});
|
5572
5612
|
}
|
5573
5613
|
},
|
5614
|
+
"bucket": {
|
5615
|
+
type: parse.type('bucket [numeric : %b] = numeric -> %b'),
|
5616
|
+
compile: function(input, _arg) {
|
5617
|
+
var default_, partitions;
|
5618
|
+
partitions = _arg[0];
|
5619
|
+
default_ = Core.fail('bucket: exceeded the last bucket');
|
5620
|
+
return partitions.foldList(default_, function(pair, next) {
|
5621
|
+
var boundary, result;
|
5622
|
+
boundary = pair.depair('first');
|
5623
|
+
result = pair.depair('second');
|
5624
|
+
return input.op2('<=', boundary).branch(result, next);
|
5625
|
+
});
|
5626
|
+
}
|
5627
|
+
},
|
5574
5628
|
"any-true?": {
|
5575
5629
|
type: parse.type('any-true? = [bool] -> bool'),
|
5576
5630
|
compile: function(list) {
|
@@ -926,10 +926,11 @@ Gibbon.ObjHash = ObjHash = (function(_super) {
|
|
926
926
|
};
|
927
927
|
|
928
928
|
ObjHash.prototype.set = function(k, v) {
|
929
|
-
|
929
|
+
this[k.hash()] = {
|
930
930
|
key: k,
|
931
931
|
value: v
|
932
932
|
};
|
933
|
+
return v;
|
933
934
|
};
|
934
935
|
|
935
936
|
ObjHash.prototype.has = function(k) {
|
@@ -2580,7 +2581,14 @@ Gibbon.Core = Core = (function(_super) {
|
|
2580
2581
|
|
2581
2582
|
Core.prototype.depair = function(key) {
|
2582
2583
|
if (key) {
|
2583
|
-
return
|
2584
|
+
return this.cases({
|
2585
|
+
pair: function() {
|
2586
|
+
return this[key];
|
2587
|
+
},
|
2588
|
+
other: function() {
|
2589
|
+
return Core.depair(this, key);
|
2590
|
+
}
|
2591
|
+
});
|
2584
2592
|
} else {
|
2585
2593
|
return [this.depair('first'), this.depair('second')];
|
2586
2594
|
}
|
@@ -2607,7 +2615,14 @@ Gibbon.Core = Core = (function(_super) {
|
|
2607
2615
|
};
|
2608
2616
|
|
2609
2617
|
Core.prototype.len = function() {
|
2610
|
-
return
|
2618
|
+
return this.cases({
|
2619
|
+
list: function(els) {
|
2620
|
+
return Core.constant(els.length);
|
2621
|
+
},
|
2622
|
+
other: function() {
|
2623
|
+
return Core.len(this);
|
2624
|
+
}
|
2625
|
+
});
|
2611
2626
|
};
|
2612
2627
|
|
2613
2628
|
Core.prototype.rescue = function(alt) {
|
@@ -2770,6 +2785,7 @@ Gibbon.Core = Core = (function(_super) {
|
|
2770
2785
|
},
|
2771
2786
|
delist: single,
|
2772
2787
|
depair: single,
|
2788
|
+
squishList: single,
|
2773
2789
|
list: function(e) {
|
2774
2790
|
return e;
|
2775
2791
|
},
|
@@ -3225,11 +3241,22 @@ Gibbon.translate = (function() {
|
|
3225
3241
|
})();
|
3226
3242
|
|
3227
3243
|
Gibbon.optimize = (function() {
|
3228
|
-
var insertBindings, partialEval;
|
3244
|
+
var insertBindings, partialEval, uncachedPartialEval;
|
3229
3245
|
partialEval = function(expr) {
|
3246
|
+
var cache, recurse, result;
|
3247
|
+
cache = new ObjHash;
|
3248
|
+
result = (recurse = function(expr) {
|
3249
|
+
return cache.cache(expr, function() {
|
3250
|
+
return uncachedPartialEval(expr, recurse);
|
3251
|
+
});
|
3252
|
+
})(expr);
|
3253
|
+
|
3254
|
+
return result;
|
3255
|
+
};
|
3256
|
+
uncachedPartialEval = function(expr, recurse) {
|
3230
3257
|
return expr.cases({
|
3231
3258
|
depair: function(expr, key) {
|
3232
|
-
return
|
3259
|
+
return recurse(expr).cases({
|
3233
3260
|
pair: function() {
|
3234
3261
|
|
3235
3262
|
return this[key];
|
@@ -3240,7 +3267,7 @@ Gibbon.optimize = (function() {
|
|
3240
3267
|
});
|
3241
3268
|
},
|
3242
3269
|
delist: function(expr, index) {
|
3243
|
-
return
|
3270
|
+
return recurse(expr).cases({
|
3244
3271
|
list: function(els) {
|
3245
3272
|
|
3246
3273
|
return els[index];
|
@@ -3252,10 +3279,10 @@ Gibbon.optimize = (function() {
|
|
3252
3279
|
},
|
3253
3280
|
branch: function(cond, ifTrue, ifFalse) {
|
3254
3281
|
var abort;
|
3255
|
-
cond =
|
3282
|
+
cond = recurse(cond);
|
3256
3283
|
abort = function() {
|
3257
|
-
ifTrue =
|
3258
|
-
ifFalse =
|
3284
|
+
ifTrue = recurse(ifTrue);
|
3285
|
+
ifFalse = recurse(ifFalse);
|
3259
3286
|
if (ifTrue.equals(ifFalse)) {
|
3260
3287
|
|
3261
3288
|
return ifTrue;
|
@@ -3266,20 +3293,21 @@ Gibbon.optimize = (function() {
|
|
3266
3293
|
constant: function(value) {
|
3267
3294
|
if (value) {
|
3268
3295
|
|
3269
|
-
return
|
3296
|
+
return recurse(ifTrue);
|
3270
3297
|
} else {
|
3271
3298
|
|
3272
|
-
return
|
3299
|
+
return recurse(ifFalse);
|
3273
3300
|
}
|
3274
3301
|
},
|
3275
3302
|
branch: function(innerCond, innerTrue, innerFalse) {
|
3303
|
+
debugger;
|
3276
3304
|
|
3277
|
-
return
|
3305
|
+
return recurse(innerCond.branch(innerTrue.branch(ifTrue, ifFalse), innerFalse.branch(ifTrue, ifFalse)));
|
3278
3306
|
},
|
3279
3307
|
op1: function(name, arg) {
|
3280
3308
|
if (name === '!') {
|
3281
3309
|
|
3282
|
-
return
|
3310
|
+
return recurse(arg.branch(ifFalse, ifTrue));
|
3283
3311
|
} else {
|
3284
3312
|
return abort();
|
3285
3313
|
}
|
@@ -3288,57 +3316,53 @@ Gibbon.optimize = (function() {
|
|
3288
3316
|
});
|
3289
3317
|
},
|
3290
3318
|
app: function(block, arg) {
|
3291
|
-
return
|
3319
|
+
return recurse(block).cases({
|
3292
3320
|
block: function(argName, body) {
|
3293
3321
|
|
3294
|
-
return
|
3322
|
+
return recurse(body.subst(argName, arg));
|
3295
3323
|
},
|
3296
3324
|
other: function() {
|
3297
|
-
return this.app(
|
3325
|
+
return this.app(recurse(arg));
|
3298
3326
|
}
|
3299
3327
|
});
|
3300
3328
|
},
|
3301
3329
|
mapList: function(list, arg, ixName, body) {
|
3302
|
-
return list.cases({
|
3330
|
+
return recurse(list).cases({
|
3303
3331
|
list: function(elements) {
|
3304
|
-
var el, i, mapped
|
3332
|
+
var el, i, mapped;
|
3305
3333
|
|
3306
|
-
for (i = _i = 0, _len = elements.length; _i < _len; i = ++_i) {
|
3307
|
-
el = elements[i];
|
3308
|
-
|
3309
|
-
partialEval(body.subst(arg, el).subst(ixName, Core.constant(i)));
|
3310
|
-
}
|
3311
3334
|
mapped = (function() {
|
3312
|
-
var
|
3335
|
+
var _i, _len, _results;
|
3313
3336
|
_results = [];
|
3314
|
-
for (
|
3315
|
-
el = elements[
|
3316
|
-
|
3337
|
+
for (i = _i = 0, _len = elements.length; _i < _len; i = ++_i) {
|
3338
|
+
el = elements[i];
|
3339
|
+
|
3340
|
+
_results.push(recurse(body.subst(arg, el).subst(ixName, Core.constant(i))));
|
3317
3341
|
}
|
3318
3342
|
return _results;
|
3319
3343
|
})();
|
3320
|
-
return
|
3344
|
+
return recurse(Core.list(mapped));
|
3321
3345
|
},
|
3322
3346
|
mapList: function(innerList, innerArg, innerIdxArg, innerBody) {
|
3323
3347
|
var newBody;
|
3324
3348
|
|
3325
3349
|
newBody = body.subst(arg, innerBody).subst(ixName, Core.variable(innerIdxArg));
|
3326
|
-
return Core.mapList(innerList, innerArg, innerIdxArg, newBody);
|
3350
|
+
return recurse(Core.mapList(innerList, innerArg, innerIdxArg, newBody));
|
3327
3351
|
},
|
3328
3352
|
other: function() {
|
3329
|
-
return Core.mapList(
|
3353
|
+
return Core.mapList(recurse(this), arg, ixName, recurse(body));
|
3330
3354
|
}
|
3331
3355
|
});
|
3332
3356
|
},
|
3333
3357
|
foldList: function(list, out, arg, accum, ixName, body) {
|
3334
|
-
return
|
3358
|
+
return recurse(list).cases({
|
3335
3359
|
list: function(elements) {
|
3336
3360
|
var _loop;
|
3337
3361
|
|
3338
|
-
return
|
3362
|
+
return recurse((_loop = function(i) {
|
3339
3363
|
var next;
|
3340
3364
|
if (i >= elements.length) {
|
3341
|
-
return
|
3365
|
+
return recurse(out);
|
3342
3366
|
}
|
3343
3367
|
next = _loop(i + 1);
|
3344
3368
|
|
@@ -3352,23 +3376,23 @@ Gibbon.optimize = (function() {
|
|
3352
3376
|
return Core.foldList(innerList, out, innerArg, accum, innerIdxArg, newBody);
|
3353
3377
|
},
|
3354
3378
|
other: function() {
|
3355
|
-
return Core.foldList(this,
|
3379
|
+
return Core.foldList(this, recurse(out), arg, accum, ixName, recurse(body));
|
3356
3380
|
}
|
3357
3381
|
});
|
3358
3382
|
},
|
3359
3383
|
len: function(list) {
|
3360
|
-
return
|
3384
|
+
return recurse(list).cases({
|
3361
3385
|
list: function(elements) {
|
3362
3386
|
|
3363
3387
|
return Core.constant(elements.length);
|
3364
3388
|
},
|
3365
3389
|
mapList: function(list) {
|
3366
3390
|
|
3367
|
-
return
|
3391
|
+
return recurse(list.len());
|
3368
3392
|
},
|
3369
3393
|
zipLists: function(l, r) {
|
3370
3394
|
|
3371
|
-
return
|
3395
|
+
return recurse(l.len());
|
3372
3396
|
},
|
3373
3397
|
other: function() {
|
3374
3398
|
return this.len();
|
@@ -3377,8 +3401,8 @@ Gibbon.optimize = (function() {
|
|
3377
3401
|
},
|
3378
3402
|
zipLists: function(l, r) {
|
3379
3403
|
var e, elements, i;
|
3380
|
-
l =
|
3381
|
-
r =
|
3404
|
+
l = recurse(l);
|
3405
|
+
r = recurse(r);
|
3382
3406
|
if (!(l._tag === 'list' && r._tag === 'list')) {
|
3383
3407
|
return Core.zipLists(l, r);
|
3384
3408
|
}
|
@@ -3391,10 +3415,10 @@ Gibbon.optimize = (function() {
|
|
3391
3415
|
}
|
3392
3416
|
return _results;
|
3393
3417
|
})();
|
3394
|
-
return
|
3418
|
+
return recurse(Core.list(elements));
|
3395
3419
|
},
|
3396
3420
|
op1: function(op, arg) {
|
3397
|
-
return
|
3421
|
+
return recurse(arg).cases({
|
3398
3422
|
constant: function(value) {
|
3399
3423
|
return Core.constant(applyOp1(op, value));
|
3400
3424
|
},
|
@@ -3405,8 +3429,8 @@ Gibbon.optimize = (function() {
|
|
3405
3429
|
},
|
3406
3430
|
op2: function(op, left, right) {
|
3407
3431
|
var checkConst, checkIdent, identFold, l, r, _ref10;
|
3408
|
-
left =
|
3409
|
-
right =
|
3432
|
+
left = recurse(left);
|
3433
|
+
right = recurse(right);
|
3410
3434
|
checkConst = function(val, f) {
|
3411
3435
|
return val._tag === 'constant' && f(val.value);
|
3412
3436
|
};
|
@@ -3442,19 +3466,19 @@ Gibbon.optimize = (function() {
|
|
3442
3466
|
return Core.constant(applyOp2(op, left.value, right.value));
|
3443
3467
|
},
|
3444
3468
|
rescue: function(expr, default_) {
|
3445
|
-
expr =
|
3469
|
+
expr = recurse(expr);
|
3446
3470
|
if (expr.alwaysSucceeds()) {
|
3447
3471
|
|
3448
3472
|
return expr;
|
3449
3473
|
} else if (expr.alwaysFails()) {
|
3450
3474
|
|
3451
|
-
return
|
3475
|
+
return recurse(default_);
|
3452
3476
|
} else {
|
3453
|
-
return Core.rescue(expr,
|
3477
|
+
return Core.rescue(expr, recurse(default_));
|
3454
3478
|
}
|
3455
3479
|
},
|
3456
3480
|
other: function() {
|
3457
|
-
return this.map(
|
3481
|
+
return this.map(recurse);
|
3458
3482
|
}
|
3459
3483
|
});
|
3460
3484
|
};
|
@@ -3466,7 +3490,7 @@ Gibbon.optimize = (function() {
|
|
3466
3490
|
}).reverse();
|
3467
3491
|
};
|
3468
3492
|
genSubstitutions = function(expr) {
|
3469
|
-
var newTrace, occurrences, queue, sub, substitutions, trace, _i, _len, _ref10, _ref11;
|
3493
|
+
var newTrace, occurrences, queue, sub, substitutions, trace, _i, _len, _ref10, _ref11, _ref12;
|
3470
3494
|
occurrences = new ObjHash;
|
3471
3495
|
substitutions = new Hash;
|
3472
3496
|
queue = [[expr, List.empty()]];
|
@@ -3480,9 +3504,12 @@ Gibbon.optimize = (function() {
|
|
3480
3504
|
} else {
|
3481
3505
|
occurrences.set(expr, [makeCrumbs(trace)]);
|
3482
3506
|
newTrace = trace.cons(expr);
|
3483
|
-
_ref11 = expr.
|
3484
|
-
|
3485
|
-
|
3507
|
+
if ((_ref11 = expr._tag) === 'rescue' || _ref11 === 'squishList') {
|
3508
|
+
continue;
|
3509
|
+
}
|
3510
|
+
_ref12 = expr.subtrees();
|
3511
|
+
for (_i = 0, _len = _ref12.length; _i < _len; _i++) {
|
3512
|
+
sub = _ref12[_i];
|
3486
3513
|
queue.push([sub, newTrace]);
|
3487
3514
|
}
|
3488
3515
|
}
|
@@ -3543,7 +3570,20 @@ Gibbon.optimize = (function() {
|
|
3543
3570
|
return Core.variable(names[i]);
|
3544
3571
|
}
|
3545
3572
|
}
|
3546
|
-
return boundExpr.
|
3573
|
+
return boundExpr.cases({
|
3574
|
+
rescue: function(expr, default_) {
|
3575
|
+
return Core.rescue(insertBindings(expr), insertBindings(default_));
|
3576
|
+
},
|
3577
|
+
squishList: function(list) {
|
3578
|
+
if (list._tag !== 'list') {
|
3579
|
+
throw 'invalid squish';
|
3580
|
+
}
|
3581
|
+
return Core.squishList(list.map(insertBindings));
|
3582
|
+
},
|
3583
|
+
other: function() {
|
3584
|
+
return this.map(recurseInner);
|
3585
|
+
}
|
3586
|
+
});
|
3547
3587
|
})(expr);
|
3548
3588
|
for (i = _i = 0, _len = bindableExprs.length; _i < _len; i = ++_i) {
|
3549
3589
|
bindable = bindableExprs[i];
|
@@ -5531,6 +5571,20 @@ stdlib = Gibbon.stdlib = (function() {
|
|
5531
5571
|
});
|
5532
5572
|
}
|
5533
5573
|
},
|
5574
|
+
"bucket": {
|
5575
|
+
type: parse.type('bucket [numeric : %b] = numeric -> %b'),
|
5576
|
+
compile: function(input, _arg) {
|
5577
|
+
var default_, partitions;
|
5578
|
+
partitions = _arg[0];
|
5579
|
+
default_ = Core.fail('bucket: exceeded the last bucket');
|
5580
|
+
return partitions.foldList(default_, function(pair, next) {
|
5581
|
+
var boundary, result;
|
5582
|
+
boundary = pair.depair('first');
|
5583
|
+
result = pair.depair('second');
|
5584
|
+
return input.op2('<=', boundary).branch(result, next);
|
5585
|
+
});
|
5586
|
+
}
|
5587
|
+
},
|
5534
5588
|
"any-true?": {
|
5535
5589
|
type: parse.type('any-true? = [bool] -> bool'),
|
5536
5590
|
compile: function(list) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goodguide-gibbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Adkisson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Run and analyze gibbon code from ruby or a browser (via a ruby app).
|
14
14
|
email:
|