trying to reduce size of code some more
This commit is contained in:
parent
bf9305d5c9
commit
a13274d63b
|
@ -52,21 +52,11 @@
|
|||
(assemble-binop-chain "plt.baselib.numbers.divide" checked-operands)]
|
||||
|
||||
[(add1)
|
||||
(string-append
|
||||
(format "(typeof(~a)==='number'&&(~a)<9E15?(~a)+1"
|
||||
(first operands) (first operands) (first operands))
|
||||
":"
|
||||
(format "RT.checkedAdd1(M, ~a)" (first operands))
|
||||
")")]
|
||||
|
||||
(format "RT.checkedAdd1(M, ~a)" (first operands))]
|
||||
|
||||
[(sub1)
|
||||
(string-append
|
||||
(format "(typeof(~a)==='number'&&(~a)>-9E15?(~a)-1"
|
||||
(first operands) (first operands) (first operands))
|
||||
":"
|
||||
(format "RT.checkedSub1(M, ~a)" (first operands))
|
||||
")")]
|
||||
(format "RT.checkedSub1(M, ~a)" (first operands))]
|
||||
|
||||
[(<)
|
||||
(assemble-boolean-chain "plt.baselib.numbers.lessThan" checked-operands)]
|
||||
|
||||
|
@ -88,13 +78,13 @@
|
|||
(second checked-operands))]
|
||||
|
||||
[(car)
|
||||
(format "(~a).first" (first checked-operands))]
|
||||
(format "RT.checkedCar(M, ~a)" (first operands))]
|
||||
|
||||
[(caar)
|
||||
(format "(~a).first.first" (first checked-operands))]
|
||||
|
||||
[(cdr)
|
||||
(format "(~a).rest" (first checked-operands))]
|
||||
(format "RT.checkedCdr(M, ~a)" (first operands))]
|
||||
|
||||
[(list)
|
||||
(let loop ([checked-operands checked-operands])
|
||||
|
|
|
@ -806,16 +806,28 @@
|
|||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
var checkedAdd1 = function(M, n) {
|
||||
if (typeof(n) === 'number' && n < 9e15) { return n+1; }
|
||||
return plt.baselib.numbers.add(
|
||||
testArgument(M, 'number', isNumber, n, 0, 'add1'),
|
||||
1);
|
||||
};
|
||||
|
||||
var checkedSub1 = function(M, n) {
|
||||
if (typeof(n) === 'number' && n > -9e15) { return n-1; }
|
||||
return plt.baselib.numbers.subtract(
|
||||
testArgument(M, 'number', isNumber, n, 0, 'add1'),
|
||||
1);
|
||||
};
|
||||
var checkedCar = function(M, v) {
|
||||
if (isPair(v)) { return v.first; }
|
||||
raiseArgumentTypeError(M, 'car', 'pair', 0, v);
|
||||
};
|
||||
|
||||
var checkedCdr = function(M, v) {
|
||||
if (isPair(v)) { return v.rest; }
|
||||
raiseArgumentTypeError(M, 'cdr', 'pair', 0, v);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -957,4 +969,6 @@
|
|||
|
||||
exports['checkedAdd1'] = checkedAdd1;
|
||||
exports['checkedSub1'] = checkedSub1;
|
||||
exports['checkedCar'] = checkedCar;
|
||||
exports['checkedCdr'] = checkedCdr;
|
||||
}(this.plt, this.plt.baselib));
|
Loading…
Reference in New Issue
Block a user