From a97d60f6a355bc6077dfc1c380d3f9c82993cd8e Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Thu, 14 Feb 2019 01:23:30 +0000 Subject: [PATCH] Switch to ECMAScript BigInt support Signed-off-by: Stefan Marr --- .gitmodules | 3 -- Makefile | 4 --- README.md | 7 ++--- jsTestDriver.conf | 1 - libs/big-integer | 1 - src/som/compiler/Parser.js | 8 ++--- src/som/primitives/IntegerPrimitives.js | 12 +++---- src/som/vm/Universe.js | 10 +++--- src/som/vmobjects/SBigInteger.js | 42 ++++++++++++------------- src/som/vmobjects/SInteger.js | 30 +++++++++--------- 10 files changed, 54 insertions(+), 64 deletions(-) delete mode 160000 libs/big-integer diff --git a/.gitmodules b/.gitmodules index 0016603..480fc04 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Makefile b/Makefile index 911762c..9f9c8a0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 5d0db6b..86a8645 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ------------ diff --git a/jsTestDriver.conf b/jsTestDriver.conf index 8ec6037..8cf0f70 100644 --- a/jsTestDriver.conf +++ b/jsTestDriver.conf @@ -1,5 +1,4 @@ load: - - libs/big-integer/BigInteger.js - src_gen/core_lib.js - src/lib/platform.js - src/lib/assert.js diff --git a/libs/big-integer b/libs/big-integer deleted file mode 160000 index 4d0d1eb..0000000 --- a/libs/big-integer +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4d0d1eb689a5fc4e8a97eda7351ef60d180da172 diff --git a/src/som/compiler/Parser.js b/src/som/compiler/Parser.js index 49242b2..b0f56ba 100644 --- a/src/som/compiler/Parser.js +++ b/src/som/compiler/Parser.js @@ -1,16 +1,16 @@ /* * Copyright (c) 2014 Stefan Marr, mail@stefan-marr.de -* +* * 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 @@ -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); } } diff --git a/src/som/primitives/IntegerPrimitives.js b/src/som/primitives/IntegerPrimitives.js index 0618d17..ce6c670 100644 --- a/src/som/primitives/IntegerPrimitives.js +++ b/src/som/primitives/IntegerPrimitives.js @@ -1,16 +1,16 @@ /* * Copyright (c) 2014 Stefan Marr, mail@stefan-marr.de -* +* * 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 @@ -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); } diff --git a/src/som/vm/Universe.js b/src/som/vm/Universe.js index 3f5b851..ff4697c 100644 --- a/src/som/vm/Universe.js +++ b/src/som/vm/Universe.js @@ -1,16 +1,16 @@ /* * Copyright (c) 2014 Stefan Marr, mail@stefan-marr.de -* +* * 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 @@ -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) { diff --git a/src/som/vmobjects/SBigInteger.js b/src/som/vmobjects/SBigInteger.js index dd6b62d..f5db945 100644 --- a/src/som/vmobjects/SBigInteger.js +++ b/src/som/vmobjects/SBigInteger.js @@ -1,16 +1,16 @@ /* * Copyright (c) 2014 Stefan Marr, mail@stefan-marr.de -* +* * 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 @@ -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; }; @@ -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) { @@ -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) { @@ -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; } diff --git a/src/som/vmobjects/SInteger.js b/src/som/vmobjects/SInteger.js index 72b90af..6833f74 100644 --- a/src/som/vmobjects/SInteger.js +++ b/src/som/vmobjects/SInteger.js @@ -1,16 +1,16 @@ /* * Copyright (c) 2014 Stefan Marr, mail@stefan-marr.de -* +* * 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 @@ -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)); } } @@ -46,11 +46,11 @@ 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 { @@ -58,14 +58,14 @@ function SInteger(intVal) { } 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); @@ -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); @@ -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); @@ -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 { @@ -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 { @@ -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) {