Skip to content

Commit

Permalink
Switch to ECMAScript BigInt support
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Feb 16, 2019
1 parent 8a4f295 commit a97d60f
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 64 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "core-lib"]
path = core-lib
url = https://github.com/SOM-st/SOM.git
[submodule "libs/big-integer"]
path = libs/big-integer
url = https://github.com/smarr/BigInteger.js.git
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ core-lib/Smalltalk:
git submodules init
git submodules update

libs/big-integer/BigInteger.js:
git submodules init
git submodules update

clean:
@rm -Rf build
@rm -Rf src_gen
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ syntax tree interpreter. It isn't optimized or tuned for performance. However,
some aspects were easier to implement by doing node-replacement in a
self-optimizing interpreter style.

To clone the repository, please use the `--recursive` option to load all
To clone the repository, please use the `--recursive` option to load all
submodules:

$ git clone --recursive https://github.com/SOM-st/JsSOM.git
Expand All @@ -38,14 +38,13 @@ JsSOM's tests can be executed with:

$ make # note, it will download the Google Closure compiler
$ ./som.sh -cp Smalltalk TestSuite/TestHarness.som

A simple Hello World program is executed with:

$ ./som.sh -cp Smalltalk Examples/Hello.som

This code is distributed under the MIT License. Please see the LICENSE file for
details. JsSOM uses [BigInteger.js][big-int] to support arbitrary-length
integer operations. To build JsSOM, you'll further need PyYAML.
details. To build JsSOM, you'll further need PyYAML.

