Repository: abs-lang/abs
Pull request #379 (2020-07-07 06:24:18)

fixed memoization bug, would use same map across functions


Patch:
diff --git a/VERSION b/VERSION
index ccbccc3..c043eea 100644
--- a/VERSION
+++ b/VERSION
@@ -1,1 +1,1 @@
-2.2.0
+2.2.1
diff --git a/evaluator/stdlib.go b/evaluator/stdlib.go
index f2f9f3c..6040388 100644
--- a/evaluator/stdlib.go
+++ b/evaluator/stdlib.go
@@ -43,7 +43,7 @@ func stdlib_runtime_index_abs() ([]byte, error) {
 	)
 }
 
-var _stdlib_util_index_abs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x74\x92\x4d\xcb\xdb\x30\x10\x84\xef\xfa\x15\x83\x73\xb1\xdb\xb7\xc2\x29\xf4\x12\xea\x9e\x7a\xec\x31\xd0\x43\x29\x41\x75\x56\x89\x40\x96\x82\xb4\x26\x25\xc1\xff\xbd\xc8\x1f\xc5\x1f\x79\x7d\x30\x68\xe7\xd9\xf5\xcc\x5a\x0d\x35\xfe\xd4\xa8\x1b\x2a\x3c\x3b\x21\x76\xf8\x4e\xb5\x0f\x8a\x7d\x00\x7b\x24\xd5\x3c\x48\xec\xc0\x57\x42\xa0\xd8\x5a\x86\xd7\x50\xd0\xad\xab\xd9\x78\x27\x85\x9e\xa8\x9c\xd9\x16\x78\x0a\x00\xd8\xe1\x27\xe1\xae\x1c\xa7\x29\x91\x7d\x20\xb0\x69\x28\x9d\xd2\xa4\xc6\x58\x6b\x22\xd5\xde\x9d\xdf\x46\x5e\x59\xeb\xef\xc6\x5d\xa0\x7d\xc0\xf1\xf8\x23\x26\xf6\x0f\xe1\x2b\xf6\x11\x39\x5d\x50\xca\xcf\x5f\xca\x42\xf6\x38\xb3\x45\xd5\xbf\x3f\x60\x5f\x96\xa5\xe8\xab\x81\xb8\x0d\x0e\x3a\xd7\x6e\xf2\xb1\x28\xcf\x8b\xe9\x89\x14\x8c\xb2\xe6\x41\xe7\x93\x0a\x97\x88\x0a\x52\x4a\x19\x39\xe4\xc5\x82\xab\x55\x7d\xa5\x33\x2a\x4c\xcb\xfa\xb5\xea\xfc\xbd\xc0\x9d\xbf\xa3\x42\xeb\xcc\xdf\x53\x13\xf3\x42\x2c\x44\xa3\xa7\x71\x4b\x2f\x0b\x4d\x72\xc4\xc7\x3e\xde\xa7\x7e\xda\x37\x94\x2f\xf0\x59\xb6\xb1\x6d\xf8\x41\x1b\xb0\x13\x9b\xd2\x94\x44\xde\xfc\x2d\x5f\xa5\x59\x86\x5f\x35\x07\x4a\x7b\xd2\x4e\xd6\xca\xda\x5c\x4a\xb9\xca\xf7\xee\x8a\xd2\x05\xdb\xd8\xc8\x38\x66\x87\x14\xf1\x6d\x2b\x0d\x61\xb2\x43\xfa\xe4\xca\xd1\xfc\x24\x5e\xac\x63\xde\x31\xd0\x9d\xe8\x84\x18\xd5\xc1\x46\x36\xde\xda\xec\xf0\xff\x96\x77\xff\x02\x00\x00\xff\xff\x7c\x7e\x69\xa8\x0d\x03\x00\x00")
+var _stdlib_util_index_abs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x74\x92\x4d\xcb\xdb\x30\x10\x84\xef\xfa\x15\x83\x73\xb1\xdb\xb7\xc2\x6f\xa1\x97\x50\xf7\xd4\x63\x8f\x81\x1e\x4a\x09\xaa\xb3\x4a\x04\xb2\x14\xa4\x35\x29\x09\xfe\xef\x45\xfe\x08\xfe\x48\x7d\x30\x68\xf6\xd9\xd5\x8c\xa4\x1d\xbe\x53\xed\x83\x62\x1f\xc0\x1e\x0d\x35\xde\xdc\x49\xec\xc0\x17\x42\xa0\xd8\x5a\x86\xd7\x50\xd0\xad\xab\xd9\x78\x27\x85\x9e\xa8\x9c\xd9\x16\x78\x08\x00\xd8\xe1\x27\xe1\xa6\x1c\xa7\x29\x91\x7d\x20\xb0\x69\x28\xad\xd2\xa4\xc6\x58\x6b\x22\xd5\xde\x9d\xde\x46\x5e\x59\xeb\x6f\xc6\x9d\xa1\x7d\xc0\xe1\xf0\x23\x26\xf6\x0f\xe1\x2b\xde\x23\x72\x3a\xa3\x94\x9f\xbf\x94\x85\xec\x71\x66\x8b\xaa\xff\x7f\xc0\x7b\x59\x96\xbd\x98\x6c\x1c\x1b\x75\x45\x85\x47\x27\x7a\x29\x10\xb7\xc1\x41\xe7\xda\x4d\xce\x16\xf2\x5c\x4c\x5f\xa4\x60\x94\x35\x77\x3a\x1d\x55\x38\x47\x54\x90\x52\xca\xc8\x21\x2f\x16\x5c\xad\xea\x0b\x9d\x50\x3d\xf7\xfc\xb5\xea\xfc\xbd\xc0\x9d\xbf\xa1\x42\xeb\xcc\xdf\x63\x13\xf3\x42\x2c\x8a\x46\x4f\xe3\x96\x5e\x16\x35\xc9\x11\x1f\xfb\xc0\x9f\xfa\x69\xdf\x50\xbe\xc0\x67\xd9\xc6\xb6\xe1\xca\x36\x60\x27\x36\xd2\x94\x44\x5e\xfd\x35\x5f\xa5\x59\x86\x5f\x35\x07\x4a\xe7\xa4\x9d\xac\x95\xb5\xb9\x94\x72\x95\xef\xbf\x47\x94\xee\x69\x63\x23\xe3\x98\xed\x53\xc4\xb7\x6d\x69\x08\x93\xed\xd3\x96\x2b\x47\xf3\x95\x78\x71\x1c\xf3\x8e\x81\xee\x44\x27\xc4\x58\x1d\x6c\x64\xe3\x3b\xce\xf6\xcf\x77\xdf\xfd\x0b\x00\x00\xff\xff\xfb\x0d\xf5\x0a\x10\x03\x00\x00")
 
 func stdlib_util_index_abs() ([]byte, error) {
 	return bindata_read(
diff --git a/stdlib/util/index.abs b/stdlib/util/index.abs
index ba9be02..3b46a03 100644
--- a/stdlib/util/index.abs
+++ b/stdlib/util/index.abs
@@ -1,11 +1,10 @@
-memo_map = {}
-
 # Decorator to memoize
 # the result of a function.
 f memoize(ttl) {
     # We want to store time to the millisecond,
     # allowing for TTLs to be < 1s (eg 0.250).
     ttl = ttl * 1000
+    memo_map = {}
 
     return f(fn) {
         return f() {


Test patch:
diff --git a/evaluator/stdlib_test.go b/evaluator/stdlib_test.go
index 778fd49..c758dab 100644
--- a/evaluator/stdlib_test.go
+++ b/evaluator/stdlib_test.go
@@ -24,9 +24,11 @@ func TestUtil(t *testing.T) {
 	tests := []tests{
 		{`memo = require('@util').memoize; @memo(1) f test() { return 1 }; test()`, 1},
 		{`memo = require('@util').memoize; @memo(1) f test(n) { return 1 + n }; test(10)`, 11},
+		{`memo = require('@util').memoize; @memo(1) f test(n, m) { return n + m }; test(10, 5)`, 15},
 		{`memo = require('@util').memoize; x = {"y": 0}; @memo(0) f test() { x.y += 1 }; test(); x.y`, 1},
 		{`memo = require('@util').memoize; x = {"y": 0}; @memo(0) f test() { x.y += 1 }; test(); test(); test(); x.y`, 3},
 		{`memo = require('@util').memoize; x = {"y": 0}; @memo(10) f test() { x.y += 1 }; test(); test(); test(); x.y`, 1},
+		{`memo = require('@util').memoize; x = {"y": 0}; @memo(10) f test() { x.y += 1 }; @memo(10) f test2() { x.y += 1 }; test(); test(); test2(); x.y`, 2},
 		{`memo = require('@util').memoize; x = {"y": 0}; @memo(0.250) f test() { x.y += 1 }; test(); test(); test(); x.y`, 1},
 		{`memo = require('@util').memoize; x = {"y": 0}; @memo(0.250) f test() { x.y += 1 }; test(); test(); sleep(251); test(); x.y`, 2},
 	}