mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-21 13:39:22 +01:00
feat(hog): start arrays from 1 (#23773)
This commit is contained in:
parent
2ca07dcfde
commit
e494d0e878
@ -1,21 +1,24 @@
|
||||
["_h", 43, 0, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 2, "print", 1, 35, 33, 1, 32, "2", 33, 3, 43, 3, 2,
|
||||
"print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 2, 33, 4, 43, 3, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2,
|
||||
33, 5, 43, 3, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 36, 0, 33, 1, 45, 2, "print", 1, 35, 36, 0, 33, 1, 48, 2,
|
||||
"print", 1, 35, 36, 0, 33, 1, 48, 2, "print", 1, 35, 36, 0, 33, 6, 48, 2, "print", 1, 35, 36, 0, 33, 6, 48, 2, "print",
|
||||
1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 33, 1, 45, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3,
|
||||
33, 1, 45, 33, 1, 45, 33, 1, 45, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 1, 48,
|
||||
33, 1, 48, 33, 1, 48, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 1, 48, 33, 1, 48,
|
||||
33, 1, 48, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 6, 48, 33, 3, 48, 33, 1, 48,
|
||||
2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 6, 48, 33, 3, 48, 33, 1, 48, 2, "print",
|
||||
1, 35, 33, 1, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 1, 45, 33, 1, 45, 33, 1, 45, 6, 2, "print", 1,
|
||||
35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 1, 45, 33, 1, 45, 33, 1, 45, 2, "print", 1, 35, 32,
|
||||
"------", 2, "print", 1, 35, 33, 4, 33, 1, 33, 2, 33, 3, 43, 3, 2, "arrayPushBack", 2, 2, "print", 1, 35, 33, 0, 33, 1,
|
||||
33, 2, 33, 3, 43, 3, 2, "arrayPushFront", 2, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 2, "arrayPopBack", 1, 2,
|
||||
"print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 2, "arrayPopFront", 1, 2, "print", 1, 35, 33, 3, 33, 2, 33, 1, 43, 3, 2,
|
||||
"arraySort", 1, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 2, "arrayReverse", 1, 2, "print", 1, 35, 33, 3, 33, 2,
|
||||
33, 1, 43, 3, 2, "arrayReverseSort", 1, 2, "print", 1, 35, 32, ",", 33, 1, 33, 2, 33, 3, 43, 3, 2, "arrayStringConcat",
|
||||
2, 2, "print", 1, 35, 32, "-----", 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 4, 36, 1, 2, "print", 1, 35, 33,
|
||||
5, 36, 1, 2, "arrayPushBack", 2, 35, 36, 1, 2, "print", 1, 35, 33, 0, 36, 1, 2, "arrayPushFront", 2, 35, 36, 1, 2,
|
||||
"print", 1, 35, 36, 1, 2, "arrayPopBack", 1, 35, 36, 1, 2, "print", 1, 35, 36, 1, 2, "arrayPopFront", 1, 35, 36, 1, 2,
|
||||
"print", 1, 35, 36, 1, 2, "arraySort", 1, 35, 36, 1, 2, "print", 1, 35, 36, 1, 2, "arrayReverse", 1, 35, 36, 1, 2,
|
||||
"print", 1, 35, 36, 1, 2, "arrayReverseSort", 1, 35, 36, 1, 2, "print", 1, 35, 35, 35]
|
||||
33, 5, 43, 3, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 36, 0, 33, 2, 45, 2, "print", 1, 35, 36, 0, 33, 2, 48, 2,
|
||||
"print", 1, 35, 36, 0, 33, 2, 48, 2, "print", 1, 35, 36, 0, 33, 7, 48, 2, "print", 1, 35, 36, 0, 33, 7, 48, 2, "print",
|
||||
1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 33, 2, 45, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3,
|
||||
33, 2, 45, 33, 2, 45, 33, 2, 45, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 2, 48,
|
||||
33, 2, 48, 33, 2, 48, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 2, 48, 33, 2, 48,
|
||||
33, 2, 48, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 7, 48, 33, 4, 48, 33, 2, 48,
|
||||
2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 7, 48, 33, 4, 48, 33, 2, 48, 2, "print",
|
||||
1, 35, 33, 1, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 2, 45, 33, 2, 45, 33, 2, 45, 6, 2, "print", 1,
|
||||
35, 33, 1, 33, 2, 33, 3, 33, 4, 43, 2, 43, 2, 33, 5, 43, 3, 33, 2, 45, 33, 2, 45, 33, 2, 45, 2, "print", 1, 35, 32,
|
||||
"------", 2, "print", 1, 35, 33, 1, 33, 2, 33, 1, 33, 2, 33, 3, 43, 3, 43, 3, 36, 1, 33, 2, 33, 4, 46, 36, 1, 33, 1, 45,
|
||||
2, "print", 1, 35, 36, 1, 33, 2, 45, 2, "print", 1, 35, 36, 1, 33, 3, 45, 2, "print", 1, 35, 36, 1, 33, 3, 45, 33, 3,
|
||||
33, 8, 46, 36, 1, 2, "print", 1, 35, 32, "------", 2, "print", 1, 35, 33, 4, 33, 1, 33, 2, 33, 3, 43, 3, 2,
|
||||
"arrayPushBack", 2, 2, "print", 1, 35, 33, 0, 33, 1, 33, 2, 33, 3, 43, 3, 2, "arrayPushFront", 2, 2, "print", 1, 35, 33,
|
||||
1, 33, 2, 33, 3, 43, 3, 2, "arrayPopBack", 1, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 2, "arrayPopFront", 1, 2,
|
||||
"print", 1, 35, 33, 3, 33, 2, 33, 1, 43, 3, 2, "arraySort", 1, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 2,
|
||||
"arrayReverse", 1, 2, "print", 1, 35, 33, 3, 33, 2, 33, 1, 43, 3, 2, "arrayReverseSort", 1, 2, "print", 1, 35, 32, ",",
|
||||
33, 1, 33, 2, 33, 3, 43, 3, 2, "arrayStringConcat", 2, 2, "print", 1, 35, 32, "-----", 2, "print", 1, 35, 33, 1, 33, 2,
|
||||
33, 3, 33, 4, 43, 4, 36, 2, 2, "print", 1, 35, 33, 5, 36, 2, 2, "arrayPushBack", 2, 35, 36, 2, 2, "print", 1, 35, 33, 0,
|
||||
36, 2, 2, "arrayPushFront", 2, 35, 36, 2, 2, "print", 1, 35, 36, 2, 2, "arrayPopBack", 1, 35, 36, 2, 2, "print", 1, 35,
|
||||
36, 2, 2, "arrayPopFront", 1, 35, 36, 2, 2, "print", 1, 35, 36, 2, 2, "arraySort", 1, 35, 36, 2, 2, "print", 1, 35, 36,
|
||||
2, 2, "arrayReverse", 1, 35, 36, 2, 2, "print", 1, 35, 36, 2, 2, "arrayReverseSort", 1, 35, 36, 2, 2, "print", 1, 35,
|
||||
35, 35, 35]
|
||||
|
@ -17,6 +17,11 @@ null
|
||||
5
|
||||
4
|
||||
------
|
||||
1
|
||||
4
|
||||
[1, 2, 3]
|
||||
[1, 4, [1, 2, 8]]
|
||||
------
|
||||
[1, 2, 3, 4]
|
||||
[0, 1, 2, 3]
|
||||
[1, 2]
|
||||
|
@ -3,20 +3,20 @@
|
||||
36, 0, 15, 40, 15, 36, 0, 2, "print", 1, 35, 33, 1, 36, 0, 6, 37, 0, 39, -22, 35, 32, "i", 1, 1, 2, "print", 1, 35, 32,
|
||||
"-- test emptier for loop --", 2, "print", 1, 35, 33, 0, 33, 3, 36, 0, 15, 40, 15, 32, "woo", 2, "print", 1, 35, 33, 1,
|
||||
36, 0, 6, 37, 0, 39, -22, 32, "hoo", 2, "print", 1, 35, 35, 32, "-- for in loop with arrays --", 2, "print", 1, 35, 33,
|
||||
1, 33, 2, 33, 3, 43, 3, 36, 0, 36, 1, 2, "values", 1, 33, 0, 36, 2, 2, "length", 1, 31, 36, 4, 36, 3, 15, 40, 22, 36, 2,
|
||||
1, 33, 2, 33, 3, 43, 3, 36, 0, 36, 1, 2, "values", 1, 33, 1, 36, 2, 2, "length", 1, 31, 36, 4, 36, 3, 16, 40, 22, 36, 2,
|
||||
36, 3, 45, 37, 5, 36, 5, 2, "print", 1, 35, 36, 3, 33, 1, 6, 37, 3, 39, -29, 35, 35, 35, 35, 35, 35, 32,
|
||||
"-- for in loop with arrays and keys --", 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 43, 3, 36, 0, 36, 1, 2, "keys", 1, 36,
|
||||
1, 2, "values", 1, 33, 0, 36, 3, 2, "length", 1, 31, 31, 36, 5, 36, 4, 15, 40, 31, 36, 2, 36, 4, 45, 37, 6, 36, 3, 36,
|
||||
1, 2, "values", 1, 33, 1, 36, 3, 2, "length", 1, 31, 31, 36, 5, 36, 4, 16, 40, 31, 36, 2, 36, 4, 45, 37, 6, 36, 3, 36,
|
||||
4, 45, 37, 7, 36, 7, 36, 6, 2, "print", 2, 35, 36, 4, 33, 1, 6, 37, 4, 39, -38, 35, 35, 35, 35, 35, 35, 35, 35, 32,
|
||||
"-- for in loop with tuples --", 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 3, 36, 0, 36, 1, 2, "values", 1, 33, 0, 36,
|
||||
2, 2, "length", 1, 31, 36, 4, 36, 3, 15, 40, 22, 36, 2, 36, 3, 45, 37, 5, 36, 5, 2, "print", 1, 35, 36, 3, 33, 1, 6, 37,
|
||||
"-- for in loop with tuples --", 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 3, 36, 0, 36, 1, 2, "values", 1, 33, 1, 36,
|
||||
2, 2, "length", 1, 31, 36, 4, 36, 3, 16, 40, 22, 36, 2, 36, 3, 45, 37, 5, 36, 5, 2, "print", 1, 35, 36, 3, 33, 1, 6, 37,
|
||||
3, 39, -29, 35, 35, 35, 35, 35, 35, 32, "-- for in loop with tuples and keys --", 2, "print", 1, 35, 33, 1, 33, 2, 33,
|
||||
3, 44, 3, 36, 0, 36, 1, 2, "keys", 1, 36, 1, 2, "values", 1, 33, 0, 36, 3, 2, "length", 1, 31, 31, 36, 5, 36, 4, 15, 40,
|
||||
3, 44, 3, 36, 0, 36, 1, 2, "keys", 1, 36, 1, 2, "values", 1, 33, 1, 36, 3, 2, "length", 1, 31, 31, 36, 5, 36, 4, 16, 40,
|
||||
31, 36, 2, 36, 4, 45, 37, 6, 36, 3, 36, 4, 45, 37, 7, 36, 7, 36, 6, 2, "print", 2, 35, 36, 4, 33, 1, 6, 37, 4, 39, -38,
|
||||
35, 35, 35, 35, 35, 35, 35, 35, 32, "-- for in loop with dicts --", 2, "print", 1, 35, 32, "first", 32, "v1", 32,
|
||||
"second", 32, "v2", 32, "third", 32, "v3", 42, 3, 36, 0, 36, 1, 2, "values", 1, 33, 0, 36, 2, 2, "length", 1, 31, 36, 4,
|
||||
36, 3, 15, 40, 22, 36, 2, 36, 3, 45, 37, 5, 36, 5, 2, "print", 1, 35, 36, 3, 33, 1, 6, 37, 3, 39, -29, 35, 35, 35, 35,
|
||||
"second", 32, "v2", 32, "third", 32, "v3", 42, 3, 36, 0, 36, 1, 2, "values", 1, 33, 1, 36, 2, 2, "length", 1, 31, 36, 4,
|
||||
36, 3, 16, 40, 22, 36, 2, 36, 3, 45, 37, 5, 36, 5, 2, "print", 1, 35, 36, 3, 33, 1, 6, 37, 3, 39, -29, 35, 35, 35, 35,
|
||||
35, 35, 32, "-- for in loop with dicts and keys --", 2, "print", 1, 35, 32, "first", 32, "v1", 32, "second", 32, "v2",
|
||||
32, "third", 32, "v3", 42, 3, 36, 0, 36, 1, 2, "keys", 1, 36, 1, 2, "values", 1, 33, 0, 36, 3, 2, "length", 1, 31, 31,
|
||||
36, 5, 36, 4, 15, 40, 31, 36, 2, 36, 4, 45, 37, 6, 36, 3, 36, 4, 45, 37, 7, 36, 7, 36, 6, 2, "print", 2, 35, 36, 4, 33,
|
||||
32, "third", 32, "v3", 42, 3, 36, 0, 36, 1, 2, "keys", 1, 36, 1, 2, "values", 1, 33, 1, 36, 3, 2, "length", 1, 31, 31,
|
||||
36, 5, 36, 4, 16, 40, 31, 36, 2, 36, 4, 45, 37, 6, 36, 3, 36, 4, 45, 37, 7, 36, 7, 36, 6, 2, "print", 2, 35, 36, 4, 33,
|
||||
1, 6, 37, 4, 39, -38, 35, 35, 35, 35, 35, 35, 35, 35]
|
||||
|
@ -1,17 +1,17 @@
|
||||
["_h", 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 6, 44, 4, 42, 1, 43, 3, 36, 0, 33, 2, 45, 32, "d", 45, 33, 1,
|
||||
45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 6, 44, 4, 42, 1, 43, 3, 36, 0, 33, 2, 45,
|
||||
32, "d", 45, 33, 2, 45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 6, 44, 4, 42, 1, 43, 3,
|
||||
36, 0, 33, 2, 45, 32, "d", 45, 33, 3, 45, 2, "print", 1, 35, 35, 32, "d", 33, 1, 33, 3, 33, 42, 33, 6, 44, 4, 42, 1, 36,
|
||||
0, 32, "d", 45, 33, 1, 45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43,
|
||||
3, 36, 0, 33, 2, 45, 32, "d", 45, 33, 2, 33, 3, 46, 36, 0, 33, 2, 45, 32, "d", 45, 33, 2, 45, 2, "print", 1, 35, 35, 33,
|
||||
1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43, 3, 36, 0, 33, 2, 45, 32, "d", 45, 33, 2, 33, 3, 46,
|
||||
36, 0, 33, 2, 45, 32, "d", 45, 33, 2, 45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43,
|
||||
4, 42, 1, 43, 3, 36, 0, 33, 2, 45, 32, "c", 33, 666, 43, 1, 46, 36, 0, 33, 2, 45, 2, "print", 1, 35, 35, 33, 1, 33, 2,
|
||||
32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43, 3, 36, 0, 33, 2, 45, 32, "d", 45, 33, 2, 33, 3, 46, 36, 0, 33,
|
||||
2, 45, 32, "d", 45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43, 3, 36,
|
||||
0, 33, 2, 45, 32, "d", 32, "a", 32, "b", 32, "c", 32, "d", 43, 4, 46, 36, 0, 33, 2, 45, 32, "d", 45, 33, 2, 45, 2,
|
||||
"print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43, 3, 32, "d", 36, 0, 33, 2, 45,
|
||||
36, 1, 32, "a", 32, "b", 32, "c", 32, "d", 43, 4, 46, 36, 0, 33, 2, 45, 32, "d", 45, 33, 2, 45, 2, "print", 1, 35, 35,
|
||||
["_h", 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 6, 44, 4, 42, 1, 43, 3, 36, 0, 33, 3, 45, 32, "d", 45, 33, 2,
|
||||
45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 6, 44, 4, 42, 1, 43, 3, 36, 0, 33, 3, 45,
|
||||
32, "d", 45, 33, 3, 45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 6, 44, 4, 42, 1, 43, 3,
|
||||
36, 0, 33, 3, 45, 32, "d", 45, 33, 4, 45, 2, "print", 1, 35, 35, 32, "d", 33, 1, 33, 3, 33, 42, 33, 6, 44, 4, 42, 1, 36,
|
||||
0, 32, "d", 45, 33, 2, 45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43,
|
||||
3, 36, 0, 33, 3, 45, 32, "d", 45, 33, 3, 33, 3, 46, 36, 0, 33, 3, 45, 32, "d", 45, 33, 3, 45, 2, "print", 1, 35, 35, 33,
|
||||
1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43, 3, 36, 0, 33, 3, 45, 32, "d", 45, 33, 3, 33, 3, 46,
|
||||
36, 0, 33, 3, 45, 32, "d", 45, 33, 3, 45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43,
|
||||
4, 42, 1, 43, 3, 36, 0, 33, 3, 45, 32, "c", 33, 666, 43, 1, 46, 36, 0, 33, 3, 45, 2, "print", 1, 35, 35, 33, 1, 33, 2,
|
||||
32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43, 3, 36, 0, 33, 3, 45, 32, "d", 45, 33, 3, 33, 3, 46, 36, 0, 33,
|
||||
3, 45, 32, "d", 45, 2, "print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43, 3, 36,
|
||||
0, 33, 3, 45, 32, "d", 32, "a", 32, "b", 32, "c", 32, "d", 43, 4, 46, 36, 0, 33, 3, 45, 32, "d", 45, 33, 3, 45, 2,
|
||||
"print", 1, 35, 35, 33, 1, 33, 2, 32, "d", 33, 1, 33, 3, 33, 42, 33, 3, 43, 4, 42, 1, 43, 3, 32, "d", 36, 0, 33, 3, 45,
|
||||
36, 1, 32, "a", 32, "b", 32, "c", 32, "d", 43, 4, 46, 36, 0, 33, 3, 45, 32, "d", 45, 33, 3, 45, 2, "print", 1, 35, 35,
|
||||
35, 32, "event", 32, "$pageview", 32, "properties", 32, "$browser", 32, "Chrome", 32, "$os", 32, "Windows", 42, 2, 42,
|
||||
2, 36, 0, 32, "properties", 45, 32, "$browser", 32, "Firefox", 46, 36, 0, 2, "print", 1, 35, 35, 32, "event", 32,
|
||||
"$pageview", 32, "properties", 32, "$browser", 32, "Chrome", 32, "$os", 32, "Windows", 42, 2, 42, 2, 36, 0, 32,
|
||||
|
@ -1,11 +1,11 @@
|
||||
["_h", 2, "tuple", 0, 2, "print", 1, 35, 33, 1, 44, 1, 2, "print", 1, 35, 33, 1, 33, 2, 44, 2, 2, "print", 1, 35, 33, 1,
|
||||
33, 2, 44, 2, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 3, 2, "print", 1, 35, 33, 1, 32, "2", 33, 3, 44, 3, 2,
|
||||
"print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 2, 33, 4, 44, 3, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2,
|
||||
33, 5, 44, 3, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 3, 36, 0, 33, 1, 45, 2, "print", 1, 35, 36, 0, 33, 1, 48, 2,
|
||||
"print", 1, 35, 36, 0, 33, 7, 48, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 1, 45,
|
||||
33, 1, 45, 33, 1, 45, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 1, 48, 33, 1, 48,
|
||||
33, 1, 48, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 1, 48, 33, 1, 48, 33, 1, 48,
|
||||
2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 3, 48, 33, 6, 48, 33, 1, 48, 2, "print",
|
||||
1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 3, 48, 33, 6, 48, 33, 1, 48, 2, "print", 1, 35, 33,
|
||||
1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 1, 45, 33, 1, 45, 33, 1, 45, 2, "print", 1, 35, 33, 1, 33, 1,
|
||||
33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 1, 45, 33, 1, 45, 33, 1, 45, 6, 2, "print", 1, 35, 35]
|
||||
33, 5, 44, 3, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 44, 3, 36, 0, 33, 2, 45, 2, "print", 1, 35, 36, 0, 33, 2, 48, 2,
|
||||
"print", 1, 35, 36, 0, 33, 8, 48, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 2, 45,
|
||||
33, 2, 45, 33, 2, 45, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 2, 48, 33, 2, 48,
|
||||
33, 2, 48, 2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 2, 48, 33, 2, 48, 33, 2, 48,
|
||||
2, "print", 1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 4, 48, 33, 7, 48, 33, 2, 48, 2, "print",
|
||||
1, 35, 33, 1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 4, 48, 33, 7, 48, 33, 2, 48, 2, "print", 1, 35, 33,
|
||||
1, 33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 2, 45, 33, 2, 45, 33, 2, 45, 2, "print", 1, 35, 33, 1, 33, 1,
|
||||
33, 2, 33, 3, 33, 4, 44, 2, 44, 2, 33, 5, 44, 3, 33, 2, 45, 33, 2, 45, 33, 2, 45, 6, 2, "print", 1, 35, 35]
|
||||
|
@ -5,19 +5,28 @@ print([1, [2, 3], 4])
|
||||
print([1, [2, [3, 4]], 5])
|
||||
|
||||
let a := [1, 2, 3]
|
||||
print(a[1])
|
||||
print(a?.[1])
|
||||
print(a?.1)
|
||||
print(a?.[6])
|
||||
print(a?.6)
|
||||
print([1, 2, 3][1], )
|
||||
print([1, [2, [3, 4], ], 5][1][1][1])
|
||||
print([1, [2, [3, 4], ], 5]?.1?.1?.1)
|
||||
print([1, [2, [3, 4], ], 5]?.[1]?.[1]?.[1])
|
||||
print([1, [2, [3, 4], ], 5]?.6?.3?.1)
|
||||
print([1, [2, [3, 4], ], 5]?.[6]?.[3]?.[1])
|
||||
print([1, [2, [3, 4]], 5][1][1][1] + 1)
|
||||
print([1, [2, [3, 4, ], ], 5, ].1.1.1)
|
||||
print(a[2])
|
||||
print(a?.[2])
|
||||
print(a?.2)
|
||||
print(a?.[7])
|
||||
print(a?.7)
|
||||
print([1, 2, 3][2], )
|
||||
print([1, [2, [3, 4], ], 5][2][2][2])
|
||||
print([1, [2, [3, 4], ], 5]?.2?.2?.2)
|
||||
print([1, [2, [3, 4], ], 5]?.[2]?.[2]?.[2])
|
||||
print([1, [2, [3, 4], ], 5]?.7?.4?.2)
|
||||
print([1, [2, [3, 4], ], 5]?.[7]?.[4]?.[2])
|
||||
print([1, [2, [3, 4]], 5][2][2][2] + 1)
|
||||
print([1, [2, [3, 4, ], ], 5, ].2.2.2)
|
||||
|
||||
print('------')
|
||||
let b := [1, 2, [1,2,3]]
|
||||
b[2] := 4
|
||||
print(b[1])
|
||||
print(b[2])
|
||||
print(b[3])
|
||||
b[3][3] := 8
|
||||
print(b)
|
||||
|
||||
print('------')
|
||||
|
||||
|
@ -1,49 +1,49 @@
|
||||
{
|
||||
let r := [1, 2, {'d': (1, 3, 42, 6)}]
|
||||
print(r.2.d.1)
|
||||
print(r.3.d.2)
|
||||
}
|
||||
{
|
||||
let r := [1, 2, {'d': (1, 3, 42, 6)}]
|
||||
print(r[2].d[2])
|
||||
print(r[3].d[3])
|
||||
}
|
||||
{
|
||||
let r := [1, 2, {'d': (1, 3, 42, 6)}]
|
||||
print(r.2['d'][3])
|
||||
print(r.3['d'][4])
|
||||
}
|
||||
{
|
||||
let r := {'d': (1, 3, 42, 6)}
|
||||
print(r.d.1)
|
||||
print(r.d.2)
|
||||
}
|
||||
{
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}]
|
||||
r.2.d.2 := 3
|
||||
print(r.2.d.2)
|
||||
r.3.d.3 := 3
|
||||
print(r.3.d.3)
|
||||
}
|
||||
{
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}]
|
||||
r[2].d[2] := 3
|
||||
print(r[2].d[2])
|
||||
r[3].d[3] := 3
|
||||
print(r[3].d[3])
|
||||
}
|
||||
{
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}]
|
||||
r[2].c := [666]
|
||||
print(r[2])
|
||||
r[3].c := [666]
|
||||
print(r[3])
|
||||
}
|
||||
{
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}]
|
||||
r[2].d[2] := 3
|
||||
print(r[2].d)
|
||||
r[3].d[3] := 3
|
||||
print(r[3].d)
|
||||
}
|
||||
{
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}]
|
||||
r.2['d'] := ['a', 'b', 'c', 'd']
|
||||
print(r[2].d[2])
|
||||
r.3['d'] := ['a', 'b', 'c', 'd']
|
||||
print(r[3].d[3])
|
||||
}
|
||||
{
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}]
|
||||
let g := 'd'
|
||||
r.2[g] := ['a', 'b', 'c', 'd']
|
||||
print(r[2].d[2])
|
||||
r.3[g] := ['a', 'b', 'c', 'd']
|
||||
print(r[3].d[3])
|
||||
}
|
||||
{
|
||||
let event := {
|
||||
|
@ -7,13 +7,13 @@ print((1, '2', 3))
|
||||
print((1, (2, 3), 4))
|
||||
print((1, (2, (3, 4)), 5))
|
||||
let a := (1, 2, 3)
|
||||
print(a[1])
|
||||
print(a?.1)
|
||||
print(a?.7)
|
||||
print((1, (2, (3, 4)), 5)[1][1][1])
|
||||
print((1, (2, (3, 4)), 5)?.1?.1?.1)
|
||||
print((1, (2, (3, 4)), 5)?.[1]?.[1]?.[1])
|
||||
print((1, (2, (3, 4)), 5)?.3?.6?.1)
|
||||
print((1, (2, (3, 4)), 5)?.[3]?.[6]?.[1])
|
||||
print((1, (2, (3, 4, ), ), 5, ).1.1.1)
|
||||
print((1, (2, (3, 4)), 5)[1][1][1] + 1)
|
||||
print(a[2])
|
||||
print(a?.2)
|
||||
print(a?.8)
|
||||
print((1, (2, (3, 4)), 5)[2][2][2])
|
||||
print((1, (2, (3, 4)), 5)?.2?.2?.2)
|
||||
print((1, (2, (3, 4)), 5)?.[2]?.[2]?.[2])
|
||||
print((1, (2, (3, 4)), 5)?.4?.7?.2)
|
||||
print((1, (2, (3, 4)), 5)?.[4]?.[7]?.[2])
|
||||
print((1, (2, (3, 4, ), ), 5, ).2.2.2)
|
||||
print((1, (2, (3, 4)), 5)[2][2][2] + 1)
|
||||
|
1
hogvm/asd.hog
Normal file
1
hogvm/asd.hog
Normal file
@ -0,0 +1 @@
|
||||
return [1, 2, 3][0]
|
1
hogvm/asd.hoge
Normal file
1
hogvm/asd.hoge
Normal file
@ -0,0 +1 @@
|
||||
["_h", 33, 1, 33, 2, 33, 3, 43, 3, 33, 0, 45, 38]
|
@ -106,10 +106,10 @@ class TestBytecodeExecute:
|
||||
chain: list[str] = ["properties", "bla"]
|
||||
assert get_nested_value(my_dict, chain) == "hello"
|
||||
|
||||
chain = ["properties", "list", 1]
|
||||
chain = ["properties", "list", 2]
|
||||
assert get_nested_value(my_dict, chain) == "item2"
|
||||
|
||||
chain = ["properties", "tuple", 2]
|
||||
chain = ["properties", "tuple", 3]
|
||||
assert get_nested_value(my_dict, chain) == "item3"
|
||||
|
||||
def test_errors(self):
|
||||
@ -634,11 +634,18 @@ class TestBytecodeExecute:
|
||||
assert self._run_program("return [1, [2, 3], 4];") == [1, [2, 3], 4]
|
||||
assert self._run_program("return [1, [2, [3, 4]], 5];") == [1, [2, [3, 4]], 5]
|
||||
|
||||
assert self._run_program("let a := [1, 2, 3]; return a[1];") == 2
|
||||
assert self._run_program("return [1, 2, 3][1];") == 2
|
||||
assert self._run_program("return [1, [2, [3, 4]], 5][1][1][1];") == 4
|
||||
assert self._run_program("return [1, [2, [3, 4]], 5][1][1][1] + 1;") == 5
|
||||
assert self._run_program("return [1, [2, [3, 4]], 5].1.1.1;") == 4
|
||||
assert self._run_program("let a := [1, 2, 3]; return a[2];") == 2
|
||||
assert self._run_program("return [1, 2, 3][2];") == 2
|
||||
assert self._run_program("return [1, [2, [3, 4]], 5][2][2][2];") == 4
|
||||
assert self._run_program("return [1, [2, [3, 4]], 5][2][2][2] + 1;") == 5
|
||||
assert self._run_program("return [1, [2, [3, 4]], 5].2.2.2;") == 4
|
||||
|
||||
try:
|
||||
self._run_program("return [1, 2, 3][0]")
|
||||
except Exception as e:
|
||||
assert str(e) == "Hog arrays start from index 1"
|
||||
else:
|
||||
raise AssertionError("Expected Exception not raised")
|
||||
|
||||
def test_bytecode_tuples(self):
|
||||
# assert self._run_program("return (,);"), ()
|
||||
@ -646,24 +653,24 @@ class TestBytecodeExecute:
|
||||
assert self._run_program("return (1, '2', 3);") == (1, "2", 3)
|
||||
assert self._run_program("return (1, (2, 3), 4);") == (1, (2, 3), 4)
|
||||
assert self._run_program("return (1, (2, (3, 4)), 5);") == (1, (2, (3, 4)), 5)
|
||||
assert self._run_program("let a := (1, 2, 3); return a[1];") == 2
|
||||
assert self._run_program("return (1, (2, (3, 4)), 5)[1][1][1];") == 4
|
||||
assert self._run_program("return (1, (2, (3, 4)), 5).1.1.1;") == 4
|
||||
assert self._run_program("return (1, (2, (3, 4)), 5)[1][1][1] + 1;") == 5
|
||||
assert self._run_program("let a := (1, 2, 3); return a[2];") == 2
|
||||
assert self._run_program("return (1, (2, (3, 4)), 5)[2][2][2];") == 4
|
||||
assert self._run_program("return (1, (2, (3, 4)), 5).2.2.2;") == 4
|
||||
assert self._run_program("return (1, (2, (3, 4)), 5)[2][2][2] + 1;") == 5
|
||||
|
||||
def test_bytecode_nested(self):
|
||||
assert self._run_program("let r := [1, 2, {'d': (1, 3, 42, 6)}]; return r.2.d.1;") == 3
|
||||
assert self._run_program("let r := [1, 2, {'d': (1, 3, 42, 6)}]; return r[2].d[2];") == 42
|
||||
assert self._run_program("let r := [1, 2, {'d': (1, 3, 42, 6)}]; return r.2['d'][3];") == 6
|
||||
assert self._run_program("let r := {'d': (1, 3, 42, 6)}; return r.d.1;") == 3
|
||||
assert self._run_program("let r := [1, 2, {'d': (1, 3, 42, 6)}]; return r.3.d.2;") == 3
|
||||
assert self._run_program("let r := [1, 2, {'d': (1, 3, 42, 6)}]; return r[3].d[3];") == 42
|
||||
assert self._run_program("let r := [1, 2, {'d': (1, 3, 42, 6)}]; return r.3['d'][4];") == 6
|
||||
assert self._run_program("let r := {'d': (1, 3, 42, 6)}; return r.d.2;") == 3
|
||||
|
||||
def test_bytecode_nested_modify(self):
|
||||
assert (
|
||||
self._run_program(
|
||||
"""
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
r.2.d.2 := 3;
|
||||
return r.2.d.2;
|
||||
r.3.d.3 := 3;
|
||||
return r.3.d.3;
|
||||
"""
|
||||
)
|
||||
== 3
|
||||
@ -673,8 +680,8 @@ class TestBytecodeExecute:
|
||||
self._run_program(
|
||||
"""
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
r[2].d[2] := 3;
|
||||
return r[2].d[2];
|
||||
r[3].d[3] := 3;
|
||||
return r[3].d[3];
|
||||
"""
|
||||
)
|
||||
== 3
|
||||
@ -683,16 +690,16 @@ class TestBytecodeExecute:
|
||||
assert self._run_program(
|
||||
"""
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
r[2].c := [666];
|
||||
return r[2];
|
||||
r[3].c := [666];
|
||||
return r[3];
|
||||
"""
|
||||
) == {"d": [1, 3, 42, 3], "c": [666]}
|
||||
|
||||
assert self._run_program(
|
||||
"""
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
r[2].d[2] := 3;
|
||||
return r[2].d;
|
||||
r[3].d[3] := 3;
|
||||
return r[3].d;
|
||||
"""
|
||||
) == [1, 3, 3, 3]
|
||||
|
||||
@ -700,8 +707,8 @@ class TestBytecodeExecute:
|
||||
self._run_program(
|
||||
"""
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
r.2['d'] := ['a', 'b', 'c', 'd'];
|
||||
return r[2].d[2];
|
||||
r.3['d'] := ['a', 'b', 'c', 'd'];
|
||||
return r[3].d[3];
|
||||
"""
|
||||
)
|
||||
== "c"
|
||||
@ -712,8 +719,8 @@ class TestBytecodeExecute:
|
||||
"""
|
||||
let r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
let g := 'd';
|
||||
r.2[g] := ['a', 'b', 'c', 'd'];
|
||||
return r[2].d[2];
|
||||
r.3[g] := ['a', 'b', 'c', 'd'];
|
||||
return r[3].d[3];
|
||||
"""
|
||||
)
|
||||
== "c"
|
||||
|
@ -22,9 +22,11 @@ def get_nested_value(obj, chain, nullish=False) -> Any:
|
||||
if nullish and obj is None:
|
||||
return None
|
||||
if isinstance(key, int):
|
||||
if nullish and len(obj) <= key:
|
||||
if key <= 0:
|
||||
raise HogVMException(f"Hog arrays start from index 1")
|
||||
if nullish and key > len(obj):
|
||||
return None
|
||||
obj = obj[key]
|
||||
obj = obj[key - 1]
|
||||
else:
|
||||
obj = obj.get(key, None)
|
||||
return obj
|
||||
@ -44,7 +46,9 @@ def set_nested_value(obj, chain, value) -> Any:
|
||||
elif isinstance(obj, list):
|
||||
if not isinstance(chain[-1], int):
|
||||
raise HogVMException(f"Invalid index: {chain[-1]}")
|
||||
obj[chain[-1]] = value
|
||||
if chain[-1] <= 0:
|
||||
raise HogVMException(f"Hog arrays start from index 1")
|
||||
obj[chain[-1] - 1] = value
|
||||
else:
|
||||
raise HogVMException(f'Can not set property "{chain[-1]}" on object of type "{type(obj).__name__}"')
|
||||
|
||||
|
@ -713,7 +713,7 @@ describe('hogvm execute', () => {
|
||||
]).result
|
||||
).toEqual([1, [2, [3, 4]], 5])
|
||||
|
||||
// var a := [1, 2, 3]; return a[1];
|
||||
// var a := [1, 2, 3]; return a[2];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -728,14 +728,14 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
]).result
|
||||
).toEqual(2)
|
||||
|
||||
// return [1, 2, 3][1];
|
||||
// return [1, 2, 3][2];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -748,13 +748,13 @@ describe('hogvm execute', () => {
|
||||
op.ARRAY,
|
||||
3,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
]).result
|
||||
).toEqual(2)
|
||||
|
||||
// return [1, [2, [3, 4]], 5][1][1][1];
|
||||
// return [1, [2, [3, 4]], 5][2][2][2];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -775,19 +775,19 @@ describe('hogvm execute', () => {
|
||||
op.ARRAY,
|
||||
3,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
]).result
|
||||
).toEqual(4)
|
||||
|
||||
// return [1, [2, [3, 4]], 5][1][1][1] + 1;
|
||||
// return [1, [2, [3, 4]], 5][2][2][2] + 1;
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -810,20 +810,20 @@ describe('hogvm execute', () => {
|
||||
op.ARRAY,
|
||||
3,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.PLUS,
|
||||
op.RETURN,
|
||||
]).result
|
||||
).toEqual(5)
|
||||
|
||||
// return [1, [2, [3, 4]], 5].1.1.1;
|
||||
// return [1, [2, [3, 4]], 5].2.2.2;
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -844,17 +844,22 @@ describe('hogvm execute', () => {
|
||||
op.ARRAY,
|
||||
3,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
]).result
|
||||
).toEqual(4)
|
||||
|
||||
// return [1, 2, 3][0]
|
||||
expect(() => execSync(['_h', 33, 1, 33, 2, 33, 3, 43, 3, 33, 0, 45, 38])).toThrow(
|
||||
'Hog arrays start from index 1'
|
||||
)
|
||||
})
|
||||
|
||||
test('test bytecode tuples', () => {
|
||||
@ -912,7 +917,7 @@ describe('hogvm execute', () => {
|
||||
]).result
|
||||
).toEqual(tuple([1, tuple([2, tuple([3, 4])]), 5]))
|
||||
|
||||
// var a := (1, 2, 3); return a[1];
|
||||
// var a := (1, 2, 3); return a[2];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -927,14 +932,14 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
]).result
|
||||
).toEqual(2)
|
||||
|
||||
// return (1, (2, (3, 4)), 5)[1][1][1];
|
||||
// return (1, (2, (3, 4)), 5)[2][2][2];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -955,19 +960,19 @@ describe('hogvm execute', () => {
|
||||
op.TUPLE,
|
||||
3,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
]).result
|
||||
).toEqual(4)
|
||||
|
||||
// return (1, (2, (3, 4)), 5).1.1.1;
|
||||
// return (1, (2, (3, 4)), 5).2.2.2;
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -988,19 +993,19 @@ describe('hogvm execute', () => {
|
||||
op.TUPLE,
|
||||
3,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
]).result
|
||||
).toEqual(4)
|
||||
|
||||
// return (1, (2, (3, 4)), 5)[1][1][1] + 1;
|
||||
// return (1, (2, (3, 4)), 5)[2][2][2] + 1;
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1023,13 +1028,13 @@ describe('hogvm execute', () => {
|
||||
op.TUPLE,
|
||||
3,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.PLUS,
|
||||
op.RETURN,
|
||||
@ -1038,7 +1043,7 @@ describe('hogvm execute', () => {
|
||||
})
|
||||
|
||||
test('test bytecode nested', () => {
|
||||
// var r := [1, 2, {'d': (1, 3, 42, 6)}]; return r.2.d.1;
|
||||
// var r := [1, 2, {'d': (1, 3, 42, 6)}]; return r.3.d.2;
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1065,20 +1070,20 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
]).result
|
||||
).toEqual(3)
|
||||
|
||||
// var r := [1, 2, {'d': (1, 3, 42, 6)}]; return r[2].d[2];
|
||||
// var r := [1, 2, {'d': (1, 3, 42, 6)}]; return r[3].d[3];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1105,20 +1110,20 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
]).result
|
||||
).toEqual(42)
|
||||
|
||||
// var r := [1, 2, {'d': (1, 3, 42, 6)}]; return r.2['d'][3];
|
||||
// var r := [1, 2, {'d': (1, 3, 42, 6)}]; return r.3['d'][4];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1145,20 +1150,20 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
3,
|
||||
4,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
]).result
|
||||
).toEqual(6)
|
||||
|
||||
// var r := {'d': (1, 3, 42, 6)}; return r.d.1;
|
||||
// var r := {'d': (1, 3, 42, 6)}; return r.d.2;
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1182,7 +1187,7 @@ describe('hogvm execute', () => {
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
1,
|
||||
2,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
@ -1192,8 +1197,8 @@ describe('hogvm execute', () => {
|
||||
|
||||
test('test bytecode nested modify', () => {
|
||||
// var r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
// r.2.d.2 := 3;
|
||||
// return r.2.d.2;
|
||||
// r.3.d.3 := 3;
|
||||
// return r.3.d.3;
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1220,26 +1225,26 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.INTEGER,
|
||||
3,
|
||||
op.SET_PROPERTY,
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
@ -1247,8 +1252,8 @@ describe('hogvm execute', () => {
|
||||
).toEqual(3)
|
||||
|
||||
// var r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
// r[2].d[2] := 3;
|
||||
// return r[2].d[2];
|
||||
// r[3].d[3] := 3;
|
||||
// return r[3].d[3];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1275,26 +1280,26 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.INTEGER,
|
||||
3,
|
||||
op.SET_PROPERTY,
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
@ -1302,8 +1307,8 @@ describe('hogvm execute', () => {
|
||||
).toEqual(3)
|
||||
|
||||
// var r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
// r[2].c := [666];
|
||||
// return r[2];
|
||||
// r[3].c := [666];
|
||||
// return r[3];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1330,7 +1335,7 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'c',
|
||||
@ -1342,7 +1347,7 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
@ -1350,8 +1355,8 @@ describe('hogvm execute', () => {
|
||||
).toEqual(map({ d: [1, 3, 42, 3], c: [666] }))
|
||||
|
||||
// var r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
// r[2].d[2] := 3;
|
||||
// return r[2].d;
|
||||
// r[3].d[3] := 3;
|
||||
// return r[3].d;
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1378,20 +1383,20 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.INTEGER,
|
||||
3,
|
||||
op.SET_PROPERTY,
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
@ -1402,8 +1407,8 @@ describe('hogvm execute', () => {
|
||||
).toEqual([1, 3, 3, 3])
|
||||
|
||||
// var r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
// r.2['d'] := ['a', 'b', 'c', 'd'];
|
||||
// return r[2].d[2];
|
||||
// r.3['d'] := ['a', 'b', 'c', 'd'];
|
||||
// return r[3].d[3];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1430,7 +1435,7 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
@ -1448,13 +1453,13 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
@ -1463,8 +1468,8 @@ describe('hogvm execute', () => {
|
||||
|
||||
// var r := [1, 2, {'d': [1, 3, 42, 3]}];
|
||||
// var g := 'd';
|
||||
// r.2[g] := ['a', 'b', 'c', 'd'];
|
||||
// return r[2].d[2];
|
||||
// r.3[g] := ['a', 'b', 'c', 'd'];
|
||||
// return r[3].d[3];
|
||||
expect(
|
||||
exec([
|
||||
'_h',
|
||||
@ -1493,7 +1498,7 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.GET_LOCAL,
|
||||
1,
|
||||
@ -1511,13 +1516,13 @@ describe('hogvm execute', () => {
|
||||
op.GET_LOCAL,
|
||||
0,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.STRING,
|
||||
'd',
|
||||
op.GET_PROPERTY,
|
||||
op.INTEGER,
|
||||
2,
|
||||
3,
|
||||
op.GET_PROPERTY,
|
||||
op.RETURN,
|
||||
op.POP,
|
||||
|
@ -19,7 +19,10 @@ export function getNestedValue(obj: any, chain: any[], nullish = false): any {
|
||||
if (obj instanceof Map) {
|
||||
obj = obj.get(key) ?? null
|
||||
} else if (typeof key === 'number') {
|
||||
obj = obj[key] ?? null
|
||||
if (key <= 0) {
|
||||
throw new Error(`Hog arrays start from index 1`)
|
||||
}
|
||||
obj = obj[key - 1] ?? null
|
||||
} else {
|
||||
obj = obj[key] ?? null
|
||||
}
|
||||
@ -37,7 +40,10 @@ export function setNestedValue(obj: any, chain: any[], value: any): void {
|
||||
if (obj instanceof Map) {
|
||||
obj = obj.get(key) ?? null
|
||||
} else if (Array.isArray(obj) && typeof key === 'number') {
|
||||
obj = obj[key]
|
||||
if (key <= 0) {
|
||||
throw new Error(`Hog arrays start from index 1`)
|
||||
}
|
||||
obj = obj[key - 1]
|
||||
} else {
|
||||
throw new Error(`Can not get ${chain} on element of type ${typeof obj}`)
|
||||
}
|
||||
@ -46,7 +52,10 @@ export function setNestedValue(obj: any, chain: any[], value: any): void {
|
||||
if (obj instanceof Map) {
|
||||
obj.set(lastKey, value)
|
||||
} else if (Array.isArray(obj) && typeof lastKey === 'number') {
|
||||
obj[lastKey] = value
|
||||
if (lastKey <= 0) {
|
||||
throw new Error(`Hog arrays start from index 1`)
|
||||
}
|
||||
obj[lastKey - 1] = value
|
||||
} else {
|
||||
throw new Error(`Can not set ${chain} on element of type ${typeof obj}`)
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ class BytecodeBuilder(Visitor):
|
||||
response.extend([Operation.GET_LOCAL, expr_local, Operation.CALL, "values", 1])
|
||||
|
||||
loop_index_local = self._declare_local("__H_index_H__") # 0
|
||||
response.extend([Operation.INTEGER, 0])
|
||||
response.extend([Operation.INTEGER, 1])
|
||||
|
||||
loop_limit_local = self._declare_local("__H_limit_H__") # length of keys
|
||||
response.extend([Operation.GET_LOCAL, expr_values_local, Operation.CALL, "length", 1])
|
||||
@ -390,7 +390,7 @@ class BytecodeBuilder(Visitor):
|
||||
response.extend([Operation.NULL])
|
||||
|
||||
# check if loop_index < loop_limit
|
||||
condition = [Operation.GET_LOCAL, loop_limit_local, Operation.GET_LOCAL, loop_index_local, Operation.LT]
|
||||
condition = [Operation.GET_LOCAL, loop_limit_local, Operation.GET_LOCAL, loop_index_local, Operation.LT_EQ]
|
||||
|
||||
# set key_var and value_var
|
||||
body: list = []
|
||||
|
Loading…
Reference in New Issue
Block a user