Build Status
------------
Expand Down
1 change: 0 additions & 1 deletion jsTestDriver.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load:
- libs/big-integer/BigInteger.js
- src_gen/core_lib.js
- src/lib/platform.js
- src/lib/assert.js
Expand Down
1 change: 0 additions & 1 deletion libs/big-integer
Submodule big-integer deleted from 4d0d1e
8 changes: 4 additions & 4 deletions src/som/compiler/Parser.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* Copyright (c) 2014 Stefan Marr, [email protected]
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -618,7 +618,7 @@ function Parser(fileContent, fileName) {
if (isInIntRange(i)) {
return createLiteralNode(universe.newInteger(i), source);
} else {
return createLiteralNode(universe.newBiginteger(bigInt(i)), source);
return createLiteralNode(universe.newBigInteger(BigInt(i)), source);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/som/primitives/IntegerPrimitives.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* Copyright (c) 2014 Stefan Marr, [email protected]
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -96,9 +96,9 @@ function IntegerPrimitives() {

var result = l << r;
if (Math.floor(l) != l || !isInIntRange(result) || !isInIntRange(l * Math.pow(2, r))) {
var big = bigInt(l);
big = big.multiply(Math.pow(2, r));
return universe.newBiginteger(big);
var big = BigInt(l);
big = big * BigInt(Math.pow(2, r));
return universe.newBigInteger(big);
}
return universe.newInteger(result);
}
Expand Down
10 changes: 5 additions & 5 deletions src/som/vm/Universe.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* Copyright (c) 2014 Stefan Marr, [email protected]
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -455,8 +455,8 @@ function Universe() {
return new SInteger(intVal);
};

this.newBiginteger = function (bigIntVal) {
return new SBigInteger(bigIntVal);
this.newBigInteger = function (BigIntVal) {
return new SBigInteger(BigIntVal);
};

this.newBlock = function (blockMethod, contextFrame) {
Expand Down
42 changes: 21 additions & 21 deletions src/som/vmobjects/SBigInteger.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* Copyright (c) 2014 Stefan Marr, [email protected]
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -35,9 +35,9 @@ function SBigInteger(bigintVal) {
if (right instanceof SDouble) {
result = bigintVal.toJSNumber() < right;
} else if (right instanceof SInteger) {
result = bigintVal.lesser(right.getEmbeddedInteger());
result = bigintVal < right.getEmbeddedInteger();
} else {
result = bigintVal.lesser(right.getEmbeddedBigInteger());
result = bigintVal < right.getEmbeddedBigInteger();
}
return (result) ? som.trueObject : som.falseObject;
};
Expand All @@ -48,36 +48,36 @@ function SBigInteger(bigintVal) {

this.primAdd = function (right) {
if (right instanceof SBigInteger) {
return universe.newBiginteger(right.getEmbeddedBigInteger().add(bigintVal));
return universe.newBigInteger(right.getEmbeddedBigInteger() + bigintVal);
} else if (right instanceof SDouble) {
return universe.newDouble(bigintVal.toJSNumber() + right.getEmbeddedDouble());
} else {
return universe.newBiginteger(bigintVal.add(right.getEmbeddedInteger()))
return universe.newBigInteger(bigintVal + right.getEmbeddedInteger())
}
};

this.primSubtract = function (right) {
var result;
if (right instanceof SBigInteger) {
result = bigintVal.subtract(right.getEmbeddedBigInteger());
result = bigintVal - right.getEmbeddedBigInteger();
} else if (right instanceof SDouble) {
return universe.newDouble(bigintVal.toJSNumber() - right.getEmbeddedDouble());
} else {
result = bigintVal.subtract(right.getEmbeddedInteger())
result = bigintVal - right.getEmbeddedInteger()
}
return universe.newBiginteger(result);
return universe.newBigInteger(result);
};

this.primMultiply = function (right) {
var result;
if (right instanceof SBigInteger) {
result = bigintVal.multiply(right.getEmbeddedBigInteger());
result = bigintVal * right.getEmbeddedBigInteger();
} else if (right instanceof SDouble) {
return universe.newDouble(bigintVal.toJSNumber() * right.getEmbeddedDouble());
} else {
result = bigintVal.multiply(right.getEmbeddedInteger())
result = bigintVal * right.getEmbeddedInteger()
}
return universe.newBiginteger(result);
return universe.newBigInteger(result);
};

this.primDoubleDiv = function (right) {
Expand All @@ -95,25 +95,25 @@ function SBigInteger(bigintVal) {
this.primIntDiv = function (right) {
var result;
if (right instanceof SBigInteger) {
result = bigintVal.divide(right.getEmbeddedBigInteger());
result = bigintVal / right.getEmbeddedBigInteger();
} else if (right instanceof SDouble) {
return universe.newDouble(bigintVal.toJSNumber()).primIntDiv(right);
} else {
result = bigintVal.divide(right.getEmbeddedInteger());
result = bigintVal / right.getEmbeddedInteger();
}
return universe.newBiginteger(result);
return universe.newBigInteger(result);
};

this.primModulo = function (right) {
var result;
if (right instanceof SBigInteger) {
result = bigintVal.mod(right.getEmbeddedBigInteger());
result = bigintVal % right.getEmbeddedBigInteger();
} else if (right instanceof SDouble) {
return universe.newDouble(bigintVal.toJSNumber()).primModulo(right);
} else {
result = bigintVal.mod(right.getEmbeddedInteger());
result = bigintVal % right.getEmbeddedInteger();
}
return universe.newBiginteger(result);
return universe.newBigInteger(result);
};

this.primAnd = function (right) {
Expand All @@ -123,11 +123,11 @@ function SBigInteger(bigintVal) {
this.primEquals = function (right) {
var result;
if (right instanceof SBigInteger) {
result = bigintVal.equals(right.getEmbeddedBigInteger());
result = bigintVal == right.getEmbeddedBigInteger();
} else if (right instanceof SDouble) {
result = bigintVal.toJSNumber() == right.getEmbeddedDouble();
} else if (right instanceof SInteger) {
result = bigintVal.equals(right.getEmbeddedInteger());
result = bigintVal == right.getEmbeddedInteger();
} else {
result = false;
}
Expand Down
30 changes: 15 additions & 15 deletions src/som/vmobjects/SInteger.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* Copyright (c) 2014 Stefan Marr, [email protected]
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -27,7 +27,7 @@ function intOrBigInt(val) {
if (isInIntRange(val)) {
return universe.newInteger(val | 0);
} else {
return universe.newBiginteger(bigInt(val));
return universe.newBigInteger(BigInt(val));
}
}

Expand All @@ -46,26 +46,26 @@ function SInteger(intVal) {
function toDouble() {
return universe.newDouble(intVal); // JS numbers are always doubles...
}

this.primLessThan = function (right) {
var result;
if (right instanceof SBigInteger) {
result = bigInt(intVal).lesser(right.getEmbeddedBigInteger());
result = BigInt(intVal).lesser(right.getEmbeddedBigInteger());
} else if (right instanceof SDouble) {
return toDouble.primLessThan(right);
} else {
result = intVal < right.getEmbeddedInteger();
}
return (result) ? som.trueObject : som.falseObject;
};

this.primAsString = function () {
return universe.newString(intVal.toString());
};

this.primAdd = function (right) {
if (right instanceof SBigInteger) {
return universe.newBiginteger(
return universe.newBigInteger(
right.getEmbeddedBigInteger().add(intVal));
} else if (right instanceof SDouble) {
return toDouble().primAdd(right);
Expand All @@ -77,7 +77,7 @@ function SInteger(intVal) {

this.primSubtract = function (right) {
if (right instanceof SBigInteger) {
return universe.newBiginteger(
return universe.newBigInteger(
right.getEmbeddedBigInteger().subtract(intVal));
} else if (right instanceof SDouble) {
return toDouble().primSubtract(right);
Expand All @@ -89,7 +89,7 @@ function SInteger(intVal) {

this.primMultiply = function (right) {
if (right instanceof SBigInteger) {
return universe.newBiginteger(
return universe.newBigInteger(
right.getEmbeddedBigInteger().multiply(intVal));
} else if (right instanceof SDouble) {
return toDouble().primMultiply(right);
Expand All @@ -113,8 +113,8 @@ function SInteger(intVal) {

this.primIntDiv = function (right) {
if (right instanceof SBigInteger) {
var result = bigInt(intVal).divide(right.getEmbeddedBigInteger());
return universe.newBiginteger(result);
var result = BigInt(intVal).divide(right.getEmbeddedBigInteger());
return universe.newBigInteger(result);
} else if (right instanceof SDouble) {
return toDouble(intVal).primIntDiv(right);
} else {
Expand All @@ -125,8 +125,8 @@ function SInteger(intVal) {

this.primModulo = function (right) {
if (right instanceof SBigInteger) {
var result = bigInt(intVal).mod(right.getEmbeddedBigInteger());
return universe.newBiginteger(result);
var result = BigInt(intVal).mod(right.getEmbeddedBigInteger());
return universe.newBigInteger(result);
} else if (right instanceof SDouble) {
return toDouble(intVal).primModulo(right);
} else {
Expand All @@ -149,7 +149,7 @@ function SInteger(intVal) {
this.primEquals = function (right) {
var result;
if (right instanceof SBigInteger) {
result = bigInt(intVal).equals(right.getEmbeddedBigInteger());
result = BigInt(intVal).equals(right.getEmbeddedBigInteger());
} else if (right instanceof SDouble) {
result = intVal == right.getEmbeddedDouble();
} else if (right instanceof SInteger) {
Expand Down

0 comments on commit a97d60f

Please sign in to comment.