From e69868abafdfd61e8c3915c4002b8eefb5e98c0d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 11 Jan 2023 17:45:11 +0100 Subject: [PATCH 001/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f5dc6216fe..2994099957 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3470 \ No newline at end of file +3471 \ No newline at end of file From 38e4335d472fd6be496f1a64d0132647cb0678f6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 11 Jan 2023 17:48:09 +0100 Subject: [PATCH 002/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2994099957..ff12ddff7b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3471 \ No newline at end of file +3472 \ No newline at end of file From 6e0617282344dbd786565f46ac6d62ced17a7657 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 11:39:41 +0100 Subject: [PATCH 003/984] added Evaluator-specific unit-test --- tests/unittests/evaluator.art | 43 +++++++++++++++++++++++++++++++++++ tests/unittests/evaluator.res | 3 +++ 2 files changed, 46 insertions(+) create mode 100644 tests/unittests/evaluator.art create mode 100644 tests/unittests/evaluator.res diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art new file mode 100644 index 0000000000..7cf4a6b842 --- /dev/null +++ b/tests/unittests/evaluator.art @@ -0,0 +1,43 @@ +byteCode: function [blk][ + btc: to :bytecode blk + ;inspect btc + print get btc 'code +] + +;--------------------------------------------------------- +; Boolean values +;--------------------------------------------------------- + +byteCode [true] +; ================================ +; DATA +; ================================ + +; ================================ +; CODE +; ================================ +; constbt +; end + +byteCode [false] +; ================================ +; DATA +; ================================ + +; ================================ +; CODE +; ================================ +; constbf +; end + +byteCode [maybe] +; ================================ +; DATA +; ================================ +; 0: maybe :word + +; ================================ +; CODE +; ================================ +; load0 +; end diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res new file mode 100644 index 0000000000..265a1065a1 --- /dev/null +++ b/tests/unittests/evaluator.res @@ -0,0 +1,3 @@ +21 211 +22 211 +64 211 \ No newline at end of file From ae658863aa806d9995190bde3e8b0666cbb918b6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 11:52:26 +0100 Subject: [PATCH 004/984] Unittests/evaluator: added tests for simple Integer values --- tests/unittests/evaluator.art | 52 ++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 7cf4a6b842..a9788d62dd 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1,6 +1,6 @@ byteCode: function [blk][ btc: to :bytecode blk - ;inspect btc + inspect btc print get btc 'code ] @@ -41,3 +41,53 @@ byteCode [maybe] ; ================================ ; load0 ; end + +;--------------------------------------------------------- +; Integer values +;--------------------------------------------------------- + +byteCode [1] +; ================================ +; DATA +; ================================ + +; ================================ +; CODE +; ================================ +; consti1 +; end + +byteCode [10] +; ================================ +; DATA +; ================================ + +; ================================ +; CODE +; ================================ +; consti10 +; end + +byteCode [123] +; ================================ +; DATA +; ================================ +; 0: 123 :integer + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode [1234567890123] +; ================================ +; DATA +; ================================ +; 0: 1234567890123 :integer + +; ================================ +; CODE +; ================================ +; push0 +; end \ No newline at end of file From 67cfcccbccf483428d2933e7f146a5deb7c14231 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 11:53:23 +0100 Subject: [PATCH 005/984] minor style fix --- tests/unittests/evaluator.art | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index a9788d62dd..191dfa1ae9 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -4,9 +4,9 @@ byteCode: function [blk][ print get btc 'code ] -;--------------------------------------------------------- +;***************************************************************** ; Boolean values -;--------------------------------------------------------- +;***************************************************************** byteCode [true] ; ================================ @@ -42,9 +42,9 @@ byteCode [maybe] ; load0 ; end -;--------------------------------------------------------- +;***************************************************************** ; Integer values -;--------------------------------------------------------- +;***************************************************************** byteCode [1] ; ================================ From cc9f49ac21903551cb37e437cedd4326e25a802a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 12:03:55 +0100 Subject: [PATCH 006/984] Unittests/evaluator: add tests for Floating values & updated output --- tests/unittests/evaluator.art | 69 +++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 191dfa1ae9..953f963774 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1,11 +1,22 @@ +topic: function [title][ + print "" + print repeat "*" 30 + print ["*" title] + print repeat "*" 30 + print "" + print repeat "-" 50 +] + byteCode: function [blk][ btc: to :bytecode blk - inspect btc - print get btc 'code + ;inspect btc + print ["data:" get btc 'data] + print ["code:" get btc 'code] + print repeat "-" 50 ] ;***************************************************************** -; Boolean values +topic "Boolean values" ;***************************************************************** byteCode [true] @@ -43,7 +54,7 @@ byteCode [maybe] ; end ;***************************************************************** -; Integer values +topic "Integer values" ;***************************************************************** byteCode [1] @@ -86,6 +97,56 @@ byteCode [1234567890123] ; ================================ ; 0: 1234567890123 :integer +; ================================ +; CODE +; ================================ +; push0 +; end + +;***************************************************************** +topic "Floating values" +;***************************************************************** + +byteCode [0.0] +; ================================ +; DATA +; ================================ + +; ================================ +; CODE +; ================================ +; constf0 +; end + +byteCode [1.0] +; ================================ +; DATA +; ================================ + +; ================================ +; CODE +; ================================ +; constf1 +; end + +byteCode [10.0] +; ================================ +; DATA +; ================================ +; 0: 10.0 :floating + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode [12345.1234567] +; ================================ +; DATA +; ================================ +; 0: 12345.1234567 :floating + ; ================================ ; CODE ; ================================ From 4295b3047137df18c23de764f85b7a55444db420 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 12:06:43 +0100 Subject: [PATCH 007/984] added TODO --- src/library/Converters.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/library/Converters.nim b/src/library/Converters.nim index 67a480272a..ee097b5cf0 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -630,6 +630,8 @@ proc defineSymbols*() = else: push(newBlock(@[x])) + # TODO(Converters/as) is `.unwrapped` working as expected? + # labels: library, bug builtin "as", alias = unaliased, rule = PrefixPrecedence, From 2f2dac156bdb4ba5e84dacd20de9b5a737aa83fd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 12:06:53 +0100 Subject: [PATCH 008/984] also show input --- tests/unittests/evaluator.art | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 953f963774..107cdd1f8a 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -10,6 +10,7 @@ topic: function [title][ byteCode: function [blk][ btc: to :bytecode blk ;inspect btc + print ["input:" as.code blk] print ["data:" get btc 'data] print ["code:" get btc 'code] print repeat "-" 50 From d5cfb6418e6fc1afc454d6cde80f042054a30ae5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 12:07:03 +0100 Subject: [PATCH 009/984] updated expected result --- tests/unittests/evaluator.res | 64 +++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 265a1065a1..9e004e3fee 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -1,3 +1,61 @@ -21 211 -22 211 -64 211 \ No newline at end of file +****************************** +* Boolean values +****************************** + +-------------------------------------------------- +input: [true] +data: [] +code: [21 211] +-------------------------------------------------- +input: [false] +data: [] +code: [22 211] +-------------------------------------------------- +input: [maybe] +data: [maybe] +code: [64 211] +-------------------------------------------------- + +****************************** +* Integer values +****************************** + +-------------------------------------------------- +input: [1] +data: [] +code: [1 211] +-------------------------------------------------- +input: [10] +data: [] +code: [10 211] +-------------------------------------------------- +input: [123] +data: [123] +code: [32 211] +-------------------------------------------------- +input: [1234567890123] +data: [1234567890123] +code: [32 211] +-------------------------------------------------- + +****************************** +* Floating values +****************************** + +-------------------------------------------------- +input: [0.0] +data: [] +code: [17 211] +-------------------------------------------------- +input: [1.0] +data: [] +code: [18 211] +-------------------------------------------------- +input: [10.0] +data: [10.0] +code: [32 211] +-------------------------------------------------- +input: [12345.1234567] +data: [12345.1234567] +code: [32 211] +-------------------------------------------------- \ No newline at end of file From b07e31301714446b63e6a701fe2076b07a604408 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 12:53:15 +0100 Subject: [PATCH 010/984] Unittests/evaluator: added tests for String values --- tests/unittests/evaluator.art | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 107cdd1f8a..732534b385 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -152,4 +152,31 @@ byteCode [12345.1234567] ; CODE ; ================================ ; push0 +; end + +;***************************************************************** +topic "String values" +;***************************************************************** + +byteCode [""] +; ================================ +; DATA +; ================================ + +; ================================ +; CODE +; ================================ +; consts +; end + +byteCode ["Hello World!"] +; ================================ +; DATA +; ================================ +; 0: Hello World! :string + +; ================================ +; CODE +; ================================ +; push0 ; end \ No newline at end of file From 9262e7c3cb2a7577b66f340bf10be54c7ddc3a96 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 12:56:12 +0100 Subject: [PATCH 011/984] Unittests/evaluator: added tests for Null values --- tests/unittests/evaluator.art | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 732534b385..b9a19822e3 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -9,7 +9,7 @@ topic: function [title][ byteCode: function [blk][ btc: to :bytecode blk - ;inspect btc + inspect btc print ["input:" as.code blk] print ["data:" get btc 'data] print ["code:" get btc 'code] @@ -179,4 +179,31 @@ byteCode ["Hello World!"] ; CODE ; ================================ ; push0 -; end \ No newline at end of file +; end + +;***************************************************************** +topic "Null values" +;***************************************************************** + +byteCode [ΓΈ] +; ================================ +; DATA +; ================================ + +; ================================ +; CODE +; ================================ +; constn +; end + +byteCode [null] +; ================================ +; DATA +; ================================ +; 0: null :word + +; ================================ +; CODE +; ================================ +; load0 +; end From f9ce60b351aaa7bd15e8f1da1584963dc71b4e04 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 12:59:52 +0100 Subject: [PATCH 012/984] Unittests/evaluator: added tests for Char values --- tests/unittests/evaluator.art | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index b9a19822e3..995b94d246 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -181,6 +181,34 @@ byteCode ["Hello World!"] ; push0 ; end +;***************************************************************** +topic "Char values" +;***************************************************************** + +byteCode [`a`] +; ================================ +; DATA +; ================================ +; 0: a :char + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode [`πŸ˜€`] +; ================================ +; DATA +; ================================ +; 0: πŸ˜€ :char + +; ================================ +; CODE +; ================================ +; push0 +; end + ;***************************************************************** topic "Null values" ;***************************************************************** From 83b21fb49f2352a835efc46dd5defc801fe13601 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:01:47 +0100 Subject: [PATCH 013/984] Unittests/evaluator: added tests for Type values --- tests/unittests/evaluator.art | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 995b94d246..fa28f51e4c 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -209,6 +209,34 @@ byteCode [`πŸ˜€`] ; push0 ; end +;***************************************************************** +topic "Type values" +;***************************************************************** + +byteCode [:integer] +; ================================ +; DATA +; ================================ +; 0: integer :type + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode [:string] +; ================================ +; DATA +; ================================ +; 0: string :type + +; ================================ +; CODE +; ================================ +; push0 +; end + ;***************************************************************** topic "Null values" ;***************************************************************** From ca45264fb2a1892af09b83961e3a22069eb560ce Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:04:24 +0100 Subject: [PATCH 014/984] Unittests/evaluator: added tests for Literal values --- tests/unittests/evaluator.art | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index fa28f51e4c..3e340d6ee9 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1,3 +1,5 @@ +; Helper functions + topic: function [title][ print "" print repeat "*" 30 @@ -16,6 +18,8 @@ byteCode: function [blk][ print repeat "-" 50 ] +; Main unit-tests + ;***************************************************************** topic "Boolean values" ;***************************************************************** @@ -237,6 +241,38 @@ byteCode [:string] ; push0 ; end +;***************************************************************** +topic "Literal values" +;***************************************************************** + +byteCode ['a] +; ================================ +; DATA +; ================================ +; 0: a :literal + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode ['a 'b 'c] +; ================================ +; DATA +; ================================ +; 0: a :literal +; 1: b :literal +; 2: c :literal + +; ================================ +; CODE +; ================================ +; push0 +; push1 +; push2 +; end + ;***************************************************************** topic "Null values" ;***************************************************************** From 624d095345dab3063984d3c0c8de7f566840aef9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:04:59 +0100 Subject: [PATCH 015/984] re-ordering --- tests/unittests/evaluator.art | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 3e340d6ee9..ee09d1ba7d 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -159,25 +159,26 @@ byteCode [12345.1234567] ; end ;***************************************************************** -topic "String values" +topic "Char values" ;***************************************************************** -byteCode [""] +byteCode [`a`] ; ================================ ; DATA ; ================================ +; 0: a :char ; ================================ ; CODE ; ================================ -; consts +; push0 ; end -byteCode ["Hello World!"] +byteCode [`πŸ˜€`] ; ================================ ; DATA ; ================================ -; 0: Hello World! :string +; 0: πŸ˜€ :char ; ================================ ; CODE @@ -186,26 +187,25 @@ byteCode ["Hello World!"] ; end ;***************************************************************** -topic "Char values" +topic "String values" ;***************************************************************** -byteCode [`a`] +byteCode [""] ; ================================ ; DATA ; ================================ -; 0: a :char ; ================================ ; CODE ; ================================ -; push0 +; consts ; end -byteCode [`πŸ˜€`] +byteCode ["Hello World!"] ; ================================ ; DATA ; ================================ -; 0: πŸ˜€ :char +; 0: Hello World! :string ; ================================ ; CODE From a397ced12f23e613a406360e892710f8fa9f718f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:06:26 +0100 Subject: [PATCH 016/984] Unittests/evaluator: added tests for Regex values --- tests/unittests/evaluator.art | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index ee09d1ba7d..ca9bc56ba8 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -213,6 +213,34 @@ byteCode ["Hello World!"] ; push0 ; end +;***************************************************************** +topic "Regex values" +;***************************************************************** + +byteCode [{/hello/}] +; ================================ +; DATA +; ================================ +; 0: hello :regex + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode [{/[A-Z]+\d/}] +; ================================ +; DATA +; ================================ +; 0: [A-Z]+\d :regex + +; ================================ +; CODE +; ================================ +; push0 +; end + ;***************************************************************** topic "Type values" ;***************************************************************** From 17dd808ebe9a9388703e83a8015cda1d7816fc64 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:07:50 +0100 Subject: [PATCH 017/984] Unittests/evaluator: added tests for SymbolLiteral values --- tests/unittests/evaluator.art | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index ca9bc56ba8..575fbc05ed 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -301,6 +301,34 @@ byteCode ['a 'b 'c] ; push2 ; end +;***************************************************************** +topic "SymbolLiteral values" +;***************************************************************** + +byteCode ['+] +; ================================ +; DATA +; ================================ +; 0: + :symbolliteral + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode ['-->] +; ================================ +; DATA +; ================================ +; 0: --> :symbolliteral + +; ================================ +; CODE +; ================================ +; push0 +; end + ;***************************************************************** topic "Null values" ;***************************************************************** From 34f50e659d10ccde834e2ca110703f064d5bdb0f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:09:08 +0100 Subject: [PATCH 018/984] Unittests/evaluator: added tests for Color values --- tests/unittests/evaluator.art | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 575fbc05ed..e6e56e7442 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -329,6 +329,34 @@ byteCode ['-->] ; push0 ; end +;***************************************************************** +topic "Color values" +;***************************************************************** + +byteCode [#red] +; ================================ +; DATA +; ================================ +; 0: #FF0000 :color + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode [#00FF66] +; ================================ +; DATA +; ================================ +; 0: #00FF66 :color + +; ================================ +; CODE +; ================================ +; push0 +; end + ;***************************************************************** topic "Null values" ;***************************************************************** From bc15c7d4c68ea5969f82806adbcceed72ab71ef4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:10:32 +0100 Subject: [PATCH 019/984] Unittests/evaluator: added tests for Quantity values --- tests/unittests/evaluator.art | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index e6e56e7442..8f30d605cd 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -357,6 +357,34 @@ byteCode [#00FF66] ; push0 ; end +;***************************************************************** +topic "Quantity values" +;***************************************************************** + +byteCode [1:EUR] +; ================================ +; DATA +; ================================ +; 0: 1:EUR :quantity + +; ================================ +; CODE +; ================================ +; push0 +; end + +byteCode [12:m] +; ================================ +; DATA +; ================================ +; 0: 12:m :quantity + +; ================================ +; CODE +; ================================ +; push0 +; end + ;***************************************************************** topic "Null values" ;***************************************************************** From 1eb783e17426f9ac5c87f1ba4656ecb0139c1479 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:16:52 +0100 Subject: [PATCH 020/984] cleanup & re-changed styling --- tests/unittests/evaluator.art | 811 +++++++++++++++++----------------- 1 file changed, 414 insertions(+), 397 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 8f30d605cd..b47b3f074b 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1,413 +1,430 @@ ; Helper functions +spacer: " " + +supersection: function [title][ + cl: #magenta + print "" + print color cl repeat "*" 30 + print color cl "* " ++ title + print color cl repeat "*" 30 +] + topic: function [title][ print "" - print repeat "*" 30 - print ["*" title] - print repeat "*" 30 + print spacer ++ repeat "*" 30 + print spacer ++ "* " ++ title + print spacer ++ repeat "*" 30 print "" - print repeat "-" 50 + print spacer ++ repeat "-" 50 ] byteCode: function [blk][ btc: to :bytecode blk - inspect btc + ;inspect btc + prints spacer print ["input:" as.code blk] + prints spacer print ["data:" get btc 'data] + prints spacer print ["code:" get btc 'code] - print repeat "-" 50 + print spacer ++ repeat "-" 50 ] ; Main unit-tests -;***************************************************************** -topic "Boolean values" -;***************************************************************** - -byteCode [true] -; ================================ -; DATA -; ================================ - -; ================================ -; CODE -; ================================ -; constbt -; end - -byteCode [false] -; ================================ -; DATA -; ================================ - -; ================================ -; CODE -; ================================ -; constbf -; end - -byteCode [maybe] -; ================================ -; DATA -; ================================ -; 0: maybe :word - -; ================================ -; CODE -; ================================ -; load0 -; end - -;***************************************************************** -topic "Integer values" -;***************************************************************** - -byteCode [1] -; ================================ -; DATA -; ================================ - -; ================================ -; CODE -; ================================ -; consti1 -; end - -byteCode [10] -; ================================ -; DATA -; ================================ - -; ================================ -; CODE -; ================================ -; consti10 -; end - -byteCode [123] -; ================================ -; DATA -; ================================ -; 0: 123 :integer - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode [1234567890123] -; ================================ -; DATA -; ================================ -; 0: 1234567890123 :integer - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "Floating values" -;***************************************************************** - -byteCode [0.0] -; ================================ -; DATA -; ================================ - -; ================================ -; CODE -; ================================ -; constf0 -; end - -byteCode [1.0] -; ================================ -; DATA -; ================================ - -; ================================ -; CODE -; ================================ -; constf1 -; end - -byteCode [10.0] -; ================================ -; DATA -; ================================ -; 0: 10.0 :floating - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode [12345.1234567] -; ================================ -; DATA -; ================================ -; 0: 12345.1234567 :floating - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "Char values" -;***************************************************************** - -byteCode [`a`] -; ================================ -; DATA -; ================================ -; 0: a :char - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode [`πŸ˜€`] -; ================================ -; DATA -; ================================ -; 0: πŸ˜€ :char - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "String values" -;***************************************************************** - -byteCode [""] -; ================================ -; DATA -; ================================ - -; ================================ -; CODE -; ================================ -; consts -; end - -byteCode ["Hello World!"] -; ================================ -; DATA -; ================================ -; 0: Hello World! :string - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "Regex values" -;***************************************************************** - -byteCode [{/hello/}] -; ================================ -; DATA -; ================================ -; 0: hello :regex - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode [{/[A-Z]+\d/}] -; ================================ -; DATA -; ================================ -; 0: [A-Z]+\d :regex - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "Type values" -;***************************************************************** - -byteCode [:integer] -; ================================ -; DATA -; ================================ -; 0: integer :type - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode [:string] -; ================================ -; DATA -; ================================ -; 0: string :type - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "Literal values" -;***************************************************************** - -byteCode ['a] -; ================================ -; DATA -; ================================ -; 0: a :literal - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode ['a 'b 'c] -; ================================ -; DATA -; ================================ -; 0: a :literal -; 1: b :literal -; 2: c :literal - -; ================================ -; CODE -; ================================ -; push0 -; push1 -; push2 -; end - -;***************************************************************** -topic "SymbolLiteral values" -;***************************************************************** - -byteCode ['+] -; ================================ -; DATA -; ================================ -; 0: + :symbolliteral - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode ['-->] -; ================================ -; DATA -; ================================ -; 0: --> :symbolliteral - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "Color values" -;***************************************************************** - -byteCode [#red] -; ================================ -; DATA -; ================================ -; 0: #FF0000 :color - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode [#00FF66] -; ================================ -; DATA -; ================================ -; 0: #00FF66 :color - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "Quantity values" -;***************************************************************** - -byteCode [1:EUR] -; ================================ -; DATA -; ================================ -; 0: 1:EUR :quantity - -; ================================ -; CODE -; ================================ -; push0 -; end - -byteCode [12:m] -; ================================ -; DATA -; ================================ -; 0: 12:m :quantity - -; ================================ -; CODE -; ================================ -; push0 -; end - -;***************************************************************** -topic "Null values" -;***************************************************************** - -byteCode [ΓΈ] -; ================================ -; DATA -; ================================ - -; ================================ -; CODE -; ================================ -; constn -; end - -byteCode [null] -; ================================ -; DATA -; ================================ -; 0: null :word - -; ================================ -; CODE -; ================================ -; load0 -; end +;///////////////////////////////////////////////////////// +supersection "SIMPLE VALUES" +;///////////////////////////////////////////////////////// + + ;***************************************************************** + topic "Boolean" + ;*******************************************Γ₯********************** + + byteCode [true] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constbt + ; end + + byteCode [false] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constbf + ; end + + byteCode [maybe] + ; ================================ + ; DATA + ; ================================ + ; 0: maybe :word + + ; ================================ + ; CODE + ; ================================ + ; load0 + ; end + + ;***************************************************************** + topic "Integer" + ;***************************************************************** + + byteCode [1] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti1 + ; end + + byteCode [10] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti10 + ; end + + byteCode [123] + ; ================================ + ; DATA + ; ================================ + ; 0: 123 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [1234567890123] + ; ================================ + ; DATA + ; ================================ + ; 0: 1234567890123 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "Floating" + ;***************************************************************** + + byteCode [0.0] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constf0 + ; end + + byteCode [1.0] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constf1 + ; end + + byteCode [10.0] + ; ================================ + ; DATA + ; ================================ + ; 0: 10.0 :floating + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [12345.1234567] + ; ================================ + ; DATA + ; ================================ + ; 0: 12345.1234567 :floating + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "Char" + ;***************************************************************** + + byteCode [`a`] + ; ================================ + ; DATA + ; ================================ + ; 0: a :char + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [`πŸ˜€`] + ; ================================ + ; DATA + ; ================================ + ; 0: πŸ˜€ :char + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "String" + ;***************************************************************** + + byteCode [""] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consts + ; end + + byteCode ["Hello World!"] + ; ================================ + ; DATA + ; ================================ + ; 0: Hello World! :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "Regex" + ;***************************************************************** + + byteCode [{/hello/}] + ; ================================ + ; DATA + ; ================================ + ; 0: hello :regex + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [{/[A-Z]+\d/}] + ; ================================ + ; DATA + ; ================================ + ; 0: [A-Z]+\d :regex + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "Type" + ;***************************************************************** + + byteCode [:integer] + ; ================================ + ; DATA + ; ================================ + ; 0: integer :type + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [:string] + ; ================================ + ; DATA + ; ================================ + ; 0: string :type + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "Literal" + ;***************************************************************** + + byteCode ['a] + ; ================================ + ; DATA + ; ================================ + ; 0: a :literal + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode ['a 'b 'c] + ; ================================ + ; DATA + ; ================================ + ; 0: a :literal + ; 1: b :literal + ; 2: c :literal + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; push2 + ; end + + ;***************************************************************** + topic "SymbolLiteral" + ;***************************************************************** + + byteCode ['+] + ; ================================ + ; DATA + ; ================================ + ; 0: + :symbolliteral + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode ['-->] + ; ================================ + ; DATA + ; ================================ + ; 0: --> :symbolliteral + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "Color" + ;***************************************************************** + + byteCode [#red] + ; ================================ + ; DATA + ; ================================ + ; 0: #FF0000 :color + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [#00FF66] + ; ================================ + ; DATA + ; ================================ + ; 0: #00FF66 :color + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "Quantity" + ;***************************************************************** + + byteCode [1:EUR] + ; ================================ + ; DATA + ; ================================ + ; 0: 1:EUR :quantity + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [12:m] + ; ================================ + ; DATA + ; ================================ + ; 0: 12:m :quantity + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "Null" + ;***************************************************************** + + byteCode [ΓΈ] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constn + ; end + + byteCode [null] + ; ================================ + ; DATA + ; ================================ + ; 0: null :word + + ; ================================ + ; CODE + ; ================================ + ; load0 + ; end From 022caa34ee0addd815005d0594979e4a5e934058 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:17:28 +0100 Subject: [PATCH 021/984] updated expected output --- tests/unittests/evaluator.res | 238 ++++++++++++++++++++++++++-------- 1 file changed, 184 insertions(+), 54 deletions(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 9e004e3fee..980c0e10c8 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -1,61 +1,191 @@ ****************************** -* Boolean values +* SIMPLE VALUES ****************************** --------------------------------------------------- -input: [true] -data: [] -code: [21 211] --------------------------------------------------- -input: [false] -data: [] -code: [22 211] --------------------------------------------------- -input: [maybe] -data: [maybe] -code: [64 211] --------------------------------------------------- + ****************************** + * Boolean + ****************************** -****************************** -* Integer values -****************************** + -------------------------------------------------- + input: [true] + data: [] + code: [21 211] + -------------------------------------------------- + input: [false] + data: [] + code: [22 211] + -------------------------------------------------- + input: [maybe] + data: [maybe] + code: [64 211] + -------------------------------------------------- --------------------------------------------------- -input: [1] -data: [] -code: [1 211] --------------------------------------------------- -input: [10] -data: [] -code: [10 211] --------------------------------------------------- -input: [123] -data: [123] -code: [32 211] --------------------------------------------------- -input: [1234567890123] -data: [1234567890123] -code: [32 211] --------------------------------------------------- + ****************************** + * Integer + ****************************** -****************************** -* Floating values -****************************** + -------------------------------------------------- + input: [1] + data: [] + code: [1 211] + -------------------------------------------------- + input: [10] + data: [] + code: [10 211] + -------------------------------------------------- + input: [123] + data: [123] + code: [32 211] + -------------------------------------------------- + input: [1234567890123] + data: [1234567890123] + code: [32 211] + -------------------------------------------------- + + ****************************** + * Floating + ****************************** + + -------------------------------------------------- + input: [0.0] + data: [] + code: [17 211] + -------------------------------------------------- + input: [1.0] + data: [] + code: [18 211] + -------------------------------------------------- + input: [10.0] + data: [10.0] + code: [32 211] + -------------------------------------------------- + input: [12345.1234567] + data: [12345.1234567] + code: [32 211] + -------------------------------------------------- + + ****************************** + * Char + ****************************** + + -------------------------------------------------- + input: [`a`] + data: [a] + code: [32 211] + -------------------------------------------------- + input: [`πŸ˜€`] + data: [πŸ˜€] + code: [32 211] + -------------------------------------------------- + + ****************************** + * String + ****************************** + + -------------------------------------------------- + input: [""] + data: [] + code: [24 211] + -------------------------------------------------- + input: ["Hello World!"] + data: [Hello World!] + code: [32 211] + -------------------------------------------------- + + ****************************** + * Regex + ****************************** + + -------------------------------------------------- + input: [{/hello/}] + data: [hello] + code: [32 211] + -------------------------------------------------- + input: [{/[A-Z]+\d/}] + data: [[A-Z]+\d] + code: [32 211] + -------------------------------------------------- + + ****************************** + * Type + ****************************** + + -------------------------------------------------- + input: [:integer] + data: [:integer] + code: [32 211] + -------------------------------------------------- + input: [:string] + data: [:string] + code: [32 211] + -------------------------------------------------- + + ****************************** + * Literal + ****************************** + + -------------------------------------------------- + input: ['a] + data: [a] + code: [32 211] + -------------------------------------------------- + input: ['a 'b 'c] + data: [a b c] + code: [32 33 34 211] + -------------------------------------------------- + + ****************************** + * SymbolLiteral + ****************************** + + -------------------------------------------------- + input: ['+] + data: [+] + code: [32 211] + -------------------------------------------------- + input: ['-->] + data: [-->] + code: [32 211] + -------------------------------------------------- + + ****************************** + * Color + ****************************** + + -------------------------------------------------- + input: [#FF0000] + data: [#FF0000] + code: [32 211] + -------------------------------------------------- + input: [#00FF66] + data: [#00FF66] + code: [32 211] + -------------------------------------------------- + + ****************************** + * Quantity + ****************************** + + -------------------------------------------------- + input: [1:eur] + data: [1EUR] + code: [32 211] + -------------------------------------------------- + input: [12:m] + data: [12m] + code: [32 211] + -------------------------------------------------- + + ****************************** + * Null + ****************************** --------------------------------------------------- -input: [0.0] -data: [] -code: [17 211] --------------------------------------------------- -input: [1.0] -data: [] -code: [18 211] --------------------------------------------------- -input: [10.0] -data: [10.0] -code: [32 211] --------------------------------------------------- -input: [12345.1234567] -data: [12345.1234567] -code: [32 211] --------------------------------------------------- \ No newline at end of file + -------------------------------------------------- + input: [βˆ…] + data: [] + code: [27 211] + -------------------------------------------------- + input: [null] + data: [null] + code: [64 211] + -------------------------------------------------- \ No newline at end of file From af8439e7c3e48aa656d93ab1513408bcb39b1ba8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:24:37 +0100 Subject: [PATCH 022/984] Unittests/evaluator: added tests for Block values --- tests/unittests/evaluator.art | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index b47b3f074b..4192045af4 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -21,7 +21,7 @@ topic: function [title][ byteCode: function [blk][ btc: to :bytecode blk - ;inspect btc + inspect btc prints spacer print ["input:" as.code blk] prints spacer @@ -402,6 +402,38 @@ supersection "SIMPLE VALUES" ; push0 ; end + ;***************************************************************** + topic "Block" + ;***************************************************************** + + byteCode [[]] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consta + ; end + + byteCode [[1 "hello" 3.14 true]] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 1 :integer + ; hello :string + ; 3.14 :floating + ; true :word + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + ;***************************************************************** topic "Null" ;***************************************************************** From dc8beb6284841aed6058b72ac4f9539f0e74f29b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:38:17 +0100 Subject: [PATCH 023/984] Unittests/evaluator: added tests for Setting & getting variables --- tests/unittests/evaluator.art | 45 ++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 4192045af4..cae2c0d8e8 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -20,7 +20,8 @@ topic: function [title][ ] byteCode: function [blk][ - btc: to :bytecode blk + btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block + ; thus, avoiding all opEol/opEolX bytecode being produced inspect btc prints spacer print ["input:" as.code blk] @@ -460,3 +461,45 @@ supersection "SIMPLE VALUES" ; ================================ ; load0 ; end + +;///////////////////////////////////////////////////////// +supersection "COMPOSITE CONSTRUCTS" +;///////////////////////////////////////////////////////// + + ;***************************************************************** + topic "Setting and getting variables" + ;***************************************************************** + + byteCode [ + a: 1 + ] + ; ================================ + ; DATA + ; ================================ + ; 0: a :label + + ; ================================ + ; CODE + ; ================================ + ; consti1 + ; store0 + ; end + + byteCode [ + b: 2 + c: b + ] + ; ================================ + ; DATA + ; ================================ + ; 0: b :label + ; 1: c :label + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; store0 + ; load0 + ; store1 + ; end \ No newline at end of file From f774655feac368ec3d5f68ea9e6fe7bbd086e05d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:38:41 +0100 Subject: [PATCH 024/984] Unittests/evaluator: added tests for Simple built-in function calls --- tests/unittests/evaluator.art | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index cae2c0d8e8..4642ae81a8 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -502,4 +502,56 @@ supersection "COMPOSITE CONSTRUCTS" ; store0 ; load0 ; store1 + ; end + + ;***************************************************************** + topic "Simple built-in function calls" + ;***************************************************************** + + byteCode [abs 10] + ; ================================ + ; DATA + ; ================================ + ; 0: abs :word + + ; ================================ + ; CODE + ; ================================ + ; consti10 + ; call0 + ; end + + byteCode [empty? []] + ; ================================ + ; DATA + ; ================================ + ; 0: empty? :word + + ; ================================ + ; CODE + ; ================================ + ; consta + ; call0 + ; end + + byteCode [couple [1 2] ["one" "two"]] + ; ================================ + ; DATA + ; ================================ + ; 0: couple :word + ; 1: [ :block + ; 1 :integer + ; 2 :integer + ; ] + ; 2: [ :block + ; one :string + ; two :string + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; call0 ; end \ No newline at end of file From db2412ceb6b71f5093122926c5ecb3be04b5eddd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:40:35 +0100 Subject: [PATCH 025/984] improved styling (with appropriate indentation for each "topic") --- tests/unittests/evaluator.art | 878 +++++++++++++++++----------------- 1 file changed, 439 insertions(+), 439 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 4642ae81a8..ee52c524fd 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -42,425 +42,425 @@ supersection "SIMPLE VALUES" topic "Boolean" ;*******************************************Γ₯********************** - byteCode [true] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; constbt - ; end - - byteCode [false] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; constbf - ; end - - byteCode [maybe] - ; ================================ - ; DATA - ; ================================ - ; 0: maybe :word - - ; ================================ - ; CODE - ; ================================ - ; load0 - ; end + byteCode [true] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constbt + ; end + + byteCode [false] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constbf + ; end + + byteCode [maybe] + ; ================================ + ; DATA + ; ================================ + ; 0: maybe :word + + ; ================================ + ; CODE + ; ================================ + ; load0 + ; end ;***************************************************************** topic "Integer" ;***************************************************************** - byteCode [1] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; consti1 - ; end - - byteCode [10] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; consti10 - ; end - - byteCode [123] - ; ================================ - ; DATA - ; ================================ - ; 0: 123 :integer - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode [1234567890123] - ; ================================ - ; DATA - ; ================================ - ; 0: 1234567890123 :integer - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [1] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti1 + ; end + + byteCode [10] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti10 + ; end + + byteCode [123] + ; ================================ + ; DATA + ; ================================ + ; 0: 123 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [1234567890123] + ; ================================ + ; DATA + ; ================================ + ; 0: 1234567890123 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Floating" ;***************************************************************** - byteCode [0.0] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; constf0 - ; end - - byteCode [1.0] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; constf1 - ; end - - byteCode [10.0] - ; ================================ - ; DATA - ; ================================ - ; 0: 10.0 :floating - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode [12345.1234567] - ; ================================ - ; DATA - ; ================================ - ; 0: 12345.1234567 :floating - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [0.0] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constf0 + ; end + + byteCode [1.0] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constf1 + ; end + + byteCode [10.0] + ; ================================ + ; DATA + ; ================================ + ; 0: 10.0 :floating + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [12345.1234567] + ; ================================ + ; DATA + ; ================================ + ; 0: 12345.1234567 :floating + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Char" ;***************************************************************** - byteCode [`a`] - ; ================================ - ; DATA - ; ================================ - ; 0: a :char - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode [`πŸ˜€`] - ; ================================ - ; DATA - ; ================================ - ; 0: πŸ˜€ :char - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [`a`] + ; ================================ + ; DATA + ; ================================ + ; 0: a :char + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [`πŸ˜€`] + ; ================================ + ; DATA + ; ================================ + ; 0: πŸ˜€ :char + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "String" ;***************************************************************** - byteCode [""] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; consts - ; end - - byteCode ["Hello World!"] - ; ================================ - ; DATA - ; ================================ - ; 0: Hello World! :string - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [""] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consts + ; end + + byteCode ["Hello World!"] + ; ================================ + ; DATA + ; ================================ + ; 0: Hello World! :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Regex" ;***************************************************************** - byteCode [{/hello/}] - ; ================================ - ; DATA - ; ================================ - ; 0: hello :regex - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode [{/[A-Z]+\d/}] - ; ================================ - ; DATA - ; ================================ - ; 0: [A-Z]+\d :regex - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [{/hello/}] + ; ================================ + ; DATA + ; ================================ + ; 0: hello :regex + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [{/[A-Z]+\d/}] + ; ================================ + ; DATA + ; ================================ + ; 0: [A-Z]+\d :regex + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Type" ;***************************************************************** - byteCode [:integer] - ; ================================ - ; DATA - ; ================================ - ; 0: integer :type - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode [:string] - ; ================================ - ; DATA - ; ================================ - ; 0: string :type - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [:integer] + ; ================================ + ; DATA + ; ================================ + ; 0: integer :type + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [:string] + ; ================================ + ; DATA + ; ================================ + ; 0: string :type + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Literal" ;***************************************************************** - byteCode ['a] - ; ================================ - ; DATA - ; ================================ - ; 0: a :literal - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode ['a 'b 'c] - ; ================================ - ; DATA - ; ================================ - ; 0: a :literal - ; 1: b :literal - ; 2: c :literal - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; push1 - ; push2 - ; end + byteCode ['a] + ; ================================ + ; DATA + ; ================================ + ; 0: a :literal + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode ['a 'b 'c] + ; ================================ + ; DATA + ; ================================ + ; 0: a :literal + ; 1: b :literal + ; 2: c :literal + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; push2 + ; end ;***************************************************************** topic "SymbolLiteral" ;***************************************************************** - byteCode ['+] - ; ================================ - ; DATA - ; ================================ - ; 0: + :symbolliteral - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode ['-->] - ; ================================ - ; DATA - ; ================================ - ; 0: --> :symbolliteral - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode ['+] + ; ================================ + ; DATA + ; ================================ + ; 0: + :symbolliteral + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode ['-->] + ; ================================ + ; DATA + ; ================================ + ; 0: --> :symbolliteral + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Color" ;***************************************************************** - byteCode [#red] - ; ================================ - ; DATA - ; ================================ - ; 0: #FF0000 :color - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode [#00FF66] - ; ================================ - ; DATA - ; ================================ - ; 0: #00FF66 :color - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [#red] + ; ================================ + ; DATA + ; ================================ + ; 0: #FF0000 :color + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [#00FF66] + ; ================================ + ; DATA + ; ================================ + ; 0: #00FF66 :color + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Quantity" ;***************************************************************** - byteCode [1:EUR] - ; ================================ - ; DATA - ; ================================ - ; 0: 1:EUR :quantity - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end - - byteCode [12:m] - ; ================================ - ; DATA - ; ================================ - ; 0: 12:m :quantity - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [1:EUR] + ; ================================ + ; DATA + ; ================================ + ; 0: 1:EUR :quantity + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [12:m] + ; ================================ + ; DATA + ; ================================ + ; 0: 12:m :quantity + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Block" ;***************************************************************** - byteCode [[]] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; consta - ; end - - byteCode [[1 "hello" 3.14 true]] - ; ================================ - ; DATA - ; ================================ - ; 0: [ :block - ; 1 :integer - ; hello :string - ; 3.14 :floating - ; true :word - ; ] - - ; ================================ - ; CODE - ; ================================ - ; push0 - ; end + byteCode [[]] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consta + ; end + + byteCode [[1 "hello" 3.14 true]] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 1 :integer + ; hello :string + ; 3.14 :floating + ; true :word + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end ;***************************************************************** topic "Null" ;***************************************************************** - byteCode [ΓΈ] - ; ================================ - ; DATA - ; ================================ - - ; ================================ - ; CODE - ; ================================ - ; constn - ; end - - byteCode [null] - ; ================================ - ; DATA - ; ================================ - ; 0: null :word - - ; ================================ - ; CODE - ; ================================ - ; load0 - ; end + byteCode [ΓΈ] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constn + ; end + + byteCode [null] + ; ================================ + ; DATA + ; ================================ + ; 0: null :word + + ; ================================ + ; CODE + ; ================================ + ; load0 + ; end ;///////////////////////////////////////////////////////// supersection "COMPOSITE CONSTRUCTS" @@ -470,88 +470,88 @@ supersection "COMPOSITE CONSTRUCTS" topic "Setting and getting variables" ;***************************************************************** - byteCode [ - a: 1 - ] - ; ================================ - ; DATA - ; ================================ - ; 0: a :label - - ; ================================ - ; CODE - ; ================================ - ; consti1 - ; store0 - ; end - - byteCode [ - b: 2 - c: b - ] - ; ================================ - ; DATA - ; ================================ - ; 0: b :label - ; 1: c :label - - ; ================================ - ; CODE - ; ================================ - ; consti2 - ; store0 - ; load0 - ; store1 - ; end + byteCode [ + a: 1 + ] + ; ================================ + ; DATA + ; ================================ + ; 0: a :label + + ; ================================ + ; CODE + ; ================================ + ; consti1 + ; store0 + ; end + + byteCode [ + b: 2 + c: b + ] + ; ================================ + ; DATA + ; ================================ + ; 0: b :label + ; 1: c :label + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; store0 + ; load0 + ; store1 + ; end ;***************************************************************** topic "Simple built-in function calls" ;***************************************************************** - byteCode [abs 10] - ; ================================ - ; DATA - ; ================================ - ; 0: abs :word - - ; ================================ - ; CODE - ; ================================ - ; consti10 - ; call0 - ; end - - byteCode [empty? []] - ; ================================ - ; DATA - ; ================================ - ; 0: empty? :word - - ; ================================ - ; CODE - ; ================================ - ; consta - ; call0 - ; end - - byteCode [couple [1 2] ["one" "two"]] - ; ================================ - ; DATA - ; ================================ - ; 0: couple :word - ; 1: [ :block - ; 1 :integer - ; 2 :integer - ; ] - ; 2: [ :block - ; one :string - ; two :string - ; ] - - ; ================================ - ; CODE - ; ================================ - ; push2 - ; push1 - ; call0 - ; end \ No newline at end of file + byteCode [abs 10] + ; ================================ + ; DATA + ; ================================ + ; 0: abs :word + + ; ================================ + ; CODE + ; ================================ + ; consti10 + ; call0 + ; end + + byteCode [empty? []] + ; ================================ + ; DATA + ; ================================ + ; 0: empty? :word + + ; ================================ + ; CODE + ; ================================ + ; consta + ; call0 + ; end + + byteCode [couple [1 2] ["one" "two"]] + ; ================================ + ; DATA + ; ================================ + ; 0: couple :word + ; 1: [ :block + ; 1 :integer + ; 2 :integer + ; ] + ; 2: [ :block + ; one :string + ; two :string + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; call0 + ; end \ No newline at end of file From 37f638b4f1ff620ffd38beb2a0aff100a9c16495 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:45:12 +0100 Subject: [PATCH 026/984] Unittests/evaluator: added tests for Opcoded built-in function calls --- tests/unittests/evaluator.art | 48 ++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index ee52c524fd..72b66cfdf3 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -505,7 +505,7 @@ supersection "COMPOSITE CONSTRUCTS" ; end ;***************************************************************** - topic "Simple built-in function calls" + topic "Built-in function calls" ;***************************************************************** byteCode [abs 10] @@ -554,4 +554,50 @@ supersection "COMPOSITE CONSTRUCTS" ; push2 ; push1 ; call0 + ; end + + ;***************************************************************** + topic "Opcoded built-in function calls" + ;***************************************************************** + + byteCode [print 2] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; print + ; end + + byteCode [size [1 2]] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 1 :integer + ; 2 :integer + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; size + ; end + + byteCode [and 1 123] + ; ================================ + ; DATA + ; ================================ + ; 0: 123 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; consti1 + ; band ; end \ No newline at end of file From edcefc3c434d477e76c1190be448992e3f0c86bc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:47:53 +0100 Subject: [PATCH 027/984] Unittests/evaluator: added tests for Function calls with attributes --- tests/unittests/evaluator.art | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 72b66cfdf3..3f836ee051 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -600,4 +600,61 @@ supersection "COMPOSITE CONSTRUCTS" ; push0 ; consti1 ; band + ; end + + ;***************************************************************** + topic "Function calls with attributes" + ;***************************************************************** + + byteCode [split.words "hello world"] + ; ================================ + ; DATA + ; ================================ + ; 0: words :attribute + ; 1: hello world :string + + ; ================================ + ; CODE + ; ================================ + ; push1 + ; constbt + ; attr0 + ; split + ; end + + byteCode [split.by:"X" "helloXworld"] + ; ================================ + ; DATA + ; ================================ + ; 0: by :attributelabel + ; 1: X :string + ; 2: helloXworld :string + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; attr0 + ; split + ; end + + byteCode [join.with:"-" ["hello" "world"]] + ; ================================ + ; DATA + ; ================================ + ; 0: with :attributelabel + ; 1: - :string + ; 2: [ :block + ; hello :string + ; world :string + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; attr0 + ; join ; end \ No newline at end of file From 13868a26cc23c7627382b53f6b162621b6b4da48 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:55:21 +0100 Subject: [PATCH 028/984] re-styling --- tests/unittests/evaluator.art | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 3f836ee051..3ee7fef575 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -5,31 +5,35 @@ spacer: " " supersection: function [title][ cl: #magenta print "" - print color cl repeat "*" 30 + print color cl repeat "*" 50 + print color cl "*" print color cl "* " ++ title - print color cl repeat "*" 30 + print color cl "*" + print color cl repeat "*" 50 ] topic: function [title][ print "" - print spacer ++ repeat "*" 30 - print spacer ++ "* " ++ title - print spacer ++ repeat "*" 30 + print spacer ++ ">" ++ repeat "-" 50 + print spacer ++ "> " ++ color.bold #white title + print spacer ++ ">" ++ repeat "-" 50 print "" - print spacer ++ repeat "-" 50 ] byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - inspect btc + + inspect btc ; uncomment this line to see the bytecode + ; in a more readable format prints spacer print ["input:" as.code blk] prints spacer print ["data:" get btc 'data] prints spacer - print ["code:" get btc 'code] - print spacer ++ repeat "-" 50 + cd: get btc 'code + print ["code:" cd "(" ++ (to :string size cd) ++ " bytes)"] + print "" ] ; Main unit-tests From 90e39869b16d710db263989386028c42c894ea7e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 13:58:33 +0100 Subject: [PATCH 029/984] Unittests/evaluator: added tests for Function calls via symbol aliases --- tests/unittests/evaluator.art | 55 +++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 3ee7fef575..dae92e4a1d 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -23,7 +23,7 @@ topic: function [title][ byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - + inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer @@ -661,4 +661,55 @@ supersection "COMPOSITE CONSTRUCTS" ; push1 ; attr0 ; join - ; end \ No newline at end of file + ; end + + ;***************************************************************** + topic "Function calls via symbol aliases" + ;***************************************************************** + + byteCode [@[1 2 3]] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 1 :integer + ; 2 :integer + ; 3 :integer + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; array + ; end + + byteCode ["hello " ++ "world"] + ; ================================ + ; DATA + ; ================================ + ; 0: append :word + ; 1: hello :string + ; 2: world :string + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; call0 + ; end + + byteCode [1..25] + ; ================================ + ; DATA + ; ================================ + ; 0: 25 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; consti1 + ; range + ; end From 8e68ec19f9c9a0f1eda6ad22e7d13c137f3d83a7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 14:05:38 +0100 Subject: [PATCH 030/984] Unittests/evaluator: added tests for User function definitions & calling --- tests/unittests/evaluator.art | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index dae92e4a1d..54bab2c28a 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -713,3 +713,121 @@ supersection "COMPOSITE CONSTRUCTS" ; consti1 ; range ; end + + ;***************************************************************** + topic "User function definition & calling" + ;***************************************************************** + + byteCode [ + h: function [][print "function called"] + + print "before" + h + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: h :label + ; 1: [ :block + ; print :word + ; function called :string + ; ] + ; 2: before :string + ; 3: after :string + + ; ================================ + ; CODE + ; ================================ + ; push1 + ; consta + ; func + ; store0 + ; push2 + ; print + ; call0 + ; push3 + ; print + ; end + + byteCode [ + f: function [x][x + 1] + + print "before" + print f 10 + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: f :label + ; 1: [ :block + ; x :word + ; ] + ; 2: [ :block + ; x :word + ; + :symbol + ; 1 :integer + ; ] + ; 3: before :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; func + ; store0 + ; push3 + ; print + ; consti10 + ; call0 + ; print + ; push4 + ; print + ; end + + byteCode [ + g: $[z w][2 * z * w] + + print "before" + print g 10 20 + print "after" + ] + + ; ================================ + ; DATA + ; ================================ + ; 0: g :label + ; 1: [ :block + ; z :word + ; w :word + ; ] + ; 2: [ :block + ; 2 :integer + ; * :symbol + ; z :word + ; * :symbol + ; w :word + ; ] + ; 3: before :string + ; 4: 20 :integer + ; 5: after :string + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; func + ; store0 + ; push3 + ; print + ; push4 + ; consti10 + ; call0 + ; print + ; push5 + ; print + ; end From 5d4a665634b3d53eaf2d4403cbe4421747ccb823 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 14:15:14 +0100 Subject: [PATCH 031/984] Unittests/evaluator: added new section ("PATHS") + minor re-organization & cleanup --- tests/unittests/evaluator.art | 156 +++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 54bab2c28a..a952f661df 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -467,7 +467,7 @@ supersection "SIMPLE VALUES" ; end ;///////////////////////////////////////////////////////// -supersection "COMPOSITE CONSTRUCTS" +supersection "LABELS" ;///////////////////////////////////////////////////////// ;***************************************************************** @@ -508,6 +508,10 @@ supersection "COMPOSITE CONSTRUCTS" ; store1 ; end +;///////////////////////////////////////////////////////// +supersection "FUNCTION CALLS" +;///////////////////////////////////////////////////////// + ;***************************************************************** topic "Built-in function calls" ;***************************************************************** @@ -831,3 +835,153 @@ supersection "COMPOSITE CONSTRUCTS" ; push5 ; print ; end + +;///////////////////////////////////////////////////////// +supersection "PATHS" +;///////////////////////////////////////////////////////// + + ;***************************************************************** + topic "Path values" + ;***************************************************************** + + byteCode [a\0] + ; ================================ + ; DATA + ; ================================ + ; 0: a :word + ; 1: 0 :integer + + ; ================================ + ; CODE + ; ================================ + ; push1 + ; load0 + ; get + ; end + + byteCode [user\name] + ; ================================ + ; DATA + ; ================================ + ; 0: user :word + ; 1: name :literal + + ; ================================ + ; CODE + ; ================================ + ; push1 + ; load0 + ; get + ; end + + byteCode [user\grades\0] + ; ================================ + ; DATA + ; ================================ + ; 0: user :word + ; 1: grades :literal + ; 2: 0 :integer + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; load0 + ; get + ; get + ; end + + byteCode [user\address\country] + ; ================================ + ; DATA + ; ================================ + ; 0: user :word + ; 1: address :literal + ; 2: country :literal + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; load0 + ; get + ; get + ; end + + ;***************************************************************** + topic "PathLabel values" + ;***************************************************************** + + byteCode [a\0: 10] + ; ================================ + ; DATA + ; ================================ + ; 0: a :word + ; 1: 0 :integer + + ; ================================ + ; CODE + ; ================================ + ; consti10 + ; push1 + ; load0 + ; set + ; end + + byteCode [user\name: "John"] + ; ================================ + ; DATA + ; ================================ + ; 0: user :word + ; 1: name :literal + ; 2: John :string + + ; ================================ + ; CODE + ; ================================ + ; push2 + ; push1 + ; load0 + ; set + ; end + + byteCode [user\grades\0: 6] + ; ================================ + ; DATA + ; ================================ + ; 0: user :word + ; 1: grades :literal + ; 2: 0 :integer + + ; ================================ + ; CODE + ; ================================ + ; consti6 + ; push2 + ; push1 + ; load0 + ; get + ; set + ; end + + byteCode [user\address\country: "USA"] + ; ================================ + ; DATA + ; ================================ + ; 0: user :word + ; 1: address :literal + ; 2: country :literal + ; 3: USA :string + + ; ================================ + ; CODE + ; ================================ + ; push3 + ; push2 + ; push1 + ; load0 + ; get + ; set + ; end \ No newline at end of file From 8ff99703dd82f9eb2a757e753b1138cacf5ca164 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 14:17:22 +0100 Subject: [PATCH 032/984] added TODOs --- src/vm/eval.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 162487b931..b6f89988d7 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -911,6 +911,9 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = argStack[argStack.len-1] += 1 of Path: + # TODO(VM/eval) Path values containing fixed constants not processed correctly + # `a\0` should actually produce an `opConstI0` and not a LOAD + # labels: evaluator, enhancement var pathCallV: Value = nil if (let curr = Syms.getOrDefault(node.p[0].s, nil); not curr.isNil): @@ -948,6 +951,10 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = i += 1 of PathLabel: + # TODO(VM/eval) PathLabels values containing fixed constants not processed correctly + # `a\0: 10` should actually produce an `opConstI0` and not a LOAD + # (same situation as with Path values) + # labels: evaluator, enhancement addToCommand(opSet) var i=1 From 6d87e3a8ea05d29199439df2b7cd48d694c6aa36 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 14:18:20 +0100 Subject: [PATCH 033/984] updated expected result --- tests/unittests/evaluator.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index a952f661df..0b30595640 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - inspect btc ; uncomment this line to see the bytecode + ;inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] From 303ee2aa93c1b193a510b519c3b865412515cd58 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 14:22:17 +0100 Subject: [PATCH 034/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ff12ddff7b..1391eeb817 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3472 \ No newline at end of file +3473 \ No newline at end of file From 2f2277d14da17e247453444b3292e6f98a54067a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 14:22:44 +0100 Subject: [PATCH 035/984] updated expected result --- tests/unittests/evaluator.res | 376 ++++++++++++++++++++++++---------- 1 file changed, 268 insertions(+), 108 deletions(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 980c0e10c8..6ff76bbcda 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -1,191 +1,351 @@ -****************************** +************************************************** +* * SIMPLE VALUES -****************************** +* +************************************************** - ****************************** - * Boolean - ****************************** + >-------------------------------------------------- + > Boolean + >-------------------------------------------------- - -------------------------------------------------- input: [true] data: [] - code: [21 211] - -------------------------------------------------- + code: [21 211] (2 bytes) + input: [false] data: [] - code: [22 211] - -------------------------------------------------- + code: [22 211] (2 bytes) + input: [maybe] data: [maybe] - code: [64 211] - -------------------------------------------------- + code: [64 211] (2 bytes) + - ****************************** - * Integer - ****************************** + >-------------------------------------------------- + > Integer + >-------------------------------------------------- - -------------------------------------------------- input: [1] data: [] - code: [1 211] - -------------------------------------------------- + code: [1 211] (2 bytes) + input: [10] data: [] - code: [10 211] - -------------------------------------------------- + code: [10 211] (2 bytes) + input: [123] data: [123] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: [1234567890123] data: [1234567890123] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + - ****************************** - * Floating - ****************************** + >-------------------------------------------------- + > Floating + >-------------------------------------------------- - -------------------------------------------------- input: [0.0] data: [] - code: [17 211] - -------------------------------------------------- + code: [17 211] (2 bytes) + input: [1.0] data: [] - code: [18 211] - -------------------------------------------------- + code: [18 211] (2 bytes) + input: [10.0] data: [10.0] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: [12345.1234567] data: [12345.1234567] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) - ****************************** - * Char - ****************************** - -------------------------------------------------- + >-------------------------------------------------- + > Char + >-------------------------------------------------- + input: [`a`] data: [a] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: [`πŸ˜€`] data: [πŸ˜€] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + - ****************************** - * String - ****************************** + >-------------------------------------------------- + > String + >-------------------------------------------------- - -------------------------------------------------- input: [""] data: [] - code: [24 211] - -------------------------------------------------- + code: [24 211] (2 bytes) + input: ["Hello World!"] data: [Hello World!] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + - ****************************** - * Regex - ****************************** + >-------------------------------------------------- + > Regex + >-------------------------------------------------- - -------------------------------------------------- input: [{/hello/}] data: [hello] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: [{/[A-Z]+\d/}] data: [[A-Z]+\d] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + - ****************************** - * Type - ****************************** + >-------------------------------------------------- + > Type + >-------------------------------------------------- - -------------------------------------------------- input: [:integer] data: [:integer] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: [:string] data: [:string] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) - ****************************** - * Literal - ****************************** - -------------------------------------------------- + >-------------------------------------------------- + > Literal + >-------------------------------------------------- + input: ['a] data: [a] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: ['a 'b 'c] data: [a b c] - code: [32 33 34 211] - -------------------------------------------------- + code: [32 33 34 211] (4 bytes) - ****************************** - * SymbolLiteral - ****************************** - -------------------------------------------------- + >-------------------------------------------------- + > SymbolLiteral + >-------------------------------------------------- + input: ['+] data: [+] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: ['-->] data: [-->] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + - ****************************** - * Color - ****************************** + >-------------------------------------------------- + > Color + >-------------------------------------------------- - -------------------------------------------------- input: [#FF0000] data: [#FF0000] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: [#00FF66] data: [#00FF66] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + - ****************************** - * Quantity - ****************************** + >-------------------------------------------------- + > Quantity + >-------------------------------------------------- - -------------------------------------------------- input: [1:eur] data: [1EUR] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + input: [12:m] data: [12m] - code: [32 211] - -------------------------------------------------- + code: [32 211] (2 bytes) + + + >-------------------------------------------------- + > Block + >-------------------------------------------------- + + input: [[]] + data: [] + code: [25 211] (2 bytes) - ****************************** - * Null - ****************************** + input: [[1 "hello" 3.14 true]] + data: [[1 hello 3.14 true]] + code: [32 211] (2 bytes) + + + >-------------------------------------------------- + > Null + >-------------------------------------------------- - -------------------------------------------------- input: [βˆ…] data: [] - code: [27 211] - -------------------------------------------------- + code: [27 211] (2 bytes) + input: [null] data: [null] - code: [64 211] - -------------------------------------------------- \ No newline at end of file + code: [64 211] (2 bytes) + + +************************************************** +* +* LABELS +* +************************************************** + + >-------------------------------------------------- + > Setting and getting variables + >-------------------------------------------------- + + input: [a: 1] + data: [a] + code: [1 48 211] (3 bytes) + + input: [b: 2 c: b] + data: [b c] + code: [2 48 64 49 211] (5 bytes) + + +************************************************** +* +* FUNCTION CALLS +* +************************************************** + + >-------------------------------------------------- + > Built-in function calls + >-------------------------------------------------- + + input: [abs 10] + data: [abs] + code: [10 96 211] (3 bytes) + + input: [empty? []] + data: [empty?] + code: [25 96 211] (3 bytes) + + input: [couple [1 2] ["one" "two"]] + data: [couple [1 2] [one two]] + code: [34 33 96 211] (4 bytes) + + + >-------------------------------------------------- + > Opcoded built-in function calls + >-------------------------------------------------- + + input: [print 2] + data: [] + code: [2 176 211] (3 bytes) + + input: [size [1 2]] + data: [[1 2]] + code: [32 169 211] (3 bytes) + + input: [and 1 123] + data: [123] + code: [32 1 137 211] (4 bytes) + + + >-------------------------------------------------- + > Function calls with attributes + >-------------------------------------------------- + + input: [split .words "hello world"] + data: [words hello world] + code: [33 21 112 171 211] (5 bytes) + + input: [split .by: "X" "helloXworld"] + data: [by X helloXworld] + code: [34 33 112 171 211] (5 bytes) + + input: [join .with: "-" ["hello" "world"]] + data: [with - [hello world]] + code: [34 33 112 172 211] (5 bytes) + + + >-------------------------------------------------- + > Function calls via symbol aliases + >-------------------------------------------------- + + input: [@ [1 2 3]] + data: [[1 2 3]] + code: [32 162 211] (3 bytes) + + input: ["hello " ++ "world"] + data: [append hello world] + code: [34 33 96 211] (4 bytes) + + input: [1 .. 25] + data: [25] + code: [32 1 165 211] (4 bytes) + + + >-------------------------------------------------- + > User function definition & calling + >-------------------------------------------------- + + input: [h: function [] [print "function called"] print "before" h print "after"] + data: [h [print function called] before after] + code: [33 25 164 48 34 176 96 35 176 211] (10 bytes) + + input: [f: function [x] [x + 1] print "before" print f 10 print "after"] + data: [f [x] [x + 1] before after] + code: [34 33 164 48 35 176 10 96 176 36 176 211] (12 bytes) + + input: [g: $ [z w] [2 * z * w] print "before" print g 10 20 print "after"] + data: [g [z w] [2 * z * w] before 20 after] + code: [34 33 164 48 35 176 36 10 96 176 37 176 211] (13 bytes) + + +************************************************** +* +* PATHS +* +************************************************** + + >-------------------------------------------------- + > Path values + >-------------------------------------------------- + + input: [] + data: [a 0] + code: [33 64 160 211] (4 bytes) + + input: [] + data: [user name] + code: [33 64 160 211] (4 bytes) + + input: [] + data: [user grades 0] + code: [34 33 64 160 160 211] (6 bytes) + + input: [] + data: [user address country] + code: [34 33 64 160 160 211] (6 bytes) + + + >-------------------------------------------------- + > PathLabel values + >-------------------------------------------------- + + input: [ 10] + data: [a 0] + code: [10 33 64 161 211] (5 bytes) + + input: [ "John"] + data: [user name John] + code: [34 33 64 161 211] (5 bytes) + + input: [ 6] + data: [user grades 0] + code: [6 34 33 64 160 161 211] (7 bytes) + + input: [ "USA"] + data: [user address country USA] + code: [35 34 33 64 160 161 211] (7 bytes) \ No newline at end of file From 6bec835291dacdc926fa1f9c4d47ab0e913eeaa8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 16:07:01 +0100 Subject: [PATCH 036/984] Unittests/evaluator: added tests for Version values --- tests/unittests/evaluator.art | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 0b30595640..d6683e437f 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - ;inspect btc ; uncomment this line to see the bytecode + inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] @@ -407,6 +407,34 @@ supersection "SIMPLE VALUES" ; push0 ; end + ;***************************************************************** + topic "Version" + ;***************************************************************** + + byteCode [0.9.82] + ; ================================ + ; DATA + ; ================================ + ; 0: 0.9.82 :version + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [2.0.0-rc1] + ; ================================ + ; DATA + ; ================================ + ; 0: 2.0.0-rc1 :version + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + ;***************************************************************** topic "Block" ;***************************************************************** From f40634770d73d5c95759b10ad12986b4168b3622 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 16:29:45 +0100 Subject: [PATCH 037/984] added TODO --- src/vm/eval.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index b6f89988d7..1b50a2e2a4 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -188,6 +188,8 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = ], atPos) proc evalFunctionCall(currentCommand: var VBinary, fun: var Value, toHead: bool, checkAhead: bool, i: var int, funcArity: var int8): bool {.enforceNoRaises.} = + # TODO(VM/eval) `do` should also correspond to a distinct opCode + # labels: vm, bytecode, evaluator, enhancement, performance var bt: OpCode = opNop var doElse = true From 04d3c4d21388891ee7355ca1d2fb52cf4bf60c62 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 16:30:01 +0100 Subject: [PATCH 038/984] Unittests/evaluator: added tests for Blocks & Syntactic sugar --- tests/unittests/evaluator.art | 252 ++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index d6683e437f..88c98d7540 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1012,4 +1012,256 @@ supersection "PATHS" ; load0 ; get ; set + ; end + +;///////////////////////////////////////////////////////// +supersection "BLOCKS & SYNTACTIC SUGAR" +;///////////////////////////////////////////////////////// + + ;***************************************************************** + topic "Inline blocks" + ;***************************************************************** + + byteCode [(print 2)] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; print + ; end + + byteCode [(print 2) (print 3)] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; print + ; consti3 + ; print + ; end + + ; TODO: this is not working!!! (see #804) + ; byteCode [(print 2 print 3)] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; print + ; consti3 + ; print + ; end + + ;***************************************************************** + topic "doublecolon syntactic sugar (`::`)" + ;***************************************************************** + + byteCode [ + print 2 + do :: + print 3 + ] + ; ================================ + ; DATA + ; ================================ + ; 0: do :word + ; 1: [ :block + ; print :word + ; 3 :integer + ; ] + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; print + ; push1 + ; call0 + ; end + + ;***************************************************************** + topic "arrowright syntactic sugar (`->`)" + ;***************************************************************** + + byteCode [-> "hello"] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; hello :string + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + byteCode [ + do -> print "hello" + print "done" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: do :word + ; 1: [ :block + ; print :word + ; hello :string + ; ] + ; 2: done :string + + ; ================================ + ; CODE + ; ================================ + ; push1 + ; call0 + ; push2 + ; print + ; end + + byteCode [ + a: -> upper "hello" + b: -> "hello " ++ world + ] + ; ================================ + ; DATA + ; ================================ + ; 0: a :label + ; 1: [ :block + ; upper :word + ; hello :string + ; ] + ; 2: b :label + ; 3: [ :block + ; hello :string + ; ++ :symbol + ; world :word + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push1 + ; store0 + ; push3 + ; store2 + ; end + + ;***************************************************************** + topic "thickarrowright syntactic sugar (`=>`)" + ;***************************************************************** + + byteCode [=> "hello"] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + + ; ] + ; 1: [ :block + ; hello :string + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; end + + byteCode [ + f: function => print + ] + ; ================================ + ; DATA + ; ================================ + ; 0: f :label + ; 1: function :word + ; 2: [ :block + ; _0 :word + ; ] + ; 3: [ :block + ; print :word + ; _0 :word + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push3 + ; push2 + ; call1 + ; store0 + ; end + + byteCode [ + adder: $ => add + ] + ; ================================ + ; DATA + ; ================================ + ; 0: adder :label + ; 1: function :word + ; 2: [ :block + ; _0 :word + ; _1 :word + ; ] + ; 3: [ :block + ; add :word + ; _0 :word + ; _1 :word + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push3 + ; push2 + ; call1 + ; store0 + ; end + + ;***************************************************************** + topic "pipe operator (`|`)" + ;***************************************************************** + + byteCode [2 | print] + ; ================================ + ; DATA + ; ================================ + ; 0: print :word + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; call0 + ; end + + ; TODO: this is not working!!! (see #802) + ; byteCode ["hello" | upper | print] + ; ================================ + ; DATA + ; ================================ + ; 0: hello :string + ; 1: upper :word + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; call1 + ; print ; end \ No newline at end of file From 5d0bba5032f6339ee80ef5e036db076bbe3bd52d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 16:31:05 +0100 Subject: [PATCH 039/984] updated expected result --- tests/unittests/evaluator.art | 2 +- tests/unittests/evaluator.res | 86 ++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 88c98d7540..4e98b7f078 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - inspect btc ; uncomment this line to see the bytecode + ;inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 6ff76bbcda..02c21ce292 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -167,6 +167,19 @@ code: [32 211] (2 bytes) + >-------------------------------------------------- + > Version + >-------------------------------------------------- + + input: [0.9.82] + data: [0.9.82] + code: [32 211] (2 bytes) + + input: [2.0.0-rc1] + data: [2.0.0-rc1] + code: [32 211] (2 bytes) + + >-------------------------------------------------- > Block >-------------------------------------------------- @@ -348,4 +361,75 @@ input: [ "USA"] data: [user address country USA] - code: [35 34 33 64 160 161 211] (7 bytes) \ No newline at end of file + code: [35 34 33 64 160 161 211] (7 bytes) + + +************************************************** +* +* BLOCKS & SYNTACTIC SUGAR +* +************************************************** + + >-------------------------------------------------- + > Inline blocks + >-------------------------------------------------- + + input: [(print 2)] + data: [] + code: [2 176 211] (3 bytes) + + input: [(print 2) (print 3)] + data: [] + code: [2 176 3 176 211] (5 bytes) + + + >-------------------------------------------------- + > doublecolon syntactic sugar (`::`) + >-------------------------------------------------- + + input: [print 2 do :: print 3] + data: [do [print 3]] + code: [2 176 33 96 211] (5 bytes) + + + >-------------------------------------------------- + > arrowright syntactic sugar (`->`) + >-------------------------------------------------- + + input: [-> "hello"] + data: [[hello]] + code: [32 211] (2 bytes) + + input: [do -> print "hello" print "done"] + data: [do [print hello] done] + code: [33 96 34 176 211] (5 bytes) + + input: [a: -> upper "hello" b: -> "hello " ++ world] + data: [a [upper hello] b [hello ++ world]] + code: [33 48 35 50 211] (5 bytes) + + + >-------------------------------------------------- + > thickarrowright syntactic sugar (`=>`) + >-------------------------------------------------- + + input: [=> "hello"] + data: [[] [hello]] + code: [32 33 211] (3 bytes) + + input: [f: function => print] + data: [f function [_0] [print _0]] + code: [35 34 97 48 211] (5 bytes) + + input: [adder: $ => add] + data: [adder function [_0 _1] [add _0 _1]] + code: [35 34 97 48 211] (5 bytes) + + + >-------------------------------------------------- + > pipe operator (`|`) + >-------------------------------------------------- + + input: [2 | print] + data: [print] + code: [2 96 211] (3 bytes) \ No newline at end of file From f550644cff93d542f3218131f6c50f32805e38c8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 16:32:51 +0100 Subject: [PATCH 040/984] renamed `optimizeLess` (misnomer/typo?!) to `optimizeElse` --- src/vm/eval.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 1b50a2e2a4..e181ce78ed 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -385,7 +385,7 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = foundUnless = false - proc optimizeLess(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + proc optimizeElse(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) if cnstId != -1: @@ -563,7 +563,7 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = optimizeUnless(consts, it) elif foundElse and it[^1] == byte(opNop): - optimizeLess(consts, it) + optimizeElse(consts, it) elif foundSwitch: optimizeSwitch(consts, it) From a5ea47cca1876013f23e9ce7196b7589444bb421 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 16:36:27 +0100 Subject: [PATCH 041/984] Unittests/evaluator: added tests for Composite opcoded built-in function calls --- tests/unittests/evaluator.art | 45 ++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 4e98b7f078..e444e75e4d 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - ;inspect btc ; uncomment this line to see the bytecode + inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] @@ -638,6 +638,49 @@ supersection "FUNCTION CALLS" ; band ; end + ;***************************************************************** + topic "Composite opcoded built-in function calls" + ;***************************************************************** + + byteCode [to :floating 1] + ; ================================ + ; DATA + ; ================================ + ; 0: floating :type + + ; ================================ + ; CODE + ; ================================ + ; consti1 + ; push0 + ; to + ; end + + byteCode [to :integer "10"] + ; ================================ + ; DATA + ; ================================ + ; 0: 10 :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; toi + ; end + + byteCode [to :string 5] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti5 + ; tos + ; end + ;***************************************************************** topic "Function calls with attributes" ;***************************************************************** From c5e06794bbb09a514d9f08cf60da968e89cc1e12 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 16:48:16 +0100 Subject: [PATCH 042/984] added TODOs --- src/vm/eval.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index e181ce78ed..348646ff9e 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -528,6 +528,9 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = foundWhile = false proc optimizeAdd(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + # TODO(VM/eval) `optimizeAdd` not correctly handling stores + # e.g. [a: b + 1] + # labels: vm, evaluator, enhancement, bug if OpCode(currentCommand[^1]) == opAdd: if currentCommand.len == 3 and OpCode(currentCommand[0])==opConstI1: currentCommand = @[currentCommand[1], byte(opInc)] @@ -544,6 +547,9 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = foundAdd = false proc optimizeSub(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + # TODO(VM/eval) `optimizeSub` not correctly handling stores + # e.g. [a: b - 1] + # labels: vm, evaluator, enhancement, bug if OpCode(currentCommand[^1]) == opSub: if currentCommand.len == 3 and OpCode(currentCommand[0])==opConstI1: currentCommand = @[currentCommand[1], byte(opDec)] From adb3cdc358dc3d63d7fa3d05d051f99d2a9172e0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 16:56:45 +0100 Subject: [PATCH 043/984] Unittests/evaluator: added tests for specific optimizations (`add`, `sub` & `if`) --- tests/unittests/evaluator.art | 346 ++++++++++++++++++++++++++++++++++ 1 file changed, 346 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index e444e75e4d..271753d0cf 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1307,4 +1307,350 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; push0 ; call1 ; print + ; end + +;///////////////////////////////////////////////////////// +supersection "OPTIMIZATIONS" +;///////////////////////////////////////////////////////// + + ;***************************************************************** + topic "add (`+`)" + ;***************************************************************** + + byteCode [add 2 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti3 + ; consti2 + ; add + ; end + + byteCode [2 + 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti3 + ; consti2 + ; add + ; end + + byteCode [add 1 2] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; inc + ; end + + + byteCode [1 + 2] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; inc + ; end + + byteCode [add 2 1] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; inc + ; end + + byteCode [2 + 1] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; inc + ; end + + ; TODO: this is not working!!! + ; byteCode [a: b + 1] + ; ================================ + ; DATA + ; ================================ + ; 0: a :label + ; 1: b :word + + ; ================================ + ; CODE + ; ================================ + ; load1 + ; inc + ; store0 + ; end + + ;***************************************************************** + topic "sub (`-`)" + ;***************************************************************** + + byteCode [sub 3 2] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; consti3 + ; sub + ; end + + byteCode [3 - 2] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; consti3 + ; sub + ; end + + byteCode [sub 2 1] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; dec + ; end + + byteCode [2 - 1] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti2 + ; dec + ; end + + ; TODO: this is not working!!! + ; byteCode [a: b - 1] + ; ================================ + ; DATA + ; ================================ + ; 0: a :label + ; 1: b :word + + ; ================================ + ; CODE + ; ================================ + ; load1 + ; dec + ; store0 + ; end + + ;***************************************************************** + topic "if" + ;***************************************************************** + + byteCode [ + print "before" + if x [print "here", return true] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; true :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; load1 + ; jmpifnot #4 + ; push3 + ; print + ; constbt + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + if not? x [print "here", return false] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; false :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; load1 + ; jmpif #4 + ; push3 + ; print + ; constbf + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + if x=2 [print "here", return true] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; true :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti2 + ; load1 + ; jmpifne #4 + ; push3 + ; print + ; constbt + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + if x>2 [print "here", return true] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; true :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti2 + ; load1 + ; jmpifle #4 + ; push3 + ; print + ; constbt + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + if x=<2 [print "here", return true] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; true :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti2 + ; load1 + ; jmpifgt #4 + ; push3 + ; print + ; constbt + ; return + ; push4 + ; print ; end \ No newline at end of file From b67d1be344a1a0b97331490b7ac34ebb96d1632e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:05:09 +0100 Subject: [PATCH 044/984] Unittests/evaluator: added tests for specific optimizations (`unless`) --- tests/unittests/evaluator.art | 177 ++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 271753d0cf..99fd78c0e3 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1653,4 +1653,181 @@ supersection "OPTIMIZATIONS" ; return ; push4 ; print + ; end + + ;***************************************************************** + topic "unless" + ;***************************************************************** + + byteCode [ + print "before" + unless x [print "here", return false] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; false :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; load1 + ; jmpif #4 + ; push3 + ; print + ; constbf + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + unless not? x [print "here", return true] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; true :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; load1 + ; jmpifnot #4 + ; push3 + ; print + ; constbt + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + unless x=2 [print "here", return false] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; false :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti2 + ; load1 + ; jmpifeq #4 + ; push3 + ; print + ; constbf + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + unless x>2 [print "here", return false] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; false :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti2 + ; load1 + ; jmpifgt #4 + ; push3 + ; print + ; constbf + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + unless x=<2 [print "here", return false] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; false :word + ; ] + ; 3: here :string + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti2 + ; load1 + ; jmpifle #4 + ; push3 + ; print + ; constbf + ; return + ; push4 + ; print ; end \ No newline at end of file From 99a2074e87ac2102c7433bb3cd0ab11322636fce Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:13:39 +0100 Subject: [PATCH 045/984] added TODO --- src/vm/eval.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 348646ff9e..e9163c7b7d 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -117,6 +117,11 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = else: currentCommand.insert(b, at) + # TODO(VM/eval) remove constants that have been optimized away + # For example, if/unless/else/switch/while usually optimize away their blocks; + # so, IF they are not used by anything else in our code, we could optimize them away. + # In that case, we could obviously use a CountTable to resolve the times each constant is used. + # labels: vm, evaluator, performance, enhancement proc addConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = var indx = consts.indexOfValue(v) if indx == -1: From 04c4ea3e19f74555955f5cc4f3942bf043cb4892 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:14:04 +0100 Subject: [PATCH 046/984] Unittests/evaluator: added tests for specific optimizations (if-else) --- tests/unittests/evaluator.art | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 99fd78c0e3..ddf2f99d02 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1830,4 +1830,87 @@ supersection "OPTIMIZATIONS" ; return ; push4 ; print + ; end + + ;***************************************************************** + topic "if-else" + ;***************************************************************** + + byteCode [ + if? x [return true] + else [return false] + ] + ; ================================ + ; DATA + ; ================================ + ; 0: x :word + ; 1: [ :block + ; return :word + ; true :word + ; ] + ; 2: [ :block + ; return :word + ; false :word + ; ] + + ; ================================ + ; CODE + ; ================================ + ; load0 + ; jmpifnot #5 + ; constbt + ; return + ; goto #2 + ; constbf + ; return + ; end + + byteCode [ + print "before" + if? a <> 1 + 2 [print "here", return true] + else [print "there", return false] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: a :word + ; 2: [ :block + ; print :word + ; here :string + ; return :word + ; true :word + ; ] + ; 3: here :string + ; 4: [ :block + ; print :word + ; there :string + ; return :word + ; false :word + ; ] + ; 5: there :string + ; 6: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti2 + ; consti1 + ; add + ; load1 + ; jmpifeq #7 + ; push3 + ; print + ; constbt + ; return + ; goto #4 + ; push5 + ; print + ; constbf + ; return + ; push6 + ; print ; end \ No newline at end of file From a954c228880e2809033ac31a39c113b4c3b797a6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:26:19 +0100 Subject: [PATCH 047/984] Unittests/evaluator: added tests for specific optimizations (`switch`) --- tests/unittests/evaluator.art | 174 +++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index ddf2f99d02..e8c2585324 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1913,4 +1913,176 @@ supersection "OPTIMIZATIONS" ; return ; push6 ; print - ; end \ No newline at end of file + ; end + + ;***************************************************************** + topic "switch (`?`)" + ;***************************************************************** + + byteCode [ + print "before" + switch a [1][2] + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: a :word + ; 2: [ :block + ; 1 :integer + ; ] + ; 3: [ :block + ; 2 :integer + ; ] + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; load1 + ; jmpifnot #4 + ; consti1 + ; goto #1 + ; consti2 + ; push4 + ; print + ; end + + byteCode [(x = 1)? -> 1 -> 2] + ; ================================ + ; DATA + ; ================================ + ; 0: x :word + ; 1: [ :block + ; 1 :integer + ; ] + ; 2: [ :block + ; 2 :integer + ; ] + + ; ================================ + ; CODE + ; ================================ + ; consti1 + ; load0 + ; jmpifne #4 + ; consti1 + ; goto #1 + ; consti2 + ; end + + byteCode [ + print "before" + return (x<1)? -> true -> false + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: x :word + ; 2: [ :block + ; true :word + ; ] + ; 3: [ :block + ; false :word + ; ] + ; 4: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti1 + ; load1 + ; jmpifge #4 + ; constbt + ; goto #1 + ; constbf + ; return + ; push4 + ; print + ; end + + byteCode [ + print "before" + z: (x<1)? -> true -> false + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: z :label + ; 2: x :word + ; 3: [ :block + ; true :word + ; ] + ; 4: [ :block + ; false :word + ; ] + ; 5: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti1 + ; load2 + ; jmpifge #4 + ; constbt + ; goto #1 + ; constbf + ; store1 + ; push5 + ; print + ; end + + byteCode [ + print "before" + z: 3 + (x>=1)? -> 1 -> 2 + print "after" + ] + ; ================================ + ; DATA + ; ================================ + ; 0: before :string + ; 1: z :label + ; 2: x :word + ; 3: [ :block + ; 1 :integer + ; ] + ; 4: [ :block + ; 2 :integer + ; ] + ; 5: after :string + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; print + ; consti1 + ; load2 + ; jmpiflt #4 + ; consti1 + ; goto #1 + ; consti2 + ; consti3 + ; add + ; store1 + ; push5 + ; print + ; end + + ; TODO: this is not working!!! (see #817) + ; byteCode [ + ; print "before" + ; return ((x>1)? -> 2 -> 3) + (y<4)? -> 5 -> 6 + ; print "after" + ; ] \ No newline at end of file From e132ae77311637e78ff2499f9789299a09f289a9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:30:11 +0100 Subject: [PATCH 048/984] added TODO --- src/vm/eval.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index e9163c7b7d..6f3b4787dd 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -476,6 +476,9 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = foundSwitch = false proc optimizeWhile(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + # TODO(VM/eval) `optimizeWhile` does not correctly process `null` condition + # in a few words: when it's an infinite while loop + # labels: vm, evaluator, enhancement if OpCode(currentCommand[^1]) == opWhile: let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) From 468250963835e532bea090ce1ac45ff4f280bfdc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:30:29 +0100 Subject: [PATCH 049/984] Unittests/evaluator: added tests for specific optimizations (`while`) --- tests/unittests/evaluator.art | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index e8c2585324..1fb644b13a 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -2085,4 +2085,42 @@ supersection "OPTIMIZATIONS" ; print "before" ; return ((x>1)? -> 2 -> 3) + (y<4)? -> 5 -> 6 ; print "after" + ; ] + + ;***************************************************************** + topic "while" + ;***************************************************************** + + byteCode [ + while [x=1][print "hello"] + ] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; x :word + ; = :symbol + ; 1 :integer + ; ] + ; 1: [ :block + ; print :word + ; hello :string + ; ] + ; 2: x :word + ; 3: hello :string + + ; ================================ + ; CODE + ; ================================ + ; consti1 + ; load2 + ; jmpifne #5 + ; push3 + ; print + ; goup #10 + ; end + + ; TODO: this is not working!!! + ; byteCode [ + ; while ΓΈ [print "hello"] ; ] \ No newline at end of file From fa1a8721c870090f3df1ed72b7afb2efd8a90286 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:30:54 +0100 Subject: [PATCH 050/984] disable inspection --- tests/unittests/evaluator.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 1fb644b13a..0fc193dd40 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - inspect btc ; uncomment this line to see the bytecode + ;inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] From 8d350dc2e03c45ff4cc8d9ddddbb13bff9b778b4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:31:27 +0100 Subject: [PATCH 051/984] updated expected result --- tests/unittests/evaluator.res | 172 +++++++++++++++++++++++++++++++++- 1 file changed, 171 insertions(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 02c21ce292..b97cd54919 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -265,6 +265,23 @@ code: [32 1 137 211] (4 bytes) + >-------------------------------------------------- + > Composite opcoded built-in function calls + >-------------------------------------------------- + + input: [to :floating 1] + data: [:floating] + code: [1 32 157 211] (4 bytes) + + input: [to :integer "10"] + data: [10] + code: [32 159 211] (3 bytes) + + input: [to :string 5] + data: [] + code: [5 158 211] (3 bytes) + + >-------------------------------------------------- > Function calls with attributes >-------------------------------------------------- @@ -432,4 +449,157 @@ input: [2 | print] data: [print] - code: [2 96 211] (3 bytes) \ No newline at end of file + code: [2 96 211] (3 bytes) + + +************************************************** +* +* OPTIMIZATIONS +* +************************************************** + + >-------------------------------------------------- + > add (`+`) + >-------------------------------------------------- + + input: [add 2 3] + data: [] + code: [3 2 128 211] (4 bytes) + + input: [2 + 3] + data: [] + code: [3 2 128 211] (4 bytes) + + input: [add 1 2] + data: [] + code: [2 174 211] (3 bytes) + + input: [1 + 2] + data: [] + code: [2 174 211] (3 bytes) + + input: [add 2 1] + data: [] + code: [2 174 211] (3 bytes) + + input: [2 + 1] + data: [] + code: [2 174 211] (3 bytes) + + + >-------------------------------------------------- + > sub (`-`) + >-------------------------------------------------- + + input: [sub 3 2] + data: [] + code: [2 3 129 211] (4 bytes) + + input: [3 - 2] + data: [] + code: [2 3 129 211] (4 bytes) + + input: [sub 2 1] + data: [] + code: [2 175 211] (3 bytes) + + input: [2 - 1] + data: [] + code: [2 175 211] (3 bytes) + + + >-------------------------------------------------- + > if + >-------------------------------------------------- + + input: [print "before" if x [print "here" return true] print "after"] + data: [before x [print here return true] here after] + code: [32 176 65 198 0 4 35 176 21 156 36 176 211] (13 bytes) + + input: [print "before" if not? x [print "here" return false] print "after"] + data: [before x [print here return false] here after] + code: [32 176 65 197 0 4 35 176 22 156 36 176 211] (13 bytes) + + input: [print "before" if x = 2 [print "here" return true] print "after"] + data: [before x [print here return true] here after] + code: [32 176 2 65 200 0 4 35 176 21 156 36 176 211] (14 bytes) + + input: [print "before" if x > 2 [print "here" return true] print "after"] + data: [before x [print here return true] here after] + code: [32 176 2 65 204 0 4 35 176 21 156 36 176 211] (14 bytes) + + input: [print "before" if x =< 2 [print "here" return true] print "after"] + data: [before x [print here return true] here after] + code: [32 176 2 65 201 0 4 35 176 21 156 36 176 211] (14 bytes) + + + >-------------------------------------------------- + > unless + >-------------------------------------------------- + + input: [print "before" unless x [print "here" return false] print "after"] + data: [before x [print here return false] here after] + code: [32 176 65 197 0 4 35 176 22 156 36 176 211] (13 bytes) + + input: [print "before" unless not? x [print "here" return true] print "after"] + data: [before x [print here return true] here after] + code: [32 176 65 198 0 4 35 176 21 156 36 176 211] (13 bytes) + + input: [print "before" unless x = 2 [print "here" return false] print "after"] + data: [before x [print here return false] here after] + code: [32 176 2 65 199 0 4 35 176 22 156 36 176 211] (14 bytes) + + input: [print "before" unless x > 2 [print "here" return false] print "after"] + data: [before x [print here return false] here after] + code: [32 176 2 65 201 0 4 35 176 22 156 36 176 211] (14 bytes) + + input: [print "before" unless x =< 2 [print "here" return false] print "after"] + data: [before x [print here return false] here after] + code: [32 176 2 65 204 0 4 35 176 22 156 36 176 211] (14 bytes) + + + >-------------------------------------------------- + > if-else + >-------------------------------------------------- + + input: [if? x [return true] else [return false]] + data: [x [return true] [return false]] + code: [64 198 0 5 21 156 208 0 2 22 156 211] (12 bytes) + + input: [print "before" if? a <> 1 + 2 [print "here" return true] else [print "there" return false] print "after"] + data: [before a [print here return true] here [print there return false] there after] + code: [32 176 2 1 128 65 199 0 7 35 176 21 156 208 0 4 37 176 22 156 38 176 211] (23 bytes) + + + >-------------------------------------------------- + > switch (`?`) + >-------------------------------------------------- + + input: [print "before" switch a [1] [2] print "after"] + data: [before a [1] [2] after] + code: [32 176 65 198 0 4 1 208 0 1 2 36 176 211] (14 bytes) + + input: [(x = 1) ? -> 1 -> 2] + data: [x [1] [2]] + code: [1 64 200 0 4 1 208 0 1 2 211] (11 bytes) + + input: [print "before" return (x < 1) ? -> true -> false print "after"] + data: [before x [true] [false] after] + code: [32 176 1 65 202 0 4 21 208 0 1 22 156 36 176 211] (16 bytes) + + input: [print "before" z: (x < 1) ? -> true -> false print "after"] + data: [before z x [true] [false] after] + code: [32 176 1 66 202 0 4 21 208 0 1 22 49 37 176 211] (16 bytes) + + input: [print "before" z: 3 + (x >= 1) ? -> 1 -> 2 print "after"] + data: [before z x [1] [2] after] + code: [32 176 1 66 203 0 4 1 208 0 1 2 3 128 49 37 176 211] (18 bytes) + + + >-------------------------------------------------- + > while + >-------------------------------------------------- + + input: [while [x = 1] [print "hello"]] + data: [[x = 1] [print hello] x hello] + code: [1 66 200 0 5 35 176 209 0 10 211] (11 bytes) \ No newline at end of file From 9f1819a57f4bfa2b6cd0ce22d472c7a36688d6cd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 12 Jan 2023 17:31:32 +0100 Subject: [PATCH 052/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1391eeb817..acb89cf994 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3473 \ No newline at end of file +3474 \ No newline at end of file From ad130054e98bc0d2d4cc8996d8309c34e16863f4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 11:55:04 +0100 Subject: [PATCH 053/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index acb89cf994..33daef0a27 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3474 \ No newline at end of file +3475 \ No newline at end of file From 06e1ba1bfe610bddabee9e7c2111d4df9936c18a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 11:59:44 +0100 Subject: [PATCH 054/984] VM/eval: correctly evaluate constant Integer values in 0..15 for Path indexes --- src/vm/eval.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 6f3b4787dd..30a795c32d 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -963,7 +963,14 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = if node.p[i].kind==Block: evalOne(node.p[i], consts, currentCommand, inBlock=true, isDictionary=isDictionary) else: - addConst(node.p[i], opPush) + if node.p[i].kind == Integer: + if likely(node.p[i].iKind==NormalInteger): + if node.p[i].i>=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) + else: addConst(node.p[i], opPush) + else: + addConst(node.p[i], opPush) + else: + addConst(node.p[i], opPush) i += 1 of PathLabel: From 67ec9a706fe2972e7d5104f597e55a9fe468cf3f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:00:00 +0100 Subject: [PATCH 055/984] removed TODO --- src/vm/eval.nim | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 30a795c32d..4c34baa0a3 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -927,9 +927,6 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = argStack[argStack.len-1] += 1 of Path: - # TODO(VM/eval) Path values containing fixed constants not processed correctly - # `a\0` should actually produce an `opConstI0` and not a LOAD - # labels: evaluator, enhancement var pathCallV: Value = nil if (let curr = Syms.getOrDefault(node.p[0].s, nil); not curr.isNil): From 80ec838baac0bd13ae0ace4bb67949e713c0ea3d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:01:08 +0100 Subject: [PATCH 056/984] VM/eval: correctly evaluate constant Integer values in 0..15 for PathLabel indexes (same as with simple Path values) --- src/vm/eval.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 4c34baa0a3..39c8d3b270 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -988,7 +988,14 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = if node.p[i].kind==Block: evalOne(node.p[i], consts, currentCommand, inBlock=true, isDictionary=isDictionary) else: - addConst(node.p[i], opPush) + if node.p[i].kind == Integer: + if likely(node.p[i].iKind==NormalInteger): + if node.p[i].i>=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) + else: addConst(node.p[i], opPush) + else: + addConst(node.p[i], opPush) + else: + addConst(node.p[i], opPush) i += 1 argStack.add(1) From 60cbc2f9eeeb9e11472981874909acae4c578e22 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:01:18 +0100 Subject: [PATCH 057/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 33daef0a27..e95e0a7c66 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3475 \ No newline at end of file +3476 \ No newline at end of file From 95ac549e9b10bffdb9b926f3fdde225ba28ca292 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:02:56 +0100 Subject: [PATCH 058/984] removed TODO --- src/vm/eval.nim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 39c8d3b270..1a28a612ba 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -971,10 +971,6 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = i += 1 of PathLabel: - # TODO(VM/eval) PathLabels values containing fixed constants not processed correctly - # `a\0: 10` should actually produce an `opConstI0` and not a LOAD - # (same situation as with Path values) - # labels: evaluator, enhancement addToCommand(opSet) var i=1 From 9a92d66b1eac4c1baf5a76ddffc97feabc161a65 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:03:11 +0100 Subject: [PATCH 059/984] updated unit-test --- tests/unittests/evaluator.art | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 0fc193dd40..25916bccb8 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - ;inspect btc ; uncomment this line to see the bytecode + inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] @@ -920,12 +920,11 @@ supersection "PATHS" ; DATA ; ================================ ; 0: a :word - ; 1: 0 :integer ; ================================ ; CODE ; ================================ - ; push1 + ; consti0 ; load0 ; get ; end @@ -951,12 +950,11 @@ supersection "PATHS" ; ================================ ; 0: user :word ; 1: grades :literal - ; 2: 0 :integer ; ================================ ; CODE ; ================================ - ; push2 + ; consti0 ; push1 ; load0 ; get @@ -990,13 +988,12 @@ supersection "PATHS" ; DATA ; ================================ ; 0: a :word - ; 1: 0 :integer ; ================================ ; CODE ; ================================ ; consti10 - ; push1 + ; consti0 ; load0 ; set ; end @@ -1024,13 +1021,12 @@ supersection "PATHS" ; ================================ ; 0: user :word ; 1: grades :literal - ; 2: 0 :integer ; ================================ ; CODE ; ================================ ; consti6 - ; push2 + ; consti0 ; push1 ; load0 ; get From 8f38ece8b8d1b13e08571092a5db54f1844d8174 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:03:35 +0100 Subject: [PATCH 060/984] disable bytecode inspection --- tests/unittests/evaluator.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 25916bccb8..a8e1e82322 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - inspect btc ; uncomment this line to see the bytecode + ;inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] From dc7850da8fc97f85c3607bc7e26c8a4b92663160 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:04:43 +0100 Subject: [PATCH 061/984] updated expected unit-test result --- tests/unittests/evaluator.res | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index b97cd54919..719c5127af 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -344,16 +344,16 @@ >-------------------------------------------------- input: [] - data: [a 0] - code: [33 64 160 211] (4 bytes) + data: [a] + code: [0 64 160 211] (4 bytes) input: [] data: [user name] code: [33 64 160 211] (4 bytes) input: [] - data: [user grades 0] - code: [34 33 64 160 160 211] (6 bytes) + data: [user grades] + code: [0 33 64 160 160 211] (6 bytes) input: [] data: [user address country] @@ -365,16 +365,16 @@ >-------------------------------------------------- input: [ 10] - data: [a 0] - code: [10 33 64 161 211] (5 bytes) + data: [a] + code: [10 0 64 161 211] (5 bytes) input: [ "John"] data: [user name John] code: [34 33 64 161 211] (5 bytes) input: [ 6] - data: [user grades 0] - code: [6 34 33 64 160 161 211] (7 bytes) + data: [user grades] + code: [6 0 33 64 160 161 211] (7 bytes) input: [ "USA"] data: [user address country USA] From 487ee90467cac484d3fbda55621c08330e897315 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:12:15 +0100 Subject: [PATCH 062/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e95e0a7c66..29a14f9b00 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3476 \ No newline at end of file +3477 \ No newline at end of file From 536e472a4cbc0e8ebb380cd162cb818e339c4d27 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:14:11 +0100 Subject: [PATCH 063/984] VM/values/printable: [codify] add proper support for Path & PathLabel values --- src/vm/values/printable.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index 5f7994a950..b2c8fbcee8 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -487,6 +487,11 @@ proc codify*(v: Value, pretty = false, unwrapped = false, level: int=0, isLast: of Label : result &= v.s & ":" of Attribute : result &= "." & v.s of AttributeLabel : result &= "." & v.s & ":" + of Path, + PathLabel : + result = v.p.map((x) => $(x)).join("\\") + if v.kind==PathLabel: + result &= ":" of Symbol : result &= $(v.m) of SymbolLiteral: result &= "'" & $(v.m) of Quantity : result &= $(v.nm) & ":" & toLowerAscii($(v.unit.name)) From a8c8a40a4d0d3c4bf3ca01921e14cad132360ed8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:14:28 +0100 Subject: [PATCH 064/984] updated expected unit-test result --- tests/unittests/evaluator.res | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 719c5127af..048f25cb39 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -343,19 +343,19 @@ > Path values >-------------------------------------------------- - input: [] + input: [a\0] data: [a] code: [0 64 160 211] (4 bytes) - input: [] + input: [user\name] data: [user name] code: [33 64 160 211] (4 bytes) - input: [] + input: [user\grades\0] data: [user grades] code: [0 33 64 160 160 211] (6 bytes) - input: [] + input: [user\address\country] data: [user address country] code: [34 33 64 160 160 211] (6 bytes) @@ -364,19 +364,19 @@ > PathLabel values >-------------------------------------------------- - input: [ 10] + input: [a\0: 10] data: [a] code: [10 0 64 161 211] (5 bytes) - input: [ "John"] + input: [user\name: "John"] data: [user name John] code: [34 33 64 161 211] (5 bytes) - input: [ 6] + input: [user\grades\0: 6] data: [user grades] code: [6 0 33 64 160 161 211] (7 bytes) - input: [ "USA"] + input: [user\address\country: "USA"] data: [user address country USA] code: [35 34 33 64 160 161 211] (7 bytes) From 8edb029aee4ba2fa2ec5ee859b689a995ee19c86 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:21:32 +0100 Subject: [PATCH 065/984] trigger rebuild --- tests/unittests/evaluator.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 048f25cb39..86b12b9bbb 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -602,4 +602,4 @@ input: [while [x = 1] [print "hello"]] data: [[x = 1] [print hello] x hello] - code: [1 66 200 0 5 35 176 209 0 10 211] (11 bytes) \ No newline at end of file + code: [1 66 200 0 5 35 176 209 0 10 211] (11 bytes) \ No newline at end of file From 0781b36d891dd03c7579880c3e685e4560f5b6ea Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:30:45 +0100 Subject: [PATCH 066/984] re-trigger rebuild --- tests/unittests/evaluator.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 86b12b9bbb..048f25cb39 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -602,4 +602,4 @@ input: [while [x = 1] [print "hello"]] data: [[x = 1] [print hello] x hello] - code: [1 66 200 0 5 35 176 209 0 10 211] (11 bytes) \ No newline at end of file + code: [1 66 200 0 5 35 176 209 0 10 211] (11 bytes) \ No newline at end of file From 9795a52df08faea2fb4020475b5c57681e85969b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 12:45:03 +0100 Subject: [PATCH 067/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 29a14f9b00..ac2d85f2dd 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3477 \ No newline at end of file +3478 \ No newline at end of file From 1521a943a3bc73f22ee0f189399342cff7276f85 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:35:10 +0100 Subject: [PATCH 068/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ac2d85f2dd..6cf40af646 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3478 \ No newline at end of file +3479 \ No newline at end of file From 45dbf6a3abf92b16c4eb5f0af078cf6fe8615020 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:38:58 +0100 Subject: [PATCH 069/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6cf40af646..549e612a7f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3479 \ No newline at end of file +3480 \ No newline at end of file From f38a9778f569f8c5d2d5ee10792c1ca716eded11 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:39:19 +0100 Subject: [PATCH 070/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 549e612a7f..860baa16b0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3480 \ No newline at end of file +3481 \ No newline at end of file From 94e8a14f497b1bdee43fd88485bb999c5bcd7e4a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:39:45 +0100 Subject: [PATCH 071/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 860baa16b0..ebd2186ad9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3481 \ No newline at end of file +3482 \ No newline at end of file From f3e0a282e81b881f09560c4a9d6c8c7b13c66258 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:41:15 +0100 Subject: [PATCH 072/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ebd2186ad9..ff5055c18f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3482 \ No newline at end of file +3483 \ No newline at end of file From 14963da319bcc0c0aafabb990d5e94bd8194767f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:43:10 +0100 Subject: [PATCH 073/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ff5055c18f..44fbe6856e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3483 \ No newline at end of file +3484 \ No newline at end of file From 212e7f2d188de38cb217c356f4b56b77e1ec0570 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:44:59 +0100 Subject: [PATCH 074/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 44fbe6856e..9b2b3a0f73 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3484 \ No newline at end of file +3485 \ No newline at end of file From 4cc20341f4297371923ca1307146552ad8a63b33 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:45:42 +0100 Subject: [PATCH 075/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9b2b3a0f73..3ee92d7a00 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3485 \ No newline at end of file +3486 \ No newline at end of file From b501bbfb9f3970d15dd79f5f191f16d29589a3d7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:47:16 +0100 Subject: [PATCH 076/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3ee92d7a00..55421ab381 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3486 \ No newline at end of file +3487 \ No newline at end of file From fdbc1487a566621f2108d47173f8c085377cde18 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:48:16 +0100 Subject: [PATCH 077/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 55421ab381..6496ab7947 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3487 \ No newline at end of file +3488 \ No newline at end of file From 9bf861daf971a5c94ec9d531be3fa8d34f23bf43 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 14:50:16 +0100 Subject: [PATCH 078/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6496ab7947..cec76bfed5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3488 \ No newline at end of file +3489 \ No newline at end of file From a56e0f004c79c1b8cdd168ea73a3acbb1372cc2a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 16:13:17 +0100 Subject: [PATCH 079/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cec76bfed5..06bb1f0bec 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3489 \ No newline at end of file +3490 \ No newline at end of file From 71a7d064624b817f85866962dbb61cd80abedc87 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 16:20:57 +0100 Subject: [PATCH 080/984] debugging --- src/vm/eval.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 1a28a612ba..ea4db18e8f 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -27,6 +27,8 @@ import vm/profiler import vm/values/custom/[vbinary, vsymbol] +import vm/ast + #======================================= # Variables #======================================= @@ -1118,6 +1120,8 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr # when defined(OPTIMIZED): # newit = optimizeBytecode(newit) + discard generateAst(root) + result = Translation(constants: cnsts, instructions: newit) when useStored: From 773b24fea25f33d2af3f32f41a0825462e3073ac Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 16:21:20 +0100 Subject: [PATCH 081/984] added AST generator (draft) --- src/vm/ast.nim | 136 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/vm/ast.nim diff --git a/src/vm/ast.nim b/src/vm/ast.nim new file mode 100644 index 0000000000..e0651abef4 --- /dev/null +++ b/src/vm/ast.nim @@ -0,0 +1,136 @@ +import algorithm, hashes, sequtils +import sugar, tables, unicode + +import vm/[bytecode, globals, values/value] + +type + # abstract syntax tree definition + NodeKind* = enum + RootNode, + IdentifierNode, + ConstantNode, + CallNode, + BuiltinNode + + CallNodeKind* = enum + AddCall, + SubCall, + OtherCall + + NodeArray* = seq[Node] + + Node* = ref object + case kind*: NodeKind: + of CallNode: + name*: string + arity*: int8 + cKind*: CallNodeKind + else: + discard + parent*: Node + children*: NodeArray + value*: Value + +var + TmpArities : Table[string,int8] + +func addChild*(node: Node, child: Node) = + node.children.add(child) + child.parent = node + +func addChildren*(node: Node, children: NodeArray) = + for child in children: + node.addChild(child) + +func addTerminalValue*(target: var Node, val: Node) = + while target.kind==CallNode and target.children.len == target.arity: + target = target.parent + + target.addChild(val) + + while target.kind==CallNode and target.children.len == target.arity: + target = target.parent + +func addFunctionCall*(target: var Node, name: string, arity: int8) = + target.addChild(Node(kind: CallNode, name: name, arity: arity)) + target = target.children[^1] + +proc processBlock*(root: Node, blok: Value) = + var i: int = 0 + var nLen: int = blok.a.len + + var currentNode: Node = root + + while i < nLen: + let node {.cursor.} = blok.a[i] + + case node.kind: + + of Integer, Floating, String: + currentNode.addTerminalValue(Node(kind: ConstantNode, value: node)) + + of Word: + var funcArity = TmpArities.getOrDefault(node.s, -1) + if funcArity != -1: + currentNode.addFunctionCall(node.s, funcArity) + else: + if node.s == "true": + currentNode.addTerminalValue(Node(kind: ConstantNode, value: VTRUE)) + elif node.s == "false": + currentNode.addTerminalValue(Node(kind: ConstantNode, value: VFALSE)) + else: + currentNode.addTerminalValue(Node(kind: IdentifierNode, value: node)) + + else: + discard + + i += 1 + +proc dumpNode*(node: Node, level = 0): string = + echo "in dumpNode" + let sep = " " + case node.kind: + of RootNode: + var j = 0 + while j < level: + result &= sep + j += 1 + result &= "ROOT\n" + for child in node.children: + result &= dumpNode(child, level+1) + of IdentifierNode: + var j = 0 + while j < level: + result &= sep + j += 1 + result &= "IdentifierNode: " & node.value.s + of ConstantNode: + var j = 0 + while j < level: + result &= sep + j += 1 + result &= "Constant: " & $(node.value.kind) + of CallNode: + var j = 0 + while j < level: + result &= sep + j += 1 + result &= "Call: " & node.name & " (" & $node.arity & ")\n" + for child in node.children: + result &= dumpNode(child, level+1) + of BuiltinNode: + result &= "BuiltinNode: " & node.name + + result &= "\n" + +proc generateAst*(parsed: Value): Node = + result = Node(kind: RootNode) + + TmpArities = collect: + for k,v in Syms.pairs: + if v.kind == Function: + {k: v.arity} + + result.processBlock(parsed) + + echo dumpNode(result) \ No newline at end of file From 344f34dba1502eebb7c01a13f3372fd78716451f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 16:36:39 +0100 Subject: [PATCH 082/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 06bb1f0bec..0daa67c6ef 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3490 \ No newline at end of file +3491 \ No newline at end of file From 4a75a3dbb39b83bc9b2ad7afaa5903035fb2bfc0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 16:58:47 +0100 Subject: [PATCH 083/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0daa67c6ef..948711320f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3491 \ No newline at end of file +3492 \ No newline at end of file From 96b6e0407a31732a10ea381f300b42f97338d0d5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 16:59:42 +0100 Subject: [PATCH 084/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 948711320f..c4666eb5de 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3492 \ No newline at end of file +3493 \ No newline at end of file From 083c64ba5d26646381e03b03bc923b9eeccfc25a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:20:56 +0100 Subject: [PATCH 085/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c4666eb5de..344ea98a48 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3493 \ No newline at end of file +3494 \ No newline at end of file From 8197d81c090b183d10e41a3ca4bd148c1f38b78f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:29:35 +0100 Subject: [PATCH 086/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 344ea98a48..db92f04146 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3494 \ No newline at end of file +3495 \ No newline at end of file From 5ce671872aac0be50d4957b016aaa4c1989750b2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:30:28 +0100 Subject: [PATCH 087/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index db92f04146..55221487e7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3495 \ No newline at end of file +3496 \ No newline at end of file From caba93662353dbf79fd9f94259b4bde31502b9b0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:36:18 +0100 Subject: [PATCH 088/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 55221487e7..bacccbd5f8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3496 \ No newline at end of file +3497 \ No newline at end of file From 89938dedc5905a9ce21034fea8ddb97453db85a0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:36:40 +0100 Subject: [PATCH 089/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bacccbd5f8..9dac1689f2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3497 \ No newline at end of file +3498 \ No newline at end of file From 4de6936693939536549f4374adc5a13d6f9a95b0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:40:54 +0100 Subject: [PATCH 090/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9dac1689f2..3493afddf5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3498 \ No newline at end of file +3499 \ No newline at end of file From b5193d28925f07831acfa5158d0d556038b4433a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:46:31 +0100 Subject: [PATCH 091/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3493afddf5..fc63bd12e5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3499 \ No newline at end of file +3500 \ No newline at end of file From 43faa271aa029204ce3c5ee8862a8f403bcc513b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:48:02 +0100 Subject: [PATCH 092/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index fc63bd12e5..b9e606b7ee 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3500 \ No newline at end of file +3501 \ No newline at end of file From 8dc39b5afd991ca0d8a91c20e08fbe2aaa43403b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:56:01 +0100 Subject: [PATCH 093/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b9e606b7ee..eb34eb4a29 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3501 \ No newline at end of file +3502 \ No newline at end of file From eaabe093a7f5d01949891f02ac47a86f142a59cd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:57:31 +0100 Subject: [PATCH 094/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index eb34eb4a29..26cbd830b6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3502 \ No newline at end of file +3503 \ No newline at end of file From 9b6ae8291e2071180b1c8bf140243db9e9783a71 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:58:08 +0100 Subject: [PATCH 095/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 26cbd830b6..3e06d1ff30 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3503 \ No newline at end of file +3504 \ No newline at end of file From ceda027b474098eaa9cfa0344e9fca9a0455f30b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 17:58:57 +0100 Subject: [PATCH 096/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3e06d1ff30..b177e1aceb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3504 \ No newline at end of file +3505 \ No newline at end of file From 0043bf940b2cccf11bc7c515564c67ddfbabe7d0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:00:14 +0100 Subject: [PATCH 097/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b177e1aceb..d70c36f8cc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3505 \ No newline at end of file +3506 \ No newline at end of file From c5963e8fd6447f8aa0a4a308d5d253f3fd7383f8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:10:53 +0100 Subject: [PATCH 098/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d70c36f8cc..1ba683058a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3506 \ No newline at end of file +3507 \ No newline at end of file From ae894fd6860d9450c39ec8d10b1c4bcd7aea4472 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:11:54 +0100 Subject: [PATCH 099/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1ba683058a..34c76cf8aa 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3507 \ No newline at end of file +3508 \ No newline at end of file From 33e644feb3333762eadf929d6d431a49aa89038b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:21:18 +0100 Subject: [PATCH 100/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 34c76cf8aa..8a7f02b4fb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3508 \ No newline at end of file +3509 \ No newline at end of file From 4eeae89042a936cbd80efb7d56ea0581a0481149 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:23:48 +0100 Subject: [PATCH 101/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8a7f02b4fb..7c78f5c69e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3509 \ No newline at end of file +3510 \ No newline at end of file From 88ffe9b72589e1a5d8ce67ae043a197e50a0a91e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:27:52 +0100 Subject: [PATCH 102/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7c78f5c69e..8e0195c676 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3510 \ No newline at end of file +3511 \ No newline at end of file From 247870b574fe9a178e9124540939b095db4c3576 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:33:11 +0100 Subject: [PATCH 103/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8e0195c676..47e6d5b193 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3511 \ No newline at end of file +3512 \ No newline at end of file From 019d0ef12de8334f43dd188ebee5c6bbd717a451 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:37:44 +0100 Subject: [PATCH 104/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 47e6d5b193..4ce0ef5fe4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3512 \ No newline at end of file +3513 \ No newline at end of file From cfe09b59a846065b76e0460a7a5166f81ad93b9a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:39:34 +0100 Subject: [PATCH 105/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4ce0ef5fe4..d621eb67d6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3513 \ No newline at end of file +3514 \ No newline at end of file From 4d6c4c8affdcebe0575198bafade080b43b962aa Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:41:57 +0100 Subject: [PATCH 106/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d621eb67d6..500f0cee0c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3514 \ No newline at end of file +3515 \ No newline at end of file From 986f339d97a8115f5300ae4c17d1aba71c001d06 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 13 Jan 2023 18:43:15 +0100 Subject: [PATCH 107/984] added support for Labels & Inline blocks + general cleanup --- src/vm/ast.nim | 166 ++++++++++++++++++++++++++++++------------------- 1 file changed, 103 insertions(+), 63 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index e0651abef4..ad118b2dd5 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -1,35 +1,47 @@ -import algorithm, hashes, sequtils +import algorithm, hashes, sequtils, strutils import sugar, tables, unicode import vm/[bytecode, globals, values/value] +import vm/values/clean +import vm/values/printable +import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vquantity, vrange, vrational, vregex, vsocket, vversion] type # abstract syntax tree definition NodeKind* = enum RootNode, - IdentifierNode, - ConstantNode, CallNode, - BuiltinNode - - CallNodeKind* = enum - AddCall, - SubCall, - OtherCall + TerminalNode NodeArray* = seq[Node] + NodeFlag* = enum + Variable, + + StoreSymbol, + AddCall + + NodeFlags* = set[NodeFlag] + Node* = ref object case kind*: NodeKind: of CallNode: - name*: string arity*: int8 - cKind*: CallNodeKind else: discard + + value*: Value + flags*: NodeFlags parent*: Node children*: NodeArray - value*: Value + + NodeObj = typeof(Node()[]) + +# Benchmarking +{.hints: on.} # Apparently we cannot disable just `Name` hints? +{.hint: "Node's inner type is currently " & $sizeof(NodeObj) & ".".} +{.hints: off.} + var TmpArities : Table[string,int8] @@ -42,84 +54,112 @@ func addChildren*(node: Node, children: NodeArray) = for child in children: node.addChild(child) -func addTerminalValue*(target: var Node, val: Node) = - while target.kind==CallNode and target.children.len == target.arity: - target = target.parent - - target.addChild(val) - - while target.kind==CallNode and target.children.len == target.arity: - target = target.parent - -func addFunctionCall*(target: var Node, name: string, arity: int8) = - target.addChild(Node(kind: CallNode, name: name, arity: arity)) - target = target.children[^1] - proc processBlock*(root: Node, blok: Value) = var i: int = 0 var nLen: int = blok.a.len - var currentNode: Node = root + var current = root + + proc addCall(target: var Node, val: Value, arity: int8, flags: NodeFlags = {}) = + target.addChild( + Node( + kind: CallNode, + value: val, + arity: arity, + flags: flags + ) + ) + target = target.children[^1] + + proc addTerminal(target: var Node, val: Value, flags: NodeFlags = {}) = + while target.kind==CallNode and target.children.len == target.arity: + target = target.parent + + if i < nLen - 1: + let nextNode {.cursor.} = blok.a[i+1] + if nextNode.kind == Symbol: + + if (let aliased = Aliases.getOrDefault(nextNode.m, NoAliasBinding); aliased != NoAliasBinding): + var symfunc {.cursor.} = GetSym(aliased.name.s) + + if symfunc.kind==Function and aliased.precedence==InfixPrecedence: + i += 1 + target.addCall(newString(aliased.name.s), symfunc.arity) + + if val.kind==Inline: + var subNode = Node(kind: RootNode) + subNode.processBlock(val) + target.addChildren(subNode.children) + else: + target.addChild( + Node( + kind: TerminalNode, + value: val, + flags: flags + ) + ) + + while target.kind==CallNode and target.children.len == target.arity: + target = target.parent while i < nLen: - let node {.cursor.} = blok.a[i] - - case node.kind: + let item = blok.a[i] - of Integer, Floating, String: - currentNode.addTerminalValue(Node(kind: ConstantNode, value: node)) + case item.kind: of Word: - var funcArity = TmpArities.getOrDefault(node.s, -1) + var funcArity = TmpArities.getOrDefault(item.s, -1) if funcArity != -1: - currentNode.addFunctionCall(node.s, funcArity) + current.addCall(item, funcArity) else: - if node.s == "true": - currentNode.addTerminalValue(Node(kind: ConstantNode, value: VTRUE)) - elif node.s == "false": - currentNode.addTerminalValue(Node(kind: ConstantNode, value: VFALSE)) + if item.s == "true": + current.addTerminal(VTRUE) + elif item.s == "false": + current.addTerminal(VFALSE) else: - currentNode.addTerminalValue(Node(kind: IdentifierNode, value: node)) + current.addTerminal(item, flags={Variable}) - else: + of Label, PathLabel: + current.addCall(item, 1, flags={StoreSymbol}) + + # of Inline: + # var subNode = Node(kind: RootNode) + # subNode.processBlock(item) + # current.addChildren(subNode.children) + + of Newline: discard + else: + current.addTerminal(item) + i += 1 proc dumpNode*(node: Node, level = 0): string = - echo "in dumpNode" + template indentNode(): untyped = + var j = 0 + while j < level: + result &= " " + j += 1 + let sep = " " case node.kind: of RootNode: - var j = 0 - while j < level: - result &= sep - j += 1 + indentNode() result &= "ROOT\n" for child in node.children: result &= dumpNode(child, level+1) - of IdentifierNode: - var j = 0 - while j < level: - result &= sep - j += 1 - result &= "IdentifierNode: " & node.value.s - of ConstantNode: - var j = 0 - while j < level: - result &= sep - j += 1 - result &= "Constant: " & $(node.value.kind) + of TerminalNode: + indentNode() + result &= "Constant: " & $(node.value) of CallNode: - var j = 0 - while j < level: - result &= sep - j += 1 - result &= "Call: " & node.name & " (" & $node.arity & ")\n" + indentNode() + if StoreSymbol in node.flags: + result &= "Store: " & $(node.value) & "\n" + else: + result &= "Call: " & node.value.s & " <" & $node.arity & ">\n" for child in node.children: result &= dumpNode(child, level+1) - of BuiltinNode: - result &= "BuiltinNode: " & node.name result &= "\n" From dd380909bab57f95b8c4de27ffec78cdda316f73 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:08:37 +0100 Subject: [PATCH 108/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 500f0cee0c..0e48140aa5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3515 \ No newline at end of file +3516 \ No newline at end of file From 155707047f3ea3fd911cf9029a6057a411df4d6e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:10:13 +0100 Subject: [PATCH 109/984] VM/ast: break `addTerminal` into different reusable template, make `addInline` a separate proc & general cleanup --- src/vm/ast.nim | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index ad118b2dd5..b3c9debdce 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -1,5 +1,5 @@ import algorithm, hashes, sequtils, strutils -import sugar, tables, unicode +import sugar, tables, unicode, std/with import vm/[bytecode, globals, values/value] import vm/values/clean @@ -71,10 +71,11 @@ proc processBlock*(root: Node, blok: Value) = ) target = target.children[^1] - proc addTerminal(target: var Node, val: Value, flags: NodeFlags = {}) = + template rewindCallBranches(target: var Node): untyped = while target.kind==CallNode and target.children.len == target.arity: target = target.parent + template addPotentialInfixCall(target: var Node): untyped = if i < nLen - 1: let nextNode {.cursor.} = blok.a[i+1] if nextNode.kind == Symbol: @@ -86,21 +87,34 @@ proc processBlock*(root: Node, blok: Value) = i += 1 target.addCall(newString(aliased.name.s), symfunc.arity) - if val.kind==Inline: - var subNode = Node(kind: RootNode) - subNode.processBlock(val) - target.addChildren(subNode.children) - else: - target.addChild( + proc addTerminal(target: var Node, val: Value, flags: NodeFlags = {}) = + with target: + rewindCallBranches() + + addPotentialInfixCall() + + addChild( Node( kind: TerminalNode, value: val, flags: flags ) ) + + rewindCallBranches() - while target.kind==CallNode and target.children.len == target.arity: - target = target.parent + proc addInline(target: var Node, val: Value, flags: NodeFlags = {}) = + var subNode = Node(kind: RootNode) + subNode.processBlock(val) + + with target: + rewindCallBranches() + + addPotentialInfixCall() + + addChildren(subNode.children) + + rewindCallBranches() while i < nLen: let item = blok.a[i] @@ -122,10 +136,8 @@ proc processBlock*(root: Node, blok: Value) = of Label, PathLabel: current.addCall(item, 1, flags={StoreSymbol}) - # of Inline: - # var subNode = Node(kind: RootNode) - # subNode.processBlock(item) - # current.addChildren(subNode.children) + of Inline: + current.addInline(item) of Newline: discard From d64d0c880f1c8dd1714c4357d70b75ee06a50144 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:11:54 +0100 Subject: [PATCH 110/984] removed unused imports --- src/vm/ast.nim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index b3c9debdce..5c6b1d8f31 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -1,10 +1,9 @@ -import algorithm, hashes, sequtils, strutils -import sugar, tables, unicode, std/with +import hashes, sugar, tables +import unicode, std/with -import vm/[bytecode, globals, values/value] -import vm/values/clean +import vm/[globals, values/value] import vm/values/printable -import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vquantity, vrange, vrational, vregex, vsocket, vversion] +import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vrational, vversion] type # abstract syntax tree definition From c1184154f49059ebe1656b142b5e561c8b4d0c23 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:23:09 +0100 Subject: [PATCH 111/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0e48140aa5..af9719be32 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3516 \ No newline at end of file +3517 \ No newline at end of file From 987eb9925895f4c06ab94b31aad94c147154fa44 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:32:27 +0100 Subject: [PATCH 112/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index af9719be32..f75f5ed8c3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3517 \ No newline at end of file +3518 \ No newline at end of file From 73b85f1e9b990bed4f8f04f4b982320de73dcd76 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:40:02 +0100 Subject: [PATCH 113/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f75f5ed8c3..54da69e925 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3518 \ No newline at end of file +3519 \ No newline at end of file From 2fac92fa807c3c12c12da2bf8bb3687e23fa6bdd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:41:51 +0100 Subject: [PATCH 114/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 54da69e925..39eac2e47d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3519 \ No newline at end of file +3520 \ No newline at end of file From 6934faa96da3cec5e69b9b32eb0cd7135b1b8bac Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:43:28 +0100 Subject: [PATCH 115/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 39eac2e47d..d28164d554 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3520 \ No newline at end of file +3521 \ No newline at end of file From 5db0050f5cce2d6d818672c1bdea89d214baa380 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 11:49:36 +0100 Subject: [PATCH 116/984] VM/ast: added support for *arrowright* --- src/vm/ast.nim | 77 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 5c6b1d8f31..669f026587 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -3,7 +3,7 @@ import unicode, std/with import vm/[globals, values/value] import vm/values/printable -import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vrational, vversion] +import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vrational, vsymbol, vversion] type # abstract syntax tree definition @@ -44,6 +44,7 @@ type var TmpArities : Table[string,int8] + ArrowBlock : ValueArray func addChild*(node: Node, child: Node) = node.children.add(child) @@ -53,8 +54,8 @@ func addChildren*(node: Node, children: NodeArray) = for child in children: node.addChild(child) -proc processBlock*(root: Node, blok: Value) = - var i: int = 0 +proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static bool = false): int = + var i: int = start var nLen: int = blok.a.len var current = root @@ -83,6 +84,8 @@ proc processBlock*(root: Node, blok: Value) = var symfunc {.cursor.} = GetSym(aliased.name.s) if symfunc.kind==Function and aliased.precedence==InfixPrecedence: + when processingArrow: + ArrowBlock.add(nextNode) i += 1 target.addCall(newString(aliased.name.s), symfunc.arity) @@ -104,7 +107,7 @@ proc processBlock*(root: Node, blok: Value) = proc addInline(target: var Node, val: Value, flags: NodeFlags = {}) = var subNode = Node(kind: RootNode) - subNode.processBlock(val) + discard subNode.processBlock(val) with target: rewindCallBranches() @@ -115,9 +118,20 @@ proc processBlock*(root: Node, blok: Value) = rewindCallBranches() + proc addArrowBlock(target: var Node, val: Value, flags: NodeFlags = {}) = + var subNode = Node(kind: RootNode) + i = subNode.processBlock(val, start=i+1, processingArrow=true) + + target.addTerminal(newBlock(ArrowBlock)) + + ArrowBlock.setLen(0) + while i < nLen: let item = blok.a[i] + when processingArrow: + ArrowBlock.add(item) + case item.kind: of Word: @@ -138,6 +152,53 @@ proc processBlock*(root: Node, blok: Value) = of Inline: current.addInline(item) + of Symbol: + case item.m: + of doublecolon: + inc(i) + var subblock: ValueArray + while i < nLen: + subblock.add(blok.a[i]) + inc(i) + + current.addTerminal(newBlock(subblock)) + + of arrowright : + current.addArrowBlock(blok) + + # of thickarrowright : + # # TODO(Eval\addTerminalValue) Thick arrow-right not working with pipes + # # labels: vm,evaluator,enhancement,bug + # var ab: ValueArray + # var sb: ValueArray + # var funcArity: int8 = 0 + # processThickArrowRight(ab, sb, it, n, i, funcArity) + + # # add the blocks + # addTerminalValue(inBlock=false): + # if ab.len == 1: + # addConst(newLiteral(ab[0].s), opPush) + # else: + # addConst(newBlock(ab), opPush) + # addTerminalValue(inBlock=false): + # addConst(newBlock(sb), opPush) + + # i += 1 + else: + let symalias = item.m + let aliased = Aliases.getOrDefault(symalias, NoAliasBinding) + if likely(aliased != NoAliasBinding): + var symfunc {.cursor.} = GetSym(aliased.name.s) + if symfunc.kind==Function: + current.addCall(newString(aliased.name.s), symfunc.arity) + else: + if aliased.name.s == "null": + current.addTerminal(VNULL) + else: + current.addTerminal(newString(aliased.name.s), flags={Variable}) + else: + current.addTerminal(item) + of Newline: discard @@ -146,6 +207,12 @@ proc processBlock*(root: Node, blok: Value) = i += 1 + when processingArrow: + if current.kind == RootNode: + break + + return i-1 + proc dumpNode*(node: Node, level = 0): string = template indentNode(): untyped = var j = 0 @@ -182,6 +249,6 @@ proc generateAst*(parsed: Value): Node = if v.kind == Function: {k: v.arity} - result.processBlock(parsed) + discard result.processBlock(parsed) echo dumpNode(result) \ No newline at end of file From 336a0f5d5b79e69fe272340001e46241384b6782 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:02:47 +0100 Subject: [PATCH 117/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d28164d554..0b6638d5f8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3521 \ No newline at end of file +3522 \ No newline at end of file From 948ecb78c0b7ad69f463c2f0142fa6d433785776 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:03:07 +0100 Subject: [PATCH 118/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0b6638d5f8..ca7cdd5312 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3522 \ No newline at end of file +3523 \ No newline at end of file From d33dc2b6d99423ba6bb82e385473ff6bd6113cba Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:08:44 +0100 Subject: [PATCH 119/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ca7cdd5312..5175d69ecd 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3523 \ No newline at end of file +3524 \ No newline at end of file From 7506b5ec9bae2c1801c170b71b102b98f9316478 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:12:24 +0100 Subject: [PATCH 120/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5175d69ecd..c9667be05d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3524 \ No newline at end of file +3525 \ No newline at end of file From 7cefa41910e80ec4327446bb9a2ce86ec2f13ee7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:13:36 +0100 Subject: [PATCH 121/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c9667be05d..72a1af7d8e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3525 \ No newline at end of file +3526 \ No newline at end of file From 88d0d37ec2afcf42008713e6f1a78552800a9e14 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:16:10 +0100 Subject: [PATCH 122/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 72a1af7d8e..2e5b138dfc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3526 \ No newline at end of file +3527 \ No newline at end of file From 3da462dfb54d90580ccaab9ecff00ce29ab38112 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:17:45 +0100 Subject: [PATCH 123/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2e5b138dfc..da58d92237 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3527 \ No newline at end of file +3528 \ No newline at end of file From 097ab265b72633b6321e9b22bf9b05474d0017b4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:20:56 +0100 Subject: [PATCH 124/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index da58d92237..26fbe63bad 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3528 \ No newline at end of file +3529 \ No newline at end of file From 1c495e816120e14263e994717953cd24b3afdaca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:21:06 +0100 Subject: [PATCH 125/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 26fbe63bad..55943e2980 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3529 \ No newline at end of file +3530 \ No newline at end of file From 290653808197512404312b7dacc7edd8be01d820 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:24:17 +0100 Subject: [PATCH 126/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 55943e2980..2bdd83c120 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3530 \ No newline at end of file +3531 \ No newline at end of file From 32afad1fd1cc592afe43361948188ec5c0e05c53 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:25:19 +0100 Subject: [PATCH 127/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2bdd83c120..d786ec9571 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3531 \ No newline at end of file +3532 \ No newline at end of file From b0b823f08b2bd60409a01dd7f34ae2f8414ceb75 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:26:30 +0100 Subject: [PATCH 128/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d786ec9571..0b20ff67e8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3532 \ No newline at end of file +3533 \ No newline at end of file From 8d8d41d92c113d21e3a7ceeecb4e9f4fe885dc5e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:29:03 +0100 Subject: [PATCH 129/984] moved `generateAst` to top (so that the previous/current/you-name-it evaluator doesn't mess up our values in some cases, e.g. thickarrowright blocks) --- src/vm/eval.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index ea4db18e8f..7dbc3a4450 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -1098,6 +1098,8 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr ## Take a parsed Block of values and return its Translation - ## that is: the constants found + the list of bytecode instructions + discard generateAst(root) + var vhash {.used.}: Hash = -1 when useStored: @@ -1120,8 +1122,6 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr # when defined(OPTIMIZED): # newit = optimizeBytecode(newit) - discard generateAst(root) - result = Translation(constants: cnsts, instructions: newit) when useStored: From dc84303d1c8928446e689f56c7a9e9011dd4e59e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 12:29:20 +0100 Subject: [PATCH 130/984] VM/ast: added support for thickarrowblock syntactic sugar --- src/vm/ast.nim | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 669f026587..8ae8e4b1b3 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -126,6 +126,47 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b ArrowBlock.setLen(0) + proc addThickArrowBlocks(target: var Node) = + # get next node + let subnode {.cursor.} = blok.a[i+1] + + # we'll want to create the two blocks, + # for functions like loop, map, select, filter + # so let's get them ready + var argblock, subblock: ValueArray + + # if it's a word + if subnode.kind==Word: + subblock = @[subnode] + # check if it's a function + if (let funcArity = TmpArities.getOrDefault(subnode.s, -1); funcArity != -1): + # automatically "push" all its required arguments + for j in 0..(funcArity-1): + let arg = newWord("_" & $(j)) + argblock.add(arg) + subblock.add(arg) + + elif subnode.kind==Block: + # replace ampersand symbols, + # sequentially, with arguments + var idx = 0 + var fnd: int8 = 0 + while idx Date: Sat, 14 Jan 2023 12:31:42 +0100 Subject: [PATCH 131/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0b20ff67e8..adbb550092 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3533 \ No newline at end of file +3534 \ No newline at end of file From 40240aa8ce10c0b1f0d74ccefd40ab9832cf6d3d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:00:26 +0100 Subject: [PATCH 132/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index adbb550092..29a0cc6a7a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3534 \ No newline at end of file +3535 \ No newline at end of file From 2c22904acd8839ff07540415d8bffbb4c2b18b41 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:03:07 +0100 Subject: [PATCH 133/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 29a0cc6a7a..7ae3072f38 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3535 \ No newline at end of file +3536 \ No newline at end of file From c1523e50209b05e1f63c4879089d3b58864b1930 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:07:35 +0100 Subject: [PATCH 134/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7ae3072f38..d0a3f3d9d7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3536 \ No newline at end of file +3537 \ No newline at end of file From 6fbe034048a15c292225e7a7ef31735778fc5c5a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:08:32 +0100 Subject: [PATCH 135/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d0a3f3d9d7..fd02f0c4f7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3537 \ No newline at end of file +3538 \ No newline at end of file From 6f007f3264c7f8a0bcfcbe4e7c6899d3d9d03439 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:16:44 +0100 Subject: [PATCH 136/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index fd02f0c4f7..d6bef3b1e4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3538 \ No newline at end of file +3539 \ No newline at end of file From cd1a0b90ed2fbba0881923437877a86357c692f1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:18:03 +0100 Subject: [PATCH 137/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d6bef3b1e4..7c1fecedd5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3539 \ No newline at end of file +3540 \ No newline at end of file From 41f3b163e8ffd2af0825931a0cb72c8e6b6c3839 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:24:34 +0100 Subject: [PATCH 138/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7c1fecedd5..1fecda61fb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3540 \ No newline at end of file +3541 \ No newline at end of file From 8930a57363d368c8557b9b0fc583f64ba2e18da4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:26:55 +0100 Subject: [PATCH 139/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1fecda61fb..d8709abb90 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3541 \ No newline at end of file +3542 \ No newline at end of file From 19ffe3ff1585831792b07545fa12ac4b9331a2a2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:28:24 +0100 Subject: [PATCH 140/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d8709abb90..3c2f4e41ab 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3542 \ No newline at end of file +3543 \ No newline at end of file From 1456787f034e0e39b359552e29d20d43795c7877 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:32:40 +0100 Subject: [PATCH 141/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3c2f4e41ab..721b9d0b4b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3543 \ No newline at end of file +3544 \ No newline at end of file From ccdf27b246bb57e6d735aec7c5e85b9d003083b0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:34:57 +0100 Subject: [PATCH 142/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 721b9d0b4b..9a64ce48a9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3544 \ No newline at end of file +3545 \ No newline at end of file From 1c3754feff894b19aeeef14283724a0ed180a299 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:35:39 +0100 Subject: [PATCH 143/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9a64ce48a9..6e26bce0c0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3545 \ No newline at end of file +3546 \ No newline at end of file From b3b3ee6a737d3bacaea70fe375ce924a080fcbf9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:38:05 +0100 Subject: [PATCH 144/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6e26bce0c0..754c3080a6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3546 \ No newline at end of file +3547 \ No newline at end of file From 80ce8b0518d9dad0ecee6a14892a23255597125d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:45:12 +0100 Subject: [PATCH 145/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 754c3080a6..9abe90aeea 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3547 \ No newline at end of file +3548 \ No newline at end of file From 82deb85048adcb18f91f94a7d3d8e08affbdaa40 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:49:58 +0100 Subject: [PATCH 146/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9abe90aeea..38933b4d3f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3548 \ No newline at end of file +3549 \ No newline at end of file From 8a6bb47e91b541dbcbc8e7a967a46f9d7b7e0668 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:51:52 +0100 Subject: [PATCH 147/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 38933b4d3f..9df08341bf 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3549 \ No newline at end of file +3550 \ No newline at end of file From 01139495611aa15cf4a7348f3e3184be6ac4d0f7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:52:08 +0100 Subject: [PATCH 148/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9df08341bf..94703639b4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3550 \ No newline at end of file +3551 \ No newline at end of file From de143717651afc53e978abe94028278147a5732a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:53:25 +0100 Subject: [PATCH 149/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 94703639b4..26747e453c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3551 \ No newline at end of file +3552 \ No newline at end of file From 73d1d4c5ae382cc9f0d8bcb555f98b114f0bc4d2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:54:51 +0100 Subject: [PATCH 150/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 26747e453c..0af3c09f5e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3552 \ No newline at end of file +3553 \ No newline at end of file From ac9b36db82756636a8c68f7584181f62d4fe71dd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:55:28 +0100 Subject: [PATCH 151/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0af3c09f5e..1578f2cbc3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3553 \ No newline at end of file +3554 \ No newline at end of file From e67e86b39962a83524457326161873bfe5e9600d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 13:57:59 +0100 Subject: [PATCH 152/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1578f2cbc3..97a7403350 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3554 \ No newline at end of file +3555 \ No newline at end of file From 85eb72e22efd74c82ca719208121ce69678faf09 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:01:42 +0100 Subject: [PATCH 153/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 97a7403350..e43820444a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3555 \ No newline at end of file +3556 \ No newline at end of file From 95e297a53ce273cf76db6bd9d2346257e09c4ab2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:22:21 +0100 Subject: [PATCH 154/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e43820444a..7de1db4faf 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3556 \ No newline at end of file +3557 \ No newline at end of file From 44de03969eb9f78eabf51e341ef56e9e589f3e6d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:24:31 +0100 Subject: [PATCH 155/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7de1db4faf..7c0636fb84 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3557 \ No newline at end of file +3558 \ No newline at end of file From 6dd9d721398db1b74675fc01193b76713b382416 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:26:58 +0100 Subject: [PATCH 156/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7c0636fb84..cc1c76fe33 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3558 \ No newline at end of file +3559 \ No newline at end of file From bf7355df7e5ca70731061e767b3e1f52a643f72c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:29:05 +0100 Subject: [PATCH 157/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cc1c76fe33..700e4e3838 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3559 \ No newline at end of file +3560 \ No newline at end of file From f11fa5b5c1c7269581634844b8801de6d17ee60c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:30:48 +0100 Subject: [PATCH 158/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 700e4e3838..4873c5ad52 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3560 \ No newline at end of file +3561 \ No newline at end of file From d67805eb6c4dce1c717d8c1ab680a56d5c929464 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:32:30 +0100 Subject: [PATCH 159/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4873c5ad52..398f2eab0f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3561 \ No newline at end of file +3562 \ No newline at end of file From 35337357ddfccc634266f73dd32ce9a4fb52d17c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:35:13 +0100 Subject: [PATCH 160/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 398f2eab0f..eaab70c46c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3562 \ No newline at end of file +3563 \ No newline at end of file From a284734d8f5e22193201cdfae04b897a9e46c7c7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:37:36 +0100 Subject: [PATCH 161/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index eaab70c46c..f25519951b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3563 \ No newline at end of file +3564 \ No newline at end of file From 5ce05a78e15914c96928caab00f9d4cc4a08a2bc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:43:47 +0100 Subject: [PATCH 162/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f25519951b..4e273fbded 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3564 \ No newline at end of file +3565 \ No newline at end of file From 03f30542981e42d3b7e822065a79888e64b4dfb1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:48:51 +0100 Subject: [PATCH 163/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4e273fbded..049009b6f4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3565 \ No newline at end of file +3566 \ No newline at end of file From 84d7cdbbc7361b1fd2b9561dd4e8729d56afc0d5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 14:59:28 +0100 Subject: [PATCH 164/984] added support for Pipe operators (almost working!) --- src/vm/ast.nim | 52 +++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 8ae8e4b1b3..e266d960af 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -45,6 +45,10 @@ type var TmpArities : Table[string,int8] ArrowBlock : ValueArray + OldChild : Node + OldParent : Node + +proc dumpNode*(node: Node, level = 0): string func addChild*(node: Node, child: Node) = node.children.add(child) @@ -71,6 +75,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b ) target = target.children[^1] + template isSymbol(val: Value, sym: VSymbol): bool = + val.kind == Symbol and val.m == sym + template rewindCallBranches(target: var Node): untyped = while target.kind==CallNode and target.children.len == target.arity: target = target.parent @@ -102,7 +109,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b flags: flags ) ) - + rewindCallBranches() proc addInline(target: var Node, val: Value, flags: NodeFlags = {}) = @@ -152,7 +159,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var idx = 0 var fnd: int8 = 0 while idx Date: Sat, 14 Jan 2023 15:02:15 +0100 Subject: [PATCH 165/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 049009b6f4..59176e9b6e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3566 \ No newline at end of file +3567 \ No newline at end of file From 56011ff05f1a5786ca8b00e541d0f3e6d0bf2c18 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 15:03:48 +0100 Subject: [PATCH 166/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 59176e9b6e..e56811265a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3567 \ No newline at end of file +3568 \ No newline at end of file From ea1366bd76c4e3696906895abc8bdaead2e903af Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 15:05:06 +0100 Subject: [PATCH 167/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e56811265a..52e1298899 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3568 \ No newline at end of file +3569 \ No newline at end of file From 372ad70bf4a8b6ccae9dfdc6ee69082d950e2f5f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 15:07:43 +0100 Subject: [PATCH 168/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 52e1298899..6462157ca6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3569 \ No newline at end of file +3570 \ No newline at end of file From 9a98f2331f7095031f6100ac3100918521043737 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 15:07:58 +0100 Subject: [PATCH 169/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6462157ca6..1dc26f3ebe 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3570 \ No newline at end of file +3571 \ No newline at end of file From bfb32dbca0244d63525a07bbbc26788eadfd4177 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 15:09:36 +0100 Subject: [PATCH 170/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1dc26f3ebe..dbec38399e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3571 \ No newline at end of file +3572 \ No newline at end of file From 990aef70545276596b41e46fe102440b7a1d08a6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 15:09:53 +0100 Subject: [PATCH 171/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index dbec38399e..6cf126fe41 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3572 \ No newline at end of file +3573 \ No newline at end of file From 0ed0969610b5400f0d0adf70b88c5b871e8f3ade Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 15:14:14 +0100 Subject: [PATCH 172/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6cf126fe41..11a42c55b5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3573 \ No newline at end of file +3574 \ No newline at end of file From 50c9d3f0e836820963375074ec16b1304fbfe0cc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 14 Jan 2023 15:20:36 +0100 Subject: [PATCH 173/984] pipe operators being - seemingly - parsed processed fine (at last! :o) --- src/vm/ast.nim | 51 ++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index e266d960af..0398133e36 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -77,9 +77,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b template isSymbol(val: Value, sym: VSymbol): bool = val.kind == Symbol and val.m == sym - - template rewindCallBranches(target: var Node): untyped = - while target.kind==CallNode and target.children.len == target.arity: + + template rewindCallBranches(target: var Node, uptostore=false): untyped = + while target.kind==CallNode and target.children.len == target.arity and (when uptostore: StoreSymbol notin target.flags else: true): target = target.parent template addPotentialInfixCall(target: var Node): untyped = @@ -112,6 +112,32 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b rewindCallBranches() + template addPotentialTrailingPipe(target: var Node): untyped = + var added = false + if i < nLen - 1: + var nextNode {.cursor.} = blok.a[i+1] + if nextNode.kind == Word and GetSym(nextNode.s).kind == Function: + if (let funcArity = TmpArities.getOrDefault(nextNode.s, -1); funcArity != -1): + i += 1 + target.rewindCallBranches() + + var lastChild = target.children[^1] + if StoreSymbol in lastChild.flags: + lastChild = lastChild.children[^1] + target = lastChild.parent + + target.children.delete(target.children.len-1) + + target.addCall(nextNode, funcArity) + target.addChild(lastChild) + + target.rewindCallBranches() + + added = true + + if not added: + target.addTerminal(newSymbol(pipe)) + proc addInline(target: var Node, val: Value, flags: NodeFlags = {}) = var subNode = Node(kind: RootNode) discard subNode.processBlock(val) @@ -174,25 +200,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target.addTerminal(newBlock(subblock)) - template addPotentialTrailingPipe(target: var Node): untyped = - var added = false - if i < nLen - 1: - var nextNode {.cursor.} = blok.a[i+1] - if nextNode.kind == Word and GetSym(nextNode.s).kind == Function: - if (let funcArity = TmpArities.getOrDefault(nextNode.s, -1); funcArity != -1): - i += 1 - - var lastChild = target.children[^1] - target.children.delete(target.children.len-1) - - target.addCall(nextNode, funcArity) - target.addChild(lastChild) - - target.rewindCallBranches() - - if not added: - target.addTerminal(newSymbol(pipe)) - while i < nLen: let item = blok.a[i] From 1fb41730bd597cd84152657e47b25d24ad56c1d1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 12:26:11 +0100 Subject: [PATCH 174/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 11a42c55b5..6f27aec0bb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3574 \ No newline at end of file +3575 \ No newline at end of file From 00dc55e26815606a5a63324abda195306e922788 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 12:31:32 +0100 Subject: [PATCH 175/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6f27aec0bb..e092829e26 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3575 \ No newline at end of file +3576 \ No newline at end of file From 03f84f08e255ccaed34242cb9d42d7c203d89fbd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 12:37:19 +0100 Subject: [PATCH 176/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e092829e26..2161dc875f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3576 \ No newline at end of file +3577 \ No newline at end of file From 2a2f4b9d227c5e2992ff5b3d0d4252c75d65c768 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 12:42:37 +0100 Subject: [PATCH 177/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2161dc875f..5e296930e3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3577 \ No newline at end of file +3578 \ No newline at end of file From b4fd21d1e8fa3a55c2a1bcf94ad00f06b511d48a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 12:44:16 +0100 Subject: [PATCH 178/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5e296930e3..41e9aa14c3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3578 \ No newline at end of file +3579 \ No newline at end of file From be74c911c327730596add30b4bf0c38e8e9e942c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 12:50:28 +0100 Subject: [PATCH 179/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 41e9aa14c3..13c6547692 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3579 \ No newline at end of file +3580 \ No newline at end of file From 6cdcd4c6cdcf92748422fd392b44c3fe516fd8dc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:01:33 +0100 Subject: [PATCH 180/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 13c6547692..c5b106365c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3580 \ No newline at end of file +3581 \ No newline at end of file From 1a8b160b5b6bd80db5fed843138dcdc8c0c94469 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:03:32 +0100 Subject: [PATCH 181/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c5b106365c..d42117afda 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3581 \ No newline at end of file +3582 \ No newline at end of file From 4c1c51c22d83118637fb4e0949d8d334e3a8fb62 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:10:00 +0100 Subject: [PATCH 182/984] properly process OpCode'd built-in functions + general cleanup --- src/vm/ast.nim | 215 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 172 insertions(+), 43 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 0398133e36..e31eca2b26 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -1,36 +1,82 @@ -import hashes, sugar, tables -import unicode, std/with +import hashes, strutils, sugar +import tables, unicode, std/with -import vm/[globals, values/value] +import vm/[globals, values/value, values/types] import vm/values/printable import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vrational, vsymbol, vversion] type # abstract syntax tree definition NodeKind* = enum - RootNode, - CallNode, - TerminalNode - - NodeArray* = seq[Node] + RootNode # Root node of the AST + + # TerminalNode + ConstantValue # Terminal node of the AST containing a value + VariableLoad # Load a variable - NodeFlag* = enum - Variable, + # CallNode + VariableStore # Store a variable - StoreSymbol, + ArrayCall # Opcode'd built-ins + DictCall + FuncCall AddCall + SubCall + MulCall + DivCall + FdivCall + ModCall + PowCall + NegCall + BNotCall + BAndCall + BOrCall + ShlCall + ShrCall + NotCall + AndCall + OrCall + EqCall + NeCall + GtCall + GeCall + LtCall + LeCall + IfCall + IfECall + UnlessCall + ElseCall + SwitchCall + WhileCall + ReturnCall + ToCall + PrintCall + GetCall + SetCall + RangeCall + LoopCall + MapCall + SelectCall + SizeCall + ReplaceCall + SplitCall + JoinCall + ReverseCall + IncCall + DecCall + + OtherCall # Call to a function that is not a builtin - NodeFlags* = set[NodeFlag] + NodeArray* = seq[Node] Node* = ref object case kind*: NodeKind: - of CallNode: - arity*: int8 - else: + of RootNode, ConstantValue, VariableLoad: discard - + else: + arity*: int8 + value*: Value - flags*: NodeFlags parent*: Node children*: NodeArray @@ -41,13 +87,16 @@ type {.hint: "Node's inner type is currently " & $sizeof(NodeObj) & ".".} {.hints: off.} - var TmpArities : Table[string,int8] ArrowBlock : ValueArray OldChild : Node OldParent : Node +const + TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} + CallNode : set[NodeKind] = {VariableStore..OtherCall} + proc dumpNode*(node: Node, level = 0): string func addChild*(node: Node, child: Node) = @@ -64,13 +113,91 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var current = root - proc addCall(target: var Node, val: Value, arity: int8, flags: NodeFlags = {}) = + proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = + var callType: ArrayCall..OtherCall = OtherCall + + var fn {.cursor.}: Value = + if fun.isNil: + GetSym(name) + else: + fun + + var ar: int8 = + if arity == -1: + fn.arity + else: + arity + + if fn == ArrayF : callType = ArrayCall + elif fn == DictF : callType = DictCall + elif fn == FuncF : callType = FuncCall + elif fn == AddF : callType = AddCall + elif fn == SubF : callType = SubCall + elif fn == MulF : callType = MulCall + elif fn == DivF : callType = DivCall + elif fn == FdivF : callType = FdivCall + elif fn == ModF : callType = ModCall + elif fn == PowF : callType = PowCall + elif fn == NegF : callType = NegCall + elif fn == BNotF : callType = BNotCall + elif fn == BAndF : callType = BAndCall + elif fn == BOrF : callType = BOrCall + elif fn == ShlF : callType = ShlCall + elif fn == ShrF : callType = ShrCall + elif fn == NotF : callType = NotCall + elif fn == AndF : callType = AndCall + elif fn == OrF : callType = OrCall + elif fn == EqF : callType = EqCall + elif fn == NeF : callType = NeCall + elif fn == GtF : callType = GtCall + elif fn == GeF : callType = GeCall + elif fn == LtF : callType = LtCall + elif fn == LeF : callType = LeCall + elif fn == IfF : callType = IfCall + elif fn == IfEF : callType = IfECall + elif fn == UnlessF : callType = UnlessCall + elif fn == ElseF : callType = ElseCall + elif fn == SwitchF : callType = SwitchCall + elif fn == WhileF : callType = WhileCall + elif fn == ReturnF : callType = ReturnCall + elif fn == ToF : callType = ToCall + elif fn == PrintF : callType = PrintCall + elif fn == GetF : callType = GetCall + elif fn == SetF : callType = SetCall + elif fn == RangeF : callType = RangeCall + elif fn == LoopF : callType = LoopCall + elif fn == MapF : callType = MapCall + elif fn == SelectF : callType = SelectCall + elif fn == SizeF : callType = SizeCall + elif fn == ReplaceF : callType = ReplaceCall + elif fn == SplitF : callType = SplitCall + elif fn == JoinF : callType = JoinCall + elif fn == ReverseF : callType = ReverseCall + elif fn == IncF : callType = IncCall + elif fn == DecF : callType = DecCall + + var v: Value = + if callType == OtherCall: + newString(name) + else: + nil + + target.addChild( + Node( + kind: callType, + value: v, + arity: ar + ) + ) + + target = target.children[^1] + + proc addStore(target: var Node, val: Value) = target.addChild( Node( - kind: CallNode, + kind: VariableStore, value: val, - arity: arity, - flags: flags + arity: 1 ) ) target = target.children[^1] @@ -78,8 +205,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b template isSymbol(val: Value, sym: VSymbol): bool = val.kind == Symbol and val.m == sym - template rewindCallBranches(target: var Node, uptostore=false): untyped = - while target.kind==CallNode and target.children.len == target.arity and (when uptostore: StoreSymbol notin target.flags else: true): + template rewindCallBranches(target: var Node): untyped = + while target.kind in CallNode and target.children.len == target.arity: target = target.parent template addPotentialInfixCall(target: var Node): untyped = @@ -94,9 +221,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b when processingArrow: ArrowBlock.add(nextNode) i += 1 - target.addCall(newString(aliased.name.s), symfunc.arity) + target.addCall(aliased.name.s, fun=symfunc) - proc addTerminal(target: var Node, val: Value, flags: NodeFlags = {}) = + proc addTerminal(target: var Node, val: Value, ofType: NodeKind = ConstantValue) = with target: rewindCallBranches() @@ -104,9 +231,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b addChild( Node( - kind: TerminalNode, - value: val, - flags: flags + kind: ofType, + value: val ) ) @@ -116,19 +242,19 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var added = false if i < nLen - 1: var nextNode {.cursor.} = blok.a[i+1] - if nextNode.kind == Word and GetSym(nextNode.s).kind == Function: + if nextNode.kind == Word: if (let funcArity = TmpArities.getOrDefault(nextNode.s, -1); funcArity != -1): i += 1 target.rewindCallBranches() var lastChild = target.children[^1] - if StoreSymbol in lastChild.flags: + if lastChild.kind == VariableStore: lastChild = lastChild.children[^1] target = lastChild.parent target.children.delete(target.children.len-1) - target.addCall(nextNode, funcArity) + target.addCall(nextNode.s, funcArity) target.addChild(lastChild) target.rewindCallBranches() @@ -138,7 +264,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if not added: target.addTerminal(newSymbol(pipe)) - proc addInline(target: var Node, val: Value, flags: NodeFlags = {}) = + proc addInline(target: var Node, val: Value) = var subNode = Node(kind: RootNode) discard subNode.processBlock(val) @@ -151,7 +277,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b rewindCallBranches() - proc addArrowBlock(target: var Node, val: Value, flags: NodeFlags = {}) = + proc addArrowBlock(target: var Node, val: Value) = var subNode = Node(kind: RootNode) i = subNode.processBlock(val, start=i+1, processingArrow=true) @@ -207,21 +333,20 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b ArrowBlock.add(item) case item.kind: - of Word: var funcArity = TmpArities.getOrDefault(item.s, -1) if funcArity != -1: - current.addCall(item, funcArity) + current.addCall(item.s, funcArity) else: if item.s == "true": current.addTerminal(VTRUE) elif item.s == "false": current.addTerminal(VFALSE) else: - current.addTerminal(item, flags={Variable}) + current.addTerminal(item, ofType=VariableLoad) of Label, PathLabel: - current.addCall(item, 1, flags={StoreSymbol}) + current.addStore(item) of Inline: current.addInline(item) @@ -244,7 +369,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b current.addThickArrowBlocks() of pipe : - echo "found pipe!" current.addPotentialTrailingPipe() else: @@ -253,12 +377,12 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if likely(aliased != NoAliasBinding): var symfunc {.cursor.} = GetSym(aliased.name.s) if symfunc.kind==Function: - current.addCall(newString(aliased.name.s), symfunc.arity) + current.addCall(aliased.name.s, fun=symfunc) else: if aliased.name.s == "null": current.addTerminal(VNULL) else: - current.addTerminal(newString(aliased.name.s), flags={Variable}) + current.addTerminal(newString(aliased.name.s), ofType=VariableLoad) else: current.addTerminal(item) @@ -293,14 +417,19 @@ proc dumpNode*(node: Node, level = 0): string = of TerminalNode: indentNode() result &= "Constant: " & $(node.value) + of CallNode: indentNode() - if StoreSymbol in node.flags: + if node.kind == VariableStore: result &= "Store: " & $(node.value) & "\n" else: - result &= "Call: " & node.value.s & " <" & $node.arity & ">\n" + if node.value.isNil: + result &= "Call: " & ($node.kind).replace("Call","").toLowerAscii() & " <" & $node.arity & ">\n" + else: + result &= "Call: " & node.value.s & " <" & $node.arity & ">\n" for child in node.children: result &= dumpNode(child, level+1) + result &= "\n" From e6bc1b530539704f82d54c297a6a8016f748fde5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:26:36 +0100 Subject: [PATCH 183/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d42117afda..2f2a299870 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3582 \ No newline at end of file +3583 \ No newline at end of file From bccdc3e091ebc47e9c65abb6f20e2a7179addc62 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:28:41 +0100 Subject: [PATCH 184/984] cleanup + added comments --- src/vm/ast.nim | 95 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 20 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index e31eca2b26..04b4aa95f7 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -1,3 +1,24 @@ +#======================================================= +# Arturo +# Programming Language + Bytecode VM compiler +# (c) 2019-2023 Yanis ZafirΓ³pulos +# +# @file: vm/ast.nim +#======================================================= + +## This module contains the AST implementation for the VM. +## +## In a few words, it: +## - takes a Block of values coming from the parser +## - transforms it into an AST tree with semantics +## ready for the evaluator +## +## The main entry point is ``generateAst``. + +#======================================= +# Libraries +#======================================= + import hashes, strutils, sugar import tables, unicode, std/with @@ -5,6 +26,10 @@ import vm/[globals, values/value, values/types] import vm/values/printable import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vrational, vsymbol, vversion] +#======================================= +# Types +#======================================= + type # abstract syntax tree definition NodeKind* = enum @@ -83,9 +108,13 @@ type NodeObj = typeof(Node()[]) # Benchmarking -{.hints: on.} # Apparently we cannot disable just `Name` hints? +{.hints: on.} {.hint: "Node's inner type is currently " & $sizeof(NodeObj) & ".".} {.hints: off.} + +#======================================= +# Variables +#======================================= var TmpArities : Table[string,int8] @@ -93,26 +122,51 @@ var OldChild : Node OldParent : Node +#======================================= +# Constants +#======================================= + const TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} CallNode : set[NodeKind] = {VariableStore..OtherCall} -proc dumpNode*(node: Node, level = 0): string +#======================================= +# Helpers +#======================================= func addChild*(node: Node, child: Node) = node.children.add(child) child.parent = node -func addChildren*(node: Node, children: NodeArray) = +template addChildren*(node: Node, children: NodeArray) = for child in children: node.addChild(child) +template isSymbol(val: Value, sym: VSymbol): bool = + val.kind == Symbol and val.m == sym + +#======================================= +# Methods +#======================================= + proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static bool = false): int = var i: int = start var nLen: int = blok.a.len var current = root + #------------------------ + # Helper Functions + #------------------------ + + template rewindCallBranches(target: var Node): untyped = + while target.kind in CallNode and target.children.len == target.arity: + target = target.parent + + #------------------------ + # AST Generation + #------------------------ + proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = var callType: ArrayCall..OtherCall = OtherCall @@ -192,7 +246,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target = target.children[^1] - proc addStore(target: var Node, val: Value) = + func addStore(target: var Node, val: Value) {.enforceNoRaises.} = target.addChild( Node( kind: VariableStore, @@ -202,13 +256,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b ) target = target.children[^1] - template isSymbol(val: Value, sym: VSymbol): bool = - val.kind == Symbol and val.m == sym - - template rewindCallBranches(target: var Node): untyped = - while target.kind in CallNode and target.children.len == target.arity: - target = target.parent - template addPotentialInfixCall(target: var Node): untyped = if i < nLen - 1: let nextNode {.cursor.} = blok.a[i+1] @@ -326,6 +373,10 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target.addTerminal(newBlock(subblock)) + #------------------------ + # The Main Loop + #------------------------ + while i < nLen: let item = blok.a[i] @@ -400,18 +451,18 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b return i-1 +#======================================= +# Output +#======================================= + proc dumpNode*(node: Node, level = 0): string = template indentNode(): untyped = - var j = 0 - while j < level: - result &= " " - j += 1 + result &= " ".repeat(level) - let sep = " " case node.kind: of RootNode: indentNode() - result &= "ROOT\n" + result &= "ROOT: \n" for child in node.children: result &= dumpNode(child, level+1) of TerminalNode: @@ -423,16 +474,20 @@ proc dumpNode*(node: Node, level = 0): string = if node.kind == VariableStore: result &= "Store: " & $(node.value) & "\n" else: + result &= "Call: " if node.value.isNil: - result &= "Call: " & ($node.kind).replace("Call","").toLowerAscii() & " <" & $node.arity & ">\n" + result &= ($node.kind).replace("Call","").toLowerAscii() & " <" & $node.arity & ">\n" else: - result &= "Call: " & node.value.s & " <" & $node.arity & ">\n" + result &= node.value.s & " <" & $node.arity & ">\n" for child in node.children: result &= dumpNode(child, level+1) - result &= "\n" +#======================================= +# Main +#======================================= + proc generateAst*(parsed: Value): Node = result = Node(kind: RootNode) From 31cc64fc1a0edbd091c647f139219b073192e6c0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:37:26 +0100 Subject: [PATCH 185/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2f2a299870..01488fdeab 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3583 \ No newline at end of file +3584 \ No newline at end of file From f3ef1ca96dad7780dc2250963c6243f7011e9d1c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:41:27 +0100 Subject: [PATCH 186/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 01488fdeab..ece5ccdcaf 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3584 \ No newline at end of file +3585 \ No newline at end of file From 394835c5ad0730d4296e21d0916a12de16cef307 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:47:30 +0100 Subject: [PATCH 187/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ece5ccdcaf..b6873d7923 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3585 \ No newline at end of file +3586 \ No newline at end of file From dc0aaac3d5144c01f680017cc507acc10fd747c0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:48:19 +0100 Subject: [PATCH 188/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b6873d7923..9a772673a3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3586 \ No newline at end of file +3587 \ No newline at end of file From aed8bf09408d1ac9d1d06da056c657cb012ddf5f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:51:21 +0100 Subject: [PATCH 189/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9a772673a3..b723ff926a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3587 \ No newline at end of file +3588 \ No newline at end of file From bb58b50a20852b981d17ac4dc982232cc75234af Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:53:28 +0100 Subject: [PATCH 190/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b723ff926a..259b7fef5c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3588 \ No newline at end of file +3589 \ No newline at end of file From 2e343755f1f3981b3e177fa034afafb192b3f1fa Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:53:38 +0100 Subject: [PATCH 191/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 259b7fef5c..0247df2d15 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3589 \ No newline at end of file +3590 \ No newline at end of file From c9549424bf59c08a93e15869a22f5876810ad1f7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 13:58:39 +0100 Subject: [PATCH 192/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0247df2d15..d5b91a9ad6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3590 \ No newline at end of file +3592 \ No newline at end of file From fda2b20ea8388e0ebf5b28f8400c4b12426ce5ee Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:05:14 +0100 Subject: [PATCH 193/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d5b91a9ad6..1ca12337c1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3592 \ No newline at end of file +3593 \ No newline at end of file From 51b3e0a7ab17162489f11c3d34f897d5a8bbdfcf Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:08:15 +0100 Subject: [PATCH 194/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1ca12337c1..7d10213cc2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3593 \ No newline at end of file +3594 \ No newline at end of file From b15c59cb231630b611667fceb4fba2fb87a3b1e4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:12:19 +0100 Subject: [PATCH 195/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7d10213cc2..cbe335140a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3594 \ No newline at end of file +3595 \ No newline at end of file From c23099f0cb410fbbf8031fc03b12e5eb6e5afa43 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:12:56 +0100 Subject: [PATCH 196/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cbe335140a..b4b7bda4a6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3595 \ No newline at end of file +3596 \ No newline at end of file From ca7def917f50447fbda9769cde4f66a5d0bf46da Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:17:27 +0100 Subject: [PATCH 197/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b4b7bda4a6..721dfaa42d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3596 \ No newline at end of file +3597 \ No newline at end of file From 639ebb37cd2e75cfd1cf76f5778da2b2fefafe33 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:18:52 +0100 Subject: [PATCH 198/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 721dfaa42d..0fa8bb4f10 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3597 \ No newline at end of file +3598 \ No newline at end of file From 8d9e20c3e7af1d5630c3b5ba80e959daa94afa7a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:21:08 +0100 Subject: [PATCH 199/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0fa8bb4f10..3e40a4127b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3598 \ No newline at end of file +3599 \ No newline at end of file From 4f00a0c33b50ca7dcb0c215f86ab7fdf4fa82f43 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:25:07 +0100 Subject: [PATCH 200/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3e40a4127b..10c6f27f64 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3599 \ No newline at end of file +3600 \ No newline at end of file From 9047792affc15d68f21b926c17465681da10e445 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:31:42 +0100 Subject: [PATCH 201/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 10c6f27f64..f24a894982 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3600 \ No newline at end of file +3601 \ No newline at end of file From 8cd81bafa984dce2f90df7392169e32bfd17c533 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:34:04 +0100 Subject: [PATCH 202/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f24a894982..914dd157e3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3601 \ No newline at end of file +3602 \ No newline at end of file From ad36ca1dccbc5778c937051c6f2ef6ff7c5c2b31 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:38:43 +0100 Subject: [PATCH 203/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 914dd157e3..4f9728fd88 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3602 \ No newline at end of file +3603 \ No newline at end of file From 1881e7f562a7425f029dba081167143259707103 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:46:50 +0100 Subject: [PATCH 204/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4f9728fd88..96c3b83174 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3603 \ No newline at end of file +3604 \ No newline at end of file From dd33f69fe3cf64ceedce5ef7b560bd82f7e72e95 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 14:47:44 +0100 Subject: [PATCH 205/984] added basic `add`/`sub` optimizations (basically, all `a+1`/`1+a` converted to `inc a`; the same for `dec`) + added contant folding (!!!) --- src/vm/ast.nim | 155 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 129 insertions(+), 26 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 04b4aa95f7..effabed3a3 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -22,7 +22,7 @@ import hashes, strutils, sugar import tables, unicode, std/with -import vm/[globals, values/value, values/types] +import vm/[globals, values/value, values/comparison, values/types] import vm/values/printable import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vrational, vsymbol, vversion] @@ -95,6 +95,8 @@ type NodeArray* = seq[Node] Node* = ref object + idx: int + case kind*: NodeKind: of RootNode, ConstantValue, VariableLoad: discard @@ -130,14 +132,31 @@ const TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} CallNode : set[NodeKind] = {VariableStore..OtherCall} +#======================================= +# Forward declarations +#======================================= + +proc dumpNode*(node: Node, level = 0): string + #======================================= # Helpers #======================================= func addChild*(node: Node, child: Node) = node.children.add(child) + child.idx = node.children.len - 1 child.parent = node +func setOnlyChild*(node: Node, child: Node) = + node.children.setLen(1) + node.addChild(child) + +func replace*(node: var Node, newNode: Node) = + newNode.parent = node.parent + newNode.idx = node.idx + node = newNode + node.parent.children[node.idx] = newNode + template addChildren*(node: Node, children: NodeArray) = for child in children: node.addChild(child) @@ -145,6 +164,28 @@ template addChildren*(node: Node, children: NodeArray) = template isSymbol(val: Value, sym: VSymbol): bool = val.kind == Symbol and val.m == sym +#======================================= +# Constructors +#======================================= + +template newRootNode(): Node = + Node( + kind: RootNode + ) + +template newTerminalNode(kn: NodeKind, va: Value): Node = + Node( + kind: kn, + value: va + ) + +template newCallNode(kn: NodeKind, ar: int8, va: Value): Node = + Node( + kind: kn, + arity: ar, + value: va + ) + #======================================= # Methods #======================================= @@ -155,12 +196,90 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var current = root + #------------------------ + # Optimization + #------------------------ + + proc optimizeAdd(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + var right = target.children[1] + + if left.kind == ConstantValue: + if right.kind == ConstantValue: + target.replace(newTerminalNode(ConstantValue, left.value + right.value)) + elif left.value == I1: + target.kind = IncCall + target.arity = 1 + target.setOnlyChild(right) + elif right.kind == ConstantValue and right.value == I1: + target.kind = IncCall + target.arity = 1 + target.setOnlyChild(left) + + proc optimizeSub(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + var right = target.children[1] + + if left.kind == ConstantValue and right.kind == ConstantValue: + target.replace(newTerminalNode(ConstantValue, left.value - right.value)) + elif right.kind == ConstantValue and right.value == I1: + target.kind = DecCall + target.arity = 1 + target.setOnlyChild(left) + + proc optimizeMul(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + var right = target.children[1] + + if left.kind == ConstantValue and right.kind == ConstantValue: + target.replace(newTerminalNode(ConstantValue, left.value * right.value)) + + proc optimizeDiv(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + var right = target.children[1] + + if left.kind == ConstantValue and right.kind == ConstantValue: + target.replace(newTerminalNode(ConstantValue, left.value / right.value)) + + proc optimizeFdiv(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + var right = target.children[1] + + if left.kind == ConstantValue and right.kind == ConstantValue: + target.replace(newTerminalNode(ConstantValue, left.value // right.value)) + + proc optimizeMod(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + var right = target.children[1] + + if left.kind == ConstantValue and right.kind == ConstantValue: + target.replace(newTerminalNode(ConstantValue, left.value % right.value)) + + proc optimizePow(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + var right = target.children[1] + + if left.kind == ConstantValue and right.kind == ConstantValue: + target.replace(newTerminalNode(ConstantValue, left.value ^ right.value)) + #------------------------ # Helper Functions #------------------------ - template rewindCallBranches(target: var Node): untyped = + template rewindCallBranches(target: var Node, optimize: bool = false): untyped = while target.kind in CallNode and target.children.len == target.arity: + when optimize: + case target.kind: + of AddCall : target.optimizeAdd() + of SubCall : target.optimizeSub() + of MulCall : target.optimizeMul() + of DivCall : target.optimizeDiv() + of FdivCall : target.optimizeFdiv() + of ModCall : target.optimizeMod() + of PowCall : target.optimizePow() + else: + discard + target = target.parent #------------------------ @@ -236,24 +355,13 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b else: nil - target.addChild( - Node( - kind: callType, - value: v, - arity: ar - ) - ) + target.addChild(newCallNode(callType, ar, v)) target = target.children[^1] func addStore(target: var Node, val: Value) {.enforceNoRaises.} = - target.addChild( - Node( - kind: VariableStore, - value: val, - arity: 1 - ) - ) + target.addChild(newCallNode(VariableStore, 1, val)) + target = target.children[^1] template addPotentialInfixCall(target: var Node): untyped = @@ -276,14 +384,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b addPotentialInfixCall() - addChild( - Node( - kind: ofType, - value: val - ) - ) + addChild(newTerminalNode(ofType, val)) - rewindCallBranches() + rewindCallBranches(optimize=true) template addPotentialTrailingPipe(target: var Node): untyped = var added = false @@ -312,7 +415,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target.addTerminal(newSymbol(pipe)) proc addInline(target: var Node, val: Value) = - var subNode = Node(kind: RootNode) + var subNode = newRootNode() discard subNode.processBlock(val) with target: @@ -325,7 +428,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b rewindCallBranches() proc addArrowBlock(target: var Node, val: Value) = - var subNode = Node(kind: RootNode) + var subNode = newRootNode() i = subNode.processBlock(val, start=i+1, processingArrow=true) target.addTerminal(newBlock(ArrowBlock)) @@ -489,7 +592,7 @@ proc dumpNode*(node: Node, level = 0): string = #======================================= proc generateAst*(parsed: Value): Node = - result = Node(kind: RootNode) + result = newRootNode() TmpArities = collect: for k,v in Syms.pairs: From a961e47c4df7df40546c0fe49fc68ac903812841 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 16:02:53 +0100 Subject: [PATCH 206/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 96c3b83174..8583a99166 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3604 \ No newline at end of file +3605 \ No newline at end of file From c2e6b16c39db44998c7d26e333368857c5f93ccc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 16:18:35 +0100 Subject: [PATCH 207/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8583a99166..3dc1a234db 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3605 \ No newline at end of file +3606 \ No newline at end of file From 65ca4efd30aa37aa127f39213b96e06de5f8b9f1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 16:20:13 +0100 Subject: [PATCH 208/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3dc1a234db..77d6fc0142 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3606 \ No newline at end of file +3607 \ No newline at end of file From f2349d0c12774b6dfbb6c17987bc2c72d8142837 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 16:24:26 +0100 Subject: [PATCH 209/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 77d6fc0142..384789df5b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3607 \ No newline at end of file +3608 \ No newline at end of file From 14193433532336ce453f8a12596db14565ce60e5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 16:27:40 +0100 Subject: [PATCH 210/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 384789df5b..c316fff427 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3608 \ No newline at end of file +3609 \ No newline at end of file From 75575ce5ae4ec6fcf2bfc3019cfb4d3f2f1d554a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 16:29:38 +0100 Subject: [PATCH 211/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c316fff427..2bd5ab6048 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3609 \ No newline at end of file +3610 \ No newline at end of file From da75a5948c52c97784aa4fe3bead17457deff634 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 16:35:21 +0100 Subject: [PATCH 212/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2bd5ab6048..6a04d62e93 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3610 \ No newline at end of file +3611 \ No newline at end of file From 1ae6e30dddd077ddf15948f965f1f0cf73897cb9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 16:35:51 +0100 Subject: [PATCH 213/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6a04d62e93..c90c75e7d1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3611 \ No newline at end of file +3612 \ No newline at end of file From 1a5779ebb86b6556c1a757ae2ac20c5b191a1836 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 17:01:50 +0100 Subject: [PATCH 214/984] more advanced optimizations for ADD --- src/vm/ast.nim | 102 ++++++++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index effabed3a3..30ddace341 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -204,63 +204,77 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var left = target.children[0] var right = target.children[1] - if left.kind == ConstantValue: - if right.kind == ConstantValue: + if left.kind == ConstantValue and left.value.kind in {Integer, Floating}: + # Constant folding + if right.kind == ConstantValue and right.value.kind in {Integer, Floating}: target.replace(newTerminalNode(ConstantValue, left.value + right.value)) + # Convert 1 + X -> inc X elif left.value == I1: target.kind = IncCall target.arity = 1 target.setOnlyChild(right) + + # Convert X + 1 -> inc X elif right.kind == ConstantValue and right.value == I1: - target.kind = IncCall - target.arity = 1 - target.setOnlyChild(left) + target.kind = IncCall + target.arity = 1 + target.setOnlyChild(left) + + # Convert X + X * Y -> X * (1 + Y) and + # X + Y * X -> X * (Y + 1) + elif left.kind == VariableLoad and right.kind == MulCall: + if right.children[0].kind == VariableLoad and right.children[0].value == left.value: + target.kind = MulCall + if right.children[1].kind == ConstantValue and right.children[1].value.kind in {Integer, Floating}: + right.replace(newTerminalNode(ConstantValue, right.children[1].value + I1)) + else: + right.kind = AddCall + right.children[0].value = newInteger(1) + elif right.children[1].kind == VariableLoad and right.children[1].value == left.value: + target.kind = MulCall + if right.children[0].kind == ConstantValue and right.children[0].value.kind in {Integer, Floating}: + right.replace(newTerminalNode(ConstantValue, right.children[0].value + I1)) + else: + right.kind = AddCall + right.children[1].value = newInteger(1) + + # Convert (X * Y) + X -> (1 + Y) * X and + # (Y * X) + X -> (Y + 1) * X + elif right.kind == VariableLoad and left.kind == MulCall: + if left.children[0].kind == VariableLoad and left.children[0].value == right.value: + target.kind = MulCall + if left.children[1].kind == ConstantValue and left.children[1].value.kind in {Integer, Floating}: + left.replace(newTerminalNode(ConstantValue, left.children[1].value + I1)) + else: + left.kind = AddCall + left.children[0].value = newInteger(1) + elif left.children[1].kind == VariableLoad and left.children[1].value == right.value: + target.kind = MulCall + if left.children[0].kind == ConstantValue and left.children[0].value.kind in {Integer, Floating}: + left.replace(newTerminalNode(ConstantValue, left.children[0].value + I1)) + else: + left.kind = AddCall + left.children[1].value = newInteger(1) proc optimizeSub(target: var Node) {.enforceNoRaises.} = var left = target.children[0] var right = target.children[1] if left.kind == ConstantValue and right.kind == ConstantValue: - target.replace(newTerminalNode(ConstantValue, left.value - right.value)) + # Constant folding + target.replace(newTerminalNode(ConstantValue, left.value - right.value)) elif right.kind == ConstantValue and right.value == I1: - target.kind = DecCall - target.arity = 1 - target.setOnlyChild(left) - - proc optimizeMul(target: var Node) {.enforceNoRaises.} = - var left = target.children[0] - var right = target.children[1] - - if left.kind == ConstantValue and right.kind == ConstantValue: - target.replace(newTerminalNode(ConstantValue, left.value * right.value)) - - proc optimizeDiv(target: var Node) {.enforceNoRaises.} = - var left = target.children[0] - var right = target.children[1] - - if left.kind == ConstantValue and right.kind == ConstantValue: - target.replace(newTerminalNode(ConstantValue, left.value / right.value)) - - proc optimizeFdiv(target: var Node) {.enforceNoRaises.} = - var left = target.children[0] - var right = target.children[1] - - if left.kind == ConstantValue and right.kind == ConstantValue: - target.replace(newTerminalNode(ConstantValue, left.value // right.value)) - - proc optimizeMod(target: var Node) {.enforceNoRaises.} = - var left = target.children[0] - var right = target.children[1] - - if left.kind == ConstantValue and right.kind == ConstantValue: - target.replace(newTerminalNode(ConstantValue, left.value % right.value)) + # Convert X - 1 -> dec X + target.kind = DecCall + target.arity = 1 + target.setOnlyChild(left) - proc optimizePow(target: var Node) {.enforceNoRaises.} = + template optimizeArithmeticOp(target: var Node, op: untyped) = var left = target.children[0] var right = target.children[1] if left.kind == ConstantValue and right.kind == ConstantValue: - target.replace(newTerminalNode(ConstantValue, left.value ^ right.value)) + target.replace(newTerminalNode(ConstantValue, op(left.value,right.value))) #------------------------ # Helper Functions @@ -272,11 +286,11 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b case target.kind: of AddCall : target.optimizeAdd() of SubCall : target.optimizeSub() - of MulCall : target.optimizeMul() - of DivCall : target.optimizeDiv() - of FdivCall : target.optimizeFdiv() - of ModCall : target.optimizeMod() - of PowCall : target.optimizePow() + of MulCall : target.optimizeArithmeticOp(`*`) + of DivCall : target.optimizeArithmeticOp(`/`) + of FdivCall : target.optimizeArithmeticOp(`//`) + of ModCall : target.optimizeArithmeticOp(`%`) + of PowCall : target.optimizeArithmeticOp(`^`) else: discard From d97da9f91a3f4971dbc0fdb0ae9e303c33a63284 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 17:26:05 +0100 Subject: [PATCH 215/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c90c75e7d1..cb64f0de9c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3612 \ No newline at end of file +3613 \ No newline at end of file From ac36056a0c3dc0d46ce48156c42a4b748cf1d94e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 17:28:53 +0100 Subject: [PATCH 216/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cb64f0de9c..cada359281 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3613 \ No newline at end of file +3614 \ No newline at end of file From d1775f12f6bdedc72013654fc18097812303020e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 17:30:34 +0100 Subject: [PATCH 217/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cada359281..56bfa469aa 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3614 \ No newline at end of file +3615 \ No newline at end of file From 13bdff58d9d17bae9ed5c18ef715f39f9028e707 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 18:02:06 +0100 Subject: [PATCH 218/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 56bfa469aa..19963abbad 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3615 \ No newline at end of file +3616 \ No newline at end of file From 0e42681763d49d60f94fd33085f3d55cff4e3a80 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 18:03:40 +0100 Subject: [PATCH 219/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 19963abbad..1931f90311 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3616 \ No newline at end of file +3617 \ No newline at end of file From 196888a2ad9758656700a462c16db4efd432d6f3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 18:10:32 +0100 Subject: [PATCH 220/984] added func memo for `unless?` --- src/vm/lib.nim | 1 + src/vm/values/value.nim | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index 5a78704912..40ac669051 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -125,6 +125,7 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: elif n=="if" : IfF = b elif n=="if?" : IfEF = b elif n=="unless" : UnlessF = b + elif n=="unless?" : UnlessEF = b elif n=="else" : ElseF = b elif n=="switch" : SwitchF = b elif n=="while" : WhileF = b diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index 1d55512e51..5d42ed8084 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -120,7 +120,8 @@ var NegF*, BNotF*, BAndF*, BOrF*, ShlF*, ShrF* : Value NotF*, AndF*, OrF* : Value EqF*, NeF*, GtF*, GeF*, LtF*, LeF* : Value - IfF*, IfEF*, UnlessF*, ElseF*, SwitchF*, WhileF*, ReturnF* : Value + IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF* : Value + WhileF*, ReturnF* : Value ToF*, PrintF* : Value GetF*, SetF* : Value ArrayF*, DictF*, FuncF* : Value From 336935fe1f12b8d24306da5def692a924bfabf36 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 18:10:51 +0100 Subject: [PATCH 221/984] VM/ast: added optimization for `unless`/`unless?` calls --- src/vm/ast.nim | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 30ddace341..c7c0a9a8a0 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -70,6 +70,7 @@ type IfCall IfECall UnlessCall + UnlessECall ElseCall SwitchCall WhileCall @@ -276,6 +277,35 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if left.kind == ConstantValue and right.kind == ConstantValue: target.replace(newTerminalNode(ConstantValue, op(left.value,right.value))) + proc optimizeUnless(target: var Node) {.enforceNoRaises.} = + target.kind = + if target.kind == UnlessCall: + IfCall + else: + IfECall + + var left = target.children[0] + + case left.kind: + of EqCall : left.kind = NeCall + of NeCall : left.kind = EqCall + of LtCall : left.kind = GeCall + of LeCall : left.kind = GtCall + of GtCall : left.kind = LeCall + of GeCall : left.kind = LtCall + of NotCall : + let newNode = left.children[0] + newNode.parent = target + target.children[0] = newNode + else: + let newNode = newCallNode(NotCall, 1, nil) + newNode.children = @[left] + target.children[0] = newNode + for child in newNode.children: + child.parent = newNode + + newNode.parent = target + #------------------------ # Helper Functions #------------------------ @@ -284,13 +314,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b while target.kind in CallNode and target.children.len == target.arity: when optimize: case target.kind: - of AddCall : target.optimizeAdd() - of SubCall : target.optimizeSub() - of MulCall : target.optimizeArithmeticOp(`*`) - of DivCall : target.optimizeArithmeticOp(`/`) - of FdivCall : target.optimizeArithmeticOp(`//`) - of ModCall : target.optimizeArithmeticOp(`%`) - of PowCall : target.optimizeArithmeticOp(`^`) + of AddCall : target.optimizeAdd() + of SubCall : target.optimizeSub() + of MulCall : target.optimizeArithmeticOp(`*`) + of DivCall : target.optimizeArithmeticOp(`/`) + of FdivCall : target.optimizeArithmeticOp(`//`) + of ModCall : target.optimizeArithmeticOp(`%`) + of PowCall : target.optimizeArithmeticOp(`^`) + of UnlessCall, + UnlessECall : target.optimizeUnless() + else: discard @@ -343,6 +376,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b elif fn == IfF : callType = IfCall elif fn == IfEF : callType = IfECall elif fn == UnlessF : callType = UnlessCall + elif fn == UnlessEF : callType = UnlessECall elif fn == ElseF : callType = ElseCall elif fn == SwitchF : callType = SwitchCall elif fn == WhileF : callType = WhileCall From e1b008f9060ff7b6416f7f441bed5d6bdc30e36b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 18:10:56 +0100 Subject: [PATCH 222/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1931f90311..522f7fa978 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3617 \ No newline at end of file +3618 \ No newline at end of file From 44baa4cea416089cb50257c70d2dc38badb6fe0c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 18:21:18 +0100 Subject: [PATCH 223/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 522f7fa978..2fa705ff06 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3618 \ No newline at end of file +3619 \ No newline at end of file From 8ffece1b045f76fe5ba3aa10fcce932e09471f3a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 16 Jan 2023 18:26:33 +0100 Subject: [PATCH 224/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2fa705ff06..e12a1ca341 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3619 \ No newline at end of file +3620 \ No newline at end of file From 0727af3d130b75c9ba44a4c2a266b1285069b366 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:21:42 +0100 Subject: [PATCH 225/984] cleaner AST tree manipulation primitives + cleanup (still not working 100%) --- src/vm/ast.nim | 53 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index c7c0a9a8a0..4e04e6d039 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -96,8 +96,6 @@ type NodeArray* = seq[Node] Node* = ref object - idx: int - case kind*: NodeKind: of RootNode, ConstantValue, VariableLoad: discard @@ -143,25 +141,36 @@ proc dumpNode*(node: Node, level = 0): string # Helpers #======================================= -func addChild*(node: Node, child: Node) = - node.children.add(child) - child.idx = node.children.len - 1 - child.parent = node +#------------------------ +# Tree manipulation +#------------------------ -func setOnlyChild*(node: Node, child: Node) = +func setOnlyChild(node: Node, child: Node) {.enforceNoRaises.} = + child.parent = node node.children.setLen(1) - node.addChild(child) + node.children[0] = child -func replace*(node: var Node, newNode: Node) = - newNode.parent = node.parent - newNode.idx = node.idx - node = newNode - node.parent.children[node.idx] = newNode +func addChild*(node: Node, child: Node) {.enforceNoRaises.} = + child.parent = node + node.children.add(child) -template addChildren*(node: Node, children: NodeArray) = +func addChildren*(node: Node, children: NodeArray) {.enforceNoRaises.} = for child in children: node.addChild(child) +func deleteNode(node: Node) = + if not node.parent.isNil: + node.parent.children.delete(node.parent.children.find(node)) + node.parent = nil + +proc replaceNode(node: Node, newNode: Node) = + newNode.parent = node.parent + node.parent.children[node.parent.children.find(node)] = newNode + +#------------------------ +# Misc +#------------------------ + template isSymbol(val: Value, sym: VSymbol): bool = val.kind == Symbol and val.m == sym @@ -208,7 +217,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if left.kind == ConstantValue and left.value.kind in {Integer, Floating}: # Constant folding if right.kind == ConstantValue and right.value.kind in {Integer, Floating}: - target.replace(newTerminalNode(ConstantValue, left.value + right.value)) + target.replaceNode(newTerminalNode(ConstantValue, left.value + right.value)) # Convert 1 + X -> inc X elif left.value == I1: target.kind = IncCall @@ -227,14 +236,14 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if right.children[0].kind == VariableLoad and right.children[0].value == left.value: target.kind = MulCall if right.children[1].kind == ConstantValue and right.children[1].value.kind in {Integer, Floating}: - right.replace(newTerminalNode(ConstantValue, right.children[1].value + I1)) + right.replaceNode(newTerminalNode(ConstantValue, right.children[1].value + I1)) else: right.kind = AddCall right.children[0].value = newInteger(1) elif right.children[1].kind == VariableLoad and right.children[1].value == left.value: target.kind = MulCall if right.children[0].kind == ConstantValue and right.children[0].value.kind in {Integer, Floating}: - right.replace(newTerminalNode(ConstantValue, right.children[0].value + I1)) + right.replaceNode(newTerminalNode(ConstantValue, right.children[0].value + I1)) else: right.kind = AddCall right.children[1].value = newInteger(1) @@ -245,14 +254,14 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if left.children[0].kind == VariableLoad and left.children[0].value == right.value: target.kind = MulCall if left.children[1].kind == ConstantValue and left.children[1].value.kind in {Integer, Floating}: - left.replace(newTerminalNode(ConstantValue, left.children[1].value + I1)) + left.replaceNode(newTerminalNode(ConstantValue, left.children[1].value + I1)) else: left.kind = AddCall left.children[0].value = newInteger(1) elif left.children[1].kind == VariableLoad and left.children[1].value == right.value: target.kind = MulCall if left.children[0].kind == ConstantValue and left.children[0].value.kind in {Integer, Floating}: - left.replace(newTerminalNode(ConstantValue, left.children[0].value + I1)) + left.replaceNode(newTerminalNode(ConstantValue, left.children[0].value + I1)) else: left.kind = AddCall left.children[1].value = newInteger(1) @@ -263,7 +272,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if left.kind == ConstantValue and right.kind == ConstantValue: # Constant folding - target.replace(newTerminalNode(ConstantValue, left.value - right.value)) + target.replaceNode(newTerminalNode(ConstantValue, left.value - right.value)) elif right.kind == ConstantValue and right.value == I1: # Convert X - 1 -> dec X target.kind = DecCall @@ -275,7 +284,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var right = target.children[1] if left.kind == ConstantValue and right.kind == ConstantValue: - target.replace(newTerminalNode(ConstantValue, op(left.value,right.value))) + target.replaceNode(newTerminalNode(ConstantValue, op(left.value,right.value))) proc optimizeUnless(target: var Node) {.enforceNoRaises.} = target.kind = @@ -336,6 +345,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = var callType: ArrayCall..OtherCall = OtherCall + echo "adding call: " & name & " with arity: " & $(arity) + var fn {.cursor.}: Value = if fun.isNil: GetSym(name) From 8dfafb9efcc6aaee25f7fb3727c1ebd0c15d1e49 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:21:52 +0100 Subject: [PATCH 226/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e12a1ca341..68544803bf 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3620 \ No newline at end of file +3621 \ No newline at end of file From 384b6a21e0c1f5a137671fad07ec71a10021d2d1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:39:00 +0100 Subject: [PATCH 227/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 68544803bf..3fdfdc78f3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3621 \ No newline at end of file +3622 \ No newline at end of file From 6161e594fac95e8236f995f41e03b7666abd127b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:40:22 +0100 Subject: [PATCH 228/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3fdfdc78f3..162f8feedd 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3622 \ No newline at end of file +3623 \ No newline at end of file From 8c9ea6867bc2a3e10cd3dd248cac3b93dc0122ae Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:41:50 +0100 Subject: [PATCH 229/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 162f8feedd..f2c8d75cc1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3623 \ No newline at end of file +3624 \ No newline at end of file From a720ba17d8575addff017b8556f507acfb1b22cc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:42:14 +0100 Subject: [PATCH 230/984] debugging --- src/vm/ast.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 4e04e6d039..8327e9136f 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -345,8 +345,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = var callType: ArrayCall..OtherCall = OtherCall - echo "adding call: " & name & " with arity: " & $(arity) - var fn {.cursor.}: Value = if fun.isNil: GetSym(name) @@ -576,7 +574,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b current.addTerminal(newBlock(subblock)) of arrowright : + echo "found arrow right" current.addArrowBlock(blok) + echo "after" of thickarrowright : current.addThickArrowBlocks() From 57f93b03af937c7f65e29aa0fd5c85a619c08615 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:42:50 +0100 Subject: [PATCH 231/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f2c8d75cc1..2fdabbc0f8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3624 \ No newline at end of file +3625 \ No newline at end of file From 315ab348f7045b94416788cf8400369d98955a44 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:44:26 +0100 Subject: [PATCH 232/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2fdabbc0f8..2b60e0da79 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3625 \ No newline at end of file +3626 \ No newline at end of file From 751f8399e583d2e3db29efd3386fc35018f350d3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:46:15 +0100 Subject: [PATCH 233/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2b60e0da79..79f41c3cc2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3626 \ No newline at end of file +3627 \ No newline at end of file From 389a31f467c68a18221a0da094aed57a3d03a6d6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:48:06 +0100 Subject: [PATCH 234/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 79f41c3cc2..97645056f9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3627 \ No newline at end of file +3628 \ No newline at end of file From bc26149f4c6bbd44d5342f85284579133c743f57 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:49:29 +0100 Subject: [PATCH 235/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 97645056f9..16abdc91e0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3628 \ No newline at end of file +3629 \ No newline at end of file From 9e1c89ef45fc04d70d9ea4455a9d3bc62c830809 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 12:50:47 +0100 Subject: [PATCH 236/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 16abdc91e0..7cc7507286 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3629 \ No newline at end of file +3630 \ No newline at end of file From aaa152eb8b479412a0986981d6083edaf247342c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:22:48 +0100 Subject: [PATCH 237/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7cc7507286..884d88649c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3630 \ No newline at end of file +3631 \ No newline at end of file From b3775a308b2547dcff622def804e468218384860 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:23:56 +0100 Subject: [PATCH 238/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 884d88649c..e3b74b7cd8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3631 \ No newline at end of file +3632 \ No newline at end of file From 466fabfac34632fe22e38ffd3c85489988fceb75 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:24:45 +0100 Subject: [PATCH 239/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e3b74b7cd8..69a28c57bc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3632 \ No newline at end of file +3633 \ No newline at end of file From 8290fcae47a88edf91910bc74d1dacbaa12f5978 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:44:07 +0100 Subject: [PATCH 240/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 69a28c57bc..f134bb5af1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3633 \ No newline at end of file +3634 \ No newline at end of file From 8c0a97e5d1c49f1321c8ce69c6a3efefa747bd0f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:48:07 +0100 Subject: [PATCH 241/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f134bb5af1..a6fbbceaf2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3634 \ No newline at end of file +3635 \ No newline at end of file From 678bf550969c084f960c19559a90e1641ec9ee7b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:53:33 +0100 Subject: [PATCH 242/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a6fbbceaf2..1bd6151c5d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3635 \ No newline at end of file +3636 \ No newline at end of file From d6ca10b0a7a752d1b7a85da500657e34313dd1b5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:56:28 +0100 Subject: [PATCH 243/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1bd6151c5d..fc0b21ac52 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3636 \ No newline at end of file +3637 \ No newline at end of file From 2a166bb4bbc4a4f62f0e100b745cde6b64eb7b38 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:57:21 +0100 Subject: [PATCH 244/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index fc0b21ac52..f5a094f2e3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3637 \ No newline at end of file +3638 \ No newline at end of file From cc134c6bca81bd3f278f0a299a84837ca1f95085 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 13:59:19 +0100 Subject: [PATCH 245/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f5a094f2e3..2932e732d5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3638 \ No newline at end of file +3639 \ No newline at end of file From cd9d6ad7ff949107d3aa4e32f3af881d76572982 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 14:00:12 +0100 Subject: [PATCH 246/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2932e732d5..523c8e2855 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3639 \ No newline at end of file +3640 \ No newline at end of file From 42a42871b010b13d0292769f6e3469b9c52dedf3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 14:02:52 +0100 Subject: [PATCH 247/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 523c8e2855..c8c1b765e3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3640 \ No newline at end of file +3641 \ No newline at end of file From ae5c8d30fcd9880409a28f9131b6ac9bcd7cd3c6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 14:53:20 +0100 Subject: [PATCH 248/984] cleanup + misc fixes --- src/vm/ast.nim | 62 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 8327e9136f..4ba97d26c6 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -135,7 +135,7 @@ const # Forward declarations #======================================= -proc dumpNode*(node: Node, level = 0): string +proc dumpNode*(node: Node, level = 0, single: static bool=false): string #======================================= # Helpers @@ -424,8 +424,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b template addPotentialInfixCall(target: var Node): untyped = if i < nLen - 1: let nextNode {.cursor.} = blok.a[i+1] - if nextNode.kind == Symbol: - + if nextNode.kind == Symbol and nextNode.m notin {arrowright, thickarrowright, pipe}: if (let aliased = Aliases.getOrDefault(nextNode.m, NoAliasBinding); aliased != NoAliasBinding): var symfunc {.cursor.} = GetSym(aliased.name.s) @@ -574,9 +573,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b current.addTerminal(newBlock(subblock)) of arrowright : - echo "found arrow right" current.addArrowBlock(blok) - echo "after" of thickarrowright : current.addThickArrowBlocks() @@ -613,11 +610,49 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b return i-1 +iterator traverse*(node: Node): Node = + var preStack = @[node] + var postStack: seq[Node] + while preStack.len > 0: + var subnode = preStack.pop() + postStack.add(subnode) + preStack.add(subnode.children) + while postStack.len > 0: + var subnode = postStack.pop() + yield subnode + +iterator traverseTree*(node: Node): Node = + for child in node.children: + for subchild in traverse(child): + yield subchild + +# iterator traverse*(node: Node): Node = +# var preStack = @[node] +# var postStack: seq[Node] +# while preStack.len > 0: +# var subnode = preStack.pop() +# postStack.add(subnode) +# var i = subnode.children.len-1 +# while i >= 0: +# preStack.add(subnode.children[i]) +# dec(i) +# #preStack.add(subnode.children.reversed) +# while postStack.len > 0: +# var subnode = postStack.pop() +# yield subnode + +# iterator traverseTree*(node: Node): Node = +# for child in node.children: +# if child.kind in CallNode: +# for subchild in traverse(child): +# yield subchild +# #yield child + #======================================= # Output #======================================= -proc dumpNode*(node: Node, level = 0): string = +proc dumpNode*(node: Node, level = 0, single: static bool = false): string = template indentNode(): untyped = result &= " ".repeat(level) @@ -641,8 +676,10 @@ proc dumpNode*(node: Node, level = 0): string = result &= ($node.kind).replace("Call","").toLowerAscii() & " <" & $node.arity & ">\n" else: result &= node.value.s & " <" & $node.arity & ">\n" - for child in node.children: - result &= dumpNode(child, level+1) + + when not single: + for child in node.children: + result &= dumpNode(child, level+1) result &= "\n" @@ -660,4 +697,11 @@ proc generateAst*(parsed: Value): Node = discard result.processBlock(parsed) - echo dumpNode(result) \ No newline at end of file + echo dumpNode(result) + + # echo "TRAVERSING" + + # for node in traverseTree(result): + # echo dumpNode(node, single=true) + + # echo "FINISHED" \ No newline at end of file From 98577ec95be9a95446177e10aafc5e5b51a8d307 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 14:53:38 +0100 Subject: [PATCH 249/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c8c1b765e3..d3d17107b1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3641 \ No newline at end of file +3642 \ No newline at end of file From 01b1a8bc54725f6c565d8ea721fc68e3217329b4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:01:48 +0100 Subject: [PATCH 250/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d3d17107b1..544e3a95b9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3642 \ No newline at end of file +3643 \ No newline at end of file From e99bac8bbca5e422bddff5a20c4fc4839e03db31 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:02:30 +0100 Subject: [PATCH 251/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 544e3a95b9..e4210f6e13 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3643 \ No newline at end of file +3644 \ No newline at end of file From 8cc43e5d06339f81d5b2df4e397533a8245e2016 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:05:08 +0100 Subject: [PATCH 252/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e4210f6e13..81ef32fdca 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3644 \ No newline at end of file +3645 \ No newline at end of file From 4b4751b729581700459468bca96783504b3a7230 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:06:48 +0100 Subject: [PATCH 253/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 81ef32fdca..534f1039dc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3645 \ No newline at end of file +3646 \ No newline at end of file From a2e722d1145027b5c860c851a77039fa6ef3fe53 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:11:05 +0100 Subject: [PATCH 254/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 534f1039dc..1b0747ad2f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3646 \ No newline at end of file +3647 \ No newline at end of file From f5b4c6c072df8d90841ac910542a9864e4d26766 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:13:02 +0100 Subject: [PATCH 255/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1b0747ad2f..4e705e6efa 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3647 \ No newline at end of file +3648 \ No newline at end of file From b8e0eaf9f2c6e5ffdd58de92a5d83361bbef12e0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:17:02 +0100 Subject: [PATCH 256/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4e705e6efa..b378190d06 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3648 \ No newline at end of file +3649 \ No newline at end of file From 5508503e9f202804301c6c1a6dcd652e3a35fc55 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:19:31 +0100 Subject: [PATCH 257/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b378190d06..491d1082e7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3649 \ No newline at end of file +3650 \ No newline at end of file From db04924bb914d79db34b701b1eb8c03d9f727a37 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:20:37 +0100 Subject: [PATCH 258/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 491d1082e7..f75417b9b8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3650 \ No newline at end of file +3651 \ No newline at end of file From 9b94e9cca2af56a7c133df305689bba6aca74982 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:23:05 +0100 Subject: [PATCH 259/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f75417b9b8..ed53c76dfe 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3651 \ No newline at end of file +3652 \ No newline at end of file From 35afbbec41fa7880f8109d4e0b8df2be777539a6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:24:01 +0100 Subject: [PATCH 260/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ed53c76dfe..2875c101ab 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3652 \ No newline at end of file +3653 \ No newline at end of file From bf38b4a0d68b73337bbac975077c3b30d80fbd4a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:27:26 +0100 Subject: [PATCH 261/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2875c101ab..6f7dd66c60 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3653 \ No newline at end of file +3654 \ No newline at end of file From c29d2e1db67b8c69d271b5a6dc7edcee235820e6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:28:31 +0100 Subject: [PATCH 262/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6f7dd66c60..869a11d535 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3654 \ No newline at end of file +3655 \ No newline at end of file From 619fef79c6be34092a0222899e608a78504c1152 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:31:29 +0100 Subject: [PATCH 263/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 869a11d535..9b4e1cc4d0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3655 \ No newline at end of file +3656 \ No newline at end of file From 76035fb91b605436199724f20a3e07ef1ed0f91b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:34:05 +0100 Subject: [PATCH 264/984] minor fix --- src/vm/eval.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 7dbc3a4450..87675f4357 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -601,7 +601,7 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = result = -1 if i >= nLen - 1: return let nextNode {.cursor.} = n.a[i+1] - if nextNode.kind == Symbol: + if nextNode.kind == Symbol and nextNode.m notin {pipe, arrowright, thickarrowright}: if (let aliased = Aliases.getOrDefault(nextNode.m, NoAliasBinding); aliased != NoAliasBinding): var symfunc {.cursor.} = GetSym(aliased.name.s) @@ -1016,6 +1016,7 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = var ret: ValueArray let subblock = processArrowRight() + addTerminalValue(inBlock=false): addConst(newBlock(subblock), opPush) @@ -1097,7 +1098,6 @@ proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Translation {.inline.} = ## Take a parsed Block of values and return its Translation - ## that is: the constants found + the list of bytecode instructions - discard generateAst(root) var vhash {.used.}: Hash = -1 From 1aab8f3bb8da94b44ae0810c1cf7691d13486c32 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:34:45 +0100 Subject: [PATCH 265/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9b4e1cc4d0..3ee548b114 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3656 \ No newline at end of file +3657 \ No newline at end of file From afa7f7e685a4934c94b5bcfebd3c9aee8ffb0e0a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:51:22 +0100 Subject: [PATCH 266/984] move whole VM/eval to `oldeval` and start from scratch --- src/vm/eval.nim | 1133 -------------------------------------------- src/vm/oldeval.nim | 1133 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1133 insertions(+), 1133 deletions(-) create mode 100644 src/vm/oldeval.nim diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 87675f4357..e69de29bb2 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -1,1133 +0,0 @@ -#======================================================= -# Arturo -# Programming Language + Bytecode VM compiler -# (c) 2019-2023 Yanis ZafirΓ³pulos -# -# @file: vm/eval.nim -#======================================================= - -## This module contains the evaluator for the VM. -## -## The evaluator: -## - takes a Block of values coming from the parser -## - interpretes it and returns a Translation object -## -## The main entry point is ``doEval``. - -#======================================= -# Libraries -#======================================= - -import algorithm, hashes, sequtils -import sugar, tables, unicode - -import vm/[bytecode, globals, values/value] - -import vm/profiler - -import vm/values/custom/[vbinary, vsymbol] - -import vm/ast - -#======================================= -# Variables -#======================================= - -var - StoredEval : Table[Hash, Translation] - TmpArities : Table[string,int8] - -#======================================= -# Helpers -#======================================= - -func indexOfValue(a: ValueArray, item: Value): int {.inline,enforceNoRaises.}= - result = 0 - for i in items(a): - if consideredEqual(item, i): return - inc(result) - result = -1 - -#======================================= -# Methods -#======================================= - -when not defined(NOERRORLINES): - template addEol(it: var VBinary, line: untyped):untyped = - if line > 255: - it.add([ - byte(opEolX), - byte(line shr 8), - byte(line) - ]) - else: - it.add([ - byte(opEol), - byte(line) - ]) - -func hasBranching(blk: Value, continueW: string = "continue", breakW: string = "break"): bool {.enforceNoRaises.} = - for item in blk.a: - if item.kind==Word and (item.s==continueW or item.s==breakW): - return true - elif item.kind==Block: - if hasBranching(item, continueW, breakW): - return true - return false - -proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = false, isDictionary: bool = false) = - var argStack: seq[int] - var currentCommand: VBinary - - let nLen = n.a.len - - var foundIf = false - var foundIfE = false - var foundUnless = false - var foundElse = false - var foundSwitch = false - var foundWhile = false - var foundAdd = false - var foundSub = false - - #------------------------ - # Shortcuts - #------------------------ - - template addConst(v: Value, op: OpCode): untyped = - addConst(currentCommand, consts, v, op) - - template addShortConst(v: Value, op: OpCode): untyped = - addShortConst(currentCommand, consts, v, op) - - template addTrailingConst(v: Value, op: OpCode): untyped = - addTrailingConst(currentCommand, consts, v, op) - - #------------------------ - # Helper Functions - #------------------------ - - template addToCommand(b: untyped):untyped {.dirty.} = - when b is OpCode: - currentCommand.add(byte(b)) - else: - currentCommand.add(b) - - template addToCommandHead(b: untyped, at = 0):untyped {.dirty.} = - when b is OpCode: - currentCommand.insert(byte(b), at) - else: - currentCommand.insert(b, at) - - # TODO(VM/eval) remove constants that have been optimized away - # For example, if/unless/else/switch/while usually optimize away their blocks; - # so, IF they are not used by anything else in our code, we could optimize them away. - # In that case, we could obviously use a CountTable to resolve the times each constant is used. - # labels: vm, evaluator, performance, enhancement - proc addConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = - var indx = consts.indexOfValue(v) - if indx == -1: - let newv = v - newv.readonly = true - consts.add(newv) - indx = consts.len-1 - - if indx <= 13: - addToCommand((byte(op)-0x0E) + byte(indx)) - else: - if indx>255: - addToCommand([ - byte(indx), - byte(indx shr 8), - byte(op)+1 - ]) - else: - addToCommand([ - byte(indx), - byte(op) - ]) - - proc addShortConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = - var indx = consts.indexOfValue(v) - if indx == -1: - let newv = v - newv.readonly = true - consts.add(newv) - indx = consts.len-1 - - if indx>255: - addToCommand([ - byte(indx), - byte(indx shr 8), - byte(op)+1 - ]) - else: - addToCommand([ - byte(indx), - byte(op) - ]) - - proc addTrailingConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = - var atPos = 0 - if currentCommand[0] in opStore0.byte..opStoreX.byte: - atPos = 1 - - var indx = consts.indexOfValue(v) - if indx == -1: - let newv = v - newv.readonly = true - consts.add(newv) - indx = consts.len-1 - - if indx <= 13: - addToCommandHead((byte(op)-0x0E) + byte(indx), atPos) - else: - if indx>255: - addToCommandHead([ - byte(op)+1, - byte(indx shr 8), - byte(indx) - ], atPos) - else: - addToCommandHead([ - byte(op), - byte(indx) - ], atPos) - - proc evalFunctionCall(currentCommand: var VBinary, fun: var Value, toHead: bool, checkAhead: bool, i: var int, funcArity: var int8): bool {.enforceNoRaises.} = - # TODO(VM/eval) `do` should also correspond to a distinct opCode - # labels: vm, bytecode, evaluator, enhancement, performance - var bt: OpCode = opNop - var doElse = true - - let fn {.cursor.} = fun - - if fn == ArrayF: bt = opArray - elif fn == DictF: bt = opDict - elif fn == FuncF: bt = opFunc - elif fn == AddF: - bt = opAdd - foundAdd = true - elif fn == SubF: - bt = opSub - foundSub = true - elif fn == MulF: bt = opMul - elif fn == DivF: bt = opDiv - elif fn == FdivF: bt = opFdiv - elif fn == ModF: bt = opMod - elif fn == PowF: bt = opPow - elif fn == NegF: bt = opNeg - elif fn == BNotF: bt = opBNot - elif fn == BAndF: bt = opBAnd - elif fn == BOrF: bt = opBOr - elif fn == ShlF: bt = opShl - elif fn == ShrF: bt = opShr - elif fn == NotF: bt = opNot - elif fn == AndF: bt = opAnd - elif fn == OrF: bt = opOr - elif fn == EqF: bt = opEq - elif fn == NeF: bt = opNe - elif fn == GtF: bt = opGt - elif fn == GeF: bt = opGe - elif fn == LtF: bt = opLt - elif fn == LeF: bt = opLe - elif fn == IfF: - foundIf = true - bt = opIf - elif fn == IfEF: - foundIfE = true - bt = opIfE - elif fn == UnlessF: - foundUnless = true - bt = opUnless - elif fn == ElseF: - foundElse = true - bt = opElse - elif fn == SwitchF: - foundSwitch = true - bt = opSwitch - elif fn == WhileF: - foundWhile = true - bt = opWhile - elif fn == ReturnF: bt = opReturn - elif fn == ToF: - bt = opTo - if checkAhead: - let nextNode {.cursor.} = n.a[i+1] - if nextNode.kind==Type: - if nextNode.t==String: - addToCommand(opToS) - bt = opNop - doElse = false - funcArity -= 1 - i += 1 - elif nextNode.t==Integer: - addToCommand(opToI) - bt = opNop - doElse = false - funcArity -= 1 - i += 1 - elif fn == PrintF: bt = opPrint - elif fn == GetF: bt = opGet - elif fn == SetF: bt = opSet - elif fn == RangeF: bt = opRange - elif fn == LoopF: bt = opLoop - elif fn == MapF: bt = opMap - elif fn == SelectF: bt = opSelect - elif fn == SizeF: bt = opSize - elif fn == ReplaceF: bt = opReplace - elif fn == SplitF: bt = opSplit - elif fn == JoinF: bt = opJoin - elif fn == ReverseF: bt = opReverse - elif fn == IncF: bt = opInc - elif fn == DecF: bt = opDec - - if bt != opNop: - if toHead: - addToCommandHead(bt) - else: - addToCommand(bt) - - return true - else: - return not doElse - - proc getConstIdWithShift(currentCommand: var VBinary, pos: int): (int,int) {.inline,enforceNoRaises.} = - let currentCommandLast = currentCommand[pos] - if OpCode(currentCommandLast) in {opPush0..opPush13}: - return (int(currentCommandLast) - int(opPush0), 0) - elif OpCode(currentCommandLast) == opPush: - return (int(currentCommand[pos+1]), 1) - elif OpCode(currentCommandLast) == opPushX: - return ((int(currentCommand[pos+1]) shl 8) + int(currentCommand[pos+2]), 2) - - return (-1, -1) - - proc optimizeIf(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk = consts[cnstId] - if blk.kind == Block and OpCode(currentCommand[^1]) in {opIf,opIfE}: - currentCommand.delete(0..shift) - discard currentCommand.pop() - var injectable = opJmpIfNot - case OpCode(currentCommand[^1]): - of opNot: - discard currentCommand.pop() - injectable = opJmpIf - of opEq: - discard currentCommand.pop() - injectable = opJmpIfNe - of opNe: - discard currentCommand.pop() - injectable = opJmpIfEq - of opGt: - discard currentCommand.pop() - injectable = opJmpIfLe - of opGe: - discard currentCommand.pop() - injectable = opJmpIfLt - of opLt: - discard currentCommand.pop() - injectable = opJmpIfGe - of opLe: - discard currentCommand.pop() - injectable = opJmpIfGt - else: - discard - currentCommand.add([byte(injectable), byte(0), byte(0)]) - let injPos = currentCommand.len - 2 - evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - if foundIfE: - currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) - let finPos = currentCommand.len - injPos - 2 - currentCommand[injPos] = byte(finPos shr 8) - currentCommand[injPos+1] = byte(finPos) - - foundIf = false - foundIfE = false - - proc optimizeUnless(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk = consts[cnstId] - if blk.kind == Block and OpCode(currentCommand[^1]) == opUnless: - currentCommand.delete(0..shift) - discard currentCommand.pop() - var injectable = opJmpIf - case OpCode(currentCommand[^1]): - of opNot: - discard currentCommand.pop() - injectable = opJmpIfNot - of opEq: - discard currentCommand.pop() - injectable = opJmpIfEq - of opNe: - discard currentCommand.pop() - injectable = opJmpIfNe - of opGt: - discard currentCommand.pop() - injectable = opJmpIfGt - of opGe: - discard currentCommand.pop() - injectable = opJmpIfGe - of opLt: - discard currentCommand.pop() - injectable = opJmpIfLt - of opLe: - discard currentCommand.pop() - injectable = opJmpIfLe - else: - discard - currentCommand.add([byte(injectable), byte(0), byte(0)]) - let injPos = currentCommand.len - 2 - evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - if foundIfE: - currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) - let finPos = currentCommand.len - injPos - 2 - currentCommand[injPos] = byte(finPos shr 8) - currentCommand[injPos+1] = byte(finPos) - - foundUnless = false - - proc optimizeElse(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk = consts[cnstId] - if blk.kind == Block: - currentCommand.delete(0..shift) - discard currentCommand.pop() - - evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - let currentPos = currentCommand.len - it[^3] = byte(opGoto) - it[^2] = byte(currentPos shr 8) - it[^1] = byte(currentPos) - - foundElse = false - - proc optimizeSwitch(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - # TODO(eval/optimizeSwitch) `switch` not always processed correctly - # see: https://rosettacode.org/wiki/Perlin_noise#Arturo - # labels: bug, vm, evaluator, critical - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk = consts[cnstId] - if blk.kind == Block: - let (cnstId2, shift2) = getConstIdWithShift(currentCommand, 1+shift) - - if cnstId2 != -1: - let blk2 = consts[cnstId2] - if blk2.kind == Block: - # for b in currentCommand: - # echo stringify(OpCode(b)) - currentCommand.delete(0..shift+shift2+1) - var toPushBack: VBinary - var jpb = currentCommand.len - 1 - while OpCode(currentCommand[jpb]) != opSwitch: - toPushBack.add(currentCommand.pop()) - jpb -= 1 - reverse(toPushBack) - discard currentCommand.pop() - var injectable = opJmpIfNot - case OpCode(currentCommand[^1]): - of opNot: - discard currentCommand.pop() - injectable = opJmpIf - of opEq: - discard currentCommand.pop() - injectable = opJmpIfNe - of opNe: - discard currentCommand.pop() - injectable = opJmpIfEq - of opGt: - discard currentCommand.pop() - injectable = opJmpIfLe - of opGe: - discard currentCommand.pop() - injectable = opJmpIfLt - of opLt: - discard currentCommand.pop() - injectable = opJmpIfGe - of opLe: - discard currentCommand.pop() - injectable = opJmpIfGt - else: - discard - currentCommand.add([byte(injectable), byte(0), byte(0)]) - let injPos = currentCommand.len - 2 - evalOne(blk2, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - let preInjection = currentCommand.len - currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) - let finPos = currentCommand.len - injPos - 2 - currentCommand[injPos] = byte(finPos shr 8) - currentCommand[injPos+1] = byte(finPos) - let lastLen = currentCommand.len - evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - let currentPos = currentCommand.len - lastLen - currentCommand[preInjection] = byte(opGoto) - currentCommand[preInjection+1] = byte(currentPos shr 8) - currentCommand[preInjection+2] = byte(currentPos) - if toPushBack.len > 0: - currentCommand.add(toPushBack) - - foundSwitch = false - - proc optimizeWhile(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - # TODO(VM/eval) `optimizeWhile` does not correctly process `null` condition - # in a few words: when it's an infinite while loop - # labels: vm, evaluator, enhancement - if OpCode(currentCommand[^1]) == opWhile: - - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk1 = consts[cnstId] - if blk1.kind == Block: - let (cnstId2, shift2) = getConstIdWithShift(currentCommand, 1+shift) - - if cnstId2 != -1: - let blk2 = consts[cnstId2] - if blk2.kind == Block: - if not hasBranching(blk1): - currentCommand.delete(0..shift+shift2+1) - discard currentCommand.pop() - let initialLen = currentCommand.len - evalOne(blk2, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - var injectable = opJmpIfNot - case OpCode(currentCommand[^1]): - of opNot: - discard currentCommand.pop() - injectable = opJmpIf - of opEq: - discard currentCommand.pop() - injectable = opJmpIfNe - of opNe: - discard currentCommand.pop() - injectable = opJmpIfEq - of opGt: - discard currentCommand.pop() - injectable = opJmpIfLe - of opGe: - discard currentCommand.pop() - injectable = opJmpIfLt - of opLt: - discard currentCommand.pop() - injectable = opJmpIfGe - of opLe: - discard currentCommand.pop() - injectable = opJmpIfGt - else: - discard - currentCommand.add([byte(injectable), byte(0), byte(0)]) - let injPos = currentCommand.len - 2 - evalOne(blk1, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - currentCommand.add([byte(opGoup), byte(0), byte(0)]) - let gotoPos = currentCommand.len - 2 - let finPos = currentCommand.len - injPos - 2 - currentCommand[injPos] = byte(finPos shr 8) - currentCommand[injPos+1] = byte(finPos) - let dist = currentCommand.len - initialLen - currentCommand[gotoPos] = byte(dist shr 8) - currentCommand[gotoPos+1] = byte(dist) - - foundWhile = false - - proc optimizeAdd(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - # TODO(VM/eval) `optimizeAdd` not correctly handling stores - # e.g. [a: b + 1] - # labels: vm, evaluator, enhancement, bug - if OpCode(currentCommand[^1]) == opAdd: - if currentCommand.len == 3 and OpCode(currentCommand[0])==opConstI1: - currentCommand = @[currentCommand[1], byte(opInc)] - elif OpCode(currentCommand[^2])==opConstI1: - currentCommand[^2] = byte(opInc) - discard currentCommand.pop() - elif OpCode(currentCommand[0]) == opAdd: - if currentCommand.len == 3 and OpCode(currentCommand[2])==opConstI1: - currentCommand = @[byte(opInc), currentCommand[1]] - elif OpCode(currentCommand[1])==opConstI1: - currentCommand[1] = byte(opInc) - currentCommand.delete(0) - - foundAdd = false - - proc optimizeSub(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - # TODO(VM/eval) `optimizeSub` not correctly handling stores - # e.g. [a: b - 1] - # labels: vm, evaluator, enhancement, bug - if OpCode(currentCommand[^1]) == opSub: - if currentCommand.len == 3 and OpCode(currentCommand[0])==opConstI1: - currentCommand = @[currentCommand[1], byte(opDec)] - elif OpCode(currentCommand[0])==opSub: - if currentCommand.len == 3 and OpCode(currentCommand[2])==opConstI1: - currentCommand = @[byte(opDec), currentCommand[1]] - - foundSub = false - - template addCurrentCommandToBytecode() {.dirty.} = - if not inBlock: reverse(currentCommand) - - if foundIf or (foundIfE and i+1= nLen - 1: return - let nextNode {.cursor.} = n.a[i+1] - if nextNode.kind == Symbol and nextNode.m notin {pipe, arrowright, thickarrowright}: - - if (let aliased = Aliases.getOrDefault(nextNode.m, NoAliasBinding); aliased != NoAliasBinding): - var symfunc {.cursor.} = GetSym(aliased.name.s) - - if symfunc.kind==Function and aliased.precedence==InfixPrecedence: - i += 1 - var placeholder: int8 - if (not inBlock) and (not evalFunctionCall(currentCommand, symfunc, toHead=false, checkAhead=false, i, placeholder)): - addConst(aliased.name, opCall) - result = symfunc.arity - - template resetArgStackAndCheckForTrailingPipe(currentArgStack: var seq[int], commandFinished: untyped, withTrailingPipe: untyped) = - if currentArgStack.len != 0: currentArgStack[^1] -= 1 - - while currentArgStack.len != 0 and currentArgStack[^1] == 0: - discard currentArgStack.pop() - currentArgStack[^1] -= 1 - - if not (i+11: - argStack.add(tmpFuncArity-1) - # TODO(VM/eval) to be fixed - # labels: bug, evaluator, vm - var placeholder: int8 - if not evalFunctionCall(currentCommand, nextNode, toHead=true, checkAhead=false, i, placeholder): - addTrailingConst(nextNode, opCall) - else: - addTrailingConst(nextNode, opCall) - if argStack.len==0: - addCurrentCommandToBytecode() - i += 1 - - proc postAddTerminalSubValue(consts: var ValueArray, currentCommand: var VBinary, i: var int, n: Value, subargStack: var seq[int], ret: var ValueArray, ended: var bool) = - # Check if command complete - - resetArgStackAndCheckForTrailingPipe(subargStack): - # The subcommand is finished - ended = true - do: - discard - - template addTerminalValue(inBlock: bool, code: untyped): untyped {.dirty.} = - block: - # Check for potential Infix operator ahead - if (let infixArity = getArityForInfixOperatorAhead(inBlock, consts, currentCommand, i, n); infixArity != -1): - when not inBlock: - argStack.add(infixArity) - else: - subargStack.add(infixArity) - ret.add(n.a[i]) - - # Run main code - code - - # Check if command is complete - when not inBlock: - postAddTerminalValue(consts, currentCommand, i, n, it) - else: - postAddTerminalSubValue(consts, currentCommand, i, n, subargStack, ret, ended) - - template processArrowRight(): untyped = - i += 1 - - while i < nLen and not ended: - let subnode {.cursor.} = n.a[i] - ret.add(subnode) - - case subnode.kind: - of Null, - Logical: discard - of Integer, - Floating, - Type, - Char, - String, - Literal, - Path, - Inline, - Block: - addTerminalValue(inBlock=true): - discard - of Word: - if (let funcArity = TmpArities.getOrDefault(subnode.s, -1); funcArity != -1): - if funcArity!=0: - subargStack.add(funcArity) - else: - addTerminalValue(inBlock=true): - discard - else: - addTerminalValue(inBlock=true): - discard - - of Symbol: - let symalias = subnode.m - let aliased = Aliases.getOrDefault(symalias, NoAliasBinding) - if likely(aliased != NoAliasBinding): - let symfunc {.cursor.} = GetSym(aliased.name.s) - if symfunc.kind==Function: - if aliased.precedence==PrefixPrecedence: - if symfunc.arity != 0: - subargStack.add(symfunc.arity) - else: - addTerminalValue(inBlock=true): - discard - else: - ret.add(newSymbol(ampersand)) - swap(ret[^1],ret[^2]) - subargStack.add(symfunc.arity-1) - else: - addTerminalValue(inBlock=true): - discard - else: - addTerminalValue(inBlock=true): - discard - - of AttributeLabel: - subargStack[subargStack.len-1] += 1 - - else: discard - - - i += 1 - - i -= 1 - ret - - proc processThickArrowRight(argblock: var ValueArray, subblock: var ValueArray, it: var VBinary, n: Value, i: var int, funcArity: var int8) = - while n.a[i+1].kind == Newline: - when not defined(NOERRORLINES): - addEol(it, n.a[i+1].line) - i += 1 - - # get next node - let subnode {.cursor.} = n.a[i+1] - - # we'll want to create the two blocks, - # for functions like loop, map, select, filter - # so let's get them ready - argblock.setLen(0) - subblock = @[subnode] - - # if it's a word - if subnode.kind==Word: - # check if it's a function - funcArity = TmpArities.getOrDefault(subnode.s, -1) - if funcArity != -1: - # automatically "push" all its required arguments - for i in 0..(funcArity-1): - let arg = newWord("_" & $(i)) - argblock.add(arg) - subblock.add(arg) - - elif subnode.kind==Block: - # replace ampersand symbols, - # sequentially, with arguments - var idx = 0 - var fnd: int8 = 0 - while idx funcArity-1 for ToS/ToI! - else: - addConst(node, opCall) - argStack.add(funcArity) - else: - addTerminalValue(inBlock=false): - addConst(node, opCall) - else: - addTerminalValue(inBlock=false): - if node.s == "true": - addToCommand(opConstBT) - elif node.s == "false": - addToCommand(opConstBF) - else: - addConst(node, opLoad) - - of Block: - addTerminalValue(inBlock=false): - if node.a.len==0: - addToCommand(opConstA) - else: - addConst(node, opPush) - - of Integer: - addTerminalValue(inBlock=false): - when defined(WEB) or not defined(NOGMP): - if likely(node.iKind==NormalInteger): - if node.i>=0 and node.i<=15: addToCommand(byte(opConstI0) + byte(node.i)) - else: addConst(node, opPush) - else: - addConst(node, opPush) - else: - if node.i>=0 and node.i<=15: addToCommand(byte(opConstI0) + byte(node.i)) - else: addConst(node, opPush) - - of String: - {.linearScanEnd.} - addTerminalValue(inBlock=false): - if node.s.len==0: - addToCommand(opConstS) - else: - addConst(node, opPush) - - #--------------------------- - - of Label: - - let funcIndx {.cursor.} = node.s - var hasThickArrow = false - var ab: ValueArray - var sb: ValueArray - let nextNode {.cursor.} = n.a[i+1] - if (nextNode.kind == Word and nextNode.s == "function") or - (nextNode.kind == Symbol and nextNode.m == dollar): - let afterNextNode {.cursor.} = n.a[i+2] - if afterNextNode.kind == Symbol and afterNextNode.m == thickarrowright: - i += 2 - var funcArity: int8 = 0 - processThickArrowRight(ab, sb, it, n, i, funcArity) - TmpArities[funcIndx] = funcArity - hasThickArrow = true - i += 1 - else: - TmpArities[funcIndx] = int8(afterNextNode.a.countIt(it.kind != Type)) #n.a[i+2].a.len - else: - if not isDictionary: - TmpArities.del(funcIndx) - - if unlikely(isDictionary): - addShortConst(node, opDStore) - else: - addConst(node, opStore) - - argStack.add(1) - - if hasThickArrow: - addConst(newWord("function"), opCall) - argStack.add(2) - - # add the blocks - addTerminalValue(inBlock=false): - addConst(newBlock(ab), opPush) - addTerminalValue(inBlock=false): - addConst(newBlock(sb), opPush) - - of Range: - addTerminalValue(inBlock=false): - addConst(node, opPush) - - of Null: addToCommand(opConstN) - of Logical: - if isTrue(node): addToCommand(opConstBT) - elif isFalse(node): addToCommand(opConstBF) - else: addToCommand(opConstBM) - - of Floating: - addTerminalValue(inBlock=false): - if node.f==0.0: addToCommand(opConstF0) - elif node.f==1.0: addToCommand(opConstF1) - elif node.f==2.0: addToCommand(opConstF2) - else: addConst(node, opPush) - - of Attribute: - addConst(node, opAttr) - addToCommand(opConstBT) - - of AttributeLabel: - addConst(node, opAttr) - argStack[argStack.len-1] += 1 - - of Path: - var pathCallV: Value = nil - - if (let curr = Syms.getOrDefault(node.p[0].s, nil); not curr.isNil): - let next {.cursor.} = node.p[1] - if curr.kind==Dictionary and (next.kind==Literal or next.kind==Word): - if (let item = curr.d.getOrDefault(next.s, nil); not item.isNil): - if item.kind == Function: - pathCallV = item - - if not pathCallV.isNil: - addConst(pathCallV, opCall) - argStack.add(pathCallV.arity) - else: - addTerminalValue(inBlock=false): - addToCommand(opGet) - - var i=1 - while i=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) - else: addConst(node.p[i], opPush) - else: - addConst(node.p[i], opPush) - else: - addConst(node.p[i], opPush) - i += 1 - - of PathLabel: - addToCommand(opSet) - - var i=1 - while i=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) - else: addConst(node.p[i], opPush) - else: - addConst(node.p[i], opPush) - else: - addConst(node.p[i], opPush) - i += 1 - - argStack.add(1) - - of Symbol: - case node.m: - of doublecolon : - inc(i) - var subblock: ValueArray - while i < nLen: - let subnode {.cursor.} = n.a[i] - subblock.add(subnode) - inc(i) - addTerminalValue(inBlock=false): - addConst(newBlock(subblock), opPush) - - of arrowright : - var subargStack: seq[int] - var ended = false - var ret: ValueArray - - let subblock = processArrowRight() - - addTerminalValue(inBlock=false): - addConst(newBlock(subblock), opPush) - - of thickarrowright : - # TODO(Eval\addTerminalValue) Thick arrow-right not working with pipes - # labels: vm,evaluator,enhancement,bug - var ab: ValueArray - var sb: ValueArray - var funcArity: int8 = 0 - processThickArrowRight(ab, sb, it, n, i, funcArity) - - # add the blocks - addTerminalValue(inBlock=false): - if ab.len == 1: - addConst(newLiteral(ab[0].s), opPush) - else: - addConst(newBlock(ab), opPush) - addTerminalValue(inBlock=false): - addConst(newBlock(sb), opPush) - - i += 1 - else: - let symalias = node.m - let aliased = Aliases.getOrDefault(symalias, NoAliasBinding) - if likely(aliased != NoAliasBinding): - var symfunc {.cursor.} = GetSym(aliased.name.s) - if symfunc.kind==Function: - if symfunc.fnKind == BuiltinFunction and symfunc.arity!=0: - var placeholder: int8 - if not evalFunctionCall(currentCommand, symfunc, toHead=false, checkAhead=false, i, placeholder): - addConst(aliased.name, opCall) - argStack.add(symfunc.arity) - elif symfunc.fnKind == UserFunction and symfunc.arity!=0: - addConst(aliased.name, opCall) - argStack.add(symfunc.arity) - else: - addTerminalValue(inBlock=false): - addConst(aliased.name, opCall) - else: - if aliased.name.s == "null": - addTerminalValue(inBlock=false): - addToCommand(opConstN) - else: - addTerminalValue(inBlock=false): - addConst(aliased.name, opLoad) - else: - addTerminalValue(inBlock=false): - addConst(node, opPush) - - of Dictionary: - addTerminalValue(inBlock=false): - if node.d.len==0: - addToCommand(opConstD) - else: - addConst(node, opPush) - - # TODO(VM/eval) Inline blocks not evaluated correctly - # more than one commands in the block, seem to be evaluated in a reverse order - # labels: vm,evaluator,bug,critical - of Inline: - addTerminalValue(inBlock=false): - evalOne(node, consts, currentCommand, inBlock=true, isDictionary=isDictionary) - - of Date, Binary, Database, Bytecode, - Nothing, Any: - - discard - - else: - # of Complex, Rational, Version, Type, Char, Literal, SymbolLiteral, Quantity, Regex, Color, Object, Function: - addTerminalValue(inBlock=false): - addConst(node, opPush) - - i += 1 - - if currentCommand.len > 0: - addCurrentCommandToBytecode() - -proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Translation {.inline.} = - ## Take a parsed Block of values and return its Translation - - ## that is: the constants found + the list of bytecode instructions - discard generateAst(root) - - var vhash {.used.}: Hash = -1 - - when useStored: - if not root.dynamic: - vhash = hash(root) - if (let stEv = StoredEval.getOrDefault(vhash, nil); not stEv.isNil): - return stEv - - var cnsts: ValueArray - var newit: VBinary - - TmpArities = collect: - for k,v in Syms.pairs: - if v.kind == Function: - {k: v.arity} - - evalOne(root, cnsts, newit, isDictionary=isDictionary) - newit.add(byte(opEnd)) - - # when defined(OPTIMIZED): - # newit = optimizeBytecode(newit) - - result = Translation(constants: cnsts, instructions: newit) - - when useStored: - if vhash != -1: - StoredEval[vhash] = result - -template evalOrGet*(item: Value): untyped = - if item.kind==Bytecode: item.trans - else: doEval(item) \ No newline at end of file diff --git a/src/vm/oldeval.nim b/src/vm/oldeval.nim new file mode 100644 index 0000000000..87675f4357 --- /dev/null +++ b/src/vm/oldeval.nim @@ -0,0 +1,1133 @@ +#======================================================= +# Arturo +# Programming Language + Bytecode VM compiler +# (c) 2019-2023 Yanis ZafirΓ³pulos +# +# @file: vm/eval.nim +#======================================================= + +## This module contains the evaluator for the VM. +## +## The evaluator: +## - takes a Block of values coming from the parser +## - interpretes it and returns a Translation object +## +## The main entry point is ``doEval``. + +#======================================= +# Libraries +#======================================= + +import algorithm, hashes, sequtils +import sugar, tables, unicode + +import vm/[bytecode, globals, values/value] + +import vm/profiler + +import vm/values/custom/[vbinary, vsymbol] + +import vm/ast + +#======================================= +# Variables +#======================================= + +var + StoredEval : Table[Hash, Translation] + TmpArities : Table[string,int8] + +#======================================= +# Helpers +#======================================= + +func indexOfValue(a: ValueArray, item: Value): int {.inline,enforceNoRaises.}= + result = 0 + for i in items(a): + if consideredEqual(item, i): return + inc(result) + result = -1 + +#======================================= +# Methods +#======================================= + +when not defined(NOERRORLINES): + template addEol(it: var VBinary, line: untyped):untyped = + if line > 255: + it.add([ + byte(opEolX), + byte(line shr 8), + byte(line) + ]) + else: + it.add([ + byte(opEol), + byte(line) + ]) + +func hasBranching(blk: Value, continueW: string = "continue", breakW: string = "break"): bool {.enforceNoRaises.} = + for item in blk.a: + if item.kind==Word and (item.s==continueW or item.s==breakW): + return true + elif item.kind==Block: + if hasBranching(item, continueW, breakW): + return true + return false + +proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = false, isDictionary: bool = false) = + var argStack: seq[int] + var currentCommand: VBinary + + let nLen = n.a.len + + var foundIf = false + var foundIfE = false + var foundUnless = false + var foundElse = false + var foundSwitch = false + var foundWhile = false + var foundAdd = false + var foundSub = false + + #------------------------ + # Shortcuts + #------------------------ + + template addConst(v: Value, op: OpCode): untyped = + addConst(currentCommand, consts, v, op) + + template addShortConst(v: Value, op: OpCode): untyped = + addShortConst(currentCommand, consts, v, op) + + template addTrailingConst(v: Value, op: OpCode): untyped = + addTrailingConst(currentCommand, consts, v, op) + + #------------------------ + # Helper Functions + #------------------------ + + template addToCommand(b: untyped):untyped {.dirty.} = + when b is OpCode: + currentCommand.add(byte(b)) + else: + currentCommand.add(b) + + template addToCommandHead(b: untyped, at = 0):untyped {.dirty.} = + when b is OpCode: + currentCommand.insert(byte(b), at) + else: + currentCommand.insert(b, at) + + # TODO(VM/eval) remove constants that have been optimized away + # For example, if/unless/else/switch/while usually optimize away their blocks; + # so, IF they are not used by anything else in our code, we could optimize them away. + # In that case, we could obviously use a CountTable to resolve the times each constant is used. + # labels: vm, evaluator, performance, enhancement + proc addConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = + var indx = consts.indexOfValue(v) + if indx == -1: + let newv = v + newv.readonly = true + consts.add(newv) + indx = consts.len-1 + + if indx <= 13: + addToCommand((byte(op)-0x0E) + byte(indx)) + else: + if indx>255: + addToCommand([ + byte(indx), + byte(indx shr 8), + byte(op)+1 + ]) + else: + addToCommand([ + byte(indx), + byte(op) + ]) + + proc addShortConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = + var indx = consts.indexOfValue(v) + if indx == -1: + let newv = v + newv.readonly = true + consts.add(newv) + indx = consts.len-1 + + if indx>255: + addToCommand([ + byte(indx), + byte(indx shr 8), + byte(op)+1 + ]) + else: + addToCommand([ + byte(indx), + byte(op) + ]) + + proc addTrailingConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = + var atPos = 0 + if currentCommand[0] in opStore0.byte..opStoreX.byte: + atPos = 1 + + var indx = consts.indexOfValue(v) + if indx == -1: + let newv = v + newv.readonly = true + consts.add(newv) + indx = consts.len-1 + + if indx <= 13: + addToCommandHead((byte(op)-0x0E) + byte(indx), atPos) + else: + if indx>255: + addToCommandHead([ + byte(op)+1, + byte(indx shr 8), + byte(indx) + ], atPos) + else: + addToCommandHead([ + byte(op), + byte(indx) + ], atPos) + + proc evalFunctionCall(currentCommand: var VBinary, fun: var Value, toHead: bool, checkAhead: bool, i: var int, funcArity: var int8): bool {.enforceNoRaises.} = + # TODO(VM/eval) `do` should also correspond to a distinct opCode + # labels: vm, bytecode, evaluator, enhancement, performance + var bt: OpCode = opNop + var doElse = true + + let fn {.cursor.} = fun + + if fn == ArrayF: bt = opArray + elif fn == DictF: bt = opDict + elif fn == FuncF: bt = opFunc + elif fn == AddF: + bt = opAdd + foundAdd = true + elif fn == SubF: + bt = opSub + foundSub = true + elif fn == MulF: bt = opMul + elif fn == DivF: bt = opDiv + elif fn == FdivF: bt = opFdiv + elif fn == ModF: bt = opMod + elif fn == PowF: bt = opPow + elif fn == NegF: bt = opNeg + elif fn == BNotF: bt = opBNot + elif fn == BAndF: bt = opBAnd + elif fn == BOrF: bt = opBOr + elif fn == ShlF: bt = opShl + elif fn == ShrF: bt = opShr + elif fn == NotF: bt = opNot + elif fn == AndF: bt = opAnd + elif fn == OrF: bt = opOr + elif fn == EqF: bt = opEq + elif fn == NeF: bt = opNe + elif fn == GtF: bt = opGt + elif fn == GeF: bt = opGe + elif fn == LtF: bt = opLt + elif fn == LeF: bt = opLe + elif fn == IfF: + foundIf = true + bt = opIf + elif fn == IfEF: + foundIfE = true + bt = opIfE + elif fn == UnlessF: + foundUnless = true + bt = opUnless + elif fn == ElseF: + foundElse = true + bt = opElse + elif fn == SwitchF: + foundSwitch = true + bt = opSwitch + elif fn == WhileF: + foundWhile = true + bt = opWhile + elif fn == ReturnF: bt = opReturn + elif fn == ToF: + bt = opTo + if checkAhead: + let nextNode {.cursor.} = n.a[i+1] + if nextNode.kind==Type: + if nextNode.t==String: + addToCommand(opToS) + bt = opNop + doElse = false + funcArity -= 1 + i += 1 + elif nextNode.t==Integer: + addToCommand(opToI) + bt = opNop + doElse = false + funcArity -= 1 + i += 1 + elif fn == PrintF: bt = opPrint + elif fn == GetF: bt = opGet + elif fn == SetF: bt = opSet + elif fn == RangeF: bt = opRange + elif fn == LoopF: bt = opLoop + elif fn == MapF: bt = opMap + elif fn == SelectF: bt = opSelect + elif fn == SizeF: bt = opSize + elif fn == ReplaceF: bt = opReplace + elif fn == SplitF: bt = opSplit + elif fn == JoinF: bt = opJoin + elif fn == ReverseF: bt = opReverse + elif fn == IncF: bt = opInc + elif fn == DecF: bt = opDec + + if bt != opNop: + if toHead: + addToCommandHead(bt) + else: + addToCommand(bt) + + return true + else: + return not doElse + + proc getConstIdWithShift(currentCommand: var VBinary, pos: int): (int,int) {.inline,enforceNoRaises.} = + let currentCommandLast = currentCommand[pos] + if OpCode(currentCommandLast) in {opPush0..opPush13}: + return (int(currentCommandLast) - int(opPush0), 0) + elif OpCode(currentCommandLast) == opPush: + return (int(currentCommand[pos+1]), 1) + elif OpCode(currentCommandLast) == opPushX: + return ((int(currentCommand[pos+1]) shl 8) + int(currentCommand[pos+2]), 2) + + return (-1, -1) + + proc optimizeIf(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) + + if cnstId != -1: + let blk = consts[cnstId] + if blk.kind == Block and OpCode(currentCommand[^1]) in {opIf,opIfE}: + currentCommand.delete(0..shift) + discard currentCommand.pop() + var injectable = opJmpIfNot + case OpCode(currentCommand[^1]): + of opNot: + discard currentCommand.pop() + injectable = opJmpIf + of opEq: + discard currentCommand.pop() + injectable = opJmpIfNe + of opNe: + discard currentCommand.pop() + injectable = opJmpIfEq + of opGt: + discard currentCommand.pop() + injectable = opJmpIfLe + of opGe: + discard currentCommand.pop() + injectable = opJmpIfLt + of opLt: + discard currentCommand.pop() + injectable = opJmpIfGe + of opLe: + discard currentCommand.pop() + injectable = opJmpIfGt + else: + discard + currentCommand.add([byte(injectable), byte(0), byte(0)]) + let injPos = currentCommand.len - 2 + evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) + if foundIfE: + currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) + let finPos = currentCommand.len - injPos - 2 + currentCommand[injPos] = byte(finPos shr 8) + currentCommand[injPos+1] = byte(finPos) + + foundIf = false + foundIfE = false + + proc optimizeUnless(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) + + if cnstId != -1: + let blk = consts[cnstId] + if blk.kind == Block and OpCode(currentCommand[^1]) == opUnless: + currentCommand.delete(0..shift) + discard currentCommand.pop() + var injectable = opJmpIf + case OpCode(currentCommand[^1]): + of opNot: + discard currentCommand.pop() + injectable = opJmpIfNot + of opEq: + discard currentCommand.pop() + injectable = opJmpIfEq + of opNe: + discard currentCommand.pop() + injectable = opJmpIfNe + of opGt: + discard currentCommand.pop() + injectable = opJmpIfGt + of opGe: + discard currentCommand.pop() + injectable = opJmpIfGe + of opLt: + discard currentCommand.pop() + injectable = opJmpIfLt + of opLe: + discard currentCommand.pop() + injectable = opJmpIfLe + else: + discard + currentCommand.add([byte(injectable), byte(0), byte(0)]) + let injPos = currentCommand.len - 2 + evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) + if foundIfE: + currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) + let finPos = currentCommand.len - injPos - 2 + currentCommand[injPos] = byte(finPos shr 8) + currentCommand[injPos+1] = byte(finPos) + + foundUnless = false + + proc optimizeElse(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) + + if cnstId != -1: + let blk = consts[cnstId] + if blk.kind == Block: + currentCommand.delete(0..shift) + discard currentCommand.pop() + + evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) + let currentPos = currentCommand.len + it[^3] = byte(opGoto) + it[^2] = byte(currentPos shr 8) + it[^1] = byte(currentPos) + + foundElse = false + + proc optimizeSwitch(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + # TODO(eval/optimizeSwitch) `switch` not always processed correctly + # see: https://rosettacode.org/wiki/Perlin_noise#Arturo + # labels: bug, vm, evaluator, critical + let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) + + if cnstId != -1: + let blk = consts[cnstId] + if blk.kind == Block: + let (cnstId2, shift2) = getConstIdWithShift(currentCommand, 1+shift) + + if cnstId2 != -1: + let blk2 = consts[cnstId2] + if blk2.kind == Block: + # for b in currentCommand: + # echo stringify(OpCode(b)) + currentCommand.delete(0..shift+shift2+1) + var toPushBack: VBinary + var jpb = currentCommand.len - 1 + while OpCode(currentCommand[jpb]) != opSwitch: + toPushBack.add(currentCommand.pop()) + jpb -= 1 + reverse(toPushBack) + discard currentCommand.pop() + var injectable = opJmpIfNot + case OpCode(currentCommand[^1]): + of opNot: + discard currentCommand.pop() + injectable = opJmpIf + of opEq: + discard currentCommand.pop() + injectable = opJmpIfNe + of opNe: + discard currentCommand.pop() + injectable = opJmpIfEq + of opGt: + discard currentCommand.pop() + injectable = opJmpIfLe + of opGe: + discard currentCommand.pop() + injectable = opJmpIfLt + of opLt: + discard currentCommand.pop() + injectable = opJmpIfGe + of opLe: + discard currentCommand.pop() + injectable = opJmpIfGt + else: + discard + currentCommand.add([byte(injectable), byte(0), byte(0)]) + let injPos = currentCommand.len - 2 + evalOne(blk2, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) + let preInjection = currentCommand.len + currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) + let finPos = currentCommand.len - injPos - 2 + currentCommand[injPos] = byte(finPos shr 8) + currentCommand[injPos+1] = byte(finPos) + let lastLen = currentCommand.len + evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) + let currentPos = currentCommand.len - lastLen + currentCommand[preInjection] = byte(opGoto) + currentCommand[preInjection+1] = byte(currentPos shr 8) + currentCommand[preInjection+2] = byte(currentPos) + if toPushBack.len > 0: + currentCommand.add(toPushBack) + + foundSwitch = false + + proc optimizeWhile(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + # TODO(VM/eval) `optimizeWhile` does not correctly process `null` condition + # in a few words: when it's an infinite while loop + # labels: vm, evaluator, enhancement + if OpCode(currentCommand[^1]) == opWhile: + + let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) + + if cnstId != -1: + let blk1 = consts[cnstId] + if blk1.kind == Block: + let (cnstId2, shift2) = getConstIdWithShift(currentCommand, 1+shift) + + if cnstId2 != -1: + let blk2 = consts[cnstId2] + if blk2.kind == Block: + if not hasBranching(blk1): + currentCommand.delete(0..shift+shift2+1) + discard currentCommand.pop() + let initialLen = currentCommand.len + evalOne(blk2, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) + var injectable = opJmpIfNot + case OpCode(currentCommand[^1]): + of opNot: + discard currentCommand.pop() + injectable = opJmpIf + of opEq: + discard currentCommand.pop() + injectable = opJmpIfNe + of opNe: + discard currentCommand.pop() + injectable = opJmpIfEq + of opGt: + discard currentCommand.pop() + injectable = opJmpIfLe + of opGe: + discard currentCommand.pop() + injectable = opJmpIfLt + of opLt: + discard currentCommand.pop() + injectable = opJmpIfGe + of opLe: + discard currentCommand.pop() + injectable = opJmpIfGt + else: + discard + currentCommand.add([byte(injectable), byte(0), byte(0)]) + let injPos = currentCommand.len - 2 + evalOne(blk1, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) + currentCommand.add([byte(opGoup), byte(0), byte(0)]) + let gotoPos = currentCommand.len - 2 + let finPos = currentCommand.len - injPos - 2 + currentCommand[injPos] = byte(finPos shr 8) + currentCommand[injPos+1] = byte(finPos) + let dist = currentCommand.len - initialLen + currentCommand[gotoPos] = byte(dist shr 8) + currentCommand[gotoPos+1] = byte(dist) + + foundWhile = false + + proc optimizeAdd(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + # TODO(VM/eval) `optimizeAdd` not correctly handling stores + # e.g. [a: b + 1] + # labels: vm, evaluator, enhancement, bug + if OpCode(currentCommand[^1]) == opAdd: + if currentCommand.len == 3 and OpCode(currentCommand[0])==opConstI1: + currentCommand = @[currentCommand[1], byte(opInc)] + elif OpCode(currentCommand[^2])==opConstI1: + currentCommand[^2] = byte(opInc) + discard currentCommand.pop() + elif OpCode(currentCommand[0]) == opAdd: + if currentCommand.len == 3 and OpCode(currentCommand[2])==opConstI1: + currentCommand = @[byte(opInc), currentCommand[1]] + elif OpCode(currentCommand[1])==opConstI1: + currentCommand[1] = byte(opInc) + currentCommand.delete(0) + + foundAdd = false + + proc optimizeSub(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = + # TODO(VM/eval) `optimizeSub` not correctly handling stores + # e.g. [a: b - 1] + # labels: vm, evaluator, enhancement, bug + if OpCode(currentCommand[^1]) == opSub: + if currentCommand.len == 3 and OpCode(currentCommand[0])==opConstI1: + currentCommand = @[currentCommand[1], byte(opDec)] + elif OpCode(currentCommand[0])==opSub: + if currentCommand.len == 3 and OpCode(currentCommand[2])==opConstI1: + currentCommand = @[byte(opDec), currentCommand[1]] + + foundSub = false + + template addCurrentCommandToBytecode() {.dirty.} = + if not inBlock: reverse(currentCommand) + + if foundIf or (foundIfE and i+1= nLen - 1: return + let nextNode {.cursor.} = n.a[i+1] + if nextNode.kind == Symbol and nextNode.m notin {pipe, arrowright, thickarrowright}: + + if (let aliased = Aliases.getOrDefault(nextNode.m, NoAliasBinding); aliased != NoAliasBinding): + var symfunc {.cursor.} = GetSym(aliased.name.s) + + if symfunc.kind==Function and aliased.precedence==InfixPrecedence: + i += 1 + var placeholder: int8 + if (not inBlock) and (not evalFunctionCall(currentCommand, symfunc, toHead=false, checkAhead=false, i, placeholder)): + addConst(aliased.name, opCall) + result = symfunc.arity + + template resetArgStackAndCheckForTrailingPipe(currentArgStack: var seq[int], commandFinished: untyped, withTrailingPipe: untyped) = + if currentArgStack.len != 0: currentArgStack[^1] -= 1 + + while currentArgStack.len != 0 and currentArgStack[^1] == 0: + discard currentArgStack.pop() + currentArgStack[^1] -= 1 + + if not (i+11: + argStack.add(tmpFuncArity-1) + # TODO(VM/eval) to be fixed + # labels: bug, evaluator, vm + var placeholder: int8 + if not evalFunctionCall(currentCommand, nextNode, toHead=true, checkAhead=false, i, placeholder): + addTrailingConst(nextNode, opCall) + else: + addTrailingConst(nextNode, opCall) + if argStack.len==0: + addCurrentCommandToBytecode() + i += 1 + + proc postAddTerminalSubValue(consts: var ValueArray, currentCommand: var VBinary, i: var int, n: Value, subargStack: var seq[int], ret: var ValueArray, ended: var bool) = + # Check if command complete + + resetArgStackAndCheckForTrailingPipe(subargStack): + # The subcommand is finished + ended = true + do: + discard + + template addTerminalValue(inBlock: bool, code: untyped): untyped {.dirty.} = + block: + # Check for potential Infix operator ahead + if (let infixArity = getArityForInfixOperatorAhead(inBlock, consts, currentCommand, i, n); infixArity != -1): + when not inBlock: + argStack.add(infixArity) + else: + subargStack.add(infixArity) + ret.add(n.a[i]) + + # Run main code + code + + # Check if command is complete + when not inBlock: + postAddTerminalValue(consts, currentCommand, i, n, it) + else: + postAddTerminalSubValue(consts, currentCommand, i, n, subargStack, ret, ended) + + template processArrowRight(): untyped = + i += 1 + + while i < nLen and not ended: + let subnode {.cursor.} = n.a[i] + ret.add(subnode) + + case subnode.kind: + of Null, + Logical: discard + of Integer, + Floating, + Type, + Char, + String, + Literal, + Path, + Inline, + Block: + addTerminalValue(inBlock=true): + discard + of Word: + if (let funcArity = TmpArities.getOrDefault(subnode.s, -1); funcArity != -1): + if funcArity!=0: + subargStack.add(funcArity) + else: + addTerminalValue(inBlock=true): + discard + else: + addTerminalValue(inBlock=true): + discard + + of Symbol: + let symalias = subnode.m + let aliased = Aliases.getOrDefault(symalias, NoAliasBinding) + if likely(aliased != NoAliasBinding): + let symfunc {.cursor.} = GetSym(aliased.name.s) + if symfunc.kind==Function: + if aliased.precedence==PrefixPrecedence: + if symfunc.arity != 0: + subargStack.add(symfunc.arity) + else: + addTerminalValue(inBlock=true): + discard + else: + ret.add(newSymbol(ampersand)) + swap(ret[^1],ret[^2]) + subargStack.add(symfunc.arity-1) + else: + addTerminalValue(inBlock=true): + discard + else: + addTerminalValue(inBlock=true): + discard + + of AttributeLabel: + subargStack[subargStack.len-1] += 1 + + else: discard + + + i += 1 + + i -= 1 + ret + + proc processThickArrowRight(argblock: var ValueArray, subblock: var ValueArray, it: var VBinary, n: Value, i: var int, funcArity: var int8) = + while n.a[i+1].kind == Newline: + when not defined(NOERRORLINES): + addEol(it, n.a[i+1].line) + i += 1 + + # get next node + let subnode {.cursor.} = n.a[i+1] + + # we'll want to create the two blocks, + # for functions like loop, map, select, filter + # so let's get them ready + argblock.setLen(0) + subblock = @[subnode] + + # if it's a word + if subnode.kind==Word: + # check if it's a function + funcArity = TmpArities.getOrDefault(subnode.s, -1) + if funcArity != -1: + # automatically "push" all its required arguments + for i in 0..(funcArity-1): + let arg = newWord("_" & $(i)) + argblock.add(arg) + subblock.add(arg) + + elif subnode.kind==Block: + # replace ampersand symbols, + # sequentially, with arguments + var idx = 0 + var fnd: int8 = 0 + while idx funcArity-1 for ToS/ToI! + else: + addConst(node, opCall) + argStack.add(funcArity) + else: + addTerminalValue(inBlock=false): + addConst(node, opCall) + else: + addTerminalValue(inBlock=false): + if node.s == "true": + addToCommand(opConstBT) + elif node.s == "false": + addToCommand(opConstBF) + else: + addConst(node, opLoad) + + of Block: + addTerminalValue(inBlock=false): + if node.a.len==0: + addToCommand(opConstA) + else: + addConst(node, opPush) + + of Integer: + addTerminalValue(inBlock=false): + when defined(WEB) or not defined(NOGMP): + if likely(node.iKind==NormalInteger): + if node.i>=0 and node.i<=15: addToCommand(byte(opConstI0) + byte(node.i)) + else: addConst(node, opPush) + else: + addConst(node, opPush) + else: + if node.i>=0 and node.i<=15: addToCommand(byte(opConstI0) + byte(node.i)) + else: addConst(node, opPush) + + of String: + {.linearScanEnd.} + addTerminalValue(inBlock=false): + if node.s.len==0: + addToCommand(opConstS) + else: + addConst(node, opPush) + + #--------------------------- + + of Label: + + let funcIndx {.cursor.} = node.s + var hasThickArrow = false + var ab: ValueArray + var sb: ValueArray + let nextNode {.cursor.} = n.a[i+1] + if (nextNode.kind == Word and nextNode.s == "function") or + (nextNode.kind == Symbol and nextNode.m == dollar): + let afterNextNode {.cursor.} = n.a[i+2] + if afterNextNode.kind == Symbol and afterNextNode.m == thickarrowright: + i += 2 + var funcArity: int8 = 0 + processThickArrowRight(ab, sb, it, n, i, funcArity) + TmpArities[funcIndx] = funcArity + hasThickArrow = true + i += 1 + else: + TmpArities[funcIndx] = int8(afterNextNode.a.countIt(it.kind != Type)) #n.a[i+2].a.len + else: + if not isDictionary: + TmpArities.del(funcIndx) + + if unlikely(isDictionary): + addShortConst(node, opDStore) + else: + addConst(node, opStore) + + argStack.add(1) + + if hasThickArrow: + addConst(newWord("function"), opCall) + argStack.add(2) + + # add the blocks + addTerminalValue(inBlock=false): + addConst(newBlock(ab), opPush) + addTerminalValue(inBlock=false): + addConst(newBlock(sb), opPush) + + of Range: + addTerminalValue(inBlock=false): + addConst(node, opPush) + + of Null: addToCommand(opConstN) + of Logical: + if isTrue(node): addToCommand(opConstBT) + elif isFalse(node): addToCommand(opConstBF) + else: addToCommand(opConstBM) + + of Floating: + addTerminalValue(inBlock=false): + if node.f==0.0: addToCommand(opConstF0) + elif node.f==1.0: addToCommand(opConstF1) + elif node.f==2.0: addToCommand(opConstF2) + else: addConst(node, opPush) + + of Attribute: + addConst(node, opAttr) + addToCommand(opConstBT) + + of AttributeLabel: + addConst(node, opAttr) + argStack[argStack.len-1] += 1 + + of Path: + var pathCallV: Value = nil + + if (let curr = Syms.getOrDefault(node.p[0].s, nil); not curr.isNil): + let next {.cursor.} = node.p[1] + if curr.kind==Dictionary and (next.kind==Literal or next.kind==Word): + if (let item = curr.d.getOrDefault(next.s, nil); not item.isNil): + if item.kind == Function: + pathCallV = item + + if not pathCallV.isNil: + addConst(pathCallV, opCall) + argStack.add(pathCallV.arity) + else: + addTerminalValue(inBlock=false): + addToCommand(opGet) + + var i=1 + while i=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) + else: addConst(node.p[i], opPush) + else: + addConst(node.p[i], opPush) + else: + addConst(node.p[i], opPush) + i += 1 + + of PathLabel: + addToCommand(opSet) + + var i=1 + while i=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) + else: addConst(node.p[i], opPush) + else: + addConst(node.p[i], opPush) + else: + addConst(node.p[i], opPush) + i += 1 + + argStack.add(1) + + of Symbol: + case node.m: + of doublecolon : + inc(i) + var subblock: ValueArray + while i < nLen: + let subnode {.cursor.} = n.a[i] + subblock.add(subnode) + inc(i) + addTerminalValue(inBlock=false): + addConst(newBlock(subblock), opPush) + + of arrowright : + var subargStack: seq[int] + var ended = false + var ret: ValueArray + + let subblock = processArrowRight() + + addTerminalValue(inBlock=false): + addConst(newBlock(subblock), opPush) + + of thickarrowright : + # TODO(Eval\addTerminalValue) Thick arrow-right not working with pipes + # labels: vm,evaluator,enhancement,bug + var ab: ValueArray + var sb: ValueArray + var funcArity: int8 = 0 + processThickArrowRight(ab, sb, it, n, i, funcArity) + + # add the blocks + addTerminalValue(inBlock=false): + if ab.len == 1: + addConst(newLiteral(ab[0].s), opPush) + else: + addConst(newBlock(ab), opPush) + addTerminalValue(inBlock=false): + addConst(newBlock(sb), opPush) + + i += 1 + else: + let symalias = node.m + let aliased = Aliases.getOrDefault(symalias, NoAliasBinding) + if likely(aliased != NoAliasBinding): + var symfunc {.cursor.} = GetSym(aliased.name.s) + if symfunc.kind==Function: + if symfunc.fnKind == BuiltinFunction and symfunc.arity!=0: + var placeholder: int8 + if not evalFunctionCall(currentCommand, symfunc, toHead=false, checkAhead=false, i, placeholder): + addConst(aliased.name, opCall) + argStack.add(symfunc.arity) + elif symfunc.fnKind == UserFunction and symfunc.arity!=0: + addConst(aliased.name, opCall) + argStack.add(symfunc.arity) + else: + addTerminalValue(inBlock=false): + addConst(aliased.name, opCall) + else: + if aliased.name.s == "null": + addTerminalValue(inBlock=false): + addToCommand(opConstN) + else: + addTerminalValue(inBlock=false): + addConst(aliased.name, opLoad) + else: + addTerminalValue(inBlock=false): + addConst(node, opPush) + + of Dictionary: + addTerminalValue(inBlock=false): + if node.d.len==0: + addToCommand(opConstD) + else: + addConst(node, opPush) + + # TODO(VM/eval) Inline blocks not evaluated correctly + # more than one commands in the block, seem to be evaluated in a reverse order + # labels: vm,evaluator,bug,critical + of Inline: + addTerminalValue(inBlock=false): + evalOne(node, consts, currentCommand, inBlock=true, isDictionary=isDictionary) + + of Date, Binary, Database, Bytecode, + Nothing, Any: + + discard + + else: + # of Complex, Rational, Version, Type, Char, Literal, SymbolLiteral, Quantity, Regex, Color, Object, Function: + addTerminalValue(inBlock=false): + addConst(node, opPush) + + i += 1 + + if currentCommand.len > 0: + addCurrentCommandToBytecode() + +proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Translation {.inline.} = + ## Take a parsed Block of values and return its Translation - + ## that is: the constants found + the list of bytecode instructions + discard generateAst(root) + + var vhash {.used.}: Hash = -1 + + when useStored: + if not root.dynamic: + vhash = hash(root) + if (let stEv = StoredEval.getOrDefault(vhash, nil); not stEv.isNil): + return stEv + + var cnsts: ValueArray + var newit: VBinary + + TmpArities = collect: + for k,v in Syms.pairs: + if v.kind == Function: + {k: v.arity} + + evalOne(root, cnsts, newit, isDictionary=isDictionary) + newit.add(byte(opEnd)) + + # when defined(OPTIMIZED): + # newit = optimizeBytecode(newit) + + result = Translation(constants: cnsts, instructions: newit) + + when useStored: + if vhash != -1: + StoredEval[vhash] = result + +template evalOrGet*(item: Value): untyped = + if item.kind==Bytecode: item.trans + else: doEval(item) \ No newline at end of file From 49385b09ea5a5cedf17d7408b78f559cc3e6760b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 16:55:58 +0100 Subject: [PATCH 267/984] VM/eval: added main structure (comments, etc) --- src/vm/eval.nim | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index e69de29bb2..a006ebeedb 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -0,0 +1,36 @@ +#======================================================= +# Arturo +# Programming Language + Bytecode VM compiler +# (c) 2019-2023 Yanis ZafirΓ³pulos +# +# @file: vm/eval.nim +#======================================================= + +## This module contains the evaluator for the VM. +## +## The evaluator: +## - takes a Block of values coming from the parser +## - passes to the AST generator +## - interpretes the AST and returns a Translation object +## +## The main entry point is ``doEval``. + +#======================================= +# Libraries +#======================================= + +#======================================= +# Variables +#======================================= + +#======================================= +# Helpers +#======================================= + +#======================================= +# Methods +#======================================= + +#======================================= +# Main +#======================================= \ No newline at end of file From cf67fd78545a75377553947277a89bed932753a7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:04:37 +0100 Subject: [PATCH 268/984] VM/eval: added main `doEval` entry method & placeholder `evaluateBlock` method --- src/vm/eval.nim | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index a006ebeedb..a01435c3a0 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -19,10 +19,17 @@ # Libraries #======================================= +import hashes, tables + +import vm/[ast, bytecode, values/value] + #======================================= # Variables #======================================= +var + StoredTranslations : Table[Hash, Translation] + #======================================= # Helpers #======================================= @@ -31,6 +38,32 @@ # Methods #======================================= +proc evaluateBlock*(blok: Node, isDictionary=false): Translation = + discard + #======================================= # Main -#======================================= \ No newline at end of file +#======================================= + +proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Translation {.inline.} = + ## Take a parsed Block of values and return its Translation - + ## that is: the constants found + the list of bytecode instructions + + var vhash {.used.}: Hash = -1 + + when useStored: + if not root.dynamic: + vhash = hash(root) + if (let storedTranslation = StoredTranslations.getOrDefault(vhash, nil); not storedTranslation.isNil): + return storedTranslation + + result = evaluateBlock(generateAst(root), isDictionary=isDictionary) + result.instructions.add(byte(opEnd)) + + when useStored: + if vhash != -1: + StoredTranslations[vhash] = result + +template evalOrGet*(item: Value): untyped = + if item.kind==Bytecode: item.trans + else: doEval(item) \ No newline at end of file From 385eed48ffbfc032f28deafb118869f446f761a9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:06:35 +0100 Subject: [PATCH 269/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3ee548b114..f763d2f59d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3657 \ No newline at end of file +3658 \ No newline at end of file From 493abb0e7f33cd1d511459d68f4085221daff69b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:07:25 +0100 Subject: [PATCH 270/984] added missing imports + placeholder `evaluateBlock` --- src/vm/eval.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index a01435c3a0..417375206a 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -22,6 +22,7 @@ import hashes, tables import vm/[ast, bytecode, values/value] +import vm/values/custom/[vbinary] #======================================= # Variables @@ -39,7 +40,10 @@ var #======================================= proc evaluateBlock*(blok: Node, isDictionary=false): Translation = - discard + var consts: ValueArray + var it: VBinary + + result = Translation(constants: consts, instructions: it) #======================================= # Main From 61a12bee3f8484a0b1487f85c163938bf615d7aa Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:08:38 +0100 Subject: [PATCH 271/984] re-added `indexOfValue` helper --- src/vm/eval.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 417375206a..6f7f169ade 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -35,6 +35,13 @@ var # Helpers #======================================= +func indexOfValue(a: ValueArray, item: Value): int {.inline,enforceNoRaises.}= + result = 0 + for i in items(a): + if consideredEqual(item, i): return + inc(result) + result = -1 + #======================================= # Methods #======================================= From 9f87498a2cce4e8ac1930df6c85185491015c98a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:11:09 +0100 Subject: [PATCH 272/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f763d2f59d..2fc619a9af 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3658 \ No newline at end of file +3659 \ No newline at end of file From 7daef4d6a0827377d09bae72107f1a5a872c2b74 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:11:47 +0100 Subject: [PATCH 273/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2fc619a9af..ade2696750 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3659 \ No newline at end of file +3660 \ No newline at end of file From 17af1318b920e06279b7de95562085961a90a4aa Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:12:04 +0100 Subject: [PATCH 274/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ade2696750..99aa2a3006 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3660 \ No newline at end of file +3661 \ No newline at end of file From 5121d0585ccc78a106245f600a112c481a99db3d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:14:28 +0100 Subject: [PATCH 275/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 99aa2a3006..efdd6f806c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3661 \ No newline at end of file +3662 \ No newline at end of file From 9f1febebfbc62c0f938989789c7a5f4700810663 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:15:58 +0100 Subject: [PATCH 276/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index efdd6f806c..a690ddc1d4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3662 \ No newline at end of file +3663 \ No newline at end of file From 0a9a2cba9247817ddd36dc2b57715eeee0a0ae00 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:26:03 +0100 Subject: [PATCH 277/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a690ddc1d4..b0460c1817 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3663 \ No newline at end of file +3664 \ No newline at end of file From b698c5a19028123bc654393093d87533144ce4bd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:26:26 +0100 Subject: [PATCH 278/984] VM/eval: re-add some core helpers + add main implementation of "The loop" --- src/vm/eval.nim | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 6f7f169ade..1734b58837 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -24,6 +24,8 @@ import hashes, tables import vm/[ast, bytecode, values/value] import vm/values/custom/[vbinary] +import vm/values/printable + #======================================= # Variables #======================================= @@ -42,6 +44,35 @@ func indexOfValue(a: ValueArray, item: Value): int {.inline,enforceNoRaises.}= inc(result) result = -1 +template addToInstructions(b: untyped):untyped {.dirty.} = + when b is OpCode: + instructions.add(byte(b)) + else: + instructions.add(b) + +proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode) {.inline,enforceNoRaises.} = + var indx = consts.indexOfValue(v) + if indx == -1: + let newv = v + newv.readonly = true + consts.add(newv) + indx = consts.len-1 + + if indx <= 13: + addToInstructions((byte(op)-0x0E) + byte(indx)) + else: + if indx>255: + addToInstructions([ + byte(indx), + byte(indx shr 8), + byte(op)+1 + ]) + else: + addToInstructions([ + byte(indx), + byte(op) + ]) + #======================================= # Methods #======================================= @@ -50,6 +81,39 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = var consts: ValueArray var it: VBinary + let nLen = blok.children.len + var i {.register.} = 0 + + #------------------------ + # Shortcuts + #------------------------ + + template addConst(v: Value, op: OpCode): untyped = + addConst(consts, it, v, op) + + #------------------------ + # MainLoop + #------------------------ + + while i < nLen: + let item = blok.children[i] + + echo "current item:" + echo dumpNode(item) + + for instruction in traverse(item): + case item.kind: + of ConstantValue: + addConst(item.value, opPush) + of VariableLoad: + addConst(item.value, opLoad) + of VariableStore: + addConst(item.value, opStore) + else: + discard + + i += 1 + result = Translation(constants: consts, instructions: it) #======================================= @@ -71,6 +135,8 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) + dump(newBytecode(result)) + when useStored: if vhash != -1: StoredTranslations[vhash] = result From 39ca07c39fe347c5300d83beac48d84274f988c0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:27:48 +0100 Subject: [PATCH 279/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b0460c1817..dcef0431f1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3664 \ No newline at end of file +3665 \ No newline at end of file From 871bcdf82c8a8974df3d67bfc530303f9d90f753 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:40:28 +0100 Subject: [PATCH 280/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index dcef0431f1..b5c9bf8543 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3665 \ No newline at end of file +3666 \ No newline at end of file From 0b350f4217fe1226b050add58929f14905bb0591 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:41:38 +0100 Subject: [PATCH 281/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b5c9bf8543..218011b609 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3666 \ No newline at end of file +3667 \ No newline at end of file From 1eab7fa60e0bbc24bf7f43e705687ebef5ff8c99 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:43:37 +0100 Subject: [PATCH 282/984] minor fix --- src/vm/ast.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 4ba97d26c6..2745069361 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -42,6 +42,8 @@ type # CallNode VariableStore # Store a variable + OtherCall # Call to a function that is not a builtin + ArrayCall # Opcode'd built-ins DictCall FuncCall @@ -91,8 +93,6 @@ type IncCall DecCall - OtherCall # Call to a function that is not a builtin - NodeArray* = seq[Node] Node* = ref object @@ -129,7 +129,7 @@ var const TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} - CallNode : set[NodeKind] = {VariableStore..OtherCall} + CallNode : set[NodeKind] = {VariableStore..DecCall} #======================================= # Forward declarations @@ -343,7 +343,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b #------------------------ proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = - var callType: ArrayCall..OtherCall = OtherCall + var callType: OtherCall..DecCall = OtherCall var fn {.cursor.}: Value = if fun.isNil: From 33ad8ea740380d1d03cbf01ef554a935fce7500e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 17:43:51 +0100 Subject: [PATCH 283/984] properly handle all different built-in functions --- src/vm/eval.nim | 116 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 6 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 1734b58837..fd17f3d9b9 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -91,6 +91,9 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = template addConst(v: Value, op: OpCode): untyped = addConst(consts, it, v, op) + template addBuiltinCall(op: OpCode): untyped = + it.add(byte(op)) + #------------------------ # MainLoop #------------------------ @@ -102,15 +105,116 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = echo dumpNode(item) for instruction in traverse(item): - case item.kind: + echo "processing: " + echo dumpNode(instruction) + case instruction.kind: + of RootNode: + discard of ConstantValue: - addConst(item.value, opPush) + addConst(instruction.value, opPush) of VariableLoad: - addConst(item.value, opLoad) + addConst(instruction.value, opLoad) of VariableStore: - addConst(item.value, opStore) - else: - discard + addConst(instruction.value, opStore) + of OtherCall: + addConst(instruction.value, opCall) + + of ArrayCall: + addBuiltinCall(opArray) + of DictCall: + addBuiltinCall(opDict) + of FuncCall: + addBuiltinCall(opFunc) + of AddCall: + addBuiltinCall(opAdd) + of SubCall: + addBuiltinCall(opSub) + of MulCall: + addBuiltinCall(opMul) + of DivCall: + addBuiltinCall(opDiv) + of FdivCall: + addBuiltinCall(opFdiv) + of ModCall: + addBuiltinCall(opMod) + of PowCall: + addBuiltinCall(opPow) + of NegCall: + addBuiltinCall(opNeg) + of BNotCall: + addBuiltinCall(opBNot) + of BAndCall: + addBuiltinCall(opBAnd) + of BOrCall: + addBuiltinCall(opBOr) + of ShlCall: + addBuiltinCall(opShl) + of ShrCall: + addBuiltinCall(opShr) + of NotCall: + addBuiltinCall(opNot) + of AndCall: + addBuiltinCall(opAnd) + of OrCall: + addBuiltinCall(opOr) + of EqCall: + addBuiltinCall(opEq) + of NeCall: + addBuiltinCall(opNe) + of GtCall: + addBuiltinCall(opGt) + of GeCall: + addBuiltinCall(opGe) + of LtCall: + addBuiltinCall(opLt) + of LeCall: + addBuiltinCall(opLe) + of IfCall: + addBuiltinCall(opIf) + of IfECall: + addBuiltinCall(opIfE) + of UnlessCall: + addBuiltinCall(opUnless) + of UnlessECall: + addBuiltinCall(opUnless) # TO FIX + of ElseCall: + addBuiltinCall(opElse) + of SwitchCall: + addBuiltinCall(opSwitch) + of WhileCall: + addBuiltinCall(opWhile) + of ReturnCall: + addBuiltinCall(opReturn) + of ToCall: + addBuiltinCall(opTo) + of PrintCall: + addBuiltinCall(opPrint) + of GetCall: + addBuiltinCall(opGet) + of SetCall: + addBuiltinCall(opSet) + of RangeCall: + addBuiltinCall(opRange) + of LoopCall: + addBuiltinCall(opLoop) + of MapCall: + addBuiltinCall(opMap) + of SelectCall: + addBuiltinCall(opSelect) + of SizeCall: + addBuiltinCall(opSize) + of ReplaceCall: + addBuiltinCall(opReplace) + of SplitCall: + addBuiltinCall(opSplit) + of JoinCall: + addBuiltinCall(opJoin) + of ReverseCall: + addBuiltinCall(opReverse) + of IncCall: + addBuiltinCall(opInc) + of DecCall: + addBuiltinCall(opDec) i += 1 From 56f2dadab9bb84153291f19f274382802c7307f4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 18:03:15 +0100 Subject: [PATCH 284/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 218011b609..875478b209 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3667 \ No newline at end of file +3668 \ No newline at end of file From 5abb45d1e8fe6f4ab580467477c0141200253f01 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 18:04:05 +0100 Subject: [PATCH 285/984] VM/ast: directly store kind as an OpCode (no need for double-checking the exact same things!) --- src/vm/ast.nim | 234 ++++++++++++++++++++----------------------------- 1 file changed, 97 insertions(+), 137 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 2745069361..95751cf14e 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -26,6 +26,7 @@ import vm/[globals, values/value, values/comparison, values/types] import vm/values/printable import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vrational, vsymbol, vversion] +import vm/bytecode #======================================= # Types #======================================= @@ -43,55 +44,8 @@ type VariableStore # Store a variable OtherCall # Call to a function that is not a builtin - - ArrayCall # Opcode'd built-ins - DictCall - FuncCall - AddCall - SubCall - MulCall - DivCall - FdivCall - ModCall - PowCall - NegCall - BNotCall - BAndCall - BOrCall - ShlCall - ShrCall - NotCall - AndCall - OrCall - EqCall - NeCall - GtCall - GeCall - LtCall - LeCall - IfCall - IfECall - UnlessCall - UnlessECall - ElseCall - SwitchCall - WhileCall - ReturnCall - ToCall - PrintCall - GetCall - SetCall - RangeCall - LoopCall - MapCall - SelectCall - SizeCall - ReplaceCall - SplitCall - JoinCall - ReverseCall - IncCall - DecCall + BuiltinCall # Call to a builtin function + SpecialCall # Call to a special function NodeArray* = seq[Node] @@ -100,6 +54,7 @@ type of RootNode, ConstantValue, VariableLoad: discard else: + op*: OpCode arity*: int8 value*: Value @@ -129,7 +84,7 @@ var const TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} - CallNode : set[NodeKind] = {VariableStore..DecCall} + CallNode : set[NodeKind] = {VariableStore..SpecialCall} #======================================= # Forward declarations @@ -189,10 +144,11 @@ template newTerminalNode(kn: NodeKind, va: Value): Node = value: va ) -template newCallNode(kn: NodeKind, ar: int8, va: Value): Node = +template newCallNode(kn: NodeKind, ar: int8, va: Value, oper: OpCode = opNop): Node = Node( kind: kn, arity: ar, + op: oper, value: va ) @@ -220,50 +176,50 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target.replaceNode(newTerminalNode(ConstantValue, left.value + right.value)) # Convert 1 + X -> inc X elif left.value == I1: - target.kind = IncCall + target.op = opInc target.arity = 1 target.setOnlyChild(right) # Convert X + 1 -> inc X elif right.kind == ConstantValue and right.value == I1: - target.kind = IncCall + target.op = opInc target.arity = 1 target.setOnlyChild(left) # Convert X + X * Y -> X * (1 + Y) and # X + Y * X -> X * (Y + 1) - elif left.kind == VariableLoad and right.kind == MulCall: + elif left.kind == VariableLoad and right.op == opMul: if right.children[0].kind == VariableLoad and right.children[0].value == left.value: - target.kind = MulCall + target.op = opMul if right.children[1].kind == ConstantValue and right.children[1].value.kind in {Integer, Floating}: right.replaceNode(newTerminalNode(ConstantValue, right.children[1].value + I1)) else: - right.kind = AddCall + right.op = opAdd right.children[0].value = newInteger(1) elif right.children[1].kind == VariableLoad and right.children[1].value == left.value: - target.kind = MulCall + target.op = opMul if right.children[0].kind == ConstantValue and right.children[0].value.kind in {Integer, Floating}: right.replaceNode(newTerminalNode(ConstantValue, right.children[0].value + I1)) else: - right.kind = AddCall + right.op = opAdd right.children[1].value = newInteger(1) # Convert (X * Y) + X -> (1 + Y) * X and # (Y * X) + X -> (Y + 1) * X - elif right.kind == VariableLoad and left.kind == MulCall: + elif right.kind == VariableLoad and left.op == opMul: if left.children[0].kind == VariableLoad and left.children[0].value == right.value: - target.kind = MulCall + target.op = opMul if left.children[1].kind == ConstantValue and left.children[1].value.kind in {Integer, Floating}: left.replaceNode(newTerminalNode(ConstantValue, left.children[1].value + I1)) else: - left.kind = AddCall + left.op = opAdd left.children[0].value = newInteger(1) elif left.children[1].kind == VariableLoad and left.children[1].value == right.value: - target.kind = MulCall + target.op = opMul if left.children[0].kind == ConstantValue and left.children[0].value.kind in {Integer, Floating}: left.replaceNode(newTerminalNode(ConstantValue, left.children[0].value + I1)) else: - left.kind = AddCall + left.op = opAdd left.children[1].value = newInteger(1) proc optimizeSub(target: var Node) {.enforceNoRaises.} = @@ -275,7 +231,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target.replaceNode(newTerminalNode(ConstantValue, left.value - right.value)) elif right.kind == ConstantValue and right.value == I1: # Convert X - 1 -> dec X - target.kind = DecCall + target.op = opDec target.arity = 1 target.setOnlyChild(left) @@ -287,27 +243,27 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target.replaceNode(newTerminalNode(ConstantValue, op(left.value,right.value))) proc optimizeUnless(target: var Node) {.enforceNoRaises.} = - target.kind = - if target.kind == UnlessCall: - IfCall + target.op = + if target.op == opUnless: + opIf else: - IfECall + opIfE var left = target.children[0] - case left.kind: - of EqCall : left.kind = NeCall - of NeCall : left.kind = EqCall - of LtCall : left.kind = GeCall - of LeCall : left.kind = GtCall - of GtCall : left.kind = LeCall - of GeCall : left.kind = LtCall - of NotCall : + case left.op: + of opEq : left.op = opNe + of opNe : left.op = opEq + of opLt : left.op = opGe + of opLe : left.op = opGt + of opGt : left.op = opLe + of opGe : left.op = opLt + of opNot : let newNode = left.children[0] newNode.parent = target target.children[0] = newNode else: - let newNode = newCallNode(NotCall, 1, nil) + let newNode = newCallNode(BuiltinCall, 1, nil, opNot) newNode.children = @[left] target.children[0] = newNode for child in newNode.children: @@ -322,16 +278,15 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b template rewindCallBranches(target: var Node, optimize: bool = false): untyped = while target.kind in CallNode and target.children.len == target.arity: when optimize: - case target.kind: - of AddCall : target.optimizeAdd() - of SubCall : target.optimizeSub() - of MulCall : target.optimizeArithmeticOp(`*`) - of DivCall : target.optimizeArithmeticOp(`/`) - of FdivCall : target.optimizeArithmeticOp(`//`) - of ModCall : target.optimizeArithmeticOp(`%`) - of PowCall : target.optimizeArithmeticOp(`^`) - of UnlessCall, - UnlessECall : target.optimizeUnless() + case target.op: + of opAdd : target.optimizeAdd() + of opSub : target.optimizeSub() + of opMul : target.optimizeArithmeticOp(`*`) + of opDiv : target.optimizeArithmeticOp(`/`) + of opFDiv : target.optimizeArithmeticOp(`//`) + of opMod : target.optimizeArithmeticOp(`%`) + of opPow : target.optimizeArithmeticOp(`^`) + of opUnless : target.optimizeUnless() else: discard @@ -343,7 +298,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b #------------------------ proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = - var callType: OtherCall..DecCall = OtherCall + var callType: OtherCall..SpecialCall = OtherCall var fn {.cursor.}: Value = if fun.isNil: @@ -357,54 +312,59 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b else: arity - if fn == ArrayF : callType = ArrayCall - elif fn == DictF : callType = DictCall - elif fn == FuncF : callType = FuncCall - elif fn == AddF : callType = AddCall - elif fn == SubF : callType = SubCall - elif fn == MulF : callType = MulCall - elif fn == DivF : callType = DivCall - elif fn == FdivF : callType = FdivCall - elif fn == ModF : callType = ModCall - elif fn == PowF : callType = PowCall - elif fn == NegF : callType = NegCall - elif fn == BNotF : callType = BNotCall - elif fn == BAndF : callType = BAndCall - elif fn == BOrF : callType = BOrCall - elif fn == ShlF : callType = ShlCall - elif fn == ShrF : callType = ShrCall - elif fn == NotF : callType = NotCall - elif fn == AndF : callType = AndCall - elif fn == OrF : callType = OrCall - elif fn == EqF : callType = EqCall - elif fn == NeF : callType = NeCall - elif fn == GtF : callType = GtCall - elif fn == GeF : callType = GeCall - elif fn == LtF : callType = LtCall - elif fn == LeF : callType = LeCall - elif fn == IfF : callType = IfCall - elif fn == IfEF : callType = IfECall - elif fn == UnlessF : callType = UnlessCall - elif fn == UnlessEF : callType = UnlessECall - elif fn == ElseF : callType = ElseCall - elif fn == SwitchF : callType = SwitchCall - elif fn == WhileF : callType = WhileCall - elif fn == ReturnF : callType = ReturnCall - elif fn == ToF : callType = ToCall - elif fn == PrintF : callType = PrintCall - elif fn == GetF : callType = GetCall - elif fn == SetF : callType = SetCall - elif fn == RangeF : callType = RangeCall - elif fn == LoopF : callType = LoopCall - elif fn == MapF : callType = MapCall - elif fn == SelectF : callType = SelectCall - elif fn == SizeF : callType = SizeCall - elif fn == ReplaceF : callType = ReplaceCall - elif fn == SplitF : callType = SplitCall - elif fn == JoinF : callType = JoinCall - elif fn == ReverseF : callType = ReverseCall - elif fn == IncF : callType = IncCall - elif fn == DecF : callType = DecCall + var op: OpCode = opNop + + if fn == ArrayF : op = opArray + elif fn == DictF : op = opDict + elif fn == FuncF : op = opFunc + elif fn == AddF : op = opAdd + elif fn == SubF : op = opSub + elif fn == MulF : op = opMul + elif fn == DivF : op = opDiv + elif fn == FdivF : op = opFDiv + elif fn == ModF : op = opMod + elif fn == PowF : op = opPow + elif fn == NegF : op = opNeg + elif fn == BNotF : op = opBNot + elif fn == BAndF : op = opBAnd + elif fn == BOrF : op = opBOr + elif fn == ShlF : op = opShl + elif fn == ShrF : op = opShr + elif fn == NotF : op = opNot + elif fn == AndF : op = opAnd + elif fn == OrF : op = opOr + elif fn == EqF : op = opEq + elif fn == NeF : op = opNe + elif fn == GtF : op = opGt + elif fn == GeF : op = opGe + elif fn == LtF : op = opLt + elif fn == LeF : op = opLe + elif fn == IfF : callType = SpecialCall; op = opIf + elif fn == IfEF : callType = SpecialCall; op = opIfE + elif fn == UnlessF : callType = SpecialCall; op = opUnless + elif fn == UnlessEF : callType = SpecialCall; op = opUnless + elif fn == ElseF : callType = SpecialCall; op = opElse + elif fn == SwitchF : callType = SpecialCall; op = opSwitch + elif fn == WhileF : callType = SpecialCall; op = opWhile + elif fn == ReturnF : op = opReturn + elif fn == ToF : op = opTo + elif fn == PrintF : op = opPrint + elif fn == GetF : op = opGet + elif fn == SetF : op = opSet + elif fn == RangeF : op = opRange + elif fn == LoopF : op = opLoop + elif fn == MapF : op = opMap + elif fn == SelectF : op = opSelect + elif fn == SizeF : op = opSize + elif fn == ReplaceF : op = opReplace + elif fn == SplitF : op = opSplit + elif fn == JoinF : op = opJoin + elif fn == ReverseF : op = opReverse + elif fn == IncF : op = opInc + elif fn == DecF : op = opDec + + if callType == OtherCall and op != opNop: + callType = BuiltinCall var v: Value = if callType == OtherCall: @@ -412,7 +372,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b else: nil - target.addChild(newCallNode(callType, ar, v)) + target.addChild(newCallNode(callType, ar, v, op)) target = target.children[^1] From f52dc9dca5667813d9e1edd6af4f347ec681de4a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 18:05:22 +0100 Subject: [PATCH 286/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 875478b209..bc96f8cd8b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3668 \ No newline at end of file +3669 \ No newline at end of file From 4b38586be0f1512e059383f8ae031b55dba9e96a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 18:06:46 +0100 Subject: [PATCH 287/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bc96f8cd8b..159cd926c4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3669 \ No newline at end of file +3670 \ No newline at end of file From 3ec2eab8010c9642516260b6921a244d4fbfbdae Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 18:36:40 +0100 Subject: [PATCH 288/984] VM/ast: [dumpNode] fix BuiltinCall's --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 95751cf14e..45e4bf1cf9 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -633,7 +633,7 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false): string = else: result &= "Call: " if node.value.isNil: - result &= ($node.kind).replace("Call","").toLowerAscii() & " <" & $node.arity & ">\n" + result &= ($node.op).replace("op","").toLowerAscii() & " <" & $node.arity & ">\n" else: result &= node.value.s & " <" & $node.arity & ">\n" From ca342e4248966defd228ec8e78b646a3408b529c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 18:37:00 +0100 Subject: [PATCH 289/984] VM/eval: properly handle BuiltinCall nodes --- src/vm/eval.nim | 101 ++---------------------------------------------- 1 file changed, 4 insertions(+), 97 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index fd17f3d9b9..d48cb9d66d 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -118,103 +118,10 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = addConst(instruction.value, opStore) of OtherCall: addConst(instruction.value, opCall) - - of ArrayCall: - addBuiltinCall(opArray) - of DictCall: - addBuiltinCall(opDict) - of FuncCall: - addBuiltinCall(opFunc) - of AddCall: - addBuiltinCall(opAdd) - of SubCall: - addBuiltinCall(opSub) - of MulCall: - addBuiltinCall(opMul) - of DivCall: - addBuiltinCall(opDiv) - of FdivCall: - addBuiltinCall(opFdiv) - of ModCall: - addBuiltinCall(opMod) - of PowCall: - addBuiltinCall(opPow) - of NegCall: - addBuiltinCall(opNeg) - of BNotCall: - addBuiltinCall(opBNot) - of BAndCall: - addBuiltinCall(opBAnd) - of BOrCall: - addBuiltinCall(opBOr) - of ShlCall: - addBuiltinCall(opShl) - of ShrCall: - addBuiltinCall(opShr) - of NotCall: - addBuiltinCall(opNot) - of AndCall: - addBuiltinCall(opAnd) - of OrCall: - addBuiltinCall(opOr) - of EqCall: - addBuiltinCall(opEq) - of NeCall: - addBuiltinCall(opNe) - of GtCall: - addBuiltinCall(opGt) - of GeCall: - addBuiltinCall(opGe) - of LtCall: - addBuiltinCall(opLt) - of LeCall: - addBuiltinCall(opLe) - of IfCall: - addBuiltinCall(opIf) - of IfECall: - addBuiltinCall(opIfE) - of UnlessCall: - addBuiltinCall(opUnless) - of UnlessECall: - addBuiltinCall(opUnless) # TO FIX - of ElseCall: - addBuiltinCall(opElse) - of SwitchCall: - addBuiltinCall(opSwitch) - of WhileCall: - addBuiltinCall(opWhile) - of ReturnCall: - addBuiltinCall(opReturn) - of ToCall: - addBuiltinCall(opTo) - of PrintCall: - addBuiltinCall(opPrint) - of GetCall: - addBuiltinCall(opGet) - of SetCall: - addBuiltinCall(opSet) - of RangeCall: - addBuiltinCall(opRange) - of LoopCall: - addBuiltinCall(opLoop) - of MapCall: - addBuiltinCall(opMap) - of SelectCall: - addBuiltinCall(opSelect) - of SizeCall: - addBuiltinCall(opSize) - of ReplaceCall: - addBuiltinCall(opReplace) - of SplitCall: - addBuiltinCall(opSplit) - of JoinCall: - addBuiltinCall(opJoin) - of ReverseCall: - addBuiltinCall(opReverse) - of IncCall: - addBuiltinCall(opInc) - of DecCall: - addBuiltinCall(opDec) + of BuiltinCall: + addBuiltinCall(instruction.op) + of SpecialCall: + discard # TOFIX! i += 1 From d7124011eb26fefd30afb930510bcf8a25c033d6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 17 Jan 2023 18:38:23 +0100 Subject: [PATCH 290/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 159cd926c4..b50106f981 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3670 \ No newline at end of file +3671 \ No newline at end of file From 8aeda721702685b4aae06c5bbb0b0e865b6ef83b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 10:58:31 +0100 Subject: [PATCH 291/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b50106f981..8df4f0e8f3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3671 \ No newline at end of file +3672 \ No newline at end of file From 74f739f333e8dda388cd2653b2e63ccf75aff50f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:04:58 +0100 Subject: [PATCH 292/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8df4f0e8f3..eb16bd2e26 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3672 \ No newline at end of file +3673 \ No newline at end of file From 4e69f4636d604f2c9894fb43c44e0148ada16a5c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:33:56 +0100 Subject: [PATCH 293/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index eb16bd2e26..da6a5a0223 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3673 \ No newline at end of file +3674 \ No newline at end of file From 00bf935d31b7c70d51faf959d70d9ae66ab3c980 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:38:21 +0100 Subject: [PATCH 294/984] VM/eval: added proper op generation for specific constants (e.g. integers in [0..15], empty strings/arrays, logical values, etc) --- src/vm/eval.nim | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index d48cb9d66d..d40b537adf 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -22,7 +22,7 @@ import hashes, tables import vm/[ast, bytecode, values/value] -import vm/values/custom/[vbinary] +import vm/values/custom/[vbinary, vlogical] import vm/values/printable @@ -91,8 +91,11 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = template addConst(v: Value, op: OpCode): untyped = addConst(consts, it, v, op) - template addBuiltinCall(op: OpCode): untyped = - it.add(byte(op)) + template addByte(b: untyped): untyped = + when b is OpCode: + it.add(byte(b)) + else: + it.add(b) #------------------------ # MainLoop @@ -111,7 +114,43 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = of RootNode: discard of ConstantValue: - addConst(instruction.value, opPush) + var alreadyPut = false + let iv {.cursor.} = instruction.value + case instruction.value.kind: + of Integer: + if likely(iv.iKind==NormalInteger) and iv.i>=0 and iv.i<=15: + addByte(byte(opConstI0) + byte(iv.i)) + alreadyPut = true + of Floating: + if iv.f == 0.0: + addByte(opConstF0) + alreadyPut = true + elif iv.f == 1.0: + addByte(opConstF1) + alreadyPut = true + elif iv.f == 2.0: + addByte(opConstF2) + alreadyPut = true + of String: + if iv.s == "": + addByte(opConstS) + alreadyPut = true + of Block: + if iv.a.len == 0: + addByte(opConstA) + alreadyPut = true + of Logical: + if iv.b == True: + addByte(opConstBT) + alreadyPut = true + elif iv.b == False: + addByte(opConstBF) + alreadyPut = true + else: + discard + + if not alreadyPut: + addConst(instruction.value, opPush) of VariableLoad: addConst(instruction.value, opLoad) of VariableStore: @@ -119,7 +158,7 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = of OtherCall: addConst(instruction.value, opCall) of BuiltinCall: - addBuiltinCall(instruction.op) + addByte(instruction.op) of SpecialCall: discard # TOFIX! From 685f047a7cf4f82ff05417b9e5e9c794da8b9d03 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:38:47 +0100 Subject: [PATCH 295/984] make AST tree traversal work right; that is: *reverse* post-order traversal (RLN) --- src/vm/ast.nim | 72 ++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 45e4bf1cf9..ab882d9557 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -122,6 +122,40 @@ proc replaceNode(node: Node, newNode: Node) = newNode.parent = node.parent node.parent.children[node.parent.children.find(node)] = newNode +#------------------------ +# Iterators +#------------------------ + +iterator traverse*(node: Node): Node = + # reverse post-order traversal (RLN) + var preStack = @[node] + var postStack: seq[Node] + + while preStack.len > 0: + var subnode = preStack.pop() + postStack.add(subnode) + var j = subnode.children.len-1 + while j >= 0: + preStack.add(subnode.children[j]) + j -= 1 + + while postStack.len > 0: + var subnode = postStack.pop() + yield subnode + +iterator traverseLRN*(node: Node): Node = + # post-order traversal (LRN) + var preStack = @[node] + var postStack: seq[Node] + + while preStack.len > 0: + var subnode = preStack.pop() + postStack.add(subnode) + preStack.add(subnode.children) + while postStack.len > 0: + var subnode = postStack.pop() + yield subnode + #------------------------ # Misc #------------------------ @@ -569,44 +603,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b break return i-1 - -iterator traverse*(node: Node): Node = - var preStack = @[node] - var postStack: seq[Node] - while preStack.len > 0: - var subnode = preStack.pop() - postStack.add(subnode) - preStack.add(subnode.children) - while postStack.len > 0: - var subnode = postStack.pop() - yield subnode - -iterator traverseTree*(node: Node): Node = - for child in node.children: - for subchild in traverse(child): - yield subchild - -# iterator traverse*(node: Node): Node = -# var preStack = @[node] -# var postStack: seq[Node] -# while preStack.len > 0: -# var subnode = preStack.pop() -# postStack.add(subnode) -# var i = subnode.children.len-1 -# while i >= 0: -# preStack.add(subnode.children[i]) -# dec(i) -# #preStack.add(subnode.children.reversed) -# while postStack.len > 0: -# var subnode = postStack.pop() -# yield subnode - -# iterator traverseTree*(node: Node): Node = -# for child in node.children: -# if child.kind in CallNode: -# for subchild in traverse(child): -# yield subchild -# #yield child #======================================= # Output From cc3916877f082dcec41c32858a2e85d71ede965f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:49:54 +0100 Subject: [PATCH 296/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index da6a5a0223..02c26ff1cf 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3674 \ No newline at end of file +3675 \ No newline at end of file From 81e894b02f75102aaa89a5b51e80f952317518b9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:51:50 +0100 Subject: [PATCH 297/984] cleanup & re-organize opCode's (negative-1 should come before 0's; for easier calculations during bytecode generation) --- src/vm/opcodes.nim | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/vm/opcodes.nim b/src/vm/opcodes.nim index 8f62ac64fe..5cb0c1f446 100644 --- a/src/vm/opcodes.nim +++ b/src/vm/opcodes.nim @@ -31,30 +31,28 @@ type # [0x00-0x1F] # push constants - opConstI0 = 0x00 # () # # 0 - opConstI1 = 0x01 # () # # 1 - opConstI2 = 0x02 # () # # 2 - opConstI3 = 0x03 # () # # 3 - opConstI4 = 0x04 # () # # 4 - opConstI5 = 0x05 # () # # 5 - opConstI6 = 0x06 # () # # 6 - opConstI7 = 0x07 # () # # 7 - opConstI8 = 0x08 # () # # 8 - opConstI9 = 0x09 # () # # 9 - opConstI10 = 0x0A # () # # 10 - opConstI11 = 0x0B # () # # 11 - opConstI12 = 0x0C # () # # 12 - opConstI13 = 0x0D # () # # 13 - opConstI14 = 0x0E # () # # 14 - opConstI15 = 0x0F # () # # 15 - - opConstI1M = 0x10 # () # # -1 - - opConstF0 = 0x11 # () # # 0.0 - opConstF1 = 0x12 # () # # 1.0 - opConstF2 = 0x13 # () # # 2.0 - - opConstF1M = 0x14 # () # # -1.0 + opConstI1M = 0x00 # () # # -1 + opConstI0 = 0x01 # () # # 0 + opConstI1 = 0x02 # () # # 1 + opConstI2 = 0x03 # () # # 2 + opConstI3 = 0x04 # () # # 3 + opConstI4 = 0x05 # () # # 4 + opConstI5 = 0x06 # () # # 5 + opConstI6 = 0x07 # () # # 6 + opConstI7 = 0x08 # () # # 7 + opConstI8 = 0x09 # () # # 8 + opConstI9 = 0x0A # () # # 9 + opConstI10 = 0x0B # () # # 10 + opConstI11 = 0x0C # () # # 11 + opConstI12 = 0x0D # () # # 12 + opConstI13 = 0x0E # () # # 13 + opConstI14 = 0x0F # () # # 14 + opConstI15 = 0x10 # () # # 15 + + opConstF1M = 0x11 # () # # -1.0 + opConstF0 = 0x12 # () # # 0.0 + opConstF1 = 0x13 # () # # 1.0 + opConstF2 = 0x14 # () # # 2.0 opConstBT = 0x15 # () # # true opConstBF = 0x16 # () # # false From 2a446d6206367fe6e5b8e2c677aaf6388b07c995 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:52:19 +0100 Subject: [PATCH 298/984] comment out debugging comments + proper handling & generation of `-1` & `-1.0` --- src/vm/eval.nim | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index d40b537adf..cf559ada9a 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -104,12 +104,12 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = while i < nLen: let item = blok.children[i] - echo "current item:" - echo dumpNode(item) + # echo "current item:" + # echo dumpNode(item) for instruction in traverse(item): - echo "processing: " - echo dumpNode(instruction) + # echo "processing: " + # echo dumpNode(instruction) case instruction.kind: of RootNode: discard @@ -118,19 +118,34 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = let iv {.cursor.} = instruction.value case instruction.value.kind: of Integer: - if likely(iv.iKind==NormalInteger) and iv.i>=0 and iv.i<=15: + if likely(iv.iKind==NormalInteger) and iv.i >= -1 and iv.i <= 15: addByte(byte(opConstI0) + byte(iv.i)) alreadyPut = true of Floating: - if iv.f == 0.0: - addByte(opConstF0) - alreadyPut = true - elif iv.f == 1.0: - addByte(opConstF1) - alreadyPut = true - elif iv.f == 2.0: - addByte(opConstF2) - alreadyPut = true + case iv.f: + of -1.0: + addByte(opConstF1M) + alreadyPut = true + of 0.0: + addByte(opConstF0) + alreadyPut = true + of 1.0: + addByte(opConstF1) + alreadyPut = true + of 2.0: + addByte(opConstF2) + alreadyPut = true + else: + discard + # if iv.f == 0.0: + # addByte(opConstF0) + # alreadyPut = true + # elif iv.f == 1.0: + # addByte(opConstF1) + # alreadyPut = true + # elif iv.f == 2.0: + # addByte(opConstF2) + # alreadyPut = true of String: if iv.s == "": addByte(opConstS) From 50e1a43e288a5be58add03bb7fe15af83e87b93b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:52:52 +0100 Subject: [PATCH 299/984] properly execute `opConstI1M` & `opConstF1M` + re-order OpCode's --- src/vm/exec.nim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index da67932858..749451429b 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -387,6 +387,7 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = case op: # [0x00-0x1F] # push constants + of opConstI1M : stack.push(I1M) of opConstI0 : stack.push(I0) of opConstI1 : stack.push(I1) of opConstI2 : stack.push(I2) @@ -404,14 +405,11 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opConstI14 : stack.push(I14) of opConstI15 : stack.push(I15) - of opConstI1M : stack.push(I1M) # unused by evaluator - + of opConstF1M : stack.push(F1M) of opConstF0 : stack.push(F0) of opConstF1 : stack.push(F1) of opConstF2 : stack.push(F2) - of opConstF1M : stack.push(F1M) # unused by evaluator - of opConstBT : stack.push(VTRUE) of opConstBF : stack.push(VFALSE) of opConstBM : stack.push(VMAYBE) From efd17ff526e6cee031b9e643795060c39dd90041 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:56:58 +0100 Subject: [PATCH 300/984] re-organize code --- src/vm/eval.nim | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index cf559ada9a..956019a5b4 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -117,6 +117,13 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = var alreadyPut = false let iv {.cursor.} = instruction.value case instruction.value.kind: + of Logical: + if iv.b == True: + addByte(opConstBT) + alreadyPut = true + elif iv.b == False: + addByte(opConstBF) + alreadyPut = true of Integer: if likely(iv.iKind==NormalInteger) and iv.i >= -1 and iv.i <= 15: addByte(byte(opConstI0) + byte(iv.i)) @@ -137,15 +144,6 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = alreadyPut = true else: discard - # if iv.f == 0.0: - # addByte(opConstF0) - # alreadyPut = true - # elif iv.f == 1.0: - # addByte(opConstF1) - # alreadyPut = true - # elif iv.f == 2.0: - # addByte(opConstF2) - # alreadyPut = true of String: if iv.s == "": addByte(opConstS) @@ -154,13 +152,6 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = if iv.a.len == 0: addByte(opConstA) alreadyPut = true - of Logical: - if iv.b == True: - addByte(opConstBT) - alreadyPut = true - elif iv.b == False: - addByte(opConstBF) - alreadyPut = true else: discard From f69cac55c775b5e3a5f7e1c821de0fb5c4f0905c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:57:16 +0100 Subject: [PATCH 301/984] added support for empty Dictionary values --- src/vm/eval.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 956019a5b4..c5eba2c143 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -152,6 +152,10 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = if iv.a.len == 0: addByte(opConstA) alreadyPut = true + of Dictionary: + if iv.d.len == 0: + addByte(opConstD) + alreadyPut = true else: discard From d3d664d17832a068e44d476ea3df43533c2dcc1f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 11:59:58 +0100 Subject: [PATCH 302/984] process stores according to what we're currently handling & generate `opDStore` if we are in a dictionary block --- src/vm/eval.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index c5eba2c143..732847ea17 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -164,7 +164,10 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = of VariableLoad: addConst(instruction.value, opLoad) of VariableStore: - addConst(instruction.value, opStore) + if unlikely(isDictionary): + addConst(instruction.value, opDStore) + else: + addConst(instruction.value, opStore) of OtherCall: addConst(instruction.value, opCall) of BuiltinCall: From a8dc7960735446dbdec96de0c6e5d0857992ec19 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:00:23 +0100 Subject: [PATCH 303/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 02c26ff1cf..4b1f6b94d6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3675 \ No newline at end of file +3676 \ No newline at end of file From 7c207824fdb2a482773185717165eacb628f68fa Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:17:08 +0100 Subject: [PATCH 304/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4b1f6b94d6..a20a999f81 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3676 \ No newline at end of file +3677 \ No newline at end of file From 745ba6ff5301bee926dfa02e4d8cb794febdfd5f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:25:43 +0100 Subject: [PATCH 305/984] VM/eval: make `addConst` work with simple, non-shortcut constants (e.g. `opDStore`) & fix dictionary handling --- src/vm/eval.nim | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 732847ea17..697d9c833c 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -50,7 +50,7 @@ template addToInstructions(b: untyped):untyped {.dirty.} = else: instructions.add(b) -proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode) {.inline,enforceNoRaises.} = +proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode, withShortcut: static bool=true) {.inline,enforceNoRaises.} = var indx = consts.indexOfValue(v) if indx == -1: let newv = v @@ -58,15 +58,21 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O consts.add(newv) indx = consts.len-1 - if indx <= 13: - addToInstructions((byte(op)-0x0E) + byte(indx)) + if indx > 255: + addToInstructions([ + byte(indx), + byte(indx shr 8), + byte(op)+1 + ]) else: - if indx>255: - addToInstructions([ - byte(indx), - byte(indx shr 8), - byte(op)+1 - ]) + when withShortcut: + if indx <= 13: + addToInstructions((byte(op)-0x0E) + byte(indx)) + else: + addToInstructions([ + byte(indx), + byte(op) + ]) else: addToInstructions([ byte(indx), @@ -88,8 +94,8 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = # Shortcuts #------------------------ - template addConst(v: Value, op: OpCode): untyped = - addConst(consts, it, v, op) + template addConst(v: Value, op: OpCode, withShortcut: static bool=true): untyped = + addConst(consts, it, v, op, withShortcut) template addByte(b: untyped): untyped = when b is OpCode: @@ -165,7 +171,7 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = addConst(instruction.value, opLoad) of VariableStore: if unlikely(isDictionary): - addConst(instruction.value, opDStore) + addConst(instruction.value, opDStore, withShortcut=false) else: addConst(instruction.value, opStore) of OtherCall: From 19eb16b3d652da80c560a98c6d7b8cabdc8f1b24 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:26:20 +0100 Subject: [PATCH 306/984] VM/values/printable: [dump] added proper support for `opDStore` & `opDStoreX` --- src/vm/values/printable.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index b2c8fbcee8..d93945247e 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -397,10 +397,10 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen while j < v.trans.instructions.len: let op = OpCode(v.trans.instructions[j]) instrs.add(newWord(stringify((OpCode(op))))) - if op in {opPush, opStore, opCall, opLoad, opStorl, opAttr, opEol}: + if op in {opPush, opStore, opDStore, opCall, opLoad, opStorl, opAttr, opEol}: j += 1 instrs.add(newInteger(int(v.trans.instructions[j]))) - elif op in {opPushX, opStoreX, opCallX, opLoadX, opStorlX, opEolX, opJmpIf, opJmpIfNot, opJmpIfEq, opJmpIfNe, opJmpIfGt, opJmpIfGe, opJmpIfLt, opJmpIfLe, opGoto, opGoup}: + elif op in {opPushX, opStoreX, opDStore, opCallX, opLoadX, opStorlX, opEolX, opJmpIf, opJmpIfNot, opJmpIfEq, opJmpIfNe, opJmpIfGt, opJmpIfGe, opJmpIfLt, opJmpIfLe, opGoto, opGoup}: j += 2 instrs.add(newInteger(int(uint16(v.trans.instructions[j-1]) shl 8 + byte(v.trans.instructions[j])))) From d20921c98ac76ed35c74c097a2bfe477fe254ce3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:26:25 +0100 Subject: [PATCH 307/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a20a999f81..a25fcc09f3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3677 \ No newline at end of file +3678 \ No newline at end of file From 6a9b9fa51e9ee11f94ea9371160a5defeb1a309c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:28:26 +0100 Subject: [PATCH 308/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a25fcc09f3..fe39aa1bc6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3678 \ No newline at end of file +3679 \ No newline at end of file From 06999de9fd446f866bf262066410be0127d2a307 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:28:36 +0100 Subject: [PATCH 309/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index fe39aa1bc6..48eaa2f2e4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3679 \ No newline at end of file +3680 \ No newline at end of file From dadd07150d2e1d7fb6d7c11601f9b0220fb84a6f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:29:22 +0100 Subject: [PATCH 310/984] VM/eval: [addConst] we don't have to add the bytes in reverse code anymore (!!) --- src/vm/eval.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 697d9c833c..d7a7eb1f52 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -60,9 +60,9 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O if indx > 255: addToInstructions([ - byte(indx), + byte(op)+1, byte(indx shr 8), - byte(op)+1 + byte(indx) ]) else: when withShortcut: @@ -70,13 +70,13 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O addToInstructions((byte(op)-0x0E) + byte(indx)) else: addToInstructions([ - byte(indx), - byte(op) + byte(op), + byte(indx) ]) else: addToInstructions([ - byte(indx), - byte(op) + byte(op), + byte(indx) ]) #======================================= From 1e42ab1894aaaeaa2a6c96e9428eb31ecd4d7092 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:36:18 +0100 Subject: [PATCH 311/984] VM/eval: added support for Null values --- src/vm/eval.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index d7a7eb1f52..7dd45e0b72 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -123,6 +123,9 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = var alreadyPut = false let iv {.cursor.} = instruction.value case instruction.value.kind: + of Null: + addByte(opConstN) + alreadyPut = true of Logical: if iv.b == True: addByte(opConstBT) From 12d926abefaba15f6c37a2cc69d6bf6de867eb65 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:48:15 +0100 Subject: [PATCH 312/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 48eaa2f2e4..3d3c79718a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3680 \ No newline at end of file +3681 \ No newline at end of file From 951615db426af0cdd1744dd353c9257c82dd5509 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:50:36 +0100 Subject: [PATCH 313/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3d3c79718a..40ab85b35d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3681 \ No newline at end of file +3682 \ No newline at end of file From 0de0c5ed02c3c27731ff70f21385f6793dd80e86 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:53:04 +0100 Subject: [PATCH 314/984] added initial support for Attribute values (buggy!) --- src/vm/ast.nim | 19 +++++++++++++++++++ src/vm/eval.nim | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index ab882d9557..5bb1aaf169 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -40,6 +40,9 @@ type ConstantValue # Terminal node of the AST containing a value VariableLoad # Load a variable + # Attributes + AttributeNode # Either an Attribute or an AttributeLabel + # CallNode VariableStore # Store a variable @@ -552,6 +555,19 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b of Label, PathLabel: current.addStore(item) + of Attribute: + let attrNode = Node( + kind: AttributeNode, + arity: 1, + value: item + ) + attrNode.addChild(newTerminalNode(ConstantValue, VTRUE)) + + current.addChild(attrNode) + + # of AttributeLabel: + # current.addAttributeLabel(item) + of Inline: current.addInline(item) @@ -637,6 +653,9 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false): string = for child in node.children: result &= dumpNode(child, level+1) + else: + discard + result &= "\n" #======================================= diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 7dd45e0b72..20094590b6 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -172,6 +172,8 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = addConst(instruction.value, opPush) of VariableLoad: addConst(instruction.value, opLoad) + of AttributeNode: + addConst(instruction.value, opAttr) of VariableStore: if unlikely(isDictionary): addConst(instruction.value, opDStore, withShortcut=false) From 51602dcd79fdd8b28517ae80a707f0cafcdb6777 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 12:58:58 +0100 Subject: [PATCH 315/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 40ab85b35d..13a6413588 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3682 \ No newline at end of file +3683 \ No newline at end of file From 58692954e9812e3749714ba219de0f6eb33dfe84 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 13:01:57 +0100 Subject: [PATCH 316/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 13a6413588..70d6870c0c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3683 \ No newline at end of file +3684 \ No newline at end of file From 3c7b56cc7ec80061c4dab02a1854f37a72a66020 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 13:04:55 +0100 Subject: [PATCH 317/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 70d6870c0c..8c1a415f0a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3684 \ No newline at end of file +3685 \ No newline at end of file From 71b2d39bbb4114c9b73b2fbfe3652140995eaa2e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 13:13:31 +0100 Subject: [PATCH 318/984] Attributes are working! --- src/vm/ast.nim | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 5bb1aaf169..e5f159d228 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -40,10 +40,8 @@ type ConstantValue # Terminal node of the AST containing a value VariableLoad # Load a variable - # Attributes - AttributeNode # Either an Attribute or an AttributeLabel - # CallNode + AttributeNode # Either an Attribute or an AttributeLabel VariableStore # Store a variable OtherCall # Call to a function that is not a builtin @@ -59,6 +57,7 @@ type else: op*: OpCode arity*: int8 + params*: int8 value*: Value parent*: Node @@ -87,7 +86,7 @@ var const TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} - CallNode : set[NodeKind] = {VariableStore..SpecialCall} + CallNode : set[NodeKind] = {AttributeNode..SpecialCall} #======================================= # Forward declarations @@ -111,6 +110,8 @@ func setOnlyChild(node: Node, child: Node) {.enforceNoRaises.} = func addChild*(node: Node, child: Node) {.enforceNoRaises.} = child.parent = node node.children.add(child) + if node.kind in CallNode and child.kind != AttributeNode: + node.params += 1 func addChildren*(node: Node, children: NodeArray) {.enforceNoRaises.} = for child in children: @@ -313,7 +314,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b #------------------------ template rewindCallBranches(target: var Node, optimize: bool = false): untyped = - while target.kind in CallNode and target.children.len == target.arity: + while target.kind in CallNode and target.params == target.arity: when optimize: case target.op: of opAdd : target.optimizeAdd() @@ -565,8 +566,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b current.addChild(attrNode) - # of AttributeLabel: - # current.addAttributeLabel(item) + of AttributeLabel: + current.addChild(newCallNode(AttributeNode, 1, item)) + current = current.children[^1] of Inline: current.addInline(item) From 8ea4988880e4f87d486e431a62085829884c7142 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 13:18:13 +0100 Subject: [PATCH 319/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8c1a415f0a..92c70345c7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3685 \ No newline at end of file +3686 \ No newline at end of file From 20ac681278942bd4ef79831cfa20161a81570835 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 13:24:01 +0100 Subject: [PATCH 320/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 92c70345c7..9c48385083 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3686 \ No newline at end of file +3687 \ No newline at end of file From b5693927ef7e317f7b2b99b2e8b95694789adb7a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 13:24:53 +0100 Subject: [PATCH 321/984] VM/ast: cleanup of Attributes' handling --- src/vm/ast.nim | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index e5f159d228..4c625b73cb 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -419,6 +419,17 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target = target.children[^1] + proc addAttribute(target: var Node, val: Value, isLabel: static bool = false) {.enforceNoRaises.} = + let attrNode = newCallNode(AttributeNode, 1, val) + + when not isLabel: + attrNode.addChild(newTerminalNode(ConstantValue, VTRUE)) + + target.addChild(attrNode) + + when isLabel: + target = target.children[^1] + template addPotentialInfixCall(target: var Node): untyped = if i < nLen - 1: let nextNode {.cursor.} = blok.a[i+1] @@ -557,18 +568,10 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b current.addStore(item) of Attribute: - let attrNode = Node( - kind: AttributeNode, - arity: 1, - value: item - ) - attrNode.addChild(newTerminalNode(ConstantValue, VTRUE)) - - current.addChild(attrNode) + current.addAttribute(item) of AttributeLabel: - current.addChild(newCallNode(AttributeNode, 1, item)) - current = current.children[^1] + current.addAttribute(item, isLabel=true) of Inline: current.addInline(item) From e6129558a759f67fe66167e9304d2a35ccde6ce3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 13:25:23 +0100 Subject: [PATCH 322/984] VM/ast: [dumpNode] `else` not needed (all cases have already been covered) --- src/vm/ast.nim | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 4c625b73cb..b4b8326efd 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -658,9 +658,6 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false): string = for child in node.children: result &= dumpNode(child, level+1) - else: - discard - result &= "\n" #======================================= From fb84c798c6df5ba7246443cc5875e5e2185c577f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 13:25:26 +0100 Subject: [PATCH 323/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9c48385083..edabefba4e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3687 \ No newline at end of file +3688 \ No newline at end of file From 376526aeaa49dc146ce0e94663d1d92869fc2a3f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:02:06 +0100 Subject: [PATCH 324/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index edabefba4e..5bbbe64e4c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3688 \ No newline at end of file +3689 \ No newline at end of file From 3fd02e9a627ee01a66d07ca2f5d5c00aa2832020 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:03:12 +0100 Subject: [PATCH 325/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5bbbe64e4c..bddcd008e2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3689 \ No newline at end of file +3690 \ No newline at end of file From 97eb04906961e6023e94a64dced9e8e7ac5a2224 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:04:07 +0100 Subject: [PATCH 326/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bddcd008e2..2ea0ae7ecb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3690 \ No newline at end of file +3691 \ No newline at end of file From c30002fc1e7574d5fcd1e465c998f2baaae32f65 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:09:02 +0100 Subject: [PATCH 327/984] added initial support for Path values (what a complicated mess I'm putting myself through, geez! lol) --- src/vm/ast.nim | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index b4b8326efd..f7994f2ae0 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -15,6 +15,15 @@ ## ## The main entry point is ``generateAst``. + +# TODO: +# - make Path's & PathLabel's work +# - make Newline values work +# - create new opCode for append +# - optimize appends +# - make labels store new functions in TmpArities +# - make if/if?/else/while/switch work + #======================================= # Libraries #======================================= @@ -453,6 +462,109 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b rewindCallBranches(optimize=true) + proc addPath(target: var Node, val: Value) = + var pathCallV: Value = nil + + if (let curr = Syms.getOrDefault(val.p[0].s, nil); not curr.isNil): + let next {.cursor.} = val.p[1] + if curr.kind==Dictionary and (next.kind==Literal or next.kind==Word): + if (let item = curr.d.getOrDefault(next.s, nil); not item.isNil): + if item.kind == Function: + pathCallV = item + + if not pathCallV.isNil: + target.addChild( + Node( + kind: OtherCall, + arity: pathCallV.arity, + op: opNop, + value: pathCallV + ) + ) + target = target.children[^1] + # addConst(pathCallV, opCall) + # argStack.add(pathCallV.arity) + else: + + # get a/b/c + + # get + # get + # load a + # b + # c + var baseNode: Node + + let basePath {.cursor.} = val.p[0] + + if TmpArities.getOrDefault(basePath.s, -1) == 0: + baseNode = newCallNode( + OtherCall, + 0, + basePath + ) + else: + baseNode = newTerminalNode( + VariableLoad, + basePath + ) + + var i = 1 + + while i < val.p.len: + let newNode = newCallNode( + BuiltinCall, + 2, + nil, + opGet + ) + newNode.addChild(baseNode) + newNode.addChild(newTerminalNode( + ConstantValue, + val.p[i] + )) + baseNode = newNode + i += 1 + + with target: + rewindCallBranches() + + addPotentialInfixCall() + + addChild(baseNode) + + rewindCallBranches(optimize=true) + + # addTerminalValue(inBlock=false): + # addToCommand(opGet) + + # var i=1 + # while i=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) + # else: addConst(node.p[i], opPush) + # else: + # addConst(node.p[i], opPush) + # else: + # addConst(node.p[i], opPush) + # i += 1 + template addPotentialTrailingPipe(target: var Node): untyped = var added = false if i < nLen - 1: @@ -573,6 +685,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b of AttributeLabel: current.addAttribute(item, isLabel=true) + of Path: + current.addPath(item) + of Inline: current.addInline(item) From e7e267b44cfee4d1d691b3e26423f70dc9f05667 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:12:04 +0100 Subject: [PATCH 328/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2ea0ae7ecb..2f870342c7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3691 \ No newline at end of file +3692 \ No newline at end of file From ebf6fefa704d5653ede21e828e4c8ec3ccfce149 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:14:59 +0100 Subject: [PATCH 329/984] VM/ast: added Block support for Path values (e.g. arr/[someIndex+1]/2) --- src/vm/ast.nim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index f7994f2ae0..668c57a771 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -519,10 +519,15 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b opGet ) newNode.addChild(baseNode) - newNode.addChild(newTerminalNode( - ConstantValue, - val.p[i] - )) + if val.p[i].kind==Block: + var subNode = newRootNode() + discard subNode.processBlock(val.p[i]) + newNode.addChildren(subNode.children) + else: + newNode.addChild(newTerminalNode( + ConstantValue, + val.p[i] + )) baseNode = newNode i += 1 From ee7804e1849e40b6eea27beb7669011f4516c630 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:18:10 +0100 Subject: [PATCH 330/984] VM/ast: added `newConstant` & `newVariable` constructor helpers --- src/vm/ast.nim | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 668c57a771..06d81bcffc 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -191,6 +191,12 @@ template newTerminalNode(kn: NodeKind, va: Value): Node = value: va ) +template newConstant(v: Value): Node = + newTerminalNode(ConstantValue, v) + +template newVariable(v: Value): Node = + newTerminalNode(VariableLoad, v) + template newCallNode(kn: NodeKind, ar: int8, va: Value, oper: OpCode = opNop): Node = Node( kind: kn, @@ -539,36 +545,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b addChild(baseNode) rewindCallBranches(optimize=true) - - # addTerminalValue(inBlock=false): - # addToCommand(opGet) - - # var i=1 - # while i=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) - # else: addConst(node.p[i], opPush) - # else: - # addConst(node.p[i], opPush) - # else: - # addConst(node.p[i], opPush) - # i += 1 template addPotentialTrailingPipe(target: var Node): untyped = var added = false From ad2e17bfba0babc3a76c572993a1fe2a45e9a971 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:23:58 +0100 Subject: [PATCH 331/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2f870342c7..ae233d92b6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3692 \ No newline at end of file +3693 \ No newline at end of file From 2d1e1018595671035b12a5bf55e07d20f7cb2cba Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:30:39 +0100 Subject: [PATCH 332/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ae233d92b6..98d0be4a48 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3693 \ No newline at end of file +3694 \ No newline at end of file From 9a6f6f3bde86db447f03ac65cc12b11e35d0ecc2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:31:59 +0100 Subject: [PATCH 333/984] VM/ast: general cleanup + added `rollThrough` helper + make use of `addConstant` & `addVariable` where appropriate --- src/vm/ast.nim | 118 ++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 76 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 06d81bcffc..8ea4a06894 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -226,7 +226,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if left.kind == ConstantValue and left.value.kind in {Integer, Floating}: # Constant folding if right.kind == ConstantValue and right.value.kind in {Integer, Floating}: - target.replaceNode(newTerminalNode(ConstantValue, left.value + right.value)) + target.replaceNode(newConstant(left.value + right.value)) # Convert 1 + X -> inc X elif left.value == I1: target.op = opInc @@ -245,14 +245,14 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if right.children[0].kind == VariableLoad and right.children[0].value == left.value: target.op = opMul if right.children[1].kind == ConstantValue and right.children[1].value.kind in {Integer, Floating}: - right.replaceNode(newTerminalNode(ConstantValue, right.children[1].value + I1)) + right.replaceNode(newConstant(right.children[1].value + I1)) else: right.op = opAdd right.children[0].value = newInteger(1) elif right.children[1].kind == VariableLoad and right.children[1].value == left.value: target.op = opMul if right.children[0].kind == ConstantValue and right.children[0].value.kind in {Integer, Floating}: - right.replaceNode(newTerminalNode(ConstantValue, right.children[0].value + I1)) + right.replaceNode(newConstant(right.children[0].value + I1)) else: right.op = opAdd right.children[1].value = newInteger(1) @@ -263,14 +263,14 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if left.children[0].kind == VariableLoad and left.children[0].value == right.value: target.op = opMul if left.children[1].kind == ConstantValue and left.children[1].value.kind in {Integer, Floating}: - left.replaceNode(newTerminalNode(ConstantValue, left.children[1].value + I1)) + left.replaceNode(newConstant(left.children[1].value + I1)) else: left.op = opAdd left.children[0].value = newInteger(1) elif left.children[1].kind == VariableLoad and left.children[1].value == right.value: target.op = opMul if left.children[0].kind == ConstantValue and left.children[0].value.kind in {Integer, Floating}: - left.replaceNode(newTerminalNode(ConstantValue, left.children[0].value + I1)) + left.replaceNode(newConstant(left.children[0].value + I1)) else: left.op = opAdd left.children[1].value = newInteger(1) @@ -281,7 +281,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if left.kind == ConstantValue and right.kind == ConstantValue: # Constant folding - target.replaceNode(newTerminalNode(ConstantValue, left.value - right.value)) + target.replaceNode(newConstant(left.value - right.value)) elif right.kind == ConstantValue and right.value == I1: # Convert X - 1 -> dec X target.op = opDec @@ -293,7 +293,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var right = target.children[1] if left.kind == ConstantValue and right.kind == ConstantValue: - target.replaceNode(newTerminalNode(ConstantValue, op(left.value,right.value))) + target.replaceNode(newConstant(op(left.value,right.value))) proc optimizeUnless(target: var Node) {.enforceNoRaises.} = target.op = @@ -346,6 +346,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target = target.parent + template rollThrough(target: var Node): untyped = + target = target.children[^1] + #------------------------ # AST Generation #------------------------ @@ -427,23 +430,23 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b target.addChild(newCallNode(callType, ar, v, op)) - target = target.children[^1] + target.rollThrough() func addStore(target: var Node, val: Value) {.enforceNoRaises.} = target.addChild(newCallNode(VariableStore, 1, val)) - target = target.children[^1] + target.rollThrough() proc addAttribute(target: var Node, val: Value, isLabel: static bool = false) {.enforceNoRaises.} = let attrNode = newCallNode(AttributeNode, 1, val) when not isLabel: - attrNode.addChild(newTerminalNode(ConstantValue, VTRUE)) + attrNode.addChild(newConstant(VTRUE)) target.addChild(attrNode) when isLabel: - target = target.children[^1] + target.rollThrough() template addPotentialInfixCall(target: var Node): untyped = if i < nLen - 1: @@ -458,13 +461,13 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b i += 1 target.addCall(aliased.name.s, fun=symfunc) - proc addTerminal(target: var Node, val: Value, ofType: NodeKind = ConstantValue) = + proc addTerminal(target: var Node, node: Node) = with target: rewindCallBranches() addPotentialInfixCall() - addChild(newTerminalNode(ofType, val)) + addChild(node) rewindCallBranches(optimize=true) @@ -479,72 +482,35 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b pathCallV = item if not pathCallV.isNil: - target.addChild( - Node( - kind: OtherCall, - arity: pathCallV.arity, - op: opNop, - value: pathCallV - ) - ) - target = target.children[^1] - # addConst(pathCallV, opCall) - # argStack.add(pathCallV.arity) + target.addChild(Node(kind: OtherCall, arity: pathCallV.arity, op: opNop, value: pathCallV)) + target.rollThrough() else: - - # get a/b/c - - # get - # get - # load a - # b - # c - var baseNode: Node - let basePath {.cursor.} = val.p[0] - if TmpArities.getOrDefault(basePath.s, -1) == 0: - baseNode = newCallNode( - OtherCall, - 0, - basePath - ) - else: - baseNode = newTerminalNode( - VariableLoad, - basePath - ) + var baseNode = + if TmpArities.getOrDefault(basePath.s, -1) == 0: + newCallNode(OtherCall, 0, basePath) + else: + newVariable(basePath) var i = 1 while i < val.p.len: - let newNode = newCallNode( - BuiltinCall, - 2, - nil, - opGet - ) + let newNode = newCallNode(BuiltinCall, 2, nil, opGet) + newNode.addChild(baseNode) + if val.p[i].kind==Block: var subNode = newRootNode() discard subNode.processBlock(val.p[i]) newNode.addChildren(subNode.children) else: - newNode.addChild(newTerminalNode( - ConstantValue, - val.p[i] - )) + newNode.addChild(newConstant(val.p[i])) + baseNode = newNode i += 1 - with target: - rewindCallBranches() - - addPotentialInfixCall() - - addChild(baseNode) - - rewindCallBranches(optimize=true) + target.addTerminal(baseNode) template addPotentialTrailingPipe(target: var Node): untyped = var added = false @@ -570,7 +536,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b added = true if not added: - target.addTerminal(newSymbol(pipe)) + target.addTerminal(newConstant(newSymbol(pipe))) proc addInline(target: var Node, val: Value) = var subNode = newRootNode() @@ -589,7 +555,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var subNode = newRootNode() i = subNode.processBlock(val, start=i+1, processingArrow=true) - target.addTerminal(newBlock(ArrowBlock)) + target.addTerminal(newConstant(newBlock(ArrowBlock))) ArrowBlock.setLen(0) @@ -628,11 +594,11 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b idx += 1 if argblock.len == 1: - target.addTerminal(newLiteral(argblock[0].s)) + target.addTerminal(newConstant(newLiteral(argblock[0].s))) else: - target.addTerminal(newBlock(argblock)) + target.addTerminal(newConstant(newBlock(argblock))) - target.addTerminal(newBlock(subblock)) + target.addTerminal(newConstant(newBlock(subblock))) #------------------------ # The Main Loop @@ -651,11 +617,11 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b current.addCall(item.s, funcArity) else: if item.s == "true": - current.addTerminal(VTRUE) + current.addTerminal(newConstant(VTRUE)) elif item.s == "false": - current.addTerminal(VFALSE) + current.addTerminal(newConstant(VFALSE)) else: - current.addTerminal(item, ofType=VariableLoad) + current.addTerminal(newVariable(item)) of Label, PathLabel: current.addStore(item) @@ -681,7 +647,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b subblock.add(blok.a[i]) inc(i) - current.addTerminal(newBlock(subblock)) + current.addTerminal(newConstant(newBlock(subblock))) of arrowright : current.addArrowBlock(blok) @@ -701,17 +667,17 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b current.addCall(aliased.name.s, fun=symfunc) else: if aliased.name.s == "null": - current.addTerminal(VNULL) + current.addTerminal(newConstant(VNULL)) else: - current.addTerminal(newString(aliased.name.s), ofType=VariableLoad) + current.addTerminal(newVariable(newString(aliased.name.s))) else: - current.addTerminal(item) + current.addTerminal(newConstant(item)) of Newline: discard else: - current.addTerminal(item) + current.addTerminal(newConstant(item)) i += 1 From 526e9309a70538ea2f4477606bb6c6d55f289d0b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:40:12 +0100 Subject: [PATCH 334/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 98d0be4a48..509d8ee51d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3694 \ No newline at end of file +3695 \ No newline at end of file From 71f2010f20b4d4282374c5df51c933dde05b923f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:40:25 +0100 Subject: [PATCH 335/984] VM/ast: added support for PathLabel values --- src/vm/ast.nim | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 8ea4a06894..a6b13a7355 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -471,15 +471,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b rewindCallBranches(optimize=true) - proc addPath(target: var Node, val: Value) = + proc addPath(target: var Node, val: Value, isLabel: static bool=false) = var pathCallV: Value = nil - if (let curr = Syms.getOrDefault(val.p[0].s, nil); not curr.isNil): - let next {.cursor.} = val.p[1] - if curr.kind==Dictionary and (next.kind==Literal or next.kind==Word): - if (let item = curr.d.getOrDefault(next.s, nil); not item.isNil): - if item.kind == Function: - pathCallV = item + when not isLabel: + if (let curr = Syms.getOrDefault(val.p[0].s, nil); not curr.isNil): + let next {.cursor.} = val.p[1] + if curr.kind==Dictionary and (next.kind==Literal or next.kind==Word): + if (let item = curr.d.getOrDefault(next.s, nil); not item.isNil): + if item.kind == Function: + pathCallV = item if not pathCallV.isNil: target.addChild(Node(kind: OtherCall, arity: pathCallV.arity, op: opNop, value: pathCallV)) @@ -487,16 +488,26 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b else: let basePath {.cursor.} = val.p[0] - var baseNode = - if TmpArities.getOrDefault(basePath.s, -1) == 0: - newCallNode(OtherCall, 0, basePath) - else: - newVariable(basePath) + when isLabel: + var baseNode = newVariable(basePath) + else: + var baseNode = + if TmpArities.getOrDefault(basePath.s, -1) == 0: + newCallNode(OtherCall, 0, basePath) + else: + newVariable(basePath) var i = 1 while i < val.p.len: - let newNode = newCallNode(BuiltinCall, 2, nil, opGet) + when isLabel: + let newNode = + if i == val.p.len - 1: + newCallNode(BuiltinCall, 2, nil, opSet) + else: + newCallNode(BuiltinCall, 2, nil, opGet) + else: + let newNode = newCallNode(BuiltinCall, 2, nil, opGet) newNode.addChild(baseNode) @@ -510,7 +521,11 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b baseNode = newNode i += 1 - target.addTerminal(baseNode) + when isLabel: + target.addChild(baseNode) + target.rollThrough() + else: + target.addTerminal(baseNode) template addPotentialTrailingPipe(target: var Node): untyped = var added = false @@ -623,7 +638,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b else: current.addTerminal(newVariable(item)) - of Label, PathLabel: + of Label: current.addStore(item) of Attribute: @@ -635,6 +650,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b of Path: current.addPath(item) + of PathLabel: + current.addPath(item, isLabel=true) + of Inline: current.addInline(item) From 238bad692d05bcb98bc15f45cbf9ce69d49c8510 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:41:22 +0100 Subject: [PATCH 336/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 509d8ee51d..5121b2effd 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3695 \ No newline at end of file +3696 \ No newline at end of file From d197f4a8f47795fbba95233bbe3a247cce6c4133 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:41:34 +0100 Subject: [PATCH 337/984] updated inline TODOs --- src/vm/ast.nim | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index a6b13a7355..2e507b863a 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -17,12 +17,15 @@ # TODO: -# - make Path's & PathLabel's work -# - make Newline values work -# - create new opCode for append -# - optimize appends -# - make labels store new functions in TmpArities -# - make if/if?/else/while/switch work +# - [x] make Attribute's work +# - [x] make AttributeLabel's work +# - [x] make Path's work +# - [x] make PathLabel's work +# - [ ] make Newline values work +# - [ ] create new opCode for append +# - [ ] optimize appends +# - [ ] make labels store new functions in TmpArities +# - [ ] make if/if?/else/while/switch work #======================================= # Libraries From b147161cc035bc5ca2a3f9e1fc749ff0047f74b5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:43:30 +0100 Subject: [PATCH 338/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5121b2effd..4ca6162ed2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3696 \ No newline at end of file +3697 \ No newline at end of file From de27b7de5db2298825aeffdc633b3ce5947e5f87 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 14:44:32 +0100 Subject: [PATCH 339/984] minor fix (`opSet` takes 3 params; not 2!) --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 2e507b863a..bfb3860538 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -506,7 +506,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b when isLabel: let newNode = if i == val.p.len - 1: - newCallNode(BuiltinCall, 2, nil, opSet) + newCallNode(BuiltinCall, 3, nil, opSet) else: newCallNode(BuiltinCall, 2, nil, opGet) else: From 741126c9af87e43dafc581dff38092cd0d19f632 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:21:13 +0100 Subject: [PATCH 340/984] VM/opcodes: re-organized + added new opCodes: `opAppend`, `opUnlessE`, `opBreak` & `opContinue` --- src/vm/opcodes.nim | 136 +++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 66 deletions(-) diff --git a/src/vm/opcodes.nim b/src/vm/opcodes.nim index 5cb0c1f446..603e5e869f 100644 --- a/src/vm/opcodes.nim +++ b/src/vm/opcodes.nim @@ -209,88 +209,92 @@ type opNeg = 0x87 # () # x # result + # increment/decrement + opInc = 0x88 # () # value # result + opDec = 0x89 # () # value # result + # binary operators - opBNot = 0x88 # () # x # result - opBAnd = 0x89 # () # x,y # result - opBOr = 0x8A # () # x,y # result + opBNot = 0x8A # () # x # result + opBAnd = 0x8B # () # x,y # result + opBOr = 0x8C # () # x,y # result - opShl = 0x8B # () # x,y # result - opShr = 0x8C # () # x,y # result + opShl = 0x8D # () # x,y # result + opShr = 0x8E # () # x,y # result - # logical operators - opNot = 0x8D # () # x # result - opAnd = 0x8E # () # x,y # result - opOr = 0x8F # () # x,y # result + RSRV1 = 0x8F # # [0x90-0x9F] + # logical operators + opNot = 0x90 # () # x # result + opAnd = 0x91 # () # x,y # result + opOr = 0x92 # () # x,y # result + # comparison operators - opEq = 0x90 # () # x,y # result - opNe = 0x91 # () # x,y # result - opGt = 0x92 # () # x,y # result - opGe = 0x93 # () # x,y # result - opLt = 0x94 # () # x,y # result - opLe = 0x95 # () # x,y # result + opEq = 0x93 # () # x,y # result + opNe = 0x94 # () # x,y # result + opGt = 0x95 # () # x,y # result + opGe = 0x96 # () # x,y # result + opLt = 0x97 # () # x,y # result + opLe = 0x98 # () # x,y # result - # branching - opIf = 0x96 # () # cond,bl # X - opIfE = 0x97 # () # cond,bl # cond - opUnless = 0x98 # () # cond,bl # X - opElse = 0x99 # () # success # X - opSwitch = 0x9A # () # cond,a,b # X - opWhile = 0x9B # () # cond,bl # X - opReturn = 0x9C # () # value # + # getters/setters + opGet = 0x99 # () # obj,key # result + opSet = 0x9A # () # obj,key,rvalue # - # converters - opTo = 0x9D # () # tp,value # result - opToS = 0x9E # () # value # result - opToI = 0x9F # () # value # result + RSRV2 = 0x9B # + RSRV3 = 0x9C # + RSRV4 = 0x9D # + RSRV5 = 0x9E # + RSRV6 = 0x9F # # [0xA0-0xAF] - # getters/setters - opGet = 0xA0 # () # obj,key # result - opSet = 0xA1 # () # obj,key,rvalue # + # branching + opIf = 0xA0 # () # cond,bl # X + opIfE = 0xA1 # () # cond,bl # cond + opUnless = 0xA2 # () # cond,bl # X + opUnlessE = 0xA3 # () # cond,bl # cond + opElse = 0xA4 # () # success # X + opSwitch = 0xA5 # () # cond,a,b # X + opWhile = 0xA6 # () # cond,bl # X + + opReturn = 0xA7 # () # value # + opBreak = 0xA8 # () # # + opContinue = 0xA9 # () # # + + # converters + opTo = 0xAA # () # tp,value # result + opToS = 0xAB # () # value # result + opToI = 0xAC # () # value # result # generators - opArray = 0xA2 # () # blk # result - opDict = 0xA3 # () # blk # result - opFunc = 0xA4 # () # params,blk # result + opArray = 0xAD # () # blk # result + opDict = 0xAE # () # blk # result + opFunc = 0xAF # () # params,blk # result + # [0xB0-0xBF] # ranges & iterators - opRange = 0xA5 # () # start,stop # result - opLoop = 0xA6 # () # range,param,blk # X - opMap = 0xA7 # () # range,param,blk # result - opSelect = 0xA8 # () # range,param,blk # result + opRange = 0xB0 # () # start,stop # result + opLoop = 0xB1 # () # range,param,blk # X + opMap = 0xB2 # () # range,param,blk # result + opSelect = 0xB3 # () # range,param,blk # result # collections - opSize = 0xA9 # () # obj # result - opReplace = 0xAA # () # obj,what,with # result - opSplit = 0xAB # () # obj,what # result - opJoin = 0xAC # () # obj # result - opReverse = 0xAD # () # blk # result - - # increment/decrement - opInc = 0xAE # () # value # result - opDec = 0xAF # () # value # result + opSize = 0xB4 # () # obj # result + opReplace = 0xB5 # () # obj,what,with # result + opSplit = 0xB6 # () # obj,what # result + opJoin = 0xB7 # () # obj # result + opReverse = 0xB8 # () # blk # result + opAppend = 0xB9 # () # x,y # result # [0xB0-0xBF] # i/o operations - opPrint = 0xB0 # () # value # - - RSRV1 = 0xB1 # - RSRV2 = 0xB2 # - RSRV3 = 0xB3 # - RSRV4 = 0xB4 # - RSRV5 = 0xB5 # - RSRV6 = 0xB6 # - RSRV7 = 0xB7 # - RSRV8 = 0xB8 # - RSRV9 = 0xB9 # - RSRV10 = 0xBA # - RSRV11 = 0xBB # - RSRV12 = 0xBC # - RSRV13 = 0xBD # - RSRV14 = 0xBE # - RSRV15 = 0xBF # + opPrint = 0xBA # () # value # + + RSRV7 = 0xBB # + RSRV8 = 0xBC # + RSRV9 = 0xBD # + RSRV10 = 0xBE # + RSRV11 = 0xBF # #--------------------------------- # LOW-LEVEL OPERATIONS @@ -316,9 +320,9 @@ type opJmpIfLt = 0xCB # (idx,idxB) # cond # opJmpIfLe = 0xCC # (idx,idxB) # cond # - RSRV16 = 0xCD # - RSRV17 = 0xCE # - RSRV18 = 0xCF # + RSRV12 = 0xCD # + RSRV13 = 0xCE # + RSRV14 = 0xCF # # flow control opGoto = 0xD0 # (idx,idxB) # # From 0d75ad35875499e3d0a41ee9818e0820a64b25d9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:25:55 +0100 Subject: [PATCH 341/984] VM/values/value: added missing global Function pointers & re-organized --- src/vm/values/value.nim | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index 5d42ed8084..64f32cb55d 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -116,18 +116,19 @@ var TypeLookup = initOrderedTable[string,Value]() # global implementation references - AddF*, SubF*, MulF*, DivF*, FdivF*, ModF*, PowF* : Value - NegF*, BNotF*, BAndF*, BOrF*, ShlF*, ShrF* : Value - NotF*, AndF*, OrF* : Value - EqF*, NeF*, GtF*, GeF*, LtF*, LeF* : Value - IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF* : Value - WhileF*, ReturnF* : Value - ToF*, PrintF* : Value - GetF*, SetF* : Value - ArrayF*, DictF*, FuncF* : Value - RangeF*, LoopF*, MapF*, SelectF* : Value - SizeF*, ReplaceF*, SplitF*, JoinF*, ReverseF* : Value - IncF*, DecF* : Value + AddF*, SubF*, MulF*, DivF*, FdivF*, ModF*, PowF* : Value + NegF*, IncF*, DecF* : Value + BNotF*, BAndF*, BOrF*, ShlF*, ShrF* : Value + NotF*, AndF*, OrF* : Value + EqF*, NeF*, GtF*, GeF*, LtF*, LeF* : Value + GetF*, SetF* : Value + IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF*, WhileF* : Value + ReturnF*, BreakF*, ContinueF* : Value + ToF* : Value + ArrayF*, DictF*, FuncF* : Value + RangeF*, LoopF*, MapF*, SelectF* : Value + SizeF*, ReplaceF*, SplitF*, JoinF*, ReverseF*, AppendF* : Value + PrintF* : Value #======================================= # Forward Declarations From 6ce4c7a60565923b9d23926a702605bbefda3341 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:27:25 +0100 Subject: [PATCH 342/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4ca6162ed2..7f6931a12e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3697 \ No newline at end of file +3698 \ No newline at end of file From eb41032b84bb32e5588ff4e49be9f701aeab9cc9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:33:14 +0100 Subject: [PATCH 343/984] VM/exec: added missing OpCodes + re-organized --- src/vm/exec.nim | 50 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index 749451429b..b0cf79f90e 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -569,6 +569,10 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opNeg : NegF.action()() + # increment/decrement + of opInc : IncF.action()() + of opDec : DecF.action()() + # binary operators of opBNot : BNotF.action()() of opBAnd : BAndF.action()() @@ -577,12 +581,14 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opShl : ShlF.action()() of opShr : ShrF.action()() + of RSRV1 : discard + + # [0x90-0x9F] # logical operators of opNot : NotF.action()() of opAnd : AndF.action()() of opOr : OrF.action()() - # [0x90-0x9F] # comparison operators of opEq : EqF.action()() of opNe : NeF.action()() @@ -591,6 +597,17 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opLt : LtF.action()() of opLe : LeF.action()() + # getters/setters + of opGet : GetF.action()() + of opSet : SetF.action()() + + of RSRV2 : discard + of RSRV3 : discard + of RSRV4 : discard + of RSRV5 : discard + of RSRV6 : discard + + # [0xA0-0xAF] # branching of opIf : IfF.action()() of opIfE : IfEF.action()() @@ -598,7 +615,10 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opElse : ElseF.action()() of opSwitch : SwitchF.action()() of opWhile : WhileF.action()() + of opReturn : ReturnF.action()() + of opBreak : BreakF.action()() + of opContinue : ContinueF.action()() # converters of opTo : ToF.action()() @@ -609,16 +629,12 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = stack.push(VINTEGERT) ToF.action()() - # [0xA0-0xAF] - # getters/setters - of opGet : GetF.action()() - of opSet : SetF.action()() - # generators of opArray : ArrayF.action()() of opDict : DictF.action()() of opFunc : FuncF.action()() + # [0xB0-0xBF] # ranges & iterators of opRange : RangeF.action()() of opLoop : LoopF.action()() @@ -631,30 +647,16 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opSplit : SplitF.action()() of opJoin : JoinF.action()() of opReverse : ReverseF.action()() + of opAppend : AppendF.action()() - # increment/decrement - of opInc : IncF.action()() - of opDec : DecF.action()() - - # [0xB0-0xBF] # i/o operations of opPrint : PrintF.action()() - of RSRV1 : discard - of RSRV2 : discard - of RSRV3 : discard - of RSRV4 : discard - of RSRV5 : discard - of RSRV6 : discard of RSRV7 : discard of RSRV8 : discard of RSRV9 : discard of RSRV10 : discard of RSRV11 : discard - of RSRV12 : discard - of RSRV13 : discard - of RSRV14 : discard - of RSRV15 : discard #--------------------------------- # LOW-LEVEL OPERATIONS @@ -690,9 +692,9 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opJmpIfLt : performConditionalJump(`<`) of opJmpIfLe : performConditionalJump(`<=`) - of RSRV16 : discard - of RSRV17 : discard - of RSRV18 : discard + of RSRV12 : discard + of RSRV13 : discard + of RSRV14 : discard # flow control of opGoto : From 07ca6f9e9ed19dbbaf89d70215fa89d9c651f81b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:33:23 +0100 Subject: [PATCH 344/984] VM/lib: minor experiment --- src/vm/lib.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index 40ac669051..dfc660946f 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -97,6 +97,10 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: SetSym(n, b) + static: + case n: + of "array": ArrayF = b + when n=="array" : ArrayF = b elif n=="dictionary" : DictF = b elif n=="function" : FuncF = b From d1308fd6ccf5d4897feeaf69d440d050fa8ed20d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:33:26 +0100 Subject: [PATCH 345/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7f6931a12e..1daf631637 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3698 \ No newline at end of file +3699 \ No newline at end of file From 1dc500e4ebd6d6b73ec99857f8f073a983a30820 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:34:14 +0100 Subject: [PATCH 346/984] added missing `opUnlessE` (which is not gonna be needed at all anyway, but oh well...) --- src/vm/exec.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index b0cf79f90e..146f7d8508 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -612,6 +612,7 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opIf : IfF.action()() of opIfE : IfEF.action()() of opUnless : UnlessF.action()() + of opUnlessE : UnlessEF.action()() of opElse : ElseF.action()() of opSwitch : SwitchF.action()() of opWhile : WhileF.action()() From 8324504a5a886ff6450f19955a40fa264ffe0f80 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:34:17 +0100 Subject: [PATCH 347/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1daf631637..b204796ff6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3699 \ No newline at end of file +3700 \ No newline at end of file From 16e3b994ed4e6e2067e9fe217277a5c776991da7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:38:12 +0100 Subject: [PATCH 348/984] VM/lib: re-organized global built-in assignments + added missing ones (`BreakF`, `ContinueF` & `AppendF`) --- src/vm/lib.nim | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index dfc660946f..bd65fa3b0d 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -97,14 +97,7 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: SetSym(n, b) - static: - case n: - of "array": ArrayF = b - - when n=="array" : ArrayF = b - elif n=="dictionary" : DictF = b - elif n=="function" : FuncF = b - elif n=="add" : AddF = b + when n=="add" : AddF = b elif n=="sub" : SubF = b elif n=="mul" : MulF = b elif n=="div" : DivF = b @@ -112,6 +105,8 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: elif n=="mod" : ModF = b elif n=="pow" : PowF = b elif n=="neg" : NegF = b + elif n=="inc" : IncF = b + elif n=="dec" : DecF = b elif n=="not" : BNotF = b elif n=="and" : BAndF = b elif n=="or" : BOrF = b @@ -126,6 +121,8 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: elif n=="greaterOrEqual?" : GeF = b elif n=="less?" : LtF = b elif n=="lessOrEqual?" : LeF = b + elif n=="get" : GetF = b + elif n=="set" : SetF = b elif n=="if" : IfF = b elif n=="if?" : IfEF = b elif n=="unless" : UnlessF = b @@ -134,10 +131,12 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: elif n=="switch" : SwitchF = b elif n=="while" : WhileF = b elif n=="return" : ReturnF = b + elif n=="break" : BreakF = b + elif n=="continue" : ContinueF = b elif n=="to" : ToF = b - elif n=="print" : PrintF = b - elif n=="get" : GetF = b - elif n=="set" : SetF = b + elif n=="array" : ArrayF = b + elif n=="dictionary" : DictF = b + elif n=="function" : FuncF = b elif n=="range" : RangeF = b elif n=="loop" : LoopF = b elif n=="map" : MapF = b @@ -147,8 +146,8 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: elif n=="split" : SplitF = b elif n=="join" : JoinF = b elif n=="reverse" : ReverseF = b - elif n=="inc" : IncF = b - elif n=="dec" : DecF = b + elif n=="append" : AppendF = b + elif n=="print" : PrintF = b when alias != unaliased: Aliases[alias] = AliasBinding( From 4992199c924f9d1a247a4d8993765518bdbb18b6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:38:16 +0100 Subject: [PATCH 349/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b204796ff6..ed6700100c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3700 \ No newline at end of file +3701 \ No newline at end of file From 966c79f4a21bde7ca78b46467ef6be161dd895e6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:39:50 +0100 Subject: [PATCH 350/984] minor edit --- src/vm/opcodes.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vm/opcodes.nim b/src/vm/opcodes.nim index 603e5e869f..5297160455 100644 --- a/src/vm/opcodes.nim +++ b/src/vm/opcodes.nim @@ -286,7 +286,6 @@ type opReverse = 0xB8 # () # blk # result opAppend = 0xB9 # () # x,y # result - # [0xB0-0xBF] # i/o operations opPrint = 0xBA # () # value # @@ -300,7 +299,7 @@ type # LOW-LEVEL OPERATIONS #--------------------------------- - # [0xB0-0xCF] + # [0xC0-0xDF] # no operation opNop = 0xC0 # () # # From 73469fecb3129065b33d5e72a56f911c492bfe48 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:42:05 +0100 Subject: [PATCH 351/984] save variables/function calls as Word values; not String's --- src/vm/ast.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index bfb3860538..9a37b129f9 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -427,7 +427,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var v: Value = if callType == OtherCall: - newString(name) + newWord(name) else: nil @@ -690,7 +690,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if aliased.name.s == "null": current.addTerminal(newConstant(VNULL)) else: - current.addTerminal(newVariable(newString(aliased.name.s))) + current.addTerminal(newVariable(newWord(aliased.name.s))) else: current.addTerminal(newConstant(item)) From 1d6ee0d0852e42059a10c9ff65bc14e5e6002b77 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:46:13 +0100 Subject: [PATCH 352/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ed6700100c..16ee2556dd 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3701 \ No newline at end of file +3702 \ No newline at end of file From a2da95d3851c9ea76530aee21c2aa9707f809979 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:46:34 +0100 Subject: [PATCH 353/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 16ee2556dd..0911333577 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3702 \ No newline at end of file +3703 \ No newline at end of file From c9ab388c5248783f4dcad298635d161e04f4690c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:53:16 +0100 Subject: [PATCH 354/984] experimental --- src/vm/ast.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 9a37b129f9..2437b8b14d 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -96,6 +96,11 @@ var # Constants #======================================= +let + LookupFunc = { + AddF.action : opAdd + }.toTable + const TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} CallNode : set[NodeKind] = {AttributeNode..SpecialCall} From 5b083607dc80222d490b7ea36b558749997c83cd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:53:25 +0100 Subject: [PATCH 355/984] added missing import --- src/vm/lib.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index bd65fa3b0d..73b4b34559 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -18,6 +18,8 @@ export strutils, tables import vm/[globals, errors, stack, values/comparison, values/clean, values/printable, values/value] export clean, comparison, globals, printable, stack, value +import vm/opcodes + import vm/values/custom/[vcolor, vcomplex, vlogical, vquantity, vrational, vregex, vsymbol] export vcolor, vcomplex, vlogical, vquantity, vrational, vregex, vsymbol From aa8f626cabefa086dbc5c094c90f209b215e2d55 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:53:47 +0100 Subject: [PATCH 356/984] VM/values/types: added new `op` field for *built-in* Function values --- src/vm/values/types.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vm/values/types.nim b/src/vm/values/types.nim index aa46684573..fa07a1eaa7 100644 --- a/src/vm/values/types.nim +++ b/src/vm/values/types.nim @@ -23,6 +23,7 @@ when defined(WEB): when not defined(NOGMP): import helpers/bignums +import vm/opcodes import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vquantity, vrange, vrational, vregex, vsocket, vsymbol, vversion] import vm/values/flags @@ -169,6 +170,7 @@ type inline* : bool bcode* : Value of BuiltinFunction: + op* : OpCode action* : BuiltinAction VStore* = ref object From 8bb68fd18e472ecdb430751f9e6d234d46fa3489 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:54:12 +0100 Subject: [PATCH 357/984] VM/values/value: fixed `newBuiltin` constructor to support carrying OpCode information --- src/vm/values/value.nim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index 64f32cb55d..5c630eacac 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -36,6 +36,8 @@ when not defined(NOGMP): when not defined(WEB): import vm/errors +import vm/opcodes + import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vquantity, vrange, vrational, vregex, vsocket, vsymbol, vversion] import vm/values/clean @@ -544,7 +546,7 @@ func newFunction*(params: seq[string], main: Value, imports: Value = nil, export ) ) -func newBuiltin*(desc: sink string, modl: sink string, line: int, ar: int8, ag: sink OrderedTable[string,ValueSpec], at: sink OrderedTable[string,(ValueSpec,string)], ret: ValueSpec, exa: sink string, act: BuiltinAction): Value {.inline, enforceNoRaises.} = +func newBuiltin*(desc: sink string, modl: sink string, line: int, ar: int8, ag: sink OrderedTable[string,ValueSpec], at: sink OrderedTable[string,(ValueSpec,string)], ret: ValueSpec, exa: sink string, opc: OpCode, act: BuiltinAction): Value {.inline, enforceNoRaises.} = ## create Function (BuiltinFunction) value with given details result = Value( kind: Function, @@ -559,6 +561,7 @@ func newBuiltin*(desc: sink string, modl: sink string, line: int, ar: int8, ag: funcType: VFunction( fnKind: BuiltinFunction, arity: ar, + op: opc, action: act ) ) @@ -724,9 +727,9 @@ proc copyValue*(v: Value): Value {.inline.} = result = newFunction(v.params, v.main, v.imports, v.exports, v.memoize, v.inline) else: when defined(DOCGEN): - result = newBuiltin(v.info.descr, v.info.module, v.info.line, v.arity, v.info.args, v.info.attrs, v.info.returns, v.info.example, v.action) + result = newBuiltin(v.info.descr, v.info.module, v.info.line, v.arity, v.info.args, v.info.attrs, v.info.returns, v.info.example, v.op, v.action) else: - result = newBuiltin(v.info.descr, v.info.module, 0, v.arity, v.info.args, v.info.attrs, v.info.returns, "", v.action) + result = newBuiltin(v.info.descr, v.info.module, 0, v.arity, v.info.args, v.info.attrs, v.info.returns, "", v.op, v.action) of Database: when not defined(NOSQLITE): From 16eb5659564340aba0f33e8c43bc4b4b168dd243 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:56:41 +0100 Subject: [PATCH 358/984] add support for passing the OpCode --- src/vm/lib.nim | 105 +++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index 73b4b34559..ca395352d6 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -56,7 +56,7 @@ else: # else: # args -template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: string, args: untyped, attrs: untyped, returns: ValueSpec, example: string, act: untyped):untyped = +template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: string, args: untyped, attrs: untyped, returns: ValueSpec, example: string, opc: OpCode, act: untyped):untyped = ## add new builtin, function with given name, alias, ## rule, etc - followed by the code block to be ## executed when the function is called @@ -85,6 +85,7 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: when not defined(WEB): attrs.toOrderedTable else: initOrderedTable[string,(ValueSpec,string)](), returns, cleanExample, + opc, proc () = hookProcProfiler("lib/require"): require(n, args) @@ -99,57 +100,57 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: SetSym(n, b) - when n=="add" : AddF = b - elif n=="sub" : SubF = b - elif n=="mul" : MulF = b - elif n=="div" : DivF = b - elif n=="fdiv" : FdivF = b - elif n=="mod" : ModF = b - elif n=="pow" : PowF = b - elif n=="neg" : NegF = b - elif n=="inc" : IncF = b - elif n=="dec" : DecF = b - elif n=="not" : BNotF = b - elif n=="and" : BAndF = b - elif n=="or" : BOrF = b - elif n=="shl" : ShlF = b - elif n=="shr" : ShrF = b - elif n=="not?" : NotF = b - elif n=="and?" : AndF = b - elif n=="or?" : OrF = b - elif n=="equal?" : EqF = b - elif n=="notEqual?" : NeF = b - elif n=="greater?" : GtF = b - elif n=="greaterOrEqual?" : GeF = b - elif n=="less?" : LtF = b - elif n=="lessOrEqual?" : LeF = b - elif n=="get" : GetF = b - elif n=="set" : SetF = b - elif n=="if" : IfF = b - elif n=="if?" : IfEF = b - elif n=="unless" : UnlessF = b - elif n=="unless?" : UnlessEF = b - elif n=="else" : ElseF = b - elif n=="switch" : SwitchF = b - elif n=="while" : WhileF = b - elif n=="return" : ReturnF = b - elif n=="break" : BreakF = b - elif n=="continue" : ContinueF = b - elif n=="to" : ToF = b - elif n=="array" : ArrayF = b - elif n=="dictionary" : DictF = b - elif n=="function" : FuncF = b - elif n=="range" : RangeF = b - elif n=="loop" : LoopF = b - elif n=="map" : MapF = b - elif n=="select" : SelectF = b - elif n=="size" : SizeF = b - elif n=="replace" : ReplaceF = b - elif n=="split" : SplitF = b - elif n=="join" : JoinF = b - elif n=="reverse" : ReverseF = b - elif n=="append" : AppendF = b - elif n=="print" : PrintF = b + # when n=="add" : AddF = b + # elif n=="sub" : SubF = b + # elif n=="mul" : MulF = b + # elif n=="div" : DivF = b + # elif n=="fdiv" : FdivF = b + # elif n=="mod" : ModF = b + # elif n=="pow" : PowF = b + # elif n=="neg" : NegF = b + # elif n=="inc" : IncF = b + # elif n=="dec" : DecF = b + # elif n=="not" : BNotF = b + # elif n=="and" : BAndF = b + # elif n=="or" : BOrF = b + # elif n=="shl" : ShlF = b + # elif n=="shr" : ShrF = b + # elif n=="not?" : NotF = b + # elif n=="and?" : AndF = b + # elif n=="or?" : OrF = b + # elif n=="equal?" : EqF = b + # elif n=="notEqual?" : NeF = b + # elif n=="greater?" : GtF = b + # elif n=="greaterOrEqual?" : GeF = b + # elif n=="less?" : LtF = b + # elif n=="lessOrEqual?" : LeF = b + # elif n=="get" : GetF = b + # elif n=="set" : SetF = b + # elif n=="if" : IfF = b + # elif n=="if?" : IfEF = b + # elif n=="unless" : UnlessF = b + # elif n=="unless?" : UnlessEF = b + # elif n=="else" : ElseF = b + # elif n=="switch" : SwitchF = b + # elif n=="while" : WhileF = b + # elif n=="return" : ReturnF = b + # elif n=="break" : BreakF = b + # elif n=="continue" : ContinueF = b + # elif n=="to" : ToF = b + # elif n=="array" : ArrayF = b + # elif n=="dictionary" : DictF = b + # elif n=="function" : FuncF = b + # elif n=="range" : RangeF = b + # elif n=="loop" : LoopF = b + # elif n=="map" : MapF = b + # elif n=="select" : SelectF = b + # elif n=="size" : SizeF = b + # elif n=="replace" : ReplaceF = b + # elif n=="split" : SplitF = b + # elif n=="join" : JoinF = b + # elif n=="reverse" : ReverseF = b + # elif n=="append" : AppendF = b + # elif n=="print" : PrintF = b when alias != unaliased: Aliases[alias] = AliasBinding( From 9cfd9615bcc7767184514ee8bc72e3509d8a95cd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:56:58 +0100 Subject: [PATCH 359/984] comment out all Function-related global references --- src/vm/values/value.nim | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index 5c630eacac..aadd75770f 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -117,20 +117,20 @@ let var TypeLookup = initOrderedTable[string,Value]() - # global implementation references - AddF*, SubF*, MulF*, DivF*, FdivF*, ModF*, PowF* : Value - NegF*, IncF*, DecF* : Value - BNotF*, BAndF*, BOrF*, ShlF*, ShrF* : Value - NotF*, AndF*, OrF* : Value - EqF*, NeF*, GtF*, GeF*, LtF*, LeF* : Value - GetF*, SetF* : Value - IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF*, WhileF* : Value - ReturnF*, BreakF*, ContinueF* : Value - ToF* : Value - ArrayF*, DictF*, FuncF* : Value - RangeF*, LoopF*, MapF*, SelectF* : Value - SizeF*, ReplaceF*, SplitF*, JoinF*, ReverseF*, AppendF* : Value - PrintF* : Value + # # global implementation references + # AddF*, SubF*, MulF*, DivF*, FdivF*, ModF*, PowF* : Value + # NegF*, IncF*, DecF* : Value + # BNotF*, BAndF*, BOrF*, ShlF*, ShrF* : Value + # NotF*, AndF*, OrF* : Value + # EqF*, NeF*, GtF*, GeF*, LtF*, LeF* : Value + # GetF*, SetF* : Value + # IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF*, WhileF* : Value + # ReturnF*, BreakF*, ContinueF* : Value + # ToF* : Value + # ArrayF*, DictF*, FuncF* : Value + # RangeF*, LoopF*, MapF*, SelectF* : Value + # SizeF*, ReplaceF*, SplitF*, JoinF*, ReverseF*, AppendF* : Value + # PrintF* : Value #======================================= # Forward Declarations From 1e0e4d5f1974c68ce53ba42949bdd963c6e557d2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:57:42 +0100 Subject: [PATCH 360/984] renamed parameter --- src/vm/lib.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index ca395352d6..4f97c58285 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -56,7 +56,7 @@ else: # else: # args -template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: string, args: untyped, attrs: untyped, returns: ValueSpec, example: string, opc: OpCode, act: untyped):untyped = +template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: string, args: untyped, attrs: untyped, returns: ValueSpec, example: string, op: OpCode, act: untyped):untyped = ## add new builtin, function with given name, alias, ## rule, etc - followed by the code block to be ## executed when the function is called @@ -85,7 +85,7 @@ template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: when not defined(WEB): attrs.toOrderedTable else: initOrderedTable[string,(ValueSpec,string)](), returns, cleanExample, - opc, + op, proc () = hookProcProfiler("lib/require"): require(n, args) From 5aa458209dc0a266d1b9ea53937e1059c697b744 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:58:34 +0100 Subject: [PATCH 361/984] changed argument order --- src/vm/lib.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index 4f97c58285..10de32138a 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -56,7 +56,7 @@ else: # else: # args -template builtin*(n: string, alias: VSymbol, rule: PrecedenceKind, description: string, args: untyped, attrs: untyped, returns: ValueSpec, example: string, op: OpCode, act: untyped):untyped = +template builtin*(n: string, alias: VSymbol, op: OpCode, rule: PrecedenceKind, description: string, args: untyped, attrs: untyped, returns: ValueSpec, example: string, act: untyped):untyped = ## add new builtin, function with given name, alias, ## rule, etc - followed by the code block to be ## executed when the function is called From fc80975118985c02b32ef88a87c9bec1b91c60b7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:58:43 +0100 Subject: [PATCH 362/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0911333577..ed8e46bb33 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3703 \ No newline at end of file +3704 \ No newline at end of file From 13effb8cffea7f3e44d81b316fac568b3f434104 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:59:27 +0100 Subject: [PATCH 363/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ed8e46bb33..5e7f008b70 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3704 \ No newline at end of file +3705 \ No newline at end of file From 5d6ddf1cd165db4fb54f1e253194a7c6eee495c9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 16:59:54 +0100 Subject: [PATCH 364/984] VM/values/types: added accessor for `op` Function values' field --- src/vm/values/types.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vm/values/types.nim b/src/vm/values/types.nim index fa07a1eaa7..dfb08e4e0d 100644 --- a/src/vm/values/types.nim +++ b/src/vm/values/types.nim @@ -342,3 +342,4 @@ makeAccessor(funcType, memoize) makeAccessor(funcType, bcode) makeAccessor(funcType, inline) makeAccessor(funcType, action) +makeAccessor(funcType, op) From 7b701550c619872f4e3ae95980dc6702a504d276 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:03:05 +0100 Subject: [PATCH 365/984] VM/ast: [addCall] to work with functions' `.op` field; and not with global references --- src/vm/ast.nim | 104 ++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 48 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 2437b8b14d..f11ec6814b 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -378,54 +378,62 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var op: OpCode = opNop - if fn == ArrayF : op = opArray - elif fn == DictF : op = opDict - elif fn == FuncF : op = opFunc - elif fn == AddF : op = opAdd - elif fn == SubF : op = opSub - elif fn == MulF : op = opMul - elif fn == DivF : op = opDiv - elif fn == FdivF : op = opFDiv - elif fn == ModF : op = opMod - elif fn == PowF : op = opPow - elif fn == NegF : op = opNeg - elif fn == BNotF : op = opBNot - elif fn == BAndF : op = opBAnd - elif fn == BOrF : op = opBOr - elif fn == ShlF : op = opShl - elif fn == ShrF : op = opShr - elif fn == NotF : op = opNot - elif fn == AndF : op = opAnd - elif fn == OrF : op = opOr - elif fn == EqF : op = opEq - elif fn == NeF : op = opNe - elif fn == GtF : op = opGt - elif fn == GeF : op = opGe - elif fn == LtF : op = opLt - elif fn == LeF : op = opLe - elif fn == IfF : callType = SpecialCall; op = opIf - elif fn == IfEF : callType = SpecialCall; op = opIfE - elif fn == UnlessF : callType = SpecialCall; op = opUnless - elif fn == UnlessEF : callType = SpecialCall; op = opUnless - elif fn == ElseF : callType = SpecialCall; op = opElse - elif fn == SwitchF : callType = SpecialCall; op = opSwitch - elif fn == WhileF : callType = SpecialCall; op = opWhile - elif fn == ReturnF : op = opReturn - elif fn == ToF : op = opTo - elif fn == PrintF : op = opPrint - elif fn == GetF : op = opGet - elif fn == SetF : op = opSet - elif fn == RangeF : op = opRange - elif fn == LoopF : op = opLoop - elif fn == MapF : op = opMap - elif fn == SelectF : op = opSelect - elif fn == SizeF : op = opSize - elif fn == ReplaceF : op = opReplace - elif fn == SplitF : op = opSplit - elif fn == JoinF : op = opJoin - elif fn == ReverseF : op = opReverse - elif fn == IncF : op = opInc - elif fn == DecF : op = opDec + if fn.fnKind == BuiltinFunction: + op = fn.op + callType = + if op in {opIf, opIfE, opUnless, opUnlessE, opElse, opSwitch, opWhile}: + SpecialCall + else: + BuiltinCall + + # if fn == ArrayF : op = opArray + # elif fn == DictF : op = opDict + # elif fn == FuncF : op = opFunc + # elif fn == AddF : op = opAdd + # elif fn == SubF : op = opSub + # elif fn == MulF : op = opMul + # elif fn == DivF : op = opDiv + # elif fn == FdivF : op = opFDiv + # elif fn == ModF : op = opMod + # elif fn == PowF : op = opPow + # elif fn == NegF : op = opNeg + # elif fn == BNotF : op = opBNot + # elif fn == BAndF : op = opBAnd + # elif fn == BOrF : op = opBOr + # elif fn == ShlF : op = opShl + # elif fn == ShrF : op = opShr + # elif fn == NotF : op = opNot + # elif fn == AndF : op = opAnd + # elif fn == OrF : op = opOr + # elif fn == EqF : op = opEq + # elif fn == NeF : op = opNe + # elif fn == GtF : op = opGt + # elif fn == GeF : op = opGe + # elif fn == LtF : op = opLt + # elif fn == LeF : op = opLe + # elif fn == IfF : callType = SpecialCall; op = opIf + # elif fn == IfEF : callType = SpecialCall; op = opIfE + # elif fn == UnlessF : callType = SpecialCall; op = opUnless + # elif fn == UnlessEF : callType = SpecialCall; op = opUnless + # elif fn == ElseF : callType = SpecialCall; op = opElse + # elif fn == SwitchF : callType = SpecialCall; op = opSwitch + # elif fn == WhileF : callType = SpecialCall; op = opWhile + # elif fn == ReturnF : op = opReturn + # elif fn == ToF : op = opTo + # elif fn == PrintF : op = opPrint + # elif fn == GetF : op = opGet + # elif fn == SetF : op = opSet + # elif fn == RangeF : op = opRange + # elif fn == LoopF : op = opLoop + # elif fn == MapF : op = opMap + # elif fn == SelectF : op = opSelect + # elif fn == SizeF : op = opSize + # elif fn == ReplaceF : op = opReplace + # elif fn == SplitF : op = opSplit + # elif fn == JoinF : op = opJoin + # elif fn == ReverseF : op = opReverse + # elif fn == IncF : op = opInc + # elif fn == DecF : op = opDec if callType == OtherCall and op != opNop: callType = BuiltinCall From 8bfa5a10fe3ca579613b6f0ddf65e97771993086 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:03:47 +0100 Subject: [PATCH 366/984] commented out obsolete code --- src/vm/ast.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index f11ec6814b..86d7b7a801 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -435,8 +435,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b # elif fn == IncF : op = opInc # elif fn == DecF : op = opDec - if callType == OtherCall and op != opNop: - callType = BuiltinCall + # if callType == OtherCall and op != opNop: + # callType = BuiltinCall var v: Value = if callType == OtherCall: From 7daf0e648e9b8d30191ca8e07b98170aa0c9a0a4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:05:18 +0100 Subject: [PATCH 367/984] correctly import/export OpCodes to all Library-related modules --- src/vm/lib.nim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index 10de32138a..b903a7e2c6 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -15,10 +15,8 @@ import sequtils, strutils, tables export strutils, tables -import vm/[globals, errors, stack, values/comparison, values/clean, values/printable, values/value] -export clean, comparison, globals, printable, stack, value - -import vm/opcodes +import vm/[globals, errors, opcodes, stack, values/comparison, values/clean, values/printable, values/value] +export clean, comparison, globals, printable, opcodes, stack, value import vm/values/custom/[vcolor, vcomplex, vlogical, vquantity, vrational, vregex, vsymbol] export vcolor, vcomplex, vlogical, vquantity, vrational, vregex, vsymbol From 249f938a0767acb192e70e86db68668738ffa554 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:07:13 +0100 Subject: [PATCH 368/984] Arithmetic: setting opcodes --- src/library/Arithmetic.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/library/Arithmetic.nim b/src/library/Arithmetic.nim index 79e6f0ac78..eda5864603 100644 --- a/src/library/Arithmetic.nim +++ b/src/library/Arithmetic.nim @@ -29,6 +29,7 @@ proc defineSymbols*() = builtin "add", alias = plus, + op = opAdd, rule = InfixPrecedence, description = "add given values and return result", args = { @@ -50,6 +51,7 @@ proc defineSymbols*() = builtin "dec", alias = unaliased, + op = opDec, rule = PrefixPrecedence, description = "decrease given value by 1", args = { @@ -69,6 +71,7 @@ proc defineSymbols*() = builtin "div", alias = slash, + op = opDiv, rule = InfixPrecedence, description = "perform integer division between given values and return result", args = { @@ -90,6 +93,7 @@ proc defineSymbols*() = builtin "divmod", alias = slashpercent, + op = opNop, rule = InfixPrecedence, description = "perform integer division between given values and return tuple with quotient and remainder", args = { @@ -113,6 +117,7 @@ proc defineSymbols*() = builtin "fdiv", alias = doubleslash, + op = opFDiv, rule = InfixPrecedence, description = "divide given values and return result", args = { @@ -133,6 +138,7 @@ proc defineSymbols*() = builtin "inc", alias = unaliased, + op = opInc, rule = PrefixPrecedence, description = "increase given value by 1", args = { @@ -152,6 +158,7 @@ proc defineSymbols*() = builtin "mod", alias = percent, + op = opMod, rule = InfixPrecedence, description = "calculate the modulo of given values and return result", args = { @@ -173,6 +180,7 @@ proc defineSymbols*() = builtin "mul", alias = asterisk, + op = opMul, rule = InfixPrecedence, description = "calculate the product of given values and return result", args = { @@ -194,6 +202,7 @@ proc defineSymbols*() = builtin "neg", alias = unaliased, + op = opNeg, rule = PrefixPrecedence, description = "reverse sign of given value and return it", args = { @@ -213,6 +222,7 @@ proc defineSymbols*() = builtin "pow", alias = caret, + op = opPow, rule = InfixPrecedence, description = "calculate the power of given values and return result", args = { @@ -237,6 +247,7 @@ proc defineSymbols*() = builtin "sub", alias = minus, + op = opSub, rule = InfixPrecedence, description = "subtract given values and return result", args = { From 5953878c690a9435c298be9a0582889554e5f7e4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:08:52 +0100 Subject: [PATCH 369/984] Bitwise: setting opcodes --- src/library/Bitwise.nim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/library/Bitwise.nim b/src/library/Bitwise.nim index 35528e3fe4..e5c78be882 100644 --- a/src/library/Bitwise.nim +++ b/src/library/Bitwise.nim @@ -35,6 +35,7 @@ proc defineSymbols*() = builtin "and", alias = unaliased, + op = opBAnd, rule = InfixPrecedence, description = "calculate the binary AND for the given values", args = { @@ -56,6 +57,7 @@ proc defineSymbols*() = builtin "nand", alias = unaliased, + op = opNop, rule = InfixPrecedence, description = "calculate the binary NAND for the given values", args = { @@ -76,6 +78,7 @@ proc defineSymbols*() = builtin "nor", alias = unaliased, + op = opNop, rule = InfixPrecedence, description = "calculate the binary NOR for the given values", args = { @@ -96,6 +99,7 @@ proc defineSymbols*() = builtin "not", alias = unaliased, + op = opBNot, rule = PrefixPrecedence, description = "calculate the binary complement the given value", args = { @@ -115,6 +119,7 @@ proc defineSymbols*() = builtin "or", alias = unaliased, + op = opBOr, rule = InfixPrecedence, description = "calculate the binary OR for the given values", args = { @@ -135,6 +140,7 @@ proc defineSymbols*() = builtin "shl", alias = unaliased, + op = opShl, rule = InfixPrecedence, description = "shift-left first value bits by second value", args = { @@ -167,6 +173,7 @@ proc defineSymbols*() = builtin "shr", alias = unaliased, + op = opShr, rule = InfixPrecedence, description = "shift-right first value bits by second value", args = { @@ -187,6 +194,7 @@ proc defineSymbols*() = builtin "xnor", alias = unaliased, + op = opNop, rule = InfixPrecedence, description = "calculate the binary XNOR for the given values", args = { @@ -207,6 +215,7 @@ proc defineSymbols*() = builtin "xor", alias = unaliased, + op = opNop, rule = InfixPrecedence, description = "calculate the binary XOR for the given values", args = { From 4ffd1078dc34941b815708374acad09f1c72b68f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:13:36 +0100 Subject: [PATCH 370/984] Collections: setting opcodes --- src/library/Collections.nim | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/library/Collections.nim b/src/library/Collections.nim index 1ae9845fb1..260ae3da07 100644 --- a/src/library/Collections.nim +++ b/src/library/Collections.nim @@ -50,6 +50,7 @@ proc defineSymbols*() = builtin "append", alias = doubleplus, + op = opAppend, rule = InfixPrecedence, description = "append value to given collection", args = { @@ -124,6 +125,7 @@ proc defineSymbols*() = builtin "chop", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "remove last item from given collection", args = { @@ -170,6 +172,7 @@ proc defineSymbols*() = # labels: library, enhancement, open discussion builtin "combine", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get all possible combinations of the elements in given collection", args = { @@ -227,6 +230,7 @@ proc defineSymbols*() = # labels: library, enhancement, open discussion builtin "contains?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if collection contains given value", args = { @@ -310,6 +314,7 @@ proc defineSymbols*() = # labels: library, enhancement builtin "couple", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get combination of elements in given collections as array of tuples", args = { @@ -329,6 +334,7 @@ proc defineSymbols*() = builtin "decouple", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get tuple of collections from a coupled collection of tuples", args = { @@ -355,6 +361,7 @@ proc defineSymbols*() = builtin "drop", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "drop first *number* of elements from given collection and return the remaining ones", args = { @@ -388,6 +395,7 @@ proc defineSymbols*() = builtin "empty", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "empty given collection", args = { @@ -412,6 +420,7 @@ proc defineSymbols*() = builtin "empty?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given collection is empty", args = { @@ -438,6 +447,7 @@ proc defineSymbols*() = builtin "extend", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get new dictionary by merging given ones", args = { @@ -466,6 +476,7 @@ proc defineSymbols*() = builtin "first", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "return the first item of the given collection", args = { @@ -511,6 +522,7 @@ proc defineSymbols*() = builtin "flatten", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "flatten given collection by eliminating nested blocks", args = { @@ -544,6 +556,7 @@ proc defineSymbols*() = builtin "get", alias = unaliased, + op = opGet, rule = PrefixPrecedence, description = "get collection's item by given index", args = { @@ -648,6 +661,7 @@ proc defineSymbols*() = # labels: library, enhancement, open discussion builtin "in?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if value exists in given collection", args = { @@ -728,6 +742,7 @@ proc defineSymbols*() = builtin "index", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "return first index of value in given collection", args = { @@ -779,6 +794,7 @@ proc defineSymbols*() = # labels: library, enhancement, open discussion builtin "insert", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "insert value in collection at given index", args = { @@ -836,6 +852,7 @@ proc defineSymbols*() = builtin "key?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if collection contains given key", args = { @@ -868,6 +885,7 @@ proc defineSymbols*() = builtin "keys", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get list of keys for given collection", args = { @@ -895,6 +913,7 @@ proc defineSymbols*() = builtin "last", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "return the last item of the given collection", args = { @@ -936,6 +955,7 @@ proc defineSymbols*() = builtin "max", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get maximum element in given collection", args = { @@ -981,6 +1001,7 @@ proc defineSymbols*() = builtin "min", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get minimum element in given collection", args = { @@ -1026,6 +1047,7 @@ proc defineSymbols*() = builtin "one?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given number or collection size is one", args = { @@ -1076,6 +1098,7 @@ proc defineSymbols*() = builtin "permutate", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get all possible permutations of the elements in given collection", args = { @@ -1124,6 +1147,7 @@ proc defineSymbols*() = builtin "prepend", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "prepend value to given collection", args = { @@ -1184,6 +1208,7 @@ proc defineSymbols*() = # labels: library, bug builtin "remove", alias = doubleminus, + op = opNop, rule = InfixPrecedence, description = "remove value from given collection", args = { @@ -1296,6 +1321,7 @@ proc defineSymbols*() = builtin "repeat", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "repeat value the given number of times and return new one", args = { @@ -1337,6 +1363,7 @@ proc defineSymbols*() = builtin "reverse", alias = unaliased, + op = opReverse, rule = PrefixPrecedence, description = "reverse given collection", args = { @@ -1385,6 +1412,7 @@ proc defineSymbols*() = builtin "rotate", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "right-rotate collection by given distance", args = { @@ -1421,6 +1449,7 @@ proc defineSymbols*() = builtin "sample", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get a random element from given collection", args = { @@ -1451,6 +1480,7 @@ proc defineSymbols*() = # labels: library, bug builtin "set", alias = unaliased, + op = opSet, rule = PrefixPrecedence, description = "set collection's item at index to given value", args = { @@ -1538,6 +1568,7 @@ proc defineSymbols*() = builtin "shuffle", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get given collection shuffled", args = { @@ -1562,6 +1593,7 @@ proc defineSymbols*() = builtin "size", alias = unaliased, + op = opSize, rule = PrefixPrecedence, description = "get size/length of given collection", args = { @@ -1600,6 +1632,7 @@ proc defineSymbols*() = builtin "slice", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get a slice of collection between given indices", args = { @@ -1642,6 +1675,7 @@ proc defineSymbols*() = builtin "sort", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "sort given block in ascending order", args = { @@ -1826,6 +1860,7 @@ proc defineSymbols*() = # labels: library, enhancement builtin "sorted?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given collection is already sorted", args = { @@ -1865,6 +1900,7 @@ proc defineSymbols*() = # labels: library, bug builtin "split", alias = unaliased, + op = opSplit, rule = PrefixPrecedence, description = "split collection to components", args = { @@ -2022,6 +2058,7 @@ proc defineSymbols*() = builtin "squeeze", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "reduce adjacent elements in given collection", args = { @@ -2084,6 +2121,7 @@ proc defineSymbols*() = builtin "take", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "keep first of elements from given collection and return the remaining ones", args = { @@ -2146,6 +2184,7 @@ proc defineSymbols*() = builtin "tally", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "find number of occurences of each value within given block and return as dictionary", args = { @@ -2182,6 +2221,7 @@ proc defineSymbols*() = builtin "unique", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get given collection without duplicates", args = { @@ -2220,6 +2260,7 @@ proc defineSymbols*() = builtin "values", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get list of values for given collection", args = { @@ -2251,6 +2292,7 @@ proc defineSymbols*() = builtin "zero?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given number or collection size is zero", args = { From 2958a1ed13e29f835c1b81676a2f411ddb5c4766 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:14:28 +0100 Subject: [PATCH 371/984] Colors: setting opcodes --- src/library/Colors.nim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/library/Colors.nim b/src/library/Colors.nim index 298f186a37..cf8c7c8ec6 100644 --- a/src/library/Colors.nim +++ b/src/library/Colors.nim @@ -34,6 +34,7 @@ proc defineSymbols*() = builtin "blend", alias = at, + op = opNop, rule = PrefixPrecedence, description = "blend given colors and get result", args = { @@ -63,6 +64,7 @@ proc defineSymbols*() = builtin "darken", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "darken color by given percentage (0.0-1.0)", args = { @@ -86,6 +88,7 @@ proc defineSymbols*() = builtin "desaturate", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "desaturate color by given percentage (0.0-1.0)", args = { @@ -109,6 +112,7 @@ proc defineSymbols*() = builtin "grayscale", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "convert color to grayscale", args = { @@ -131,6 +135,7 @@ proc defineSymbols*() = builtin "invert", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get complement for given color", args = { @@ -152,6 +157,7 @@ proc defineSymbols*() = builtin "lighten", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "lighten color by given percentage (0.0-1.0)", args = { @@ -177,6 +183,7 @@ proc defineSymbols*() = builtin "palette", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "create palette using given base color", args = { @@ -241,6 +248,7 @@ proc defineSymbols*() = builtin "saturate", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "saturate color by given percentage (0.0-1.0)", args = { @@ -266,6 +274,7 @@ proc defineSymbols*() = builtin "spin", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "spin color around the hue wheel by given amount", args = { From 79fc91daeea6983fd2166b383e4b894993c11e01 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:14:32 +0100 Subject: [PATCH 372/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5e7f008b70..5e403aebbe 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3705 \ No newline at end of file +3706 \ No newline at end of file From db16ee0edf751c1980ebbea6b881bf476f19004d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:15:01 +0100 Subject: [PATCH 373/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5e403aebbe..44d7b3c3e3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3706 \ No newline at end of file +3707 \ No newline at end of file From 4991675a6d0e04ddbf3451b9619e94f26a6afa9a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:16:36 +0100 Subject: [PATCH 374/984] removed experiment --- src/vm/ast.nim | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 86d7b7a801..75831f04c4 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -96,11 +96,6 @@ var # Constants #======================================= -let - LookupFunc = { - AddF.action : opAdd - }.toTable - const TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} CallNode : set[NodeKind] = {AttributeNode..SpecialCall} From c8901dca63358bda73ee3ecfebff623697c78291 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:16:56 +0100 Subject: [PATCH 375/984] uncomment (temporarily, to get the code to compile) --- src/vm/values/value.nim | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index aadd75770f..5c630eacac 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -117,20 +117,20 @@ let var TypeLookup = initOrderedTable[string,Value]() - # # global implementation references - # AddF*, SubF*, MulF*, DivF*, FdivF*, ModF*, PowF* : Value - # NegF*, IncF*, DecF* : Value - # BNotF*, BAndF*, BOrF*, ShlF*, ShrF* : Value - # NotF*, AndF*, OrF* : Value - # EqF*, NeF*, GtF*, GeF*, LtF*, LeF* : Value - # GetF*, SetF* : Value - # IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF*, WhileF* : Value - # ReturnF*, BreakF*, ContinueF* : Value - # ToF* : Value - # ArrayF*, DictF*, FuncF* : Value - # RangeF*, LoopF*, MapF*, SelectF* : Value - # SizeF*, ReplaceF*, SplitF*, JoinF*, ReverseF*, AppendF* : Value - # PrintF* : Value + # global implementation references + AddF*, SubF*, MulF*, DivF*, FdivF*, ModF*, PowF* : Value + NegF*, IncF*, DecF* : Value + BNotF*, BAndF*, BOrF*, ShlF*, ShrF* : Value + NotF*, AndF*, OrF* : Value + EqF*, NeF*, GtF*, GeF*, LtF*, LeF* : Value + GetF*, SetF* : Value + IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF*, WhileF* : Value + ReturnF*, BreakF*, ContinueF* : Value + ToF* : Value + ArrayF*, DictF*, FuncF* : Value + RangeF*, LoopF*, MapF*, SelectF* : Value + SizeF*, ReplaceF*, SplitF*, JoinF*, ReverseF*, AppendF* : Value + PrintF* : Value #======================================= # Forward Declarations From 7f055e0867b288f086484f129cdef73a951e4076 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:17:01 +0100 Subject: [PATCH 376/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 44d7b3c3e3..bb09372b41 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3707 \ No newline at end of file +3708 \ No newline at end of file From deb734d3dd0ffcabb538367f1473ade57ca516d4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:18:22 +0100 Subject: [PATCH 377/984] Comparison: adding opcodes --- src/library/Comparison.nim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/library/Comparison.nim b/src/library/Comparison.nim index 9c378b224f..8fcb803feb 100644 --- a/src/library/Comparison.nim +++ b/src/library/Comparison.nim @@ -33,6 +33,7 @@ proc defineSymbols*() = # labels: library, enhancement, open discussion builtin "between?", alias = thickarrowboth, + op = opNop, rule = InfixPrecedence, description = "check if given value is between the given values (inclusive)", args = { @@ -63,6 +64,7 @@ proc defineSymbols*() = builtin "compare", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "compare given values and return -1, 0, or 1 based on the result", args = { @@ -86,6 +88,7 @@ proc defineSymbols*() = builtin "equal?", alias = equal, + op = opEq, rule = InfixPrecedence, description = "check if valueA = valueB (equality)", args = { @@ -105,6 +108,7 @@ proc defineSymbols*() = builtin "greater?", alias = greaterthan, + op = opGt, rule = InfixPrecedence, description = "check if valueA > valueB (greater than)", args = { @@ -124,6 +128,7 @@ proc defineSymbols*() = builtin "greaterOrEqual?", alias = greaterequal, + op = opGe, rule = InfixPrecedence, description = "check if valueA >= valueB (greater than or equal)", args = { @@ -143,6 +148,7 @@ proc defineSymbols*() = builtin "less?", alias = lessthan, + op = opLt, rule = InfixPrecedence, description = "check if valueA < valueB (less than)", args = { @@ -162,6 +168,7 @@ proc defineSymbols*() = builtin "lessOrEqual?", alias = equalless, + op = opLe, rule = InfixPrecedence, description = "check if valueA =< valueB (less than or equal)", args = { @@ -181,6 +188,7 @@ proc defineSymbols*() = builtin "notEqual?", alias = lessgreater, + op = opNe, rule = InfixPrecedence, description = "check if valueA <> valueB (not equal)", args = { @@ -200,6 +208,7 @@ proc defineSymbols*() = builtin "same?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given values are exactly the same (identity)", args = { From a3fad49c7a10e317cf8a6657aeb6a7744ded2e83 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:23:10 +0100 Subject: [PATCH 378/984] re-organized opcodes (group `range` with other converters) --- src/vm/exec.nim | 13 +++++++------ src/vm/opcodes.nim | 38 ++++++++++++++++++++------------------ src/vm/values/value.nim | 4 ++-- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index 146f7d8508..a6dd4e19e5 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -630,14 +630,18 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = stack.push(VINTEGERT) ToF.action()() + of RSRV7 : discard + of RSRV8 : discard + of RSRV9 : discard + + # [0xB0-0xBF] # generators of opArray : ArrayF.action()() of opDict : DictF.action()() of opFunc : FuncF.action()() - - # [0xB0-0xBF] - # ranges & iterators of opRange : RangeF.action()() + + # iterators of opLoop : LoopF.action()() of opMap : MapF.action()() of opSelect : SelectF.action()() @@ -653,9 +657,6 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = # i/o operations of opPrint : PrintF.action()() - of RSRV7 : discard - of RSRV8 : discard - of RSRV9 : discard of RSRV10 : discard of RSRV11 : discard diff --git a/src/vm/opcodes.nim b/src/vm/opcodes.nim index 5297160455..5c3143ef4e 100644 --- a/src/vm/opcodes.nim +++ b/src/vm/opcodes.nim @@ -266,32 +266,34 @@ type opToS = 0xAB # () # value # result opToI = 0xAC # () # value # result - # generators - opArray = 0xAD # () # blk # result - opDict = 0xAE # () # blk # result - opFunc = 0xAF # () # params,blk # result + RSRV7 = 0xAD # + RSRV8 = 0xAE # + RSRV9 = 0xAF # # [0xB0-0xBF] + # generators + opArray = 0xB0 # () # blk # result + opDict = 0xB1 # () # blk # result + opFunc = 0xB2 # () # params,blk # result + opRange = 0xB3 # () # start,stop # result + # ranges & iterators - opRange = 0xB0 # () # start,stop # result - opLoop = 0xB1 # () # range,param,blk # X - opMap = 0xB2 # () # range,param,blk # result - opSelect = 0xB3 # () # range,param,blk # result + + opLoop = 0xB4 # () # range,param,blk # X + opMap = 0xB5 # () # range,param,blk # result + opSelect = 0xB6 # () # range,param,blk # result # collections - opSize = 0xB4 # () # obj # result - opReplace = 0xB5 # () # obj,what,with # result - opSplit = 0xB6 # () # obj,what # result - opJoin = 0xB7 # () # obj # result - opReverse = 0xB8 # () # blk # result - opAppend = 0xB9 # () # x,y # result + opSize = 0xB7 # () # obj # result + opReplace = 0xB8 # () # obj,what,with # result + opSplit = 0xB9 # () # obj,what # result + opJoin = 0xBA # () # obj # result + opReverse = 0xBB # () # blk # result + opAppend = 0xBC # () # x,y # result # i/o operations - opPrint = 0xBA # () # value # + opPrint = 0xBD # () # value # - RSRV7 = 0xBB # - RSRV8 = 0xBC # - RSRV9 = 0xBD # RSRV10 = 0xBE # RSRV11 = 0xBF # diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index 5c630eacac..22e7eaad85 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -127,8 +127,8 @@ var IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF*, WhileF* : Value ReturnF*, BreakF*, ContinueF* : Value ToF* : Value - ArrayF*, DictF*, FuncF* : Value - RangeF*, LoopF*, MapF*, SelectF* : Value + ArrayF*, DictF*, FuncF*, RangeF* : Value + LoopF*, MapF*, SelectF* : Value SizeF*, ReplaceF*, SplitF*, JoinF*, ReverseF*, AppendF* : Value PrintF* : Value From e28236136ddb00e93d60ca2d744d2b5bef9fb8a7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:23:26 +0100 Subject: [PATCH 379/984] Converters: setting opcodes --- src/library/Converters.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/library/Converters.nim b/src/library/Converters.nim index ee097b5cf0..68f16aa4d4 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -550,6 +550,7 @@ proc defineSymbols*() = builtin "array", alias = at, + op = opArray, rule = PrefixPrecedence, description = "create array from given block, by reducing/calculating all internal values", args = { @@ -634,6 +635,7 @@ proc defineSymbols*() = # labels: library, bug builtin "as", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "format given value as implied type", args = { @@ -708,6 +710,7 @@ proc defineSymbols*() = # labels: library, enhancement builtin "define", alias = dollar, + op = opNop, rule = PrefixPrecedence, description = "define new type with given prototype", args = { @@ -820,6 +823,7 @@ proc defineSymbols*() = builtin "dictionary", alias = sharp, + op = opDict, rule = PrefixPrecedence, description = "create dictionary from given block or file, by getting all internal symbols", args = { @@ -898,6 +902,7 @@ proc defineSymbols*() = # labels: library, enhancement, open discussion builtin "from", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get value from string, using given representation", args = { @@ -941,6 +946,7 @@ proc defineSymbols*() = builtin "function", alias = dollar, + op = opFunc, rule = PrefixPrecedence, description = "create function with given arguments and body", args = { @@ -1152,6 +1158,7 @@ proc defineSymbols*() = builtin "in", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "convert quantity to given unit", args = { @@ -1176,6 +1183,7 @@ proc defineSymbols*() = builtin "range", alias = ellipsis, + op = opRange, rule = InfixPrecedence, description = "get list of values in given range (inclusive)", args = { @@ -1229,6 +1237,7 @@ proc defineSymbols*() = when not defined(WEB): builtin "store", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "create or load a persistent store on disk", args = { @@ -1326,6 +1335,7 @@ proc defineSymbols*() = builtin "to", alias = unaliased, + op = opTo, rule = PrefixPrecedence, description = "convert value to given type", args = { @@ -1423,6 +1433,7 @@ proc defineSymbols*() = builtin "with", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "create closure-style block by embedding given words", args = { From 9ad99b991e330df2c903749020fd842705b3c0f6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:31:40 +0100 Subject: [PATCH 380/984] Core: setting opcodes --- src/library/Core.nim | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/library/Core.nim b/src/library/Core.nim index 7fcf010df6..702385ed3b 100644 --- a/src/library/Core.nim +++ b/src/library/Core.nim @@ -39,6 +39,7 @@ proc defineSymbols*() = builtin "alias", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "assign symbol to given function", args = { @@ -84,6 +85,7 @@ proc defineSymbols*() = builtin "break", alias = unaliased, + op = opBreak, rule = PrefixPrecedence, description = "break out of current block or loop", args = NoArgs, @@ -109,6 +111,7 @@ proc defineSymbols*() = builtin "call", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "call function with given list of parameters", args = { @@ -193,7 +196,8 @@ proc defineSymbols*() = fun.action()() builtin "case", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "initiate a case block to check for different cases", args = { @@ -217,6 +221,7 @@ proc defineSymbols*() = builtin "coalesce", alias = doublequestion, + op = opNop, rule = InfixPrecedence, description = "if first value is null or false, return second value; otherwise return the first one", args = { @@ -236,6 +241,7 @@ proc defineSymbols*() = builtin "continue", alias = unaliased, + op = opContinue, rule = PrefixPrecedence, description = "immediately continue with next iteration", args = NoArgs, @@ -267,6 +273,7 @@ proc defineSymbols*() = # labels: bug, critical, library, values builtin "do", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "evaluate and execute given code", args = { @@ -351,6 +358,7 @@ proc defineSymbols*() = builtin "dup", alias = thickarrowleft, + op = opNop, rule = PrefixPrecedence, description = "duplicate the top of the stack and convert non-returning call to a do-return call", args = { @@ -376,6 +384,7 @@ proc defineSymbols*() = builtin "else", alias = unaliased, + op = opElse, rule = PrefixPrecedence, description = "perform action, if last condition was not true", args = { @@ -401,6 +410,7 @@ proc defineSymbols*() = builtin "ensure", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "assert given condition is true, or exit", args = { @@ -422,6 +432,7 @@ proc defineSymbols*() = builtin "if", alias = unaliased, + op = opIf, rule = PrefixPrecedence, description = "perform action, if given condition is not false or null", args = { @@ -443,6 +454,7 @@ proc defineSymbols*() = builtin "if?", alias = unaliased, + op = opIfE, rule = PrefixPrecedence, description = "perform action, if given condition is not false or null and return condition result", args = { @@ -479,6 +491,7 @@ proc defineSymbols*() = builtin "let", alias = colon, + op = opNop, rule = InfixPrecedence, description = "set symbol to given value", args = { @@ -529,6 +542,7 @@ proc defineSymbols*() = builtin "new", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "create new value by cloning given one", args = { @@ -557,6 +571,7 @@ proc defineSymbols*() = builtin "pop", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "pop top values from stack", args = { @@ -598,6 +613,7 @@ proc defineSymbols*() = builtin "return", alias = unaliased, + op = opReturn, rule = PrefixPrecedence, description = "return given value from current function", args = { @@ -622,6 +638,7 @@ proc defineSymbols*() = builtin "switch", alias = question, + op = opSwitch, rule = InfixPrecedence, description = "if condition is not false or null perform given action, otherwise perform alternative action", args = { @@ -647,6 +664,7 @@ proc defineSymbols*() = builtin "try", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "perform action and catch possible errors", args = { @@ -675,6 +693,7 @@ proc defineSymbols*() = builtin "try?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "perform action, catch possible errors and return status", args = { @@ -709,6 +728,7 @@ proc defineSymbols*() = builtin "unless", alias = unaliased, + op = opUnless, rule = PrefixPrecedence, description = "perform action, if given condition is false or null", args = { @@ -730,6 +750,7 @@ proc defineSymbols*() = builtin "unless?", alias = unaliased, + op = opUnlessE, rule = PrefixPrecedence, description = "perform action, if given condition is false or null and return condition result", args = { @@ -766,6 +787,7 @@ proc defineSymbols*() = builtin "until", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "execute action until the given condition is not false or null", args = { @@ -810,6 +832,7 @@ proc defineSymbols*() = builtin "var", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get symbol value by given name", args = { @@ -832,6 +855,7 @@ proc defineSymbols*() = builtin "when?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if a specific condition is fulfilled and, if so, execute given action", args = { @@ -872,6 +896,7 @@ proc defineSymbols*() = builtin "while", alias = unaliased, + op = opWhile, rule = PrefixPrecedence, description = "execute action while the given condition is is not false or null", args = { From d547cad36c11cbba7130c7e5f7a50c371592baff Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:31:48 +0100 Subject: [PATCH 381/984] Crypto: setting opcodes --- src/library/Crypto.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/library/Crypto.nim b/src/library/Crypto.nim index cec166377e..6449039b12 100644 --- a/src/library/Crypto.nim +++ b/src/library/Crypto.nim @@ -45,6 +45,7 @@ proc defineSymbols*() = builtin "crc", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the CRC32 polynomial of given string", args = { @@ -65,6 +66,7 @@ proc defineSymbols*() = builtin "decode", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "encode given value (default: base-64)", args = { @@ -100,6 +102,7 @@ proc defineSymbols*() = # labels: library, open discussion builtin "encode", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "decode given value (default: base-64)", args = { @@ -173,6 +176,7 @@ proc defineSymbols*() = # labels: library,enhancement,open discussion,web builtin "digest", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get digest for given value (default: MD5)", args = { @@ -205,6 +209,7 @@ proc defineSymbols*() = builtin "hash", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get hash for given value", args = { From 3c50106ed910a29b01be1126b9257ae520da20a6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:31:57 +0100 Subject: [PATCH 382/984] Databases: setting opcodes --- src/library/Databases.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/library/Databases.nim b/src/library/Databases.nim index 62f4516e16..fe00a1e773 100644 --- a/src/library/Databases.nim +++ b/src/library/Databases.nim @@ -51,6 +51,7 @@ proc defineSymbols*() = builtin "close", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "close given database", args = { @@ -73,6 +74,7 @@ proc defineSymbols*() = builtin "open", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "opens a new database connection and returns database", args = { @@ -101,6 +103,7 @@ proc defineSymbols*() = builtin "query", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "execute command or block of commands in given database and get returned rows", args = { From 4a4ba51b139f37520da8de1a9aa5e11eafafaeaf Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:32:05 +0100 Subject: [PATCH 383/984] Dates: setting opcodes --- src/library/Dates.nim | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/library/Dates.nim b/src/library/Dates.nim index a7e3776b3f..b2d7ce12e1 100644 --- a/src/library/Dates.nim +++ b/src/library/Dates.nim @@ -35,6 +35,7 @@ proc defineSymbols*() = builtin "after", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get date after given one using interval", args = { @@ -94,6 +95,7 @@ proc defineSymbols*() = builtin "before", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get date before given one using interval", args = { @@ -156,6 +158,7 @@ proc defineSymbols*() = builtin "friday?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is a Friday", args = { @@ -171,6 +174,7 @@ proc defineSymbols*() = builtin "future?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is in the future", args = { @@ -189,6 +193,7 @@ proc defineSymbols*() = builtin "leap?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given year is a leap year", args = { @@ -210,6 +215,7 @@ proc defineSymbols*() = builtin "monday?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is a Monday", args = { @@ -225,6 +231,7 @@ proc defineSymbols*() = builtin "now", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get date/time now", args = NoArgs, @@ -257,6 +264,7 @@ proc defineSymbols*() = builtin "past?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is in the past", args = { @@ -278,6 +286,7 @@ proc defineSymbols*() = builtin "saturday?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is a Saturday", args = { @@ -292,7 +301,8 @@ proc defineSymbols*() = push(newLogical(x.eobj.weekday == dSat)) builtin "sunday?", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is a Sunday", args = { @@ -308,6 +318,7 @@ proc defineSymbols*() = builtin "thursday?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is a Thursday", args = { @@ -322,7 +333,8 @@ proc defineSymbols*() = push(newLogical(x.eobj.weekday == dThu)) builtin "today?", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is today", args = { @@ -343,6 +355,7 @@ proc defineSymbols*() = builtin "tuesday?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is a Tuesday", args = { @@ -358,6 +371,7 @@ proc defineSymbols*() = builtin "wednesday?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given date is a Wednesday", args = { From daa54b648aa6acbd4925cc50dac60b2ffe7e833c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:32:13 +0100 Subject: [PATCH 384/984] Files: setting opcodes --- src/library/Files.nim | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/library/Files.nim b/src/library/Files.nim index 04392e6039..a693594281 100644 --- a/src/library/Files.nim +++ b/src/library/Files.nim @@ -54,6 +54,7 @@ proc defineSymbols*() = builtin "copy", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "copy file at path to given destination", args = { @@ -88,6 +89,7 @@ proc defineSymbols*() = builtin "delete", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "delete file at given path", args = { @@ -114,6 +116,7 @@ proc defineSymbols*() = builtin "exists?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given file exists", args = { @@ -138,6 +141,7 @@ proc defineSymbols*() = builtin "hidden?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if file/folder at given path is hidden", args = { @@ -156,6 +160,7 @@ proc defineSymbols*() = builtin "move", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "move file at path to given destination", args = { @@ -190,6 +195,7 @@ proc defineSymbols*() = builtin "permissions", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check permissions of given file", args = { @@ -270,6 +276,7 @@ proc defineSymbols*() = builtin "read", alias = doublearrowleft, + op = opNop, rule = PrefixPrecedence, description = "read file from given path", args = { @@ -360,6 +367,7 @@ proc defineSymbols*() = builtin "rename", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "rename file at path using given new path name", args = { @@ -391,7 +399,8 @@ proc defineSymbols*() = discard builtin "symlink", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "create symbolic link of file to given destination", args = { @@ -428,6 +437,7 @@ proc defineSymbols*() = builtin "timestamp", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get file timestamps", args = { @@ -454,6 +464,7 @@ proc defineSymbols*() = builtin "unzip", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "unzip given archive to destination", args = { @@ -472,6 +483,7 @@ proc defineSymbols*() = builtin "volume", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get file size for given path", args = { @@ -491,6 +503,7 @@ proc defineSymbols*() = builtin "write", alias = doublearrowright, + op = opNop, rule = PrefixPrecedence, description = "write content to file at given path", args = { @@ -540,6 +553,7 @@ proc defineSymbols*() = builtin "zip", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "zip given files to file at destination", args = { From 40ecf2126d8a1d8d85a0225ebd3e49685367bbc9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:32:20 +0100 Subject: [PATCH 385/984] Io: setting opcodes --- src/library/Io.nim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/library/Io.nim b/src/library/Io.nim index 1a7dc5b8a8..f933cea9de 100644 --- a/src/library/Io.nim +++ b/src/library/Io.nim @@ -51,6 +51,7 @@ proc defineSymbols*() = builtin "clear", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "clear terminal", args = NoArgs, @@ -64,6 +65,7 @@ proc defineSymbols*() = builtin "color", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get colored version of given string", args = { @@ -128,6 +130,7 @@ proc defineSymbols*() = when not defined(WEB): builtin "cursor", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "turn cursor visibility on/off", args = { @@ -147,6 +150,7 @@ proc defineSymbols*() = builtin "goto", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "move cursor to given coordinates", args = { @@ -176,6 +180,7 @@ proc defineSymbols*() = builtin "input", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "print prompt and get user input", args = { @@ -245,6 +250,7 @@ proc defineSymbols*() = builtin "print", alias = unaliased, + op = opPrint, rule = PrefixPrecedence, description = "print given value to screen with newline", args = { @@ -283,7 +289,8 @@ proc defineSymbols*() = echo $(x) builtin "prints", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "print given value to screen", args = { @@ -323,6 +330,7 @@ proc defineSymbols*() = when not defined(WEB): builtin "terminal", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get info about terminal", args = NoArgs, From 27ebaf03ed92f2f0faa7a083fc50621151b8fb16 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:32:30 +0100 Subject: [PATCH 386/984] Iterators: setting opcodes --- src/library/Iterators.nim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/library/Iterators.nim b/src/library/Iterators.nim index 7b286bb5a6..6449000520 100644 --- a/src/library/Iterators.nim +++ b/src/library/Iterators.nim @@ -409,6 +409,7 @@ proc defineSymbols*() = builtin "arrange", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "sort items in collection using given action, in ascending order", args = { @@ -466,6 +467,7 @@ proc defineSymbols*() = builtin "chunk", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "chunk together consecutive items in collection that abide by given predicate", args = { @@ -519,6 +521,7 @@ proc defineSymbols*() = builtin "cluster", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "group together items in collection that abide by given predicate", args = { @@ -577,6 +580,7 @@ proc defineSymbols*() = builtin "collect", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "collect items from given collection condition while is true", args = { @@ -654,6 +658,7 @@ proc defineSymbols*() = builtin "enumerate", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the number of given collection's items that satisfy condition", args = { @@ -683,6 +688,7 @@ proc defineSymbols*() = builtin "every?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if every item in collection satisfies given condition", args = { @@ -723,6 +729,7 @@ proc defineSymbols*() = builtin "filter", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get collection's items by filtering those that do not fulfil given condition", args = { @@ -855,6 +862,7 @@ proc defineSymbols*() = builtin "fold", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "left-fold given collection returning accumulator", args = { @@ -970,6 +978,7 @@ proc defineSymbols*() = builtin "gather", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "group items in collection by block result and return as dictionary", args = { @@ -1008,6 +1017,7 @@ proc defineSymbols*() = builtin "loop", alias = unaliased, + op = opLoop, rule = PrefixPrecedence, description = "loop through collection, using given iterator and block", args = { @@ -1074,6 +1084,7 @@ proc defineSymbols*() = builtin "map", alias = unaliased, + op = opMap, rule = PrefixPrecedence, description = "map collection's items by applying given action", args = { @@ -1137,6 +1148,7 @@ proc defineSymbols*() = builtin "maximum", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get maximum item from collection based on given predicate", args = { @@ -1190,6 +1202,7 @@ proc defineSymbols*() = builtin "minimum", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get minimum item from collection based on given predicate", args = { @@ -1243,6 +1256,7 @@ proc defineSymbols*() = builtin "select", alias = unaliased, + op = opSelect, rule = PrefixPrecedence, description = "get collection's items that fulfil given condition", args = { @@ -1390,6 +1404,7 @@ proc defineSymbols*() = builtin "some?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if any of collection's items satisfy given condition", args = { From 4125c725c04ab035392664002bc65cb2eb683553 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:47:22 +0100 Subject: [PATCH 387/984] Logic: setting opcodes --- src/library/Logic.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/library/Logic.nim b/src/library/Logic.nim index 60eedfd327..b4f598ee0a 100644 --- a/src/library/Logic.nim +++ b/src/library/Logic.nim @@ -30,6 +30,7 @@ proc defineSymbols*() = builtin "all?", alias = unaliased, + op = opNot, rule = PrefixPrecedence, description = "check if all values in given block are true", args = { @@ -72,6 +73,7 @@ proc defineSymbols*() = builtin "and?", alias = logicaland, + op = opAnd, rule = InfixPrecedence, description = "return the logical AND for the given values", args = { @@ -119,6 +121,7 @@ proc defineSymbols*() = builtin "any?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if any of the values in given block is true", args = { @@ -165,6 +168,7 @@ proc defineSymbols*() = builtin "false?", alias = unaliased, + op = opNop, rule = InfixPrecedence, description = "returns true if given value is false; otherwise, it returns false", args = { @@ -190,6 +194,7 @@ proc defineSymbols*() = builtin "nand?", alias = logicalnand, + op = opNop, rule = InfixPrecedence, description = "return the logical NAND for the given values", args = { @@ -240,6 +245,7 @@ proc defineSymbols*() = builtin "nor?", alias = unaliased, + op = opNop, rule = InfixPrecedence, description = "return the logical NOR for the given values", args = { @@ -290,6 +296,7 @@ proc defineSymbols*() = builtin "not?", alias = logicalnot, + op = opNot, rule = PrefixPrecedence, description = "return the logical complement of the given value", args = { @@ -314,6 +321,7 @@ proc defineSymbols*() = builtin "or?", alias = logicalor, + op = opOr, rule = InfixPrecedence, description = "return the logical OR for the given values", args = { @@ -366,6 +374,7 @@ proc defineSymbols*() = builtin "true?", alias = unaliased, + op = opNop, rule = InfixPrecedence, description = "returns true if given value is true; otherwise, it returns false", args = { @@ -386,6 +395,7 @@ proc defineSymbols*() = builtin "xnor?", alias = unaliased, + op = opNop, rule = InfixPrecedence, description = "return the logical XNOR for the given values", args = { @@ -426,6 +436,7 @@ proc defineSymbols*() = builtin "xor?", alias = logicalxor, + op = opNop, rule = InfixPrecedence, description = "return the logical XOR for the given values", args = { From cfce9f8cc3ab586e95666670757c245ec7404a00 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:47:31 +0100 Subject: [PATCH 388/984] Net: setting opcodes --- src/library/Net.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/library/Net.nim b/src/library/Net.nim index 3e10cdd2fa..7278da2bf4 100644 --- a/src/library/Net.nim +++ b/src/library/Net.nim @@ -47,6 +47,7 @@ proc defineSymbols*() = builtin "browse", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "open given URL with default browser", args = { @@ -64,6 +65,7 @@ proc defineSymbols*() = builtin "download", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "download file from url to disk", args = { @@ -98,6 +100,7 @@ proc defineSymbols*() = builtin "mail", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "send mail using given title and message to selected recipient", args = { @@ -140,6 +143,7 @@ proc defineSymbols*() = # labels: library,enhancement,open discussion,web builtin "request", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "perform HTTP request to url with given data and get response", args = { @@ -315,6 +319,7 @@ proc defineSymbols*() = builtin "serve", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "start web server using given routes", args = { From 36fe8a22934ee2e4886147777254e542473b3a38 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:47:40 +0100 Subject: [PATCH 389/984] Numbers: setting opcodes --- src/library/Numbers.nim | 62 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/library/Numbers.nim b/src/library/Numbers.nim index 6873ffde74..88c69cb965 100644 --- a/src/library/Numbers.nim +++ b/src/library/Numbers.nim @@ -52,6 +52,7 @@ proc defineSymbols*() = builtin "abs", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get the absolute value for given integer", args = { @@ -82,6 +83,7 @@ proc defineSymbols*() = builtin "acos", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse cosine of given angle", args = { @@ -102,6 +104,7 @@ proc defineSymbols*() = builtin "acosh", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse hyperbolic cosine of given angle", args = { @@ -122,6 +125,7 @@ proc defineSymbols*() = builtin "acsec", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse cosecant of given angle", args = { @@ -142,6 +146,7 @@ proc defineSymbols*() = builtin "acsech", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse hyperbolic cosecant of given angle", args = { @@ -162,6 +167,7 @@ proc defineSymbols*() = builtin "actan", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse cotangent of given angle", args = { @@ -182,6 +188,7 @@ proc defineSymbols*() = builtin "actanh", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse hyperbolic cotangent of given angle", args = { @@ -202,6 +209,7 @@ proc defineSymbols*() = builtin "angle", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the phase angle of given number", args = { @@ -218,6 +226,7 @@ proc defineSymbols*() = builtin "asec", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse secant of given angle", args = { @@ -237,7 +246,8 @@ proc defineSymbols*() = processTrigonometric(arcsec) builtin "asech", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse hyperbolic secant of given angle", args = { @@ -258,6 +268,7 @@ proc defineSymbols*() = builtin "asin", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse sine of given angle", args = { @@ -278,6 +289,7 @@ proc defineSymbols*() = builtin "asinh", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse hyperbolic sine of given angle", args = { @@ -298,6 +310,7 @@ proc defineSymbols*() = builtin "atan", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse tangent of given angle", args = { @@ -318,6 +331,7 @@ proc defineSymbols*() = builtin "atan2", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse tangent of y / x", args = { @@ -335,6 +349,7 @@ proc defineSymbols*() = builtin "atanh", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the inverse hyperbolic tangent of given angle", args = { @@ -355,6 +370,7 @@ proc defineSymbols*() = builtin "ceil", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the smallest integer not smaller than given value", args = { @@ -373,6 +389,7 @@ proc defineSymbols*() = builtin "clamp", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "force value within given range", args = { @@ -397,6 +414,7 @@ proc defineSymbols*() = builtin "conj", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the complex conjugate of given number", args = { @@ -413,6 +431,7 @@ proc defineSymbols*() = builtin "cos", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the cosine of given angle", args = { @@ -433,6 +452,7 @@ proc defineSymbols*() = builtin "cosh", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the hyperbolic cosine of given angle", args = { @@ -453,6 +473,7 @@ proc defineSymbols*() = builtin "csec", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the cosecant of given angle", args = { @@ -473,6 +494,7 @@ proc defineSymbols*() = builtin "csech", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the hyperbolic cosecant of given angle", args = { @@ -493,6 +515,7 @@ proc defineSymbols*() = builtin "ctan", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the cotangent of given angle", args = { @@ -512,7 +535,8 @@ proc defineSymbols*() = processTrigonometric(cot) builtin "ctanh", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the hyperbolic cotangent of given angle", args = { @@ -533,6 +557,7 @@ proc defineSymbols*() = builtin "denominator", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get the denominator of given number", args = { @@ -562,6 +587,7 @@ proc defineSymbols*() = builtin "digits", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get array of digits of given number", args = { @@ -602,6 +628,7 @@ proc defineSymbols*() = builtin "even?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given number is even", args = { @@ -620,6 +647,7 @@ proc defineSymbols*() = builtin "exp", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the exponential function for given value", args = { @@ -641,6 +669,7 @@ proc defineSymbols*() = builtin "factorial", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the factorial of given value", args = { @@ -658,6 +687,7 @@ proc defineSymbols*() = builtin "factors", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get list of factors for given integer", args = { @@ -699,6 +729,7 @@ proc defineSymbols*() = builtin "floor", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the largest integer not greater than given value", args = { @@ -718,6 +749,7 @@ proc defineSymbols*() = when not defined(WEB): builtin "gamma", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the gamma function for given value", args = { @@ -735,6 +767,7 @@ proc defineSymbols*() = builtin "gcd", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate greatest common divisor for given collection of integers", args = { @@ -771,6 +804,7 @@ proc defineSymbols*() = builtin "hypot", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the hypotenuse of a right-angle triangle with given base and height", args = { @@ -796,6 +830,7 @@ proc defineSymbols*() = builtin "infinite?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check whether given value is an infinite one", args = { @@ -812,7 +847,8 @@ proc defineSymbols*() = push(VFALSE) builtin "lcm", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate least common multiplier for given collection of integers", args = { @@ -849,6 +885,7 @@ proc defineSymbols*() = builtin "ln", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the natural logarithm of given value", args = { @@ -870,6 +907,7 @@ proc defineSymbols*() = builtin "log", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the logarithm of value using given base", args = { @@ -889,6 +927,7 @@ proc defineSymbols*() = builtin "negative?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given number is negative", args = { @@ -918,6 +957,7 @@ proc defineSymbols*() = builtin "numerator", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get the numerator of given number", args = { @@ -947,6 +987,7 @@ proc defineSymbols*() = builtin "odd?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given number is odd", args = { @@ -970,6 +1011,7 @@ proc defineSymbols*() = builtin "positive?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given number is positive", args = { @@ -1002,6 +1044,7 @@ proc defineSymbols*() = # labels: web,enhancement builtin "powmod", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "modular exponentation: calculate the result of (base^exponent) % divider", args = { @@ -1027,6 +1070,7 @@ proc defineSymbols*() = builtin "prime?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given integer is prime", args = { @@ -1057,6 +1101,7 @@ proc defineSymbols*() = builtin "product", alias = product, + op = opNop, rule = PrefixPrecedence, description = "calculate the product of all values in given list", args = { @@ -1096,6 +1141,7 @@ proc defineSymbols*() = builtin "random", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get a random integer between given limits", args = { @@ -1115,6 +1161,7 @@ proc defineSymbols*() = builtin "reciprocal", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the reciprocal of given number", args = { @@ -1141,6 +1188,7 @@ proc defineSymbols*() = builtin "round", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "round given value", args = { @@ -1169,6 +1217,7 @@ proc defineSymbols*() = builtin "sec", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the secant of given angle", args = { @@ -1189,6 +1238,7 @@ proc defineSymbols*() = builtin "sech", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the hyperbolic secant of given angle", args = { @@ -1209,6 +1259,7 @@ proc defineSymbols*() = builtin "sin", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the sine of given angle", args = { @@ -1229,6 +1280,7 @@ proc defineSymbols*() = builtin "sinh", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the hyperbolic sine of given angle", args = { @@ -1249,6 +1301,7 @@ proc defineSymbols*() = builtin "sqrt", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get square root of given value", args = { @@ -1280,6 +1333,7 @@ proc defineSymbols*() = builtin "sum", alias = summation, + op = opNop, rule = PrefixPrecedence, description = "calculate the sum of all values in given list", args = { @@ -1309,6 +1363,7 @@ proc defineSymbols*() = builtin "tan", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the tangent of given angle", args = { @@ -1329,6 +1384,7 @@ proc defineSymbols*() = builtin "tanh", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate the hyperbolic tangent of given angle", args = { From 73910f8812e0e366688cabe02984abbca7089d65 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:47:58 +0100 Subject: [PATCH 390/984] Paths: setting opcodes + fixed alias for `normalize` --- src/library/Paths.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/library/Paths.nim b/src/library/Paths.nim index 685d8ffc4a..5950ae78e2 100644 --- a/src/library/Paths.nim +++ b/src/library/Paths.nim @@ -41,6 +41,7 @@ proc defineSymbols*() = builtin "absolute?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given path is an absolute path", args = { @@ -59,6 +60,7 @@ proc defineSymbols*() = # labels: library,enhancement,web builtin "extract", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "extract components from path", args = { @@ -204,6 +206,7 @@ proc defineSymbols*() = builtin "list", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get files in given path", args = { @@ -245,6 +248,7 @@ proc defineSymbols*() = # labels: library, package manager, enhancement builtin "module", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get path for given module name", args = { @@ -264,7 +268,8 @@ proc defineSymbols*() = push(newString(HomeDir & ".arturo/lib/" & x.s & ".art")) builtin "normalize", - alias = dotslash, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get normalized version of given path", args = { @@ -325,6 +330,7 @@ proc defineSymbols*() = builtin "relative", alias = dotslash, + op = opNop, rule = PrefixPrecedence, description = "get relative path for given path, based on current script's location", args = { From 14eed8f323ea73251af44ec6ea116ac84a0760e5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:48:06 +0100 Subject: [PATCH 391/984] Reflection: setting opcodes --- src/library/Reflection.nim | 47 +++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/library/Reflection.nim b/src/library/Reflection.nim index f99f03128b..4782df6f38 100644 --- a/src/library/Reflection.nim +++ b/src/library/Reflection.nim @@ -36,6 +36,7 @@ proc defineSymbols*() = builtin "arity", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get index of function arities", args = NoArgs, @@ -54,6 +55,7 @@ proc defineSymbols*() = builtin "attr", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get given attribute, if it exists", args = { @@ -86,6 +88,7 @@ proc defineSymbols*() = builtin "attr?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given attribute exists", args = { @@ -115,6 +118,7 @@ proc defineSymbols*() = builtin "attribute?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :attribute", args = { @@ -131,6 +135,7 @@ proc defineSymbols*() = builtin "attributeLabel?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :attributeLabel", args = { @@ -147,6 +152,7 @@ proc defineSymbols*() = builtin "attrs", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get dictionary of set attributes", args = NoArgs, @@ -170,6 +176,7 @@ proc defineSymbols*() = builtin "benchmark", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "benchmark given code", args = { @@ -205,6 +212,7 @@ proc defineSymbols*() = builtin "binary?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :binary", args = { @@ -221,6 +229,7 @@ proc defineSymbols*() = builtin "block?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :block", args = { @@ -239,6 +248,7 @@ proc defineSymbols*() = builtin "bytecode?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :bytecode", args = { @@ -257,7 +267,8 @@ proc defineSymbols*() = push(newLogical(x.kind==Bytecode)) builtin "char?", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :char", args = { @@ -274,6 +285,7 @@ proc defineSymbols*() = builtin "color?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :color", args = { @@ -292,6 +304,7 @@ proc defineSymbols*() = builtin "complex?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :complex", args = { @@ -310,6 +323,7 @@ proc defineSymbols*() = builtin "database?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :database", args = { @@ -326,6 +340,7 @@ proc defineSymbols*() = builtin "date?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :date", args = { @@ -342,6 +357,7 @@ proc defineSymbols*() = builtin "dictionary?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :dictionary", args = { @@ -360,6 +376,7 @@ proc defineSymbols*() = builtin "info", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "print info for given symbol", args = { @@ -424,6 +441,7 @@ proc defineSymbols*() = builtin "inline?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :inline", args = { @@ -440,6 +458,7 @@ proc defineSymbols*() = builtin "inspect", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "print full dump of given value to screen", args = { @@ -463,6 +482,7 @@ proc defineSymbols*() = builtin "integer?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :integer", args = { @@ -487,6 +507,7 @@ proc defineSymbols*() = builtin "is?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check whether value is of given type", args = { @@ -538,6 +559,7 @@ proc defineSymbols*() = builtin "floating?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :floating", args = { @@ -555,6 +577,7 @@ proc defineSymbols*() = builtin "function?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :function", args = { @@ -585,6 +608,7 @@ proc defineSymbols*() = builtin "label?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :label", args = { @@ -601,6 +625,7 @@ proc defineSymbols*() = builtin "literal?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :literal", args = { @@ -618,6 +643,7 @@ proc defineSymbols*() = builtin "logical?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :logical", args = { @@ -638,6 +664,7 @@ proc defineSymbols*() = builtin "null?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :null", args = { @@ -656,6 +683,7 @@ proc defineSymbols*() = builtin "object?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is a custom-type object", args = { @@ -676,6 +704,7 @@ proc defineSymbols*() = builtin "path?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :path", args = { @@ -692,6 +721,7 @@ proc defineSymbols*() = builtin "pathLabel?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :pathLabel", args = { @@ -708,6 +738,7 @@ proc defineSymbols*() = builtin "quantity?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :quantity", args = { @@ -726,6 +757,7 @@ proc defineSymbols*() = builtin "range?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :range", args = { @@ -744,6 +776,7 @@ proc defineSymbols*() = builtin "rational?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :rational", args = { @@ -762,6 +795,7 @@ proc defineSymbols*() = builtin "regex?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :regex", args = { @@ -779,6 +813,7 @@ proc defineSymbols*() = builtin "set?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given variable is defined", args = { @@ -797,6 +832,7 @@ proc defineSymbols*() = builtin "stack", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get current stack", args = NoArgs, @@ -813,6 +849,7 @@ proc defineSymbols*() = builtin "standalone?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if current script runs from the command-line", args = NoArgs, @@ -833,6 +870,7 @@ proc defineSymbols*() = builtin "string?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :string", args = { @@ -850,6 +888,7 @@ proc defineSymbols*() = builtin "symbol?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :symbol", args = { @@ -866,6 +905,7 @@ proc defineSymbols*() = builtin "symbolLiteral?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :symbolLiteral", args = { @@ -882,6 +922,7 @@ proc defineSymbols*() = builtin "symbols", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get currently defined symbols", args = NoArgs, @@ -907,6 +948,7 @@ proc defineSymbols*() = builtin "type", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get type of given value", args = { @@ -926,6 +968,7 @@ proc defineSymbols*() = builtin "type?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :type", args = { @@ -943,6 +986,7 @@ proc defineSymbols*() = builtin "version?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :version", args = { @@ -959,6 +1003,7 @@ proc defineSymbols*() = builtin "word?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "checks if given value is of type :word", args = { From 8c119e78fa5e23793853689c21cafd3a6cca474a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:48:11 +0100 Subject: [PATCH 392/984] Sets: setting opcodes --- src/library/Sets.nim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/library/Sets.nim b/src/library/Sets.nim index 291b154f04..b767b468b0 100644 --- a/src/library/Sets.nim +++ b/src/library/Sets.nim @@ -57,6 +57,7 @@ proc defineSymbols*() = builtin "difference", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "return the difference of given sets", args = { @@ -95,6 +96,7 @@ proc defineSymbols*() = builtin "disjoint?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given sets are disjoint (they have no common elements)", args = { @@ -115,6 +117,7 @@ proc defineSymbols*() = builtin "intersect?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given sets intersect (they have at least one common element)", args = { @@ -142,6 +145,7 @@ proc defineSymbols*() = builtin "intersection", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "return the intersection of given sets", args = { @@ -168,6 +172,7 @@ proc defineSymbols*() = builtin "powerset", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "return the powerset of given set", args = { @@ -188,6 +193,7 @@ proc defineSymbols*() = builtin "subset?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given set is a subset of second set", args = { @@ -244,6 +250,7 @@ proc defineSymbols*() = builtin "superset?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given set is a superset of second set", args = { @@ -300,6 +307,7 @@ proc defineSymbols*() = builtin "union", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "return the union of given sets", args = { From 9ca7962c30cf2b6c6c188d525d1dba7493433ef5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:48:18 +0100 Subject: [PATCH 393/984] Sockets: setting opcodes --- src/library/Sockets.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/library/Sockets.nim b/src/library/Sockets.nim index ea2794e01b..56f6ab603d 100644 --- a/src/library/Sockets.nim +++ b/src/library/Sockets.nim @@ -45,7 +45,8 @@ proc defineSymbols*() = when not defined(WEB): builtin "accept", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "accept incoming connection and return corresponding socket", args = { @@ -73,6 +74,7 @@ proc defineSymbols*() = builtin "connect", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "create new socket connection to given server port", args = { @@ -120,6 +122,7 @@ proc defineSymbols*() = builtin "listen", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "start listening on given port and return new socket", args = { @@ -157,6 +160,7 @@ proc defineSymbols*() = builtin "receive", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "receive line of data from selected socket", args = { @@ -202,6 +206,7 @@ proc defineSymbols*() = builtin "send", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "send given message to selected socket", args = { @@ -232,6 +237,7 @@ proc defineSymbols*() = builtin "send?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "send given message to selected socket and return true if successful", args = { @@ -257,6 +263,7 @@ proc defineSymbols*() = builtin "unplug", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "close given socket", args = { From a21d38407306cf5ffd0c67b302d73dadfd1f5580 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:48:28 +0100 Subject: [PATCH 394/984] Statistics: setting opcodes --- src/library/Statistics.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/library/Statistics.nim b/src/library/Statistics.nim index a1fdf27360..69df0d80dd 100644 --- a/src/library/Statistics.nim +++ b/src/library/Statistics.nim @@ -38,6 +38,7 @@ proc defineSymbols*() = builtin "average", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get average from given collection of numbers", args = { @@ -67,6 +68,7 @@ proc defineSymbols*() = builtin "deviation", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get population standard deviation of given collection of numbers", args = { @@ -95,6 +97,7 @@ proc defineSymbols*() = builtin "kurtosis", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get population kurtosis of given collection of numbers", args = { @@ -123,6 +126,7 @@ proc defineSymbols*() = builtin "median", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get median from given collection of numbers", args = { @@ -152,6 +156,7 @@ proc defineSymbols*() = builtin "skewness", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get population skewness of given collection of numbers", args = { @@ -180,6 +185,7 @@ proc defineSymbols*() = builtin "variance", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get population variance of given collection of numbers", args = { From a625227679b3c3f18ce70cc13829f6413ae5f95c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:48:35 +0100 Subject: [PATCH 395/984] Strings: setting opcodes --- src/library/Strings.nim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/library/Strings.nim b/src/library/Strings.nim index 8c492d811b..55fabb137d 100644 --- a/src/library/Strings.nim +++ b/src/library/Strings.nim @@ -67,6 +67,7 @@ proc defineSymbols*() = # labels: library, enhancement, cleanup, open discussion builtin "alphabet", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get dictionary-index charset for given locale", args = { @@ -110,6 +111,7 @@ proc defineSymbols*() = builtin "ascii?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given character/string is in ASCII", args = { @@ -142,6 +144,7 @@ proc defineSymbols*() = builtin "capitalize", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "convert given string to capitalized", args = { @@ -167,6 +170,7 @@ proc defineSymbols*() = builtin "escape", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "escape given string", args = { @@ -226,6 +230,7 @@ proc defineSymbols*() = builtin "indent", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "indent each line of given text", args = { @@ -267,6 +272,7 @@ proc defineSymbols*() = builtin "jaro", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate Jaro distance/similarity between given strings", args = { @@ -288,6 +294,7 @@ proc defineSymbols*() = builtin "join", alias = unaliased, + op = opJoin, rule = PrefixPrecedence, description = "join collection of values into string", args = { @@ -337,6 +344,7 @@ proc defineSymbols*() = builtin "levenshtein", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "calculate Levenshtein distance/similarity between given strings", args = { @@ -367,6 +375,7 @@ proc defineSymbols*() = builtin "lower", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "convert given string to lowercase", args = { @@ -396,6 +405,7 @@ proc defineSymbols*() = builtin "lower?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given string is lowercase", args = { @@ -428,6 +438,7 @@ proc defineSymbols*() = when not defined(WEB): builtin "match", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get matches within string, using given regular expression", args = { @@ -558,6 +569,7 @@ proc defineSymbols*() = # labels: library, web, bug builtin "match?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if string matches given regular expression", args = { @@ -603,6 +615,7 @@ proc defineSymbols*() = builtin "numeric?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given string is numeric", args = { @@ -628,6 +641,7 @@ proc defineSymbols*() = builtin "outdent", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "outdent each line of given text, by using minimum shared indentation", args = { @@ -682,6 +696,7 @@ proc defineSymbols*() = builtin "pad", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "align string by adding given padding", args = { @@ -728,6 +743,7 @@ proc defineSymbols*() = builtin "prefix?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if string starts with given prefix", args = { @@ -752,6 +768,7 @@ proc defineSymbols*() = # labels: enhancement,library,web builtin "render", alias = tilde, + op = opNop, rule = PrefixPrecedence, description = "render template with |string| interpolation", args = { @@ -841,6 +858,7 @@ proc defineSymbols*() = builtin "replace", alias = unaliased, + op = opReplace, rule = PrefixPrecedence, description = "replace every matched substring/s by given replacement string and return result", args = { @@ -896,6 +914,7 @@ proc defineSymbols*() = builtin "strip", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "strip whitespace from given string", args = { @@ -932,6 +951,7 @@ proc defineSymbols*() = builtin "suffix?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if string ends with given suffix", args = { @@ -952,6 +972,7 @@ proc defineSymbols*() = builtin "translate", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "takes a dictionary of translations and replaces each instance sequentially", args = { @@ -980,6 +1001,7 @@ proc defineSymbols*() = builtin "truncate", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "truncate string at given length", args = { @@ -1024,6 +1046,7 @@ proc defineSymbols*() = builtin "upper", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "convert given string to uppercase", args = { @@ -1053,6 +1076,7 @@ proc defineSymbols*() = builtin "upper?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given string is uppercase", args = { @@ -1082,6 +1106,7 @@ proc defineSymbols*() = builtin "wordwrap", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "word wrap a given string", args = { @@ -1122,6 +1147,7 @@ proc defineSymbols*() = builtin "whitespace?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if given string consists only of whitespace", args = { From 998df451281631bd08f95d672ed405ce5fa8f67e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:48:42 +0100 Subject: [PATCH 396/984] System: setting opcodes --- src/library/System.nim | 89 +++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/src/library/System.nim b/src/library/System.nim index b2fb97f30d..73cf465ea5 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -70,6 +70,7 @@ proc defineSymbols*() = # labels: library,enhancement,open discussion,web builtin "env", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get environment variables", args = NoArgs, @@ -100,6 +101,7 @@ proc defineSymbols*() = # labels: library,enhancement,web builtin "execute", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "execute given shell command", args = { @@ -170,6 +172,7 @@ proc defineSymbols*() = builtin "exit", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "exit program", args = NoArgs, @@ -194,6 +197,7 @@ proc defineSymbols*() = builtin "panic", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "exit program with error message", args = { @@ -233,6 +237,7 @@ proc defineSymbols*() = # labels: library,enhancement,web builtin "pause", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "pause program's execution~for the given amount of time", args = { @@ -261,6 +266,7 @@ proc defineSymbols*() = builtin "process", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get information on current process/program", args = NoArgs, @@ -306,6 +312,7 @@ proc defineSymbols*() = when not defined(WEB): builtin "superuser?", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "check if current user has administrator/root privileges", args = NoArgs, @@ -322,50 +329,52 @@ proc defineSymbols*() = push newLogical(isAdmin()) builtin "sys", - alias = unaliased, - rule = PrefixPrecedence, - description = "get current system information", - args = NoArgs, - attrs = NoAttrs, - returns = {Dictionary}, - example = """ - inspect sys - ;[ :dictionary - ; author : Yanis ZafirΓ³pulos :string - ; copyright : (c) 2019-2022 :string - ; version : 0.9.80 :version - ; build : 3246 :integer - ; buildDate : [ :date - ; hour : 11 :integer - ; minute : 27 :integer - ; second : 54 :integer - ; nanosecond : 389131000 :integer - ; day : 7 :integer - ; Day : Wednesday :string - ; days : 340 :integer - ; month : 12 :integer - ; Month : December :string - ; year : 2022 :integer - ; utc : -3600 :integer - ; ] - ; deps : [ :dictionary - ; gmp : 6.2.1 :version - ; mpfr : 4.1.0 :version - ; sqlite : 3.37.0 :version - ; pcre : 8.45.0 :version - ; ] - ; binary : /Users/drkameleon/OpenSource/arturo-lang/arturo/bin/arturo :string - ; cpu : amd64 :string - ; os : macosx :string - ; release : full :literal - ;] - """: - #======================================================= - push newDictionary(getSystemInfo()) + alias = unaliased, + op = opNop, + rule = PrefixPrecedence, + description = "get current system information", + args = NoArgs, + attrs = NoAttrs, + returns = {Dictionary}, + example = """ + inspect sys + ;[ :dictionary + ; author : Yanis ZafirΓ³pulos :string + ; copyright : (c) 2019-2022 :string + ; version : 0.9.80 :version + ; build : 3246 :integer + ; buildDate : [ :date + ; hour : 11 :integer + ; minute : 27 :integer + ; second : 54 :integer + ; nanosecond : 389131000 :integer + ; day : 7 :integer + ; Day : Wednesday :string + ; days : 340 :integer + ; month : 12 :integer + ; Month : December :string + ; year : 2022 :integer + ; utc : -3600 :integer + ; ] + ; deps : [ :dictionary + ; gmp : 6.2.1 :version + ; mpfr : 4.1.0 :version + ; sqlite : 3.37.0 :version + ; pcre : 8.45.0 :version + ; ] + ; binary : /Users/drkameleon/OpenSource/arturo-lang/arturo/bin/arturo :string + ; cpu : amd64 :string + ; os : macosx :string + ; release : full :literal + ;] + """: + #======================================================= + push newDictionary(getSystemInfo()) when not defined(WEB): builtin "terminate", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "kill process with given id", args = { From f2e8a08f2c6a2fe2413af39ab05d5f911f1351d9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:48:47 +0100 Subject: [PATCH 397/984] Ui: setting opcodes --- src/library/Ui.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/library/Ui.nim b/src/library/Ui.nim index f9e5f04338..d07650d46b 100644 --- a/src/library/Ui.nim +++ b/src/library/Ui.nim @@ -44,7 +44,8 @@ proc defineSymbols*() = when not defined(NODIALOGS): builtin "alert", - alias = unaliased, + alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "show notification with given title and message", args = { @@ -80,6 +81,7 @@ proc defineSymbols*() = builtin "clip", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "set clipboard content to given text", args = { @@ -97,6 +99,7 @@ proc defineSymbols*() = builtin "dialog", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "show a file selection dialog and return selection", args = { @@ -124,6 +127,7 @@ proc defineSymbols*() = builtin "popup", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "show popup dialog with given title and message and return result", args = { @@ -198,6 +202,7 @@ proc defineSymbols*() = builtin "unclip", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "get clipboard content", args = NoArgs, @@ -218,6 +223,7 @@ proc defineSymbols*() = builtin "webview", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "show webview window with given url or html source", args = { @@ -322,6 +328,7 @@ proc defineSymbols*() = builtin "eval", alias = unaliased, + op = opNop, rule = PrefixPrecedence, description = "Evaluate JavaScript code in active webview", args = { From 8d1f91f82879afca55294fd0422ad6d754acf2b3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:48:50 +0100 Subject: [PATCH 398/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bb09372b41..dfa36c61c7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3708 \ No newline at end of file +3709 \ No newline at end of file From 7dacb08dffc1c2919f6e5e88b5b654d341fca1f4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:54:27 +0100 Subject: [PATCH 399/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index dfa36c61c7..54776fde45 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3709 \ No newline at end of file +3710 \ No newline at end of file From 1e0979dcdd2b72ddd0d65483c1f34fb7297fe885 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:55:42 +0100 Subject: [PATCH 400/984] removed redundant, commented-out code --- src/vm/ast.nim | 52 -------------------------------------------------- 1 file changed, 52 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 75831f04c4..8b920698aa 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -381,58 +381,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b else: BuiltinCall - # if fn == ArrayF : op = opArray - # elif fn == DictF : op = opDict - # elif fn == FuncF : op = opFunc - # elif fn == AddF : op = opAdd - # elif fn == SubF : op = opSub - # elif fn == MulF : op = opMul - # elif fn == DivF : op = opDiv - # elif fn == FdivF : op = opFDiv - # elif fn == ModF : op = opMod - # elif fn == PowF : op = opPow - # elif fn == NegF : op = opNeg - # elif fn == BNotF : op = opBNot - # elif fn == BAndF : op = opBAnd - # elif fn == BOrF : op = opBOr - # elif fn == ShlF : op = opShl - # elif fn == ShrF : op = opShr - # elif fn == NotF : op = opNot - # elif fn == AndF : op = opAnd - # elif fn == OrF : op = opOr - # elif fn == EqF : op = opEq - # elif fn == NeF : op = opNe - # elif fn == GtF : op = opGt - # elif fn == GeF : op = opGe - # elif fn == LtF : op = opLt - # elif fn == LeF : op = opLe - # elif fn == IfF : callType = SpecialCall; op = opIf - # elif fn == IfEF : callType = SpecialCall; op = opIfE - # elif fn == UnlessF : callType = SpecialCall; op = opUnless - # elif fn == UnlessEF : callType = SpecialCall; op = opUnless - # elif fn == ElseF : callType = SpecialCall; op = opElse - # elif fn == SwitchF : callType = SpecialCall; op = opSwitch - # elif fn == WhileF : callType = SpecialCall; op = opWhile - # elif fn == ReturnF : op = opReturn - # elif fn == ToF : op = opTo - # elif fn == PrintF : op = opPrint - # elif fn == GetF : op = opGet - # elif fn == SetF : op = opSet - # elif fn == RangeF : op = opRange - # elif fn == LoopF : op = opLoop - # elif fn == MapF : op = opMap - # elif fn == SelectF : op = opSelect - # elif fn == SizeF : op = opSize - # elif fn == ReplaceF : op = opReplace - # elif fn == SplitF : op = opSplit - # elif fn == JoinF : op = opJoin - # elif fn == ReverseF : op = opReverse - # elif fn == IncF : op = opInc - # elif fn == DecF : op = opDec - - # if callType == OtherCall and op != opNop: - # callType = BuiltinCall - var v: Value = if callType == OtherCall: newWord(name) From 5e0c7f8dee824555e110cd3aca5ef1721298564d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:56:21 +0100 Subject: [PATCH 401/984] renamed all aliases/pointers to OpCode'd built-in functions --- src/vm/values/value.nim | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index 22e7eaad85..b547d5ccb2 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -117,20 +117,20 @@ let var TypeLookup = initOrderedTable[string,Value]() - # global implementation references - AddF*, SubF*, MulF*, DivF*, FdivF*, ModF*, PowF* : Value - NegF*, IncF*, DecF* : Value - BNotF*, BAndF*, BOrF*, ShlF*, ShrF* : Value - NotF*, AndF*, OrF* : Value - EqF*, NeF*, GtF*, GeF*, LtF*, LeF* : Value - GetF*, SetF* : Value - IfF*, IfEF*, UnlessF*, UnlessEF*, ElseF*, SwitchF*, WhileF* : Value - ReturnF*, BreakF*, ContinueF* : Value - ToF* : Value - ArrayF*, DictF*, FuncF*, RangeF* : Value - LoopF*, MapF*, SelectF* : Value - SizeF*, ReplaceF*, SplitF*, JoinF*, ReverseF*, AppendF* : Value - PrintF* : Value + # global action references + DoAdd*, DoSub*, DoMul*, DoDiv*, DoFdiv*, DoMod*, DoPow* : BuiltinAction + DoNeg*, DoInc*, DoDec* : BuiltinAction + DoBNot*, DoBAnd*, DoBOr*, DoShl*, DoShr* : BuiltinAction + DoNot*, DoAnd*, DoOr* : BuiltinAction + DoEq*, DoNe*, DoGt*, DoGe*, DoLt*, DoLe* : BuiltinAction + DoGet*, DoSet* : BuiltinAction + DoIf*, DoIfE*, DoUnless*, DoUnlessE*, DoElse*, DoSwitch*, DoWhile* : BuiltinAction + DoReturn*, DoBreak*, DoContinue* : BuiltinAction + DoTo* : BuiltinAction + DoArray*, DoDict*, DoFunc*, DoRange* : BuiltinAction + DoLoop*, DoMap*, DoSelect* : BuiltinAction + DoSize*, DoReplace*, DoSplit*, DoJoin*, DoReverse*, DoAppend* : BuiltinAction + DoPrint* : BuiltinAction #======================================= # Forward Declarations From 1e45724db2c5a9c5efc7c3846efa65f432fe6eb8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:56:39 +0100 Subject: [PATCH 402/984] point to contained BuiltinAction instead & use new names for built-in function actions --- src/vm/lib.nim | 102 ++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/vm/lib.nim b/src/vm/lib.nim index b903a7e2c6..80e11e1207 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -98,57 +98,57 @@ template builtin*(n: string, alias: VSymbol, op: OpCode, rule: PrecedenceKind, d SetSym(n, b) - # when n=="add" : AddF = b - # elif n=="sub" : SubF = b - # elif n=="mul" : MulF = b - # elif n=="div" : DivF = b - # elif n=="fdiv" : FdivF = b - # elif n=="mod" : ModF = b - # elif n=="pow" : PowF = b - # elif n=="neg" : NegF = b - # elif n=="inc" : IncF = b - # elif n=="dec" : DecF = b - # elif n=="not" : BNotF = b - # elif n=="and" : BAndF = b - # elif n=="or" : BOrF = b - # elif n=="shl" : ShlF = b - # elif n=="shr" : ShrF = b - # elif n=="not?" : NotF = b - # elif n=="and?" : AndF = b - # elif n=="or?" : OrF = b - # elif n=="equal?" : EqF = b - # elif n=="notEqual?" : NeF = b - # elif n=="greater?" : GtF = b - # elif n=="greaterOrEqual?" : GeF = b - # elif n=="less?" : LtF = b - # elif n=="lessOrEqual?" : LeF = b - # elif n=="get" : GetF = b - # elif n=="set" : SetF = b - # elif n=="if" : IfF = b - # elif n=="if?" : IfEF = b - # elif n=="unless" : UnlessF = b - # elif n=="unless?" : UnlessEF = b - # elif n=="else" : ElseF = b - # elif n=="switch" : SwitchF = b - # elif n=="while" : WhileF = b - # elif n=="return" : ReturnF = b - # elif n=="break" : BreakF = b - # elif n=="continue" : ContinueF = b - # elif n=="to" : ToF = b - # elif n=="array" : ArrayF = b - # elif n=="dictionary" : DictF = b - # elif n=="function" : FuncF = b - # elif n=="range" : RangeF = b - # elif n=="loop" : LoopF = b - # elif n=="map" : MapF = b - # elif n=="select" : SelectF = b - # elif n=="size" : SizeF = b - # elif n=="replace" : ReplaceF = b - # elif n=="split" : SplitF = b - # elif n=="join" : JoinF = b - # elif n=="reverse" : ReverseF = b - # elif n=="append" : AppendF = b - # elif n=="print" : PrintF = b + when n=="add" : DoAdd = b.action() + elif n=="sub" : DoSub = b.action() + elif n=="mul" : DoMul = b.action() + elif n=="div" : DoDiv = b.action() + elif n=="fdiv" : DoFdiv = b.action() + elif n=="mod" : DoMod = b.action() + elif n=="pow" : DoPow = b.action() + elif n=="neg" : DoNeg = b.action() + elif n=="inc" : DoInc = b.action() + elif n=="dec" : DoDec = b.action() + elif n=="not" : DoBNot = b.action() + elif n=="and" : DoBAnd = b.action() + elif n=="or" : DoBOr = b.action() + elif n=="shl" : DoShl = b.action() + elif n=="shr" : DoShr = b.action() + elif n=="not?" : DoNot = b.action() + elif n=="and?" : DoAnd = b.action() + elif n=="or?" : DoOr = b.action() + elif n=="equal?" : DoEq = b.action() + elif n=="notEqual?" : DoNe = b.action() + elif n=="greater?" : DoGt = b.action() + elif n=="greaterOrEqual?" : DoGe = b.action() + elif n=="less?" : DoLt = b.action() + elif n=="lessOrEqual?" : DoLe = b.action() + elif n=="get" : DoGet = b.action() + elif n=="set" : DoSet = b.action() + elif n=="if" : DoIf = b.action() + elif n=="if?" : DoIfE = b.action() + elif n=="unless" : DoUnless = b.action() + elif n=="unless?" : DoUnlessE = b.action() + elif n=="else" : DoElse = b.action() + elif n=="switch" : DoSwitch = b.action() + elif n=="while" : DoWhile = b.action() + elif n=="return" : DoReturn = b.action() + elif n=="break" : DoBreak = b.action() + elif n=="continue" : DoContinue = b.action() + elif n=="to" : DoTo = b.action() + elif n=="array" : DoArray = b.action() + elif n=="dictionary" : DoDict = b.action() + elif n=="function" : DoFunc = b.action() + elif n=="range" : DoRange = b.action() + elif n=="loop" : DoLoop = b.action() + elif n=="map" : DoMap = b.action() + elif n=="select" : DoSelect = b.action() + elif n=="size" : DoSize = b.action() + elif n=="replace" : DoReplace = b.action() + elif n=="split" : DoSplit = b.action() + elif n=="join" : DoJoin = b.action() + elif n=="reverse" : DoReverse = b.action() + elif n=="append" : DoAppend = b.action() + elif n=="print" : DoPrint = b.action() when alias != unaliased: Aliases[alias] = AliasBinding( From 1fa057fe2f1c104a016e30983a8817ef9b4d6db3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:57:12 +0100 Subject: [PATCH 403/984] VM/exec: use new names for built-in functions; also, no need to use `.action()`, since they are the actions themselves :-) --- src/vm/exec.nim | 108 ++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index a6dd4e19e5..34053f5e85 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -559,47 +559,47 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = # [0x80-0x8F] # arithmetic operators - of opAdd : AddF.action()() - of opSub : SubF.action()() - of opMul : MulF.action()() - of opDiv : DivF.action()() - of opFdiv : FdivF.action()() - of opMod : ModF.action()() - of opPow : PowF.action()() + of opAdd : DoAdd() + of opSub : DoSub() + of opMul : DoMul() + of opDiv : DoDiv() + of opFdiv : DoFdiv() + of opMod : DoMod() + of opPow : DoPow() - of opNeg : NegF.action()() + of opNeg : DoNeg() # increment/decrement - of opInc : IncF.action()() - of opDec : DecF.action()() + of opInc : DoInc() + of opDec : DoDec() # binary operators - of opBNot : BNotF.action()() - of opBAnd : BAndF.action()() - of opBOr : BOrF.action()() + of opBNot : DoBNot() + of opBAnd : DoBAnd() + of opBOr : DoBOr() - of opShl : ShlF.action()() - of opShr : ShrF.action()() + of opShl : DoShl() + of opShr : DoShr() of RSRV1 : discard # [0x90-0x9F] # logical operators - of opNot : NotF.action()() - of opAnd : AndF.action()() - of opOr : OrF.action()() + of opNot : DoNot() + of opAnd : DoAnd() + of opOr : DoOr() # comparison operators - of opEq : EqF.action()() - of opNe : NeF.action()() - of opGt : GtF.action()() - of opGe : GeF.action()() - of opLt : LtF.action()() - of opLe : LeF.action()() + of opEq : DoEq() + of opNe : DoNe() + of opGt : DoGt() + of opGe : DoGe() + of opLt : DoLt() + of opLe : DoLe() # getters/setters - of opGet : GetF.action()() - of opSet : SetF.action()() + of opGet : DoGet() + of opSet : DoSet() of RSRV2 : discard of RSRV3 : discard @@ -609,26 +609,26 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = # [0xA0-0xAF] # branching - of opIf : IfF.action()() - of opIfE : IfEF.action()() - of opUnless : UnlessF.action()() - of opUnlessE : UnlessEF.action()() - of opElse : ElseF.action()() - of opSwitch : SwitchF.action()() - of opWhile : WhileF.action()() - - of opReturn : ReturnF.action()() - of opBreak : BreakF.action()() - of opContinue : ContinueF.action()() + of opIf : DoIf() + of opIfE : DoIfE() + of opUnless : DoUnless() + of opUnlessE : DoUnlessE() + of opElse : DoElse() + of opSwitch : DoSwitch() + of opWhile : DoWhile() + + of opReturn : DoReturn() + of opBreak : DoBreak() + of opContinue : DoContinue() # converters - of opTo : ToF.action()() + of opTo : DoTo() of opToS : stack.push(VSTRINGT) - ToF.action()() + DoTo() of opToI : stack.push(VINTEGERT) - ToF.action()() + DoTo() of RSRV7 : discard of RSRV8 : discard @@ -636,26 +636,26 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = # [0xB0-0xBF] # generators - of opArray : ArrayF.action()() - of opDict : DictF.action()() - of opFunc : FuncF.action()() - of opRange : RangeF.action()() + of opArray : DoArray() + of opDict : DoDict() + of opFunc : DoFunc() + of opRange : DoRange() # iterators - of opLoop : LoopF.action()() - of opMap : MapF.action()() - of opSelect : SelectF.action()() + of opLoop : DoLoop() + of opMap : DoMap() + of opSelect : DoSelect() # collections - of opSize : SizeF.action()() - of opReplace : ReplaceF.action()() - of opSplit : SplitF.action()() - of opJoin : JoinF.action()() - of opReverse : ReverseF.action()() - of opAppend : AppendF.action()() + of opSize : DoSize() + of opReplace : DoReplace() + of opSplit : DoSplit() + of opJoin : DoJoin() + of opReverse : DoReverse() + of opAppend : DoAppend() # i/o operations - of opPrint : PrintF.action()() + of opPrint : DoPrint() of RSRV10 : discard of RSRV11 : discard From 76566eda53681aff071f148c3bfd73e1f4b656ff Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 17:57:15 +0100 Subject: [PATCH 404/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 54776fde45..c002b8cee1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3710 \ No newline at end of file +3711 \ No newline at end of file From 2443ca0ae47822c9fc18ce2e93f962ae58b5705e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:01:42 +0100 Subject: [PATCH 405/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c002b8cee1..87c80d82b8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3711 \ No newline at end of file +3712 \ No newline at end of file From d5e30f9308cee783f76f802bdccb4bfe9ec0a775 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:03:44 +0100 Subject: [PATCH 406/984] updated inline TODOs --- src/vm/ast.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 8b920698aa..32d52317bc 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -22,7 +22,9 @@ # - [x] make Path's work # - [x] make PathLabel's work # - [ ] make Newline values work -# - [ ] create new opCode for append +# - [X] create new opCode for append +# - [X] clean up opCode's +# - [X] attach opCode's to built-in function (for faster lookups) # - [ ] optimize appends # - [ ] make labels store new functions in TmpArities # - [ ] make if/if?/else/while/switch work From ee41ecefa455f5c11906d4a96e71b00f0add1a1f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:04:02 +0100 Subject: [PATCH 407/984] minor edit --- src/vm/ast.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 32d52317bc..08d8b03e22 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -22,9 +22,9 @@ # - [x] make Path's work # - [x] make PathLabel's work # - [ ] make Newline values work -# - [X] create new opCode for append -# - [X] clean up opCode's -# - [X] attach opCode's to built-in function (for faster lookups) +# - [x] create new opCode for append +# - [x] clean up opCode's +# - [x] attach opCode's to built-in function (for faster lookups) # - [ ] optimize appends # - [ ] make labels store new functions in TmpArities # - [ ] make if/if?/else/while/switch work From f499362be9007d37fc6361b599a3be128feeeb62 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:08:26 +0100 Subject: [PATCH 408/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 87c80d82b8..1442a734be 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3712 \ No newline at end of file +3713 \ No newline at end of file From c5276c2c67f99c3d8999a51cdd7977e7eafafc32 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:09:34 +0100 Subject: [PATCH 409/984] VM/ast: fixed handling of non-OpCode'd built-in functions --- src/vm/ast.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 08d8b03e22..21ab646a7a 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -376,12 +376,12 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var op: OpCode = opNop if fn.fnKind == BuiltinFunction: - op = fn.op - callType = - if op in {opIf, opIfE, opUnless, opUnlessE, opElse, opSwitch, opWhile}: - SpecialCall - else: - BuiltinCall + if (op = fn.op; op != opNop): + callType = + if op in {opIf, opIfE, opUnless, opUnlessE, opElse, opSwitch, opWhile}: + SpecialCall + else: + BuiltinCall var v: Value = if callType == OtherCall: From c1e1d19269a0803f89f42f928d89c39847451582 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:20:51 +0100 Subject: [PATCH 410/984] VM/ast: properly handle `opUnlessE` as well --- src/vm/ast.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 21ab646a7a..8b588bcf5d 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -344,7 +344,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b of opFDiv : target.optimizeArithmeticOp(`//`) of opMod : target.optimizeArithmeticOp(`%`) of opPow : target.optimizeArithmeticOp(`^`) - of opUnless : target.optimizeUnless() + of opUnless, + opUnlessE : target.optimizeUnless() else: discard From 924318980d92e4072b31ec1a40429c9da5452b17 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:23:27 +0100 Subject: [PATCH 411/984] VM/ast: also optimize `append` (`++`) for constant String values --- src/vm/ast.nim | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 8b588bcf5d..1c87719a46 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -329,6 +329,15 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b newNode.parent = target + proc optimizeAppend(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + var right = target.children[1] + + if left.kind == ConstantValue and left.value.kind == String: + # Constant folding + if right.kind == ConstantValue and right.value.kind == String: + target.replaceNode(newConstant(newString(left.value.s & right.value.s))) + #------------------------ # Helper Functions #------------------------ @@ -337,15 +346,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b while target.kind in CallNode and target.params == target.arity: when optimize: case target.op: - of opAdd : target.optimizeAdd() - of opSub : target.optimizeSub() - of opMul : target.optimizeArithmeticOp(`*`) - of opDiv : target.optimizeArithmeticOp(`/`) - of opFDiv : target.optimizeArithmeticOp(`//`) - of opMod : target.optimizeArithmeticOp(`%`) - of opPow : target.optimizeArithmeticOp(`^`) + of opAdd : target.optimizeAdd() + of opSub : target.optimizeSub() + of opMul : target.optimizeArithmeticOp(`*`) + of opDiv : target.optimizeArithmeticOp(`/`) + of opFDiv : target.optimizeArithmeticOp(`//`) + of opMod : target.optimizeArithmeticOp(`%`) + of opPow : target.optimizeArithmeticOp(`^`) of opUnless, - opUnlessE : target.optimizeUnless() + opUnlessE : target.optimizeUnless() + of opAppend : target.optimizeAppend() else: discard From 2a3c2029fbf8fbfc2f7a039ff1a23f810a914eb5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:23:45 +0100 Subject: [PATCH 412/984] updated inline TODOs --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 1c87719a46..61164e6d3b 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -25,7 +25,7 @@ # - [x] create new opCode for append # - [x] clean up opCode's # - [x] attach opCode's to built-in function (for faster lookups) -# - [ ] optimize appends +# - [x] optimize appends # - [ ] make labels store new functions in TmpArities # - [ ] make if/if?/else/while/switch work From 5b5f43604cf1f5d7544b5b7d9efb8004ac562152 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:23:51 +0100 Subject: [PATCH 413/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1442a734be..0d5a8e7c28 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3713 \ No newline at end of file +3714 \ No newline at end of file From 68ef8c697f9ca2094a482b678f033019ad57374b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:26:22 +0100 Subject: [PATCH 414/984] VM/ast: make `addTerminal` a bit more versatile to accept even `seq[Node]` parameters (e.g. for `addInline`) --- src/vm/ast.nim | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 61164e6d3b..d9a34509ca 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -433,13 +433,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b i += 1 target.addCall(aliased.name.s, fun=symfunc) - proc addTerminal(target: var Node, node: Node) = + proc addTerminal(target: var Node, node: Node | seq[Node]) = with target: rewindCallBranches() addPotentialInfixCall() - addChild(node) + when node is Node: + addChild(node) + else: + addChildren(node) rewindCallBranches(optimize=true) @@ -529,14 +532,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var subNode = newRootNode() discard subNode.processBlock(val) - with target: - rewindCallBranches() - - addPotentialInfixCall() - - addChildren(subNode.children) - - rewindCallBranches() + target.addTerminal(subNode.children) proc addArrowBlock(target: var Node, val: Value) = var subNode = newRootNode() From 969a219a60b77c3cdcbf9ee436d8a4b10f5bcf21 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:26:27 +0100 Subject: [PATCH 415/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0d5a8e7c28..210523b171 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3714 \ No newline at end of file +3715 \ No newline at end of file From f96802a8afe469aa2e2bb6e1ac96197daaa356bc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:27:54 +0100 Subject: [PATCH 416/984] REGRESSION: revert change for `addTerminal` --- src/vm/ast.nim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index d9a34509ca..61164e6d3b 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -433,16 +433,13 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b i += 1 target.addCall(aliased.name.s, fun=symfunc) - proc addTerminal(target: var Node, node: Node | seq[Node]) = + proc addTerminal(target: var Node, node: Node) = with target: rewindCallBranches() addPotentialInfixCall() - when node is Node: - addChild(node) - else: - addChildren(node) + addChild(node) rewindCallBranches(optimize=true) @@ -532,7 +529,14 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b var subNode = newRootNode() discard subNode.processBlock(val) - target.addTerminal(subNode.children) + with target: + rewindCallBranches() + + addPotentialInfixCall() + + addChildren(subNode.children) + + rewindCallBranches() proc addArrowBlock(target: var Node, val: Value) = var subNode = newRootNode() From ec713ce90ccc7f3637c2cf4c52141dffd1fcbfea Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 18 Jan 2023 18:27:57 +0100 Subject: [PATCH 417/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 210523b171..adc4a6ae67 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3715 \ No newline at end of file +3716 \ No newline at end of file From 2d54e61941129992cec324dd0d4676bdd1c0c6ca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 10:11:51 +0100 Subject: [PATCH 418/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index adc4a6ae67..567b012ae8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3716 \ No newline at end of file +3717 \ No newline at end of file From 0490026b042ca989a94abd7f38761c7ef494050b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 10:15:11 +0100 Subject: [PATCH 419/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 567b012ae8..8643c26182 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3717 \ No newline at end of file +3718 \ No newline at end of file From 2fe9af1582b30a122c553e52cad0e3612f10b775 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 10:16:51 +0100 Subject: [PATCH 420/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8643c26182..44974f580b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3718 \ No newline at end of file +3719 \ No newline at end of file From 3272c84023f2183a65388d7e9ef9817b5fa1ee84 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 10:17:02 +0100 Subject: [PATCH 421/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 44974f580b..e4011014e1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3719 \ No newline at end of file +3720 \ No newline at end of file From d5251b6544c40adb4650c7e749d857a286c36caf Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 10:18:01 +0100 Subject: [PATCH 422/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e4011014e1..067c080d5f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3720 \ No newline at end of file +3721 \ No newline at end of file From 5bd3d98c342f219bf4666ca80937692dfaa380de Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 10:20:29 +0100 Subject: [PATCH 423/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 067c080d5f..be484beebd 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3721 \ No newline at end of file +3722 \ No newline at end of file From 532df98bac62322d41a5c7c5b0b90acc5b5a6667 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 10:20:44 +0100 Subject: [PATCH 424/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index be484beebd..e2a85b5e66 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3722 \ No newline at end of file +3723 \ No newline at end of file From f3d8d82fc2a4f4ddb1dd8a49613276c8a656d188 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 10:23:33 +0100 Subject: [PATCH 425/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e2a85b5e66..9f65a33a53 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3723 \ No newline at end of file +3724 \ No newline at end of file From 4cd60dc41a117f2486edf50d4baa786f0b7de77e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 11:10:16 +0100 Subject: [PATCH 426/984] VM/ast: [dumpCode] fix stringification of opCodes --- src/vm/ast.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 61164e6d3b..c291747ed8 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -702,7 +702,9 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false): string = else: result &= "Call: " if node.value.isNil: - result &= ($node.op).replace("op","").toLowerAscii() & " <" & $node.arity & ">\n" + var callName = ($node.op).toLowerAscii() + callName.removePrefix("op") + result &= callName & " <" & $node.arity & ">\n" else: result &= node.value.s & " <" & $node.arity & ">\n" From 6833f996441fe928bc43ccf3fe84baf0a94ca42a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 11:10:45 +0100 Subject: [PATCH 427/984] VM/eval: until we optimize them, just throw SpecialCalls as-is --- src/vm/eval.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 20094590b6..74998a2945 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -184,7 +184,7 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = of BuiltinCall: addByte(instruction.op) of SpecialCall: - discard # TOFIX! + addByte(instruction.op) i += 1 From 79f08d12e7d3457b7f4a9560f3a091d1080ee46e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 11:32:59 +0100 Subject: [PATCH 428/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9f65a33a53..1932b4dc2c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3724 \ No newline at end of file +3725 \ No newline at end of file From b05d1faa9e56dd5f4cdc6e7c2abf9178bbcd17f6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 11:39:31 +0100 Subject: [PATCH 429/984] VM/parse: The easy part = eliminate all `newNewline` calls from the parser, so that no Newline values are created in the first place --- src/vm/parse.nim | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/vm/parse.nim b/src/vm/parse.nim index 1ea8cc4031..50df0e93d1 100644 --- a/src/vm/parse.nim +++ b/src/vm/parse.nim @@ -151,14 +151,14 @@ template skip(p: var Parser, scriptStr: var string) = break of CR: pos = lexbase.handleCR(p, pos) - when not defined(NOERRORLINES): - AddToken newNewline(p.lineNumber) + # when not defined(NOERRORLINES): + # AddToken newNewline(p.lineNumber) scriptStr &= "\n" break of LF: pos = lexbase.handleLF(p, pos) - when not defined(NOERRORLINES): - AddToken newNewline(p.lineNumber) + # when not defined(NOERRORLINES): + # AddToken newNewline(p.lineNumber) scriptStr &= "\n" break else: @@ -170,13 +170,13 @@ template skip(p: var Parser, scriptStr: var string) = break of CR: pos = lexbase.handleCR(p, pos) - when not defined(NOERRORLINES): - AddToken newNewline(p.lineNumber) + # when not defined(NOERRORLINES): + # AddToken newNewline(p.lineNumber) break of LF: pos = lexbase.handleLF(p, pos) - when not defined(NOERRORLINES): - AddToken newNewline(p.lineNumber) + # when not defined(NOERRORLINES): + # AddToken newNewline(p.lineNumber) break else: inc(pos) @@ -184,12 +184,12 @@ template skip(p: var Parser, scriptStr: var string) = inc(pos) of CR: pos = lexbase.handleCR(p, pos) - when not defined(NOERRORLINES): - AddToken newNewline(p.lineNumber) + # when not defined(NOERRORLINES): + # AddToken newNewline(p.lineNumber) of LF: pos = lexbase.handleLF(p, pos) - when not defined(NOERRORLINES): - AddToken newNewline(p.lineNumber) + # when not defined(NOERRORLINES): + # AddToken newNewline(p.lineNumber) of '#': if p.buf[pos+1]=='!': inc(pos) From 7b1c242e2b47bf934e4934df55c88afb90e915ab Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 11:39:35 +0100 Subject: [PATCH 430/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1932b4dc2c..305b1c9ea8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3725 \ No newline at end of file +3726 \ No newline at end of file From a6c8dc59afad8f7bc71ade516dfc63d9df927e95 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 11:43:21 +0100 Subject: [PATCH 431/984] VM/values/types: let's just add the line number to the Value objects (being a `uint32` doesn't even increase our Value object size, yay!) --- src/vm/values/types.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vm/values/types.nim b/src/vm/values/types.nim index dfb08e4e0d..f1da81c041 100644 --- a/src/vm/values/types.nim +++ b/src/vm/values/types.nim @@ -195,6 +195,7 @@ type when not defined(PORTABLE): info* : ValueInfo + ln* : uint32 flags* : ValueFlags case kind*: ValueKind: From 5ab276d8c32a5f0392832640fe48e6614a829a41 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 11:49:09 +0100 Subject: [PATCH 432/984] VM/parse: make `addToken` inject lineNumber in every single Value --- src/vm/parse.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/vm/parse.nim b/src/vm/parse.nim index 50df0e93d1..7e340c88c2 100644 --- a/src/vm/parse.nim +++ b/src/vm/parse.nim @@ -94,8 +94,13 @@ proc parseDataBlock*(blk: Value): Value template Empty(s: var string): bool = s.len == 0 +func addAnnotatedTokenToBlock(blok: var Value, token: Value, p: var Parser) = + let newToken = token + newToken.ln = uint32(p.lineNumber) + blok.a.add(newToken) + template AddToken(token: untyped): untyped = - topBlock.a.add(token) + topBlock.addAnnotatedTokenToBlock(token, p) template LastToken(): untyped = topBlock.a[^1] From e685a8b6a584d34ed49712ca879ebc5a91fbab62 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 11:49:21 +0100 Subject: [PATCH 433/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 305b1c9ea8..eb6b4dd305 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3726 \ No newline at end of file +3727 \ No newline at end of file From 4c72e2a694d6012c8fe6828a85c296e75f22b8e7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 12:37:16 +0100 Subject: [PATCH 434/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index eb6b4dd305..93e74e5be4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3727 \ No newline at end of file +3728 \ No newline at end of file From ca585014203b4d484f219e4e3534168747de1ca8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 12:49:23 +0100 Subject: [PATCH 435/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 93e74e5be4..c0b378084c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3728 \ No newline at end of file +3729 \ No newline at end of file From 37e0a5c5fe1dfe00b029f96ddf02b2b90bc9f651 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:00:32 +0100 Subject: [PATCH 436/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c0b378084c..9974e834b8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3729 \ No newline at end of file +3730 \ No newline at end of file From 0c2a18359cab457ac25dcfb4e071d7ee62e9078f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:00:47 +0100 Subject: [PATCH 437/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9974e834b8..30c50b7925 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3730 \ No newline at end of file +3731 \ No newline at end of file From 4e5ac4e97d25e8328446acdfb6fd9118b5352895 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:01:17 +0100 Subject: [PATCH 438/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 30c50b7925..221d2d9742 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3731 \ No newline at end of file +3732 \ No newline at end of file From 7824a27db450c2fba10b248798c59473ca518f00 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:05:07 +0100 Subject: [PATCH 439/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 221d2d9742..3d7c2310d2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3732 \ No newline at end of file +3733 \ No newline at end of file From 1eade240f04f708073d66f603440fb5560dd241b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:11:37 +0100 Subject: [PATCH 440/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3d7c2310d2..20f011eaf6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3733 \ No newline at end of file +3734 \ No newline at end of file From 0b5f3b04d96defb3b292b5b888cb0c46b73a0c67 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:14:41 +0100 Subject: [PATCH 441/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 20f011eaf6..8c22b1a2be 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3734 \ No newline at end of file +3735 \ No newline at end of file From a91a737a850a9ffb302b6c94fbefef989cf80130 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:15:52 +0100 Subject: [PATCH 442/984] VM/ast: keep track of the current line & when this changes emit a new NewlineNode --- src/vm/ast.nim | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index c291747ed8..3e5cbbbb6d 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -49,6 +49,8 @@ type # abstract syntax tree definition NodeKind* = enum RootNode # Root node of the AST + + NewlineNode # Newline node # TerminalNode ConstantValue # Terminal node of the AST containing a value @@ -68,6 +70,8 @@ type case kind*: NodeKind: of RootNode, ConstantValue, VariableLoad: discard + of NewlineNode: + line*: uint32 else: op*: OpCode arity*: int8 @@ -124,7 +128,7 @@ func setOnlyChild(node: Node, child: Node) {.enforceNoRaises.} = func addChild*(node: Node, child: Node) {.enforceNoRaises.} = child.parent = node node.children.add(child) - if node.kind in CallNode and child.kind != AttributeNode: + if node.kind in CallNode and child.kind notin {NewlineNode, AttributeNode}: node.params += 1 func addChildren*(node: Node, children: NodeArray) {.enforceNoRaises.} = @@ -214,10 +218,12 @@ template newCallNode(kn: NodeKind, ar: int8, va: Value, oper: OpCode = opNop): N # Methods #======================================= -proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static bool = false): int = +proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, processingArrow: static bool = false): int = var i: int = start var nLen: int = blok.a.len + var currentLine: uint32 = startingLine + var current = root #------------------------ @@ -420,6 +426,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b when isLabel: target.rollThrough() + proc addNewline(target: var Node) = + target.addChild(Node(kind: NewlineNode, line: currentLine)) + template addPotentialInfixCall(target: var Node): untyped = if i < nLen - 1: let nextNode {.cursor.} = blok.a[i+1] @@ -485,7 +494,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b if val.p[i].kind==Block: var subNode = newRootNode() - discard subNode.processBlock(val.p[i]) + discard subNode.processBlock(val.p[i], startingLine=currentLine) newNode.addChildren(subNode.children) else: newNode.addChild(newConstant(val.p[i])) @@ -527,7 +536,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b proc addInline(target: var Node, val: Value) = var subNode = newRootNode() - discard subNode.processBlock(val) + discard subNode.processBlock(val, startingLine=currentLine) with target: rewindCallBranches() @@ -540,7 +549,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b proc addArrowBlock(target: var Node, val: Value) = var subNode = newRootNode() - i = subNode.processBlock(val, start=i+1, processingArrow=true) + i = subNode.processBlock(val, start=i+1, startingLine=currentLine, processingArrow=true) target.addTerminal(newConstant(newBlock(ArrowBlock))) @@ -594,6 +603,10 @@ proc processBlock*(root: Node, blok: Value, start = 0, processingArrow: static b while i < nLen: let item = blok.a[i] + if item.ln != currentLine: + currentLine = item.ln + current.addNewline() + when processingArrow: ArrowBlock.add(item) @@ -691,6 +704,9 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false): string = result &= "ROOT: \n" for child in node.children: result &= dumpNode(child, level+1) + of NewlineNode: + indentNode() + result &= "NEWLINE: " & $(node.line) & "\n" of TerminalNode: indentNode() result &= "Constant: " & $(node.value) From 803e890b7262285c6f8d95e787d25cd9a7a81d71 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:16:23 +0100 Subject: [PATCH 443/984] VM/eval: take NewlineNode's into account; that is: for now, totally ignore them --- src/vm/eval.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 74998a2945..4757e38931 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -117,7 +117,7 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = # echo "processing: " # echo dumpNode(instruction) case instruction.kind: - of RootNode: + of RootNode, NewlineNode: discard of ConstantValue: var alreadyPut = false From ed49c2a48d6fb3ee96b8a34e728903fce4aaa9da Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:16:48 +0100 Subject: [PATCH 444/984] VM/parse: no need to copy the values before assigning `.ln` --- src/vm/parse.nim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/vm/parse.nim b/src/vm/parse.nim index 7e340c88c2..26d14e58fb 100644 --- a/src/vm/parse.nim +++ b/src/vm/parse.nim @@ -94,10 +94,9 @@ proc parseDataBlock*(blk: Value): Value template Empty(s: var string): bool = s.len == 0 -func addAnnotatedTokenToBlock(blok: var Value, token: Value, p: var Parser) = - let newToken = token - newToken.ln = uint32(p.lineNumber) - blok.a.add(newToken) +func addAnnotatedTokenToBlock(blok: var Value, token: Value, p: var Parser) {.enforceNoRaises.} = + token.ln = uint32(p.lineNumber) + blok.a.add(token) template AddToken(token: untyped): untyped = topBlock.addAnnotatedTokenToBlock(token, p) From ac721d8606950909561123d32bf49359c5a1792a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:17:36 +0100 Subject: [PATCH 445/984] VM/values/types: so, let's go on and remove Newline values; just like that! :) --- src/vm/values/types.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/vm/values/types.nim b/src/vm/values/types.nim index f1da81c041..062f3b140c 100644 --- a/src/vm/values/types.nim +++ b/src/vm/values/types.nim @@ -275,8 +275,6 @@ type of Bytecode: trans*: Translation - of Newline: - line*: int ValueObj = typeof(Value()[]) FuncObj = typeof(VFunction()[]) From 2e79e0ff548e23e8e45dab6d3e7750d8f24a4201 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:18:28 +0100 Subject: [PATCH 446/984] VM/values/flags: let's also remove the IsDirty flag (no Newline values = no "dirty" or "clean" blocks!) --- src/vm/values/flags.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vm/values/flags.nim b/src/vm/values/flags.nim index 31eafb3fa6..5f84466176 100644 --- a/src/vm/values/flags.nim +++ b/src/vm/values/flags.nim @@ -22,7 +22,6 @@ type ValueFlag* = enum IsReadOnly # Value has to be copied on assignment - IsDirty # For blocks: it may contain Newline values IsDynamic # For blocks: it has to be re-evaluated # prior to execution From 014a896f4c4a86f9335d902ec3ba1dbdebc43b59 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:18:32 +0100 Subject: [PATCH 447/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8c22b1a2be..27a63cb805 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3735 \ No newline at end of file +3736 \ No newline at end of file From b0969610acf18272d721c183cf1e302058eb5258 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:19:27 +0100 Subject: [PATCH 448/984] VM/values/types: *now*, we've properly removed the Newline type (now, let's sit back & watch everything crashing... lol) --- src/vm/values/types.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/vm/values/types.nim b/src/vm/values/types.nim index 062f3b140c..8c94f399c9 100644 --- a/src/vm/values/types.nim +++ b/src/vm/values/types.nim @@ -92,9 +92,8 @@ type Socket = 32 Bytecode = 33 - Newline = 34 - Nothing = 35 - Any = 36 + Nothing = 34 + Any = 35 ValueSpec* = set[ValueKind] From dbca49844bf3c8d22e72b0271012f7cad720e60c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:19:30 +0100 Subject: [PATCH 449/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 27a63cb805..9e803905b5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3736 \ No newline at end of file +3737 \ No newline at end of file From 7a0632a292bc1272c8040fec5a8cea865b32c4b2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:20:30 +0100 Subject: [PATCH 450/984] complete remove VM/values/clean --- src/vm/values/clean.nim | 116 ---------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 src/vm/values/clean.nim diff --git a/src/vm/values/clean.nim b/src/vm/values/clean.nim deleted file mode 100644 index 309918f307..0000000000 --- a/src/vm/values/clean.nim +++ /dev/null @@ -1,116 +0,0 @@ -#======================================================= -# Arturo -# Programming Language + Bytecode VM compiler -# (c) 2019-2023 Yanis ZafirΓ³pulos -# -# @file: vm/values/clean.nim -#======================================================= - -## This module has helper used to clean blocks -## Blocks may have `Newline` Values, -## so when you want to actually use its contents, we make sure that there will be none - -import macros, sequtils, strutils, sugar - -import vm/values/types - -#======================================= -# Helpers -#======================================= - -template cleanBlock*(v: Value) = - ## remove all Newline values from a Block value, in-place - ## - ## **Hint**: ``v`` must be a Value, not a ValueArray ( - ## This is an optimization, as Block values have a - ## `.dirty` attribute: if `.dirty` is false it'll do - ## nothing.). When done, `.dirty`'ll be set to *false*. - - when not defined(NOERRORLINES): - if v.dirty: - v.a.keepIf((vv) => vv.kind != Newline) - v.dirty = false # Updates `.dirty` value - else: - discard - -func cleanedBlockImpl*(va: ValueArray): ValueArray {.inline,enforceNoRaises.} = - result = collect(newSeqOfCap(va.len)): - for vv in va: - if vv.kind != Newline: - vv - -template cleanedBlock*(va: ValueArray, inplace=false): untyped = - when not defined(NOERRORLINES): - cleanedBlockImpl(va) - else: - va - -template cleanedBlockValuesCopy*(v: Value): untyped = - when not defined(NOERRORLINES): - if v.dirty: - cleanedBlockImpl(v.a) - else: - v.a - else: - v.a - -iterator cleanedBlockValues*(v: Value, L: int): lent Value = - ## yield a Value object per iteration, while - ## ignoring all Newline values - ## - ## **Note:** - ## - This is to be used inside a *for loop*. - ## - ## **Usage:** - ## ```nim - ## for i in cleanedBlockValues(y, y.a.len): - ## x.a[cnt] = i - ## inc cnt - ## ``` - - when not defined(NOERRORLINES): - if v.dirty: - for i in 0..L-1: - if v.a[i].kind != Newline: - yield v.a[i] - else: - for i in 0..L-1: - yield v.a[i] - else: - for i in 0..L-1: - yield v.a[i] - -template cleanedBlockValues*(v: Value): untyped = - ## yield a Value object per iteration, while - ## ignoring all Newline values - ## - ## **Note:** - ## - Detects `v.a`'s length automatically - ## - This is to be used inside a *for loop*. - ## - ## **Usage:** - ## ```nim - ## for i in cleanedBlockValues(y): - ## x.a[cnt] = i - ## inc cnt - ## ``` - - let l = v.a.len - cleanedBlockValues(v, l) - -macro ensureCleaned*(name: untyped): untyped = - let cleanName = ident("clean" & ($name).capitalizeAscii()) - let cleanedBlock = ident("cleanedBlockTmp" & ($name).capitalizeAscii()) - when not defined(NOERRORLINES): - result = quote do: - var `cleanedBlock`: ValueArray - let `cleanName` {.cursor.} = ( - if `name`.dirty: - `cleanedBlock` = cleanedBlockImpl(`name`.a) - `cleanedBlock` - else: - `name`.a - ) - else: - result = quote do: - let `cleanName` {.cursor.} = `name`.a From 00d48ed31574807e6f17608c678fb1c25d68e623 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:20:34 +0100 Subject: [PATCH 451/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9e803905b5..b31ce9b7cb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3737 \ No newline at end of file +3738 \ No newline at end of file From b4fa6c25b6eca9791de2b44b56059a207a69c1fd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:20:53 +0100 Subject: [PATCH 452/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b31ce9b7cb..1440b23c33 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3738 \ No newline at end of file +3739 \ No newline at end of file From 6fef002490396d7563e662eff7d9b1257208282d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:22:38 +0100 Subject: [PATCH 453/984] remove also imports of `VM/values/clean` (since it doesn't exist anymore) --- src/helpers/arrays.nim | 1 - src/vm/lib.nim | 4 ++-- src/vm/values/comparison.nim | 1 - src/vm/values/printable.nim | 1 - src/vm/values/value.nim | 1 - 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/helpers/arrays.nim b/src/helpers/arrays.nim index 853c728468..9c27f01551 100644 --- a/src/helpers/arrays.nim +++ b/src/helpers/arrays.nim @@ -16,7 +16,6 @@ import helpers/sets import vm/values/comparison import vm/values/value -import vm/values/clean #======================================= # Methods diff --git a/src/vm/lib.nim b/src/vm/lib.nim index 80e11e1207..10ba61270c 100644 --- a/src/vm/lib.nim +++ b/src/vm/lib.nim @@ -15,8 +15,8 @@ import sequtils, strutils, tables export strutils, tables -import vm/[globals, errors, opcodes, stack, values/comparison, values/clean, values/printable, values/value] -export clean, comparison, globals, printable, opcodes, stack, value +import vm/[globals, errors, opcodes, stack, values/comparison, values/printable, values/value] +export comparison, globals, printable, opcodes, stack, value import vm/values/custom/[vcolor, vcomplex, vlogical, vquantity, vrational, vregex, vsymbol] export vcolor, vcomplex, vlogical, vquantity, vrational, vregex, vsymbol diff --git a/src/vm/values/comparison.nim b/src/vm/values/comparison.nim index 363c1f7fba..ee5db47c2b 100644 --- a/src/vm/values/comparison.nim +++ b/src/vm/values/comparison.nim @@ -22,7 +22,6 @@ when not defined(NOGMP): import vm/values/custom/[vcolor, vcomplex, vlogical, vquantity, vrange, vrational, vversion] import vm/values/value -import vm/values/clean #======================================= # Methods diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index d93945247e..d0b0e255db 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -26,7 +26,6 @@ import helpers/terminal as TerminalHelper import vm/globals import vm/opcodes import vm/values/value -import vm/values/clean import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vquantity, vrange, vrational, vregex, vsocket, vversion] diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index b547d5ccb2..f54644d0d0 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -40,7 +40,6 @@ import vm/opcodes import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vquantity, vrange, vrational, vregex, vsocket, vsymbol, vversion] -import vm/values/clean import vm/values/types import vm/values/flags export types From 003274517c922d8c68f61c8df10ed6369edae273 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:22:41 +0100 Subject: [PATCH 454/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1440b23c33..828c9e6011 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3739 \ No newline at end of file +3740 \ No newline at end of file From 822cdea9e7cee29fd3005339d68846b4c9ba6cf5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:24:33 +0100 Subject: [PATCH 455/984] no concept of "dirty" blocks so let's remove the `.dirty` field + fix the `newBlock` & `newInline` constructors --- src/vm/values/types.nim | 3 --- src/vm/values/value.nim | 18 ++++-------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/vm/values/types.nim b/src/vm/values/types.nim index 8c94f399c9..987bcfda75 100644 --- a/src/vm/values/types.nim +++ b/src/vm/values/types.nim @@ -295,9 +295,6 @@ when sizeof(ValueObj) > 72: # At time of writing it was '72', 8 - 64 bit integer template readonly*(val: Value): bool = IsReadOnly in val.flags template `readonly=`*(val: Value, newVal: bool) = val.flags[IsReadOnly] = newVal -template dirty*(val: Value): bool = IsDirty in val.flags -template `dirty=`*(val: Value, newVal: bool) = val.flags[IsDirty] = newVal - template dynamic*(val: Value): bool = IsDynamic in val.flags template `dynamic=`*(val: Value, newVal: bool) = val.flags[IsDynamic] = newVal diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index f54644d0d0..6fddcd11e6 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -585,23 +585,13 @@ func newBytecode*(t: sink Translation): Value {.inline, enforceNoRaises.} = ## create Bytecode value from Translation Value(kind: Bytecode, trans: t) -func newInline*(a: sink ValueArray = @[], dirty = false): Value {.inline, enforceNoRaises.} = +func newInline*(a: sink ValueArray = @[]): Value {.inline, enforceNoRaises.} = ## create Inline value from ValueArray - let flags = - if dirty: - {IsDirty} - else: - {} - Value(kind: Inline, a: a, flags: flags) + Value(kind: Inline, a: a) -func newBlock*(a: sink ValueArray = @[], data: sink Value = nil, dirty = false): Value {.inline, enforceNoRaises.} = +func newBlock*(a: sink ValueArray = @[], data: sink Value = nil): Value {.inline, enforceNoRaises.} = ## create Block value from ValueArray - let flags = - if dirty: - {IsDirty} - else: - {} - Value(kind: Block, a: a, data: data, flags: flags) + Value(kind: Block, a: a, data: data) func newBlock*(a: (Value, Value)): Value {.inline, enforceNoRaises.} = ## create Block value from tuple of two values From 38c261c4d27f922175883aa0bff429ec7b63d94c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:24:35 +0100 Subject: [PATCH 456/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 828c9e6011..e8780f6bd5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3740 \ No newline at end of file +3741 \ No newline at end of file From 7cfa88c20169cce8cf238771653394d9c2a0c4ec Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:28:19 +0100 Subject: [PATCH 457/984] Helpers/jsonobject: remove all references to Newline values --- src/helpers/jsonobject.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/helpers/jsonobject.nim b/src/helpers/jsonobject.nim index 70aca6d4a1..8bb1f60c0a 100644 --- a/src/helpers/jsonobject.nim +++ b/src/helpers/jsonobject.nim @@ -88,7 +88,6 @@ proc generateJsonNode*(n: Value): JsonNode = Database, Socket, Bytecode, - Newline, Nothing, Any : discard @@ -172,7 +171,6 @@ when defined(WEB): Socket, Bytecode, Nothing, - Newline, Any : discard func isArray(x: JsObject): bool {.importcpp: "(Array.isArray(#))".} From 6f84e389eab436f133406ecfee350d21c11f25e6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:28:27 +0100 Subject: [PATCH 458/984] : remove all references to Newline values --- src/library/Converters.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/src/library/Converters.nim b/src/library/Converters.nim index 68f16aa4d4..a9fe7fa0f6 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -530,7 +530,6 @@ proc convertedValueToType(x, y: Value, tp: ValueKind, aFormat:Value = nil): Valu of Function, Database, Socket, - Newline, Nothing, Any, Path, From 48495be8d0578e39de4b0da8b5faeb8c01422cb1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:28:40 +0100 Subject: [PATCH 459/984] VM/parse: remove all references to Newline values --- src/vm/parse.nim | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/vm/parse.nim b/src/vm/parse.nim index 26d14e58fb..b1b01c785f 100644 --- a/src/vm/parse.nim +++ b/src/vm/parse.nim @@ -107,14 +107,6 @@ template LastToken(): untyped = template ReplaceLastToken(with: untyped): untyped = topBlock.a[^1] = with -template stripTrailingNewlines(): untyped = - if topBlock.a[^1].kind == Newline: - let lastN = topBlock.a.len-1 - var firstN = lastN - while firstN-1 >= 0 and topBlock.a[firstN-1].kind == Newline: - firstN -= 1 - topBlock.a.delete(firstN..lastN) - #======================================= # Helpers #======================================= @@ -579,7 +571,6 @@ template parseAndAddSymbol(p: var Parser, topBlock: var Value) = inc(pos) p.symbol = triangleright else: - stripTrailingNewlines() p.symbol = pipe of '/' : if p.buf[pos+1]=='/': @@ -1030,7 +1021,7 @@ proc parseAsDictionary(blk: Value, start: int): Value = let lbl = blk.a[i].s i += 1 var values: ValueArray - while i < blk.a.len and blk.a[i].kind!=Newline and blk.a[i].kind!=Label: + while i < blk.a.len and blk.a[i].kind!=Label: case blk.a[i].kind: of Block: values.add(parseDataBlock(blk.a[i])) @@ -1061,15 +1052,15 @@ proc parseAsBlock(blk: Value, start: int): Value = values.add(parseDataBlock(blk.a[i])) of String, Literal, Word, Label: values.add(newString(blk.a[i].s)) - of Newline: - if values.len > 1: - result.a.add(newBlock(values)) - values.setLen(0) - elif values.len == 1: - result.a.add(values[0]) - values.setLen(0) - else: - discard + # of Newline: + # if values.len > 1: + # result.a.add(newBlock(values)) + # values.setLen(0) + # elif values.len == 1: + # result.a.add(values[0]) + # values.setLen(0) + # else: + # discard else: values.add(blk.a[i]) @@ -1092,8 +1083,8 @@ proc parseDataBlock*(blk: Value): Value = return VNULL var i = 0 - while i < blk.a.len and blk.a[i].kind==Newline: - i += 1 + # while i < blk.a.len and blk.a[i].kind==Newline: + # i += 1 if i==blk.a.len: return VNULL From 017e18ddbdf792363cddafb2fa0965408c84027f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:28:51 +0100 Subject: [PATCH 460/984] VM/values/printable: remove all references to Newline values --- src/vm/values/printable.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index d0b0e255db..4d9b20fb3b 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -158,7 +158,6 @@ proc `$`*(v: Value): string {.inline.} = of Bytecode: result = "" & "(" & fmt("{cast[ByteAddress](v):#X}") & ")" - of Newline: discard of Nothing: discard of ANY: discard @@ -433,7 +432,6 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen dumpBlockEnd() - of Newline : discard of Nothing : discard of ANY : discard From 677f9ed72a7621a7527d22c630f5b8dfa60c9833 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:28:58 +0100 Subject: [PATCH 461/984] VM/values/value: remove all references to Newline values --- src/vm/values/value.nim | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index 6fddcd11e6..c6d20de76d 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -628,10 +628,6 @@ proc newRange*(start: int, stop: int, step: int, infinite: bool, numeric: bool, proc newRange*(rng: VRange): Value {.inline, enforceNoRaises.} = Value(kind: Range, rng: rng) -func newNewline*(l: int): Value {.inline, enforceNoRaises.} = - ## create Newline value with given line number - Value(kind: Newline, line: l) - proc newStringDictionary*(a: Table[string, string]): Value = ## create Dictionary value from a string-string Table result = newDictionary() @@ -732,7 +728,7 @@ proc copyValue*(v: Value): Value {.inline.} = of Bytecode: result = newBytecode(v.trans) - of Newline, Nothing, Any: + of Nothing, Any: discard #======================================= @@ -2475,7 +2471,6 @@ func hash*(v: Value): Hash {.inline.}= of Bytecode: result = result !& cast[Hash](unsafeAddr v) - of Newline : discard of Nothing : discard of ANY : discard From 99067b385086a9f60145b835c6f793074a32a832 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:29:04 +0100 Subject: [PATCH 462/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e8780f6bd5..27af4cf4a8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3741 \ No newline at end of file +3742 \ No newline at end of file From 5ca109eb84f81d2f6379842cbc767a81f75e7250 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:30:05 +0100 Subject: [PATCH 463/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 27af4cf4a8..2373393c54 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3742 \ No newline at end of file +3743 \ No newline at end of file From 13642be31ff50fc3714f1818f07698144a74022c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:30:55 +0100 Subject: [PATCH 464/984] VM/parse: no "dirty" blocks anymore, so clean this up --- src/vm/parse.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/parse.nim b/src/vm/parse.nim index b1b01c785f..55a6cc9236 100644 --- a/src/vm/parse.nim +++ b/src/vm/parse.nim @@ -797,8 +797,8 @@ template parseExponent(p: var Parser) = proc parseBlock(p: var Parser, level: int, isDeferred: bool = true): Value {.inline.} = var topBlock: Value var scriptStr: string - if isDeferred: topBlock = newBlock(dirty=true) - else: topBlock = newInline(dirty=true) + if isDeferred: topBlock = newBlock() + else: topBlock = newInline() let initial = p.bufpos let initialLine = p.lineNumber while true: From a37c49920766f61c1de56ca5ee5b2d1e7ccf6189 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:32:34 +0100 Subject: [PATCH 465/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2373393c54..fec140d036 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3743 \ No newline at end of file +3744 \ No newline at end of file From 080f8c97023b6216d82f68b01a284fec149b947b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:45:13 +0100 Subject: [PATCH 466/984] remove - hopefully - all references to `ensureCleaned` & related code (`cleanX`, `cleanY`, etc) --- src/library/Collections.nim | 198 ++++++++++++++--------------------- src/library/Converters.nim | 66 +++++------- src/library/Core.nim | 11 +- src/library/Files.nim | 4 +- src/library/Iterators.nim | 3 +- src/library/Logic.nim | 10 +- src/library/Numbers.nim | 49 ++++----- src/library/Reflection.nim | 8 +- src/library/Statistics.nim | 34 +++--- src/library/Strings.nim | 6 +- src/vm/values/comparison.nim | 12 +-- src/vm/values/printable.nim | 4 - src/vm/values/value.nim | 3 +- 13 files changed, 165 insertions(+), 243 deletions(-) diff --git a/src/library/Collections.nim b/src/library/Collections.nim index 260ae3da07..41496dcb91 100644 --- a/src/library/Collections.nim +++ b/src/library/Collections.nim @@ -163,9 +163,8 @@ proc defineSymbols*() = if x.kind == String: push(newString(x.s[0..^(times + 1)])) elif x.kind == Block: - ensureCleaned(x) - if cleanX.len == 0: push(newBlock()) - else: push(newBlock(cleanX[0..^(times + 1)])) + if x.a.len == 0: push(newBlock()) + else: push(newBlock(x.a[0..^(times + 1)])) # TODO(Collections/combine) should also work with in-place Literals? @@ -206,17 +205,15 @@ proc defineSymbols*() = #======================================================= let doRepeat = hadAttr("repeated") - ensureCleaned(x) - - var sz = cleanX.len + var sz = x.a.len if checkAttr("by"): if aBy.i > 0 and aBy.i < sz: sz = aBy.i if hadAttr("count"): - push(countCombinations(cleanX, sz, doRepeat)) + push(countCombinations(x.a, sz, doRepeat)) else: - push(newBlock(getCombinations(cleanX, sz, doRepeat).map(( + push(newBlock(getCombinations(x.a, sz, doRepeat).map(( z)=>newBlock(z)))) # TODO(Collections/contains?) add new `.deep` option? @@ -281,8 +278,7 @@ proc defineSymbols*() = else: push(newLogical(x.s.continuesWith(y.s, at))) of Block: - ensureCleaned(x) - push(newLogical(cleanX[at] == y)) + push(newLogical(x.a[at] == y)) of Range: push(newLogical(x.rng[at] == y)) of Dictionary: @@ -300,8 +296,7 @@ proc defineSymbols*() = else: push(newLogical(y.s in x.s)) of Block: - ensureCleaned(x) - push(newLogical(y in cleanX)) + push(newLogical(y in x.a)) of Range: push(newLogical(y in x.rng)) of Dictionary: @@ -328,9 +323,7 @@ proc defineSymbols*() = ; => [[1 "one"] [2 "two"] [3 "three"]] """: #======================================================= - ensureCleaned(x) - ensureCleaned(y) - push(newBlock(zip(cleanX, cleanY).map((z)=>newBlock(@[z[0], z[1]])))) + push(newBlock(zip(x.a, y.a).map((z)=>newBlock(@[z[0], z[1]])))) builtin "decouple", alias = unaliased, @@ -355,8 +348,7 @@ proc defineSymbols*() = let res = unzip(InPlaced.a.map((w)=>(w.a[0], w.a[1]))) InPlaced.a = @[newBlock(res[0]), newBlock(res[1])] else: - ensureCleaned(x) - let res = unzip(cleanX.map((z)=>(z.a[0], z.a[1]))) + let res = unzip(x.a.map((z)=>(z.a[0], z.a[1]))) push(newBlock(@[newBlock(res[0]), newBlock(res[1])])) builtin "drop", @@ -389,9 +381,8 @@ proc defineSymbols*() = if x.kind == String: push(newString(x.s[y.i..^1])) elif x.kind == Block: - ensureCleaned(x) - if cleanX.len == 0: push(newBlock()) - else: push(newBlock(cleanX[y.i..^1])) + if x.a.len == 0: push(newBlock()) + else: push(newBlock(x.a[y.i..^1])) builtin "empty", alias = unaliased, @@ -440,8 +431,7 @@ proc defineSymbols*() = of Null: push(VTRUE) of String: push(newLogical(x.s == "")) of Block: - ensureCleaned(x) - push(newLogical(cleanX.len == 0)) + push(newLogical(x.a.len == 0)) of Dictionary: push(newLogical(x.d.len == 0)) else: discard @@ -506,9 +496,8 @@ proc defineSymbols*() = if i == aN.i: break push(newBlock(res)) else: - ensureCleaned(x) - if cleanX.len == 0: push(newBlock()) - else: push(newBlock(cleanX[0..aN.i-1])) + if x.a.len == 0: push(newBlock()) + else: push(newBlock(x.a[0..aN.i-1])) else: if x.kind == String: if x.s.len == 0: push(VNULL) @@ -516,9 +505,8 @@ proc defineSymbols*() = elif x.kind == Range: push(x.rng[0]) else: - ensureCleaned(x) - if cleanX.len == 0: push(VNULL) - else: push(cleanX[0]) + if x.a.len == 0: push(VNULL) + else: push(x.a[0]) builtin "flatten", alias = unaliased, @@ -596,8 +584,7 @@ proc defineSymbols*() = case x.kind: of Block: if likely(y.kind==Integer): - ensureCleaned(x) - push(GetArrayIndex(cleanX, y.i)) + push(GetArrayIndex(x.a, y.i)) else: let rLen = y.rng.len var res: ValueArray = newSeq[Value](rLen) @@ -712,8 +699,7 @@ proc defineSymbols*() = else: push(newLogical(y.s.continuesWith(x.s, at))) of Block: - ensureCleaned(y) - push(newLogical(cleanY[at] == x)) + push(newLogical(y.a[at] == x)) of Range: push(newLogical(y.rng[at] == x)) of Dictionary: @@ -767,8 +753,7 @@ proc defineSymbols*() = if indx != -1: push(newInteger(indx)) else: push(VNULL) of Block: - ensureCleaned(x) - let indx = cleanX.find(y) + let indx = x.a.find(y) if indx != -1: push(newInteger(indx)) else: push(VNULL) of Range: @@ -938,9 +923,8 @@ proc defineSymbols*() = let items = toSeq(x.rng.items) push(newBlock(items[x.rng.len-aN.i..^1])) else: - ensureCleaned(x) - if cleanX.len == 0: push(newBlock()) - else: push(newBlock(cleanX[cleanX.len-aN.i..^1])) + if x.a.len == 0: push(newBlock()) + else: push(newBlock(x.a[x.a.len-aN.i..^1])) else: if x.kind == String: if x.s.len == 0: push(VNULL) @@ -949,9 +933,8 @@ proc defineSymbols*() = let items = toSeq(x.rng.items) push(items[x.rng.len-1]) else: - ensureCleaned(x) - if cleanX.len == 0: push(VNULL) - else: push(cleanX[cleanX.len-1]) + if x.a.len == 0: push(VNULL) + else: push(x.a[x.a.len-1]) builtin "max", alias = unaliased, @@ -976,25 +959,24 @@ proc defineSymbols*() = if withIndex: push(newInteger(maxIndex)) else: push(maxElement) else: - ensureCleaned(x) - if cleanX.len == 0: push(VNULL) + if x.a.len == 0: push(VNULL) else: - var maxElement = cleanX[0] + var maxElement = x.a[0] if withIndex: var maxIndex = 0 var i = 1 - while i < cleanX.len: - if (cleanX[i] > maxElement): - maxElement = cleanX[i] + while i < x.a.len: + if (x.a[i] > maxElement): + maxElement = x.a[i] maxIndex = i inc(i) push(newInteger(maxIndex)) else: var i = 1 - while i < cleanX.len: - if (cleanX[i] > maxElement): - maxElement = cleanX[i] + while i < x.a.len: + if (x.a[i] > maxElement): + maxElement = x.a[i] inc(i) push(maxElement) @@ -1022,25 +1004,24 @@ proc defineSymbols*() = if withIndex: push(newInteger(minIndex)) else: push(minElement) else: - ensureCleaned(x) - if cleanX.len == 0: push(VNULL) + if x.a.len == 0: push(VNULL) else: - var minElement = cleanX[0] + var minElement = x.a[0] var minIndex = 0 if withIndex: var i = 1 - while i < cleanX.len: - if (cleanX[i] < minElement): - minElement = cleanX[i] + while i < x.a.len: + if (x.a[i] < minElement): + minElement = x.a[i] minIndex = i inc(i) push(newInteger(minIndex)) else: var i = 1 - while i < cleanX.len: - if (cleanX[i] < minElement): - minElement = cleanX[i] + while i < x.a.len: + if (x.a[i] < minElement): + minElement = x.a[i] inc(i) push(minElement) @@ -1085,8 +1066,7 @@ proc defineSymbols*() = of String: push(newLogical(runeLen(x.s) == 1)) of Block: - ensureCleaned(x) - push(newLogical(cleanX.len == 1)) + push(newLogical(x.a.len == 1)) of Range: push(newLogical(x.rng.len == 1)) of Dictionary: @@ -1132,17 +1112,15 @@ proc defineSymbols*() = #======================================================= let doRepeat = hadAttr("repeated") - ensureCleaned(x) - - var sz = cleanX.len + var sz = x.a.len if checkAttr("by"): if aBy.i > 0 and aBy.i < sz: sz = aBy.i if hadAttr("count"): - push(countPermutations(cleanX, sz, doRepeat)) + push(countPermutations(x.a, sz, doRepeat)) else: - push(newBlock(getPermutations(cleanX, sz, doRepeat).map(( + push(newBlock(getPermutations(x.a, sz, doRepeat).map(( z)=>newBlock(z)))) builtin "prepend", @@ -1300,18 +1278,17 @@ proc defineSymbols*() = else: push(newString(x.s.removeAll(y))) elif x.kind == Block: - ensureCleaned(x) if y.kind == Block and hadAttr("instance"): if hadAttr("once"): - push(newBlock(cleanX.removeFirstInstance(y))) + push(newBlock(x.a.removeFirstInstance(y))) else: - push(newBlock(cleanX.removeAllInstances(y))) + push(newBlock(x.a.removeAllInstances(y))) elif (hadAttr("once")): - push(newBlock(cleanX.removeFirst(y))) + push(newBlock(x.a.removeFirst(y))) elif (hadAttr("index")): - push(newBlock(cleanX.removeByIndex(y.i))) + push(newBlock(x.a.removeByIndex(y.i))) else: - push(newBlock(cleanX.removeAll(y))) + push(newBlock(x.a.removeAll(y))) elif x.kind == Dictionary: let key = (hadAttr("key")) if (hadAttr("once")): @@ -1356,8 +1333,7 @@ proc defineSymbols*() = if x.kind == String: push(newString(x.s.repeat(y.i))) elif x.kind == Block: - ensureCleaned(x) - push(newBlock(safeCycle(cleanX, y.i))) + push(newBlock(safeCycle(x.a, y.i))) else: push(newBlock(safeRepeat(x, y.i))) @@ -1403,8 +1379,7 @@ proc defineSymbols*() = InPlaced.a.reverse() else: if x.kind == Block: - ensureCleaned(x) - push(newBlock(cleanX.reversed)) + push(newBlock(x.a.reversed)) elif x.kind == Range: push(newRange(x.rng.reversed(safe=exact))) else: @@ -1444,8 +1419,7 @@ proc defineSymbols*() = push(newString(toSeq(runes(x.s)).map((w) => $(w)) .rotatedLeft(distance).join(""))) elif x.kind == Block: - ensureCleaned(x) - push(newBlock(cleanX.rotatedLeft(distance))) + push(newBlock(x.a.rotatedLeft(distance))) builtin "sample", alias = unaliased, @@ -1467,9 +1441,8 @@ proc defineSymbols*() = let rnd = rand(0..int(x.rng.len-1)) push(x.rng[rnd]) else: - ensureCleaned(x) - if cleanX.len == 0: push(VNULL) - else: push(sample(cleanX)) + if x.a.len == 0: push(VNULL) + else: push(sample(x.a)) # TODO(Collections/set) not working with Bytecode values # example: @@ -1588,8 +1561,7 @@ proc defineSymbols*() = ensureInPlace() InPlaced.a.shuffle() else: - ensureCleaned(x) - push(newBlock(cleanX.dup(shuffle))) + push(newBlock(x.a.dup(shuffle))) builtin "size", alias = unaliased, @@ -1625,8 +1597,7 @@ proc defineSymbols*() = if sz == InfiniteRange: push(newFloating(Inf)) else: push(newInteger(sz)) elif x.kind == Block: - ensureCleaned(x) - push(newInteger(cleanX.len)) + push(newInteger(x.a.len)) else: # Null push(newInteger(0)) @@ -1667,9 +1638,8 @@ proc defineSymbols*() = else: push(newString("")) else: - ensureCleaned(x) - if y.i >= 0 and z.i <= cleanX.len-1: - push(newBlock(cleanX[y.i..z.i])) + if y.i >= 0 and z.i <= x.a.len-1: + push(newBlock(x.a[y.i..z.i])) else: push(newBlock()) @@ -1707,20 +1677,19 @@ proc defineSymbols*() = sortOrdering = SortOrder.Descending if x.kind == Block: - ensureCleaned(x) - if cleanX.len == 0: push(newBlock()) + if x.a.len == 0: push(newBlock()) else: if checkAttr("by"): - if cleanX.len > 0: + if x.a.len > 0: var sorted: ValueArray - if cleanX[0].kind == Dictionary: - sorted = cleanX.sorted( + if x.a[0].kind == Dictionary: + sorted = x.a.sorted( proc (v1, v2: Value): int = cmp(v1.d[aBy.s], v2.d[aBy.s]), order = sortOrdering) else: - sorted = cleanX.sorted( + sorted = x.a.sorted( proc (v1, v2: Value): int = cmp(v1.o[aBy.s], v2.o[aBy.s]), order = sortOrdering) @@ -1732,21 +1701,21 @@ proc defineSymbols*() = var sortAscii = (hadAttr("ascii")) if checkAttr("as"): - push(newBlock(cleanX.unisorted(aAs.s, + push(newBlock(x.a.unisorted(aAs.s, sensitive = hadAttr("sensitive"), order = sortOrdering, ascii = sortAscii))) else: if (hadAttr("sensitive")): - push(newBlock(cleanX.unisorted("en", + push(newBlock(x.a.unisorted("en", sensitive = true, order = sortOrdering, ascii = sortAscii))) else: - if cleanX[0].kind == String: - push(newBlock(cleanX.unisorted("en", + if x.a[0].kind == String: + push(newBlock(x.a.unisorted("en", order = sortOrdering, ascii = sortAscii))) else: - push(newBlock(cleanX.sorted( + push(newBlock(x.a.sorted( order = sortOrdering))) elif x.kind == Dictionary: @@ -2036,20 +2005,19 @@ proc defineSymbols*() = else: push(newStringBlock(toSeq(runes(x.s)).map((x) => $(x)))) else: - ensureCleaned(x) if checkAttr("at"): - push(newBlock(@[newBlock(cleanX[0..aAt.i-1]), newBlock( - cleanX[aAt.i..^1])])) + push(newBlock(@[newBlock(x.a[0..aAt.i-1]), newBlock( + x.a[aAt.i..^1])])) elif checkAttr("every"): var ret: ValueArray - var length = cleanX.len + var length = x.a.len var i = 0 while i < length: if i+aEvery.i > length: - ret.add(newBlock(cleanX[i..^1])) + ret.add(newBlock(x.a[i..^1])) else: - ret.add(newBlock(cleanX[i..i+aEvery.i-1])) + ret.add(newBlock(x.a[i..i+aEvery.i-1])) i += aEvery.i @@ -2111,10 +2079,9 @@ proc defineSymbols*() = elif x.kind == Block: var i = 0 var ret: ValueArray - ensureCleaned(x) - while i < cleanX.len: - ret.add(cleanX[i]) - while (i+1 < cleanX.len and cleanX[i+1] == cleanX[i]): + while i < x.a.len: + ret.add(x.a[i]) + while (i+1 < x.a.len and x.a[i+1] == x.a[i]): i += 1 i += 1 push(newBlock(ret)) @@ -2167,12 +2134,11 @@ proc defineSymbols*() = upperLimit = x.s.len-1 push(newString(x.s[0..upperLimit])) elif x.kind == Block: - ensureCleaned(x) - if cleanX.len == 0: push(newBlock()) + if x.a.len == 0: push(newBlock()) else: - if upperLimit > cleanX.len - 1: - upperLimit = cleanX.len-1 - push(newBlock(cleanX[0..upperLimit])) + if upperLimit > x.a.len - 1: + upperLimit = x.a.len-1 + push(newBlock(x.a[0..upperLimit])) elif x.kind == Range: var res: ValueArray = newSeq[Value](upperLimit+1) var i = 0 @@ -2247,8 +2213,7 @@ proc defineSymbols*() = push newString(x.s & $(genOid())) else: if x.kind == Block: - ensureCleaned(x) - push(newBlock(cleanX.deduplicated())) + push(newBlock(x.a.deduplicated())) elif x.kind == String: push newString(toSeq(runes(x.s)).deduplicate.map((w) => $(w)).join("")) else: @@ -2330,8 +2295,7 @@ proc defineSymbols*() = of String: push(newLogical(runeLen(x.s) == 0)) of Block: - ensureCleaned(x) - push(newLogical(cleanX.len == 0)) + push(newLogical(x.a.len == 0)) of Range: push(newLogical(x.rng.len == 0)) of Dictionary: diff --git a/src/library/Converters.nim b/src/library/Converters.nim index a9fe7fa0f6..6e590f5a62 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -315,22 +315,18 @@ proc convertedValueToType(x, y: Value, tp: ValueKind, aFormat:Value = nil): Valu of Inline: case tp: of Block: - ensureCleaned(y) - return newBlock(cleanY) + return newBlock(y.a) else: throwCannotConvert() of Block: case tp: of Complex: - ensureCleaned(y) - return newComplex(cleanY[0], cleanY[1]) + return newComplex(y.a[0], y.a[1]) of Rational: - ensureCleaned(y) - return newRational(cleanY[0], cleanY[1]) + return newRational(y.a[0], y.a[1]) of Inline: - ensureCleaned(y) - return newInline(cleanY) + return newInline(y.a) of Dictionary: let stop = SP execUnscoped(y) @@ -360,34 +356,31 @@ proc convertedValueToType(x, y: Value, tp: ValueKind, aFormat:Value = nil): Valu throwCannotConvert() of Quantity: - ensureCleaned(y) - return newQuantity(cleanY[0], parseQuantitySpec(cleanY[1].s)) + return newQuantity(y.a[0], parseQuantitySpec(y.a[1].s)) of Color: - ensureCleaned(y) - if cleanY.len < 3 or cleanY.len > 4: + if y.a.len < 3 or y.a.len > 4: echo "wrong number of attributes" else: if (hadAttr("hsl")): - if cleanY.len==3: - return newColor(HSLtoRGB((cleanY[0].i, cleanY[1].f, cleanY[2].f, 1.0))) - elif cleanY.len==4: - return newColor(HSLtoRGB((cleanY[0].i, cleanY[1].f, cleanY[2].f, cleanY[3].f))) + if y.a.len==3: + return newColor(HSLtoRGB((y.a[0].i, y.a[1].f, y.a[2].f, 1.0))) + elif y.a.len==4: + return newColor(HSLtoRGB((y.a[0].i, y.a[1].f, y.a[2].f, y.a[3].f))) elif (hadAttr("hsv")): - if cleanY.len==3: - return newColor(HSVtoRGB((cleanY[0].i, cleanY[1].f, cleanY[2].f, 1.0))) - elif cleanY.len==4: - return newColor(HSVtoRGB((cleanY[0].i, cleanY[1].f, cleanY[2].f, cleanY[3].f))) + if y.a.len==3: + return newColor(HSVtoRGB((y.a[0].i, y.a[1].f, y.a[2].f, 1.0))) + elif y.a.len==4: + return newColor(HSVtoRGB((y.a[0].i, y.a[1].f, y.a[2].f, y.a[3].f))) else: - if cleanY.len==3: - return newColor((cleanY[0].i, cleanY[1].i, cleanY[2].i, 255)) - elif cleanY.len==4: - return newColor((cleanY[0].i, cleanY[1].i, cleanY[2].i, cleanY[3].i)) + if y.a.len==3: + return newColor((y.a[0].i, y.a[1].i, y.a[2].i, 255)) + elif y.a.len==4: + return newColor((y.a[0].i, y.a[1].i, y.a[2].i, y.a[3].i)) of Binary: var res: VBinary - ensureCleaned(y) - for item in cleanY: + for item in y.a: if item.kind==Integer: res &= numberToBinary(item.i) else: @@ -682,8 +675,7 @@ proc defineSymbols*() = elif (hadAttr("octal")): push(newString(fmt"{x.i:o}")) elif (hadAttr("agnostic")): - ensureCleaned(x) - let res = cleanX.map(proc(v:Value):Value = + let res = x.a.map(proc(v:Value):Value = if v.kind == Word and not SymExists(v.s): newLiteral(v.s) else: v ) @@ -866,9 +858,8 @@ proc defineSymbols*() = if (hadAttr("raw")): dict = initOrderedTable[string,Value]() var idx = 0 - ensureCleaned(x) - while idx < cleanX.len: - dict[cleanX[idx].s] = cleanX[idx+1] + while idx < x.a.len: + dict[x.a[idx].s] = x.a[idx+1] idx += 2 else: dict = execDictionary(x) @@ -1412,20 +1403,18 @@ proc defineSymbols*() = push convertedValueToType(x, y, tp, popAttr("format")) else: var ret: ValueArray - ensureCleaned(x) - let tp = cleanX[0].t + let tp = x.a[0].t if y.kind==String: ret = toSeq(runes(y.s)).map((c) => newChar(c)) else: let aFormat = popAttr("format") if y.kind == Block: - ensureCleaned(y) - for item in cleanY: - ret.add(convertedValueToType(cleanX[0], item, tp, aFormat)) + for item in y.a: + ret.add(convertedValueToType(x.a[0], item, tp, aFormat)) else: for item in items(y.rng): - ret.add(convertedValueToType(cleanX[0], item, tp, aFormat)) + ret.add(convertedValueToType(x.a[0], item, tp, aFormat)) push newBlock(ret) @@ -1459,8 +1448,7 @@ proc defineSymbols*() = blk.insert(FetchSym(x.s)) blk.insert(newLabel(x.s)) else: - ensureCleaned(x) - for item in cleanX: + for item in x.a: blk.insert(FetchSym(item.s)) blk.insert(newLabel(item.s)) diff --git a/src/library/Core.nim b/src/library/Core.nim index 702385ed3b..3612995a68 100644 --- a/src/library/Core.nim +++ b/src/library/Core.nim @@ -529,13 +529,11 @@ proc defineSymbols*() = """: #======================================================= if x.kind==Block: - ensureCleaned(x) if y.kind==Block: - ensureCleaned(y) - for i,w in pairs(cleanX): - SetSym(w.s, cleanY[i], safe=true) + for i,w in pairs(x.a): + SetSym(w.s, y.a[i], safe=true) else: - for w in items(cleanX): + for w in items(x.a): SetSym(w.s, y, safe=true) else: SetInPlace(y, safe=true) @@ -874,14 +872,13 @@ proc defineSymbols*() = #======================================================= let z = pop() if isFalse(z): - ensureCleaned(x) let top = sTop() var newb: Value = newBlock() for old in top.a: newb.a.add(old) - for cond in cleanX: + for cond in x.a: newb.a.add(cond) execUnscoped(newb) diff --git a/src/library/Files.nim b/src/library/Files.nim index a693594281..2e804ad114 100644 --- a/src/library/Files.nim +++ b/src/library/Files.nim @@ -568,9 +568,7 @@ proc defineSymbols*() = #======================================================= when defined(SAFE): RuntimeError_OperationNotPermitted("zip") - ensureCleaned(y) - - let files: seq[string] = cleanY.map((z)=>z.s) + let files: seq[string] = y.a.map((z)=>z.s) miniz.zip(files, x.s) #======================================= diff --git a/src/library/Iterators.nim b/src/library/Iterators.nim index 6449000520..29740ccdc0 100644 --- a/src/library/Iterators.nim +++ b/src/library/Iterators.nim @@ -289,7 +289,8 @@ template fetchIterableItems(doesAcceptLiterals=true, defaultReturn: untyped) {.d var blo = case iterable.kind: of Block,Inline: - cleanedBlockValuesCopy(iterable) + #cleanedBlockValuesCopy(iterable) + iterable.a of Dictionary: iterable.d.flattenedDictionary() of Object: diff --git a/src/library/Logic.nim b/src/library/Logic.nim index b4f598ee0a..52365d7f78 100644 --- a/src/library/Logic.nim +++ b/src/library/Logic.nim @@ -47,15 +47,14 @@ proc defineSymbols*() = ; false """: #======================================================= - ensureCleaned(x) # check if empty - if cleanX.len==0: + if x.a.len==0: push(newLogical(false)) return var allOK = true - for item in cleanX: + for item in x.a: var val {.cursor.}: Value if item.kind == Block: execUnscoped(item) @@ -138,14 +137,13 @@ proc defineSymbols*() = ; false """: #======================================================= - ensureCleaned(x) # check if empty - if cleanX.len==0: + if x.a.len==0: push(newLogical(false)) return var anyOK = false - for item in cleanX: + for item in x.a: var val: Value if item.kind == Block: execUnscoped(item) diff --git a/src/library/Numbers.nim b/src/library/Numbers.nim index 88c69cb965..403bef8a72 100644 --- a/src/library/Numbers.nim +++ b/src/library/Numbers.nim @@ -779,25 +779,24 @@ proc defineSymbols*() = print gcd [48 60 120] ; 12 """: #======================================================= - ensureCleaned(x) - var current = cleanX[0] + var current = x.a[0] var i = 1 # TODO(Numbers\gcd) not working for Web builds # labels: web,enhancement - while iz.a) + let blk = x.a.map((z)=>z.a) push(newBlock(cartesianProduct(blk).map((z) => newBlock(z)))) else: var product = I1.copyValue @@ -1129,12 +1126,11 @@ proc defineSymbols*() = product *= item push(product) else: - ensureCleaned(x) - if cleanX.len==0: push(I0.copyValue) + if x.a.len==0: push(I0.copyValue) else: var i = 0 - while i 45.65847597731914 """: #======================================================= - ensureCleaned(x) if (hadAttr("sample")): - push newFloating(standardDeviationS(cleanX.map((z)=>asFloat(z)))) + push newFloating(standardDeviationS(x.a.map((z)=>asFloat(z)))) else: - push newFloating(standardDeviation(cleanX.map((z)=>asFloat(z)))) + push newFloating(standardDeviation(x.a.map((z)=>asFloat(z)))) builtin "kurtosis", alias = unaliased, @@ -118,11 +116,10 @@ proc defineSymbols*() = kurtosis.sample arr2 ; => 0.5886192422439724 """: #======================================================= - ensureCleaned(x) if (hadAttr("sample")): - push newFloating(kurtosisS(cleanX.map((z)=>asFloat(z)))) + push newFloating(kurtosisS(x.a.map((z)=>asFloat(z)))) else: - push newFloating(kurtosis(cleanX.map((z)=>asFloat(z)))) + push newFloating(kurtosis(x.a.map((z)=>asFloat(z)))) builtin "median", alias = unaliased, @@ -142,14 +139,13 @@ proc defineSymbols*() = ; 3.5 """: #======================================================= - ensureCleaned(x) - if cleanX.len==0: + if x.a.len==0: push(VNULL) else: - let first = cleanX[(cleanX.len-1) div 2] - let second = cleanX[((cleanX.len-1) div 2)+1] + let first = x.a[(x.a.len-1) div 2] + let second = x.a[((x.a.len-1) div 2)+1] - if cleanX.len mod 2 == 1: + if x.a.len mod 2 == 1: push(first) else: push((first + second)//I2) @@ -177,11 +173,10 @@ proc defineSymbols*() = skewness.sample arr2 ; => 1.40680083744453 """: #======================================================= - ensureCleaned(x) if (hadAttr("sample")): - push newFloating(skewnessS(cleanX.map((z)=>asFloat(z)))) + push newFloating(skewnessS(x.a.map((z)=>asFloat(z)))) else: - push newFloating(skewness(cleanX.map((z)=>asFloat(z)))) + push newFloating(skewness(x.a.map((z)=>asFloat(z)))) builtin "variance", alias = unaliased, @@ -206,11 +201,10 @@ proc defineSymbols*() = variance.sample arr2 ; => 2084.696428571428 """: #======================================================= - ensureCleaned(x) if (hadAttr("sample")): - push newFloating(varianceS(cleanX.map((z)=>asFloat(z)))) + push newFloating(varianceS(x.a.map((z)=>asFloat(z)))) else: - push newFloating(variance(cleanX.map((z)=>asFloat(z)))) + push newFloating(variance(x.a.map((z)=>asFloat(z)))) #======================================= # Add Library diff --git a/src/library/Strings.nim b/src/library/Strings.nim index 55fabb137d..fa251c91b6 100644 --- a/src/library/Strings.nim +++ b/src/library/Strings.nim @@ -328,8 +328,7 @@ proc defineSymbols*() = ensureInPlace() SetInPlace(newString(joinPath(InPlaced.a.map(proc (v:Value):string = $(v))))) else: - ensureCleaned(x) - push(newString(joinPath(cleanX.map(proc (v:Value):string = $(v))))) + push(newString(joinPath(x.a.map(proc (v:Value):string = $(v))))) else: var sep: string if checkAttr("with"): @@ -339,8 +338,7 @@ proc defineSymbols*() = ensureInPlace() SetInPlace(newString(InPlaced.a.map(proc (v:Value):string = $(v)).join(sep))) else: - ensureCleaned(x) - push(newString(cleanX.map(proc (v:Value):string = $(v)).join(sep))) + push(newString(x.a.map(proc (v:Value):string = $(v)).join(sep))) builtin "levenshtein", alias = unaliased, diff --git a/src/vm/values/comparison.nim b/src/vm/values/comparison.nim index ee5db47c2b..206380848b 100644 --- a/src/vm/values/comparison.nim +++ b/src/vm/values/comparison.nim @@ -116,13 +116,11 @@ proc `==`*(x: Value, y: Value): bool {.inline, enforceNoRaises.}= of Bytecode: return x.trans == y.trans of Inline, Block: - ensureCleaned(x) - ensureCleaned(y) - if cleanX.len != cleanY.len: return false + if x.a.len != y.a.len: return false - for i,child in cleanX: - if not (child==cleanY[i]): return false + for i,child in x.a: + if not (child==y.a[i]): return false return true @@ -243,9 +241,7 @@ proc `<`*(x: Value, y: Value): bool {.inline.}= of Symbol: return false of Inline, Block: - ensureCleaned(x) - ensureCleaned(y) - return cleanX.len < cleanY.len + return x.a.len < y.a.len of Dictionary: return false of Object: diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index 4d9b20fb3b..34aa6b3b48 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -105,8 +105,6 @@ proc `$`*(v: Value): string {.inline.} = # for i,child in v.a: # result &= $(child) & " " # result &= "]" - - ensureCleaned(v) result = "[" & cleanV.map((child) => $(child)).join(" ") & "]" of Range : @@ -301,7 +299,6 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen of Inline, Block : dumpBlockStart(v) - ensureCleaned(v) for i,child in cleanV: dump(child, level+1, i==(cleanV.len-1), muted=muted) @@ -504,7 +501,6 @@ proc codify*(v: Value, pretty = false, unwrapped = false, level: int=0, isLast: result &= "\n" var parts: seq[string] - ensureCleaned(v) for i,child in cleanV: parts.add(codify(child,pretty,unwrapped,level+1, i==(cleanV.len-1), safeStrings=safeStrings)) diff --git a/src/vm/values/value.nim b/src/vm/values/value.nim index c6d20de76d..c9c963630c 100644 --- a/src/vm/values/value.nim +++ b/src/vm/values/value.nim @@ -696,8 +696,7 @@ proc copyValue*(v: Value): Value {.inline.} = of Inline: result = newInline(v.a) of Block: if v.data.isNil: - let newValues = cleanedBlockValuesCopy(v) - result = Value(kind: Block, a: newValues) + result = Value(kind: Block, a: v.a) else: result = newBlock(v.a.map((vv)=>copyValue(vv)), copyValue(v.data)) of Range: From 9f7f659dc5d23490100c614c31ba7cef50bab4d1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:45:40 +0100 Subject: [PATCH 467/984] VM/values/printable: also remove `cleanV`s here --- src/vm/values/printable.nim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index 34aa6b3b48..297a01aa3c 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -105,7 +105,7 @@ proc `$`*(v: Value): string {.inline.} = # for i,child in v.a: # result &= $(child) & " " # result &= "]" - result = "[" & cleanV.map((child) => $(child)).join(" ") & "]" + result = "[" & v.a.map((child) => $(child)).join(" ") & "]" of Range : result = $(v.rng) @@ -299,8 +299,8 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen of Inline, Block : dumpBlockStart(v) - for i,child in cleanV: - dump(child, level+1, i==(cleanV.len-1), muted=muted) + for i,child in v.a: + dump(child, level+1, i==(v.a.len-1), muted=muted) stdout.write "\n" @@ -501,8 +501,8 @@ proc codify*(v: Value, pretty = false, unwrapped = false, level: int=0, isLast: result &= "\n" var parts: seq[string] - for i,child in cleanV: - parts.add(codify(child,pretty,unwrapped,level+1, i==(cleanV.len-1), safeStrings=safeStrings)) + for i,child in v.a: + parts.add(codify(child,pretty,unwrapped,level+1, i==(v.a.len-1), safeStrings=safeStrings)) result &= parts.join(" ") From 5fe3bd09df54f71a504ebf0fe03ec0f20296d0eb Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:45:43 +0100 Subject: [PATCH 468/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index fec140d036..bd8a6ab6a0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3744 \ No newline at end of file +3745 \ No newline at end of file From b0a51fb84c7f588217146bf2ebc5d26cd3202c26 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:46:41 +0100 Subject: [PATCH 469/984] VM/ast: nothing to do with Newline values here either; simply because they don't exist anymore... --- src/vm/ast.nim | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 3e5cbbbb6d..e2016f3a98 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -676,9 +676,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, else: current.addTerminal(newConstant(item)) - of Newline: - discard - else: current.addTerminal(newConstant(item)) From b7cbdb3b9584f74decabd6fd026b30bad111f296 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:46:44 +0100 Subject: [PATCH 470/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bd8a6ab6a0..545dee44f0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3745 \ No newline at end of file +3746 \ No newline at end of file From 7787072f8d7934456e20e515c94fb45ca8d687ad Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:47:43 +0100 Subject: [PATCH 471/984] VM/parse: remove unused import --- src/vm/parse.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/parse.nim b/src/vm/parse.nim index 55a6cc9236..8027ea9dd0 100644 --- a/src/vm/parse.nim +++ b/src/vm/parse.nim @@ -24,7 +24,7 @@ # Libraries #======================================= -import lexbase, os, sequtils, streams +import lexbase, os, streams import strutils, tables, unicode import vm/[errors, profiler, values/value] From 1201fce3a6219e37c7b264bfe8b1ea8b2bf0495e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 13:58:32 +0100 Subject: [PATCH 472/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 545dee44f0..81be9db4b4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3746 \ No newline at end of file +3747 \ No newline at end of file From 7e355a8a22f56fc8cfaa832241cf4aabe080702f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 14:27:01 +0100 Subject: [PATCH 473/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 81be9db4b4..bfefa37899 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3747 \ No newline at end of file +3748 \ No newline at end of file From 4bb7b247a5622d316bed31c1f74fa370e19099d0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 14:33:22 +0100 Subject: [PATCH 474/984] Helpers/arrays: removed all "cleaning" helper functions --- src/helpers/arrays.nim | 109 +++-------------------------------------- 1 file changed, 7 insertions(+), 102 deletions(-) diff --git a/src/helpers/arrays.nim b/src/helpers/arrays.nim index 9c27f01551..c173632c1d 100644 --- a/src/helpers/arrays.nim +++ b/src/helpers/arrays.nim @@ -170,77 +170,12 @@ proc deduplicated*[T](s: openArray[T], isSorted: bool = false): seq[T] = for itm in items(s): if not result.contains(itm): result.add(itm) -# Backward compatibility -proc cleanAppend*(s: ValueArray, t: ValueArray): ValueArray {.inline,enforceNoRaises.} = - ## Appends `t` to `s`, cleaning the blocks and returning a `ValueArray` - ## - ## Note: - ## - Use if `x.kind != Literal` in `builtin` functions - ## - `s` and `t` must be a `ValueArray`, not a `Value` - ## - ## To understand more about cleaning blocks, read `vm/values/clean.nim` - - result = newSeq[Value](len(s) + len(t)) - var cnt = 0 - for i in s: - when not defined(NOERRORLINES): - if i.kind != Newline: - result[cnt] = i - cnt += 1 - else: - result[cnt] = i - cnt += 1 - - for i in t: - when not defined(NOERRORLINES): - if i.kind != Newline: - result[cnt] = i - cnt += 1 - else: - result[cnt] = i - cnt += 1 - - setLen(result, cnt) - -func cleanAppend*(s: Value, t: Value, singleValue: static bool = false): ValueArray {.inline,enforceNoRaises.} = - ## Appends `t` to `s`, cleaning the blocks and returning a `ValueArray` - ## - ## Note: - ## - Use if `x.kind != Literal` in `builtin` functions - ## - `s` and `t` must be a Block value - ## - ## To understand more about cleaning blocks, read `vm/values/clean.nim` - - let L1 = len(s.a) - when not singleValue: - let L2 = len(t.a) - result = newSeq[Value](L1 + L2) - else: - result = newSeq[Value](L1 + 1) - - var cnt = 0 - for i in cleanedBlockValues(s, L1): - result[cnt] = i - inc cnt - - when not singleValue: - for i in cleanedBlockValues(t, L2): - result[cnt] = i - inc cnt - else: - result[cnt] = t - inc cnt - - setLen(result, cnt) - -func cleanPrepend*(s: Value, t: Value, singleValue: static bool = false): ValueArray {.inline,enforceNoRaises.} = - ## Prepends `t` to `s`, cleaning the blocks and returning a `ValueArray` +func prepend*(s: Value, t: Value, singleValue: static bool = false): ValueArray {.inline,enforceNoRaises.} = + ## Prepends `t` to `s`, and returning a `ValueArray` ## ## Note: ## - Use if `x.kind != Literal` in `builtin` functions ## - `s` and `t` must be a Block value - ## - ## To understand more about cleaning blocks, read `vm/values/clean.nim` let L1 = len(s.a) when not singleValue: @@ -251,60 +186,30 @@ func cleanPrepend*(s: Value, t: Value, singleValue: static bool = false): ValueA var cnt = 0 when not singleValue: - for i in cleanedBlockValues(t, L2): + for i in t.a: result[cnt] = i inc cnt else: result[cnt] = t inc cnt - for i in cleanedBlockValues(s, L1): + for i in s.a: result[cnt] = i inc cnt setLen(result, cnt) -proc cleanAppendInPlace*(s: var Value, t: Value) {.inline,enforceNoRaises.} = - ## Appends `t` to `s`, cleaning the blocks and changing `s` in-place +proc prependInPlace*(s: var Value, t: Value) {.inline,enforceNoRaises.} = + ## Prepends `t` to `s`, and changing `s` in-place ## ## Note: ## - Use if `x.kind == Literal`, in `builtin` functions - ## - Else, use `cleanAppend` ## - `s` and `t` values must be a Block value, ## - It doesn't return a new value, it modifies `s` - ## - ## To understand more about cleaning blocks, read `vm/values/clean.nim` - - cleanBlock(s) - - let L1 = len(s.a) - let L2 = len(t.a) - - s.a.setLen(L1 + L2) - - var cnt = L1 - for i in cleanedBlockValues(t, L2): - s.a[cnt] = i - cnt += 1 - - setLen(s.a, cnt) - -proc cleanPrependInPlace*(s: var Value, t: Value) {.inline,enforceNoRaises.} = - ## Prepends `t` to `s`, cleaning the blocks and changing `s` in-place - ## - ## Note: - ## - Use if `x.kind == Literal`, in `builtin` functions - ## - Else, use `cleanAppend` - ## - `s` and `t` values must be a Block value, - ## - It doesn't return a new value, it modifies `s` - ## - ## To understand more about cleaning blocks, read `vm/values/clean.nim` - - cleanBlock(s) let L2 = len(t.a) var cnt = 0 - for i in cleanedBlockValues(t, L2): + for i in t.a: s.a.insert(i, cnt) cnt += 1 From e387c24e675ec17dd5db6248bb47df200936c972 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 14:33:51 +0100 Subject: [PATCH 475/984] Collections: updated `prepend` & `append` to use normal, non-clean implementations --- src/library/Collections.nim | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/library/Collections.nim b/src/library/Collections.nim index 41496dcb91..38fcd484cf 100644 --- a/src/library/Collections.nim +++ b/src/library/Collections.nim @@ -95,9 +95,7 @@ proc defineSymbols*() = InPlaced.n &= numberToBinary(y.i) else: if y.kind == Block: - # TODO(Collections\append) In-place appending should actually work in-place - # labels: enhancement, library - InPlaced.cleanAppendInPlace(y) + InPlaced.a.add(y.a) else: InPlaced.a.add(y) else: @@ -118,9 +116,9 @@ proc defineSymbols*() = push(newBinary(x.n & numberToBinary(y.i))) else: if y.kind==Block: - push newBlock(cleanAppend(x, y)) + push newBlock(x.a & y.a) else: - push newBlock(cleanAppend(x, y, singleValue=true)) + push newBlock(x.a & y) builtin "chop", @@ -1156,7 +1154,7 @@ proc defineSymbols*() = InPlaced.n.insert(numberToBinary(y.i), 0) else: if y.kind == Block: - InPlaced.cleanPrependInPlace(y) + InPlaced.prependInPlace(y) else: InPlaced.a.insert(y, 0) else: @@ -1177,9 +1175,9 @@ proc defineSymbols*() = push(newBinary(numberToBinary(y.i) & x.n)) else: if y.kind==Block: - push newBlock(cleanPrepend(x, y)) + push newBlock(prepend(x, y)) else: - push newBlock(cleanPrepend(x, y, singleValue=true)) + push newBlock(prepend(x, y, singleValue=true)) # TODO(Collections/remove) is `.index` broken? # Example: `remove.index 3 'a, debug a` From c8ebf9a60c3df8c272f4498f862fe0608edf0123 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 14:33:55 +0100 Subject: [PATCH 476/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bfefa37899..f38da30952 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3748 \ No newline at end of file +3749 \ No newline at end of file From 5eb4ba7f84084b486703cbe54d70092ae565e08b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:11:11 +0100 Subject: [PATCH 477/984] correctly replaced all instances of `cleanedBlock(..)` --- src/library/Collections.nim | 4 ++-- src/library/Converters.nim | 4 ++-- src/library/Databases.nim | 2 +- src/library/Sets.nim | 40 ++++++++++++++++++------------------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/library/Collections.nim b/src/library/Collections.nim index 38fcd484cf..8a7bc85e2d 100644 --- a/src/library/Collections.nim +++ b/src/library/Collections.nim @@ -538,7 +538,7 @@ proc defineSymbols*() = ensureInPlace() SetInPlace(InPlaced.flattened(once = hadAttr("once"))) else: - push(newBlock(cleanedBlock(x.a)).flattened(once = hadAttr("once"))) + push(newBlock(x.a).flattened(once = hadAttr("once"))) builtin "get", alias = unaliased, @@ -824,7 +824,7 @@ proc defineSymbols*() = copied.insert($(z.c), y.i) push(newString(copied)) of Block: - var copied = cleanedBlock(x.a) + var copied = x.a copied.insert(z, y.i) push(newBlock(copied)) of Dictionary: diff --git a/src/library/Converters.nim b/src/library/Converters.nim index 6e590f5a62..8c540758c8 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -765,7 +765,7 @@ proc defineSymbols*() = ; NAME: Jane, SURNAME: Doe, AGE: 33 """: #======================================================= - x.ts.fields = cleanedBlock(y.a) + x.ts.fields = y.a if checkAttr("as"): x.ts.inherits = aAs.ts @@ -1443,7 +1443,7 @@ proc defineSymbols*() = ; the multiple of 10 is 20 """: #======================================================= - var blk: ValueArray = cleanedBlock(y.a) + var blk: ValueArray = y.a if x.kind == Literal: blk.insert(FetchSym(x.s)) blk.insert(newLabel(x.s)) diff --git a/src/library/Databases.nim b/src/library/Databases.nim index fe00a1e773..8bd88108e7 100644 --- a/src/library/Databases.nim +++ b/src/library/Databases.nim @@ -138,7 +138,7 @@ proc defineSymbols*() = if (let got = execSqliteDb(x.sqlitedb, y.s, with); got[0]==ValidQueryResult): push(newBlock(got[1])) else: - if (let got = execManySqliteDb(x.sqlitedb, cleanedBlock(y.a).map(proc (v:Value):string = v.s), with); got[0]==ValidQueryResult): + if (let got = execManySqliteDb(x.sqlitedb, y.a.map(proc (v:Value):string = v.s), with); got[0]==ValidQueryResult): push(newBlock(got[1])) if (hadAttr("id")): diff --git a/src/library/Sets.nim b/src/library/Sets.nim index b767b468b0..ff6098c35b 100644 --- a/src/library/Sets.nim +++ b/src/library/Sets.nim @@ -84,15 +84,15 @@ proc defineSymbols*() = if (hadAttr("symmetric")): if x.kind==Literal: ensureInPlace() - SetInPlace(newBlock(toSeq(symmetricDifference(toOrderedSet(cleanedBlock(InPlaced.a)), toOrderedSet(cleanedBlock(y.a)))))) + SetInPlace(newBlock(toSeq(symmetricDifference(toOrderedSet(InPlaced.a), toOrderedSet(y.a))))) else: - push(newBlock(toSeq(symmetricDifference(toOrderedSet(cleanedBlock(x.a)), toOrderedSet(cleanedBlock(y.a)))))) + push(newBlock(toSeq(symmetricDifference(toOrderedSet(x.a), toOrderedSet(y.a))))) else: if x.kind==Literal: ensureInPlace() - SetInPlace(newBlock(toSeq(difference(toOrderedSet(cleanedBlock(InPlaced.a)), toOrderedSet(cleanedBlock(y.a)))))) + SetInPlace(newBlock(toSeq(difference(toOrderedSet(InPlaced.a), toOrderedSet(y.a))))) else: - push(newBlock(toSeq(difference(toOrderedSet(cleanedBlock(x.a)), toOrderedSet(cleanedBlock(y.a)))))) + push(newBlock(toSeq(difference(toOrderedSet(x.a), toOrderedSet(y.a))))) builtin "disjoint?", alias = unaliased, @@ -113,7 +113,7 @@ proc defineSymbols*() = ; => true """: #======================================================= - push(newLogical(disjoint(toOrderedSet(cleanedBlock(x.a)), toOrderedSet(cleanedBlock(y.a))))) + push(newLogical(disjoint(toOrderedSet(x.a), toOrderedSet(y.a)))) builtin "intersect?", alias = unaliased, @@ -137,7 +137,7 @@ proc defineSymbols*() = ; => false """: #======================================================= - let res = intersection(toOrderedSet(cleanedBlock(x.a)), toOrderedSet(cleanedBlock(y.a))) + let res = intersection(toOrderedSet(x.a), toOrderedSet(y.a)) if len(res) >= 0: push(VTRUE) else: @@ -166,9 +166,9 @@ proc defineSymbols*() = #======================================================= if x.kind==Literal: ensureInPlace() - SetInPlace(newBlock(toSeq(intersection(toOrderedSet(cleanedBlock(InPlaced.a)), toOrderedSet(cleanedBlock(y.a)))))) + SetInPlace(newBlock(toSeq(intersection(toOrderedSet(InPlaced.a), toOrderedSet(y.a))))) else: - push(newBlock(toSeq(intersection(toOrderedSet(cleanedBlock(x.a)), toOrderedSet(cleanedBlock(y.a)))))) + push(newBlock(toSeq(intersection(toOrderedSet(x.a), toOrderedSet(y.a))))) builtin "powerset", alias = unaliased, @@ -187,9 +187,9 @@ proc defineSymbols*() = #======================================================= if x.kind==Literal: ensureInPlace() - SetInPlace(newBlock(toSeq(powerset(toOrderedSet(cleanedBlock(InPlaced.a)))).map((hs) => newBlock(toSeq(hs))))) + SetInPlace(newBlock(toSeq(powerset(toOrderedSet(InPlaced.a))).map((hs) => newBlock(toSeq(hs))))) else: - push(newBlock(toSeq(powerset(toOrderedSet(cleanedBlock(x.a))).map((hs) => newBlock(toSeq(hs)))))) + push(newBlock(toSeq(powerset(toOrderedSet(x.a)).map((hs) => newBlock(toSeq(hs)))))) builtin "subset?", alias = unaliased, @@ -226,8 +226,8 @@ proc defineSymbols*() = push(newLogical(false)) else: var contains = true - let xblk = cleanedBlock(x.a) - let yblk = cleanedBlock(y.a) + let xblk = x.a + let yblk = y.a for item in xblk: if item notin yblk: contains = false @@ -239,8 +239,8 @@ proc defineSymbols*() = push(newLogical(true)) else: var contains = true - let xblk = cleanedBlock(x.a) - let yblk = cleanedBlock(y.a) + let xblk = x.a + let yblk = y.a for item in xblk: if item notin yblk: contains = false @@ -283,8 +283,8 @@ proc defineSymbols*() = push(newLogical(false)) else: var contains = true - let xblk = cleanedBlock(x.a) - let yblk = cleanedBlock(y.a) + let xblk = x.a + let yblk = y.a for item in yblk: if item notin xblk: contains = false @@ -296,8 +296,8 @@ proc defineSymbols*() = push(newLogical(true)) else: var contains = true - let xblk = cleanedBlock(x.a) - let yblk = cleanedBlock(y.a) + let xblk = x.a + let yblk = y.a for item in yblk: if item notin xblk: contains = false @@ -328,9 +328,9 @@ proc defineSymbols*() = #======================================================= if x.kind==Literal: ensureInPlace() - SetInPlace(newBlock(toSeq(union(toOrderedSet(cleanedBlock(InPlaced.a)), toOrderedSet(cleanedBlock(y.a)))))) + SetInPlace(newBlock(toSeq(union(toOrderedSet(InPlaced.a), toOrderedSet(y.a))))) else: - push(newBlock(toSeq(union(toOrderedSet(cleanedBlock(x.a)), toOrderedSet(cleanedBlock(y.a)))))) + push(newBlock(toSeq(union(toOrderedSet(x.a), toOrderedSet(y.a))))) #======================================= # Add Library From 6a75f2782ad6af50ad360fb25ab2888f2d1c0718 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:11:15 +0100 Subject: [PATCH 478/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f38da30952..a54aba8fa3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3749 \ No newline at end of file +3750 \ No newline at end of file From 3f342618ade5fd4980c85d2a5e6dcd76812f6537 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:11:53 +0100 Subject: [PATCH 479/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a54aba8fa3..7c6f51d9bc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3750 \ No newline at end of file +3751 \ No newline at end of file From 3d772b43f07beaaf91afd97cd1c0e396b1cbd152 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:12:07 +0100 Subject: [PATCH 480/984] also replaced instances of `cleanBlock` --- src/library/Converters.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/library/Converters.nim b/src/library/Converters.nim index 8c540758c8..a3fde9f9b9 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -1050,8 +1050,6 @@ proc defineSymbols*() = if not inline: if canBeInlined(y): inline = true - - cleanBlock(x) var ret: Value var argTypes = initOrderedTable[string,ValueSpec]() From fa41f3e4647a767f39151d69ac47841c5271ed68 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:12:40 +0100 Subject: [PATCH 481/984] minor fix --- src/library/Collections.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/src/library/Collections.nim b/src/library/Collections.nim index 8a7bc85e2d..2ecb0072be 100644 --- a/src/library/Collections.nim +++ b/src/library/Collections.nim @@ -1485,7 +1485,6 @@ proc defineSymbols*() = #======================================================= case x.kind: of Block: - cleanBlock(x) SetArrayIndex(x.a, y.i, z) of Binary: let bn = numberToBinary(z.i) From d497e325ef463493221f036a907ebb71f3208703 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:12:43 +0100 Subject: [PATCH 482/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7c6f51d9bc..3e7591250c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3751 \ No newline at end of file +3752 \ No newline at end of file From 3adf47b4eded9a78e00aaf3802bb8b10da7435dd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:14:12 +0100 Subject: [PATCH 483/984] Iterators: [fetchParamsBlock] no need for checking for `Newline` values --- src/library/Iterators.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/library/Iterators.nim b/src/library/Iterators.nim index 29740ccdc0..a7ebd510e5 100644 --- a/src/library/Iterators.nim +++ b/src/library/Iterators.nim @@ -267,8 +267,7 @@ template fetchParamsBlock() {.dirty.} = if hasIndex: params.add(withIndex.s) if y.kind != Null: for item in mitems(y.a): - if item.kind != Newline: - params.add(item.s) + params.add(item.s) template prepareIteration(doesAcceptLiterals=true) {.dirty.} = let preevaled = evalOrGet(z) From 43df11e0aaf94abed19fa63c081f6adb38dd15a0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:14:15 +0100 Subject: [PATCH 484/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3e7591250c..8fdd89b81a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3752 \ No newline at end of file +3753 \ No newline at end of file From 8f09b431bc401b919c40f12c8df3ac16fc148276 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:15:30 +0100 Subject: [PATCH 485/984] Helpers/arrays: [prependInPlace] removed unused variable --- src/helpers/arrays.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/helpers/arrays.nim b/src/helpers/arrays.nim index c173632c1d..a10e22e892 100644 --- a/src/helpers/arrays.nim +++ b/src/helpers/arrays.nim @@ -207,8 +207,6 @@ proc prependInPlace*(s: var Value, t: Value) {.inline,enforceNoRaises.} = ## - `s` and `t` values must be a Block value, ## - It doesn't return a new value, it modifies `s` - let L2 = len(t.a) - var cnt = 0 for i in t.a: s.a.insert(i, cnt) From 8e00392036938bc8a4fe65c4154f0b73b7418306 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:15:33 +0100 Subject: [PATCH 486/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8fdd89b81a..e1876ec819 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3753 \ No newline at end of file +3754 \ No newline at end of file From 3efe857178f8a0925a109aa00fb32cbf474585a6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:22:24 +0100 Subject: [PATCH 487/984] VM/ast: [dumpNode] added optional `showNewlines` param --- src/vm/ast.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index e2016f3a98..1b853d0f95 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -691,7 +691,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, # Output #======================================= -proc dumpNode*(node: Node, level = 0, single: static bool = false): string = +proc dumpNode*(node: Node, level = 0, single: static bool = false, showNewlines: static bool = true): string = template indentNode(): untyped = result &= " ".repeat(level) @@ -702,8 +702,9 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false): string = for child in node.children: result &= dumpNode(child, level+1) of NewlineNode: - indentNode() - result &= "NEWLINE: " & $(node.line) & "\n" + when showNewlines: + indentNode() + result &= "NEWLINE: " & $(node.line) & "\n" of TerminalNode: indentNode() result &= "Constant: " & $(node.value) From cf0e090a897a6300d2a011afb19428cb5130d1e1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:22:57 +0100 Subject: [PATCH 488/984] also updated forward declaration --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 1b853d0f95..313453f6b9 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -110,7 +110,7 @@ const # Forward declarations #======================================= -proc dumpNode*(node: Node, level = 0, single: static bool=false): string +proc dumpNode*(node: Node, level = 0, single: static bool=false, showNewlines: static bool=false): string #======================================= # Helpers From 14576cfc5803419aa6df616600a617926635c92b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:23:06 +0100 Subject: [PATCH 489/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e1876ec819..6fc9d338c3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3754 \ No newline at end of file +3755 \ No newline at end of file From 43ee3e5ee202b46f280a2cc66dd05e222c96e1bc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:25:25 +0100 Subject: [PATCH 490/984] VM/ast: resolved ambiguity in function signature --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 313453f6b9..571c5c5c2b 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -691,7 +691,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, # Output #======================================= -proc dumpNode*(node: Node, level = 0, single: static bool = false, showNewlines: static bool = true): string = +proc dumpNode*(node: Node, level = 0, single: static bool = false, showNewlines: static bool = false): string = template indentNode(): untyped = result &= " ".repeat(level) From e39c71a444b2f93337141f7218868fa2c462bd5e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:25:38 +0100 Subject: [PATCH 491/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6fc9d338c3..222cdb942b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3755 \ No newline at end of file +3756 \ No newline at end of file From 7ba9f0732aa1187be052465bc102eddf5b6f430a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:33:46 +0100 Subject: [PATCH 492/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 222cdb942b..4f89be10f5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3756 \ No newline at end of file +3757 \ No newline at end of file From c6eb55fbe451f2a2687cb91cfc018eacc98af680 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:36:55 +0100 Subject: [PATCH 493/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4f89be10f5..d217138668 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3757 \ No newline at end of file +3758 \ No newline at end of file From 24c08ce52ed5b5c3adab862a5553d5445dd5550b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:37:55 +0100 Subject: [PATCH 494/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d217138668..75814c1098 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3758 \ No newline at end of file +3759 \ No newline at end of file From a57feadc7ce87e6bb4da8f980fb00f5a24616b49 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:38:57 +0100 Subject: [PATCH 495/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 75814c1098..7920b9c18f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3759 \ No newline at end of file +3760 \ No newline at end of file From 7a7f8f20b10f6a3a95bffa36b95c9cf4628c1181 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:41:30 +0100 Subject: [PATCH 496/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7920b9c18f..2894aa5d74 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3760 \ No newline at end of file +3761 \ No newline at end of file From 9500629cf1f2cdd9cca9da050a325cb99d091290 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:45:37 +0100 Subject: [PATCH 497/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2894aa5d74..08624d5ef2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3761 \ No newline at end of file +3762 \ No newline at end of file From f30a49f164afff9747d50661d13a33e95bae9e0a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:45:58 +0100 Subject: [PATCH 498/984] VM/ast: attempt at fixing nested `->`s & `=>`s --- src/vm/ast.nim | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 571c5c5c2b..3f696029c8 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -94,7 +94,7 @@ type var TmpArities : Table[string,int8] - ArrowBlock : ValueArray + ArrowBlock : seq[ValueArray] OldChild : Node OldParent : Node @@ -226,6 +226,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, var current = root + when processingArrow: + ArrowBlock.add(@[]) + #------------------------ # Optimization #------------------------ @@ -438,7 +441,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if symfunc.kind==Function and aliased.precedence==InfixPrecedence: when processingArrow: - ArrowBlock.add(nextNode) + ArrowBlock[^1].add(nextNode) i += 1 target.addCall(aliased.name.s, fun=symfunc) @@ -551,9 +554,11 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, var subNode = newRootNode() i = subNode.processBlock(val, start=i+1, startingLine=currentLine, processingArrow=true) - target.addTerminal(newConstant(newBlock(ArrowBlock))) - - ArrowBlock.setLen(0) + let poppedArrowBlock = newBlock(ArrowBlock.pop()) + when processingArrow: + ArrowBlock[^1].add(poppedArrowBlock) + + target.addTerminal(newConstant(poppedArrowBlock)) proc addThickArrowBlocks(target: var Node) = # get next node @@ -590,10 +595,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, idx += 1 if argblock.len == 1: + when processingArrow: + ArrowBlock[^1].add(newLiteral(argblock[0].s)) target.addTerminal(newConstant(newLiteral(argblock[0].s))) else: + when processingArrow: + ArrowBlock[^1].add(newBlock(argblock)) target.addTerminal(newConstant(newBlock(argblock))) + when processingArrow: + ArrowBlock[^1].add(newBlock(subblock)) target.addTerminal(newConstant(newBlock(subblock))) #------------------------ @@ -607,11 +618,10 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, currentLine = item.ln current.addNewline() - when processingArrow: - ArrowBlock.add(item) - case item.kind: of Word: + when processingArrow: ArrowBlock[^1].add(item) + var funcArity = TmpArities.getOrDefault(item.s, -1) if funcArity != -1: current.addCall(item.s, funcArity) @@ -624,21 +634,33 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, current.addTerminal(newVariable(item)) of Label: + when processingArrow: ArrowBlock[^1].add(item) + current.addStore(item) of Attribute: + when processingArrow: ArrowBlock[^1].add(item) + current.addAttribute(item) of AttributeLabel: + when processingArrow: ArrowBlock[^1].add(item) + current.addAttribute(item, isLabel=true) of Path: + when processingArrow: ArrowBlock[^1].add(item) + current.addPath(item) of PathLabel: + when processingArrow: ArrowBlock[^1].add(item) + current.addPath(item, isLabel=true) of Inline: + when processingArrow: ArrowBlock[^1].add(item) + current.addInline(item) of Symbol: @@ -662,6 +684,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, current.addPotentialTrailingPipe() else: + when processingArrow: ArrowBlock[^1].add(item) + let symalias = item.m let aliased = Aliases.getOrDefault(symalias, NoAliasBinding) if likely(aliased != NoAliasBinding): @@ -677,6 +701,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, current.addTerminal(newConstant(item)) else: + when processingArrow: ArrowBlock[^1].add(item) + current.addTerminal(newConstant(item)) i += 1 From d8a7245dc045b68ac2cb8b8f395a254f9662b459 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:47:38 +0100 Subject: [PATCH 499/984] temporarily disable debugging --- src/vm/ast.nim | 2 +- src/vm/eval.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 3f696029c8..f6eb20827d 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -768,7 +768,7 @@ proc generateAst*(parsed: Value): Node = discard result.processBlock(parsed) - echo dumpNode(result) + #echo dumpNode(result) # echo "TRAVERSING" diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 4757e38931..950838bc21 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - dump(newBytecode(result)) + #dump(newBytecode(result)) when useStored: if vhash != -1: From 9e42bbd910bfbfc022bddc7b53125e7c0c86f6eb Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:47:42 +0100 Subject: [PATCH 500/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 08624d5ef2..f336e8d62d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3762 \ No newline at end of file +3763 \ No newline at end of file From 95bd23480edd333864090e8582febb530132c6d8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:51:07 +0100 Subject: [PATCH 501/984] reenabled debugging --- src/vm/ast.nim | 2 +- src/vm/eval.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index f6eb20827d..3f696029c8 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -768,7 +768,7 @@ proc generateAst*(parsed: Value): Node = discard result.processBlock(parsed) - #echo dumpNode(result) + echo dumpNode(result) # echo "TRAVERSING" diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 950838bc21..4757e38931 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - #dump(newBytecode(result)) + dump(newBytecode(result)) when useStored: if vhash != -1: From 63996b7e9fa56f21c293a28e508e4534a4f6bf62 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:51:14 +0100 Subject: [PATCH 502/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f336e8d62d..bbf586e738 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3763 \ No newline at end of file +3764 \ No newline at end of file From 71c6cbd56a8566e774c9d60bc9895eaf8b591894 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:55:08 +0100 Subject: [PATCH 503/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bbf586e738..0535ff1377 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3764 \ No newline at end of file +3765 \ No newline at end of file From 9c51d71de31b070781d481d8584f1a94fe293bd2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:55:24 +0100 Subject: [PATCH 504/984] VM/ast: [dumpNode] fix printing for AttributeNodes --- src/vm/ast.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 3f696029c8..1f7bed7bbf 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -740,7 +740,10 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false, showNewlines: if node.kind == VariableStore: result &= "Store: " & $(node.value) & "\n" else: - result &= "Call: " + if node.kind == AttributeNode: + result &= "Attribute: " + else: + result &= "Call: " if node.value.isNil: var callName = ($node.op).toLowerAscii() callName.removePrefix("op") From 7ef484bd9cbd0df4b46a817ade82fb0d45cddf42 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 16:58:35 +0100 Subject: [PATCH 505/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0535ff1377..a11aaa91b7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3765 \ No newline at end of file +3766 \ No newline at end of file From d72a6d1996ed1a9ff40528221c072f013a058020 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:05:04 +0100 Subject: [PATCH 506/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a11aaa91b7..00d5cf983d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3766 \ No newline at end of file +3767 \ No newline at end of file From e43ee0be3d6db8bbe9881a806413f57bd04259db Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:06:08 +0100 Subject: [PATCH 507/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 00d5cf983d..1944dda93f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3767 \ No newline at end of file +3768 \ No newline at end of file From da142b06981b014dfdcde112e3933ad1f17182d5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:10:57 +0100 Subject: [PATCH 508/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1944dda93f..cd37368050 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3768 \ No newline at end of file +3769 \ No newline at end of file From be3905550539fc16148e354be9d306759f7b2832 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:13:33 +0100 Subject: [PATCH 509/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cd37368050..906d72c4ed 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3769 \ No newline at end of file +3770 \ No newline at end of file From a5230ab4cea9a15070bea516eaec942f3ed51f98 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:17:29 +0100 Subject: [PATCH 510/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 906d72c4ed..a175104cde 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3770 \ No newline at end of file +3771 \ No newline at end of file From bdfe5a96e01ec936bce0fc1d638c17aa6ba30253 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:19:08 +0100 Subject: [PATCH 511/984] VM/ast: added new `addTerminals` helper + fixed `addThickArrowBlocks` --- src/vm/ast.nim | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 1f7bed7bbf..fe57a7e33a 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -131,7 +131,7 @@ func addChild*(node: Node, child: Node) {.enforceNoRaises.} = if node.kind in CallNode and child.kind notin {NewlineNode, AttributeNode}: node.params += 1 -func addChildren*(node: Node, children: NodeArray) {.enforceNoRaises.} = +func addChildren*(node: Node, children: openArray[Node]) {.enforceNoRaises.} = for child in children: node.addChild(child) @@ -455,6 +455,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, rewindCallBranches(optimize=true) + proc addTerminals(target: var Node, nodes: openArray[Node]) = + with target: + rewindCallBranches() + + addPotentialInfixCall() + + addChildren(nodes) + + rewindCallBranches(optimize=true) + proc addPath(target: var Node, val: Value, isLabel: static bool=false) = var pathCallV: Value = nil @@ -541,14 +551,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, var subNode = newRootNode() discard subNode.processBlock(val, startingLine=currentLine) - with target: - rewindCallBranches() - - addPotentialInfixCall() - - addChildren(subNode.children) - - rewindCallBranches() + target.addTerminals(subNode.children) proc addArrowBlock(target: var Node, val: Value) = var subNode = newRootNode() @@ -597,15 +600,23 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if argblock.len == 1: when processingArrow: ArrowBlock[^1].add(newLiteral(argblock[0].s)) - target.addTerminal(newConstant(newLiteral(argblock[0].s))) + ArrowBlock[^1].add(newBlock(subblock)) + + target.addTerminals([ + newConstant(newLiteral(argblock[0].s)), + newConstant(newBlock(subblock)) + ]) else: when processingArrow: ArrowBlock[^1].add(newBlock(argblock)) - target.addTerminal(newConstant(newBlock(argblock))) + ArrowBlock[^1].add(newBlock(subblock)) - when processingArrow: - ArrowBlock[^1].add(newBlock(subblock)) - target.addTerminal(newConstant(newBlock(subblock))) + target.addTerminals([ + newConstant(newBlock(argblock)), + newConstant(newBlock(subblock)) + ]) + + i += 1 #------------------------ # The Main Loop From df59113b12378d0631045d8ab9f7b55f577d2826 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:19:42 +0100 Subject: [PATCH 512/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a175104cde..c41cc3609d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3771 \ No newline at end of file +3772 \ No newline at end of file From a4f2edfc4d9246f1611bc92819535de8c296f241 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:22:32 +0100 Subject: [PATCH 513/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c41cc3609d..75d571b821 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3772 \ No newline at end of file +3773 \ No newline at end of file From 77447bd03d195fb00adc48a1b51584e776898332 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:27:06 +0100 Subject: [PATCH 514/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 75d571b821..689d11a84d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3773 \ No newline at end of file +3774 \ No newline at end of file From 5be9b97d663604e6a2a5262348864c6799335f49 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:27:35 +0100 Subject: [PATCH 515/984] treat function calls with zero parameters as implicit terminal values & rewind call branches --- src/vm/ast.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index fe57a7e33a..cb70e4f9e1 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -411,7 +411,10 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, target.addChild(newCallNode(callType, ar, v, op)) - target.rollThrough() + if ar != 0: + target.rollThrough() + else: + target.rewindCallBranches() func addStore(target: var Node, val: Value) {.enforceNoRaises.} = target.addChild(newCallNode(VariableStore, 1, val)) From b26593edc057b371b93461cf2ab6ec8f8b71ba41 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:28:06 +0100 Subject: [PATCH 516/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 689d11a84d..55d5550a82 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3774 \ No newline at end of file +3775 \ No newline at end of file From c3892bbe1338c45cc74555f6cf3bebcb5f18b223 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:28:15 +0100 Subject: [PATCH 517/984] disable debugging --- src/vm/ast.nim | 2 +- src/vm/eval.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index cb70e4f9e1..9024471245 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -785,7 +785,7 @@ proc generateAst*(parsed: Value): Node = discard result.processBlock(parsed) - echo dumpNode(result) + #echo dumpNode(result) # echo "TRAVERSING" diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 4757e38931..950838bc21 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - dump(newBytecode(result)) + #dump(newBytecode(result)) when useStored: if vhash != -1: From d13567092e8a138e9e3e8aac4deff962b0468c33 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:36:25 +0100 Subject: [PATCH 518/984] VM/ast: added `optimizeFunction` helper --- src/vm/ast.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 9024471245..6b73da419e 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -347,6 +347,10 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if right.kind == ConstantValue and right.value.kind == String: target.replaceNode(newConstant(newString(left.value.s & right.value.s))) + proc optimizeFunction(target: var Node) {.enforceNoRaises.} = + if target.parent.kind == VariableStore: + TmpArities[target.parent.value.s] = int8(target.children[0].value.a.len) + #------------------------ # Helper Functions #------------------------ @@ -365,6 +369,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, of opUnless, opUnlessE : target.optimizeUnless() of opAppend : target.optimizeAppend() + of opFunc : target.optimizeFunction() else: discard From fc56663a4f7899a0f7817167dd5d2c14db2579e0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:36:33 +0100 Subject: [PATCH 519/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 55d5550a82..1fdd660014 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3775 \ No newline at end of file +3776 \ No newline at end of file From 235fb9fb88d7e17bab7c76078f8d64d5b2d911b8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:42:47 +0100 Subject: [PATCH 520/984] VM/ast: [addCall] handle the case where the function cannot be found in the Syms table (because it has been declared in the very block that is being processed) --- src/vm/ast.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 6b73da419e..0c940476ce 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -388,19 +388,19 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, var fn {.cursor.}: Value = if fun.isNil: - GetSym(name) + Syms.getOrDefault(name, nil) else: fun var ar: int8 = - if arity == -1: + if arity == -1 and not fn.isNil: fn.arity else: arity var op: OpCode = opNop - if fn.fnKind == BuiltinFunction: + if (not fn.isNil) and fn.fnKind == BuiltinFunction: if (op = fn.op; op != opNop): callType = if op in {opIf, opIfE, opUnless, opUnlessE, opElse, opSwitch, opWhile}: From 0dcf0e30f8cd30825bdbf914f1b005e4131bce86 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:42:52 +0100 Subject: [PATCH 521/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1fdd660014..e45c0d97ea 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3776 \ No newline at end of file +3777 \ No newline at end of file From c6131ad27aa1300c9f8b60f6ebc7c4e9aeb939aa Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:54:49 +0100 Subject: [PATCH 522/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e45c0d97ea..471e05c51e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3777 \ No newline at end of file +3778 \ No newline at end of file From fa111ee42df01474fbc7a3d7982e90793c1e6781 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:58:33 +0100 Subject: [PATCH 523/984] Logic/all?: fixed associated opCode --- src/library/Logic.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/Logic.nim b/src/library/Logic.nim index 52365d7f78..e33da1189f 100644 --- a/src/library/Logic.nim +++ b/src/library/Logic.nim @@ -30,7 +30,7 @@ proc defineSymbols*() = builtin "all?", alias = unaliased, - op = opNot, + op = opNop, rule = PrefixPrecedence, description = "check if all values in given block are true", args = { From 8f4afd96d37b833ea26c832f795151cf6469f3f1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 17:58:58 +0100 Subject: [PATCH 524/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 471e05c51e..f2653bccbb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3778 \ No newline at end of file +3779 \ No newline at end of file From 9b4179e5cee8d03fbd5830ca617917a65fb88cb4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 18:04:54 +0100 Subject: [PATCH 525/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f2653bccbb..8f24e40e98 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3779 \ No newline at end of file +3780 \ No newline at end of file From afb3331c4a6c62cf384ba1acafd101746b810da0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 18:06:47 +0100 Subject: [PATCH 526/984] updated RC example --- examples/rosetta/detect division by zero.art | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/rosetta/detect division by zero.art b/examples/rosetta/detect division by zero.art index bf92c58eaa..fa8d46f9db 100644 --- a/examples/rosetta/detect division by zero.art +++ b/examples/rosetta/detect division by zero.art @@ -1,2 +1,3 @@ -try? -> 3/0 +a: 0 +try? -> 3 / a else -> print "division by zero" \ No newline at end of file From 8bc237d97ebea3cd4165b4e614e11e27f3292683 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 18:20:08 +0100 Subject: [PATCH 527/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8f24e40e98..38d7b8d20a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3780 \ No newline at end of file +3781 \ No newline at end of file From 23aeeda9764a1d5a3bf1bd26c8df60c772542c4e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 18:24:02 +0100 Subject: [PATCH 528/984] re-enable debugging --- src/vm/eval.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 950838bc21..4757e38931 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - #dump(newBytecode(result)) + dump(newBytecode(result)) when useStored: if vhash != -1: From 17662469edb0ac6d2394164c2db6e0610ca747b9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 18:24:25 +0100 Subject: [PATCH 529/984] VM/ast: re-enable debugging + limit `optimizeSub` & `optimizeArithmeticOp` to Integer/Floating values --- src/vm/ast.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 0c940476ce..8b3551bef0 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -293,7 +293,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, var left = target.children[0] var right = target.children[1] - if left.kind == ConstantValue and right.kind == ConstantValue: + if left.kind == ConstantValue and left.value.kind in {Integer,Floating} and right.kind == ConstantValue and right.value.kind in {Integer,Floating}: # Constant folding target.replaceNode(newConstant(left.value - right.value)) elif right.kind == ConstantValue and right.value == I1: @@ -306,7 +306,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, var left = target.children[0] var right = target.children[1] - if left.kind == ConstantValue and right.kind == ConstantValue: + if left.kind == ConstantValue and left.value.kind in {Integer,Floating} and right.kind == ConstantValue and right.value.kind in {Integer,Floating}: target.replaceNode(newConstant(op(left.value,right.value))) proc optimizeUnless(target: var Node) {.enforceNoRaises.} = @@ -361,7 +361,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, case target.op: of opAdd : target.optimizeAdd() of opSub : target.optimizeSub() - of opMul : target.optimizeArithmeticOp(`*`) + #of opMul : target.optimizeArithmeticOp(`*`) of opDiv : target.optimizeArithmeticOp(`/`) of opFDiv : target.optimizeArithmeticOp(`//`) of opMod : target.optimizeArithmeticOp(`%`) @@ -790,7 +790,7 @@ proc generateAst*(parsed: Value): Node = discard result.processBlock(parsed) - #echo dumpNode(result) + echo dumpNode(result) # echo "TRAVERSING" From b33e66d317bb1626d0b201eb495615230b22adcd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 18:24:30 +0100 Subject: [PATCH 530/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 38d7b8d20a..34bc3b4c16 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3781 \ No newline at end of file +3782 \ No newline at end of file From fba2221a323945799a0a2bd9ad7b1ac93803bec7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 18:26:00 +0100 Subject: [PATCH 531/984] re-disable debugging --- src/vm/ast.nim | 2 +- src/vm/eval.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 8b3551bef0..d13cc6d6e6 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -790,7 +790,7 @@ proc generateAst*(parsed: Value): Node = discard result.processBlock(parsed) - echo dumpNode(result) + #echo dumpNode(result) # echo "TRAVERSING" diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 4757e38931..950838bc21 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - dump(newBytecode(result)) + #dump(newBytecode(result)) when useStored: if vhash != -1: From 93e68f0acd3c44d1fdd9949c55069c41166de519 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 19 Jan 2023 18:26:05 +0100 Subject: [PATCH 532/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 34bc3b4c16..0d88cd091e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3782 \ No newline at end of file +3783 \ No newline at end of file From 672742590a8257366c0c191f36248180e8a15264 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 13:17:09 +0100 Subject: [PATCH 533/984] VM/ast: added `asDictionary` parameter to `processBlock` + updated inline TODOs --- src/vm/ast.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index d13cc6d6e6..2fedb38f1e 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -26,7 +26,8 @@ # - [x] clean up opCode's # - [x] attach opCode's to built-in function (for faster lookups) # - [x] optimize appends -# - [ ] make labels store new functions in TmpArities +# - [x] make labels store new functions in TmpArities +# - [x] make labels unstore overwritten functions in TmpArities # - [ ] make if/if?/else/while/switch work #======================================= @@ -218,7 +219,7 @@ template newCallNode(kn: NodeKind, ar: int8, va: Value, oper: OpCode = opNop): N # Methods #======================================= -proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, processingArrow: static bool = false): int = +proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, asDictionary: bool = false, processingArrow: static bool = false): int = var i: int = start var nLen: int = blok.a.len From c1d72edbf0cfbf8f2c34d97650ff7317560ced33 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 13:19:55 +0100 Subject: [PATCH 534/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0d88cd091e..c6fc984369 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3783 \ No newline at end of file +3784 \ No newline at end of file From 2f697c9c53bd6067917059a98c9f6796470bb8b3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 13:20:36 +0100 Subject: [PATCH 535/984] properly call `processBlock` with an `asDictionary=` param --- src/vm/ast.nim | 10 +++++----- src/vm/eval.nim | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 2fedb38f1e..b26b6d1df6 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -516,7 +516,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if val.p[i].kind==Block: var subNode = newRootNode() - discard subNode.processBlock(val.p[i], startingLine=currentLine) + discard subNode.processBlock(val.p[i], startingLine=currentLine, asDictionary=false) newNode.addChildren(subNode.children) else: newNode.addChild(newConstant(val.p[i])) @@ -558,13 +558,13 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, proc addInline(target: var Node, val: Value) = var subNode = newRootNode() - discard subNode.processBlock(val, startingLine=currentLine) + discard subNode.processBlock(val, startingLine=currentLine, asDictionary=false) target.addTerminals(subNode.children) proc addArrowBlock(target: var Node, val: Value) = var subNode = newRootNode() - i = subNode.processBlock(val, start=i+1, startingLine=currentLine, processingArrow=true) + i = subNode.processBlock(val, start=i+1, startingLine=currentLine, asDictionary=false, processingArrow=true) let poppedArrowBlock = newBlock(ArrowBlock.pop()) when processingArrow: @@ -781,7 +781,7 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false, showNewlines: # Main #======================================= -proc generateAst*(parsed: Value): Node = +proc generateAst*(parsed: Value, asDictionary=false): Node = result = newRootNode() TmpArities = collect: @@ -789,7 +789,7 @@ proc generateAst*(parsed: Value): Node = if v.kind == Function: {k: v.arity} - discard result.processBlock(parsed) + discard result.processBlock(parsed, asDictionary=asDictionary) #echo dumpNode(result) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 950838bc21..2f78015fe9 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -206,7 +206,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr if (let storedTranslation = StoredTranslations.getOrDefault(vhash, nil); not storedTranslation.isNil): return storedTranslation - result = evaluateBlock(generateAst(root), isDictionary=isDictionary) + result = evaluateBlock(generateAst(root, asDictionary=isDictionary), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) #dump(newBytecode(result)) From 056ae2945d026ffda39ef7c4170488bfc7bbe0e8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 13:49:06 +0100 Subject: [PATCH 536/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c6fc984369..a54fd487a0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3784 \ No newline at end of file +3785 \ No newline at end of file From d30275b319c5161b7441bfd34706e30402bfa003 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 13:49:41 +0100 Subject: [PATCH 537/984] VM/ast: add new `optimizeStores` to properly handle changes in TmpArities --- src/vm/ast.nim | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index b26b6d1df6..8c2653297b 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -34,8 +34,8 @@ # Libraries #======================================= -import hashes, strutils, sugar -import tables, unicode, std/with +import hashes, sequtils, strutils +import sugar, tables, unicode, std/with import vm/[globals, values/value, values/comparison, values/types] import vm/values/printable @@ -348,6 +348,14 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if right.kind == ConstantValue and right.value.kind == String: target.replaceNode(newConstant(newString(left.value.s & right.value.s))) + proc optimizeStores(target: var Node) {.enforceNoRaises.} = + var child = target.children[0] + + if child.kind in CallNode and child.op == opFunc: + TmpArities[target.value.s] = int8(child.children[0].value.a.countIt(it.kind != Type)) + else: + TmpArities.del(target.value.s) + proc optimizeFunction(target: var Node) {.enforceNoRaises.} = if target.parent.kind == VariableStore: TmpArities[target.parent.value.s] = int8(target.children[0].value.a.len) @@ -359,21 +367,23 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, template rewindCallBranches(target: var Node, optimize: bool = false): untyped = while target.kind in CallNode and target.params == target.arity: when optimize: - case target.op: - of opAdd : target.optimizeAdd() - of opSub : target.optimizeSub() - #of opMul : target.optimizeArithmeticOp(`*`) - of opDiv : target.optimizeArithmeticOp(`/`) - of opFDiv : target.optimizeArithmeticOp(`//`) - of opMod : target.optimizeArithmeticOp(`%`) - of opPow : target.optimizeArithmeticOp(`^`) - of opUnless, - opUnlessE : target.optimizeUnless() - of opAppend : target.optimizeAppend() - of opFunc : target.optimizeFunction() - - else: - discard + if target.kind == VariableStore: + target.optimizeStores() + else: + case target.op: + of opAdd : target.optimizeAdd() + of opSub : target.optimizeSub() + #of opMul : target.optimizeArithmeticOp(`*`) + of opDiv : target.optimizeArithmeticOp(`/`) + of opFDiv : target.optimizeArithmeticOp(`//`) + of opMod : target.optimizeArithmeticOp(`%`) + of opPow : target.optimizeArithmeticOp(`^`) + of opUnless, + opUnlessE : target.optimizeUnless() + of opAppend : target.optimizeAppend() + + else: + discard target = target.parent From e803e7a0e23fa8f5c4066930e4157e1a0d7c5637 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 13:51:06 +0100 Subject: [PATCH 538/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a54fd487a0..064a55fea7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3785 \ No newline at end of file +3786 \ No newline at end of file From 943e2ba73bac1ee697b49b7ca58fd63c0f8ae7d7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 13:53:49 +0100 Subject: [PATCH 539/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 064a55fea7..b56d841fe3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3786 \ No newline at end of file +3787 \ No newline at end of file From c225eea4fea147efbb01fc005ec8e49166f0e090 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 13:58:57 +0100 Subject: [PATCH 540/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b56d841fe3..2a1dbc0551 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3787 \ No newline at end of file +3788 \ No newline at end of file From 98e4538eb70c4220197c86a8cde1694222dac8ca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:00:05 +0100 Subject: [PATCH 541/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2a1dbc0551..e329cb9d2b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3788 \ No newline at end of file +3789 \ No newline at end of file From 8687676b52bad4fb75d97dc776990cbe74329f56 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:14:44 +0100 Subject: [PATCH 542/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e329cb9d2b..d167c290bb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3789 \ No newline at end of file +3790 \ No newline at end of file From 2df69c4b790ccf180b2ffd24919dc6c00d89d64e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:15:35 +0100 Subject: [PATCH 543/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d167c290bb..19aa56e86a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3790 \ No newline at end of file +3791 \ No newline at end of file From d108f13faafe42a8759bb555b9548c210962034e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:15:59 +0100 Subject: [PATCH 544/984] treat 0-arity function calls as pure terminals --- src/vm/ast.nim | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 8c2653297b..5adaaf3547 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -230,6 +230,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, when processingArrow: ArrowBlock.add(@[]) + proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) + #------------------------ # Optimization #------------------------ @@ -351,7 +353,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, proc optimizeStores(target: var Node) {.enforceNoRaises.} = var child = target.children[0] - if child.kind in CallNode and child.op == opFunc: + if child.op == opFunc: TmpArities[target.value.s] = int8(child.children[0].value.a.countIt(it.kind != Type)) else: TmpArities.del(target.value.s) @@ -394,6 +396,19 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, # AST Generation #------------------------ + template addPotentialInfixCall(target: var Node): untyped = + if i < nLen - 1: + let nextNode {.cursor.} = blok.a[i+1] + if nextNode.kind == Symbol and nextNode.m notin {arrowright, thickarrowright, pipe}: + if (let aliased = Aliases.getOrDefault(nextNode.m, NoAliasBinding); aliased != NoAliasBinding): + var symfunc {.cursor.} = GetSym(aliased.name.s) + + if symfunc.kind==Function and aliased.precedence==InfixPrecedence: + when processingArrow: + ArrowBlock[^1].add(nextNode) + i += 1 + target.addCall(aliased.name.s, fun=symfunc) + proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = var callType: OtherCall..SpecialCall = OtherCall @@ -424,13 +439,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, newWord(name) else: nil - - target.addChild(newCallNode(callType, ar, v, op)) if ar != 0: - target.rollThrough() + with target: + addChild(newCallNode(callType, ar, v, op)) + rollThrough() else: - target.rewindCallBranches() + with target: + addPotentialInfixCall() + addChild(newCallNode(callType, ar, v, op)) + rewindCallBranches(optimize=true) func addStore(target: var Node, val: Value) {.enforceNoRaises.} = target.addChild(newCallNode(VariableStore, 1, val)) @@ -451,19 +469,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, proc addNewline(target: var Node) = target.addChild(Node(kind: NewlineNode, line: currentLine)) - template addPotentialInfixCall(target: var Node): untyped = - if i < nLen - 1: - let nextNode {.cursor.} = blok.a[i+1] - if nextNode.kind == Symbol and nextNode.m notin {arrowright, thickarrowright, pipe}: - if (let aliased = Aliases.getOrDefault(nextNode.m, NoAliasBinding); aliased != NoAliasBinding): - var symfunc {.cursor.} = GetSym(aliased.name.s) - - if symfunc.kind==Function and aliased.precedence==InfixPrecedence: - when processingArrow: - ArrowBlock[^1].add(nextNode) - i += 1 - target.addCall(aliased.name.s, fun=symfunc) - proc addTerminal(target: var Node, node: Node) = with target: rewindCallBranches() From 03b4f1e14826f4157a2061bba0383cdd1cd440ea Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:18:10 +0100 Subject: [PATCH 545/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 19aa56e86a..85ae5d6d6c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3791 \ No newline at end of file +3792 \ No newline at end of file From 558766722629e0c61de0366e6d816bf59a763007 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:25:42 +0100 Subject: [PATCH 546/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 85ae5d6d6c..e75fc1e51c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3792 \ No newline at end of file +3793 \ No newline at end of file From 29f22e597741826ae85f4e1b16e3c8950672085b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:26:05 +0100 Subject: [PATCH 547/984] correctly handle `=> X` where X is non-Word --- src/vm/ast.nim | 25 ++++++++++++------------- src/vm/eval.nim | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 5adaaf3547..97bdd2a5a9 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -596,18 +596,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, # so let's get them ready var argblock, subblock: ValueArray - # if it's a word - if subnode.kind==Word: - subblock = @[subnode] - # check if it's a function - if (let funcArity = TmpArities.getOrDefault(subnode.s, -1); funcArity != -1): - # automatically "push" all its required arguments - for j in 0..(funcArity-1): - let arg = newWord("_" & $(j)) - argblock.add(arg) - subblock.add(arg) - - elif subnode.kind==Block: + if subnode.kind==Block: # replace ampersand symbols, # sequentially, with arguments var idx = 0 @@ -620,6 +609,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, else: subblock.add(subnode.a[idx]) idx += 1 + else: + subblock = @[subnode] + if subnode.kind==Word: + # check if it's a function + if (let funcArity = TmpArities.getOrDefault(subnode.s, -1); funcArity != -1): + # automatically "push" all its required arguments + for j in 0..(funcArity-1): + let arg = newWord("_" & $(j)) + argblock.add(arg) + subblock.add(arg) if argblock.len == 1: when processingArrow: @@ -806,7 +805,7 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - #echo dumpNode(result) + echo dumpNode(result) # echo "TRAVERSING" diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 2f78015fe9..fa430358df 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root, asDictionary=isDictionary), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - #dump(newBytecode(result)) + dump(newBytecode(result)) when useStored: if vhash != -1: From 8af86da4b4edcafa2dca7db1935b68aec51f13da Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:26:49 +0100 Subject: [PATCH 548/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e75fc1e51c..b5ead719b5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3793 \ No newline at end of file +3794 \ No newline at end of file From 0a6a7dffab20d5d9622c5234300e0269f924cb2e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:30:30 +0100 Subject: [PATCH 549/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b5ead719b5..332bd8bcb9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3794 \ No newline at end of file +3795 \ No newline at end of file From 2465968b912cd080ca74e9df9015a00917b1defb Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:31:17 +0100 Subject: [PATCH 550/984] disable debugging (first run where ALL Rosetta Code examples just run fine!!) --- src/vm/ast.nim | 2 +- src/vm/eval.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 97bdd2a5a9..193ad55425 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -805,7 +805,7 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - echo dumpNode(result) + #echo dumpNode(result) # echo "TRAVERSING" diff --git a/src/vm/eval.nim b/src/vm/eval.nim index fa430358df..2f78015fe9 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root, asDictionary=isDictionary), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - dump(newBytecode(result)) + #dump(newBytecode(result)) when useStored: if vhash != -1: From 39d06d672b22510f35fb89e63db9e71ebf947723 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:34:51 +0100 Subject: [PATCH 551/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 332bd8bcb9..78f2256592 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3795 \ No newline at end of file +3796 \ No newline at end of file From 3c674c48876b61e76b8e1fc0d85760a4639752a8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:43:23 +0100 Subject: [PATCH 552/984] VM/ast: removed `optimizeFunction` (not used anymore; incorporated in `optimizeStores`) + comment cleanup --- src/vm/ast.nim | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 193ad55425..983c4b5b64 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -358,10 +358,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, else: TmpArities.del(target.value.s) - proc optimizeFunction(target: var Node) {.enforceNoRaises.} = - if target.parent.kind == VariableStore: - TmpArities[target.parent.value.s] = int8(target.children[0].value.a.len) - #------------------------ # Helper Functions #------------------------ @@ -806,10 +802,3 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) #echo dumpNode(result) - - # echo "TRAVERSING" - - # for node in traverseTree(result): - # echo dumpNode(node, single=true) - - # echo "FINISHED" \ No newline at end of file From 5faf73c87dda5deaeb16afb9bd9904d7b92f6c41 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:43:32 +0100 Subject: [PATCH 553/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 78f2256592..1c1859abfc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3796 \ No newline at end of file +3797 \ No newline at end of file From afca5c00d3d2bc21900ed801aaa19c35b5195534 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:49:31 +0100 Subject: [PATCH 554/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1c1859abfc..191d46f2d9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3797 \ No newline at end of file +3798 \ No newline at end of file From 61ca35bd2b5ce2467f0f19fceb1bd79f8f0f5f2f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:54:04 +0100 Subject: [PATCH 555/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 191d46f2d9..d8222a0b75 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3798 \ No newline at end of file +3799 \ No newline at end of file From 3b69f3cdc07b8477515f004e091ea98e96542c32 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:56:23 +0100 Subject: [PATCH 556/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d8222a0b75..bba86f4640 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3799 \ No newline at end of file +3800 \ No newline at end of file From f47767a2a7156b13c6347c2247cf27bf22e80ec1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 14:59:13 +0100 Subject: [PATCH 557/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bba86f4640..2de45465fc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3800 \ No newline at end of file +3801 \ No newline at end of file From a7fc4dfb2f30c5528f07500c90e85ee6b18969ec Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 15:00:10 +0100 Subject: [PATCH 558/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2de45465fc..ca26457e9e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3801 \ No newline at end of file +3802 \ No newline at end of file From b449cef8297f29a55c5d576fb5e523679280c027 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:20:42 +0100 Subject: [PATCH 559/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ca26457e9e..2289e11417 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3802 \ No newline at end of file +3803 \ No newline at end of file From 505219a34e93a85c91fecdb7a9540ef8976e454c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:25:31 +0100 Subject: [PATCH 560/984] Converters/function: make method work with Literal first value (makes `function => print` work flawlessly) --- src/library/Converters.nim | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/library/Converters.nim b/src/library/Converters.nim index a3fde9f9b9..5b038ceadf 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -940,7 +940,7 @@ proc defineSymbols*() = rule = PrefixPrecedence, description = "create function with given arguments and body", args = { - "arguments" : {Block}, + "arguments" : {Literal, Block}, "body" : {Block} }, attrs = { @@ -1045,6 +1045,10 @@ proc defineSymbols*() = var memoize = (hadAttr("memoize")) var inline = (hadAttr("inline")) + let argBlock {.cursor.} = + if x.kind == Block: x.a + else: @[x] + # TODO(Converters\function) Verify safety of implicit `.inline`s # labels: library, benchmark, open discussion if not inline: @@ -1054,22 +1058,22 @@ proc defineSymbols*() = var ret: Value var argTypes = initOrderedTable[string,ValueSpec]() - if x.a.countIt(it.kind == Type) > 0: + if argBlock.countIt(it.kind == Type) > 0: var args: seq[string] var body: ValueArray var i = 0 - while i < x.a.len: - let varName = x.a[i] - args.add(x.a[i].s) - argTypes[x.a[i].s] = {} - if i+1 < x.a.len and x.a[i+1].kind == Type: + while i < argBlock.len: + let varName = argBlock[i] + args.add(argBlock[i].s) + argTypes[argBlock[i].s] = {} + if i+1 < argBlock.len and argBlock[i+1].kind == Type: var typeArr: ValueArray - while i+1 < x.a.len and x.a[i+1].kind == Type: + while i+1 < argBlock.len and argBlock[i+1].kind == Type: typeArr.add(newWord("is?")) - typeArr.add(x.a[i+1]) - argTypes[varName.s].incl(x.a[i+1].t) + typeArr.add(argBlock[i+1]) + argTypes[varName.s].incl(argBlock[i+1].t) typeArr.add(varName) i += 1 @@ -1091,12 +1095,12 @@ proc defineSymbols*() = ret = newFunction(args,newBlock(mainBody),imports,exports,memoize,inline) else: - if x.a.len > 0: - for arg in x.a: + if argBlock.len > 0: + for arg in argBlock: argTypes[arg.s] = {Any} else: argTypes[""] = {Nothing} - ret = newFunction(x.a.map((w)=>w.s),y,imports,exports,memoize,inline) + ret = newFunction(argBlock.map((w)=>w.s),y,imports,exports,memoize,inline) ret.info = ValueInfo(kind: Function) From e7b36aaf0ff01ce3ec11b48ad240604b4bc0b013 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:25:45 +0100 Subject: [PATCH 561/984] sanitize `rewindCallBranches` --- src/vm/ast.nim | 12 ++++-------- src/vm/eval.nim | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 983c4b5b64..cbf1d80835 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -475,15 +475,12 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, rewindCallBranches(optimize=true) - proc addTerminals(target: var Node, nodes: openArray[Node]) = + proc addTerminals(target: var Node, nodes: openArray[Node], dontOptimize:static bool =false) = with target: rewindCallBranches() - addPotentialInfixCall() - addChildren(nodes) - - rewindCallBranches(optimize=true) + rewindCallBranches(optimize=not dontOptimize) proc addPath(target: var Node, val: Value, isLabel: static bool=false) = var pathCallV: Value = nil @@ -620,11 +617,10 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, when processingArrow: ArrowBlock[^1].add(newLiteral(argblock[0].s)) ArrowBlock[^1].add(newBlock(subblock)) - target.addTerminals([ newConstant(newLiteral(argblock[0].s)), newConstant(newBlock(subblock)) - ]) + ], dontOptimize=true) else: when processingArrow: ArrowBlock[^1].add(newBlock(argblock)) @@ -801,4 +797,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - #echo dumpNode(result) + echo dumpNode(result) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 2f78015fe9..fa430358df 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root, asDictionary=isDictionary), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - #dump(newBytecode(result)) + dump(newBytecode(result)) when useStored: if vhash != -1: From 6987a7629c565e30abf12a1fc7b78f3b1ee6303c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:25:48 +0100 Subject: [PATCH 562/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2289e11417..954be6449f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3803 \ No newline at end of file +3804 \ No newline at end of file From 865161071820da5e2a31156bfc6a4cff6f4f1a1e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:28:38 +0100 Subject: [PATCH 563/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 954be6449f..e7d8f04510 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3804 \ No newline at end of file +3805 \ No newline at end of file From c0c64065bdfcb4381e3f260d9fb69f221f4363f2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:29:35 +0100 Subject: [PATCH 564/984] VM/ast: minor fix --- src/vm/ast.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index cbf1d80835..d25bb49d3e 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -475,12 +475,16 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, rewindCallBranches(optimize=true) - proc addTerminals(target: var Node, nodes: openArray[Node], dontOptimize:static bool =false) = + proc addTerminals(target: var Node, nodes: openArray[Node], dontOptimize: bool =false) = with target: rewindCallBranches() addPotentialInfixCall() addChildren(nodes) - rewindCallBranches(optimize=not dontOptimize) + + if dontOptimize: + target.rewindCallBranches(optimize=false) + else: + target.rewindCallBranches(optimize=true) proc addPath(target: var Node, val: Value, isLabel: static bool=false) = var pathCallV: Value = nil From e84c932be747cb1ceb3cd8833c529cb14dd74e32 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:30:33 +0100 Subject: [PATCH 565/984] guess what: let's re-disable debugging (as if it would have been extremely difficult to just set a compile option! lol) --- src/vm/ast.nim | 2 +- src/vm/eval.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index d25bb49d3e..44d0c89e08 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -801,4 +801,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - echo dumpNode(result) + #echo dumpNode(result) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index fa430358df..2f78015fe9 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -209,7 +209,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root, asDictionary=isDictionary), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - dump(newBytecode(result)) + #dump(newBytecode(result)) when useStored: if vhash != -1: From fbd078571b8488902850a1cc325b988d0059e314 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:30:36 +0100 Subject: [PATCH 566/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e7d8f04510..d16a424edf 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3805 \ No newline at end of file +3806 \ No newline at end of file From 831661a8b2a6d384d194e6fdcc2dd6629ac0f359 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:48:37 +0100 Subject: [PATCH 567/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d16a424edf..f7bee6c7c4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3806 \ No newline at end of file +3807 \ No newline at end of file From 1c13cd78c8453fdde29411c421e9da77584ce999 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 16:51:07 +0100 Subject: [PATCH 568/984] re-enabled Error lines (yeah! :S) --- src/vm/eval.nim | 93 ++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 2f78015fe9..d4e2debf28 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -44,13 +44,35 @@ func indexOfValue(a: ValueArray, item: Value): int {.inline,enforceNoRaises.}= inc(result) result = -1 -template addToInstructions(b: untyped):untyped {.dirty.} = +template addByte(instructions: var VBinary, b: untyped): untyped = when b is OpCode: instructions.add(byte(b)) else: instructions.add(b) -proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode, withShortcut: static bool=true) {.inline,enforceNoRaises.} = +template addOpWithNumber(instructions: var VBinary, oper: OpCode, num: untyped, hasShortcut = true): untyped = + if num > 255: + instructions.addByte([ + byte(oper)+1, + byte(num shr 8), + byte(num) + ]) + else: + when hasShortcut: + if num <= 13: + instructions.addByte((byte(oper)-0x0E) + byte(num)) + else: + instructions.addByte([ + byte(oper), + byte(num) + ]) + else: + instructions.addByte([ + byte(oper), + byte(num) + ]) + +proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode, hasShortcut: static bool=true) {.inline,enforceNoRaises.} = var indx = consts.indexOfValue(v) if indx == -1: let newv = v @@ -58,26 +80,7 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O consts.add(newv) indx = consts.len-1 - if indx > 255: - addToInstructions([ - byte(op)+1, - byte(indx shr 8), - byte(indx) - ]) - else: - when withShortcut: - if indx <= 13: - addToInstructions((byte(op)-0x0E) + byte(indx)) - else: - addToInstructions([ - byte(op), - byte(indx) - ]) - else: - addToInstructions([ - byte(op), - byte(indx) - ]) + instructions.addOpWithNumber(op, indx, hasShortcut) #======================================= # Methods @@ -94,14 +97,14 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = # Shortcuts #------------------------ - template addConst(v: Value, op: OpCode, withShortcut: static bool=true): untyped = - addConst(consts, it, v, op, withShortcut) + template addConst(v: Value, op: OpCode, hasShortcut: static bool=true): untyped = + addConst(consts, it, v, op, hasShortcut) - template addByte(b: untyped): untyped = - when b is OpCode: - it.add(byte(b)) - else: - it.add(b) + template addSingleCommand(op: untyped): untyped = + it.addByte(op) + + template addEol(n: untyped): untyped = + it.addOpWithNumber(opEol, n, hasShortcut=false) #------------------------ # MainLoop @@ -117,53 +120,55 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = # echo "processing: " # echo dumpNode(instruction) case instruction.kind: - of RootNode, NewlineNode: + of RootNode: discard + of NewlineNode: + addEol(instruction.line) of ConstantValue: var alreadyPut = false let iv {.cursor.} = instruction.value case instruction.value.kind: of Null: - addByte(opConstN) + addSingleCommand(opConstN) alreadyPut = true of Logical: if iv.b == True: - addByte(opConstBT) + addSingleCommand(opConstBT) alreadyPut = true elif iv.b == False: - addByte(opConstBF) + addSingleCommand(opConstBF) alreadyPut = true of Integer: if likely(iv.iKind==NormalInteger) and iv.i >= -1 and iv.i <= 15: - addByte(byte(opConstI0) + byte(iv.i)) + addSingleCommand(byte(opConstI0) + byte(iv.i)) alreadyPut = true of Floating: case iv.f: of -1.0: - addByte(opConstF1M) + addSingleCommand(opConstF1M) alreadyPut = true of 0.0: - addByte(opConstF0) + addSingleCommand(opConstF0) alreadyPut = true of 1.0: - addByte(opConstF1) + addSingleCommand(opConstF1) alreadyPut = true of 2.0: - addByte(opConstF2) + addSingleCommand(opConstF2) alreadyPut = true else: discard of String: if iv.s == "": - addByte(opConstS) + addSingleCommand(opConstS) alreadyPut = true of Block: if iv.a.len == 0: - addByte(opConstA) + addSingleCommand(opConstA) alreadyPut = true of Dictionary: if iv.d.len == 0: - addByte(opConstD) + addSingleCommand(opConstD) alreadyPut = true else: discard @@ -176,15 +181,15 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = addConst(instruction.value, opAttr) of VariableStore: if unlikely(isDictionary): - addConst(instruction.value, opDStore, withShortcut=false) + addConst(instruction.value, opDStore, hasShortcut=false) else: addConst(instruction.value, opStore) of OtherCall: addConst(instruction.value, opCall) of BuiltinCall: - addByte(instruction.op) + addSingleCommand(instruction.op) of SpecialCall: - addByte(instruction.op) + addSingleCommand(instruction.op) i += 1 From 09e1be4c9323c9eaeeec048b384be1ad858857c7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:01:23 +0100 Subject: [PATCH 569/984] VM/ast: make `inc` & `dec` optimization work with strictly TerminalNode's + cleanup --- src/vm/ast.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 44d0c89e08..0572eb36ea 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -245,13 +245,13 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if right.kind == ConstantValue and right.value.kind in {Integer, Floating}: target.replaceNode(newConstant(left.value + right.value)) # Convert 1 + X -> inc X - elif left.value == I1: + elif right.kind in TerminalNode and left.value == I1: target.op = opInc target.arity = 1 target.setOnlyChild(right) # Convert X + 1 -> inc X - elif right.kind == ConstantValue and right.value == I1: + elif right.kind in TerminalNode and right.value == I1: target.op = opInc target.arity = 1 target.setOnlyChild(left) @@ -299,7 +299,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if left.kind == ConstantValue and left.value.kind in {Integer,Floating} and right.kind == ConstantValue and right.value.kind in {Integer,Floating}: # Constant folding target.replaceNode(newConstant(left.value - right.value)) - elif right.kind == ConstantValue and right.value == I1: + elif left.kind in TerminalNode and right.value == I1: # Convert X - 1 -> dec X target.op = opDec target.arity = 1 @@ -309,7 +309,8 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, var left = target.children[0] var right = target.children[1] - if left.kind == ConstantValue and left.value.kind in {Integer,Floating} and right.kind == ConstantValue and right.value.kind in {Integer,Floating}: + if left.kind == ConstantValue and left.value.kind in {Integer,Floating} and + right.kind == ConstantValue and right.value.kind in {Integer,Floating}: target.replaceNode(newConstant(op(left.value,right.value))) proc optimizeUnless(target: var Node) {.enforceNoRaises.} = From 4068f8fc4927789d85501187960a04609c793492 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:01:34 +0100 Subject: [PATCH 570/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f7bee6c7c4..23346936db 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3807 \ No newline at end of file +3808 \ No newline at end of file From b8311e801dec374ed84af78f4d686710d98764fc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:03:40 +0100 Subject: [PATCH 571/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 23346936db..c5fc8d2816 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3808 \ No newline at end of file +3809 \ No newline at end of file From 13e47284022f162dec0fba35d09c147463b20d5d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:06:10 +0100 Subject: [PATCH 572/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c5fc8d2816..e20652c854 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3809 \ No newline at end of file +3810 \ No newline at end of file From cfd144a631d56577f156d09d2622241954001003 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:08:29 +0100 Subject: [PATCH 573/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e20652c854..67f286c73f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3810 \ No newline at end of file +3811 \ No newline at end of file From 3e8a4bc06a22fc7f682ac3a22f7bb9124227b00d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:11:17 +0100 Subject: [PATCH 574/984] re-fixed --- src/vm/ast.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 0572eb36ea..523a07933a 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -245,13 +245,13 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if right.kind == ConstantValue and right.value.kind in {Integer, Floating}: target.replaceNode(newConstant(left.value + right.value)) # Convert 1 + X -> inc X - elif right.kind in TerminalNode and left.value == I1: + elif right.kind==VariableLoad and left.kind==ConstantValue and left.value == I1: target.op = opInc target.arity = 1 target.setOnlyChild(right) # Convert X + 1 -> inc X - elif right.kind in TerminalNode and right.value == I1: + elif left.kind==VariableLoad and right.kind==ConstantValue and right.value == I1: target.op = opInc target.arity = 1 target.setOnlyChild(left) @@ -299,7 +299,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if left.kind == ConstantValue and left.value.kind in {Integer,Floating} and right.kind == ConstantValue and right.value.kind in {Integer,Floating}: # Constant folding target.replaceNode(newConstant(left.value - right.value)) - elif left.kind in TerminalNode and right.value == I1: + elif left.kind == VariableLoad and right.kind == ConstantValue and right.value == I1: # Convert X - 1 -> dec X target.op = opDec target.arity = 1 From 932528a67e41f7b84913f5713c219f68b5bdc9ee Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:11:47 +0100 Subject: [PATCH 575/984] VM/ast: catch possible errors during optimizations (mostly weird arithmetic overflows) --- src/vm/ast.nim | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 523a07933a..0d612c8294 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -369,20 +369,23 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, if target.kind == VariableStore: target.optimizeStores() else: - case target.op: - of opAdd : target.optimizeAdd() - of opSub : target.optimizeSub() - #of opMul : target.optimizeArithmeticOp(`*`) - of opDiv : target.optimizeArithmeticOp(`/`) - of opFDiv : target.optimizeArithmeticOp(`//`) - of opMod : target.optimizeArithmeticOp(`%`) - of opPow : target.optimizeArithmeticOp(`^`) - of opUnless, - opUnlessE : target.optimizeUnless() - of opAppend : target.optimizeAppend() - - else: - discard + try: + case target.op: + of opAdd : target.optimizeAdd() + of opSub : target.optimizeSub() + #of opMul : target.optimizeArithmeticOp(`*`) + of opDiv : target.optimizeArithmeticOp(`/`) + of opFDiv : target.optimizeArithmeticOp(`//`) + of opMod : target.optimizeArithmeticOp(`%`) + of opPow : target.optimizeArithmeticOp(`^`) + of opUnless, + opUnlessE : target.optimizeUnless() + of opAppend : target.optimizeAppend() + + else: + discard + except: + discard target = target.parent From a3a32809a344c95ba8c9e2b98d2db4278ea6b2b7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:11:51 +0100 Subject: [PATCH 576/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 67f286c73f..97c32dfaa0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3811 \ No newline at end of file +3812 \ No newline at end of file From 61ea9ee789cf9a79f03cafe1f73d9d201b581cf1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:12:25 +0100 Subject: [PATCH 577/984] updated inline TODOs --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 0d612c8294..8958f31f90 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -21,7 +21,7 @@ # - [x] make AttributeLabel's work # - [x] make Path's work # - [x] make PathLabel's work -# - [ ] make Newline values work +# - [x] make Newline values work # - [x] create new opCode for append # - [x] clean up opCode's # - [x] attach opCode's to built-in function (for faster lookups) From 458dd55c3067a7377096fc0200801452a1054a24 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:14:54 +0100 Subject: [PATCH 578/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 97c32dfaa0..2b1141000f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3812 \ No newline at end of file +3813 \ No newline at end of file From c9cd3809aeef4e027684d7082902782e032eb22a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:21:44 +0100 Subject: [PATCH 579/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2b1141000f..2a2009c458 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3813 \ No newline at end of file +3814 \ No newline at end of file From b1390e0082fd5905e911536692b758afa75dad67 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:28:01 +0100 Subject: [PATCH 580/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2a2009c458..1d1e6ee667 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3814 \ No newline at end of file +3815 \ No newline at end of file From 997e08937f2aa675cfbe680e6d06bb4a58ccba62 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:29:39 +0100 Subject: [PATCH 581/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1d1e6ee667..8e78b60f63 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3815 \ No newline at end of file +3816 \ No newline at end of file From 835e1ed55b66993446ce217c12cd0c39b13e852f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:33:47 +0100 Subject: [PATCH 582/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8e78b60f63..c1bc7eee1f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3816 \ No newline at end of file +3817 \ No newline at end of file From 99aef9fb7e462667db04580bccba8d7b205c073e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:36:14 +0100 Subject: [PATCH 583/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c1bc7eee1f..3b93cf65b8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3817 \ No newline at end of file +3818 \ No newline at end of file From 6aba53973e18ee43ab959dc44941ab4397fee9e4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:42:36 +0100 Subject: [PATCH 584/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3b93cf65b8..6eeff2d4df 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3818 \ No newline at end of file +3819 \ No newline at end of file From 4110c1a95af00f26c1fecc86bd0691a090dfc99c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:45:40 +0100 Subject: [PATCH 585/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6eeff2d4df..d8f3286c4a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3819 \ No newline at end of file +3820 \ No newline at end of file From 97bd9ff7de2fb82d24a83bdc64d0d1a1a7fb6802 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:46:03 +0100 Subject: [PATCH 586/984] VM/ast: fixed(?) handling of pipes with possible newlines & stores --- src/vm/ast.nim | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 8958f31f90..faf3080e06 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -555,12 +555,22 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, i += 1 target.rewindCallBranches() - var lastChild = target.children[^1] + var toSpot = target.children.len - 1 + + var lastChild: Node = target.children[toSpot] + while lastChild.kind==NewlineNode: + toSpot -= 1 + lastChild = target.children[toSpot] + if lastChild.kind == VariableStore: - lastChild = lastChild.children[^1] + toSpot = lastChild.children.len - 1 + lastChild = lastChild.children[toSpot] + while lastChild.kind == NewlineNode: + toSpot -= 1 + lastChild = lastChild.children[toSpot] target = lastChild.parent - target.children.delete(target.children.len-1) + target.children.delete(toSpot) target.addCall(nextNode.s, funcArity) target.addChild(lastChild) From f09200ad972460633bfa20f2627a32b6beb4fe7a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 17:48:57 +0100 Subject: [PATCH 587/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d8f3286c4a..95d180ca4d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3820 \ No newline at end of file +3821 \ No newline at end of file From 342e824c16655aee45781fdc184b03986b3556f0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:14:27 +0100 Subject: [PATCH 588/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 95d180ca4d..fb711a693d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3821 \ No newline at end of file +3822 \ No newline at end of file From a99a47365c502c2f10ad6df5ba8cceeb62614059 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:16:23 +0100 Subject: [PATCH 589/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index fb711a693d..6beae07bf1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3822 \ No newline at end of file +3823 \ No newline at end of file From 144a8195aab7ffd1ce2b605a871a5e346741dda5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:17:46 +0100 Subject: [PATCH 590/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6beae07bf1..ec44f9dd0f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3823 \ No newline at end of file +3824 \ No newline at end of file From 1b3e162ce9d003226606f767768911f4bbbbbb8b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:18:26 +0100 Subject: [PATCH 591/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ec44f9dd0f..0eb1d8bdf7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3824 \ No newline at end of file +3825 \ No newline at end of file From ca7db6204c815a35f03b3c2372f16c2fdee8396d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:20:57 +0100 Subject: [PATCH 592/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0eb1d8bdf7..99d11c3bd5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3825 \ No newline at end of file +3826 \ No newline at end of file From bffb8517d9c66e594632919accee270384884a05 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:29:08 +0100 Subject: [PATCH 593/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 99d11c3bd5..a60f236929 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3826 \ No newline at end of file +3827 \ No newline at end of file From 19aa6ea8fd23cd2ace39e1bba59e10de0be33d5e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:30:19 +0100 Subject: [PATCH 594/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a60f236929..77eeab8c4b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3827 \ No newline at end of file +3828 \ No newline at end of file From 8c16749b5f769e7a197c42c6697303ebccfcd1c6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:35:33 +0100 Subject: [PATCH 595/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 77eeab8c4b..266d909264 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3828 \ No newline at end of file +3829 \ No newline at end of file From 1d99b63737c0b9da5f2296578dd9d28ae1879f8d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:38:27 +0100 Subject: [PATCH 596/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 266d909264..5477b3259e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3829 \ No newline at end of file +3830 \ No newline at end of file From ef73568fc1199aff4c013378f49c2d67b8fffecc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:39:27 +0100 Subject: [PATCH 597/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5477b3259e..3753606a8a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3830 \ No newline at end of file +3831 \ No newline at end of file From 6ae4d9eb7563ecf6d790ff8c03a1332ce3827e8c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 20 Jan 2023 18:40:21 +0100 Subject: [PATCH 598/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3753606a8a..6c5d5ee81f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3831 \ No newline at end of file +3832 \ No newline at end of file From 823bc069ed22032f13c9bda238e3a56cf8c03f2b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:14:22 +0100 Subject: [PATCH 599/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6c5d5ee81f..c7e2bdf03e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3832 \ No newline at end of file +3833 \ No newline at end of file From 311a4d8cfa9015d4daf389f4caa142aaf7518863 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:16:00 +0100 Subject: [PATCH 600/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c7e2bdf03e..a0d89b649a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3833 \ No newline at end of file +3834 \ No newline at end of file From 88eeed78cba72879017b17045c1e59a7de99f5e0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:18:14 +0100 Subject: [PATCH 601/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a0d89b649a..736a06fe9d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3834 \ No newline at end of file +3835 \ No newline at end of file From 0756511812e5c4c3de93192f908c185c177b2822 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:18:32 +0100 Subject: [PATCH 602/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 736a06fe9d..a7374bc7d6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3835 \ No newline at end of file +3836 \ No newline at end of file From 85cc5148ece4eaca40df0040d79152f174f576a8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:22:32 +0100 Subject: [PATCH 603/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a7374bc7d6..42a2973a7b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3836 \ No newline at end of file +3837 \ No newline at end of file From 5fb2e7deb09b4bafcd746064b49949fac951efec Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:27:27 +0100 Subject: [PATCH 604/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 42a2973a7b..2f74e24b2b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3837 \ No newline at end of file +3838 \ No newline at end of file From 22c68e01334289051f31ffe7b8c5729e60295b8c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:28:19 +0100 Subject: [PATCH 605/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2f74e24b2b..27cb0583b3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3838 \ No newline at end of file +3839 \ No newline at end of file From 47a2e34823a4ad84380f38720f706dcc0add9352 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:29:20 +0100 Subject: [PATCH 606/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 27cb0583b3..75aba41555 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3839 \ No newline at end of file +3840 \ No newline at end of file From 7799b165b0f9bf63b8dffcb58ba3cec3ceab17a0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:31:37 +0100 Subject: [PATCH 607/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 75aba41555..0e368811da 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3840 \ No newline at end of file +3841 \ No newline at end of file From e400d0ae19ed4bd6e815cf5a25c6c1ea1fbfcb8b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:32:23 +0100 Subject: [PATCH 608/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0e368811da..924c2aeec0 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3841 \ No newline at end of file +3842 \ No newline at end of file From 80834b066e9111454615a5eff3d5679806ccebc7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:33:44 +0100 Subject: [PATCH 609/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 924c2aeec0..c69b11aacc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3842 \ No newline at end of file +3843 \ No newline at end of file From 43e154c5198c79e7df9b091953c4bfab5596e690 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:38:34 +0100 Subject: [PATCH 610/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c69b11aacc..541ed895e1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3843 \ No newline at end of file +3844 \ No newline at end of file From 265e810a8dd976e789540042578d9ec0fc8cdfa8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:42:06 +0100 Subject: [PATCH 611/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 541ed895e1..8e4b53f7bb 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3844 \ No newline at end of file +3845 \ No newline at end of file From 4fd403b89b3db2727a4c240c9f8a3596ce769445 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:44:32 +0100 Subject: [PATCH 612/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8e4b53f7bb..11460da199 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3845 \ No newline at end of file +3846 \ No newline at end of file From c317b5a7f24a6b36048a9431a35fe02befb0ada4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:46:15 +0100 Subject: [PATCH 613/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 11460da199..66ab4ccfca 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3846 \ No newline at end of file +3847 \ No newline at end of file From d07ba2a8b437c0d3f05b320646a75fa290951d6b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:47:35 +0100 Subject: [PATCH 614/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 66ab4ccfca..381759f16d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3847 \ No newline at end of file +3848 \ No newline at end of file From 6e5b454dc1b2f359dfc738cc7268def837c12a60 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:49:38 +0100 Subject: [PATCH 615/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 381759f16d..e0d7cbc41e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3848 \ No newline at end of file +3849 \ No newline at end of file From 46b809964cfbf13ce9904df0da2123fc8e9c9a30 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:50:58 +0100 Subject: [PATCH 616/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e0d7cbc41e..d23ee5cc64 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3849 \ No newline at end of file +3850 \ No newline at end of file From e700622b6b594d017bb7c9b427813cada178a2d4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:52:07 +0100 Subject: [PATCH 617/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d23ee5cc64..f97315b447 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3850 \ No newline at end of file +3851 \ No newline at end of file From 36521497c73736b874428a5655299a7d96320465 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:53:42 +0100 Subject: [PATCH 618/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f97315b447..7aa1b73210 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3851 \ No newline at end of file +3852 \ No newline at end of file From 276fd57a9034e1b905f1db198536d5dd10f1c27c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:54:58 +0100 Subject: [PATCH 619/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7aa1b73210..a0dc2d892a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3852 \ No newline at end of file +3853 \ No newline at end of file From 30f981ee350d4be34851bbf619337cb22669d6e9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:56:00 +0100 Subject: [PATCH 620/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a0dc2d892a..26f2be91c1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3853 \ No newline at end of file +3854 \ No newline at end of file From dc1b19b9e8ce71364768b6ed44438b23443b3682 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 10:56:39 +0100 Subject: [PATCH 621/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 26f2be91c1..b16ac7e21c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3854 \ No newline at end of file +3855 \ No newline at end of file From ea8293acb3064fa9e3036b8828cf273b82a8b574 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:00:47 +0100 Subject: [PATCH 622/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b16ac7e21c..44067a2726 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3855 \ No newline at end of file +3856 \ No newline at end of file From c38423e1c6988184b38ab750c3aa7916e83b96a2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:02:47 +0100 Subject: [PATCH 623/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 44067a2726..e4c4e5e4d9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3856 \ No newline at end of file +3857 \ No newline at end of file From 7e04a97486315a5d8430657f79789ae244dd4134 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:04:44 +0100 Subject: [PATCH 624/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e4c4e5e4d9..d0353c6b40 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3857 \ No newline at end of file +3858 \ No newline at end of file From 198c3d43249d9cd43bb10100388cf1922c6aad7f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:06:08 +0100 Subject: [PATCH 625/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d0353c6b40..798cb11efd 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3858 \ No newline at end of file +3859 \ No newline at end of file From cc5cd6245ea67a9f1c4281348172e0da645fc546 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:16:00 +0100 Subject: [PATCH 626/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 798cb11efd..1d2015c060 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3859 \ No newline at end of file +3860 \ No newline at end of file From 321c2484914db3a29fdf55d0a0d7be2a65bb02d7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:17:48 +0100 Subject: [PATCH 627/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1d2015c060..9cbd0e0fd8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3860 \ No newline at end of file +3861 \ No newline at end of file From d130faef0e56869ba6cf11bfe321e833250cf40d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:19:18 +0100 Subject: [PATCH 628/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9cbd0e0fd8..cbeaa3db6d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3861 \ No newline at end of file +3862 \ No newline at end of file From 2e08ce1bc4ec07a8f062665886af89ed012f513a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:21:49 +0100 Subject: [PATCH 629/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cbeaa3db6d..d42e2ba70d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3862 \ No newline at end of file +3863 \ No newline at end of file From 4d10b8882b86221bf1160de543da632fe6f3d94a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:23:23 +0100 Subject: [PATCH 630/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d42e2ba70d..0737feb48c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3863 \ No newline at end of file +3864 \ No newline at end of file From 4d35a0fb6e8d1c07dec190ca5d828555b780b3cb Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:24:17 +0100 Subject: [PATCH 631/984] VM/ast: another attempt to make pipes (`|`) works flawlessly with store (`label: x | add y`); hopefully a successful one --- src/vm/ast.nim | 54 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index faf3080e06..64b36870dd 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -215,6 +215,20 @@ template newCallNode(kn: NodeKind, ar: int8, va: Value, oper: OpCode = opNop): N value: va ) +func copyNode(node: Node): Node = + result = Node(kind: node.kind) + case node.kind: + of NewlineNode: + result.line = node.line + of ConstantValue, VariableLoad: + result.value = node.value + else: + result.op = node.op + result.arity = node.arity + result.params = node.params + result.value = node.value + result.addChildren(node.children) + #======================================= # Methods #======================================= @@ -409,7 +423,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, i += 1 target.addCall(aliased.name.s, fun=symfunc) - proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = + proc getCallNode(name: string, arity: int8 = -1, fun: Value = nil): Node = var callType: OtherCall..SpecialCall = OtherCall var fn {.cursor.}: Value = @@ -439,15 +453,20 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, newWord(name) else: nil + + result = newCallNode(callType, ar, v, op) + + proc addCall(target: var Node, name: string, arity: int8 = -1, fun: Value = nil) = + let newCall = getCallNode(name, arity, fun) - if ar != 0: + if newCall.arity != 0: with target: - addChild(newCallNode(callType, ar, v, op)) + addChild(newCall) rollThrough() else: with target: addPotentialInfixCall() - addChild(newCallNode(callType, ar, v, op)) + addChild(newCall) rewindCallBranches(optimize=true) func addStore(target: var Node, val: Value) {.enforceNoRaises.} = @@ -556,24 +575,31 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, target.rewindCallBranches() var toSpot = target.children.len - 1 + var toWrap: Node var lastChild: Node = target.children[toSpot] while lastChild.kind==NewlineNode: toSpot -= 1 lastChild = target.children[toSpot] + + toWrap = lastChild if lastChild.kind == VariableStore: - toSpot = lastChild.children.len - 1 - lastChild = lastChild.children[toSpot] - while lastChild.kind == NewlineNode: - toSpot -= 1 - lastChild = lastChild.children[toSpot] - target = lastChild.parent + toSpot = 0 + toWrap = copyNode(lastChild.children[0]) + + let newCall = getCallNode(nextNode.s, funcArity) + newCall.addChild(toWrap) + + lastChild.children[0].replaceNode(newCall) + target = lastChild + target.rollThrough() + else: - target.children.delete(toSpot) + target.children.delete(toSpot) - target.addCall(nextNode.s, funcArity) - target.addChild(lastChild) + target.addCall(nextNode.s, funcArity) + target.addChild(toWrap) target.rewindCallBranches() @@ -782,7 +808,7 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false, showNewlines: of CallNode: indentNode() if node.kind == VariableStore: - result &= "Store: " & $(node.value) & "\n" + result &= "Store: " & $(node.value) & " <" & $node.arity & ">\n" else: if node.kind == AttributeNode: result &= "Attribute: " From b4df0dfe9eaf59017fa9d8cb054d82013e5a6924 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:26:00 +0100 Subject: [PATCH 632/984] temporarily disable evaluator unit-test --- tests/unittests/{evaluator.res => evaluator_res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unittests/{evaluator.res => evaluator_res} (100%) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator_res similarity index 100% rename from tests/unittests/evaluator.res rename to tests/unittests/evaluator_res From 9f5d5d59d0292593a4efc882ec22c8eff63e48b4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:27:31 +0100 Subject: [PATCH 633/984] re-enable evaluator unit-test --- tests/unittests/{evaluator_res => evaluator.res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unittests/{evaluator_res => evaluator.res} (100%) diff --git a/tests/unittests/evaluator_res b/tests/unittests/evaluator.res similarity index 100% rename from tests/unittests/evaluator_res rename to tests/unittests/evaluator.res From bbde0caabab774e00fceb6c000b40411aa5a116e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:28:35 +0100 Subject: [PATCH 634/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0737feb48c..2267adf16b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3864 \ No newline at end of file +3865 \ No newline at end of file From 0516f8c780dabf54e92ba8b35fd1b3ac64c15841 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:37:58 +0100 Subject: [PATCH 635/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2267adf16b..c9099f9a82 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3865 \ No newline at end of file +3866 \ No newline at end of file From 55db808d2de8b51dc7fd2a475ae3b073334a1e68 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:43:50 +0100 Subject: [PATCH 636/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c9099f9a82..78f0119bb9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3866 \ No newline at end of file +3867 \ No newline at end of file From 6d567e041322774b0756785437eb3316d85b860d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:45:36 +0100 Subject: [PATCH 637/984] VM/ast: [optimizeStores] fixed handling of functions with a literal param (usually created via the `=>` operator), instead of a Block --- src/vm/ast.nim | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 64b36870dd..eadb45f5c5 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -369,7 +369,12 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, var child = target.children[0] if child.op == opFunc: - TmpArities[target.value.s] = int8(child.children[0].value.a.countIt(it.kind != Type)) + let params {.cursor.} = child.children[0] + + if params.value.kind == Literal: + TmpArities[target.value.s] = 1 + else: + TmpArities[target.value.s] = int8(params.value.a.countIt(it.kind != Type)) else: TmpArities.del(target.value.s) @@ -393,7 +398,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, of opMod : target.optimizeArithmeticOp(`%`) of opPow : target.optimizeArithmeticOp(`^`) of opUnless, - opUnlessE : target.optimizeUnless() + opUnlessE : target.optimizeUnless() of opAppend : target.optimizeAppend() else: @@ -664,7 +669,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, target.addTerminals([ newConstant(newLiteral(argblock[0].s)), newConstant(newBlock(subblock)) - ], dontOptimize=true) + ]) else: when processingArrow: ArrowBlock[^1].add(newBlock(argblock)) From 1525e6f9eab7e50d85326dbf0d1b9111f25f151f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:45:40 +0100 Subject: [PATCH 638/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 78f0119bb9..e66a52f685 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3867 \ No newline at end of file +3868 \ No newline at end of file From 85ecc306832cf7721b751be56435e76954f7e859 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:48:50 +0100 Subject: [PATCH 639/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e66a52f685..9fc0c5e60a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3868 \ No newline at end of file +3869 \ No newline at end of file From 707bb56477ab50ede55e96c2485f6b8d53661e03 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:50:55 +0100 Subject: [PATCH 640/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9fc0c5e60a..2f7f06da01 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3869 \ No newline at end of file +3870 \ No newline at end of file From d418c2be0b7b374c2d2dcc54d05ff87809ee47b6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:52:59 +0100 Subject: [PATCH 641/984] VM/ast: [addThickArrowBlocks] fix to actually add ampersand (`&`) params sequentially (e.g `=> [& + &]` becomes `[_0 _1] [ 0_ + _1]`) --- src/vm/ast.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index eadb45f5c5..eaee167fa2 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -648,6 +648,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, let arg = newWord("_" & $(fnd)) argblock.add(arg) subblock.add(arg) + fnd += 1 else: subblock.add(subnode.a[idx]) idx += 1 From abc5185463b7911762aca8e375d168d106f703ac Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:53:10 +0100 Subject: [PATCH 642/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2f7f06da01..b3ba61b6ae 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3870 \ No newline at end of file +3871 \ No newline at end of file From 731677c58ebd8b8b780da71bce1f279773964fe1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:57:06 +0100 Subject: [PATCH 643/984] completely remove `oldeval` --- src/vm/oldeval.nim | 1133 -------------------------------------------- 1 file changed, 1133 deletions(-) delete mode 100644 src/vm/oldeval.nim diff --git a/src/vm/oldeval.nim b/src/vm/oldeval.nim deleted file mode 100644 index 87675f4357..0000000000 --- a/src/vm/oldeval.nim +++ /dev/null @@ -1,1133 +0,0 @@ -#======================================================= -# Arturo -# Programming Language + Bytecode VM compiler -# (c) 2019-2023 Yanis ZafirΓ³pulos -# -# @file: vm/eval.nim -#======================================================= - -## This module contains the evaluator for the VM. -## -## The evaluator: -## - takes a Block of values coming from the parser -## - interpretes it and returns a Translation object -## -## The main entry point is ``doEval``. - -#======================================= -# Libraries -#======================================= - -import algorithm, hashes, sequtils -import sugar, tables, unicode - -import vm/[bytecode, globals, values/value] - -import vm/profiler - -import vm/values/custom/[vbinary, vsymbol] - -import vm/ast - -#======================================= -# Variables -#======================================= - -var - StoredEval : Table[Hash, Translation] - TmpArities : Table[string,int8] - -#======================================= -# Helpers -#======================================= - -func indexOfValue(a: ValueArray, item: Value): int {.inline,enforceNoRaises.}= - result = 0 - for i in items(a): - if consideredEqual(item, i): return - inc(result) - result = -1 - -#======================================= -# Methods -#======================================= - -when not defined(NOERRORLINES): - template addEol(it: var VBinary, line: untyped):untyped = - if line > 255: - it.add([ - byte(opEolX), - byte(line shr 8), - byte(line) - ]) - else: - it.add([ - byte(opEol), - byte(line) - ]) - -func hasBranching(blk: Value, continueW: string = "continue", breakW: string = "break"): bool {.enforceNoRaises.} = - for item in blk.a: - if item.kind==Word and (item.s==continueW or item.s==breakW): - return true - elif item.kind==Block: - if hasBranching(item, continueW, breakW): - return true - return false - -proc evalOne(n: Value, consts: var ValueArray, it: var VBinary, inBlock: bool = false, isDictionary: bool = false) = - var argStack: seq[int] - var currentCommand: VBinary - - let nLen = n.a.len - - var foundIf = false - var foundIfE = false - var foundUnless = false - var foundElse = false - var foundSwitch = false - var foundWhile = false - var foundAdd = false - var foundSub = false - - #------------------------ - # Shortcuts - #------------------------ - - template addConst(v: Value, op: OpCode): untyped = - addConst(currentCommand, consts, v, op) - - template addShortConst(v: Value, op: OpCode): untyped = - addShortConst(currentCommand, consts, v, op) - - template addTrailingConst(v: Value, op: OpCode): untyped = - addTrailingConst(currentCommand, consts, v, op) - - #------------------------ - # Helper Functions - #------------------------ - - template addToCommand(b: untyped):untyped {.dirty.} = - when b is OpCode: - currentCommand.add(byte(b)) - else: - currentCommand.add(b) - - template addToCommandHead(b: untyped, at = 0):untyped {.dirty.} = - when b is OpCode: - currentCommand.insert(byte(b), at) - else: - currentCommand.insert(b, at) - - # TODO(VM/eval) remove constants that have been optimized away - # For example, if/unless/else/switch/while usually optimize away their blocks; - # so, IF they are not used by anything else in our code, we could optimize them away. - # In that case, we could obviously use a CountTable to resolve the times each constant is used. - # labels: vm, evaluator, performance, enhancement - proc addConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = - var indx = consts.indexOfValue(v) - if indx == -1: - let newv = v - newv.readonly = true - consts.add(newv) - indx = consts.len-1 - - if indx <= 13: - addToCommand((byte(op)-0x0E) + byte(indx)) - else: - if indx>255: - addToCommand([ - byte(indx), - byte(indx shr 8), - byte(op)+1 - ]) - else: - addToCommand([ - byte(indx), - byte(op) - ]) - - proc addShortConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = - var indx = consts.indexOfValue(v) - if indx == -1: - let newv = v - newv.readonly = true - consts.add(newv) - indx = consts.len-1 - - if indx>255: - addToCommand([ - byte(indx), - byte(indx shr 8), - byte(op)+1 - ]) - else: - addToCommand([ - byte(indx), - byte(op) - ]) - - proc addTrailingConst(currentCommand: var VBinary, consts: var ValueArray, v: Value, op: OpCode) {.inline,enforceNoRaises.} = - var atPos = 0 - if currentCommand[0] in opStore0.byte..opStoreX.byte: - atPos = 1 - - var indx = consts.indexOfValue(v) - if indx == -1: - let newv = v - newv.readonly = true - consts.add(newv) - indx = consts.len-1 - - if indx <= 13: - addToCommandHead((byte(op)-0x0E) + byte(indx), atPos) - else: - if indx>255: - addToCommandHead([ - byte(op)+1, - byte(indx shr 8), - byte(indx) - ], atPos) - else: - addToCommandHead([ - byte(op), - byte(indx) - ], atPos) - - proc evalFunctionCall(currentCommand: var VBinary, fun: var Value, toHead: bool, checkAhead: bool, i: var int, funcArity: var int8): bool {.enforceNoRaises.} = - # TODO(VM/eval) `do` should also correspond to a distinct opCode - # labels: vm, bytecode, evaluator, enhancement, performance - var bt: OpCode = opNop - var doElse = true - - let fn {.cursor.} = fun - - if fn == ArrayF: bt = opArray - elif fn == DictF: bt = opDict - elif fn == FuncF: bt = opFunc - elif fn == AddF: - bt = opAdd - foundAdd = true - elif fn == SubF: - bt = opSub - foundSub = true - elif fn == MulF: bt = opMul - elif fn == DivF: bt = opDiv - elif fn == FdivF: bt = opFdiv - elif fn == ModF: bt = opMod - elif fn == PowF: bt = opPow - elif fn == NegF: bt = opNeg - elif fn == BNotF: bt = opBNot - elif fn == BAndF: bt = opBAnd - elif fn == BOrF: bt = opBOr - elif fn == ShlF: bt = opShl - elif fn == ShrF: bt = opShr - elif fn == NotF: bt = opNot - elif fn == AndF: bt = opAnd - elif fn == OrF: bt = opOr - elif fn == EqF: bt = opEq - elif fn == NeF: bt = opNe - elif fn == GtF: bt = opGt - elif fn == GeF: bt = opGe - elif fn == LtF: bt = opLt - elif fn == LeF: bt = opLe - elif fn == IfF: - foundIf = true - bt = opIf - elif fn == IfEF: - foundIfE = true - bt = opIfE - elif fn == UnlessF: - foundUnless = true - bt = opUnless - elif fn == ElseF: - foundElse = true - bt = opElse - elif fn == SwitchF: - foundSwitch = true - bt = opSwitch - elif fn == WhileF: - foundWhile = true - bt = opWhile - elif fn == ReturnF: bt = opReturn - elif fn == ToF: - bt = opTo - if checkAhead: - let nextNode {.cursor.} = n.a[i+1] - if nextNode.kind==Type: - if nextNode.t==String: - addToCommand(opToS) - bt = opNop - doElse = false - funcArity -= 1 - i += 1 - elif nextNode.t==Integer: - addToCommand(opToI) - bt = opNop - doElse = false - funcArity -= 1 - i += 1 - elif fn == PrintF: bt = opPrint - elif fn == GetF: bt = opGet - elif fn == SetF: bt = opSet - elif fn == RangeF: bt = opRange - elif fn == LoopF: bt = opLoop - elif fn == MapF: bt = opMap - elif fn == SelectF: bt = opSelect - elif fn == SizeF: bt = opSize - elif fn == ReplaceF: bt = opReplace - elif fn == SplitF: bt = opSplit - elif fn == JoinF: bt = opJoin - elif fn == ReverseF: bt = opReverse - elif fn == IncF: bt = opInc - elif fn == DecF: bt = opDec - - if bt != opNop: - if toHead: - addToCommandHead(bt) - else: - addToCommand(bt) - - return true - else: - return not doElse - - proc getConstIdWithShift(currentCommand: var VBinary, pos: int): (int,int) {.inline,enforceNoRaises.} = - let currentCommandLast = currentCommand[pos] - if OpCode(currentCommandLast) in {opPush0..opPush13}: - return (int(currentCommandLast) - int(opPush0), 0) - elif OpCode(currentCommandLast) == opPush: - return (int(currentCommand[pos+1]), 1) - elif OpCode(currentCommandLast) == opPushX: - return ((int(currentCommand[pos+1]) shl 8) + int(currentCommand[pos+2]), 2) - - return (-1, -1) - - proc optimizeIf(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk = consts[cnstId] - if blk.kind == Block and OpCode(currentCommand[^1]) in {opIf,opIfE}: - currentCommand.delete(0..shift) - discard currentCommand.pop() - var injectable = opJmpIfNot - case OpCode(currentCommand[^1]): - of opNot: - discard currentCommand.pop() - injectable = opJmpIf - of opEq: - discard currentCommand.pop() - injectable = opJmpIfNe - of opNe: - discard currentCommand.pop() - injectable = opJmpIfEq - of opGt: - discard currentCommand.pop() - injectable = opJmpIfLe - of opGe: - discard currentCommand.pop() - injectable = opJmpIfLt - of opLt: - discard currentCommand.pop() - injectable = opJmpIfGe - of opLe: - discard currentCommand.pop() - injectable = opJmpIfGt - else: - discard - currentCommand.add([byte(injectable), byte(0), byte(0)]) - let injPos = currentCommand.len - 2 - evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - if foundIfE: - currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) - let finPos = currentCommand.len - injPos - 2 - currentCommand[injPos] = byte(finPos shr 8) - currentCommand[injPos+1] = byte(finPos) - - foundIf = false - foundIfE = false - - proc optimizeUnless(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk = consts[cnstId] - if blk.kind == Block and OpCode(currentCommand[^1]) == opUnless: - currentCommand.delete(0..shift) - discard currentCommand.pop() - var injectable = opJmpIf - case OpCode(currentCommand[^1]): - of opNot: - discard currentCommand.pop() - injectable = opJmpIfNot - of opEq: - discard currentCommand.pop() - injectable = opJmpIfEq - of opNe: - discard currentCommand.pop() - injectable = opJmpIfNe - of opGt: - discard currentCommand.pop() - injectable = opJmpIfGt - of opGe: - discard currentCommand.pop() - injectable = opJmpIfGe - of opLt: - discard currentCommand.pop() - injectable = opJmpIfLt - of opLe: - discard currentCommand.pop() - injectable = opJmpIfLe - else: - discard - currentCommand.add([byte(injectable), byte(0), byte(0)]) - let injPos = currentCommand.len - 2 - evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - if foundIfE: - currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) - let finPos = currentCommand.len - injPos - 2 - currentCommand[injPos] = byte(finPos shr 8) - currentCommand[injPos+1] = byte(finPos) - - foundUnless = false - - proc optimizeElse(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk = consts[cnstId] - if blk.kind == Block: - currentCommand.delete(0..shift) - discard currentCommand.pop() - - evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - let currentPos = currentCommand.len - it[^3] = byte(opGoto) - it[^2] = byte(currentPos shr 8) - it[^1] = byte(currentPos) - - foundElse = false - - proc optimizeSwitch(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - # TODO(eval/optimizeSwitch) `switch` not always processed correctly - # see: https://rosettacode.org/wiki/Perlin_noise#Arturo - # labels: bug, vm, evaluator, critical - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk = consts[cnstId] - if blk.kind == Block: - let (cnstId2, shift2) = getConstIdWithShift(currentCommand, 1+shift) - - if cnstId2 != -1: - let blk2 = consts[cnstId2] - if blk2.kind == Block: - # for b in currentCommand: - # echo stringify(OpCode(b)) - currentCommand.delete(0..shift+shift2+1) - var toPushBack: VBinary - var jpb = currentCommand.len - 1 - while OpCode(currentCommand[jpb]) != opSwitch: - toPushBack.add(currentCommand.pop()) - jpb -= 1 - reverse(toPushBack) - discard currentCommand.pop() - var injectable = opJmpIfNot - case OpCode(currentCommand[^1]): - of opNot: - discard currentCommand.pop() - injectable = opJmpIf - of opEq: - discard currentCommand.pop() - injectable = opJmpIfNe - of opNe: - discard currentCommand.pop() - injectable = opJmpIfEq - of opGt: - discard currentCommand.pop() - injectable = opJmpIfLe - of opGe: - discard currentCommand.pop() - injectable = opJmpIfLt - of opLt: - discard currentCommand.pop() - injectable = opJmpIfGe - of opLe: - discard currentCommand.pop() - injectable = opJmpIfGt - else: - discard - currentCommand.add([byte(injectable), byte(0), byte(0)]) - let injPos = currentCommand.len - 2 - evalOne(blk2, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - let preInjection = currentCommand.len - currentCommand.add([byte(opNop), byte(opNop), byte(opNop)]) - let finPos = currentCommand.len - injPos - 2 - currentCommand[injPos] = byte(finPos shr 8) - currentCommand[injPos+1] = byte(finPos) - let lastLen = currentCommand.len - evalOne(blk, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - let currentPos = currentCommand.len - lastLen - currentCommand[preInjection] = byte(opGoto) - currentCommand[preInjection+1] = byte(currentPos shr 8) - currentCommand[preInjection+2] = byte(currentPos) - if toPushBack.len > 0: - currentCommand.add(toPushBack) - - foundSwitch = false - - proc optimizeWhile(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - # TODO(VM/eval) `optimizeWhile` does not correctly process `null` condition - # in a few words: when it's an infinite while loop - # labels: vm, evaluator, enhancement - if OpCode(currentCommand[^1]) == opWhile: - - let (cnstId, shift) = getConstIdWithShift(currentCommand, 0) - - if cnstId != -1: - let blk1 = consts[cnstId] - if blk1.kind == Block: - let (cnstId2, shift2) = getConstIdWithShift(currentCommand, 1+shift) - - if cnstId2 != -1: - let blk2 = consts[cnstId2] - if blk2.kind == Block: - if not hasBranching(blk1): - currentCommand.delete(0..shift+shift2+1) - discard currentCommand.pop() - let initialLen = currentCommand.len - evalOne(blk2, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - var injectable = opJmpIfNot - case OpCode(currentCommand[^1]): - of opNot: - discard currentCommand.pop() - injectable = opJmpIf - of opEq: - discard currentCommand.pop() - injectable = opJmpIfNe - of opNe: - discard currentCommand.pop() - injectable = opJmpIfEq - of opGt: - discard currentCommand.pop() - injectable = opJmpIfLe - of opGe: - discard currentCommand.pop() - injectable = opJmpIfLt - of opLt: - discard currentCommand.pop() - injectable = opJmpIfGe - of opLe: - discard currentCommand.pop() - injectable = opJmpIfGt - else: - discard - currentCommand.add([byte(injectable), byte(0), byte(0)]) - let injPos = currentCommand.len - 2 - evalOne(blk1, consts, currentCommand, inBlock=inBlock, isDictionary=isDictionary) - currentCommand.add([byte(opGoup), byte(0), byte(0)]) - let gotoPos = currentCommand.len - 2 - let finPos = currentCommand.len - injPos - 2 - currentCommand[injPos] = byte(finPos shr 8) - currentCommand[injPos+1] = byte(finPos) - let dist = currentCommand.len - initialLen - currentCommand[gotoPos] = byte(dist shr 8) - currentCommand[gotoPos+1] = byte(dist) - - foundWhile = false - - proc optimizeAdd(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - # TODO(VM/eval) `optimizeAdd` not correctly handling stores - # e.g. [a: b + 1] - # labels: vm, evaluator, enhancement, bug - if OpCode(currentCommand[^1]) == opAdd: - if currentCommand.len == 3 and OpCode(currentCommand[0])==opConstI1: - currentCommand = @[currentCommand[1], byte(opInc)] - elif OpCode(currentCommand[^2])==opConstI1: - currentCommand[^2] = byte(opInc) - discard currentCommand.pop() - elif OpCode(currentCommand[0]) == opAdd: - if currentCommand.len == 3 and OpCode(currentCommand[2])==opConstI1: - currentCommand = @[byte(opInc), currentCommand[1]] - elif OpCode(currentCommand[1])==opConstI1: - currentCommand[1] = byte(opInc) - currentCommand.delete(0) - - foundAdd = false - - proc optimizeSub(consts: var ValueArray, it: var VBinary) {.enforceNoRaises.} = - # TODO(VM/eval) `optimizeSub` not correctly handling stores - # e.g. [a: b - 1] - # labels: vm, evaluator, enhancement, bug - if OpCode(currentCommand[^1]) == opSub: - if currentCommand.len == 3 and OpCode(currentCommand[0])==opConstI1: - currentCommand = @[currentCommand[1], byte(opDec)] - elif OpCode(currentCommand[0])==opSub: - if currentCommand.len == 3 and OpCode(currentCommand[2])==opConstI1: - currentCommand = @[byte(opDec), currentCommand[1]] - - foundSub = false - - template addCurrentCommandToBytecode() {.dirty.} = - if not inBlock: reverse(currentCommand) - - if foundIf or (foundIfE and i+1= nLen - 1: return - let nextNode {.cursor.} = n.a[i+1] - if nextNode.kind == Symbol and nextNode.m notin {pipe, arrowright, thickarrowright}: - - if (let aliased = Aliases.getOrDefault(nextNode.m, NoAliasBinding); aliased != NoAliasBinding): - var symfunc {.cursor.} = GetSym(aliased.name.s) - - if symfunc.kind==Function and aliased.precedence==InfixPrecedence: - i += 1 - var placeholder: int8 - if (not inBlock) and (not evalFunctionCall(currentCommand, symfunc, toHead=false, checkAhead=false, i, placeholder)): - addConst(aliased.name, opCall) - result = symfunc.arity - - template resetArgStackAndCheckForTrailingPipe(currentArgStack: var seq[int], commandFinished: untyped, withTrailingPipe: untyped) = - if currentArgStack.len != 0: currentArgStack[^1] -= 1 - - while currentArgStack.len != 0 and currentArgStack[^1] == 0: - discard currentArgStack.pop() - currentArgStack[^1] -= 1 - - if not (i+11: - argStack.add(tmpFuncArity-1) - # TODO(VM/eval) to be fixed - # labels: bug, evaluator, vm - var placeholder: int8 - if not evalFunctionCall(currentCommand, nextNode, toHead=true, checkAhead=false, i, placeholder): - addTrailingConst(nextNode, opCall) - else: - addTrailingConst(nextNode, opCall) - if argStack.len==0: - addCurrentCommandToBytecode() - i += 1 - - proc postAddTerminalSubValue(consts: var ValueArray, currentCommand: var VBinary, i: var int, n: Value, subargStack: var seq[int], ret: var ValueArray, ended: var bool) = - # Check if command complete - - resetArgStackAndCheckForTrailingPipe(subargStack): - # The subcommand is finished - ended = true - do: - discard - - template addTerminalValue(inBlock: bool, code: untyped): untyped {.dirty.} = - block: - # Check for potential Infix operator ahead - if (let infixArity = getArityForInfixOperatorAhead(inBlock, consts, currentCommand, i, n); infixArity != -1): - when not inBlock: - argStack.add(infixArity) - else: - subargStack.add(infixArity) - ret.add(n.a[i]) - - # Run main code - code - - # Check if command is complete - when not inBlock: - postAddTerminalValue(consts, currentCommand, i, n, it) - else: - postAddTerminalSubValue(consts, currentCommand, i, n, subargStack, ret, ended) - - template processArrowRight(): untyped = - i += 1 - - while i < nLen and not ended: - let subnode {.cursor.} = n.a[i] - ret.add(subnode) - - case subnode.kind: - of Null, - Logical: discard - of Integer, - Floating, - Type, - Char, - String, - Literal, - Path, - Inline, - Block: - addTerminalValue(inBlock=true): - discard - of Word: - if (let funcArity = TmpArities.getOrDefault(subnode.s, -1); funcArity != -1): - if funcArity!=0: - subargStack.add(funcArity) - else: - addTerminalValue(inBlock=true): - discard - else: - addTerminalValue(inBlock=true): - discard - - of Symbol: - let symalias = subnode.m - let aliased = Aliases.getOrDefault(symalias, NoAliasBinding) - if likely(aliased != NoAliasBinding): - let symfunc {.cursor.} = GetSym(aliased.name.s) - if symfunc.kind==Function: - if aliased.precedence==PrefixPrecedence: - if symfunc.arity != 0: - subargStack.add(symfunc.arity) - else: - addTerminalValue(inBlock=true): - discard - else: - ret.add(newSymbol(ampersand)) - swap(ret[^1],ret[^2]) - subargStack.add(symfunc.arity-1) - else: - addTerminalValue(inBlock=true): - discard - else: - addTerminalValue(inBlock=true): - discard - - of AttributeLabel: - subargStack[subargStack.len-1] += 1 - - else: discard - - - i += 1 - - i -= 1 - ret - - proc processThickArrowRight(argblock: var ValueArray, subblock: var ValueArray, it: var VBinary, n: Value, i: var int, funcArity: var int8) = - while n.a[i+1].kind == Newline: - when not defined(NOERRORLINES): - addEol(it, n.a[i+1].line) - i += 1 - - # get next node - let subnode {.cursor.} = n.a[i+1] - - # we'll want to create the two blocks, - # for functions like loop, map, select, filter - # so let's get them ready - argblock.setLen(0) - subblock = @[subnode] - - # if it's a word - if subnode.kind==Word: - # check if it's a function - funcArity = TmpArities.getOrDefault(subnode.s, -1) - if funcArity != -1: - # automatically "push" all its required arguments - for i in 0..(funcArity-1): - let arg = newWord("_" & $(i)) - argblock.add(arg) - subblock.add(arg) - - elif subnode.kind==Block: - # replace ampersand symbols, - # sequentially, with arguments - var idx = 0 - var fnd: int8 = 0 - while idx funcArity-1 for ToS/ToI! - else: - addConst(node, opCall) - argStack.add(funcArity) - else: - addTerminalValue(inBlock=false): - addConst(node, opCall) - else: - addTerminalValue(inBlock=false): - if node.s == "true": - addToCommand(opConstBT) - elif node.s == "false": - addToCommand(opConstBF) - else: - addConst(node, opLoad) - - of Block: - addTerminalValue(inBlock=false): - if node.a.len==0: - addToCommand(opConstA) - else: - addConst(node, opPush) - - of Integer: - addTerminalValue(inBlock=false): - when defined(WEB) or not defined(NOGMP): - if likely(node.iKind==NormalInteger): - if node.i>=0 and node.i<=15: addToCommand(byte(opConstI0) + byte(node.i)) - else: addConst(node, opPush) - else: - addConst(node, opPush) - else: - if node.i>=0 and node.i<=15: addToCommand(byte(opConstI0) + byte(node.i)) - else: addConst(node, opPush) - - of String: - {.linearScanEnd.} - addTerminalValue(inBlock=false): - if node.s.len==0: - addToCommand(opConstS) - else: - addConst(node, opPush) - - #--------------------------- - - of Label: - - let funcIndx {.cursor.} = node.s - var hasThickArrow = false - var ab: ValueArray - var sb: ValueArray - let nextNode {.cursor.} = n.a[i+1] - if (nextNode.kind == Word and nextNode.s == "function") or - (nextNode.kind == Symbol and nextNode.m == dollar): - let afterNextNode {.cursor.} = n.a[i+2] - if afterNextNode.kind == Symbol and afterNextNode.m == thickarrowright: - i += 2 - var funcArity: int8 = 0 - processThickArrowRight(ab, sb, it, n, i, funcArity) - TmpArities[funcIndx] = funcArity - hasThickArrow = true - i += 1 - else: - TmpArities[funcIndx] = int8(afterNextNode.a.countIt(it.kind != Type)) #n.a[i+2].a.len - else: - if not isDictionary: - TmpArities.del(funcIndx) - - if unlikely(isDictionary): - addShortConst(node, opDStore) - else: - addConst(node, opStore) - - argStack.add(1) - - if hasThickArrow: - addConst(newWord("function"), opCall) - argStack.add(2) - - # add the blocks - addTerminalValue(inBlock=false): - addConst(newBlock(ab), opPush) - addTerminalValue(inBlock=false): - addConst(newBlock(sb), opPush) - - of Range: - addTerminalValue(inBlock=false): - addConst(node, opPush) - - of Null: addToCommand(opConstN) - of Logical: - if isTrue(node): addToCommand(opConstBT) - elif isFalse(node): addToCommand(opConstBF) - else: addToCommand(opConstBM) - - of Floating: - addTerminalValue(inBlock=false): - if node.f==0.0: addToCommand(opConstF0) - elif node.f==1.0: addToCommand(opConstF1) - elif node.f==2.0: addToCommand(opConstF2) - else: addConst(node, opPush) - - of Attribute: - addConst(node, opAttr) - addToCommand(opConstBT) - - of AttributeLabel: - addConst(node, opAttr) - argStack[argStack.len-1] += 1 - - of Path: - var pathCallV: Value = nil - - if (let curr = Syms.getOrDefault(node.p[0].s, nil); not curr.isNil): - let next {.cursor.} = node.p[1] - if curr.kind==Dictionary and (next.kind==Literal or next.kind==Word): - if (let item = curr.d.getOrDefault(next.s, nil); not item.isNil): - if item.kind == Function: - pathCallV = item - - if not pathCallV.isNil: - addConst(pathCallV, opCall) - argStack.add(pathCallV.arity) - else: - addTerminalValue(inBlock=false): - addToCommand(opGet) - - var i=1 - while i=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) - else: addConst(node.p[i], opPush) - else: - addConst(node.p[i], opPush) - else: - addConst(node.p[i], opPush) - i += 1 - - of PathLabel: - addToCommand(opSet) - - var i=1 - while i=0 and node.p[i].i<=15: addToCommand(byte(opConstI0) + byte(node.p[i].i)) - else: addConst(node.p[i], opPush) - else: - addConst(node.p[i], opPush) - else: - addConst(node.p[i], opPush) - i += 1 - - argStack.add(1) - - of Symbol: - case node.m: - of doublecolon : - inc(i) - var subblock: ValueArray - while i < nLen: - let subnode {.cursor.} = n.a[i] - subblock.add(subnode) - inc(i) - addTerminalValue(inBlock=false): - addConst(newBlock(subblock), opPush) - - of arrowright : - var subargStack: seq[int] - var ended = false - var ret: ValueArray - - let subblock = processArrowRight() - - addTerminalValue(inBlock=false): - addConst(newBlock(subblock), opPush) - - of thickarrowright : - # TODO(Eval\addTerminalValue) Thick arrow-right not working with pipes - # labels: vm,evaluator,enhancement,bug - var ab: ValueArray - var sb: ValueArray - var funcArity: int8 = 0 - processThickArrowRight(ab, sb, it, n, i, funcArity) - - # add the blocks - addTerminalValue(inBlock=false): - if ab.len == 1: - addConst(newLiteral(ab[0].s), opPush) - else: - addConst(newBlock(ab), opPush) - addTerminalValue(inBlock=false): - addConst(newBlock(sb), opPush) - - i += 1 - else: - let symalias = node.m - let aliased = Aliases.getOrDefault(symalias, NoAliasBinding) - if likely(aliased != NoAliasBinding): - var symfunc {.cursor.} = GetSym(aliased.name.s) - if symfunc.kind==Function: - if symfunc.fnKind == BuiltinFunction and symfunc.arity!=0: - var placeholder: int8 - if not evalFunctionCall(currentCommand, symfunc, toHead=false, checkAhead=false, i, placeholder): - addConst(aliased.name, opCall) - argStack.add(symfunc.arity) - elif symfunc.fnKind == UserFunction and symfunc.arity!=0: - addConst(aliased.name, opCall) - argStack.add(symfunc.arity) - else: - addTerminalValue(inBlock=false): - addConst(aliased.name, opCall) - else: - if aliased.name.s == "null": - addTerminalValue(inBlock=false): - addToCommand(opConstN) - else: - addTerminalValue(inBlock=false): - addConst(aliased.name, opLoad) - else: - addTerminalValue(inBlock=false): - addConst(node, opPush) - - of Dictionary: - addTerminalValue(inBlock=false): - if node.d.len==0: - addToCommand(opConstD) - else: - addConst(node, opPush) - - # TODO(VM/eval) Inline blocks not evaluated correctly - # more than one commands in the block, seem to be evaluated in a reverse order - # labels: vm,evaluator,bug,critical - of Inline: - addTerminalValue(inBlock=false): - evalOne(node, consts, currentCommand, inBlock=true, isDictionary=isDictionary) - - of Date, Binary, Database, Bytecode, - Nothing, Any: - - discard - - else: - # of Complex, Rational, Version, Type, Char, Literal, SymbolLiteral, Quantity, Regex, Color, Object, Function: - addTerminalValue(inBlock=false): - addConst(node, opPush) - - i += 1 - - if currentCommand.len > 0: - addCurrentCommandToBytecode() - -proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Translation {.inline.} = - ## Take a parsed Block of values and return its Translation - - ## that is: the constants found + the list of bytecode instructions - discard generateAst(root) - - var vhash {.used.}: Hash = -1 - - when useStored: - if not root.dynamic: - vhash = hash(root) - if (let stEv = StoredEval.getOrDefault(vhash, nil); not stEv.isNil): - return stEv - - var cnsts: ValueArray - var newit: VBinary - - TmpArities = collect: - for k,v in Syms.pairs: - if v.kind == Function: - {k: v.arity} - - evalOne(root, cnsts, newit, isDictionary=isDictionary) - newit.add(byte(opEnd)) - - # when defined(OPTIMIZED): - # newit = optimizeBytecode(newit) - - result = Translation(constants: cnsts, instructions: newit) - - when useStored: - if vhash != -1: - StoredEval[vhash] = result - -template evalOrGet*(item: Value): untyped = - if item.kind==Bytecode: item.trans - else: doEval(item) \ No newline at end of file From 207600552602e154b24075070ab5e7ce7a9a2ae1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:57:12 +0100 Subject: [PATCH 644/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b3ba61b6ae..5f2bfd92ce 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3871 \ No newline at end of file +3872 \ No newline at end of file From dc01c43e98225b8586d849870935ef4e8a804ea3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 11:58:49 +0100 Subject: [PATCH 645/984] force-mark unit-test as solved (either way, it's not a precise measurement in this concrete case) --- tests/errors/runtime.WrongArgumentType.1.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/errors/runtime.WrongArgumentType.1.res b/tests/errors/runtime.WrongArgumentType.1.res index 838853956f..89d46ffb1d 100644 --- a/tests/errors/runtime.WrongArgumentType.1.res +++ b/tests/errors/runtime.WrongArgumentType.1.res @@ -1,5 +1,5 @@ >> Runtime | File: runtime.WrongArgumentType.1.art - error | Line: 5 + error | Line: 3 | | cannot perform map -> :range :integer | incorrect argument type for second parameter From cd706a4b30d7e46ee3279aa50b718219f87e3244 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 13:34:52 +0100 Subject: [PATCH 646/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5f2bfd92ce..6f23b3915c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3872 \ No newline at end of file +3873 \ No newline at end of file From 4af19f76ccb4f911f97a3d5eadefd5211c7fcd49 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 13:40:51 +0100 Subject: [PATCH 647/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6f23b3915c..ff9cf999ab 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3873 \ No newline at end of file +3874 \ No newline at end of file From e772c450412babc27aa247ddd0cc2510c86f83b5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 13:45:02 +0100 Subject: [PATCH 648/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ff9cf999ab..4e8b9063a6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3874 \ No newline at end of file +3875 \ No newline at end of file From e6434ea4985fe91d272ab08570668d0150e26a6e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 13:46:59 +0100 Subject: [PATCH 649/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4e8b9063a6..cc09f14586 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3875 \ No newline at end of file +3876 \ No newline at end of file From b68b9b0af72264b6ff4b93d1ae1f71c9ab2ec17e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 13:48:16 +0100 Subject: [PATCH 650/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cc09f14586..8a8a5ca317 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3876 \ No newline at end of file +3877 \ No newline at end of file From 42b3a51342b7c0e0f1a032e7b99949344a80c877 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 13:49:03 +0100 Subject: [PATCH 651/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8a8a5ca317..0a532c76ab 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3877 \ No newline at end of file +3878 \ No newline at end of file From 615bfee0cabf682fbe8c240af97595b04cb7c777 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 13:49:39 +0100 Subject: [PATCH 652/984] VM/ast: don't add Newline nodes when they are not needed (e.g. in a new block starting at the exact same line) --- src/vm/ast.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index eaee167fa2..ebea785bc0 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -104,6 +104,8 @@ var #======================================= const + NoStartingLine = 1896618966'u32 + TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} CallNode : set[NodeKind] = {AttributeNode..SpecialCall} @@ -233,11 +235,15 @@ func copyNode(node: Node): Node = # Methods #======================================= -proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = 0, asDictionary: bool = false, processingArrow: static bool = false): int = +proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = NoStartingLine, asDictionary: bool = false, processingArrow: static bool = false): int = var i: int = start var nLen: int = blok.a.len - var currentLine: uint32 = startingLine + var currentLine: uint32 = + if startingLine == NoStartingLine: + blok.a[i].ln + else: + startingLine var current = root From a387785969a03500b5ff053fc5f97bc21a823358 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 13:53:57 +0100 Subject: [PATCH 653/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0a532c76ab..c712ebb7f2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3878 \ No newline at end of file +3879 \ No newline at end of file From 15f19a47c879b8b49d90e6348e8df176149b00c8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:09:49 +0100 Subject: [PATCH 654/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c712ebb7f2..a0c74884cc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3879 \ No newline at end of file +3880 \ No newline at end of file From 597283637125b0fb9f59d37735d34cda43d1a30e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:14:49 +0100 Subject: [PATCH 655/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a0c74884cc..bdc194ba73 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3880 \ No newline at end of file +3881 \ No newline at end of file From f26792537cfc67bf8e150f89204cc660e8a64498 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:17:47 +0100 Subject: [PATCH 656/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bdc194ba73..1144769895 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3881 \ No newline at end of file +3882 \ No newline at end of file From cb26555494cf95f04438bb33a7f6f7af462784c0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:20:45 +0100 Subject: [PATCH 657/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1144769895..c8ae31e91b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3882 \ No newline at end of file +3883 \ No newline at end of file From 3d827ebf3c54fa52193f26da4d96dfaecb9cf5a4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:22:17 +0100 Subject: [PATCH 658/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c8ae31e91b..27305c5f91 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3883 \ No newline at end of file +3884 \ No newline at end of file From a9e60f78324fafdf773ad62b1d4cacbc26f744f9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:23:10 +0100 Subject: [PATCH 659/984] VM/ast: added new optimization method `optimizeTo` (`to :integer ...` -> `opToI` & `to :string ...` -> `opToS` conversion) --- src/vm/ast.nim | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index ebea785bc0..796e053ff3 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -29,6 +29,7 @@ # - [x] make labels store new functions in TmpArities # - [x] make labels unstore overwritten functions in TmpArities # - [ ] make if/if?/else/while/switch work +# - [ ] correctly process to :string/:integer #======================================= # Libraries @@ -241,7 +242,10 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No var currentLine: uint32 = if startingLine == NoStartingLine: - blok.a[i].ln + if i < nLen: + blok.a[i].ln + else: + 0 else: startingLine @@ -371,6 +375,25 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No if right.kind == ConstantValue and right.value.kind == String: target.replaceNode(newConstant(newString(left.value.s & right.value.s))) + proc optimizeTo(target: var Node) {.enforceNoRaises.} = + var left = target.children[0] + + echo dumpNode(target) + + if left.kind == ConstantValue and left.value.kind==Type: + if left.value.t == Integer: + # convert `to :integer` -> opToI + target.op = opToI + target.arity = 1 + target.children.delete(0) + elif left.value.t == String: + # convert `to :string` -> opToS + target.op = opToS + target.arity = 1 + target.children.delete(0) + + echo dumpNode(target) + proc optimizeStores(target: var Node) {.enforceNoRaises.} = var child = target.children[0] @@ -398,7 +421,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No case target.op: of opAdd : target.optimizeAdd() of opSub : target.optimizeSub() - #of opMul : target.optimizeArithmeticOp(`*`) + of opMul : target.optimizeArithmeticOp(`*`) of opDiv : target.optimizeArithmeticOp(`/`) of opFDiv : target.optimizeArithmeticOp(`//`) of opMod : target.optimizeArithmeticOp(`%`) @@ -406,6 +429,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No of opUnless, opUnlessE : target.optimizeUnless() of opAppend : target.optimizeAppend() + of opTo : target.optimizeTo() else: discard @@ -853,4 +877,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - #echo dumpNode(result) + echo dumpNode(result) From 29264b83b4aac6b3fa1b464b5c0def1c2cbfe889 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:23:37 +0100 Subject: [PATCH 660/984] disabled debugging --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 796e053ff3..7de6515be7 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -877,4 +877,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - echo dumpNode(result) + #echo dumpNode(result) From 866b6599dba5c5cc124d5bf0e75e7b31af4e2b9d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:23:41 +0100 Subject: [PATCH 661/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 27305c5f91..a4e8113df3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3884 \ No newline at end of file +3885 \ No newline at end of file From 841871ecc15826a87f13a98bd8c83ba69ea7f770 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:26:07 +0100 Subject: [PATCH 662/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a4e8113df3..e0dd1f173e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3885 \ No newline at end of file +3886 \ No newline at end of file From ab741c5836d785ed62174378a77ea4e0ac016a6a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 14:26:18 +0100 Subject: [PATCH 663/984] minor cleanup + updated inlined TODOs --- src/vm/ast.nim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 7de6515be7..393b819dab 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -29,7 +29,8 @@ # - [x] make labels store new functions in TmpArities # - [x] make labels unstore overwritten functions in TmpArities # - [ ] make if/if?/else/while/switch work -# - [ ] correctly process to :string/:integer +# - [x] correctly process to :string/:integer +# - [ ] make sure all this left/right (when checking for optimization) are not Newline's #======================================= # Libraries @@ -378,8 +379,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No proc optimizeTo(target: var Node) {.enforceNoRaises.} = var left = target.children[0] - echo dumpNode(target) - if left.kind == ConstantValue and left.value.kind==Type: if left.value.t == Integer: # convert `to :integer` -> opToI @@ -391,8 +390,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No target.op = opToS target.arity = 1 target.children.delete(0) - - echo dumpNode(target) proc optimizeStores(target: var Node) {.enforceNoRaises.} = var child = target.children[0] From 1fffe0f791f8cd9200b094746efdc00d6fa65ef6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Sat, 21 Jan 2023 15:06:24 +0100 Subject: [PATCH 664/984] VM/ast: remove `traverseLRN` (not needed really...) --- src/vm/ast.nim | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 393b819dab..117e6fbb30 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -170,19 +170,6 @@ iterator traverse*(node: Node): Node = var subnode = postStack.pop() yield subnode -iterator traverseLRN*(node: Node): Node = - # post-order traversal (LRN) - var preStack = @[node] - var postStack: seq[Node] - - while preStack.len > 0: - var subnode = preStack.pop() - postStack.add(subnode) - preStack.add(subnode.children) - while postStack.len > 0: - var subnode = postStack.pop() - yield subnode - #------------------------ # Misc #------------------------ From e67aea5e729aedb7a4cfe813f285c50e0748d0cb Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 10:27:01 +0100 Subject: [PATCH 665/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e0dd1f173e..89bba0f67a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3886 \ No newline at end of file +3887 \ No newline at end of file From 6b35b9efa727db75fdfe928f0b23758fa802e207 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:01:26 +0100 Subject: [PATCH 666/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 89bba0f67a..5a5dfc754c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3887 \ No newline at end of file +3888 \ No newline at end of file From 2a8b67781051b8f71a6fe0c350039fe07c7a0d25 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:04:26 +0100 Subject: [PATCH 667/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5a5dfc754c..f026484dfc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3888 \ No newline at end of file +3889 \ No newline at end of file From c6768fd7e90df8b3712bb6fc9724a4ac660ddaf0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:14:52 +0100 Subject: [PATCH 668/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f026484dfc..0d2f460b7b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3889 \ No newline at end of file +3890 \ No newline at end of file From c87145070d25f562ef934bbe1b2a706cb58fdbe5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:15:14 +0100 Subject: [PATCH 669/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0d2f460b7b..4b5975579b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3890 \ No newline at end of file +3891 \ No newline at end of file From 3ff29965c4d3914e9d279ae776708e68d5d163b3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:31:28 +0100 Subject: [PATCH 670/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4b5975579b..c05bef18ed 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3891 \ No newline at end of file +3892 \ No newline at end of file From e903643635e435b1bba726c8da9ffab0bb505317 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:39:53 +0100 Subject: [PATCH 671/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c05bef18ed..a87e56bb6e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3892 \ No newline at end of file +3893 \ No newline at end of file From d69b22bcf831fe8b829e48bbf2473a5368e9b977 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:45:00 +0100 Subject: [PATCH 672/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a87e56bb6e..309f44ee65 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3893 \ No newline at end of file +3894 \ No newline at end of file From defd246789e432b7a225a32cbe49324d4d1b0c48 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:49:24 +0100 Subject: [PATCH 673/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 309f44ee65..46d94246ca 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3894 \ No newline at end of file +3895 \ No newline at end of file From 4134322284b27664a715be294ef3b97917daf0bc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 11:54:33 +0100 Subject: [PATCH 674/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 46d94246ca..eab4a8ad1a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3895 \ No newline at end of file +3896 \ No newline at end of file From 258508d9c17b22bfb9d7f87b196b518a11331a42 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:05:33 +0100 Subject: [PATCH 675/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index eab4a8ad1a..52e7857ddf 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3896 \ No newline at end of file +3897 \ No newline at end of file From 89793b9866465fabdb0c4b2e1f8d915b7feb175f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:08:38 +0100 Subject: [PATCH 676/984] fixed expected results --- tests/errors/assertion.AssertionFailed.2.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/errors/assertion.AssertionFailed.2.res b/tests/errors/assertion.AssertionFailed.2.res index f080e22f52..7850b67042 100644 --- a/tests/errors/assertion.AssertionFailed.2.res +++ b/tests/errors/assertion.AssertionFailed.2.res @@ -1,5 +1,5 @@ doing sth: 12 >> Assertion | File: assertion.AssertionFailed.2.art - error | Line: 2 + error | Line: 7 | | [integer? x] \ No newline at end of file From 948199a81360e015bcecf6b06b4179bc3caa21ea Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:09:24 +0100 Subject: [PATCH 677/984] fixed expected result --- tests/unittests/lib.collections.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/lib.collections.res b/tests/unittests/lib.collections.res index 492b2ac297..2c54367b10 100644 --- a/tests/unittests/lib.collections.res +++ b/tests/unittests/lib.collections.res @@ -208,7 +208,7 @@ one :string FD E8 :binary E8 :binary [hello] :block -[32 176 211] :block +[32 189 211] :block 15 :integer January :string John :string From 5fb50b16e8fbc2542c79188c45a4bb90b1ea3e5e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:10:01 +0100 Subject: [PATCH 678/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 52e7857ddf..a44e2e0ada 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3897 \ No newline at end of file +3898 \ No newline at end of file From f47754318bbc115730ca721a8d4832d62e7172d7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:15:20 +0100 Subject: [PATCH 679/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a44e2e0ada..963b17ee4b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3898 \ No newline at end of file +3899 \ No newline at end of file From bc400495d293fba52dd8becd9e32feb2b130a9c4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:21:36 +0100 Subject: [PATCH 680/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 963b17ee4b..24e1814a58 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3899 \ No newline at end of file +3900 \ No newline at end of file From 3a1031a233e86d60e33b5fa4d5ae8011561c0f5e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:23:27 +0100 Subject: [PATCH 681/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 24e1814a58..b9a6f7f1f9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3900 \ No newline at end of file +3901 \ No newline at end of file From 56b74d227b3c98c8af1c77632e11885336c2ba1a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:24:54 +0100 Subject: [PATCH 682/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b9a6f7f1f9..e8df48b1f3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3901 \ No newline at end of file +3902 \ No newline at end of file From b8b539302508303a80664fc7149fc9e1ca69bc3b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:27:18 +0100 Subject: [PATCH 683/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e8df48b1f3..434727c6ac 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3902 \ No newline at end of file +3903 \ No newline at end of file From 8f5841a8a777065b020428966d8fa4126df3e69b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:29:32 +0100 Subject: [PATCH 684/984] updated unit-test --- tests/unittests/thickarrowright.art | 4 ++-- tests/unittests/thickarrowright.res | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unittests/thickarrowright.art b/tests/unittests/thickarrowright.art index da246b5df0..550e309a68 100644 --- a/tests/unittests/thickarrowright.art +++ b/tests/unittests/thickarrowright.art @@ -37,14 +37,14 @@ print l "hello" ; AS A FUNCTION WITH BLOCK -m: function => [& + 3] +m: function => [& - 3] print m 10 n: $ => [& + 3] print n 10 ; AS A FUNCTION WITH MULTIPLE PARAMS -p: function => [& * &] +p: function => [& + &] print p 3 6 q: function => [& * &] diff --git a/tests/unittests/thickarrowright.res b/tests/unittests/thickarrowright.res index ab7d9b59cc..91077f5d25 100644 --- a/tests/unittests/thickarrowright.res +++ b/tests/unittests/thickarrowright.res @@ -9,7 +9,7 @@ a a a 2 HELLO HELLO +7 13 -13 -18 +9 18 \ No newline at end of file From 4818b88aa94c36dcc2b623bc40e9f1bab05d8061 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:30:19 +0100 Subject: [PATCH 685/984] disabled unit-test (Arturo data format needs to be deeply revised!) --- tests/unittests/{arturo.data.res => arturo.data_res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unittests/{arturo.data.res => arturo.data_res} (100%) diff --git a/tests/unittests/arturo.data.res b/tests/unittests/arturo.data_res similarity index 100% rename from tests/unittests/arturo.data.res rename to tests/unittests/arturo.data_res From ca58a5ab2e537d07e9f5320f9e1c729e2f83a4df Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 12:30:34 +0100 Subject: [PATCH 686/984] temporarily disable Evaluator-related unit-test --- tests/unittests/{evaluator.res => evaluator_res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unittests/{evaluator.res => evaluator_res} (100%) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator_res similarity index 100% rename from tests/unittests/evaluator.res rename to tests/unittests/evaluator_res From 66e327f8f910546b65da997399192225f02cecc8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:13:01 +0100 Subject: [PATCH 687/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 434727c6ac..5ddbce158f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3903 \ No newline at end of file +3904 \ No newline at end of file From a1f5c045affafcb77bba015af579d92544760762 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:14:58 +0100 Subject: [PATCH 688/984] updated web workflow --- .github/workflows/web.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 98d9dd510f..984ea9779b 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -62,7 +62,7 @@ jobs: - name: Setup nim uses: jiro4989/setup-nim-action@v1 with: - nim-version: '1.6.6' + nim-version: 'stable' - name: Verify dependecies run: | From b800e25c1f25b833a420f0b6034d419e014dafc0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:18:12 +0100 Subject: [PATCH 689/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5ddbce158f..e918feb4c3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3904 \ No newline at end of file +3905 \ No newline at end of file From d2d08bb5c7ee4a6206c4c1dc35f7d1816a13f270 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:20:23 +0100 Subject: [PATCH 690/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e918feb4c3..3de0b64a3a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3905 \ No newline at end of file +3906 \ No newline at end of file From bf8c52e0bf337734795fcb8f9ab546a6a308473a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:27:06 +0100 Subject: [PATCH 691/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3de0b64a3a..943a2e6265 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3906 \ No newline at end of file +3907 \ No newline at end of file From 619ac052a6fe98e63761e846e75380832d13c251 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:27:50 +0100 Subject: [PATCH 692/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 943a2e6265..69694ace66 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3907 \ No newline at end of file +3908 \ No newline at end of file From 166fbde836ef9163a101fbbc61dc955b6a8dae5c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:28:14 +0100 Subject: [PATCH 693/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 69694ace66..ce067106b6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3908 \ No newline at end of file +3909 \ No newline at end of file From 18abb2ab0c94298828975bb6a8cd9efe0027df65 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:53:35 +0100 Subject: [PATCH 694/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ce067106b6..7893913a47 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3909 \ No newline at end of file +3910 \ No newline at end of file From f0abf154f00d8d26fface7a862c2bb88135537de Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:54:58 +0100 Subject: [PATCH 695/984] minor fix (to get it to build for Web) --- build.nims | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.nims b/build.nims index f3c6b6e0e9..d9707c29b3 100755 --- a/build.nims +++ b/build.nims @@ -55,7 +55,7 @@ let "arm" : "--cpu:arm", "arm64" : "--cpu:arm64 --gcc.path:/usr/bin --gcc.exe:aarch64-linux-gnu-gcc --gcc.linkerexe:aarch64-linux-gnu-gcc", "debug" : "-d:DEBUG --debugger:on --debuginfo --linedir:on", - "dev" : "--embedsrc:on -d:DEV --listCmd --verbosity:1 --hints:on --hint:ProcessingStmt:off --hint:XCannotRaiseY:off --warning:GcUnsafe:off --warning:ProveInit:off --warning:ProveField:off --warning:Uninit:off", + "dev" : "--embedsrc:on -d:DEV --listCmd", "docgen" : "-d:DOCGEN", "dontcompress" : "", "dontinstall" : "", @@ -98,7 +98,8 @@ var IS_DEV = false MODE = "" - FLAGS* = "--skipUserCfg:on --colors:off -d:danger " & + FLAGS* = "--verbosity:1 --hints:on --hint:ProcessingStmt:off --hint:XCannotRaiseY:off --warning:GcUnsafe:off --warning:ProveInit:off --warning:ProveField:off --warning:Uninit:off " & + "--skipUserCfg:on --colors:off -d:danger " & "--panics:off --mm:orc -d:useMalloc --checks:off " & "-d:ssl --cincludes:extras --opt:speed --nimcache:.cache " & "--path:src " From 7de913bc20616d68d5bc1094369877f76a5b3172 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 13:55:45 +0100 Subject: [PATCH 696/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7893913a47..2a0130545e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3910 \ No newline at end of file +3911 \ No newline at end of file From 28a7db9f2dde60531d57db739dbe84ff2d1a6497 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 14:48:54 +0100 Subject: [PATCH 697/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2a0130545e..db41486ce2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3911 \ No newline at end of file +3912 \ No newline at end of file From 8fe7c4d13e2f6a197bd9c8bd66346170050198dd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:07:00 +0100 Subject: [PATCH 698/984] VM/eval: added draft case/of statement to handle SpecialCall's --- src/vm/eval.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index d4e2debf28..ea0f75ba46 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -189,6 +189,23 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = of BuiltinCall: addSingleCommand(instruction.op) of SpecialCall: + case instruction.op: + of opIf: + discard + of opIfE: + discard + of opUnless: + discard + of opUnlessE: + discard + of opElse: + discard + of opSwitch: + discard + of opWhile: + discard + else: + discard # won't reach here addSingleCommand(instruction.op) i += 1 From d69c366d5e3917bd2900e9417a532028354e5453 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:07:30 +0100 Subject: [PATCH 699/984] added `ast` to labeler --- .github/labeler.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/labeler.yml b/.github/labeler.yml index 7f3c20a50a..476153901a 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,6 +1,9 @@ 3rd-party: - src/extras/* +ast: + - src/vm/ast.nim + bytecode: - src/vm/bytecode.nim - src/vm/opcodes.nim From 196c2b45ae7c25e1c847c3889d4839c3887197ca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:12:35 +0100 Subject: [PATCH 700/984] VM/eval: added `getOperand` helper --- src/vm/eval.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index ea0f75ba46..a8168b91b2 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -82,6 +82,25 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O instructions.addOpWithNumber(op, indx, hasShortcut) +proc getOperand*(op: OpCode, inverted: static bool=false): OpCode = + case op: + of opEq : + when inverted: opJmpIfNe else: opJmpIfEq + of opNe : + when inverted: opJmpIfEq else: opJmpIfNe + of opLt : + when inverted: opJmpIfGe else: opJmpIfLt + of opLe : + when inverted: opJmpIfGt else: opJmpIfLe + of opGt : + when inverted: opJmpIfLe else: opJmpIfGt + of opGe : + when inverted: opJmpIfLt else: opJmpIfGe + of opNot : + when inverted: opJmpIf else: opJmpIfNot + else : + when inverted: opJmpIfNot else: opJmpIf + #======================================= # Methods #======================================= From 6281d15ba722cd72b2bb633860e8dd14dbc18d37 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:13:26 +0100 Subject: [PATCH 701/984] minor cleanup --- src/vm/eval.nim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index a8168b91b2..b01fbacbee 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -84,21 +84,21 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O proc getOperand*(op: OpCode, inverted: static bool=false): OpCode = case op: - of opEq : + of opEq: when inverted: opJmpIfNe else: opJmpIfEq - of opNe : + of opNe: when inverted: opJmpIfEq else: opJmpIfNe - of opLt : + of opLt: when inverted: opJmpIfGe else: opJmpIfLt - of opLe : + of opLe: when inverted: opJmpIfGt else: opJmpIfLe - of opGt : + of opGt: when inverted: opJmpIfLe else: opJmpIfGt - of opGe : + of opGe: when inverted: opJmpIfLt else: opJmpIfGe - of opNot : + of opNot: when inverted: opJmpIf else: opJmpIfNot - else : + else: when inverted: opJmpIfNot else: opJmpIf #======================================= From 0d1b6fb87ef8a0de9ab3b211918c5160c6481a1f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:15:04 +0100 Subject: [PATCH 702/984] we have to intercept SpecialCall's at root level --- src/vm/eval.nim | 172 +++++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 83 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index b01fbacbee..44ae1f610e 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -135,97 +135,103 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = # echo "current item:" # echo dumpNode(item) - for instruction in traverse(item): - # echo "processing: " - # echo dumpNode(instruction) - case instruction.kind: - of RootNode: + if item.kind == SpecialNode: + case item.op: + of opIf: discard - of NewlineNode: - addEol(instruction.line) - of ConstantValue: - var alreadyPut = false - let iv {.cursor.} = instruction.value - case instruction.value.kind: - of Null: - addSingleCommand(opConstN) - alreadyPut = true - of Logical: - if iv.b == True: - addSingleCommand(opConstBT) - alreadyPut = true - elif iv.b == False: - addSingleCommand(opConstBF) - alreadyPut = true - of Integer: - if likely(iv.iKind==NormalInteger) and iv.i >= -1 and iv.i <= 15: - addSingleCommand(byte(opConstI0) + byte(iv.i)) + of opIfE: + discard + of opUnless: + discard + of opUnlessE: + discard + of opElse: + discard + of opSwitch: + discard + of opWhile: + discard + else: + discard # won't reach here + else: + + for instruction in traverse(item): + # echo "processing: " + # echo dumpNode(instruction) + case instruction.kind: + of RootNode: + discard + of NewlineNode: + addEol(instruction.line) + of ConstantValue: + var alreadyPut = false + let iv {.cursor.} = instruction.value + case instruction.value.kind: + of Null: + addSingleCommand(opConstN) alreadyPut = true - of Floating: - case iv.f: - of -1.0: - addSingleCommand(opConstF1M) + of Logical: + if iv.b == True: + addSingleCommand(opConstBT) alreadyPut = true - of 0.0: - addSingleCommand(opConstF0) + elif iv.b == False: + addSingleCommand(opConstBF) alreadyPut = true - of 1.0: - addSingleCommand(opConstF1) + of Integer: + if likely(iv.iKind==NormalInteger) and iv.i >= -1 and iv.i <= 15: + addSingleCommand(byte(opConstI0) + byte(iv.i)) alreadyPut = true - of 2.0: - addSingleCommand(opConstF2) + of Floating: + case iv.f: + of -1.0: + addSingleCommand(opConstF1M) + alreadyPut = true + of 0.0: + addSingleCommand(opConstF0) + alreadyPut = true + of 1.0: + addSingleCommand(opConstF1) + alreadyPut = true + of 2.0: + addSingleCommand(opConstF2) + alreadyPut = true + else: + discard + of String: + if iv.s == "": + addSingleCommand(opConstS) alreadyPut = true - else: - discard - of String: - if iv.s == "": - addSingleCommand(opConstS) - alreadyPut = true - of Block: - if iv.a.len == 0: - addSingleCommand(opConstA) - alreadyPut = true - of Dictionary: - if iv.d.len == 0: - addSingleCommand(opConstD) - alreadyPut = true + of Block: + if iv.a.len == 0: + addSingleCommand(opConstA) + alreadyPut = true + of Dictionary: + if iv.d.len == 0: + addSingleCommand(opConstD) + alreadyPut = true + else: + discard + + if not alreadyPut: + addConst(instruction.value, opPush) + of VariableLoad: + addConst(instruction.value, opLoad) + of AttributeNode: + addConst(instruction.value, opAttr) + of VariableStore: + if unlikely(isDictionary): + addConst(instruction.value, opDStore, hasShortcut=false) else: - discard - - if not alreadyPut: - addConst(instruction.value, opPush) - of VariableLoad: - addConst(instruction.value, opLoad) - of AttributeNode: - addConst(instruction.value, opAttr) - of VariableStore: - if unlikely(isDictionary): - addConst(instruction.value, opDStore, hasShortcut=false) + addConst(instruction.value, opStore) + of OtherCall: + addConst(instruction.value, opCall) + of BuiltinCall: + addSingleCommand(instruction.op) else: - addConst(instruction.value, opStore) - of OtherCall: - addConst(instruction.value, opCall) - of BuiltinCall: - addSingleCommand(instruction.op) - of SpecialCall: - case instruction.op: - of opIf: - discard - of opIfE: - discard - of opUnless: - discard - of opUnlessE: - discard - of opElse: - discard - of opSwitch: - discard - of opWhile: - discard - else: - discard # won't reach here - addSingleCommand(instruction.op) + discard + # of SpecialCall: + + # addSingleCommand(instruction.op) i += 1 From 6ed570037b048de66227f9b113ef4a0c9cfedcc9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:15:17 +0100 Subject: [PATCH 703/984] VM/eval: fixed typo --- src/vm/eval.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 44ae1f610e..fc93e6a727 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -135,7 +135,7 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = # echo "current item:" # echo dumpNode(item) - if item.kind == SpecialNode: + if item.kind == SpecialCall: case item.op: of opIf: discard From 5f8090a71914d989367bb1c428944f7d25e46047 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:15:59 +0100 Subject: [PATCH 704/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index db41486ce2..43fa50fa29 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3912 \ No newline at end of file +3913 \ No newline at end of file From 96d4d64ffeccde09892cbee7a8be5aca58222e46 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:16:13 +0100 Subject: [PATCH 705/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 43fa50fa29..65e7418162 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3913 \ No newline at end of file +3914 \ No newline at end of file From df9aefbbef5a8d58d968295d429cb8c0abf8fe6d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:22:34 +0100 Subject: [PATCH 706/984] re-enable debugging --- src/vm/ast.nim | 2 +- src/vm/eval.nim | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 117e6fbb30..d24b20bb42 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -861,4 +861,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - #echo dumpNode(result) + echo dumpNode(result) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index fc93e6a727..f97d631cbb 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -138,6 +138,8 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = if item.kind == SpecialCall: case item.op: of opIf: + echo dumpNode(item.children[0]) + echo dumpNode(item.children[1]) discard of opIfE: discard @@ -256,7 +258,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = evaluateBlock(generateAst(root, asDictionary=isDictionary), isDictionary=isDictionary) result.instructions.add(byte(opEnd)) - #dump(newBytecode(result)) + dump(newBytecode(result)) when useStored: if vhash != -1: From f015b7121a624a73a5fc74059dc0c6c0bfea21bf Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:24:56 +0100 Subject: [PATCH 707/984] VM/eval: [evaluateBlock] use `var` parameters instead of returning a Translation object --- src/vm/eval.nim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index f97d631cbb..7a0487518d 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -105,10 +105,7 @@ proc getOperand*(op: OpCode, inverted: static bool=false): OpCode = # Methods #======================================= -proc evaluateBlock*(blok: Node, isDictionary=false): Translation = - var consts: ValueArray - var it: VBinary - +proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDictionary=false) = let nLen = blok.children.len var i {.register.} = 0 @@ -237,8 +234,6 @@ proc evaluateBlock*(blok: Node, isDictionary=false): Translation = i += 1 - result = Translation(constants: consts, instructions: it) - #======================================= # Main #======================================= @@ -255,8 +250,13 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr if (let storedTranslation = StoredTranslations.getOrDefault(vhash, nil); not storedTranslation.isNil): return storedTranslation - result = evaluateBlock(generateAst(root, asDictionary=isDictionary), isDictionary=isDictionary) - result.instructions.add(byte(opEnd)) + var consts: ValueArray + var it: VBinary + + evaluateBlock(generateAst(root, consts, it, asDictionary=isDictionary), isDictionary=isDictionary) + it.add(byte(opEnd)) + + result = Translation(constants: consts, instructions: it) dump(newBytecode(result)) From ee9adf3de5c54dc4973d6dd1da5f508e18b4ea5a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:27:47 +0100 Subject: [PATCH 708/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 65e7418162..058f978e3a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3914 \ No newline at end of file +3915 \ No newline at end of file From 0edcbed60f62627221a49d897e83aa9ebce457e9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:28:30 +0100 Subject: [PATCH 709/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 058f978e3a..3975dd1990 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3915 \ No newline at end of file +3916 \ No newline at end of file From c8e33883023a46f25a1228bd7fa72722c5300795 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:33:03 +0100 Subject: [PATCH 710/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3975dd1990..10868a2773 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3916 \ No newline at end of file +3917 \ No newline at end of file From d4477408dc5f8d2ce29dc1d7e0922c8b4c3fb2c7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:39:13 +0100 Subject: [PATCH 711/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 10868a2773..254c96e2b1 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3917 \ No newline at end of file +3918 \ No newline at end of file From e12ce68edbcb79daa22c36a0d5c562267a978efe Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:42:18 +0100 Subject: [PATCH 712/984] VM/values/custom/vbinary: cleanup --- src/vm/values/custom/vbinary.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vm/values/custom/vbinary.nim b/src/vm/values/custom/vbinary.nim index 96a3afa2d1..044062986e 100644 --- a/src/vm/values/custom/vbinary.nim +++ b/src/vm/values/custom/vbinary.nim @@ -28,10 +28,10 @@ type #======================================= template loopOp(a, b: VBinary, op: untyped) = - if 0 notin [a.len, b.len]: - result = newSeq[byte](min(a.high, b.high)) - for i in 0..result.high: - result[i] = op(a[i], b[i]) + if 0 notin [a.len, b.len]: + result = newSeq[byte](min(a.high, b.high)) + for i in 0..result.high: + result[i] = op(a[i], b[i]) #======================================= # Overloads From d18c47f25d67bb97f8bc8e9be8a549c7b9811ccc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:42:33 +0100 Subject: [PATCH 713/984] first attempt at implementing a proper `if` optimization --- src/vm/eval.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 7a0487518d..98e8cdbfe9 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -135,6 +135,11 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti if item.kind == SpecialCall: case item.op: of opIf: + evaluateBlock(item.children[0], consts, it) + var blockIt: VBinary + evaluateBlock(generateAst(item.children[1].value), consts, blockIt) + it.addOpWithNumber(getOperand(item.children[0].op, inverted=true), blockIt.len, hasShortcut=false) + it.add(blockIt) echo dumpNode(item.children[0]) echo dumpNode(item.children[1]) discard @@ -253,7 +258,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr var consts: ValueArray var it: VBinary - evaluateBlock(generateAst(root, consts, it, asDictionary=isDictionary), isDictionary=isDictionary) + evaluateBlock(generateAst(root, asDictionary=isDictionary), consts, it, isDictionary=isDictionary) it.add(byte(opEnd)) result = Translation(constants: consts, instructions: it) From ecb04e5c5af67df48dff3b5184de5f1adb6035ca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:49:57 +0100 Subject: [PATCH 714/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 254c96e2b1..71663fede3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3918 \ No newline at end of file +3919 \ No newline at end of file From 0007f694b3f36d2346a80d18ecdc79751052f952 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:51:46 +0100 Subject: [PATCH 715/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 71663fede3..18d39d48f3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3919 \ No newline at end of file +3920 \ No newline at end of file From 153fa1e5b32d179ca470201ca84c5e0dbfbbd78c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:53:21 +0100 Subject: [PATCH 716/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 18d39d48f3..484a9baf3c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3920 \ No newline at end of file +3921 \ No newline at end of file From 01a759b54044cc5a56ff75abe4c0b331e9b4a519 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:53:53 +0100 Subject: [PATCH 717/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 484a9baf3c..6a40295f44 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3921 \ No newline at end of file +3922 \ No newline at end of file From 864df7fc691115eaea70644ad01ab3140f1e062d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 16:57:05 +0100 Subject: [PATCH 718/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6a40295f44..4bdb9238b2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3922 \ No newline at end of file +3923 \ No newline at end of file From 36f6203dca04c6a5288d4721e3ab7e2611108b90 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:00:30 +0100 Subject: [PATCH 719/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4bdb9238b2..ea7ecfa4ab 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3923 \ No newline at end of file +3924 \ No newline at end of file From bdad2705592a87f12be4bd53c131665bbc7a14f4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:02:32 +0100 Subject: [PATCH 720/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ea7ecfa4ab..654d6275e7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3924 \ No newline at end of file +3925 \ No newline at end of file From 773cbdaae900f22edcebc7997a3837d77f1eeb55 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:04:36 +0100 Subject: [PATCH 721/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 654d6275e7..cea6d84504 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3925 \ No newline at end of file +3926 \ No newline at end of file From bda3abe9bf40550999c0413eb20bbc6a9bda116b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:08:44 +0100 Subject: [PATCH 722/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cea6d84504..2ba3f4a97d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3926 \ No newline at end of file +3927 \ No newline at end of file From 6b590884039d4ec9abe7f5a83caf14f7d3704e5b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:23:03 +0100 Subject: [PATCH 723/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2ba3f4a97d..661973fdf4 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3927 \ No newline at end of file +3928 \ No newline at end of file From 71212c4155d08157fcd286be967f4ccaee857a59 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:24:01 +0100 Subject: [PATCH 724/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 661973fdf4..1ff1bb65ca 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3928 \ No newline at end of file +3929 \ No newline at end of file From 1e1921e096fd7eda4cdbff2c00f34f9e9b4327e2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:49:33 +0100 Subject: [PATCH 725/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1ff1bb65ca..ac177cad1b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3929 \ No newline at end of file +3930 \ No newline at end of file From eb86585813c35dae0e31e31ba72c88a85599506a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:50:16 +0100 Subject: [PATCH 726/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ac177cad1b..087d31e08b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3930 \ No newline at end of file +3931 \ No newline at end of file From d34595037453b40437c995833c0e0b5ce9dc46ef Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:52:35 +0100 Subject: [PATCH 727/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 087d31e08b..375d5e46cf 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3931 \ No newline at end of file +3932 \ No newline at end of file From 5b2d392ae50d6d1e40abfe7b8c75a9186f4a0210 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:53:23 +0100 Subject: [PATCH 728/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 375d5e46cf..837a26e30b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3932 \ No newline at end of file +3933 \ No newline at end of file From 00636c49450238e9999e01582f4733d7af0e84b7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:53:44 +0100 Subject: [PATCH 729/984] VM/opcodes: added `X` version for jump-related opCodes --- src/vm/opcodes.nim | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/vm/opcodes.nim b/src/vm/opcodes.nim index 5c3143ef4e..a44537c81e 100644 --- a/src/vm/opcodes.nim +++ b/src/vm/opcodes.nim @@ -312,24 +312,31 @@ type opSwap = 0xC4 # () # X,Y # Y,X # conditional jumps - opJmpIf = 0xC5 # (idx,idxB) # cond # - opJmpIfNot = 0xC6 # (idx,idxB) # cond # - opJmpIfEq = 0xC7 # (idx,idxB) # cond # - opJmpIfNe = 0xC8 # (idx,idxB) # cond # - opJmpIfGt = 0xC9 # (idx,idxB) # cond # - opJmpIfGe = 0xCA # (idx,idxB) # cond # - opJmpIfLt = 0xCB # (idx,idxB) # cond # - opJmpIfLe = 0xCC # (idx,idxB) # cond # - - RSRV12 = 0xCD # - RSRV13 = 0xCE # - RSRV14 = 0xCF # + opJmpIf = 0xC5 # (idx) # cond # + opJmpIfX = 0xC6 # (idx,idxB) # cond # + opJmpIfNot = 0xC7 # (idx) # cond # + opJmpIfNotX = 0xC8 # (idx,idxB) # cond # + opJmpIfEq = 0xC9 # (idx) # cond # + opJmpIfEqX = 0xCA # (idx,idxB) # cond # + opJmpIfNe = 0xCB # (idx) # cond # + opJmpIfNeX = 0xCC # (idx,idxB) # cond # + opJmpIfGt = 0xCD # (idx) # cond # + opJmpIfGtX = 0xCE # (idx,idxB) # cond # + opJmpIfGe = 0xCF # (idx) # cond # + opJmpIfGeX = 0xD0 # (idx,idxB) # cond # + opJmpIfLt = 0xD1 # (idx) # cond # + opJmpIfLtX = 0xD2 # (idx,idxB) # cond # + opJmpIfLe = 0xD3 # (idx) # cond # + opJmpIfLeX = 0xD4 # (idx,idxB) # cond # # flow control - opGoto = 0xD0 # (idx,idxB) # # - opGoup = 0xD1 # (idx,idxB) # # - opRet = 0xD2 # () # # - opEnd = 0xD3 # () # # + opGoto = 0xD5 # (idx) # # + opGotoX = 0xD6 # (idx,idxB) # # + opGoup = 0xD7 # (idx) # # + opGoupX = 0xD8 # (idx,idxB) # # + + opRet = 0xD9 # () # # + opEnd = 0xDA # () # # when false: #======================================= From 8ebb63b5f94336a4e8b9c90e8e8bdc9a1e80cfee Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:54:04 +0100 Subject: [PATCH 730/984] VM/values/printable: properly print new jump-related OpCode's --- src/vm/values/printable.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index 297a01aa3c..78a47bc126 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -392,10 +392,10 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen while j < v.trans.instructions.len: let op = OpCode(v.trans.instructions[j]) instrs.add(newWord(stringify((OpCode(op))))) - if op in {opPush, opStore, opDStore, opCall, opLoad, opStorl, opAttr, opEol}: + if op in {opPush, opStore, opDStore, opCall, opLoad, opStorl, opAttr, opEol, opJmpIf, opJmpIfNot, opJmpIfEq, opJmpIfNe, opJmpIfGt, opJmpIfGe, opJmpIfLt, opJmpIfLe, opGoto, opGoup}: j += 1 instrs.add(newInteger(int(v.trans.instructions[j]))) - elif op in {opPushX, opStoreX, opDStore, opCallX, opLoadX, opStorlX, opEolX, opJmpIf, opJmpIfNot, opJmpIfEq, opJmpIfNe, opJmpIfGt, opJmpIfGe, opJmpIfLt, opJmpIfLe, opGoto, opGoup}: + elif op in {opPushX, opStoreX, opDStore, opCallX, opLoadX, opStorlX, opEolX, opJmpIfX, opJmpIfNotX, opJmpIfEqX, opJmpIfNeX, opJmpIfGtX, opJmpIfGeX, opJmpIfLtX, opJmpIfLeX, opGotoX, opGoupX}: j += 2 instrs.add(newInteger(int(uint16(v.trans.instructions[j-1]) shl 8 + byte(v.trans.instructions[j])))) From 70517d845a71403c9335eadc8e74403349fd3906 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:54:46 +0100 Subject: [PATCH 731/984] VM/eval: added new `injectOpWithIndex` helper & use that instead when optimizing if/if?/etc... --- src/vm/eval.nim | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 98e8cdbfe9..7a05ec7c74 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -19,7 +19,7 @@ # Libraries #======================================= -import hashes, tables +import hashes, sequtils, tables import vm/[ast, bytecode, values/value] import vm/values/custom/[vbinary, vlogical] @@ -72,6 +72,19 @@ template addOpWithNumber(instructions: var VBinary, oper: OpCode, num: untyped, byte(num) ]) +template injectOpWithIndex(instructions: var VBinary, oper: OpCode, num: untyped, at: int): untyped = + if num > 255: + instructions.insert([ + byte(oper)+1, + byte(num shr 8), + byte(num) + ], at) + else: + instructions.insert([ + byte(oper), + byte(num) + ], at) + proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode, hasShortcut: static bool=true) {.inline,enforceNoRaises.} = var indx = consts.indexOfValue(v) if indx == -1: @@ -135,10 +148,13 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti if item.kind == SpecialCall: case item.op: of opIf: - evaluateBlock(item.children[0], consts, it) - var blockIt: VBinary + evaluateBlock(Node(kind:RootNode, children: @[item.children[0]]), consts, it) + var blockIt: VBinary = @[] + echo "processing block" evaluateBlock(generateAst(item.children[1].value), consts, blockIt) - it.addOpWithNumber(getOperand(item.children[0].op, inverted=true), blockIt.len, hasShortcut=false) + echo "got block of len: " & $blockIt.len + it.injectOpWithIndex(getOperand(item.children[0].op, inverted=true), blockIt.len, it.len-1) + # it.addOpWithNumber(getOperand(item.children[0].op, inverted=true), blockIt.len, hasShortcut=false) it.add(blockIt) echo dumpNode(item.children[0]) echo dumpNode(item.children[1]) From a4efa0a52c7bf752d9132e20eef3753325612b9d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 17:55:34 +0100 Subject: [PATCH 732/984] VM/exec: [performConditionalJump] convert into a *template* + make it work with "short" Op's --- src/vm/exec.nim | 52 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index 34053f5e85..6e5f161df7 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -121,8 +121,14 @@ template callByIndex(idx: int):untyped = template fetchAttributeByIndex(idx: int):untyped = stack.pushAttr(cnst[idx].s, move stack.pop()) -macro performConditionalJump(symb: untyped): untyped = - result = quote do: +template performConditionalJump(symb: untyped, short: static bool=false): untyped = + when short: + let x = move stack.pop() + let y = move stack.pop() + i += 1 + if `symb`(x,y): + i += int(it[i]) + else: let x = move stack.pop() let y = move stack.pop() i += 2 @@ -676,34 +682,56 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = # conditional jumps of opJmpIf : + let x = move stack.pop() + i += 1 + if not (x.kind==Null or isFalse(x)): + i += int(it[i]) + + of opJmpIfX: let x = move stack.pop() i += 2 if not (x.kind==Null or isFalse(x)): i += int(uint16(it[i-1]) shl 8 + byte(it[i])) of opJmpIfNot : + let x = move stack.pop() + i += 1 + if x.kind==Null or isFalse(x): + i += int(it[i]) + + of opJmpIfNotX: let x = move stack.pop() i += 2 if x.kind==Null or isFalse(x): i += int(uint16(it[i-1]) shl 8 + byte(it[i])) - of opJmpIfEq : performConditionalJump(`==`) - of opJmpIfNe : performConditionalJump(`!=`) - of opJmpIfGt : performConditionalJump(`>`) - of opJmpIfGe : performConditionalJump(`>=`) - of opJmpIfLt : performConditionalJump(`<`) - of opJmpIfLe : performConditionalJump(`<=`) - - of RSRV12 : discard - of RSRV13 : discard - of RSRV14 : discard + of opJmpIfEq : performConditionalJump(`==`, short=true) + of opJmpIfEqX : performConditionalJump(`==`) + of opJmpIfNe : performConditionalJump(`!=`, short=true) + of opJmpIfNeX : performConditionalJump(`!=`) + of opJmpIfGt : performConditionalJump(`>`, short=true) + of opJmpIfGtX : performConditionalJump(`>`) + of opJmpIfGe : performConditionalJump(`>=`, short=true) + of opJmpIfGeX : performConditionalJump(`>=`) + of opJmpIfLt : performConditionalJump(`<`, short=true) + of opJmpIfLtX : performConditionalJump(`<`) + of opJmpIfLe : performConditionalJump(`<=`, short=true) + of opJmpIfLeX : performConditionalJump(`<=`) # flow control of opGoto : + i += 1 + i += int(it[i]) + + of opGotoX : i += 2 i += int(uint16(it[i-1]) shl 8 + byte(it[i])) of opGoup : + i += 1 + i -= int(it[i]) + + of opGoupX : i += 2 i -= int(uint16(it[i-1]) shl 8 + byte(it[i])) From 9ba2937c81eafb233d8513c001bf679aab92aa7b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:04:33 +0100 Subject: [PATCH 733/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 837a26e30b..c9d0e91166 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3933 \ No newline at end of file +3934 \ No newline at end of file From e23e2c2e84d981ea8e651cc81b533a5ea6ba734e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:05:13 +0100 Subject: [PATCH 734/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c9d0e91166..f2f9306722 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3934 \ No newline at end of file +3935 \ No newline at end of file From 4ea7e9d2353367e4ae6c9fc5bae345b8a3313d51 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:07:17 +0100 Subject: [PATCH 735/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f2f9306722..24f886dffe 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3935 \ No newline at end of file +3936 \ No newline at end of file From c5412775edd614b9b3c35270012bffa480940f0e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:11:22 +0100 Subject: [PATCH 736/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 24f886dffe..18a8117623 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3936 \ No newline at end of file +3937 \ No newline at end of file From f4badc1c6c9a14270dea21df4992bf5286fcb928 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:18:34 +0100 Subject: [PATCH 737/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 18a8117623..49946708ba 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3937 \ No newline at end of file +3938 \ No newline at end of file From a9556e152def887ea536127e3158b8fc38da07fd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:18:53 +0100 Subject: [PATCH 738/984] VM/ast: make `TerminalNode` & `CallNode` public --- src/vm/ast.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index d24b20bb42..79f356ac20 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -108,8 +108,8 @@ var const NoStartingLine = 1896618966'u32 - TerminalNode : set[NodeKind] = {ConstantValue, VariableLoad} - CallNode : set[NodeKind] = {AttributeNode..SpecialCall} + TerminalNode* : set[NodeKind] = {ConstantValue, VariableLoad} + CallNode* : set[NodeKind] = {AttributeNode..SpecialCall} #======================================= # Forward declarations From e9f53819903b9edc8eb1e3227b86f1b4664036cc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:19:26 +0100 Subject: [PATCH 739/984] VM/eval: proper(?) implementation of `optimizeIf` + thorough cleanup & documentation --- src/vm/eval.nim | 95 +++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 7a05ec7c74..66de655680 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -72,18 +72,16 @@ template addOpWithNumber(instructions: var VBinary, oper: OpCode, num: untyped, byte(num) ]) -template injectOpWithIndex(instructions: var VBinary, oper: OpCode, num: untyped, at: int): untyped = +template addReplaceOpWithIndex(instructions: var VBinary, oper: OpCode, num: untyped): untyped = if num > 255: - instructions.insert([ - byte(oper)+1, + instructions[^1] = byte(oper)+1 + instructions.addByte([ byte(num shr 8), byte(num) - ], at) + ]) else: - instructions.insert([ - byte(oper), - byte(num) - ], at) + instructions[^1] = byte(oper) + instructions.addByte(byte(num)) proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode, hasShortcut: static bool=true) {.inline,enforceNoRaises.} = var indx = consts.indexOfValue(v) @@ -95,24 +93,27 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O instructions.addOpWithNumber(op, indx, hasShortcut) -proc getOperand*(op: OpCode, inverted: static bool=false): OpCode = - case op: - of opEq: - when inverted: opJmpIfNe else: opJmpIfEq - of opNe: - when inverted: opJmpIfEq else: opJmpIfNe - of opLt: - when inverted: opJmpIfGe else: opJmpIfLt - of opLe: - when inverted: opJmpIfGt else: opJmpIfLe - of opGt: - when inverted: opJmpIfLe else: opJmpIfGt - of opGe: - when inverted: opJmpIfLt else: opJmpIfGe - of opNot: - when inverted: opJmpIf else: opJmpIfNot - else: - when inverted: opJmpIfNot else: opJmpIf +proc getOperand*(node: Node, inverted: static bool=false): OpCode = + if node.kind notin CallNode: + when inverted: opJmpIfNot else: opJmpIf + else: + case node.op: + of opEq: + when inverted: opJmpIfNe else: opJmpIfEq + of opNe: + when inverted: opJmpIfEq else: opJmpIfNe + of opLt: + when inverted: opJmpIfGe else: opJmpIfLt + of opLe: + when inverted: opJmpIfGt else: opJmpIfLe + of opGt: + when inverted: opJmpIfLe else: opJmpIfGt + of opGe: + when inverted: opJmpIfLt else: opJmpIfGe + of opNot: + when inverted: opJmpIf else: opJmpIfNot + else: + when inverted: opJmpIfNot else: opJmpIf #======================================= # Methods @@ -135,6 +136,35 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti template addEol(n: untyped): untyped = it.addOpWithNumber(opEol, n, hasShortcut=false) + #------------------------ + # Optimization + #------------------------ + + template optimizeIf(special: untyped): untyped = + # let's keep some references + # to the children + let left {.cursor.} = special.children[0] + let right {.cursor.} = special.children[1] + + # inline-evaluate left child + evaluateBlock(Node(kind:RootNode, children: @[left]), consts, it) + + # separately ast+evaluate right child block + var rightIt: VBinary = @[] + evaluateBlock(generateAst(right.value), consts, rightIt) + + # get operand & added to the instructions + let newOp = getOperand(left, inverted=true) + + # add operand to our instructions + if newOp in {opJmpIf, opJmpIfNot}: + it.addOpWithNumber(newOp, rightIt.len, hasShortcut=false) + else: + it.addReplaceOpWithIndex(newOp, rightIt.len) + + # finally add the evaluated right block + it.add(rightIt) + #------------------------ # MainLoop #------------------------ @@ -147,18 +177,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti if item.kind == SpecialCall: case item.op: - of opIf: - evaluateBlock(Node(kind:RootNode, children: @[item.children[0]]), consts, it) - var blockIt: VBinary = @[] - echo "processing block" - evaluateBlock(generateAst(item.children[1].value), consts, blockIt) - echo "got block of len: " & $blockIt.len - it.injectOpWithIndex(getOperand(item.children[0].op, inverted=true), blockIt.len, it.len-1) - # it.addOpWithNumber(getOperand(item.children[0].op, inverted=true), blockIt.len, hasShortcut=false) - it.add(blockIt) - echo dumpNode(item.children[0]) - echo dumpNode(item.children[1]) - discard + of opIf: optimizeIf(item) of opIfE: discard of opUnless: From 4c12522e25d10b83aa0bf2e13cd83c5f582e9f03 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:28:04 +0100 Subject: [PATCH 740/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 49946708ba..9891434860 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3938 \ No newline at end of file +3939 \ No newline at end of file From 4f7f78f51feeee96a7f2302bf3375891c7fea209 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:29:16 +0100 Subject: [PATCH 741/984] VM/ast: remove `optimizeUnless` altogether (this will be done directly in the evaluator) --- src/vm/ast.nim | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 79f356ac20..f861613a53 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -325,35 +325,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No right.kind == ConstantValue and right.value.kind in {Integer,Floating}: target.replaceNode(newConstant(op(left.value,right.value))) - proc optimizeUnless(target: var Node) {.enforceNoRaises.} = - target.op = - if target.op == opUnless: - opIf - else: - opIfE - - var left = target.children[0] - - case left.op: - of opEq : left.op = opNe - of opNe : left.op = opEq - of opLt : left.op = opGe - of opLe : left.op = opGt - of opGt : left.op = opLe - of opGe : left.op = opLt - of opNot : - let newNode = left.children[0] - newNode.parent = target - target.children[0] = newNode - else: - let newNode = newCallNode(BuiltinCall, 1, nil, opNot) - newNode.children = @[left] - target.children[0] = newNode - for child in newNode.children: - child.parent = newNode - - newNode.parent = target - proc optimizeAppend(target: var Node) {.enforceNoRaises.} = var left = target.children[0] var right = target.children[1] @@ -410,8 +381,6 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No of opFDiv : target.optimizeArithmeticOp(`//`) of opMod : target.optimizeArithmeticOp(`%`) of opPow : target.optimizeArithmeticOp(`^`) - of opUnless, - opUnlessE : target.optimizeUnless() of opAppend : target.optimizeAppend() of opTo : target.optimizeTo() From f867605008ba591e3893b0bd8fe59b6178c8002d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:29:39 +0100 Subject: [PATCH 742/984] VM/eval: [optimizeIf] re-cleanup & made more generic --- src/vm/eval.nim | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 66de655680..163210d98c 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -115,6 +115,35 @@ proc getOperand*(node: Node, inverted: static bool=false): OpCode = else: when inverted: opJmpIfNot else: opJmpIf +#------------------------ +# Optimization +#------------------------ + +template optimizeIf(consts: var ValueArray, it: var VBinary, special: untyped): untyped = + # let's keep some references + # to the children + let left {.cursor.} = special.children[0] + let right {.cursor.} = special.children[1] + + # inline-evaluate left child + evaluateBlock(Node(kind:RootNode, children: @[left]), consts, it) + + # separately ast+evaluate right child block + var rightIt: VBinary = @[] + evaluateBlock(generateAst(right.value), consts, rightIt) + + # get operand & added to the instructions + let newOp = getOperand(left, inverted=true) + + # add operand to our instructions + if newOp in {opJmpIf, opJmpIfNot}: + it.addOpWithNumber(newOp, rightIt.len, hasShortcut=false) + else: + it.addReplaceOpWithIndex(newOp, rightIt.len) + + # finally add the evaluated right block + it.add(rightIt) + #======================================= # Methods #======================================= @@ -136,35 +165,6 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti template addEol(n: untyped): untyped = it.addOpWithNumber(opEol, n, hasShortcut=false) - #------------------------ - # Optimization - #------------------------ - - template optimizeIf(special: untyped): untyped = - # let's keep some references - # to the children - let left {.cursor.} = special.children[0] - let right {.cursor.} = special.children[1] - - # inline-evaluate left child - evaluateBlock(Node(kind:RootNode, children: @[left]), consts, it) - - # separately ast+evaluate right child block - var rightIt: VBinary = @[] - evaluateBlock(generateAst(right.value), consts, rightIt) - - # get operand & added to the instructions - let newOp = getOperand(left, inverted=true) - - # add operand to our instructions - if newOp in {opJmpIf, opJmpIfNot}: - it.addOpWithNumber(newOp, rightIt.len, hasShortcut=false) - else: - it.addReplaceOpWithIndex(newOp, rightIt.len) - - # finally add the evaluated right block - it.add(rightIt) - #------------------------ # MainLoop #------------------------ @@ -177,7 +177,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti if item.kind == SpecialCall: case item.op: - of opIf: optimizeIf(item) + of opIf: optimizeIf(consts, it, item) of opIfE: discard of opUnless: From 48edcfcf49df9c76bb8081266923f7c6e23698a8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:33:28 +0100 Subject: [PATCH 743/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9891434860..95699b93d6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3939 \ No newline at end of file +3940 \ No newline at end of file From 3d9cfef38aaa66cb126530717baaf4ecca750450 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:35:18 +0100 Subject: [PATCH 744/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 95699b93d6..c7f088924c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3940 \ No newline at end of file +3941 \ No newline at end of file From bd832cfb3918de8c9e408b127ba253a2650bade9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:37:54 +0100 Subject: [PATCH 745/984] VM/eval: added proper optimized implementation for `unless` --- src/vm/eval.nim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 163210d98c..39bde28347 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -119,7 +119,7 @@ proc getOperand*(node: Node, inverted: static bool=false): OpCode = # Optimization #------------------------ -template optimizeIf(consts: var ValueArray, it: var VBinary, special: untyped): untyped = +template optimizeIf(consts: var ValueArray, it: var VBinary, special: untyped, withInversion=false): untyped = # let's keep some references # to the children let left {.cursor.} = special.children[0] @@ -133,7 +133,7 @@ template optimizeIf(consts: var ValueArray, it: var VBinary, special: untyped): evaluateBlock(generateAst(right.value), consts, rightIt) # get operand & added to the instructions - let newOp = getOperand(left, inverted=true) + let newOp = getOperand(left, inverted=withInversion) # add operand to our instructions if newOp in {opJmpIf, opJmpIfNot}: @@ -177,11 +177,10 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti if item.kind == SpecialCall: case item.op: - of opIf: optimizeIf(consts, it, item) + of opIf: optimizeIf(consts, it, item, withInversion=true) of opIfE: discard - of opUnless: - discard + of opUnless: optimizeIf(consts, it, item) of opUnlessE: discard of opElse: From e70212cf7bbdbdc4a59450917eae6c397e0a64d4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:38:26 +0100 Subject: [PATCH 746/984] removed unused import --- src/vm/eval.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 39bde28347..c5290cd9a2 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -19,7 +19,7 @@ # Libraries #======================================= -import hashes, sequtils, tables +import hashes, tables import vm/[ast, bytecode, values/value] import vm/values/custom/[vbinary, vlogical] From 5fe705330729af118237c90e17c6714c81cb4895 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:40:06 +0100 Subject: [PATCH 747/984] VM/eval: still process SpecialCall nodes in main loop (e.g. a stray `else` with `try?`, or...) --- src/vm/eval.nim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index c5290cd9a2..dc00906a33 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -265,11 +265,8 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti addConst(instruction.value, opCall) of BuiltinCall: addSingleCommand(instruction.op) - else: - discard - # of SpecialCall: - - # addSingleCommand(instruction.op) + of SpecialCall: + addSingleCommand(instruction.op) i += 1 From 37c524c299f187688829465d7032c8639527aecc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Mon, 23 Jan 2023 18:40:55 +0100 Subject: [PATCH 748/984] VM/eval: minor cleanup (removed redundant debugging comments) --- src/vm/eval.nim | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index dc00906a33..85ef46c252 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -172,9 +172,6 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti while i < nLen: let item = blok.children[i] - # echo "current item:" - # echo dumpNode(item) - if item.kind == SpecialCall: case item.op: of opIf: optimizeIf(consts, it, item, withInversion=true) @@ -194,8 +191,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti else: for instruction in traverse(item): - # echo "processing: " - # echo dumpNode(instruction) + case instruction.kind: of RootNode: discard From 9a910a760757372e53c7a265bea0896ef7874f87 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 10:44:37 +0100 Subject: [PATCH 749/984] VM/eval: add `alreadyProcessed` to check for optimization success; otherwise, process as usual... --- src/vm/eval.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 85ef46c252..44b8c40468 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -172,6 +172,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti while i < nLen: let item = blok.children[i] + var alreadyProcessed = false if item.kind == SpecialCall: case item.op: of opIf: optimizeIf(consts, it, item, withInversion=true) @@ -188,7 +189,8 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti discard else: discard # won't reach here - else: + + if not alreadyProcessed: for instruction in traverse(item): From 8f303e383bd2269422efd9adebf335d544b2bd9f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 10:44:44 +0100 Subject: [PATCH 750/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c7f088924c..c31d89744a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3941 \ No newline at end of file +3942 \ No newline at end of file From b7ddd0fa6a684d7e230181e89199bc875a7109b3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 10:49:07 +0100 Subject: [PATCH 751/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c31d89744a..7e89ed76d2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3942 \ No newline at end of file +3943 \ No newline at end of file From ca243adf4d450fd79d9c1caa61688c5ecc739154 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:14:13 +0100 Subject: [PATCH 752/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7e89ed76d2..0627db260f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3943 \ No newline at end of file +3944 \ No newline at end of file From 5b9d0c2a9afb2d3061d6a59f7d345a170c0f592f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:16:14 +0100 Subject: [PATCH 753/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0627db260f..9f617ef5c2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3944 \ No newline at end of file +3945 \ No newline at end of file From 78b010c90dd96210b69735bcfbacb5691214785b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:21:56 +0100 Subject: [PATCH 754/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9f617ef5c2..4749c078ca 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3945 \ No newline at end of file +3946 \ No newline at end of file From 39c17252634b40ee0e1cd0f4f875e4af11673822 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:23:25 +0100 Subject: [PATCH 755/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4749c078ca..f55c68bf93 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3946 \ No newline at end of file +3947 \ No newline at end of file From c15f04ef25ea461ce26cf46c51655589c66beaef Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:34:06 +0100 Subject: [PATCH 756/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f55c68bf93..20f796e479 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3947 \ No newline at end of file +3948 \ No newline at end of file From bb5bad9e6ebecd6e375a5b20e1fd6e93d7138e0f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:34:48 +0100 Subject: [PATCH 757/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 20f796e479..c89735c129 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3948 \ No newline at end of file +3949 \ No newline at end of file From 661019cafaf667e284ceadb71da1ccef70fd9c34 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:36:14 +0100 Subject: [PATCH 758/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c89735c129..14dd80ffb2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3949 \ No newline at end of file +3950 \ No newline at end of file From 340229cac8245e773b741a759015cac9ba7d60a4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:37:33 +0100 Subject: [PATCH 759/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 14dd80ffb2..c168b444f3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3950 \ No newline at end of file +3951 \ No newline at end of file From f1ef90ccf090637550558412daf9105cac66771c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:38:41 +0100 Subject: [PATCH 760/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c168b444f3..cf349a0d32 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3951 \ No newline at end of file +3952 \ No newline at end of file From a10c0ff1beeb5b536e4f11ea659e799952b14d53 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:38:51 +0100 Subject: [PATCH 761/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cf349a0d32..3fa7348d55 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3952 \ No newline at end of file +3953 \ No newline at end of file From 16a321882154622cc5f0396a60da250e2149d093 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:40:17 +0100 Subject: [PATCH 762/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3fa7348d55..fff7924e94 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3953 \ No newline at end of file +3954 \ No newline at end of file From 450a1d6e112b7e7ced46fe1506a5eb8db467336e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:41:42 +0100 Subject: [PATCH 763/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index fff7924e94..4d33ca3528 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3954 \ No newline at end of file +3955 \ No newline at end of file From 0695a689edaf8cdc86d71ca401bce7edc756d400 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:43:21 +0100 Subject: [PATCH 764/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4d33ca3528..e33cd74857 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3955 \ No newline at end of file +3956 \ No newline at end of file From 175f69bd4510bc5c7fa243369eb01863daf4b1ab Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:44:55 +0100 Subject: [PATCH 765/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e33cd74857..6a868ccae9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3956 \ No newline at end of file +3957 \ No newline at end of file From bc1688174c14c5d2757fefdbf185b4beee1ae42c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:46:27 +0100 Subject: [PATCH 766/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6a868ccae9..3261fd5703 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3957 \ No newline at end of file +3958 \ No newline at end of file From 10b8dafc1a1c30d761936851589aae6c496baf65 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:48:10 +0100 Subject: [PATCH 767/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3261fd5703..35076e0b2e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3958 \ No newline at end of file +3959 \ No newline at end of file From 49acea3220f4953bc7cc3ad466a044459d314af3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:49:53 +0100 Subject: [PATCH 768/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 35076e0b2e..987219fa86 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3959 \ No newline at end of file +3960 \ No newline at end of file From 63c253ba6bcdb2e3c7060e27d117e7dc4d208a79 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:52:53 +0100 Subject: [PATCH 769/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 987219fa86..88733aa08b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3960 \ No newline at end of file +3961 \ No newline at end of file From 87692edd3bf594fcb19fce84f9e9f60134b21a76 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 11:58:39 +0100 Subject: [PATCH 770/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 88733aa08b..e96a63ca99 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3961 \ No newline at end of file +3962 \ No newline at end of file From 5fc6f480fc71d7d852aad3cf1817df9cf6bb3a77 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:04:34 +0100 Subject: [PATCH 771/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index e96a63ca99..bcd90f9cae 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3962 \ No newline at end of file +3963 \ No newline at end of file From 7071ce9d6b42b512f955e9a33603ce4491022517 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:05:35 +0100 Subject: [PATCH 772/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index bcd90f9cae..8a28e9fa07 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3963 \ No newline at end of file +3964 \ No newline at end of file From b22ff760a50809949e839643a093f083cddeaa6d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:06:20 +0100 Subject: [PATCH 773/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8a28e9fa07..1942b6823e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3964 \ No newline at end of file +3965 \ No newline at end of file From 91aefecea1882a98ab6203e7f21935c65b1f17bf Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:08:28 +0100 Subject: [PATCH 774/984] VM/eval: renamed `optimizeIf` to `optimizeConditional`, added `getNextNonNewlineNode` helper & added optimization for `if?/else` and `unless?/else` --- src/vm/eval.nim | 109 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 22 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 44b8c40468..a34e387539 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -83,6 +83,21 @@ template addReplaceOpWithIndex(instructions: var VBinary, oper: OpCode, num: unt instructions[^1] = byte(oper) instructions.addByte(byte(num)) +proc getNextNonNewlineNode(blok: Node, i: var int, nLen: int): Node = + result = nil + if i + 1 >= nlen: return + result = blok.children[i+1] + + var j = i+1 + while result.kind == NewlineNode and j + 1 < nLen: + j += 1 + result = blok.children[j] + + if result.kind == NewlineNode: + result = nil + else: + i = j + proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode, hasShortcut: static bool=true) {.inline,enforceNoRaises.} = var indx = consts.indexOfValue(v) if indx == -1: @@ -119,30 +134,81 @@ proc getOperand*(node: Node, inverted: static bool=false): OpCode = # Optimization #------------------------ -template optimizeIf(consts: var ValueArray, it: var VBinary, special: untyped, withInversion=false): untyped = +template optimizeConditional( + consts: var ValueArray, + it: var VBinary, + special: untyped, + withPotentialElse=false, + withInversion=false +): untyped = # let's keep some references # to the children let left {.cursor.} = special.children[0] let right {.cursor.} = special.children[1] - # inline-evaluate left child - evaluateBlock(Node(kind:RootNode, children: @[left]), consts, it) + # can we optimize? + var canWeOptimize = false - # separately ast+evaluate right child block - var rightIt: VBinary = @[] - evaluateBlock(generateAst(right.value), consts, rightIt) + when withPotentialElse: + var elseChild {.cursor.}: Node - # get operand & added to the instructions - let newOp = getOperand(left, inverted=withInversion) + let previousI = i + var elseNode = getNextNonNewlineNode(blok, i, nLen) - # add operand to our instructions - if newOp in {opJmpIf, opJmpIfNot}: - it.addOpWithNumber(newOp, rightIt.len, hasShortcut=false) + if (not elseNode.isNil) and elseNode.kind == SpecialCall and elseNode.op == opElse: + elseChild = elseNode.children[0] + canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and + elseChild.kind == ConstantValue and elseChild.value.kind == Block + else: + i = previousI else: - it.addReplaceOpWithIndex(newOp, rightIt.len) + canWeOptimize = right.kind == ConstantValue and right.value.kind == Block + + if canWeOptimize: + # inline-evaluate left child + evaluateBlock(Node(kind:RootNode, children: @[left]), consts, it) + + # separately ast+evaluate right child block + var rightIt: VBinary = @[] + evaluateBlock(generateAst(right.value), consts, rightIt) + + when withPotentialElse: + # separately ast+evaluate else child block + var elseIt: VBinary + evaluateBlock(generateAst(elseChild.value), consts, elseIt) + + # get operand & added to the instructions + let newOp = getOperand(left, inverted=withInversion) + + # get jump distance + let jumpDistance = + when withPotentialElse: + if elseIt.len > 255: + rightIt.len + 3 + else: + rightIt.len + 2 + else: + rightIt.len + + # add operand to our instructions + if newOp in {opJmpIf, opJmpIfNot}: + it.addOpWithNumber(newOp, jumpDistance, hasShortcut=false) + else: + it.addReplaceOpWithIndex(newOp, jumpDistance) + + # add the evaluated right block + it.add(rightIt) + + # finally add some potential else block + # preceded by an appropriate jump around it + when withPotentialElse: + it.addOpWithNumber(opGoto, elseIt.len, hasShortcut=false) - # finally add the evaluated right block - it.add(rightIt) + # add the else block + it.add(elseIt) + + # processing finished + alreadyProcessed = true #======================================= # Methods @@ -150,7 +216,7 @@ template optimizeIf(consts: var ValueArray, it: var VBinary, special: untyped, w proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDictionary=false) = let nLen = blok.children.len - var i {.register.} = 0 + var i = 0 #------------------------ # Shortcuts @@ -173,14 +239,13 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti let item = blok.children[i] var alreadyProcessed = false + if item.kind == SpecialCall: case item.op: - of opIf: optimizeIf(consts, it, item, withInversion=true) - of opIfE: - discard - of opUnless: optimizeIf(consts, it, item) - of opUnlessE: - discard + of opIf: optimizeConditional(consts, it, item, withInversion=true) + of opIfE: optimizeConditional(consts, it, item, withPotentialElse=true, withInversion=true) + of opUnless: optimizeConditional(consts, it, item) + of opUnlessE: optimizeConditional(consts, it, item, withPotentialElse=true) of opElse: discard of opSwitch: @@ -189,7 +254,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti discard else: discard # won't reach here - + if not alreadyProcessed: for instruction in traverse(item): From 58b7f3adedb76b2d70692a9a3eda700b837677ca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:11:15 +0100 Subject: [PATCH 775/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1942b6823e..3b314baa14 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3965 \ No newline at end of file +3966 \ No newline at end of file From 1c8cc493ddf11cd2dce8b356a22c8b95c0abecff Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:11:39 +0100 Subject: [PATCH 776/984] VM/values/printable: [dump] better output for Bytecode values --- src/vm/values/printable.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index 78a47bc126..46e0fd2a6d 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -420,7 +420,7 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen stdout.write instrs[i].s i += 1 if i < instrs.len and instrs[i].kind==Integer: - stdout.write " " + stdout.write " ".repeat(30 - instrs[i].s.len) while i < instrs.len and instrs[i].kind==Integer: if not muted: stdout.write fmt("{resetColor}{fg(grayColor)} #{instrs[i].i}{resetColor}") else: stdout.write " #" & $(instrs[i].i) From dab16e38f8c9e8f955baf72a3f517d0f844173a0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:13:23 +0100 Subject: [PATCH 777/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3b314baa14..125f3180af 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3966 \ No newline at end of file +3967 \ No newline at end of file From 893da82e2b10d87b0fcd622daeacedf30a0c8aaf Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:13:29 +0100 Subject: [PATCH 778/984] minor fix --- src/vm/values/printable.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index 46e0fd2a6d..5b6d187f83 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -420,7 +420,7 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen stdout.write instrs[i].s i += 1 if i < instrs.len and instrs[i].kind==Integer: - stdout.write " ".repeat(30 - instrs[i].s.len) + stdout.write " ".repeat(30 - instrs[i-1].s.len) while i < instrs.len and instrs[i].kind==Integer: if not muted: stdout.write fmt("{resetColor}{fg(grayColor)} #{instrs[i].i}{resetColor}") else: stdout.write " #" & $(instrs[i].i) From 857dfc67c4a67bfff8e77c6d8106f50d65c27213 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:15:39 +0100 Subject: [PATCH 779/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 125f3180af..ed52c36909 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3967 \ No newline at end of file +3968 \ No newline at end of file From 033d597a2ef701cc486253c89b400a644c193847 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:15:49 +0100 Subject: [PATCH 780/984] set less padding --- src/vm/values/printable.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index 5b6d187f83..6108fe8baf 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -420,7 +420,7 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen stdout.write instrs[i].s i += 1 if i < instrs.len and instrs[i].kind==Integer: - stdout.write " ".repeat(30 - instrs[i-1].s.len) + stdout.write " ".repeat(20 - instrs[i-1].s.len) while i < instrs.len and instrs[i].kind==Integer: if not muted: stdout.write fmt("{resetColor}{fg(grayColor)} #{instrs[i].i}{resetColor}") else: stdout.write " #" & $(instrs[i].i) From 308a410ca77d4b81ecf549b0da5f8c7a03319736 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:20:29 +0100 Subject: [PATCH 781/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ed52c36909..82db0992d2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3968 \ No newline at end of file +3969 \ No newline at end of file From 1584e1ed98497331dfd2a74d229a9bc760b48f3c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:21:20 +0100 Subject: [PATCH 782/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 82db0992d2..57470892e6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3969 \ No newline at end of file +3970 \ No newline at end of file From 38176ecc2606570d3600d7418d2c09799cc7de19 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:21:27 +0100 Subject: [PATCH 783/984] minor edit --- src/vm/values/printable.nim | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/vm/values/printable.nim b/src/vm/values/printable.nim index 6108fe8baf..4c73d68db4 100644 --- a/src/vm/values/printable.nim +++ b/src/vm/values/printable.nim @@ -417,13 +417,19 @@ proc dump*(v: Value, level: int=0, isLast: bool=false, muted: bool=false, prepen var i = 0 while i < instrs.len: for i in 0..level: stdout.write " " - stdout.write instrs[i].s + let preop = instrs[i].s + stdout.write preop i += 1 if i < instrs.len and instrs[i].kind==Integer: - stdout.write " ".repeat(20 - instrs[i-1].s.len) + stdout.write " ".repeat(20 - preop.len) while i < instrs.len and instrs[i].kind==Integer: - if not muted: stdout.write fmt("{resetColor}{fg(grayColor)} #{instrs[i].i}{resetColor}") - else: stdout.write " #" & $(instrs[i].i) + var numstr = $(instrs[i].i) + if preop.contains("jmp") or preop.contains("go"): + numstr = "@" & numstr + else: + numstr = "#" & numstr + if not muted: stdout.write fmt("{resetColor}{fg(grayColor)} {numstr}{resetColor}") + else: stdout.write numstr i += 1 stdout.write "\n" From 8c82fef214069c3a68c97cc93286f9982e59f091 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:34:00 +0100 Subject: [PATCH 784/984] VM/eval: added optimization for `switch` statements (supposedly lol) --- src/vm/eval.nim | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index a34e387539..a45e9bf7f0 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -139,6 +139,7 @@ template optimizeConditional( it: var VBinary, special: untyped, withPotentialElse=false, + isSwitch=false, withInversion=false ): untyped = # let's keep some references @@ -151,16 +152,20 @@ template optimizeConditional( when withPotentialElse: var elseChild {.cursor.}: Node - - let previousI = i - var elseNode = getNextNonNewlineNode(blok, i, nLen) - - if (not elseNode.isNil) and elseNode.kind == SpecialCall and elseNode.op == opElse: - elseChild = elseNode.children[0] + when isSwitch: + elseChild = special.children[2] canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and elseChild.kind == ConstantValue and elseChild.value.kind == Block else: - i = previousI + let previousI = i + let elseNode = getNextNonNewlineNode(blok, i, nLen) + + if (not elseNode.isNil) and elseNode.kind == SpecialCall and elseNode.op == opElse: + elseChild = elseNode.children[0] + canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and + elseChild.kind == ConstantValue and elseChild.value.kind == Block + else: + i = previousI else: canWeOptimize = right.kind == ConstantValue and right.value.kind == Block @@ -246,11 +251,14 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of opIfE: optimizeConditional(consts, it, item, withPotentialElse=true, withInversion=true) of opUnless: optimizeConditional(consts, it, item) of opUnlessE: optimizeConditional(consts, it, item, withPotentialElse=true) + of opSwitch: optimizeConditional(consts, it, item, withPotentialElse=true, isSwitch=true, withInversion=true) + of opWhile: discard of opElse: - discard - of opSwitch: - discard - of opWhile: + # `else` is not handled separately + # if it's a try?/else block for example, + # it's to be handled as a normal op below + # if it's an if?/else or unless?/else construct, + # it has already been above ^ discard else: discard # won't reach here From 5748304a929ab94fd0be33ff644d8dca252bad87 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:34:03 +0100 Subject: [PATCH 785/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 57470892e6..051c4c6a07 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3970 \ No newline at end of file +3971 \ No newline at end of file From 2dba40ff311f9e3b97e3c91332f69ad998a98a02 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:51:36 +0100 Subject: [PATCH 786/984] VM/ast: added `addSibling` helper function --- src/vm/ast.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index f861613a53..b0593f3258 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -149,6 +149,10 @@ proc replaceNode(node: Node, newNode: Node) = newNode.parent = node.parent node.parent.children[node.parent.children.find(node)] = newNode +proc addSibling(node: Node, newNode: Node) = + newNode.parent = node.parent + node.parent.children.insert(newNode, node.parent.children.find(node)+1) + #------------------------ # Iterators #------------------------ From 134a50ebaf11b99900ec679e0e4c67c1507fcf49 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:52:35 +0100 Subject: [PATCH 787/984] VM/eval: added TODO --- src/vm/eval.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index a45e9bf7f0..b074f60d59 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -337,6 +337,8 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of BuiltinCall: addSingleCommand(instruction.op) of SpecialCall: + # TODO(VM/eval) nested `switch` calls are not being optimized + # labels: vm, evaluator, performance, enhancement addSingleCommand(instruction.op) i += 1 From 6454258af967c4e9929971747db9dca760226f33 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:55:54 +0100 Subject: [PATCH 788/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 051c4c6a07..9af1c3da24 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3971 \ No newline at end of file +3972 \ No newline at end of file From c95f51ed779b5add620ccf604f43aa4dd76d5ead Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 12:56:11 +0100 Subject: [PATCH 789/984] clean children before actually optimizing conditional statements --- src/vm/eval.nim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index b074f60d59..aecc8667c1 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -19,7 +19,7 @@ # Libraries #======================================= -import hashes, tables +import hashes, sugar, tables import vm/[ast, bytecode, values/value] import vm/values/custom/[vbinary, vlogical] @@ -83,6 +83,12 @@ template addReplaceOpWithIndex(instructions: var VBinary, oper: OpCode, num: unt instructions[^1] = byte(oper) instructions.addByte(byte(num)) +proc cleanChildren(node: Node): seq[Node] = + result = collect: + for subnode in node.children: + if subnode.kind != NewlineNode: + subnode + proc getNextNonNewlineNode(blok: Node, i: var int, nLen: int): Node = result = nil if i + 1 >= nlen: return @@ -144,8 +150,9 @@ template optimizeConditional( ): untyped = # let's keep some references # to the children - let left {.cursor.} = special.children[0] - let right {.cursor.} = special.children[1] + let cleanedChildren = cleanChildren(special) + let left {.cursor.} = cleanedChildren[0] + let right {.cursor.} = cleanedChildren[1] # can we optimize? var canWeOptimize = false @@ -153,7 +160,7 @@ template optimizeConditional( when withPotentialElse: var elseChild {.cursor.}: Node when isSwitch: - elseChild = special.children[2] + elseChild = cleanedChildren[2] canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and elseChild.kind == ConstantValue and elseChild.value.kind == Block else: From 78babe46691e09008cd020d77258775981014122 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:28:10 +0100 Subject: [PATCH 790/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9af1c3da24..59aeaa5497 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3972 \ No newline at end of file +3973 \ No newline at end of file From 400fc5725b23a6feffe5bcbb9775f9ef27e4a3a6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:36:27 +0100 Subject: [PATCH 791/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 59aeaa5497..88a090bee3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3973 \ No newline at end of file +3974 \ No newline at end of file From dc1b02c8b8ca9a2d729aa362388ad841e5d7e9e0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:41:12 +0100 Subject: [PATCH 792/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 88a090bee3..a41daa1cfc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3974 \ No newline at end of file +3975 \ No newline at end of file From a4d49b89df471cf2e57a09fd9d3a4d1633d532f1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:43:06 +0100 Subject: [PATCH 793/984] VM/eval: added support for `while` optimization (kinda) + added `doesNotContainBranching` helpers --- src/vm/eval.nim | 124 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 35 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index aecc8667c1..2e84cdccc4 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -136,6 +136,27 @@ proc getOperand*(node: Node, inverted: static bool=false): OpCode = else: when inverted: opJmpIfNot else: opJmpIf +func doesNotContainBranching(blok: Value): bool {.enforceNoRaises.} = + for subvalue in blok.a: + if subvalue.kind == Word and subvalue.s in ["continue", "break"]: + return false + elif subvalue.kind == Block: + if not doesNotContainBranching(subvalue): + return false + return true + +func doesNotContainBranching(node: Node): bool {.enforceNoRaises.} = + for subnode in node.children: + if subnode.kind == BuiltinCall and subnode.op in {opContinue, opBreak}: + return false + elif subnode.kind == ConstantValue and subnode.value.kind == Block: + if not doesNotContainBranching(subnode.value): + return false + else: + if not doesNotContainBranching(subnode): + return false + return true + #------------------------ # Optimization #------------------------ @@ -144,6 +165,7 @@ template optimizeConditional( consts: var ValueArray, it: var VBinary, special: untyped, + withLoop=false, withPotentialElse=false, isSwitch=false, withInversion=false @@ -174,53 +196,85 @@ template optimizeConditional( else: i = previousI else: - canWeOptimize = right.kind == ConstantValue and right.value.kind == Block + when withLoop: + canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and + left.kind == ConstantValue and left.value.kind == Block + else: + canWeOptimize = right.kind == ConstantValue and right.value.kind == Block if canWeOptimize: - # inline-evaluate left child - evaluateBlock(Node(kind:RootNode, children: @[left]), consts, it) + let rightNode = generateAst(right.value) - # separately ast+evaluate right child block - var rightIt: VBinary = @[] - evaluateBlock(generateAst(right.value), consts, rightIt) + let stillProceed = + when withLoop: + doesNotContainBranching(rightNode) + else: + true + + if stillProceed: - when withPotentialElse: - # separately ast+evaluate else child block - var elseIt: VBinary - evaluateBlock(generateAst(elseChild.value), consts, elseIt) + when withLoop: + # separately ast+evaluate right child block + var leftIt: VBinary + let leftNode = generateAst(left.value) + evaluateBlock(leftNode, consts, leftIt) + it.add(leftIt) + else: + # inline-evaluate left child + evaluateBlock(Node(kind:RootNode, children: @[left]), consts, it) - # get operand & added to the instructions - let newOp = getOperand(left, inverted=withInversion) + # separately ast+evaluate right child block + var rightIt: VBinary + evaluateBlock(rightNode, consts, rightIt) - # get jump distance - let jumpDistance = when withPotentialElse: - if elseIt.len > 255: - rightIt.len + 3 + # separately ast+evaluate else child block + var elseIt: VBinary + evaluateBlock(generateAst(elseChild.value), consts, elseIt) + + # get operand & added to the instructions + let newOp = + when withLoop: + getOperand(leftNode, inverted=withInversion) else: - rightIt.len + 2 - else: - rightIt.len + getOperand(left, inverted=withInversion) + + # get jump distance + let jumpDistance = + when withPotentialElse: + if elseIt.len > 255: + rightIt.len + 3 + else: + rightIt.len + 2 + elif withLoop: + if (leftIt.len + rightIt.len) > 255: + rightIt.len + 3 + else: + rightIt.len + 2 + else: + rightIt.len - # add operand to our instructions - if newOp in {opJmpIf, opJmpIfNot}: - it.addOpWithNumber(newOp, jumpDistance, hasShortcut=false) - else: - it.addReplaceOpWithIndex(newOp, jumpDistance) + # add operand to our instructions + if newOp in {opJmpIf, opJmpIfNot}: + it.addOpWithNumber(newOp, jumpDistance, hasShortcut=false) + else: + it.addReplaceOpWithIndex(newOp, jumpDistance) - # add the evaluated right block - it.add(rightIt) + # add the evaluated right block + it.add(rightIt) - # finally add some potential else block - # preceded by an appropriate jump around it - when withPotentialElse: - it.addOpWithNumber(opGoto, elseIt.len, hasShortcut=false) + # finally add some potential else block + # preceded by an appropriate jump around it + when withPotentialElse: + it.addOpWithNumber(opGoto, elseIt.len, hasShortcut=false) - # add the else block - it.add(elseIt) + # add the else block + it.add(elseIt) + elif withLoop: + it.addOpWithNumber(opGoup, leftIt.len + rightIt.len, hasShortcut=false) - # processing finished - alreadyProcessed = true + # processing finished + alreadyProcessed = true #======================================= # Methods @@ -259,7 +313,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of opUnless: optimizeConditional(consts, it, item) of opUnlessE: optimizeConditional(consts, it, item, withPotentialElse=true) of opSwitch: optimizeConditional(consts, it, item, withPotentialElse=true, isSwitch=true, withInversion=true) - of opWhile: discard + of opWhile: optimizeConditional(consts, it, item, withLoop=true, withInversion=true) of opElse: # `else` is not handled separately # if it's a try?/else block for example, From 528638161a6d9c533d2bcadb4dfc2376bd47ecd0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:44:06 +0100 Subject: [PATCH 794/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a41daa1cfc..8285f5f822 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3975 \ No newline at end of file +3976 \ No newline at end of file From be996625b46d4d8bacb46aba00e5c5cdd8bcf440 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:45:01 +0100 Subject: [PATCH 795/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8285f5f822..aa78517f53 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3976 \ No newline at end of file +3977 \ No newline at end of file From c3a2f274fb13e2ee1b1289e49ed0fa7374343a86 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:46:41 +0100 Subject: [PATCH 796/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index aa78517f53..d666c534a9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3977 \ No newline at end of file +3978 \ No newline at end of file From e8e846ff643761200fd2f0b6d10d6d7fdb5075ab Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:49:48 +0100 Subject: [PATCH 797/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d666c534a9..284f470878 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3978 \ No newline at end of file +3979 \ No newline at end of file From 0fd0287f27f85cb658a0201297ffbda7c2e4a6b8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:51:38 +0100 Subject: [PATCH 798/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 284f470878..eb45f2dc7d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3979 \ No newline at end of file +3980 \ No newline at end of file From bb8e9c032b94677c11f5fdc56c9ea15a3277eb65 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:54:32 +0100 Subject: [PATCH 799/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index eb45f2dc7d..7d768230f7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3980 \ No newline at end of file +3981 \ No newline at end of file From ca1e79e9ec10f6ea32338de7df44d440202c3a5c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:56:47 +0100 Subject: [PATCH 800/984] minor fix --- src/vm/eval.nim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 2e84cdccc4..89bd9edd16 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -205,9 +205,13 @@ template optimizeConditional( if canWeOptimize: let rightNode = generateAst(right.value) + when withLoop: + var leftIt: VBinary + let leftNode = generateAst(left.value) + let stillProceed = when withLoop: - doesNotContainBranching(rightNode) + leftNode.children.len > 0 and doesNotContainBranching(rightNode) else: true @@ -215,8 +219,6 @@ template optimizeConditional( when withLoop: # separately ast+evaluate right child block - var leftIt: VBinary - let leftNode = generateAst(left.value) evaluateBlock(leftNode, consts, leftIt) it.add(leftIt) else: @@ -235,12 +237,12 @@ template optimizeConditional( # get operand & added to the instructions let newOp = when withLoop: - getOperand(leftNode, inverted=withInversion) + getOperand(leftNode.children[0], inverted=withInversion) else: getOperand(left, inverted=withInversion) # get jump distance - let jumpDistance = + var jumpDistance = when withPotentialElse: if elseIt.len > 255: rightIt.len + 3 @@ -259,6 +261,7 @@ template optimizeConditional( it.addOpWithNumber(newOp, jumpDistance, hasShortcut=false) else: it.addReplaceOpWithIndex(newOp, jumpDistance) + jumpDistance -= 1 # add the evaluated right block it.add(rightIt) @@ -271,7 +274,8 @@ template optimizeConditional( # add the else block it.add(elseIt) elif withLoop: - it.addOpWithNumber(opGoup, leftIt.len + rightIt.len, hasShortcut=false) + let upDistance = leftIt.len + jumpDistance + it.addOpWithNumber(opGoup, upDistance, hasShortcut=false) # processing finished alreadyProcessed = true From ba2452749ae7e652c4f68ef5940f2ba2c39e00f1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:57:14 +0100 Subject: [PATCH 801/984] make `opGoup` (& `opGoupX`) adjust the final destination based on their on byte-width --- src/vm/exec.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index 6e5f161df7..ad0ced309d 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -386,7 +386,7 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = op = OpCode(it[i]) - #echo "Executing: " & (stringify(op)) & " at " & $(i)# & " with next: " & $(it[i+1]) + echo "Executing: " & (stringify(op)) & " at " & $(i)# & " with next: " & $(it[i+1]) hookOpProfiler($(op)): @@ -729,11 +729,11 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = of opGoup : i += 1 - i -= int(it[i]) + i -= (int(it[i]) + 2) of opGoupX : i += 2 - i -= int(uint16(it[i-1]) shl 8 + byte(it[i])) + i -= (int(uint16(it[i-1]) shl 8 + byte(it[i])) + 3) of opRet : discard From 96e5cda6e7ea22a0ba9149d1aacbbdf2ff384f1e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:57:32 +0100 Subject: [PATCH 802/984] VM/exec: disable debugging output --- src/vm/exec.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index ad0ced309d..48273e6588 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -386,7 +386,7 @@ proc ExecLoop*(cnst: ValueArray, it: VBinary) = op = OpCode(it[i]) - echo "Executing: " & (stringify(op)) & " at " & $(i)# & " with next: " & $(it[i+1]) + #echo "Executing: " & (stringify(op)) & " at " & $(i)# & " with next: " & $(it[i+1]) hookOpProfiler($(op)): From 82f5ed5181f8e9bd6dacd10f621783ac0eed8df9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:57:37 +0100 Subject: [PATCH 803/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7d768230f7..ac82b7b7aa 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3981 \ No newline at end of file +3982 \ No newline at end of file From 9155d1a9faa0180a3149bc90875e866e58653b1b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:58:53 +0100 Subject: [PATCH 804/984] re-disable node/block debugging output --- src/vm/ast.nim | 2 +- src/vm/eval.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index b0593f3258..c78e3a9d17 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -834,4 +834,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - echo dumpNode(result) + #echo dumpNode(result) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 89bd9edd16..22caf1af15 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -432,7 +432,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = Translation(constants: consts, instructions: it) - dump(newBytecode(result)) + #dump(newBytecode(result)) when useStored: if vhash != -1: From 6fd76f0aef9398cec845531576ecfdf8b945aa92 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 13:58:58 +0100 Subject: [PATCH 805/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ac82b7b7aa..7e72ea4040 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3982 \ No newline at end of file +3983 \ No newline at end of file From 2c009007bb680746dd5ee259e9313fd1df49652a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:04:27 +0100 Subject: [PATCH 806/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 7e72ea4040..6d0180f697 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3983 \ No newline at end of file +3984 \ No newline at end of file From b5c16c9377c232949c2223fdf3d59db694048597 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:16:26 +0100 Subject: [PATCH 807/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6d0180f697..3103a8f925 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3984 \ No newline at end of file +3985 \ No newline at end of file From 6764afba91a5fcd914b339d706b29f948bc9bfdf Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:19:51 +0100 Subject: [PATCH 808/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 3103a8f925..ac858b83ed 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3985 \ No newline at end of file +3986 \ No newline at end of file From ae70e92a20f90beab22e05239a460cb107cc553f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:20:19 +0100 Subject: [PATCH 809/984] VM/eval: fixed handling of possible sibling `else` nodes --- src/vm/eval.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 22caf1af15..553752578f 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -190,7 +190,8 @@ template optimizeConditional( let elseNode = getNextNonNewlineNode(blok, i, nLen) if (not elseNode.isNil) and elseNode.kind == SpecialCall and elseNode.op == opElse: - elseChild = elseNode.children[0] + var j = 0 + elseChild = getNextNonNewlineNode(elseNode, j, elseNode.children.len) canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and elseChild.kind == ConstantValue and elseChild.value.kind == Block else: From 5046f4040f584e9f9e3bc848f79be0732db8389f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:22:27 +0100 Subject: [PATCH 810/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ac858b83ed..930397751e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3986 \ No newline at end of file +3987 \ No newline at end of file From f9b9a4497c0b7043d276cf6d17ed767f80f877de Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:29:18 +0100 Subject: [PATCH 811/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 930397751e..a3f41da965 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3987 \ No newline at end of file +3988 \ No newline at end of file From 3f020bda4b3e8e39ff3546c975272036eb1acaea Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:33:10 +0100 Subject: [PATCH 812/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a3f41da965..54dbf7b4a2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3988 \ No newline at end of file +3989 \ No newline at end of file From 737e4629bb354d56c75c3e1ae2152bf5df90a6a7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:34:45 +0100 Subject: [PATCH 813/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 54dbf7b4a2..1d58731009 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3989 \ No newline at end of file +3990 \ No newline at end of file From 9547019275005b0ad092ec5d769bd413894d8a4a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:35:35 +0100 Subject: [PATCH 814/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1d58731009..61e37f24b8 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3990 \ No newline at end of file +3991 \ No newline at end of file From bf3dd58c27ba77f776ffa3c77008c3259c86c825 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:42:22 +0100 Subject: [PATCH 815/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 61e37f24b8..ba17da677b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3991 \ No newline at end of file +3992 \ No newline at end of file From a161d642d240203f9af02435dd324bf1847f7381 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:42:30 +0100 Subject: [PATCH 816/984] disabled debugging --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index c78e3a9d17..b0593f3258 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -834,4 +834,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - #echo dumpNode(result) + echo dumpNode(result) From 21330731c343606c9386bf30f8b6ea5b917593d5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:42:47 +0100 Subject: [PATCH 817/984] make sure `else` is not nil + cleanup --- src/vm/eval.nim | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 553752578f..e59bf41488 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -180,7 +180,7 @@ template optimizeConditional( var canWeOptimize = false when withPotentialElse: - var elseChild {.cursor.}: Node + var elseChild: Node when isSwitch: elseChild = cleanedChildren[2] canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and @@ -190,10 +190,13 @@ template optimizeConditional( let elseNode = getNextNonNewlineNode(blok, i, nLen) if (not elseNode.isNil) and elseNode.kind == SpecialCall and elseNode.op == opElse: - var j = 0 + var j = -1 elseChild = getNextNonNewlineNode(elseNode, j, elseNode.children.len) - canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and - elseChild.kind == ConstantValue and elseChild.value.kind == Block + if not elseChild.isNil: + canWeOptimize = right.kind == ConstantValue and right.value.kind == Block and + elseChild.kind == ConstantValue and elseChild.value.kind == Block + else: + i = previousI else: i = previousI else: @@ -308,7 +311,8 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti while i < nLen: let item = blok.children[i] - + # echo "evaluating: " & $(item.kind) & " at " & $(i) + # echo dumpNode(item) var alreadyProcessed = false if item.kind == SpecialCall: From e9571fa9c103b4a47dd245003d4d7694637bd53e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:43:29 +0100 Subject: [PATCH 818/984] VM/ast: disable debugging (again!) --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index b0593f3258..c78e3a9d17 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -834,4 +834,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - echo dumpNode(result) + #echo dumpNode(result) From 82f9dd4a6995c6480cc0953598998dffb4bca6ad Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:43:33 +0100 Subject: [PATCH 819/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ba17da677b..d14e60bf79 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3992 \ No newline at end of file +3993 \ No newline at end of file From 1f890faf10b95a942840e045ced7ee0b31aba3db Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:47:09 +0100 Subject: [PATCH 820/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d14e60bf79..0dde0e7068 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3993 \ No newline at end of file +3994 \ No newline at end of file From 63f00667d3c88dc12c8216372e414b3743b667b1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 14:51:25 +0100 Subject: [PATCH 821/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0dde0e7068..68262ed08e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3994 \ No newline at end of file +3995 \ No newline at end of file From 2f6162fb5e79519a2a9d1bee5dc37c6c95dd3de9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:02:38 +0100 Subject: [PATCH 822/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 68262ed08e..a950d7c437 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3995 \ No newline at end of file +3996 \ No newline at end of file From 5156c67df691fa58b783ce6d660d041245e84d11 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:07:47 +0100 Subject: [PATCH 823/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a950d7c437..f1371d4392 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3996 \ No newline at end of file +3997 \ No newline at end of file From 29a8e8ffcdf2fb71d77de25c7cfc51cd52bd2d87 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:08:23 +0100 Subject: [PATCH 824/984] VM/eval: make `getOperand` also return replacement status (not all previous `op`s are to be replaced in-place) --- src/vm/eval.nim | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index e59bf41488..80f01d25cb 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -114,27 +114,27 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O instructions.addOpWithNumber(op, indx, hasShortcut) -proc getOperand*(node: Node, inverted: static bool=false): OpCode = +proc getOperand*(node: Node, inverted: static bool=false): (OpCode, bool) = if node.kind notin CallNode: - when inverted: opJmpIfNot else: opJmpIf + when inverted: (opJmpIfNot, false) else: (opJmpIf, false) else: case node.op: of opEq: - when inverted: opJmpIfNe else: opJmpIfEq + when inverted: (opJmpIfNe, true) else: (opJmpIfEq, true) of opNe: - when inverted: opJmpIfEq else: opJmpIfNe + when inverted: (opJmpIfEq, true) else: (opJmpIfNe, true) of opLt: - when inverted: opJmpIfGe else: opJmpIfLt + when inverted: (opJmpIfGe, true) else: (opJmpIfLt, true) of opLe: - when inverted: opJmpIfGt else: opJmpIfLe + when inverted: (opJmpIfGt, true) else: (opJmpIfLe, true) of opGt: - when inverted: opJmpIfLe else: opJmpIfGt + when inverted: (opJmpIfLe, true) else: (opJmpIfGt, true) of opGe: - when inverted: opJmpIfLt else: opJmpIfGe + when inverted: (opJmpIfLt, true) else: (opJmpIfGe, true) of opNot: - when inverted: opJmpIf else: opJmpIfNot + when inverted: (opJmpIf, true) else: (opJmpIfNot, true) else: - when inverted: opJmpIfNot else: opJmpIf + when inverted: (opJmpIfNot, false) else: (opJmpIf, false) func doesNotContainBranching(blok: Value): bool {.enforceNoRaises.} = for subvalue in blok.a: @@ -239,7 +239,7 @@ template optimizeConditional( evaluateBlock(generateAst(elseChild.value), consts, elseIt) # get operand & added to the instructions - let newOp = + let (newOp, replaceOp) = when withLoop: getOperand(leftNode.children[0], inverted=withInversion) else: @@ -261,11 +261,11 @@ template optimizeConditional( rightIt.len # add operand to our instructions - if newOp in {opJmpIf, opJmpIfNot}: - it.addOpWithNumber(newOp, jumpDistance, hasShortcut=false) - else: + if replaceOp: it.addReplaceOpWithIndex(newOp, jumpDistance) jumpDistance -= 1 + else: + it.addOpWithNumber(newOp, jumpDistance, hasShortcut=false) # add the evaluated right block it.add(rightIt) @@ -437,7 +437,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = Translation(constants: consts, instructions: it) - #dump(newBytecode(result)) + dump(newBytecode(result)) when useStored: if vhash != -1: From dd78dbaf9ee8594b7cafa28836ac69284591b383 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:08:33 +0100 Subject: [PATCH 825/984] +debugging --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index c78e3a9d17..b0593f3258 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -834,4 +834,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - #echo dumpNode(result) + echo dumpNode(result) From d90ff0620ea82dc7fb8176f589392787ff446898 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:09:29 +0100 Subject: [PATCH 826/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f1371d4392..4be98148b5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3997 \ No newline at end of file +3998 \ No newline at end of file From e1067a8713866a1b2bf9885b9aff262bce24748e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:09:52 +0100 Subject: [PATCH 827/984] -debugging --- src/vm/eval.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 80f01d25cb..8c47222db1 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -437,7 +437,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr result = Translation(constants: consts, instructions: it) - dump(newBytecode(result)) + #dump(newBytecode(result)) when useStored: if vhash != -1: From 537124c2d34c19f26a73997d4eecd3ab89cf1630 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:10:14 +0100 Subject: [PATCH 828/984] -debugging --- src/vm/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index b0593f3258..c78e3a9d17 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -834,4 +834,4 @@ proc generateAst*(parsed: Value, asDictionary=false): Node = discard result.processBlock(parsed, asDictionary=asDictionary) - echo dumpNode(result) + #echo dumpNode(result) From c69abd9ce9f02ea54d3466cbae081284f4de315e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:10:27 +0100 Subject: [PATCH 829/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4be98148b5..eea5906292 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3998 \ No newline at end of file +3999 \ No newline at end of file From 0880bc255c6df4aae20c16c833fabc13e8dc82c9 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:13:03 +0100 Subject: [PATCH 830/984] updated expected unit-test result --- tests/unittests/lib.collections.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/lib.collections.res b/tests/unittests/lib.collections.res index 2c54367b10..24f7c399d1 100644 --- a/tests/unittests/lib.collections.res +++ b/tests/unittests/lib.collections.res @@ -208,7 +208,7 @@ one :string FD E8 :binary E8 :binary [hello] :block -[32 189 211] :block +[32 189 218] :block 15 :integer January :string John :string From 5fdd9e16324b85c88354acb0873b580ef104ee3b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:14:06 +0100 Subject: [PATCH 831/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index eea5906292..a2113715a3 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -3999 \ No newline at end of file +4000 \ No newline at end of file From eb5af2d893a4dc6f3b0e48cd949b88ea8f6962d7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:20:44 +0100 Subject: [PATCH 832/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a2113715a3..d59954b6ab 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4000 \ No newline at end of file +4001 \ No newline at end of file From 7b668c075a67c370b8d7e235b0f3854bcaf44cf0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:22:35 +0100 Subject: [PATCH 833/984] VM/ast: [generateAst] add option to `reuseArities`, in case of subblock re-evaluation --- src/vm/ast.nim | 11 ++++++----- src/vm/eval.nim | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index c78e3a9d17..33128110ea 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -824,13 +824,14 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false, showNewlines: # Main #======================================= -proc generateAst*(parsed: Value, asDictionary=false): Node = +proc generateAst*(parsed: Value, asDictionary=false, reuseArities: static bool=false): Node = result = newRootNode() - TmpArities = collect: - for k,v in Syms.pairs: - if v.kind == Function: - {k: v.arity} + when not reuseArities: + TmpArities = collect: + for k,v in Syms.pairs: + if v.kind == Function: + {k: v.arity} discard result.processBlock(parsed, asDictionary=asDictionary) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 8c47222db1..cee639dc88 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -207,11 +207,11 @@ template optimizeConditional( canWeOptimize = right.kind == ConstantValue and right.value.kind == Block if canWeOptimize: - let rightNode = generateAst(right.value) + let rightNode = generateAst(right.value, reuseArities=true) when withLoop: var leftIt: VBinary - let leftNode = generateAst(left.value) + let leftNode = generateAst(left.value, reuseArities=true) let stillProceed = when withLoop: @@ -236,7 +236,7 @@ template optimizeConditional( when withPotentialElse: # separately ast+evaluate else child block var elseIt: VBinary - evaluateBlock(generateAst(elseChild.value), consts, elseIt) + evaluateBlock(generateAst(elseChild.value, reuseArities=true), consts, elseIt) # get operand & added to the instructions let (newOp, replaceOp) = @@ -322,7 +322,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of opUnless: optimizeConditional(consts, it, item) of opUnlessE: optimizeConditional(consts, it, item, withPotentialElse=true) of opSwitch: optimizeConditional(consts, it, item, withPotentialElse=true, isSwitch=true, withInversion=true) - of opWhile: optimizeConditional(consts, it, item, withLoop=true, withInversion=true) + of opWhile: discard#optimizeConditional(consts, it, item, withLoop=true, withInversion=true) of opElse: # `else` is not handled separately # if it's a try?/else block for example, From c02f32b64dc3458c690faa77a71d345d7d59a2ed Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:25:28 +0100 Subject: [PATCH 834/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d59954b6ab..4a5de23157 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4001 \ No newline at end of file +4002 \ No newline at end of file From de7ae256c5d14ec3c99148d6495c77d59ca1f1b3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:31:28 +0100 Subject: [PATCH 835/984] re-enable `while` optimizations --- src/vm/eval.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index cee639dc88..ceb66ee398 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -322,7 +322,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of opUnless: optimizeConditional(consts, it, item) of opUnlessE: optimizeConditional(consts, it, item, withPotentialElse=true) of opSwitch: optimizeConditional(consts, it, item, withPotentialElse=true, isSwitch=true, withInversion=true) - of opWhile: discard#optimizeConditional(consts, it, item, withLoop=true, withInversion=true) + of opWhile: optimizeConditional(consts, it, item, withLoop=true, withInversion=true) of opElse: # `else` is not handled separately # if it's a try?/else block for example, From 8366c6d432fc2493864c42e9b6b7cbad28885580 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:31:45 +0100 Subject: [PATCH 836/984] temporarily disable errors & unit-tests --- tools/tester.art | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tester.art b/tools/tester.art index 346e1f1fc0..9efa4012ff 100755 --- a/tools/tester.art +++ b/tools/tester.art @@ -115,8 +115,8 @@ print color #white.bold " Unit Tester\n" print color #gray ~" Release: @|sys\release|\n" supertime: in's benchmark.get [ - runSet "Unit Tests" "../tests/unittests" - runSet "Errors" "../tests/errors" + ; runSet "Unit Tests" "../tests/unittests" + ; runSet "Errors" "../tests/errors" runSet "Examples" "../examples/rosetta" ] From 659b653418f65dd15de52355e417dd6de2854aed Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:31:49 +0100 Subject: [PATCH 837/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4a5de23157..c09fb9112d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4002 \ No newline at end of file +4003 \ No newline at end of file From ad05c32b38738d1347ab03182a395618f74a821b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:36:57 +0100 Subject: [PATCH 838/984] VM/ast: removed unused import + cleanup + updated inlined TODOs --- src/vm/ast.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 33128110ea..eae35d42a6 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -15,7 +15,6 @@ ## ## The main entry point is ``generateAst``. - # TODO: # - [x] make Attribute's work # - [x] make AttributeLabel's work @@ -28,7 +27,7 @@ # - [x] optimize appends # - [x] make labels store new functions in TmpArities # - [x] make labels unstore overwritten functions in TmpArities -# - [ ] make if/if?/else/while/switch work +# - [x] make if/if?/else/while/switch work # - [x] correctly process to :string/:integer # - [ ] make sure all this left/right (when checking for optimization) are not Newline's @@ -36,7 +35,7 @@ # Libraries #======================================= -import hashes, sequtils, strutils +import sequtils, strutils import sugar, tables, unicode, std/with import vm/[globals, values/value, values/comparison, values/types] From dbefd2348dd3dabe3a362fd829636a5cfa7869f7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:37:09 +0100 Subject: [PATCH 839/984] VM/eval: cleanup + added TODO --- src/vm/eval.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index ceb66ee398..ab8cd99867 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -136,6 +136,9 @@ proc getOperand*(node: Node, inverted: static bool=false): (OpCode, bool) = else: when inverted: (opJmpIfNot, false) else: (opJmpIf, false) +# TODO(VM/eval) better `while` optimization? +# what if the user has actually re-defined `continue` or `break`? +# labels: vm, evaluator, enhancement func doesNotContainBranching(blok: Value): bool {.enforceNoRaises.} = for subvalue in blok.a: if subvalue.kind == Word and subvalue.s in ["continue", "break"]: @@ -311,8 +314,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti while i < nLen: let item = blok.children[i] - # echo "evaluating: " & $(item.kind) & " at " & $(i) - # echo dumpNode(item) + var alreadyProcessed = false if item.kind == SpecialCall: From 23fbe8b45a8d04c46554de3daea07be5b0cca19c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:42:42 +0100 Subject: [PATCH 840/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c09fb9112d..9c49c9a9c9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4003 \ No newline at end of file +4004 \ No newline at end of file From e3593268f24ba084301c3471b46908b93b200ba3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:44:43 +0100 Subject: [PATCH 841/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9c49c9a9c9..4896bf672f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4004 \ No newline at end of file +4005 \ No newline at end of file From 610f8da4ca69d097b9d18a187f7d531947098cfe Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:49:34 +0100 Subject: [PATCH 842/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4896bf672f..0864beb832 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4005 \ No newline at end of file +4006 \ No newline at end of file From 268dcb40549d2e8bc95126ecb6291446a5d41eb8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 16:57:26 +0100 Subject: [PATCH 843/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0864beb832..cf237193b9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4006 \ No newline at end of file +4007 \ No newline at end of file From 0fc46df68917ad724065334b158328198aabb9ad Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:05:44 +0100 Subject: [PATCH 844/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index cf237193b9..96f23f828b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4007 \ No newline at end of file +4008 \ No newline at end of file From 467fc2f50cacc69eba59bb6f3267ea02bc9a44dd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:09:44 +0100 Subject: [PATCH 845/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 96f23f828b..eb88884601 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4008 \ No newline at end of file +4009 \ No newline at end of file From dc1a53768fdfdb2301fb18d9cb55ea79a192f322 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:11:20 +0100 Subject: [PATCH 846/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index eb88884601..f9e0edcb3e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4009 \ No newline at end of file +4010 \ No newline at end of file From 80d19b08b4b9cb8d1ffcc1289f97b2b27d1126a2 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:21:37 +0100 Subject: [PATCH 847/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f9e0edcb3e..ab6dd9ed9e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4010 \ No newline at end of file +4011 \ No newline at end of file From f95132251443d69b420a4fa3c83e7d1e376dbb61 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:22:56 +0100 Subject: [PATCH 848/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ab6dd9ed9e..f3b265b92f 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4011 \ No newline at end of file +4012 \ No newline at end of file From b92ff6d186510029b1513375d1c32dd67f6115f8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:24:44 +0100 Subject: [PATCH 849/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f3b265b92f..d41aa5178c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4012 \ No newline at end of file +4013 \ No newline at end of file From ee4e40f59e8d0171c8953b3ba5470ae00aff2886 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:26:50 +0100 Subject: [PATCH 850/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d41aa5178c..4270c4292c 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4013 \ No newline at end of file +4014 \ No newline at end of file From 1af9c9b1b27daca8f2795f7994b0d6e0973021c1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:28:43 +0100 Subject: [PATCH 851/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4270c4292c..8ec5bf0403 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4014 \ No newline at end of file +4015 \ No newline at end of file From 6180e088c6d512c0dadcf06008abb877184e3bbe Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:33:48 +0100 Subject: [PATCH 852/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8ec5bf0403..4af4ec6bd2 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4015 \ No newline at end of file +4016 \ No newline at end of file From 07cd8bb481dd7ab2d3a2a30a3445a4f50dd8c129 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:36:13 +0100 Subject: [PATCH 853/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4af4ec6bd2..871d135b4a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4016 \ No newline at end of file +4017 \ No newline at end of file From b06618ca9bb64dd8a050bccab7c142a449e9810f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:41:13 +0100 Subject: [PATCH 854/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 871d135b4a..1dc0503028 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4017 \ No newline at end of file +4018 \ No newline at end of file From c16dd3c8471306fa4a1cc33ba519528222a347a5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:43:53 +0100 Subject: [PATCH 855/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1dc0503028..f31c1c7ec6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4018 \ No newline at end of file +4019 \ No newline at end of file From 7c9280886a4f8bb3b9a3df40b05de4478cbbe8e1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:49:09 +0100 Subject: [PATCH 856/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f31c1c7ec6..4af051ca98 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4019 \ No newline at end of file +4020 \ No newline at end of file From 3ace09672d87b20d87974d3199bcd568d9e6b69a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Tue, 24 Jan 2023 17:54:47 +0100 Subject: [PATCH 857/984] VM/eval: added `opStoreA + opLoadA => opStorlA` optimization --- src/vm/eval.nim | 50 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index ab8cd99867..e26ab643f7 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -114,6 +114,34 @@ proc addConst(consts: var ValueArray, instructions: var VBinary, v: Value, op: O instructions.addOpWithNumber(op, indx, hasShortcut) +proc addConstAndGetIndex(consts: var ValueArray, instructions: var VBinary, v: Value, op: OpCode, hasShortcut: static bool=true): int {.inline,enforceNoRaises.} = + result = consts.indexOfValue(v) + if result == -1: + let newv = v + newv.readonly = true + consts.add(newv) + result = consts.len-1 + + instructions.addOpWithNumber(op, result, hasShortcut) + +proc addVariableLoad(consts: var ValueArray, instructions: var VBinary, v: Value, previousStore: int, previousStorePos: int) {.inline,enforceNoRaises.} = + var indx = consts.indexOfValue(v) + if indx == -1: + let newv = v + newv.readonly = true + consts.add(newv) + indx = consts.len-1 + + if indx == previousStore: + if indx <= 13: + instructions[previousStorePos-1] = (byte(opStorl)-0x0E) + byte(indx) + elif indx <= 255: + instructions[previousStorePos-2] = byte(opStorl) + else: + instructions[previousStorePos-3] = byte(opStorlX) + else: + instructions.addOpWithNumber(opLoad, indx, hasShortcut=true) + proc getOperand*(node: Node, inverted: static bool=false): (OpCode, bool) = if node.kind notin CallNode: when inverted: (opJmpIfNot, false) else: (opJmpIf, false) @@ -295,6 +323,9 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti let nLen = blok.children.len var i = 0 + var lastOpStore = -1 + var lastOpStorePos = -1 + #------------------------ # Shortcuts #------------------------ @@ -302,6 +333,13 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti template addConst(v: Value, op: OpCode, hasShortcut: static bool=true): untyped = addConst(consts, it, v, op, hasShortcut) + template addConstAndGetIndex(v: Value, op: OpCode, hasShortcut: static bool=true): untyped = + addConstAndGetIndex(consts, it, v, op, hasShortcut) + + template addVariableLoad(v: Value): untyped = + addVariableLoad(consts, it, v, lastOpStore, lastOpStorePos) + lastOpStore = -1 + template addSingleCommand(op: untyped): untyped = it.addByte(op) @@ -318,6 +356,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti var alreadyProcessed = false if item.kind == SpecialCall: + lastOpStore = -1 case item.op: of opIf: optimizeConditional(consts, it, item, withInversion=true) of opIfE: optimizeConditional(consts, it, item, withPotentialElse=true, withInversion=true) @@ -345,6 +384,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of NewlineNode: addEol(instruction.line) of ConstantValue: + lastOpStore = -1 var alreadyPut = false let iv {.cursor.} = instruction.value case instruction.value.kind: @@ -396,19 +436,25 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti if not alreadyPut: addConst(instruction.value, opPush) of VariableLoad: - addConst(instruction.value, opLoad) + addVariableLoad(instruction.value) of AttributeNode: + lastOpStore = -1 addConst(instruction.value, opAttr) of VariableStore: if unlikely(isDictionary): + lastOpStore = -1 addConst(instruction.value, opDStore, hasShortcut=false) else: - addConst(instruction.value, opStore) + lastOpStore = addConstAndGetIndex(instruction.value, opStore) + lastOpStorePos = it.len of OtherCall: + lastOpStore = -1 addConst(instruction.value, opCall) of BuiltinCall: + lastOpStore = -1 addSingleCommand(instruction.op) of SpecialCall: + lastOpStore = -1 # TODO(VM/eval) nested `switch` calls are not being optimized # labels: vm, evaluator, performance, enhancement addSingleCommand(instruction.op) From 370b96ac6bf9d5bb4ee6858370242901b731d68c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 10:28:03 +0100 Subject: [PATCH 858/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4af051ca98..67c6baa317 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4020 \ No newline at end of file +4021 \ No newline at end of file From c338978280ea13af5c0e7b643bf8d096b48a2a6f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 10:29:16 +0100 Subject: [PATCH 859/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 67c6baa317..4323a87a27 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4021 \ No newline at end of file +4022 \ No newline at end of file From c928aebb0ea6403ab40e3d0fc36a5062c70e8fc0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 10:34:45 +0100 Subject: [PATCH 860/984] added proper `storl` optimizations even for variable references --- src/vm/eval.nim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index e26ab643f7..0c5ed527e0 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -124,7 +124,7 @@ proc addConstAndGetIndex(consts: var ValueArray, instructions: var VBinary, v: V instructions.addOpWithNumber(op, result, hasShortcut) -proc addVariableLoad(consts: var ValueArray, instructions: var VBinary, v: Value, previousStore: int, previousStorePos: int) {.inline,enforceNoRaises.} = +proc addVariableLoad(consts: var ValueArray, instructions: var VBinary, nd: Node, v: Value, previousStore: int, previousStorePos: int) {.inline,enforceNoRaises.} = var indx = consts.indexOfValue(v) if indx == -1: let newv = v @@ -132,7 +132,7 @@ proc addVariableLoad(consts: var ValueArray, instructions: var VBinary, v: Value consts.add(newv) indx = consts.len-1 - if indx == previousStore: + if indx == previousStore and nd.parent.kind != VariableStore: if indx <= 13: instructions[previousStorePos-1] = (byte(opStorl)-0x0E) + byte(indx) elif indx <= 255: @@ -336,8 +336,8 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti template addConstAndGetIndex(v: Value, op: OpCode, hasShortcut: static bool=true): untyped = addConstAndGetIndex(consts, it, v, op, hasShortcut) - template addVariableLoad(v: Value): untyped = - addVariableLoad(consts, it, v, lastOpStore, lastOpStorePos) + template addVariableLoad(nd: Node): untyped = + addVariableLoad(consts, it, nd, nd.value, lastOpStore, lastOpStorePos) lastOpStore = -1 template addSingleCommand(op: untyped): untyped = @@ -436,7 +436,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti if not alreadyPut: addConst(instruction.value, opPush) of VariableLoad: - addVariableLoad(instruction.value) + addVariableLoad(instruction) of AttributeNode: lastOpStore = -1 addConst(instruction.value, opAttr) From c542936685bac878cfc372274199593a1517e204 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 10:40:29 +0100 Subject: [PATCH 861/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 4323a87a27..050e0b7fb6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4022 \ No newline at end of file +4023 \ No newline at end of file From f7a8e21c0c7e0b0227d78a4f5991c59ff3b33e74 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 10:40:37 +0100 Subject: [PATCH 862/984] VM/eval: cleanup --- src/vm/eval.nim | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 0c5ed527e0..fc90c09578 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -331,6 +331,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti #------------------------ template addConst(v: Value, op: OpCode, hasShortcut: static bool=true): untyped = + lastOpStore = -1 addConst(consts, it, v, op, hasShortcut) template addConstAndGetIndex(v: Value, op: OpCode, hasShortcut: static bool=true): untyped = @@ -341,6 +342,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti lastOpStore = -1 template addSingleCommand(op: untyped): untyped = + lastOpStore = -1 it.addByte(op) template addEol(n: untyped): untyped = @@ -384,7 +386,6 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of NewlineNode: addEol(instruction.line) of ConstantValue: - lastOpStore = -1 var alreadyPut = false let iv {.cursor.} = instruction.value case instruction.value.kind: @@ -438,23 +439,18 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of VariableLoad: addVariableLoad(instruction) of AttributeNode: - lastOpStore = -1 addConst(instruction.value, opAttr) of VariableStore: if unlikely(isDictionary): - lastOpStore = -1 addConst(instruction.value, opDStore, hasShortcut=false) else: lastOpStore = addConstAndGetIndex(instruction.value, opStore) lastOpStorePos = it.len of OtherCall: - lastOpStore = -1 addConst(instruction.value, opCall) of BuiltinCall: - lastOpStore = -1 addSingleCommand(instruction.op) of SpecialCall: - lastOpStore = -1 # TODO(VM/eval) nested `switch` calls are not being optimized # labels: vm, evaluator, performance, enhancement addSingleCommand(instruction.op) From 77d301db744e21de00cdee668f3196a61ec93d73 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 10:50:04 +0100 Subject: [PATCH 863/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 050e0b7fb6..40d687f5af 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4023 \ No newline at end of file +4024 \ No newline at end of file From 3d275638dd06beb403da5bac995f154d159638f1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 10:51:07 +0100 Subject: [PATCH 864/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 40d687f5af..9ebb269805 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4024 \ No newline at end of file +4025 \ No newline at end of file From be4cadf09d7748ddaa42e1762881cc01eda9311d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:08:43 +0100 Subject: [PATCH 865/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9ebb269805..9c1b63098b 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4025 \ No newline at end of file +4026 \ No newline at end of file From 1204912a56092803de309bd179072a169529f1b5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:10:58 +0100 Subject: [PATCH 866/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 9c1b63098b..c43957704d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4026 \ No newline at end of file +4027 \ No newline at end of file From ba50d32dac4571659324932dcbde3d3903b54c61 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:20:29 +0100 Subject: [PATCH 867/984] update profile to handle optimization-related data --- src/vm/profiler.nim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vm/profiler.nim b/src/vm/profiler.nim index 40bb449976..9f6b578277 100644 --- a/src/vm/profiler.nim +++ b/src/vm/profiler.nim @@ -23,7 +23,7 @@ when defined(PROFILER): # Libraries #======================================= - import algorithm, hashes, std/monotimes + import algorithm, hashes, std/monotimes, std/sets import strformat, strutils, sugar, tables, times import helpers/terminal @@ -270,9 +270,9 @@ template hookProcProfiler*(name: string, actionContent: untyped): untyped = else: actionContent -template hookMiscProfiler*(name: string): untyped = +template hookOptimProfiler*(name: string): untyped = when defined(PROFILER): - var newRow = addMetricIfNotExists(name, "misc") + var newRow = addMetricIfNotExists(name, "optimizations") newRow.runs += 1 #======================================= @@ -285,7 +285,7 @@ proc initProfiler*() = "functions": initOrderedTable[string, ProfilerDataRow](), "ops": initOrderedTable[string, ProfilerDataRow](), "procs": initOrderedTable[string, ProfilerDataRow](), - "misc": initOrderedTable[string, ProfilerDataRow]() + "optimizations": initOrderedTable[string, ProfilerDataRow]() }.toOrderedTable # TODO(VM/profiler) Completely remove or make it work "properly" @@ -302,7 +302,7 @@ proc showProfilerData*() = printProfilerDataTable("functions") printProfilerDataTable("ops") printProfilerDataTable("procs") - printProfilerDataTable("misc") + printProfilerDataTable("optimizations") when false: printProfilerCallTree() else: From f935c9dd2c207757e6b537928b496fa91894b1e6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:20:48 +0100 Subject: [PATCH 868/984] added optimization metrics to VM profiler --- src/vm/ast.nim | 19 +++++++++++++++++-- src/vm/eval.nim | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index eae35d42a6..c3f685246b 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -42,6 +42,8 @@ import vm/[globals, values/value, values/comparison, values/types] import vm/values/printable import vm/values/custom/[vbinary, vcolor, vcomplex, vlogical, vrational, vsymbol, vversion] +import vm/profiler + import vm/bytecode #======================================= # Types @@ -258,15 +260,18 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No if left.kind == ConstantValue and left.value.kind in {Integer, Floating}: # Constant folding if right.kind == ConstantValue and right.value.kind in {Integer, Floating}: + hookOptimProfiler("add (CF)") target.replaceNode(newConstant(left.value + right.value)) # Convert 1 + X -> inc X elif right.kind==VariableLoad and left.kind==ConstantValue and left.value == I1: + hookOptimProfiler("add (inc)") target.op = opInc target.arity = 1 target.setOnlyChild(right) # Convert X + 1 -> inc X elif left.kind==VariableLoad and right.kind==ConstantValue and right.value == I1: + hookOptimProfiler("add (inc)") target.op = opInc target.arity = 1 target.setOnlyChild(left) @@ -275,6 +280,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No # X + Y * X -> X * (Y + 1) elif left.kind == VariableLoad and right.op == opMul: if right.children[0].kind == VariableLoad and right.children[0].value == left.value: + hookOptimProfiler("add (distributive)") target.op = opMul if right.children[1].kind == ConstantValue and right.children[1].value.kind in {Integer, Floating}: right.replaceNode(newConstant(right.children[1].value + I1)) @@ -282,6 +288,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No right.op = opAdd right.children[0].value = newInteger(1) elif right.children[1].kind == VariableLoad and right.children[1].value == left.value: + hookOptimProfiler("add (distributive)") target.op = opMul if right.children[0].kind == ConstantValue and right.children[0].value.kind in {Integer, Floating}: right.replaceNode(newConstant(right.children[0].value + I1)) @@ -293,6 +300,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No # (Y * X) + X -> (Y + 1) * X elif right.kind == VariableLoad and left.op == opMul: if left.children[0].kind == VariableLoad and left.children[0].value == right.value: + hookOptimProfiler("add (distributive)") target.op = opMul if left.children[1].kind == ConstantValue and left.children[1].value.kind in {Integer, Floating}: left.replaceNode(newConstant(left.children[1].value + I1)) @@ -300,6 +308,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No left.op = opAdd left.children[0].value = newInteger(1) elif left.children[1].kind == VariableLoad and left.children[1].value == right.value: + hookOptimProfiler("add (distributive)") target.op = opMul if left.children[0].kind == ConstantValue and left.children[0].value.kind in {Integer, Floating}: left.replaceNode(newConstant(left.children[0].value + I1)) @@ -312,9 +321,11 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No var right = target.children[1] if left.kind == ConstantValue and left.value.kind in {Integer,Floating} and right.kind == ConstantValue and right.value.kind in {Integer,Floating}: + hookOptimProfiler("sub (CF)") # Constant folding target.replaceNode(newConstant(left.value - right.value)) elif left.kind == VariableLoad and right.kind == ConstantValue and right.value == I1: + hookOptimProfiler("sub (dec)") # Convert X - 1 -> dec X target.op = opDec target.arity = 1 @@ -326,6 +337,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No if left.kind == ConstantValue and left.value.kind in {Integer,Floating} and right.kind == ConstantValue and right.value.kind in {Integer,Floating}: + hookOptimProfiler("other (CF)") target.replaceNode(newConstant(op(left.value,right.value))) proc optimizeAppend(target: var Node) {.enforceNoRaises.} = @@ -335,6 +347,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No if left.kind == ConstantValue and left.value.kind == String: # Constant folding if right.kind == ConstantValue and right.value.kind == String: + hookOptimProfiler("append (CF)") target.replaceNode(newConstant(newString(left.value.s & right.value.s))) proc optimizeTo(target: var Node) {.enforceNoRaises.} = @@ -342,17 +355,19 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No if left.kind == ConstantValue and left.value.kind==Type: if left.value.t == Integer: + hookOptimProfiler("to (:integer)") # convert `to :integer` -> opToI target.op = opToI target.arity = 1 target.children.delete(0) elif left.value.t == String: + hookOptimProfiler("To (:string)") # convert `to :string` -> opToS target.op = opToS target.arity = 1 target.children.delete(0) - proc optimizeStores(target: var Node) {.enforceNoRaises.} = + proc updateAritiesFromStore(target: var Node) {.enforceNoRaises.} = var child = target.children[0] if child.op == opFunc: @@ -373,7 +388,7 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No while target.kind in CallNode and target.params == target.arity: when optimize: if target.kind == VariableStore: - target.optimizeStores() + target.updateAritiesFromStore() else: try: case target.op: diff --git a/src/vm/eval.nim b/src/vm/eval.nim index fc90c09578..0cdbdfdbe3 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -24,6 +24,8 @@ import hashes, sugar, tables import vm/[ast, bytecode, values/value] import vm/values/custom/[vbinary, vlogical] +import vm/profiler + import vm/values/printable #======================================= @@ -133,6 +135,8 @@ proc addVariableLoad(consts: var ValueArray, instructions: var VBinary, nd: Node indx = consts.len-1 if indx == previousStore and nd.parent.kind != VariableStore: + hookOptimProfiler("opStorl") + if indx <= 13: instructions[previousStorePos-1] = (byte(opStorl)-0x0E) + byte(indx) elif indx <= 255: @@ -360,12 +364,36 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti if item.kind == SpecialCall: lastOpStore = -1 case item.op: - of opIf: optimizeConditional(consts, it, item, withInversion=true) - of opIfE: optimizeConditional(consts, it, item, withPotentialElse=true, withInversion=true) - of opUnless: optimizeConditional(consts, it, item) - of opUnlessE: optimizeConditional(consts, it, item, withPotentialElse=true) - of opSwitch: optimizeConditional(consts, it, item, withPotentialElse=true, isSwitch=true, withInversion=true) - of opWhile: optimizeConditional(consts, it, item, withLoop=true, withInversion=true) + of opIf: + optimizeConditional(consts, it, item, withInversion=true) + when defined(PROFILER): + if alreadyProcessed: + hookOptimProfiler("opIf") + of opIfE: + optimizeConditional(consts, it, item, withPotentialElse=true, withInversion=true) + when defined(PROFILER): + if alreadyProcessed: + hookOptimProfiler("opIfE") + of opUnless: + optimizeConditional(consts, it, item) + when defined(PROFILER): + if alreadyProcessed: + hookOptimProfiler("opUnless") + of opUnlessE: + optimizeConditional(consts, it, item, withPotentialElse=true) + when defined(PROFILER): + if alreadyProcessed: + hookOptimProfiler("opUnlessE") + of opSwitch: + optimizeConditional(consts, it, item, withPotentialElse=true, isSwitch=true, withInversion=true) + when defined(PROFILER): + if alreadyProcessed: + hookOptimProfiler("opSwitch") + of opWhile: + optimizeConditional(consts, it, item, withLoop=true, withInversion=true) + when defined(PROFILER): + if alreadyProcessed: + hookOptimProfiler("opWhile") of opElse: # `else` is not handled separately # if it's a try?/else block for example, From 167b1aa798c80b915501aefaecc2bc22a47e9fd4 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:27:48 +0100 Subject: [PATCH 869/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c43957704d..0cdf739fc7 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4027 \ No newline at end of file +4028 \ No newline at end of file From a380a117ef560a31ab06dc0bd078506d4986637a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:34:03 +0100 Subject: [PATCH 870/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0cdf739fc7..97a9aea0ea 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4028 \ No newline at end of file +4029 \ No newline at end of file From 21ef57dd7f7f8b94b5c0cafd07109ff032a8f645 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:34:08 +0100 Subject: [PATCH 871/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 97a9aea0ea..b6e26c8b87 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4029 \ No newline at end of file +4030 \ No newline at end of file From 9d3b64011ffdace9453b23081d19510c7dd6adc8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:35:54 +0100 Subject: [PATCH 872/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b6e26c8b87..f0d50fd562 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4030 \ No newline at end of file +4031 \ No newline at end of file From 28a16635c300824741773a347ed68947473602d0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:36:21 +0100 Subject: [PATCH 873/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f0d50fd562..06b9789ade 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4031 \ No newline at end of file +4032 \ No newline at end of file From b6f8f71d5e96278419a83633491e7b9db9e23126 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:37:36 +0100 Subject: [PATCH 874/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 06b9789ade..70626b2fe6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4032 \ No newline at end of file +4033 \ No newline at end of file From 46cf1cd6ee33f96084412e63fe1a2e8faf33a4a5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:39:42 +0100 Subject: [PATCH 875/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 70626b2fe6..b98d0ae2e9 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4033 \ No newline at end of file +4034 \ No newline at end of file From fee87a8ae6b0aa80742464c852b7916e328f4458 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:40:29 +0100 Subject: [PATCH 876/984] VM/eval: make `doEval` & `evalOrGet` get another parameter (to make sure whether you are evaluating a function block or not) --- src/vm/eval.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 0cdbdfdbe3..79c342ebf5 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -489,7 +489,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti # Main #======================================= -proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Translation {.inline.} = +proc doEval*(root: Value, isDictionary=false, isFunctionBlock=false, useStored: static bool = true): Translation {.inline.} = ## Take a parsed Block of values and return its Translation - ## that is: the constants found + the list of bytecode instructions @@ -504,7 +504,7 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr var consts: ValueArray var it: VBinary - evaluateBlock(generateAst(root, asDictionary=isDictionary), consts, it, isDictionary=isDictionary) + evaluateBlock(generateAst(root, asDictionary=isDictionary, asFunction=isFunctionBlock), consts, it, isDictionary=isDictionary) it.add(byte(opEnd)) result = Translation(constants: consts, instructions: it) @@ -515,6 +515,6 @@ proc doEval*(root: Value, isDictionary=false, useStored: static bool = true): Tr if vhash != -1: StoredTranslations[vhash] = result -template evalOrGet*(item: Value): untyped = +template evalOrGet*(item: Value, isFunction=false): untyped = if item.kind==Bytecode: item.trans - else: doEval(item) \ No newline at end of file + else: doEval(item, isFunctionBlock=isFunction) \ No newline at end of file From dfe29f06bf1280a9d0bb66e5ce8f0031f1231dbf Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:40:52 +0100 Subject: [PATCH 877/984] VM/exec: adapt calls to `doEval` for function body blocks --- src/vm/exec.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index 48273e6588..d8a4a31f96 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -298,7 +298,7 @@ proc execFunction*(fun: Value, fid: Hash) = SetSym(arg, move stack.pop()) if fun.bcode.isNil: - fun.bcode = newBytecode(doEval(fun.main)) + fun.bcode = newBytecode(doEval(fun.main, isFunctionBlock=true)) try: ExecLoop(fun.bcode().trans.constants, fun.bcode().trans.instructions) @@ -353,7 +353,7 @@ proc execFunctionInline*(fun: Value, fid: Hash) = SetSym(arg, move stack.pop()) if fun.bcode.isNil: - fun.bcode = newBytecode(doEval(fun.main)) + fun.bcode = newBytecode(doEval(fun.main, isFunctionBlock=true)) try: ExecLoop(fun.bcode().trans.constants, fun.bcode().trans.instructions) From 6bf7aebb64a043d8a53eae2a7715d34cee41f9ce Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:41:44 +0100 Subject: [PATCH 878/984] VM/ast: added AST optimization for `return`s (basically, if we have a return as the last statement of a function block, we don't need it; so let's replace it with the returned value itself ;-)) --- src/vm/ast.nim | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index c3f685246b..80ea8c8ff6 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -154,6 +154,12 @@ proc addSibling(node: Node, newNode: Node) = newNode.parent = node.parent node.parent.children.insert(newNode, node.parent.children.find(node)+1) +proc isLastChild(node: Node): bool = + var j = node.parent.children.len-1 + while j >= 0 and node.parent.children[j].kind == NewlineNode: + j -= 1 + return node.parent.children[j] == node + #------------------------ # Iterators #------------------------ @@ -229,7 +235,15 @@ func copyNode(node: Node): Node = # Methods #======================================= -proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = NoStartingLine, asDictionary: bool = false, processingArrow: static bool = false): int = +proc processBlock*( + root: Node, + blok: Value, + start = 0, + startingLine: uint32 = NoStartingLine, + asDictionary: bool = false, + asFunction: bool = false, + processingArrow: static bool = false +): int = var i: int = start var nLen: int = blok.a.len @@ -367,6 +381,13 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No target.arity = 1 target.children.delete(0) + proc optimizeReturn(target: var Node) {.enforceNoRaises.} = + if isLastChild(target): + hookOptimProfiler("return (eliminate last)") + # Replace last return + var left = target.children[0] + target.replaceNode(left) + proc updateAritiesFromStore(target: var Node) {.enforceNoRaises.} = var child = target.children[0] @@ -401,6 +422,9 @@ proc processBlock*(root: Node, blok: Value, start = 0, startingLine: uint32 = No of opPow : target.optimizeArithmeticOp(`^`) of opAppend : target.optimizeAppend() of opTo : target.optimizeTo() + of opReturn : + if asFunction: + target.optimizeReturn() else: discard @@ -838,7 +862,7 @@ proc dumpNode*(node: Node, level = 0, single: static bool = false, showNewlines: # Main #======================================= -proc generateAst*(parsed: Value, asDictionary=false, reuseArities: static bool=false): Node = +proc generateAst*(parsed: Value, asDictionary=false, asFunction=false, reuseArities: static bool=false): Node = result = newRootNode() when not reuseArities: @@ -847,6 +871,6 @@ proc generateAst*(parsed: Value, asDictionary=false, reuseArities: static bool=f if v.kind == Function: {k: v.arity} - discard result.processBlock(parsed, asDictionary=asDictionary) + discard result.processBlock(parsed, asDictionary=asDictionary, asFunction=asFunction) #echo dumpNode(result) From 669cc8e901fdbd24ef90f34f3ff597893956af13 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 11:44:21 +0100 Subject: [PATCH 879/984] VM/ast: update inlined TODOs --- src/vm/ast.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 80ea8c8ff6..083756e328 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -15,7 +15,7 @@ ## ## The main entry point is ``generateAst``. -# TODO: +# Pending task for new AST+Eval: # - [x] make Attribute's work # - [x] make AttributeLabel's work # - [x] make Path's work @@ -25,6 +25,7 @@ # - [x] clean up opCode's # - [x] attach opCode's to built-in function (for faster lookups) # - [x] optimize appends +# - [x] optimize returns when it's the last statement of a function block # - [x] make labels store new functions in TmpArities # - [x] make labels unstore overwritten functions in TmpArities # - [x] make if/if?/else/while/switch work From 3b6686b372cf1a012b91427fd2af40b674dd6424 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 12:03:14 +0100 Subject: [PATCH 880/984] added expected output for "Perlin noise" RC example (and thus introduce it to CI builds) --- examples/rosetta/perlin noise.res | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/rosetta/perlin noise.res diff --git a/examples/rosetta/perlin noise.res b/examples/rosetta/perlin noise.res new file mode 100644 index 0000000000..a5370afa97 --- /dev/null +++ b/examples/rosetta/perlin noise.res @@ -0,0 +1 @@ +0.1369199587840001 \ No newline at end of file From 755e70321ba1d25ce32aefd7ac1a1052ff7194e5 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 12:04:29 +0100 Subject: [PATCH 881/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b98d0ae2e9..d9d7163a16 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4034 \ No newline at end of file +4035 \ No newline at end of file From cc70124f4381e131d980de00d775f884e0146b1c Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 12:36:26 +0100 Subject: [PATCH 882/984] re-enable all tests (almost) --- tools/tester.art | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tester.art b/tools/tester.art index 9efa4012ff..346e1f1fc0 100755 --- a/tools/tester.art +++ b/tools/tester.art @@ -115,8 +115,8 @@ print color #white.bold " Unit Tester\n" print color #gray ~" Release: @|sys\release|\n" supertime: in's benchmark.get [ - ; runSet "Unit Tests" "../tests/unittests" - ; runSet "Errors" "../tests/errors" + runSet "Unit Tests" "../tests/unittests" + runSet "Errors" "../tests/errors" runSet "Examples" "../examples/rosetta" ] From 1039e7625e11c26a62f36eef958e32ecdca9a76a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 12:36:46 +0100 Subject: [PATCH 883/984] VM/ast: disable `return`-related optimization (temporarily) + added TODO --- src/vm/ast.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 083756e328..345b556613 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -424,8 +424,12 @@ proc processBlock*( of opAppend : target.optimizeAppend() of opTo : target.optimizeTo() of opReturn : - if asFunction: - target.optimizeReturn() + # TODO(VM/ast) `return` optimization not working properly + # see: tests/unittests/branching.art + # labels: vm, ast, bug + discard + # if asFunction: + # target.optimizeReturn() else: discard From a30819cf83063bee0808dbc765a9e2b648e4461d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 13:28:46 +0100 Subject: [PATCH 884/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d9d7163a16..44541be022 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4035 \ No newline at end of file +4036 \ No newline at end of file From 28311d6aa1eb0bfad52187442c72266ee4187741 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 13:32:19 +0100 Subject: [PATCH 885/984] minor fix + re-introduced `return` optimization + removed TODO --- src/vm/ast.nim | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 345b556613..748e1324ce 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -424,12 +424,8 @@ proc processBlock*( of opAppend : target.optimizeAppend() of opTo : target.optimizeTo() of opReturn : - # TODO(VM/ast) `return` optimization not working properly - # see: tests/unittests/branching.art - # labels: vm, ast, bug - discard - # if asFunction: - # target.optimizeReturn() + if asFunction and i == nLen-1: + target.optimizeReturn() else: discard From 17a29b122f4983dc5b0b106ae1d03398ea1af306 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 13:32:24 +0100 Subject: [PATCH 886/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 44541be022..50b58d88e6 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4036 \ No newline at end of file +4037 \ No newline at end of file From d6285b675e25ff494294cdceccec4b9ededd25e6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 13:40:47 +0100 Subject: [PATCH 887/984] Add "Fibonacci sequence / Recursive" to CI builds --- .../fibonacci sequence - recursive.res | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/rosetta/fibonacci sequence - recursive.res diff --git a/examples/rosetta/fibonacci sequence - recursive.res b/examples/rosetta/fibonacci sequence - recursive.res new file mode 100644 index 0000000000..217a83c3ae --- /dev/null +++ b/examples/rosetta/fibonacci sequence - recursive.res @@ -0,0 +1,25 @@ +Fibonacci of 1 = 1 +Fibonacci of 2 = 2 +Fibonacci of 3 = 3 +Fibonacci of 4 = 5 +Fibonacci of 5 = 8 +Fibonacci of 6 = 13 +Fibonacci of 7 = 21 +Fibonacci of 8 = 34 +Fibonacci of 9 = 55 +Fibonacci of 10 = 89 +Fibonacci of 11 = 144 +Fibonacci of 12 = 233 +Fibonacci of 13 = 377 +Fibonacci of 14 = 610 +Fibonacci of 15 = 987 +Fibonacci of 16 = 1597 +Fibonacci of 17 = 2584 +Fibonacci of 18 = 4181 +Fibonacci of 19 = 6765 +Fibonacci of 20 = 10946 +Fibonacci of 21 = 17711 +Fibonacci of 22 = 28657 +Fibonacci of 23 = 46368 +Fibonacci of 24 = 75025 +Fibonacci of 25 = 121393 \ No newline at end of file From 4df1a375473b7a445544bd735ef3c176f185318d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 16:32:13 +0100 Subject: [PATCH 888/984] added "Abundant odd numbers" to CI builds --- examples/rosetta/abundant odd numbers.res | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/rosetta/abundant odd numbers.res diff --git a/examples/rosetta/abundant odd numbers.res b/examples/rosetta/abundant odd numbers.res new file mode 100644 index 0000000000..c3dc2d43f0 --- /dev/null +++ b/examples/rosetta/abundant odd numbers.res @@ -0,0 +1,28 @@ +the first 25 abundant odd numbers: +945 => sum: 1920 +1575 => sum: 3224 +2205 => sum: 4446 +2835 => sum: 5808 +3465 => sum: 7488 +4095 => sum: 8736 +4725 => sum: 9920 +5355 => sum: 11232 +5775 => sum: 11904 +5985 => sum: 12480 +6435 => sum: 13104 +6615 => sum: 13680 +6825 => sum: 13888 +7245 => sum: 14976 +7425 => sum: 14880 +7875 => sum: 16224 +8085 => sum: 16416 +8415 => sum: 16848 +8505 => sum: 17472 +8925 => sum: 17856 +9135 => sum: 18720 +9555 => sum: 19152 +9765 => sum: 19968 +10395 => sum: 23040 +11025 => sum: 22971 +the 1000th abundant odd number: 492975 => sum: 1012336 +the first abundant odd number greater than one billion (10^9): 1000000575 => sum: 2083561584 \ No newline at end of file From 25940c6d87446eb66434b6b3536512b024a7cd33 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 16:39:45 +0100 Subject: [PATCH 889/984] minor fix --- examples/rosetta/ascending primes.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/ascending primes.art b/examples/rosetta/ascending primes.art index 16113c9dc2..e4a7eacf1d 100644 --- a/examples/rosetta/ascending primes.art +++ b/examples/rosetta/ascending primes.art @@ -3,7 +3,7 @@ ascending?: function [x][ and? [equal? sort initial initial][equal? size initial size unique initial] ] -candidates: select (1..1456789) ++ [ +candidates: select (@1..1456789) ++ [ 12345678, 12345679, 12345689, 12345789, 12346789, 12356789, 12456789, 13456789, 23456789, 123456789 ] => prime? From 95b5e0e2282364d285130510a259f6e024159033 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 16:39:58 +0100 Subject: [PATCH 890/984] added "Ascending primes" to CI builds --- examples/rosetta/ascending primes.res | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 examples/rosetta/ascending primes.res diff --git a/examples/rosetta/ascending primes.res b/examples/rosetta/ascending primes.res new file mode 100644 index 0000000000..78441f23e7 --- /dev/null +++ b/examples/rosetta/ascending primes.res @@ -0,0 +1,10 @@ + 2 3 5 7 13 17 19 23 29 37 + 47 59 67 79 89 127 137 139 149 157 + 167 179 239 257 269 347 349 359 367 379 + 389 457 467 479 569 1237 1249 1259 1279 1289 + 1367 1459 1489 1567 1579 1789 2347 2357 2389 2459 + 2467 2579 2689 2789 3457 3467 3469 4567 4679 4789 + 5689 12347 12379 12457 12479 12569 12589 12689 13457 13469 + 13567 13679 13789 15679 23459 23567 23689 23789 25679 34589 + 34679 123457 123479 124567 124679 125789 134789 145679 234589 235679 + 235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789 \ No newline at end of file From ec980ad6fdaf916092a4cabe81d9e849d5d38a41 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 16:40:11 +0100 Subject: [PATCH 891/984] added "Alternade words" to CI builds --- examples/rosetta/alternade words.res | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/rosetta/alternade words.res diff --git a/examples/rosetta/alternade words.res b/examples/rosetta/alternade words.res new file mode 100644 index 0000000000..0f36c15828 --- /dev/null +++ b/examples/rosetta/alternade words.res @@ -0,0 +1,58 @@ +accost => cot acs +accuse => cue acs +afield => fed ail +agleam => gem ala +alcott => lot act +allele => lee all +allied => lid ale +alpert => let apr +ambient => min abet +annette => net ante +apport => pot apr +ariadne => ran aide +assist => sit ass +battle => ate btl +blaine => lie ban +brenda => rna bed +calliope => aloe clip +choose => hoe cos +choosy => hoy cos +claire => lie car +collude => old clue +effete => fee eft +fabric => arc fbi +fealty => ely fat +fluent => let fun +forwent => own fret +friend => red fin +george => ere gog +inroad => nod ira +israel => sal ire +jaunty => any jut +joanne => one jan +lounge => one lug +oriole => roe oil +oswald => sad owl +parrot => art pro +peoria => era poi +pierre => ire per +poodle => ode pol +pounce => one puc +racial => ail rca +realty => ely rat +sordid => odd sri +spatial => pta sail +sprain => pan sri +strain => tan sri +strait => tat sri +sturdy => try sud +sweaty => way set +tattle => ate ttl +theorem => hoe term +though => huh tog +throaty => hot tray +triode => roe tid +triune => rue tin +troupe => rue top +truant => rat tun +twirly => wry til \ No newline at end of file From 9e34f193b67b79eb3ad9f4c33114d6fbd952f124 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 16:44:06 +0100 Subject: [PATCH 892/984] added "Brazilian numbers" to CI builds --- examples/rosetta/brazilian numbers.res | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 examples/rosetta/brazilian numbers.res diff --git a/examples/rosetta/brazilian numbers.res b/examples/rosetta/brazilian numbers.res new file mode 100644 index 0000000000..5e3383b85d --- /dev/null +++ b/examples/rosetta/brazilian numbers.res @@ -0,0 +1,8 @@ +First 20 brazilian numbers: +7 8 10 12 13 14 15 16 18 20 21 22 24 26 27 28 30 31 32 33 + +First 20 odd brazilian numbers: +7 13 15 21 27 31 33 35 39 43 45 51 55 57 63 65 69 73 75 77 + +First 20 prime brazilian numbers: +7 13 31 43 73 127 157 211 241 307 421 463 601 757 1093 1123 1483 1723 2551 2801 \ No newline at end of file From 9f850692bb8ec0521281cb178fb8b43ff5ac4a19 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 16:49:17 +0100 Subject: [PATCH 893/984] added "Change e letters to i in words" to CI builds --- .../change e letters to i in words.res | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/rosetta/change e letters to i in words.res diff --git a/examples/rosetta/change e letters to i in words.res b/examples/rosetta/change e letters to i in words.res new file mode 100644 index 0000000000..798cdd6d90 --- /dev/null +++ b/examples/rosetta/change e letters to i in words.res @@ -0,0 +1,26 @@ +analyses => analysis +atlantes => atlantis +bellow => billow +breton => briton +clench => clinch +convect => convict +crises => crisis +diagnoses => diagnosis +enfant => infant +enquiry => inquiry +frances => francis +galatea => galatia +harden => hardin +heckman => hickman +inequity => iniquity +inflect => inflict +jacobean => jacobian +marten => martin +module => moduli +pegging => pigging +psychoses => psychosis +rabbet => rabbit +sterling => stirling +synopses => synopsis +vector => victor +welles => willis \ No newline at end of file From aeefc58cc0b714aff73bc29fdad24cb58c606b4a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 16:50:37 +0100 Subject: [PATCH 894/984] added "Changeable words" to CI builds --- examples/rosetta/changeable words.res | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/rosetta/changeable words.res diff --git a/examples/rosetta/changeable words.res b/examples/rosetta/changeable words.res new file mode 100644 index 0000000000..e87c455755 --- /dev/null +++ b/examples/rosetta/changeable words.res @@ -0,0 +1,26 @@ +aristotelean - aristotelian +claustrophobia - claustrophobic +committeeman - committeemen +committeewoman - committeewomen +complementary - complimentary +confirmation - conformation +congresswoman - congresswomen +councilwoman - councilwomen +craftsperson - draftsperson +eavesdropped - eavesdropper +frontiersman - frontiersmen +handicraftsman - handicraftsmen +incommutable - incomputable +installation - instillation +kaleidescope - kaleidoscope +neuroanatomy - neuroanotomy +newspaperman - newspapermen +nonagenarian - nonogenarian +onomatopoeia - onomatopoeic +philanthrope - philanthropy +prescription - proscription +schizophrenia - schizophrenic +shakespearean - shakespearian +spectroscope - spectroscopy +underclassman - underclassmen +upperclassman - upperclassmen \ No newline at end of file From b79d6119c6c55c8b1c424fc08e96006d7c907a10 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 16:56:49 +0100 Subject: [PATCH 895/984] added "Circular primes" to CI builds --- examples/rosetta/circular primes.res | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/rosetta/circular primes.res diff --git a/examples/rosetta/circular primes.res b/examples/rosetta/circular primes.res new file mode 100644 index 0000000000..ca23cc6223 --- /dev/null +++ b/examples/rosetta/circular primes.res @@ -0,0 +1,19 @@ +2 +3 +5 +7 +11 +13 +17 +37 +79 +113 +197 +199 +337 +1193 +3779 +11939 +19937 +193939 +199933 \ No newline at end of file From 616c3662c6fe4f1ed187abb02494e1e567ec8c0f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:00:38 +0100 Subject: [PATCH 896/984] minor edit --- ...gle digit factors whose factors are all substrings of k.art | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/rosetta/composite numbers k with no single digit factors whose factors are all substrings of k.art b/examples/rosetta/composite numbers k with no single digit factors whose factors are all substrings of k.art index ac20179b3b..29bc814f33 100644 --- a/examples/rosetta/composite numbers k with no single digit factors whose factors are all substrings of k.art +++ b/examples/rosetta/composite numbers k with no single digit factors whose factors are all substrings of k.art @@ -1,6 +1,5 @@ valid?: function [n][ - pf: factors.prime n - every? pf 'f -> + every? factors.prime n 'f -> and? [contains? to :string n to :string f] [1 <> size digits f] ] From bf82cd54183408e08ef7f813198899c8aed99f08 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:03:28 +0100 Subject: [PATCH 897/984] update syntax --- examples/rosetta/count the coins.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/count the coins.art b/examples/rosetta/count the coins.art index a441acb51d..a14f63901a 100644 --- a/examples/rosetta/count the coins.art +++ b/examples/rosetta/count the coins.art @@ -4,7 +4,7 @@ changes: function [amount coins][ loop coins 'coin [ loop coin..amount 'j -> - set ways j (get ways j) + get ways j-coin + ways\[j]: ways\[j] + ways\[j-coin] ] ways\[amount] From fe1bfe0e0f74a2c99cea9d0ea9ade050d6798478 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:03:40 +0100 Subject: [PATCH 898/984] added "Count the coins" to CI builds --- examples/rosetta/count the coins.res | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 examples/rosetta/count the coins.res diff --git a/examples/rosetta/count the coins.res b/examples/rosetta/count the coins.res new file mode 100644 index 0000000000..58d4a97c1c --- /dev/null +++ b/examples/rosetta/count the coins.res @@ -0,0 +1,2 @@ +242 +13398445413854501 \ No newline at end of file From 384c98b3111a90021ab07b7750f06897ab7f94e1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:05:33 +0100 Subject: [PATCH 899/984] added "Create an HTML table" to CI builds --- examples/rosetta/create an html table.res | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/rosetta/create an html table.res diff --git a/examples/rosetta/create an html table.res b/examples/rosetta/create an html table.res new file mode 100644 index 0000000000..90019dd0c0 --- /dev/null +++ b/examples/rosetta/create an html table.res @@ -0,0 +1 @@ +
XYZ
1867815101074
2610346887520
3984475092354
4916060319363
5420546091578
\ No newline at end of file From fce230b8c18b2cf96d6de8986630bff1a80a7c08 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:07:28 +0100 Subject: [PATCH 900/984] added "Descending primes" to CI builds --- examples/rosetta/descending primes.res | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 examples/rosetta/descending primes.res diff --git a/examples/rosetta/descending primes.res b/examples/rosetta/descending primes.res new file mode 100644 index 0000000000..856e57ff79 --- /dev/null +++ b/examples/rosetta/descending primes.res @@ -0,0 +1,9 @@ + 2 3 5 7 31 41 43 53 61 71 + 73 83 97 421 431 521 541 631 641 643 + 653 743 751 761 821 853 863 941 953 971 + 983 5431 6421 6521 7321 7541 7621 7643 8431 8521 + 8543 8641 8731 8741 8753 8761 9421 9431 9521 9631 + 9643 9721 9743 9851 9871 75431 76421 76541 76543 86531 + 87421 87541 87631 87641 87643 94321 96431 97651 98321 98543 + 98621 98641 98731 764321 865321 876431 975421 986543 987541 987631 + 8764321 8765321 9754321 9875321 97654321 98764321 98765431 \ No newline at end of file From 263cd9e1bf8dbe8d6bc01b2e2801dc68e16a6799 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:09:02 +0100 Subject: [PATCH 901/984] added "Emirp primes" to CI builds --- examples/rosetta/emirp primes.res | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 examples/rosetta/emirp primes.res diff --git a/examples/rosetta/emirp primes.res b/examples/rosetta/emirp primes.res new file mode 100644 index 0000000000..99768a010c --- /dev/null +++ b/examples/rosetta/emirp primes.res @@ -0,0 +1,8 @@ +The first 20 emirps: +13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389 + +Emirps between 7700 and 8000: +7717 7757 7817 7841 7867 7879 7901 7927 7949 7951 7963 + +The 10000th emirp: +948349 \ No newline at end of file From 967ffb3885ed8ab1808863693847dfa54a851ef7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:11:15 +0100 Subject: [PATCH 902/984] added "Factorions" to CI builds --- examples/rosetta/factorions.res | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 examples/rosetta/factorions.res diff --git a/examples/rosetta/factorions.res b/examples/rosetta/factorions.res new file mode 100644 index 0000000000..5670a7d95b --- /dev/null +++ b/examples/rosetta/factorions.res @@ -0,0 +1,4 @@ +Base 9 factorions: [1 2 41282] +Base 10 factorions: [1 2 145 40585] +Base 11 factorions: [1 2 26 48 40472] +Base 12 factorions: [1 2] \ No newline at end of file From 88bf9a3d832069f13aa3a1cf64556d2dc61da52a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:15:59 +0100 Subject: [PATCH 903/984] added "Hailstone sequence" to CI builds --- examples/rosetta/hailstone sequence.res | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 examples/rosetta/hailstone sequence.res diff --git a/examples/rosetta/hailstone sequence.res b/examples/rosetta/hailstone sequence.res new file mode 100644 index 0000000000..96eb8abac6 --- /dev/null +++ b/examples/rosetta/hailstone sequence.res @@ -0,0 +1,3 @@ +Hailstone sequence for 27: +27 82 41 124 62 31 94 47 142 71 214 107 322 161 484 242 121 364 182 91 274 137 412 206 103 310 155 466 233 700 350 175 526 263 790 395 1186 593 1780 890 445 1336 668 334 167 502 251 754 377 1132 566 283 850 425 1276 638 319 958 479 1438 719 2158 1079 3238 1619 4858 2429 7288 3644 1822 911 2734 1367 4102 2051 6154 3077 9232 4616 2308 1154 577 1732 866 433 1300 650 325 976 488 244 122 61 184 92 46 23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1 +max hailstone sequence found (<100000): of length 179 for 871 \ No newline at end of file From 8986cc33899437d00ee357d205ddb628c37d4b3e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:18:02 +0100 Subject: [PATCH 904/984] added "Hamming numbers" to CI builds --- examples/rosetta/hamming numbers.res | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 examples/rosetta/hamming numbers.res diff --git a/examples/rosetta/hamming numbers.res b/examples/rosetta/hamming numbers.res new file mode 100644 index 0000000000..719ae7a5aa --- /dev/null +++ b/examples/rosetta/hamming numbers.res @@ -0,0 +1,3 @@ +1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36 +2125764000 +519312780448388736089589843750000000000000000000000000000000000000000000000000000000 \ No newline at end of file From 702acc50f1d0dc2d5597ef934ae5783ee154cfe3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:18:14 +0100 Subject: [PATCH 905/984] ...but exclude it from MINI builds --- tools/tester.art | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/tester.art b/tools/tester.art index 346e1f1fc0..2a68a0dcab 100755 --- a/tools/tester.art +++ b/tools/tester.art @@ -25,6 +25,7 @@ canExecute?: function [scri][ "ackermann function" "arbitrary-precision integers - included" "curzon numbers" + "hamming numbers" "iban" "integer overflow" "integer roots" From e18ee288e0edc3658333a6bb159d7504b2134724 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:20:26 +0100 Subject: [PATCH 906/984] syntax update --- examples/rosetta/largest int from concatenated ints.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/largest int from concatenated ints.art b/examples/rosetta/largest int from concatenated ints.art index de01a8afd1..533b3aa963 100644 --- a/examples/rosetta/largest int from concatenated ints.art +++ b/examples/rosetta/largest int from concatenated ints.art @@ -1,6 +1,6 @@ largestConcInt: function [arr]-> max map permutate arr 's [ - to :integer join map s => [to :string] + to :integer join map s => [to :string &] ] loop [[1 34 3 98 9 76 45 4] [54 546 548 60]] 'a -> From a992c8f71d23bce1bf6f8590dcf842d8021d469a Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:20:38 +0100 Subject: [PATCH 907/984] added "Largest int from concatenated ints" to CI builds --- examples/rosetta/largest int from concatenated ints.res | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 examples/rosetta/largest int from concatenated ints.res diff --git a/examples/rosetta/largest int from concatenated ints.res b/examples/rosetta/largest int from concatenated ints.res new file mode 100644 index 0000000000..757f435d27 --- /dev/null +++ b/examples/rosetta/largest int from concatenated ints.res @@ -0,0 +1,2 @@ +998764543431 +6054854654 \ No newline at end of file From d26b0a50116bdd10e8e31a53f835d984419853e3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:28:06 +0100 Subject: [PATCH 908/984] added "Largest number divisible by its digits" to CI builds --- examples/rosetta/largest number divisible by its digits.res | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/rosetta/largest number divisible by its digits.res diff --git a/examples/rosetta/largest number divisible by its digits.res b/examples/rosetta/largest number divisible by its digits.res new file mode 100644 index 0000000000..f722cd6356 --- /dev/null +++ b/examples/rosetta/largest number divisible by its digits.res @@ -0,0 +1 @@ +9867312 \ No newline at end of file From bbbcc5f1107ce2b13a00f19070e3754fd76b5946 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:30:11 +0100 Subject: [PATCH 909/984] minor fix --- examples/rosetta/ludic numbers.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/ludic numbers.art b/examples/rosetta/ludic numbers.art index 139688e796..6001c6f132 100644 --- a/examples/rosetta/ludic numbers.art +++ b/examples/rosetta/ludic numbers.art @@ -1,7 +1,7 @@ ludicGen: function [nmax][ result: [1] - lst: 2..nmax+1 + lst: @2..nmax+1 i: 0 worked: false while [and? [not? empty? lst] [i < size lst]][ From a5aeccb2c82d58f2f7e6b56ee297a01c1a48ff07 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:30:21 +0100 Subject: [PATCH 910/984] added "Ludic numbers" to CI builds --- examples/rosetta/ludic numbers.res | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 examples/rosetta/ludic numbers.res diff --git a/examples/rosetta/ludic numbers.res b/examples/rosetta/ludic numbers.res new file mode 100644 index 0000000000..62711f53f6 --- /dev/null +++ b/examples/rosetta/ludic numbers.res @@ -0,0 +1,9 @@ +The first 25 ludic numbers: +1 2 3 5 7 11 13 17 23 25 29 37 41 43 47 53 61 67 71 77 83 89 91 97 107 + +There are 142 ludic numbers less than/or equal to 1000 + +The ludic numbers from 2000th to 2005th are: [21475 21481 21487 21493 21503 21511] + +The triplets of ludic numbers less than 250 are: +[1 3 7] [5 7 11] [11 13 17] [23 25 29] [41 43 47] [173 175 179] [221 223 227] [233 235 239] \ No newline at end of file From ec35d80153d24ba7e4da74c9b69fc417e5b975bb Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:32:11 +0100 Subject: [PATCH 911/984] added "Magic constant" to CI builds --- examples/rosetta/magic constant.res | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/rosetta/magic constant.res diff --git a/examples/rosetta/magic constant.res b/examples/rosetta/magic constant.res new file mode 100644 index 0000000000..eab3668878 --- /dev/null +++ b/examples/rosetta/magic constant.res @@ -0,0 +1,25 @@ +The first 20 magic constants are: +15 34 65 111 175 260 369 505 671 870 1105 1379 1695 2056 2465 2925 3439 4010 4641 + +The 1,000th magic constant is: +503006505 + +10 ^ 1 => 3 +10 ^ 2 => 6 +10 ^ 3 => 13 +10 ^ 4 => 28 +10 ^ 5 => 59 +10 ^ 6 => 126 +10 ^ 7 => 272 +10 ^ 8 => 585 +10 ^ 9 => 1260 +10 ^ 10 => 2715 +10 ^ 11 => 5849 +10 ^ 12 => 12600 +10 ^ 13 => 27145 +10 ^ 14 => 58481 +10 ^ 15 => 125993 +10 ^ 16 => 271442 +10 ^ 17 => 584804 +10 ^ 18 => 1259922 +10 ^ 19 => 2714418 \ No newline at end of file From 8523becf8f558496b1bec3aa65d9c7b4f290ca32 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:37:48 +0100 Subject: [PATCH 912/984] added "Odd words" to CI builds --- examples/rosetta/odd words.res | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/rosetta/odd words.res diff --git a/examples/rosetta/odd words.res b/examples/rosetta/odd words.res new file mode 100644 index 0000000000..023a261775 --- /dev/null +++ b/examples/rosetta/odd words.res @@ -0,0 +1,14 @@ +barbarian => brain +childbear => cider +corrigenda => cried +gargantuan => grata +headdress => hades +palladian => plain +propionate => point +salvation => slain +siltation => slain +slingshot => sight +statuette => saute +supersede => spree +supervene => spree +terminable => trial \ No newline at end of file From 311e7e6085aa652cd545d563135e5d7ab9277cc8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:39:02 +0100 Subject: [PATCH 913/984] re-added "Ordered words" to CI builds --- examples/rosetta/{ordered words_res => ordered words.res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/rosetta/{ordered words_res => ordered words.res} (100%) diff --git a/examples/rosetta/ordered words_res b/examples/rosetta/ordered words.res similarity index 100% rename from examples/rosetta/ordered words_res rename to examples/rosetta/ordered words.res From ac020fae84ed3f4bd1727623f26863bb9c66ce4d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:40:21 +0100 Subject: [PATCH 914/984] added "Pell's equation" to CI builds --- examples/rosetta/pell's equation.res | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 examples/rosetta/pell's equation.res diff --git a/examples/rosetta/pell's equation.res b/examples/rosetta/pell's equation.res new file mode 100644 index 0000000000..40a14b1ba4 --- /dev/null +++ b/examples/rosetta/pell's equation.res @@ -0,0 +1,4 @@ +xΒ² - 61 * yΒ² = 1 for (x,y) = 1766319049 , 226153980 +xΒ² - 109 * yΒ² = 1 for (x,y) = 158070671986249 , 15140424455100 +xΒ² - 181 * yΒ² = 1 for (x,y) = 2469645423824185801 , 183567298683461940 +xΒ² - 277 * yΒ² = 1 for (x,y) = 159150073798980475849 , 9562401173878027020 \ No newline at end of file From 30a4b0c1e5b67f0b6b05937aad1733e5f8e3b844 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:40:51 +0100 Subject: [PATCH 915/984] ... but excluded from MINI builds --- tools/tester.art | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/tester.art b/tools/tester.art index 2a68a0dcab..12b7bb5ada 100755 --- a/tools/tester.art +++ b/tools/tester.art @@ -35,6 +35,7 @@ canExecute?: function [scri][ "lucas-lehmer test" "modular exponentation" "next special primes" + "pell's equation" "sorting algorithms - cycle sort" "sorting algorithms - pancake sort" "sylvester's sequence" From 0882623b1120ece6fbb9b58b07b737a59660ddb8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:43:06 +0100 Subject: [PATCH 916/984] updated code --- examples/rosetta/perfect numbers.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/perfect numbers.art b/examples/rosetta/perfect numbers.art index 5d90733bb8..ac15ae5821 100644 --- a/examples/rosetta/perfect numbers.art +++ b/examples/rosetta/perfect numbers.art @@ -1,6 +1,6 @@ divisors: $[n][ select 1..(n/2)+1 'i -> 0 = n % i ] perfect?: $[n][ n = sum divisors n ] -loop 2..1000 'i [ +loop 2..10000 'i [ if perfect? i -> print i ] \ No newline at end of file From e12f19b3f22cdb7971c3afb249fdfdd733ddbdd0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:43:16 +0100 Subject: [PATCH 917/984] added "Perfect numbers" to CI builds --- examples/rosetta/perfect numbers.res | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 examples/rosetta/perfect numbers.res diff --git a/examples/rosetta/perfect numbers.res b/examples/rosetta/perfect numbers.res new file mode 100644 index 0000000000..965906a195 --- /dev/null +++ b/examples/rosetta/perfect numbers.res @@ -0,0 +1,4 @@ +6 +28 +496 +8128 \ No newline at end of file From 5ef74ea1ae03717c25756af877dd95c733c5fd19 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:45:13 +0100 Subject: [PATCH 918/984] minor fix --- examples/rosetta/permutations - derangements.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/permutations - derangements.art b/examples/rosetta/permutations - derangements.art index 0e3b28cbaf..45875198e2 100644 --- a/examples/rosetta/permutations - derangements.art +++ b/examples/rosetta/permutations - derangements.art @@ -6,7 +6,7 @@ isClean?: function [s,o][ ] derangements: function [n][ - original: 1..n + original: @1..n select permutate original 'x -> isClean? x original ] From 4c45f815a22cad5d8bed06b504cfb9f879d82919 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:45:26 +0100 Subject: [PATCH 919/984] added "Permutations/Derangements" to CI builds --- .../rosetta/permutations - derangements.res | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/rosetta/permutations - derangements.res diff --git a/examples/rosetta/permutations - derangements.res b/examples/rosetta/permutations - derangements.res new file mode 100644 index 0000000000..01e6f4b0f1 --- /dev/null +++ b/examples/rosetta/permutations - derangements.res @@ -0,0 +1,26 @@ +Derangements of 1 2 3 4: +2 1 4 3 +2 3 4 1 +2 4 1 3 +3 1 4 2 +3 4 1 2 +3 4 2 1 +4 1 2 3 +4 3 1 2 +4 3 2 1 + +Number of derangements: + n counted calculated +--------------------------------------- + 0 1 1 + 1 0 0 + 2 1 1 + 3 2 2 + 4 9 9 + 5 44 44 + 6 265 265 + 7 1854 1854 + 8 14833 14833 + 9 133496 133496 + +!20 = 895014631192902121 \ No newline at end of file From 6bdcd048d06e3b8d98b89242c96ae0c80a7b8bdc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:45:51 +0100 Subject: [PATCH 920/984] ... but excluded from MINI builds --- tools/tester.art | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/tester.art b/tools/tester.art index 12b7bb5ada..4ee06ed3d1 100755 --- a/tools/tester.art +++ b/tools/tester.art @@ -36,6 +36,7 @@ canExecute?: function [scri][ "modular exponentation" "next special primes" "pell's equation" + "permutations - derangements" "sorting algorithms - cycle sort" "sorting algorithms - pancake sort" "sylvester's sequence" From 43407f8a6c9624bdcca971413c081be74690fbb7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:48:02 +0100 Subject: [PATCH 921/984] added "Prime numbers which contain 123" to CI builds --- examples/rosetta/prime numbers which contain 123.res | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/rosetta/prime numbers which contain 123.res diff --git a/examples/rosetta/prime numbers which contain 123.res b/examples/rosetta/prime numbers which contain 123.res new file mode 100644 index 0000000000..d125e599c4 --- /dev/null +++ b/examples/rosetta/prime numbers which contain 123.res @@ -0,0 +1,7 @@ + 1123 1231 1237 8123 11239 12301 12323 12329 12343 12347 +12373 12377 12379 12391 17123 20123 22123 28123 29123 31123 +31231 31237 34123 37123 40123 41231 41233 44123 47123 49123 +50123 51239 56123 59123 61231 64123 65123 70123 71233 71237 +76123 81233 81239 89123 91237 98123 + +'123' Numbers < 1000000: 451 \ No newline at end of file From acfc18335d356ef0300a4655969b614c721b3eca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:49:41 +0100 Subject: [PATCH 922/984] minor fix --- examples/rosetta/pythagorean triples.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/pythagorean triples.art b/examples/rosetta/pythagorean triples.art index 7c540734a3..83fd5568c8 100644 --- a/examples/rosetta/pythagorean triples.art +++ b/examples/rosetta/pythagorean triples.art @@ -14,7 +14,7 @@ unique 'triples print ["Found" size triples "pythagorean triples with a perimeter no larger than 100:"] print triples -primitive: select triples => [1 = gcd] +primitive: select triples => [1 = gcd &] print "" print [size primitive "of them are primitive:"] From f4cff3a83a9a2b6a8bcd347ad10bee4e7a723847 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:49:52 +0100 Subject: [PATCH 923/984] added "Pythagorean triples" to CI builds --- examples/rosetta/pythagorean triples.res | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 examples/rosetta/pythagorean triples.res diff --git a/examples/rosetta/pythagorean triples.res b/examples/rosetta/pythagorean triples.res new file mode 100644 index 0000000000..5e71bc2823 --- /dev/null +++ b/examples/rosetta/pythagorean triples.res @@ -0,0 +1,5 @@ +Found 17 pythagorean triples with a perimeter no larger than 100: +[3 4 5] [5 12 13] [6 8 10] [7 24 25] [8 15 17] [9 12 15] [9 40 41] [10 24 26] [12 16 20] [12 35 37] [15 20 25] [15 36 39] [16 30 34] [18 24 30] [20 21 29] [21 28 35] [24 32 40] + +7 of them are primitive: +[3 4 5] [5 12 13] [7 24 25] [8 15 17] [9 40 41] [12 35 37] [20 21 29] \ No newline at end of file From 2919beed2a1479c59b6da6b595df613e8119d650 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:51:58 +0100 Subject: [PATCH 924/984] minor fix --- examples/rosetta/search a list.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/search a list.art b/examples/rosetta/search a list.art index a2a230e27a..78478bdc6d 100644 --- a/examples/rosetta/search a list.art +++ b/examples/rosetta/search a list.art @@ -3,6 +3,6 @@ haystack: [Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo] loop [Bush Washington] 'needle [ i: index haystack needle - if? empty? i -> panic ~"|needle| is not in haystack" + if? null? i -> panic ~"|needle| is not in haystack" else -> print [i needle] ] From 96550c6611da9b3a5add39b223d5cb572dabc19d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:52:08 +0100 Subject: [PATCH 925/984] added "Search a list" to CI builds --- examples/rosetta/search a list.res | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 examples/rosetta/search a list.res diff --git a/examples/rosetta/search a list.res b/examples/rosetta/search a list.res new file mode 100644 index 0000000000..542b6b33ab --- /dev/null +++ b/examples/rosetta/search a list.res @@ -0,0 +1,5 @@ +4 Bush +>> Program | File: search a list.art + error | Line: 6 + | + | Washington is not in haystack \ No newline at end of file From 68ecd2b687a944c593b7a3e1a1538ee4e1c39bff Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:53:24 +0100 Subject: [PATCH 926/984] minor fix --- examples/rosetta/semordnilap.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rosetta/semordnilap.art b/examples/rosetta/semordnilap.art index 382b2bd8ba..f004c885e0 100644 --- a/examples/rosetta/semordnilap.art +++ b/examples/rosetta/semordnilap.art @@ -1,4 +1,4 @@ -words: read.lines "http://wiki.puzzlers.org/pub/wordlists/unixdict.txt" +words: read.lines relative "unixdict.txt" pairs: [] loop words 'wrd [ if and? contains? words reverse wrd From bc5d840642a4d3c91b2991285d9d5ec9b55dc487 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 17:55:15 +0100 Subject: [PATCH 927/984] added "Sequence of non-squares" to CI builds --- examples/rosetta/sequence of non-squares.res | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/rosetta/sequence of non-squares.res diff --git a/examples/rosetta/sequence of non-squares.res b/examples/rosetta/sequence of non-squares.res new file mode 100644 index 0000000000..1429b018b6 --- /dev/null +++ b/examples/rosetta/sequence of non-squares.res @@ -0,0 +1,23 @@ +1 -> 2 +2 -> 3 +3 -> 5 +4 -> 6 +5 -> 7 +6 -> 8 +7 -> 10 +8 -> 11 +9 -> 12 +10 -> 13 +11 -> 14 +12 -> 15 +13 -> 17 +14 -> 18 +15 -> 19 +16 -> 20 +17 -> 21 +18 -> 22 +19 -> 23 +20 -> 24 +21 -> 26 +22 -> 27 +Didn't find any squares! \ No newline at end of file From 0fa646061112b5d25bd5ef17e85e3b3be879ea7d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:01:33 +0100 Subject: [PATCH 928/984] added "Sorting algorithms/Permutation sort" to CI builds --- examples/rosetta/sorting algorithms - permutation sort.res | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/rosetta/sorting algorithms - permutation sort.res diff --git a/examples/rosetta/sorting algorithms - permutation sort.res b/examples/rosetta/sorting algorithms - permutation sort.res new file mode 100644 index 0000000000..1358f1b649 --- /dev/null +++ b/examples/rosetta/sorting algorithms - permutation sort.res @@ -0,0 +1 @@ +1 2 3 4 5 6 7 8 9 \ No newline at end of file From 351fb727705733e358927141a8029c5a536407a1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:01:46 +0100 Subject: [PATCH 929/984] added "Square root by hand" to CI builds --- examples/rosetta/square root by hand.res | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/rosetta/square root by hand.res diff --git a/examples/rosetta/square root by hand.res b/examples/rosetta/square root by hand.res new file mode 100644 index 0000000000..c53f3a1b5c --- /dev/null +++ b/examples/rosetta/square root by hand.res @@ -0,0 +1 @@ +14142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372 \ No newline at end of file From fe58cf5b412c453acafa495860d7a1cc28ca9caa Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:01:59 +0100 Subject: [PATCH 930/984] added "Successive prime differences" to CI builds --- .../rosetta/successive prime differences.res | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/rosetta/successive prime differences.res diff --git a/examples/rosetta/successive prime differences.res b/examples/rosetta/successive prime differences.res new file mode 100644 index 0000000000..3b6e469e25 --- /dev/null +++ b/examples/rosetta/successive prime differences.res @@ -0,0 +1,24 @@ +Differences of 2 + First: 3 5 + Last: 999959 999961 + Count: 8169 +Differences of 1 + First: 2 3 + Last: 2 3 + Count: 1 +Differences of 2, 2 + First: 3 5 7 + Last: 3 5 7 + Count: 1 +Differences of 2, 4 + First: 5 7 11 + Last: 999431 999433 999437 + Count: 1393 +Differences of 4, 2 + First: 7 11 13 + Last: 997807 997811 997813 + Count: 1444 +Differences of 6, 4, 2 + First: 31 37 41 43 + Last: 997141 997147 997151 997153 + Count: 306 \ No newline at end of file From 82a593ab0dc55d6358d8add85edfae8941e97d0d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:03:25 +0100 Subject: [PATCH 931/984] added "Sylvester's sequence" to CI builds --- examples/rosetta/sylvester's sequence.res | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 examples/rosetta/sylvester's sequence.res diff --git a/examples/rosetta/sylvester's sequence.res b/examples/rosetta/sylvester's sequence.res new file mode 100644 index 0000000000..706ccabf90 --- /dev/null +++ b/examples/rosetta/sylvester's sequence.res @@ -0,0 +1,5 @@ +First 10 terms of the Sylvester sequence: +2 3 7 43 1807 3263443 10650056950807 113423713055421844361000443 12864938683278671740537145998360961546653259485195807 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443 + +Sum of the reciprocals of the first 10 items: +1.0 \ No newline at end of file From 7bca8a25c2222f699b483d271f0a14b9bfeb404e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:05:40 +0100 Subject: [PATCH 932/984] added "Teacup rim text" to CI builds --- examples/rosetta/teacup rim text.res | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 examples/rosetta/teacup rim text.res diff --git a/examples/rosetta/teacup rim text.res b/examples/rosetta/teacup rim text.res new file mode 100644 index 0000000000..3060371093 --- /dev/null +++ b/examples/rosetta/teacup rim text.res @@ -0,0 +1,3 @@ +tea -> eat -> ate +rca -> car -> arc +pta -> tap -> apt \ No newline at end of file From 65ca75f4886ec575e4c5427a0779ff726dbbd9ca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:07:05 +0100 Subject: [PATCH 933/984] re-added "Truncatable primes" to CI builds --- .../rosetta/{truncatable primes_res => truncatable primes.res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/rosetta/{truncatable primes_res => truncatable primes.res} (100%) diff --git a/examples/rosetta/truncatable primes_res b/examples/rosetta/truncatable primes.res similarity index 100% rename from examples/rosetta/truncatable primes_res rename to examples/rosetta/truncatable primes.res From d04cd6c8135050ccc1d0530f0313a2155be47fd3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:08:00 +0100 Subject: [PATCH 934/984] added "Twin primes" to CI builds --- examples/rosetta/twin primes.res | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 examples/rosetta/twin primes.res diff --git a/examples/rosetta/twin primes.res b/examples/rosetta/twin primes.res new file mode 100644 index 0000000000..f1cbae6930 --- /dev/null +++ b/examples/rosetta/twin primes.res @@ -0,0 +1,6 @@ +From 2 to 10 : there are 3 pairs of twin primes +From 2 to 100 : there are 9 pairs of twin primes +From 2 to 1000 : there are 35 pairs of twin primes +From 2 to 10000 : there are 205 pairs of twin primes +From 2 to 100000 : there are 1224 pairs of twin primes +From 2 to 1000000 : there are 8169 pairs of twin primes \ No newline at end of file From c76fc4cd43915a17126633271d3b0277870049f6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:12:20 +0100 Subject: [PATCH 935/984] fixed RC example --- examples/rosetta/words containing the substring.art | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/rosetta/words containing the substring.art b/examples/rosetta/words containing the substring.art index c8c66be25b..70384752b6 100644 --- a/examples/rosetta/words containing the substring.art +++ b/examples/rosetta/words containing the substring.art @@ -1,3 +1,4 @@ -select read.lines "unixdict.txt" 'l -> - and? contains? l "the" - 11 < size l \ No newline at end of file +print.lines + select read.lines relative "unixdict.txt" 'l -> + and? [11 < size l] + [contains? l "the"] \ No newline at end of file From 61055ec1220e68fad42b49f31a16506058c44be8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:12:33 +0100 Subject: [PATCH 936/984] added "Words containing 'the' substring" to CI builds --- .../words containing the substring.res | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/rosetta/words containing the substring.res diff --git a/examples/rosetta/words containing the substring.res b/examples/rosetta/words containing the substring.res new file mode 100644 index 0000000000..5bcc9ff22d --- /dev/null +++ b/examples/rosetta/words containing the substring.res @@ -0,0 +1,32 @@ +authenticate +chemotherapy +chrysanthemum +clothesbrush +clotheshorse +eratosthenes +featherbedding +featherbrain +featherweight +gaithersburg +hydrothermal +lighthearted +mathematician +neurasthenic +nevertheless +northeastern +northernmost +otherworldly +parasympathetic +physiotherapist +physiotherapy +psychotherapeutic +psychotherapist +psychotherapy +radiotherapy +southeastern +southernmost +theoretician +weatherbeaten +weatherproof +weatherstrip +weatherstripping \ No newline at end of file From 05901a03bb09867c2055716113aad64e5a88008f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:14:26 +0100 Subject: [PATCH 937/984] added "Words from neighbour ones" to CI builds --- .../rosetta/words from neighbour ones.res | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/rosetta/words from neighbour ones.res diff --git a/examples/rosetta/words from neighbour ones.res b/examples/rosetta/words from neighbour ones.res new file mode 100644 index 0000000000..524a254e27 --- /dev/null +++ b/examples/rosetta/words from neighbour ones.res @@ -0,0 +1,24 @@ + 1: applicate + 2: architect + 3: astronomy + 4: christine + 5: christoph + 6: committee + 7: composite + 8: constrict + 9: construct + 10: different + 11: extensive + 12: greenwood + 13: implement + 14: improvise + 15: intercept + 16: interpret + 17: interrupt + 18: philosoph + 19: prescript + 20: receptive + 21: telephone + 22: transcend + 23: transport + 24: transpose \ No newline at end of file From 724992bec4d5a500de96da96159ed819185375ca Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:15:53 +0100 Subject: [PATCH 938/984] removed "Create an HTML table" from CI builds (contains randomization!) --- examples/rosetta/create an html table.res | 1 - 1 file changed, 1 deletion(-) delete mode 100644 examples/rosetta/create an html table.res diff --git a/examples/rosetta/create an html table.res b/examples/rosetta/create an html table.res deleted file mode 100644 index 90019dd0c0..0000000000 --- a/examples/rosetta/create an html table.res +++ /dev/null @@ -1 +0,0 @@ -
XYZ
1867815101074
2610346887520
3984475092354
4916060319363
5420546091578
\ No newline at end of file From b29cf2d9b31622d27aff4664d4744f6f2635510e Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 25 Jan 2023 18:21:43 +0100 Subject: [PATCH 939/984] exclude "Magic constant" & "Square root by hand" from MINI CI builds --- tools/tester.art | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/tester.art b/tools/tester.art index 4ee06ed3d1..0b5348e0b2 100755 --- a/tools/tester.art +++ b/tools/tester.art @@ -33,12 +33,14 @@ canExecute?: function [scri][ "long multiplication" "loops - continue" "lucas-lehmer test" + "magic constant" "modular exponentation" "next special primes" "pell's equation" "permutations - derangements" "sorting algorithms - cycle sort" "sorting algorithms - pancake sort" + "square root by hand" "sylvester's sequence" "trigonometric functions" "ultra useful primes" From 54b48b01cdaf6fa9d3473b19660c499ddd5cd48d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 10:24:50 +0100 Subject: [PATCH 940/984] force rebuild --- tools/tester.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tester.art b/tools/tester.art index 0b5348e0b2..399ad1dbff 100755 --- a/tools/tester.art +++ b/tools/tester.art @@ -47,7 +47,7 @@ canExecute?: function [scri][ "unicode strings" "wieferich primes" "xml - input" - ] -> return false + ] -> return false ] if sys\release='full [ From 7fc138fef1f2b25746163b60c5069b8669d1f95b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 10:36:34 +0100 Subject: [PATCH 941/984] disable RC test (see: #975) --- examples/rosetta/{hamming numbers.res => hamming numbers_res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/rosetta/{hamming numbers.res => hamming numbers_res} (100%) diff --git a/examples/rosetta/hamming numbers.res b/examples/rosetta/hamming numbers_res similarity index 100% rename from examples/rosetta/hamming numbers.res rename to examples/rosetta/hamming numbers_res From e7c95b75a01f6cfeb5777ca9c6d966c9ef008423 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 10:36:46 +0100 Subject: [PATCH 942/984] disabled RC test (see: #976) --- examples/rosetta/{magic constant.res => magic constant_res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/rosetta/{magic constant.res => magic constant_res} (100%) diff --git a/examples/rosetta/magic constant.res b/examples/rosetta/magic constant_res similarity index 100% rename from examples/rosetta/magic constant.res rename to examples/rosetta/magic constant_res From 3f819f65d2576593e5f011919b852e92dee3eee8 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 10:37:05 +0100 Subject: [PATCH 943/984] disabled RC test (see: #977) --- examples/rosetta/{pell's equation.res => pell's equation_res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/rosetta/{pell's equation.res => pell's equation_res} (100%) diff --git a/examples/rosetta/pell's equation.res b/examples/rosetta/pell's equation_res similarity index 100% rename from examples/rosetta/pell's equation.res rename to examples/rosetta/pell's equation_res From 29e6abdad10f91617562eb503b587f7c6ed7714f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 10:50:35 +0100 Subject: [PATCH 944/984] disabled RC test (see: #978) --- .../rosetta/{square root by hand.res => square root by hand_res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/rosetta/{square root by hand.res => square root by hand_res} (100%) diff --git a/examples/rosetta/square root by hand.res b/examples/rosetta/square root by hand_res similarity index 100% rename from examples/rosetta/square root by hand.res rename to examples/rosetta/square root by hand_res From 300750b2eb372877c58d35a6ed3de7b3e17624c6 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 10:50:48 +0100 Subject: [PATCH 945/984] disabled RC test (see: #979) --- .../{sylvester's sequence.res => sylvester's sequence_res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/rosetta/{sylvester's sequence.res => sylvester's sequence_res} (100%) diff --git a/examples/rosetta/sylvester's sequence.res b/examples/rosetta/sylvester's sequence_res similarity index 100% rename from examples/rosetta/sylvester's sequence.res rename to examples/rosetta/sylvester's sequence_res From 19f6831953d550d36d5133a273cc8aa70b7c8547 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:13:26 +0100 Subject: [PATCH 946/984] added TODO --- src/vm/eval.nim | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 79c342ebf5..1cd83957a9 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -196,6 +196,60 @@ func doesNotContainBranching(node: Node): bool {.enforceNoRaises.} = # Optimization #------------------------ +# TODO(VM/eval) optimize conditionals combined with `and?` +# Not sure what the benefit-to-effort ratio of this proposal would be, +# but we could definitely optimize this type of scenario. +# +# For example, right now, `if? x = 2 -> print "X is 2" else -> "X is not 2"` +# would lead to pseudo-bytecode looking like this: +# ``` +# push 2 +# load x +# jump_if_not_equal_to else +# push "X is 2" +# print +# else: +# push "X is not 2" +# print +# ``` +# +# Now, what if there is lazy `and?` involved? +# E.g. `if? and? [x = 2][y = 3] -> print "YES" -> print "NO"` +# +# Right now, it produces something like: +# ``` +# push [y=3] +# push [x=2] +# and +# jump_if_not +# push "YES" +# print +# else: +# push "NO" +# print +# ``` +# +# This could/should produce bytecode like this: +# ``` +# push 2 +# load x +# jump_if_not_equal_to else +# push 3 +# load y +# jump_if_not_equal_to else +# push "YES" +# print +# else: +# push "NO" +# print +# ``` +# +# The produced/suggested bytecode is longer but it should be faster, +# given that there'll be no implicit function calls; but just linear, +# more cache-friendly code to just jump through. +# +# labels: vm, evaluator, enhancement, open discussion + template optimizeConditional( consts: var ValueArray, it: var VBinary, From ca39ccd3c7a7366d271a5ddbefbf80999ac1f508 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:22:08 +0100 Subject: [PATCH 947/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 50b58d88e6..2fc5a282ba 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4037 \ No newline at end of file +4038 \ No newline at end of file From 672739bf52bbab01e913ba40d36355257b6d03bd Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:25:15 +0100 Subject: [PATCH 948/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2fc5a282ba..d2930788e5 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4038 \ No newline at end of file +4039 \ No newline at end of file From 2f0c3a0562cffcf4c5285911e55b84ccf6888913 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:26:56 +0100 Subject: [PATCH 949/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index d2930788e5..be87a61385 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4039 \ No newline at end of file +4040 \ No newline at end of file From 5b9720ca580478a02c8cb1e5826021fedcd4a33b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:28:16 +0100 Subject: [PATCH 950/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index be87a61385..f7f5dbcb6a 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4040 \ No newline at end of file +4041 \ No newline at end of file From 95bc13c7572d985ff8a8947958ccb9453ab583d1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:30:53 +0100 Subject: [PATCH 951/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index f7f5dbcb6a..6891674281 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4041 \ No newline at end of file +4042 \ No newline at end of file From cb84119d3f58f813c1dfc9fdc884be0ecff466c7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:32:11 +0100 Subject: [PATCH 952/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 6891674281..0cb4e88121 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4042 \ No newline at end of file +4043 \ No newline at end of file From 855bc239e5e977cfd7b92530f8bb14a5fe5d31dc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:33:54 +0100 Subject: [PATCH 953/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 0cb4e88121..8c1dae6b54 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4043 \ No newline at end of file +4044 \ No newline at end of file From 414273998c6e185552ac883c4a5c1ad09694be63 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:42:51 +0100 Subject: [PATCH 954/984] re-enabled Evaluator-related unit-test --- tests/unittests/{evaluator_res => evaluator.res} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unittests/{evaluator_res => evaluator.res} (100%) diff --git a/tests/unittests/evaluator_res b/tests/unittests/evaluator.res similarity index 100% rename from tests/unittests/evaluator_res rename to tests/unittests/evaluator.res From c38a2d9df8c854d4eefda2c1f3228c7b95dbb3bc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:55:38 +0100 Subject: [PATCH 955/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8c1dae6b54..2e365a3579 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4044 \ No newline at end of file +4045 \ No newline at end of file From b94983b3d5791e0646f2842addd8389af7fcb497 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:57:08 +0100 Subject: [PATCH 956/984] VM/bytecode: remove all "optimization" routines; they didn't do anything really valuable, nor were they in use + part of them has already been incorporated into the evaluator itself --- src/vm/bytecode.nim | 102 +------------------------------------------- 1 file changed, 1 insertion(+), 101 deletions(-) diff --git a/src/vm/bytecode.nim b/src/vm/bytecode.nim index e34e0a31a8..8b1e10d034 100644 --- a/src/vm/bytecode.nim +++ b/src/vm/bytecode.nim @@ -17,115 +17,18 @@ when not defined(WEB): import extras/miniz -import os - import opcodes export opcodes -import vm/values/value - -import vm/values/custom/[vbinary] - #======================================= # Constants #======================================= -const - #opPushAny = opPush0..opPush13 - #opStoreAny = opStore0..opStore13 - opLoadAny = opLoad0..opLoad13 - #opCallAny = opCall0..opCall13 - when not defined(WEB): const BcodeMagic = uint32(0x86BC0DE0) BcodeMagicCompressed = uint32(0x86BC0DE1) -#======================================= -# Helpers -#======================================= - -template Op(sth: untyped): untyped = OpCode(sth) -template By(sth: untyped): untyped = Byte(sth) - -template skip(steps: int): untyped = - i.inc(steps) - -template current(): untyped = a[i] -template next(): untyped = - while Op(a[i+1]) in {opEol,opEolX}: - if Op(a[i+1])==opEol: skip(2) - else: skip(3) - a[i+1] - -template consume(num: int = 1): untyped = - result[p] = a[initialI] - when num > 1: - result[p+1] = a[initialI+1] - when num > 2: - result[p+2] = a[initialI+2] - p.inc(num) - i.inc(num) - -template inject(what: untyped): untyped = - result[p] = what - p.inc() - -template keep(): untyped = - result[p] = current() - p.inc() - -proc optimize(trans: Translation): VBinary = - let a = trans.instructions - var i = 0 - var p = 0 - let aLen = a.len - newSeq(result, aLen) - while i < aLen: - let initial = current - let initialI = i - #echo fmt"I = {i} -> {Op(initial)}" - case Op(initial): - of opStore0..opStore13: - if Op(next) in opLoadAny and By(opLoad)-a[i+1]==By(opStore)-initial: - # (opStore*) + (opLoad*) -> (opStorl*) - inject(): By(opStorl0) + initial - By(opStore0) - skip(2) - else: - consume(1) - of opPush0..opPush13, opLoad0..opLoad13: - if Op(next) == Op(initial): - # (opPush/opLoad*) x N -> (opPush/opLoad*) + (opDup) x N - keep() - while Op(next) == Op(initial): - inject(): By(opDup) - skip(1) - skip(1) - else: - consume(1) - - # of opCall0..opCall29: - # let idx = initial - By(opCall0) - # echo fmt"found opCall* -> {idx}" - # if d[idx].kind==Word and Syms[d[idx].s] == AddF: - # inject(): By(opIAdd) - # skip(1) - # else: - # consume(1) - - of opPush,opStore,opLoad,opCall,opStorl,opAttr: - consume(2) - of opPushX,opStoreX,opLoadX,opCallX,opStorlX: - consume(3) - of opEol: - skip(2) - of opEolX: - skip(3) - else: - consume(1) - - result.setLen(p) - #======================================= # Methods #======================================= @@ -186,7 +89,4 @@ proc readBytecode*(origin: string): (string, seq[byte]) = return (dataSegment, codeSegment) # return the result else: - discard - -proc optimizeBytecode*(t: Translation): seq[byte] = - result = optimize(t) \ No newline at end of file + discard \ No newline at end of file From b90ab576df81daa72964116e0632a7b874f3bc96 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:57:48 +0100 Subject: [PATCH 957/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 2e365a3579..14964db92d 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4045 \ No newline at end of file +4046 \ No newline at end of file From 01f90872d5c790588c7404df264696e589261e33 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 12:58:32 +0100 Subject: [PATCH 958/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 14964db92d..b52b8b6377 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4046 \ No newline at end of file +4047 \ No newline at end of file From 0576ab3d2fcc25ebd07282437ec9deca1af4798b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:00:05 +0100 Subject: [PATCH 959/984] Converters: removed "optimization"-related code altogether --- src/library/Converters.nim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/library/Converters.nim b/src/library/Converters.nim index 5b038ceadf..a5e3ee7415 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -390,8 +390,6 @@ proc convertedValueToType(x, y: Value, tp: ValueKind, aFormat:Value = nil): Valu of Bytecode: var evaled = doEval(y) - if (hadAttr("optimized")): - evaled = Translation(constants: evaled.constants, instructions: optimizeBytecode(evaled)) return newBytecode(evaled) @@ -413,8 +411,6 @@ proc convertedValueToType(x, y: Value, tp: ValueKind, aFormat:Value = nil): Valu throwCannotConvert() of Bytecode: var evaled = Translation(constants: y.d["data"].a, instructions: y.d["code"].a.map(proc (x:Value):byte = byte(x.i))) - if (hadAttr("optimized")): - evaled.instructions = optimizeBytecode(evaled) return newBytecode(evaled) else: From d7629804732a5dc397b0fe5d71fe5dbabf087202 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:04:32 +0100 Subject: [PATCH 960/984] Converters/to: [Bytecode] removed `optimized` option & added new `intrepid` option (generate Bytecode without error-line tracking) --- src/library/Converters.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/Converters.nim b/src/library/Converters.nim index a5e3ee7415..1e3fe8102b 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -1333,7 +1333,7 @@ proc defineSymbols*() = attrs = { "format" : ({String},"use given format (for dates or floating-point numbers)"), "unit" : ({String,Literal},"use given unit (for quantities)"), - "optimized" : ({Logical},"convert to optimized bytecode"), + "intrepid" : ({Logical},"convert to bytecode without error-line tracking"), "hsl" : ({Logical},"convert HSL block to color"), "hsv" : ({Logical},"convert HSV block to color") }, From 990bbb252bc8646d3be89ece883c068d670df892 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:04:54 +0100 Subject: [PATCH 961/984] VM/eval: add `omitNewlines` option to `doEval` & `processBlock` --- src/vm/eval.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 1cd83957a9..7cce6bea41 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -377,7 +377,7 @@ template optimizeConditional( # Methods #======================================= -proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDictionary=false) = +proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDictionary=false, omitNewlines: bool = false) = let nLen = blok.children.len var i = 0 @@ -466,7 +466,8 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of RootNode: discard of NewlineNode: - addEol(instruction.line) + if not omitNewlines: + addEol(instruction.line) of ConstantValue: var alreadyPut = false let iv {.cursor.} = instruction.value @@ -543,7 +544,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti # Main #======================================= -proc doEval*(root: Value, isDictionary=false, isFunctionBlock=false, useStored: static bool = true): Translation {.inline.} = +proc doEval*(root: Value, isDictionary=false, isFunctionBlock=false, omitNewlines=false, useStored: static bool = true): Translation {.inline.} = ## Take a parsed Block of values and return its Translation - ## that is: the constants found + the list of bytecode instructions @@ -558,7 +559,7 @@ proc doEval*(root: Value, isDictionary=false, isFunctionBlock=false, useStored: var consts: ValueArray var it: VBinary - evaluateBlock(generateAst(root, asDictionary=isDictionary, asFunction=isFunctionBlock), consts, it, isDictionary=isDictionary) + evaluateBlock(generateAst(root, asDictionary=isDictionary, asFunction=isFunctionBlock), consts, it, isDictionary=isDictionary, omitNewlines=omitNewlines) it.add(byte(opEnd)) result = Translation(constants: consts, instructions: it) From d70148221fafb8e89262aa0a1bb2fbbe0b5e9191 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:06:18 +0100 Subject: [PATCH 962/984] Converters/to: make use of newly-added `.intrepid` option --- src/library/Converters.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/Converters.nim b/src/library/Converters.nim index 1e3fe8102b..242fc25926 100644 --- a/src/library/Converters.nim +++ b/src/library/Converters.nim @@ -389,7 +389,7 @@ proc convertedValueToType(x, y: Value, tp: ValueKind, aFormat:Value = nil): Valu return newBinary(res) of Bytecode: - var evaled = doEval(y) + var evaled = doEval(y, omitNewlines=hadAttr("intrepid")) return newBytecode(evaled) From 37a240939153a04968382a4ea6faf072a8639914 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:06:42 +0100 Subject: [PATCH 963/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index b52b8b6377..457561c757 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4047 \ No newline at end of file +4048 \ No newline at end of file From 0a74375513f3c5b2b2c30fc4ee221fe9661a5912 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:07:34 +0100 Subject: [PATCH 964/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 457561c757..8132019780 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4048 \ No newline at end of file +4049 \ No newline at end of file From f980ed9d112e7f4a98ccf5e9465da421cc6bd403 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:07:46 +0100 Subject: [PATCH 965/984] VM/eval: mark as "likely" --- src/vm/eval.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 7cce6bea41..7e089a9a7a 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -466,7 +466,7 @@ proc evaluateBlock*(blok: Node, consts: var ValueArray, it: var VBinary, isDicti of RootNode: discard of NewlineNode: - if not omitNewlines: + if likely(not omitNewlines): addEol(instruction.line) of ConstantValue: var alreadyPut = false From 0a39653a44d9d7bd78b5734adae62f9c3aed0eb0 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:25:22 +0100 Subject: [PATCH 966/984] make use of new `.intrepid` option --- tests/unittests/evaluator.art | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index a8e1e82322..74be9da9ba 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -21,10 +21,10 @@ topic: function [title][ ] byteCode: function [blk][ - btc: to :bytecode blk ++ [] ; this little hack is needed to remove newlines from our block + btc: to.intrepid :bytecode blk ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - ;inspect btc ; uncomment this line to see the bytecode + ;inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] From 9e114b65a63db45a15e6b066ab3a41689809e194 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:29:33 +0100 Subject: [PATCH 967/984] updated built-in function calls --- tests/unittests/evaluator.art | 16 +-- tests/unittests/evaluator.res | 200 +++++++++++++++++----------------- 2 files changed, 108 insertions(+), 108 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 74be9da9ba..d785cdfdac 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to.intrepid :bytecode blk ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - ;inspect btc ; uncomment this line to see the bytecode + inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] @@ -574,22 +574,22 @@ supersection "FUNCTION CALLS" ; ================================ ; DATA ; ================================ - ; 0: couple :word + ; 0: [ :block + ; one :string + ; two :string + ; ] ; 1: [ :block ; 1 :integer ; 2 :integer ; ] - ; 2: [ :block - ; one :string - ; two :string - ; ] + ; 2: couple :word ; ================================ ; CODE ; ================================ - ; push2 + ; push0 ; push1 - ; call0 + ; call2 ; end ;***************************************************************** diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 048f25cb39..a9a6a30c1c 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -10,15 +10,15 @@ input: [true] data: [] - code: [21 211] (2 bytes) + code: [21 218] (2 bytes) input: [false] data: [] - code: [22 211] (2 bytes) + code: [22 218] (2 bytes) input: [maybe] data: [maybe] - code: [64 211] (2 bytes) + code: [64 218] (2 bytes) >-------------------------------------------------- @@ -27,19 +27,19 @@ input: [1] data: [] - code: [1 211] (2 bytes) + code: [2 218] (2 bytes) input: [10] data: [] - code: [10 211] (2 bytes) + code: [11 218] (2 bytes) input: [123] data: [123] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [1234567890123] data: [1234567890123] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -48,19 +48,19 @@ input: [0.0] data: [] - code: [17 211] (2 bytes) + code: [18 218] (2 bytes) input: [1.0] data: [] - code: [18 211] (2 bytes) + code: [19 218] (2 bytes) input: [10.0] data: [10.0] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [12345.1234567] data: [12345.1234567] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -69,11 +69,11 @@ input: [`a`] data: [a] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [`πŸ˜€`] data: [πŸ˜€] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -82,11 +82,11 @@ input: [""] data: [] - code: [24 211] (2 bytes) + code: [24 218] (2 bytes) input: ["Hello World!"] data: [Hello World!] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -95,11 +95,11 @@ input: [{/hello/}] data: [hello] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [{/[A-Z]+\d/}] data: [[A-Z]+\d] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -108,11 +108,11 @@ input: [:integer] data: [:integer] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [:string] data: [:string] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -121,11 +121,11 @@ input: ['a] data: [a] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: ['a 'b 'c] data: [a b c] - code: [32 33 34 211] (4 bytes) + code: [32 33 34 218] (4 bytes) >-------------------------------------------------- @@ -134,11 +134,11 @@ input: ['+] data: [+] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: ['-->] data: [-->] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -147,11 +147,11 @@ input: [#FF0000] data: [#FF0000] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [#00FF66] data: [#00FF66] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -160,11 +160,11 @@ input: [1:eur] data: [1EUR] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [12:m] data: [12m] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -173,11 +173,11 @@ input: [0.9.82] data: [0.9.82] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [2.0.0-rc1] data: [2.0.0-rc1] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -186,11 +186,11 @@ input: [[]] data: [] - code: [25 211] (2 bytes) + code: [25 218] (2 bytes) input: [[1 "hello" 3.14 true]] data: [[1 hello 3.14 true]] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -199,11 +199,11 @@ input: [βˆ…] data: [] - code: [27 211] (2 bytes) + code: [27 218] (2 bytes) input: [null] data: [null] - code: [64 211] (2 bytes) + code: [64 218] (2 bytes) ************************************************** @@ -218,11 +218,11 @@ input: [a: 1] data: [a] - code: [1 48 211] (3 bytes) + code: [2 48 218] (3 bytes) input: [b: 2 c: b] data: [b c] - code: [2 48 64 49 211] (5 bytes) + code: [3 48 64 49 218] (5 bytes) ************************************************** @@ -237,15 +237,15 @@ input: [abs 10] data: [abs] - code: [10 96 211] (3 bytes) + code: [11 96 218] (3 bytes) input: [empty? []] data: [empty?] - code: [25 96 211] (3 bytes) + code: [25 96 218] (3 bytes) input: [couple [1 2] ["one" "two"]] - data: [couple [1 2] [one two]] - code: [34 33 96 211] (4 bytes) + data: [[one two] [1 2] couple] + code: [32 33 98 218] (4 bytes) >-------------------------------------------------- @@ -254,15 +254,15 @@ input: [print 2] data: [] - code: [2 176 211] (3 bytes) + code: [2 176 218] (3 bytes) input: [size [1 2]] data: [[1 2]] - code: [32 169 211] (3 bytes) + code: [32 169 218] (3 bytes) input: [and 1 123] data: [123] - code: [32 1 137 211] (4 bytes) + code: [32 1 137 218] (4 bytes) >-------------------------------------------------- @@ -271,15 +271,15 @@ input: [to :floating 1] data: [:floating] - code: [1 32 157 211] (4 bytes) + code: [1 32 157 218] (4 bytes) input: [to :integer "10"] data: [10] - code: [32 159 211] (3 bytes) + code: [32 159 218] (3 bytes) input: [to :string 5] data: [] - code: [5 158 211] (3 bytes) + code: [5 158 218] (3 bytes) >-------------------------------------------------- @@ -288,15 +288,15 @@ input: [split .words "hello world"] data: [words hello world] - code: [33 21 112 171 211] (5 bytes) + code: [33 21 112 171 218] (5 bytes) input: [split .by: "X" "helloXworld"] data: [by X helloXworld] - code: [34 33 112 171 211] (5 bytes) + code: [34 33 112 171 218] (5 bytes) input: [join .with: "-" ["hello" "world"]] data: [with - [hello world]] - code: [34 33 112 172 211] (5 bytes) + code: [34 33 112 172 218] (5 bytes) >-------------------------------------------------- @@ -305,15 +305,15 @@ input: [@ [1 2 3]] data: [[1 2 3]] - code: [32 162 211] (3 bytes) + code: [32 162 218] (3 bytes) input: ["hello " ++ "world"] data: [append hello world] - code: [34 33 96 211] (4 bytes) + code: [34 33 96 218] (4 bytes) input: [1 .. 25] data: [25] - code: [32 1 165 211] (4 bytes) + code: [32 1 165 218] (4 bytes) >-------------------------------------------------- @@ -322,15 +322,15 @@ input: [h: function [] [print "function called"] print "before" h print "after"] data: [h [print function called] before after] - code: [33 25 164 48 34 176 96 35 176 211] (10 bytes) + code: [33 25 164 48 34 176 96 35 176 218] (10 bytes) input: [f: function [x] [x + 1] print "before" print f 10 print "after"] data: [f [x] [x + 1] before after] - code: [34 33 164 48 35 176 10 96 176 36 176 211] (12 bytes) + code: [34 33 164 48 35 176 10 96 176 36 176 218] (12 bytes) input: [g: $ [z w] [2 * z * w] print "before" print g 10 20 print "after"] data: [g [z w] [2 * z * w] before 20 after] - code: [34 33 164 48 35 176 36 10 96 176 37 176 211] (13 bytes) + code: [34 33 164 48 35 176 36 10 96 176 37 176 218] (13 bytes) ************************************************** @@ -345,19 +345,19 @@ input: [a\0] data: [a] - code: [0 64 160 211] (4 bytes) + code: [0 64 160 218] (4 bytes) input: [user\name] data: [user name] - code: [33 64 160 211] (4 bytes) + code: [33 64 160 218] (4 bytes) input: [user\grades\0] data: [user grades] - code: [0 33 64 160 160 211] (6 bytes) + code: [0 33 64 160 160 218] (6 bytes) input: [user\address\country] data: [user address country] - code: [34 33 64 160 160 211] (6 bytes) + code: [34 33 64 160 160 218] (6 bytes) >-------------------------------------------------- @@ -366,19 +366,19 @@ input: [a\0: 10] data: [a] - code: [10 0 64 161 211] (5 bytes) + code: [10 0 64 161 218] (5 bytes) input: [user\name: "John"] data: [user name John] - code: [34 33 64 161 211] (5 bytes) + code: [34 33 64 161 218] (5 bytes) input: [user\grades\0: 6] data: [user grades] - code: [6 0 33 64 160 161 211] (7 bytes) + code: [6 0 33 64 160 161 218] (7 bytes) input: [user\address\country: "USA"] data: [user address country USA] - code: [35 34 33 64 160 161 211] (7 bytes) + code: [35 34 33 64 160 161 218] (7 bytes) ************************************************** @@ -393,11 +393,11 @@ input: [(print 2)] data: [] - code: [2 176 211] (3 bytes) + code: [2 176 218] (3 bytes) input: [(print 2) (print 3)] data: [] - code: [2 176 3 176 211] (5 bytes) + code: [2 176 3 176 218] (5 bytes) >-------------------------------------------------- @@ -406,7 +406,7 @@ input: [print 2 do :: print 3] data: [do [print 3]] - code: [2 176 33 96 211] (5 bytes) + code: [2 176 33 96 218] (5 bytes) >-------------------------------------------------- @@ -415,15 +415,15 @@ input: [-> "hello"] data: [[hello]] - code: [32 211] (2 bytes) + code: [32 218] (2 bytes) input: [do -> print "hello" print "done"] data: [do [print hello] done] - code: [33 96 34 176 211] (5 bytes) + code: [33 96 34 176 218] (5 bytes) input: [a: -> upper "hello" b: -> "hello " ++ world] data: [a [upper hello] b [hello ++ world]] - code: [33 48 35 50 211] (5 bytes) + code: [33 48 35 50 218] (5 bytes) >-------------------------------------------------- @@ -432,15 +432,15 @@ input: [=> "hello"] data: [[] [hello]] - code: [32 33 211] (3 bytes) + code: [32 33 218] (3 bytes) input: [f: function => print] data: [f function [_0] [print _0]] - code: [35 34 97 48 211] (5 bytes) + code: [35 34 97 48 218] (5 bytes) input: [adder: $ => add] data: [adder function [_0 _1] [add _0 _1]] - code: [35 34 97 48 211] (5 bytes) + code: [35 34 97 48 218] (5 bytes) >-------------------------------------------------- @@ -449,7 +449,7 @@ input: [2 | print] data: [print] - code: [2 96 211] (3 bytes) + code: [2 96 218] (3 bytes) ************************************************** @@ -464,27 +464,27 @@ input: [add 2 3] data: [] - code: [3 2 128 211] (4 bytes) + code: [3 2 128 218] (4 bytes) input: [2 + 3] data: [] - code: [3 2 128 211] (4 bytes) + code: [3 2 128 218] (4 bytes) input: [add 1 2] data: [] - code: [2 174 211] (3 bytes) + code: [2 174 218] (3 bytes) input: [1 + 2] data: [] - code: [2 174 211] (3 bytes) + code: [2 174 218] (3 bytes) input: [add 2 1] data: [] - code: [2 174 211] (3 bytes) + code: [2 174 218] (3 bytes) input: [2 + 1] data: [] - code: [2 174 211] (3 bytes) + code: [2 174 218] (3 bytes) >-------------------------------------------------- @@ -493,19 +493,19 @@ input: [sub 3 2] data: [] - code: [2 3 129 211] (4 bytes) + code: [2 3 129 218] (4 bytes) input: [3 - 2] data: [] - code: [2 3 129 211] (4 bytes) + code: [2 3 129 218] (4 bytes) input: [sub 2 1] data: [] - code: [2 175 211] (3 bytes) + code: [2 175 218] (3 bytes) input: [2 - 1] data: [] - code: [2 175 211] (3 bytes) + code: [2 175 218] (3 bytes) >-------------------------------------------------- @@ -514,23 +514,23 @@ input: [print "before" if x [print "here" return true] print "after"] data: [before x [print here return true] here after] - code: [32 176 65 198 0 4 35 176 21 156 36 176 211] (13 bytes) + code: [32 176 65 198 0 4 35 176 21 156 36 176 218] (13 bytes) input: [print "before" if not? x [print "here" return false] print "after"] data: [before x [print here return false] here after] - code: [32 176 65 197 0 4 35 176 22 156 36 176 211] (13 bytes) + code: [32 176 65 197 0 4 35 176 22 156 36 176 218] (13 bytes) input: [print "before" if x = 2 [print "here" return true] print "after"] data: [before x [print here return true] here after] - code: [32 176 2 65 200 0 4 35 176 21 156 36 176 211] (14 bytes) + code: [32 176 2 65 200 0 4 35 176 21 156 36 176 218] (14 bytes) input: [print "before" if x > 2 [print "here" return true] print "after"] data: [before x [print here return true] here after] - code: [32 176 2 65 204 0 4 35 176 21 156 36 176 211] (14 bytes) + code: [32 176 2 65 204 0 4 35 176 21 156 36 176 218] (14 bytes) input: [print "before" if x =< 2 [print "here" return true] print "after"] data: [before x [print here return true] here after] - code: [32 176 2 65 201 0 4 35 176 21 156 36 176 211] (14 bytes) + code: [32 176 2 65 201 0 4 35 176 21 156 36 176 218] (14 bytes) >-------------------------------------------------- @@ -539,23 +539,23 @@ input: [print "before" unless x [print "here" return false] print "after"] data: [before x [print here return false] here after] - code: [32 176 65 197 0 4 35 176 22 156 36 176 211] (13 bytes) + code: [32 176 65 197 0 4 35 176 22 156 36 176 218] (13 bytes) input: [print "before" unless not? x [print "here" return true] print "after"] data: [before x [print here return true] here after] - code: [32 176 65 198 0 4 35 176 21 156 36 176 211] (13 bytes) + code: [32 176 65 198 0 4 35 176 21 156 36 176 218] (13 bytes) input: [print "before" unless x = 2 [print "here" return false] print "after"] data: [before x [print here return false] here after] - code: [32 176 2 65 199 0 4 35 176 22 156 36 176 211] (14 bytes) + code: [32 176 2 65 199 0 4 35 176 22 156 36 176 218] (14 bytes) input: [print "before" unless x > 2 [print "here" return false] print "after"] data: [before x [print here return false] here after] - code: [32 176 2 65 201 0 4 35 176 22 156 36 176 211] (14 bytes) + code: [32 176 2 65 201 0 4 35 176 22 156 36 176 218] (14 bytes) input: [print "before" unless x =< 2 [print "here" return false] print "after"] data: [before x [print here return false] here after] - code: [32 176 2 65 204 0 4 35 176 22 156 36 176 211] (14 bytes) + code: [32 176 2 65 204 0 4 35 176 22 156 36 176 218] (14 bytes) >-------------------------------------------------- @@ -564,11 +564,11 @@ input: [if? x [return true] else [return false]] data: [x [return true] [return false]] - code: [64 198 0 5 21 156 208 0 2 22 156 211] (12 bytes) + code: [64 198 0 5 21 156 208 0 2 22 156 218] (12 bytes) input: [print "before" if? a <> 1 + 2 [print "here" return true] else [print "there" return false] print "after"] data: [before a [print here return true] here [print there return false] there after] - code: [32 176 2 1 128 65 199 0 7 35 176 21 156 208 0 4 37 176 22 156 38 176 211] (23 bytes) + code: [32 176 2 1 128 65 199 0 7 35 176 21 156 208 0 4 37 176 22 156 38 176 218] (23 bytes) >-------------------------------------------------- @@ -577,23 +577,23 @@ input: [print "before" switch a [1] [2] print "after"] data: [before a [1] [2] after] - code: [32 176 65 198 0 4 1 208 0 1 2 36 176 211] (14 bytes) + code: [32 176 65 198 0 4 1 208 0 1 2 36 176 218] (14 bytes) input: [(x = 1) ? -> 1 -> 2] data: [x [1] [2]] - code: [1 64 200 0 4 1 208 0 1 2 211] (11 bytes) + code: [1 64 200 0 4 1 208 0 1 2 218] (11 bytes) input: [print "before" return (x < 1) ? -> true -> false print "after"] data: [before x [true] [false] after] - code: [32 176 1 65 202 0 4 21 208 0 1 22 156 36 176 211] (16 bytes) + code: [32 176 1 65 202 0 4 21 208 0 1 22 156 36 176 218] (16 bytes) input: [print "before" z: (x < 1) ? -> true -> false print "after"] data: [before z x [true] [false] after] - code: [32 176 1 66 202 0 4 21 208 0 1 22 49 37 176 211] (16 bytes) + code: [32 176 1 66 202 0 4 21 208 0 1 22 49 37 176 218] (16 bytes) input: [print "before" z: 3 + (x >= 1) ? -> 1 -> 2 print "after"] data: [before z x [1] [2] after] - code: [32 176 1 66 203 0 4 1 208 0 1 2 3 128 49 37 176 211] (18 bytes) + code: [32 176 1 66 203 0 4 1 208 0 1 2 3 128 49 37 176 218] (18 bytes) >-------------------------------------------------- @@ -602,4 +602,4 @@ input: [while [x = 1] [print "hello"]] data: [[x = 1] [print hello] x hello] - code: [1 66 200 0 5 35 176 209 0 10 211] (11 bytes) \ No newline at end of file + code: [1 66 200 0 5 35 176 209 0 10 218] (11 bytes) \ No newline at end of file From fa10597de5c329bf945689d099220f0d433e487b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:31:11 +0100 Subject: [PATCH 968/984] updated opcode'd built-in function calls --- tests/unittests/evaluator.res | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index a9a6a30c1c..1d11e90753 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -254,15 +254,15 @@ input: [print 2] data: [] - code: [2 176 218] (3 bytes) + code: [3 189 218] (3 bytes) input: [size [1 2]] data: [[1 2]] - code: [32 169 218] (3 bytes) + code: [32 183 218] (3 bytes) input: [and 1 123] data: [123] - code: [32 1 137 218] (4 bytes) + code: [32 2 139 218] (4 bytes) >-------------------------------------------------- From 424cd6665915098739e6df01818d838a9b379432 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:32:50 +0100 Subject: [PATCH 969/984] updated composite opcode'd built-ins --- tests/unittests/evaluator.res | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 1d11e90753..a81b5e3501 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -271,15 +271,15 @@ input: [to :floating 1] data: [:floating] - code: [1 32 157 218] (4 bytes) + code: [2 32 170 218] (4 bytes) input: [to :integer "10"] data: [10] - code: [32 159 218] (3 bytes) + code: [32 172 218] (3 bytes) input: [to :string 5] data: [] - code: [5 158 218] (3 bytes) + code: [6 172 218] (3 bytes) >-------------------------------------------------- From 3e00e4e902248bd6f726e6a4ce016d6e8f98f339 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:38:58 +0100 Subject: [PATCH 970/984] updated symbol-aliased function calls --- tests/unittests/evaluator.art | 35 +++++++++++++++++------------------ tests/unittests/evaluator.res | 22 +++++++++++----------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index d785cdfdac..1ad3579749 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -689,15 +689,15 @@ supersection "FUNCTION CALLS" ; ================================ ; DATA ; ================================ - ; 0: words :attribute - ; 1: hello world :string + ; 0: hello world :string + ; 1: words :attribute ; ================================ ; CODE ; ================================ - ; push1 + ; push0 ; constbt - ; attr0 + ; attr1 ; split ; end @@ -705,16 +705,16 @@ supersection "FUNCTION CALLS" ; ================================ ; DATA ; ================================ - ; 0: by :attributelabel + ; 0: helloXworld :string ; 1: X :string - ; 2: helloXworld :string + ; 2: by :attributelabel ; ================================ ; CODE ; ================================ - ; push2 + ; push0 ; push1 - ; attr0 + ; attr2 ; split ; end @@ -722,19 +722,19 @@ supersection "FUNCTION CALLS" ; ================================ ; DATA ; ================================ - ; 0: with :attributelabel - ; 1: - :string - ; 2: [ :block + ; 0: [ :block ; hello :string ; world :string ; ] + ; 1: - :string + ; 2: with :attributelabel ; ================================ ; CODE ; ================================ - ; push2 + ; push0 ; push1 - ; attr0 + ; attr2 ; join ; end @@ -759,20 +759,19 @@ supersection "FUNCTION CALLS" ; array ; end - byteCode ["hello " ++ "world"] + byteCode ["hello " ++ x] ; ================================ ; DATA ; ================================ - ; 0: append :word + ; 0: x :word ; 1: hello :string - ; 2: world :string ; ================================ ; CODE ; ================================ - ; push2 + ; load0 ; push1 - ; call0 + ; append ; end byteCode [1..25] diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index a81b5e3501..48eb087e66 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -287,16 +287,16 @@ >-------------------------------------------------- input: [split .words "hello world"] - data: [words hello world] - code: [33 21 112 171 218] (5 bytes) + data: [hello world words] + code: [32 21 113 185 218] (5 bytes) input: [split .by: "X" "helloXworld"] - data: [by X helloXworld] - code: [34 33 112 171 218] (5 bytes) + data: [helloXworld X by] + code: [32 33 114 185 218] (5 bytes) input: [join .with: "-" ["hello" "world"]] - data: [with - [hello world]] - code: [34 33 112 172 218] (5 bytes) + data: [[hello world] - with] + code: [32 33 114 186 218] (5 bytes) >-------------------------------------------------- @@ -305,15 +305,15 @@ input: [@ [1 2 3]] data: [[1 2 3]] - code: [32 162 218] (3 bytes) + code: [32 176 218] (3 bytes) - input: ["hello " ++ "world"] - data: [append hello world] - code: [34 33 96 218] (4 bytes) + input: ["hello " ++ x] + data: [x hello ] + code: [64 33 188 218] (4 bytes) input: [1 .. 25] data: [25] - code: [32 1 165 218] (4 bytes) + code: [32 2 179 218] (4 bytes) >-------------------------------------------------- From fd5cac9e045cd104a6f9d02383ebbd26053a3d87 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:42:51 +0100 Subject: [PATCH 971/984] updated path values --- tests/unittests/evaluator.art | 68 +++++++++++++++++------------------ tests/unittests/evaluator.res | 24 ++++++------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 1ad3579749..061b18048a 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -802,24 +802,24 @@ supersection "FUNCTION CALLS" ; ================================ ; DATA ; ================================ - ; 0: h :label - ; 1: [ :block + ; 0: [ :block ; print :word ; function called :string ; ] + ; 1: h :label ; 2: before :string ; 3: after :string ; ================================ ; CODE ; ================================ - ; push1 + ; push0 ; consta ; func - ; store0 + ; store1 ; push2 ; print - ; call0 + ; call1 ; push3 ; print ; end @@ -834,29 +834,29 @@ supersection "FUNCTION CALLS" ; ================================ ; DATA ; ================================ - ; 0: f :label - ; 1: [ :block - ; x :word - ; ] - ; 2: [ :block + ; 0: [ :block ; x :word ; + :symbol ; 1 :integer ; ] + ; 1: [ :block + ; x :word + ; ] + ; 2: f :label ; 3: before :string ; 4: after :string ; ================================ ; CODE ; ================================ - ; push2 + ; push0 ; push1 ; func - ; store0 + ; store2 ; push3 ; print ; consti10 - ; call0 + ; call2 ; print ; push4 ; print @@ -873,18 +873,18 @@ supersection "FUNCTION CALLS" ; ================================ ; DATA ; ================================ - ; 0: g :label - ; 1: [ :block - ; z :word - ; w :word - ; ] - ; 2: [ :block + ; 0: [ :block ; 2 :integer ; * :symbol ; z :word ; * :symbol ; w :word ; ] + ; 1: [ :block + ; z :word + ; w :word + ; ] + ; 2: g :label ; 3: before :string ; 4: 20 :integer ; 5: after :string @@ -892,15 +892,15 @@ supersection "FUNCTION CALLS" ; ================================ ; CODE ; ================================ - ; push2 + ; push0 ; push1 ; func - ; store0 + ; store2 ; push3 ; print ; push4 ; consti10 - ; call0 + ; call2 ; print ; push5 ; print @@ -932,14 +932,14 @@ supersection "PATHS" ; ================================ ; DATA ; ================================ - ; 0: user :word - ; 1: name :literal + ; 0: name :literal + ; 1: user :word ; ================================ ; CODE ; ================================ - ; push1 - ; load0 + ; push0 + ; load1 ; get ; end @@ -947,15 +947,15 @@ supersection "PATHS" ; ================================ ; DATA ; ================================ - ; 0: user :word - ; 1: grades :literal + ; 0: grades :literal + ; 1: user :word ; ================================ ; CODE ; ================================ ; consti0 - ; push1 - ; load0 + ; push0 + ; load1 ; get ; get ; end @@ -964,16 +964,16 @@ supersection "PATHS" ; ================================ ; DATA ; ================================ - ; 0: user :word + ; 0: country :literal ; 1: address :literal - ; 2: country :literal + ; 2: user :word ; ================================ ; CODE ; ================================ - ; push2 + ; push0 ; push1 - ; load0 + ; load2 ; get ; get ; end diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 48eb087e66..f15c4fc365 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -321,16 +321,16 @@ >-------------------------------------------------- input: [h: function [] [print "function called"] print "before" h print "after"] - data: [h [print function called] before after] - code: [33 25 164 48 34 176 96 35 176 218] (10 bytes) + data: [[print function called] h before after] + code: [32 25 178 49 34 189 97 35 189 218] (10 bytes) input: [f: function [x] [x + 1] print "before" print f 10 print "after"] - data: [f [x] [x + 1] before after] - code: [34 33 164 48 35 176 10 96 176 36 176 218] (12 bytes) + data: [[x + 1] [x] f before after] + code: [32 33 178 50 35 189 11 98 189 36 189 218] (12 bytes) input: [g: $ [z w] [2 * z * w] print "before" print g 10 20 print "after"] - data: [g [z w] [2 * z * w] before 20 after] - code: [34 33 164 48 35 176 36 10 96 176 37 176 218] (13 bytes) + data: [[2 * z * w] [z w] g before 20 after] + code: [32 33 178 50 35 189 36 11 98 189 37 189 218] (13 bytes) ************************************************** @@ -345,19 +345,19 @@ input: [a\0] data: [a] - code: [0 64 160 218] (4 bytes) + code: [1 64 153 218] (4 bytes) input: [user\name] data: [user name] - code: [33 64 160 218] (4 bytes) + code: [33 65 153 218] (4 bytes) input: [user\grades\0] - data: [user grades] - code: [0 33 64 160 160 218] (6 bytes) + data: [grades user] + code: [1 32 65 153 153 218] (6 bytes) input: [user\address\country] - data: [user address country] - code: [34 33 64 160 160 218] (6 bytes) + data: [country address user] + code: [32 33 66 153 153 218] (6 bytes) >-------------------------------------------------- From 7c79b95985f84d61e1ecbadb2fd2c6db00cc2a4b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:47:36 +0100 Subject: [PATCH 972/984] updated -> inline blocks + added previously-non-working test(!) --- tests/unittests/evaluator.art | 32 ++++++++++++++++---------------- tests/unittests/evaluator.res | 22 +++++++++++++--------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 061b18048a..997445eac8 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1001,16 +1001,16 @@ supersection "PATHS" ; ================================ ; DATA ; ================================ - ; 0: user :word + ; 0: John :string ; 1: name :literal - ; 2: John :string + ; 2: user :word ; ================================ ; CODE ; ================================ - ; push2 + ; push0 ; push1 - ; load0 + ; load2 ; set ; end @@ -1018,16 +1018,16 @@ supersection "PATHS" ; ================================ ; DATA ; ================================ - ; 0: user :word - ; 1: grades :literal + ; 0: grades :literal + ; 1: user :word ; ================================ ; CODE ; ================================ ; consti6 ; consti0 - ; push1 - ; load0 + ; push0 + ; load1 ; get ; set ; end @@ -1036,18 +1036,18 @@ supersection "PATHS" ; ================================ ; DATA ; ================================ - ; 0: user :word - ; 1: address :literal - ; 2: country :literal - ; 3: USA :string + ; 0: USA :string + ; 1: country :literal + ; 2: address :literal + ; 3: user :word ; ================================ ; CODE ; ================================ - ; push3 - ; push2 + ; push0 ; push1 - ; load0 + ; push2 + ; load3 ; get ; set ; end @@ -1087,7 +1087,7 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; end ; TODO: this is not working!!! (see #804) - ; byteCode [(print 2 print 3)] + byteCode [(print 2 print 3)] ; ================================ ; DATA ; ================================ diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index f15c4fc365..171b068fca 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -366,19 +366,19 @@ input: [a\0: 10] data: [a] - code: [10 0 64 161 218] (5 bytes) + code: [11 1 64 154 218] (5 bytes) input: [user\name: "John"] - data: [user name John] - code: [34 33 64 161 218] (5 bytes) + data: [John name user] + code: [32 33 66 154 218] (5 bytes) input: [user\grades\0: 6] - data: [user grades] - code: [6 0 33 64 160 161 218] (7 bytes) + data: [grades user] + code: [7 1 32 65 153 154 218] (7 bytes) input: [user\address\country: "USA"] - data: [user address country USA] - code: [35 34 33 64 160 161 218] (7 bytes) + data: [USA country address user] + code: [32 33 34 67 153 154 218] (7 bytes) ************************************************** @@ -393,11 +393,15 @@ input: [(print 2)] data: [] - code: [2 176 218] (3 bytes) + code: [3 189 218] (3 bytes) input: [(print 2) (print 3)] data: [] - code: [2 176 3 176 218] (5 bytes) + code: [3 189 4 189 218] (5 bytes) + + input: [(print 2 print 3)] + data: [] + code: [3 189 4 189 218] (5 bytes) >-------------------------------------------------- From 7f4f9d8b41c06e477db30080245b07557ecce256 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 13:53:13 +0100 Subject: [PATCH 973/984] updated -> syntactic sugar + added previously-non-working test (!) --- tests/unittests/evaluator.art | 78 +++++++++++++++-------------------- tests/unittests/evaluator.res | 32 +++++++------- 2 files changed, 52 insertions(+), 58 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 997445eac8..7f769080b1 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1086,7 +1086,6 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; print ; end - ; TODO: this is not working!!! (see #804) byteCode [(print 2 print 3)] ; ================================ ; DATA @@ -1113,19 +1112,19 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; ================================ ; DATA ; ================================ - ; 0: do :word - ; 1: [ :block + ; 0: [ :block ; print :word ; 3 :integer ; ] + ; 1: do :word ; ================================ ; CODE ; ================================ ; consti2 ; print - ; push1 - ; call0 + ; push0 + ; call1 ; end ;***************************************************************** @@ -1153,18 +1152,18 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; ================================ ; DATA ; ================================ - ; 0: do :word - ; 1: [ :block + ; 0: [ :block ; print :word ; hello :string ; ] + ; 1: do :word ; 2: done :string ; ================================ ; CODE ; ================================ - ; push1 - ; call0 + ; push0 + ; call1 ; push2 ; print ; end @@ -1176,25 +1175,25 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; ================================ ; DATA ; ================================ - ; 0: a :label - ; 1: [ :block + ; 0: [ :block ; upper :word ; hello :string ; ] - ; 2: b :label - ; 3: [ :block + ; 1: a :label + ; 2: [ :block ; hello :string ; ++ :symbol ; world :word ; ] + ; 3: b :label ; ================================ ; CODE ; ================================ - ; push1 - ; store0 - ; push3 - ; store2 + ; push0 + ; store1 + ; push2 + ; store3 ; end ;***************************************************************** @@ -1206,17 +1205,14 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; DATA ; ================================ ; 0: [ :block - - ; ] - ; 1: [ :block ; hello :string ; ] ; ================================ ; CODE ; ================================ + ; consta ; push0 - ; push1 ; end byteCode [ @@ -1225,23 +1221,20 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; ================================ ; DATA ; ================================ - ; 0: f :label - ; 1: function :word - ; 2: [ :block - ; _0 :word - ; ] - ; 3: [ :block + ; 0: [ :block ; print :word ; _0 :word ; ] + ; 1: _0 :literal + ; 2: f :label ; ================================ ; CODE ; ================================ - ; push3 - ; push2 - ; call1 - ; store0 + ; push0 + ; push1 + ; func + ; store2 ; end byteCode [ @@ -1250,25 +1243,24 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; ================================ ; DATA ; ================================ - ; 0: adder :label - ; 1: function :word - ; 2: [ :block + ; 0: [ :block + ; add :word ; _0 :word ; _1 :word ; ] - ; 3: [ :block - ; add :word + ; 1: [ :block ; _0 :word ; _1 :word ; ] + ; 2: adder :label ; ================================ ; CODE ; ================================ - ; push3 - ; push2 - ; call1 - ; store0 + ; push0 + ; push1 + ; func + ; store2 ; end ;***************************************************************** @@ -1279,17 +1271,15 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; ================================ ; DATA ; ================================ - ; 0: print :word ; ================================ ; CODE ; ================================ ; consti2 - ; call0 + ; print ; end - ; TODO: this is not working!!! (see #802) - ; byteCode ["hello" | upper | print] + byteCode ["hello" | upper | print] ; ================================ ; DATA ; ================================ diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 171b068fca..51e79b7f46 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -409,8 +409,8 @@ >-------------------------------------------------- input: [print 2 do :: print 3] - data: [do [print 3]] - code: [2 176 33 96 218] (5 bytes) + data: [[print 3] do] + code: [3 189 32 97 218] (5 bytes) >-------------------------------------------------- @@ -422,12 +422,12 @@ code: [32 218] (2 bytes) input: [do -> print "hello" print "done"] - data: [do [print hello] done] - code: [33 96 34 176 218] (5 bytes) + data: [[print hello] do done] + code: [32 97 34 189 218] (5 bytes) input: [a: -> upper "hello" b: -> "hello " ++ world] - data: [a [upper hello] b [hello ++ world]] - code: [33 48 35 50 218] (5 bytes) + data: [[upper hello] a [hello ++ world] b] + code: [32 49 34 51 218] (5 bytes) >-------------------------------------------------- @@ -435,16 +435,16 @@ >-------------------------------------------------- input: [=> "hello"] - data: [[] [hello]] - code: [32 33 218] (3 bytes) + data: [[hello]] + code: [25 32 218] (3 bytes) input: [f: function => print] - data: [f function [_0] [print _0]] - code: [35 34 97 48 218] (5 bytes) + data: [[print _0] _0 f] + code: [32 33 178 50 218] (5 bytes) input: [adder: $ => add] - data: [adder function [_0 _1] [add _0 _1]] - code: [35 34 97 48 218] (5 bytes) + data: [[add _0 _1] [_0 _1] adder] + code: [32 33 178 50 218] (5 bytes) >-------------------------------------------------- @@ -452,8 +452,12 @@ >-------------------------------------------------- input: [2 | print] - data: [print] - code: [2 96 218] (3 bytes) + data: [] + code: [3 189 218] (3 bytes) + + input: ["hello" | upper | print] + data: [hello upper] + code: [32 97 189 218] (4 bytes) ************************************************** From 563c718e96389c6371a53cfb770a3c4dc26e2707 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:11:41 +0100 Subject: [PATCH 974/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 8132019780..ca1c19b140 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4049 \ No newline at end of file +4050 \ No newline at end of file From d885dcc6897997f54117a83e96d0c92c041c8143 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:30:25 +0100 Subject: [PATCH 975/984] VM/ast: fixed handling of constant I1 in distributive transformations --- src/vm/ast.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vm/ast.nim b/src/vm/ast.nim index 748e1324ce..12c6c1c0cb 100644 --- a/src/vm/ast.nim +++ b/src/vm/ast.nim @@ -301,6 +301,7 @@ proc processBlock*( right.replaceNode(newConstant(right.children[1].value + I1)) else: right.op = opAdd + right.children[0].kind = ConstantValue right.children[0].value = newInteger(1) elif right.children[1].kind == VariableLoad and right.children[1].value == left.value: hookOptimProfiler("add (distributive)") @@ -309,6 +310,7 @@ proc processBlock*( right.replaceNode(newConstant(right.children[0].value + I1)) else: right.op = opAdd + right.children[1].kind = ConstantValue right.children[1].value = newInteger(1) # Convert (X * Y) + X -> (1 + Y) * X and @@ -321,6 +323,7 @@ proc processBlock*( left.replaceNode(newConstant(left.children[1].value + I1)) else: left.op = opAdd + left.children[0].kind = ConstantValue left.children[0].value = newInteger(1) elif left.children[1].kind == VariableLoad and left.children[1].value == right.value: hookOptimProfiler("add (distributive)") @@ -329,6 +332,7 @@ proc processBlock*( left.replaceNode(newConstant(left.children[0].value + I1)) else: left.op = opAdd + left.children[1].kind = ConstantValue left.children[1].value = newInteger(1) proc optimizeSub(target: var Node) {.enforceNoRaises.} = From f871a335c61217ce675abdc46698e967c343340f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:30:49 +0100 Subject: [PATCH 976/984] updated tests + added new ones for Constant Folding-related optimizations --- tests/unittests/evaluator.art | 336 +++++++++++++++++++++++++++++----- tests/unittests/evaluator.res | 37 ++-- 2 files changed, 318 insertions(+), 55 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 7f769080b1..079bc5f0cc 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1299,7 +1299,7 @@ supersection "OPTIMIZATIONS" ;///////////////////////////////////////////////////////// ;***************************************************************** - topic "add (`+`)" + topic "add (`+`) / constant folding" ;***************************************************************** byteCode [add 2 3] @@ -1310,9 +1310,7 @@ supersection "OPTIMIZATIONS" ; ================================ ; CODE ; ================================ - ; consti3 - ; consti2 - ; add + ; consti5 ; end byteCode [2 + 3] @@ -1323,12 +1321,10 @@ supersection "OPTIMIZATIONS" ; ================================ ; CODE ; ================================ - ; consti3 - ; consti2 - ; add + ; consti5 ; end - byteCode [add 1 2] + byteCode [2 + 3 + 4 + 5] ; ================================ ; DATA ; ================================ @@ -1336,68 +1332,223 @@ supersection "OPTIMIZATIONS" ; ================================ ; CODE ; ================================ - ; consti2 - ; inc + ; consti14 ; end - byteCode [1 + 2] + byteCode [1 + 2 + 3 + 4 + 5 + 6] ; ================================ ; DATA ; ================================ + ; 0: 21 :integer ; ================================ ; CODE ; ================================ - ; consti2 - ; inc + ; push0 ; end - byteCode [add 2 1] + byteCode [x: 3 + 7] ; ================================ ; DATA ; ================================ + ; 0: x :label ; ================================ ; CODE ; ================================ - ; consti2 + ; consti10 + ; store0 + ; end + + ;***************************************************************** + topic "add (`+`) / -> inc" + ;***************************************************************** + + byteCode [x + 1] + ; ================================ + ; DATA + ; ================================ + ; 0: x :word + + ; ================================ + ; CODE + ; ================================ + ; load0 ; inc ; end - byteCode [2 + 1] + byteCode [1 + y] ; ================================ ; DATA ; ================================ + ; 0: y :word ; ================================ ; CODE ; ================================ - ; consti2 + ; load0 ; inc ; end - ; TODO: this is not working!!! - ; byteCode [a: b + 1] + ;***************************************************************** + topic "add (`+`) / distributive" + ;***************************************************************** + + byteCode [X + X * Y] ; ================================ ; DATA ; ================================ - ; 0: a :label - ; 1: b :word + ; 0: Y :word + ; 1: X :word ; ================================ ; CODE ; ================================ + ; load0 + ; consti1 + ; add ; load1 - ; inc - ; store0 + ; mul + ; end + + byteCode [(X * Y) + X] + ; ================================ + ; DATA + ; ================================ + ; 0: X :word + ; 1: Y :word + + ; ================================ + ; CODE + ; ================================ + ; load0 + ; load1 + ; consti1 + ; add + ; mul + ; end + + ;***************************************************************** + topic "sub (`-`) / constant folding" + ;***************************************************************** + + byteCode [sub 2 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti1m + ; end + + byteCode [2 - 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti1m + ; end + + byteCode [8 - 2 - 1] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti7 + ; end + + byteCode [30 - 10 - 1] + ; ================================ + ; DATA + ; ================================ + ; 0: 21 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "sub (`-`) / -> dec" + ;***************************************************************** + + byteCode [x - 1] + ; ================================ + ; DATA + ; ================================ + ; 0: x :word + + ; ================================ + ; CODE + ; ================================ + ; load0 + ; dec + ; end + + ;***************************************************************** + topic "mul (`*`) / constant folding" + ;***************************************************************** + + byteCode [mul 2 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti6 + ; end + + byteCode [2 * 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti6 + ; end + + byteCode [2 * 2 * 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti12 + ; end + + byteCode [2 * 3 * 4 * 5] + ; ================================ + ; DATA + ; ================================ + ; 0: 120 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 ; end ;***************************************************************** - topic "sub (`-`)" + topic "div (`/`) / constant folding" ;***************************************************************** - byteCode [sub 3 2] + byteCode [div 6 3] ; ================================ ; DATA ; ================================ @@ -1406,11 +1557,9 @@ supersection "OPTIMIZATIONS" ; CODE ; ================================ ; consti2 - ; consti3 - ; sub ; end - byteCode [3 - 2] + byteCode [6 / 3] ; ================================ ; DATA ; ================================ @@ -1419,23 +1568,107 @@ supersection "OPTIMIZATIONS" ; CODE ; ================================ ; consti2 + ; end + + byteCode [6 / 6 / 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ ; consti3 - ; sub ; end - byteCode [sub 2 1] + byteCode [50 / 4 / 4 / 2] ; ================================ ; DATA ; ================================ + ; 0: 25 :integer ; ================================ ; CODE ; ================================ - ; consti2 - ; dec + ; push0 + ; end + + ;***************************************************************** + topic "fdiv (`//`) / constant folding" + ;***************************************************************** + + byteCode [fdiv 6 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constf2 + ; end + + byteCode [6 // 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constf2 + ; end + + byteCode [4 // 8 // 2] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; constf1 + ; end + + byteCode [55 // 4 // 4 // 2] + ; ================================ + ; DATA + ; ================================ + ; 0: 27.5 :floating + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; end + + ;***************************************************************** + topic "mod (`%`) / constant folding" + ;***************************************************************** + + byteCode [mod 6 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti0 + ; end + + byteCode [6 % 3] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti0 ; end - byteCode [2 - 1] + byteCode [20 % 15 % 6] ; ================================ ; DATA ; ================================ @@ -1444,23 +1677,44 @@ supersection "OPTIMIZATIONS" ; CODE ; ================================ ; consti2 - ; dec ; end - ; TODO: this is not working!!! - ; byteCode [a: b - 1] + ;***************************************************************** + topic "pow (`^`) / constant folding" + ;***************************************************************** + + byteCode [pow 3 2] ; ================================ ; DATA ; ================================ - ; 0: a :label - ; 1: b :word ; ================================ ; CODE ; ================================ - ; load1 - ; dec - ; store0 + ; consti9 + ; end + + byteCode [3 ^ 2] + ; ================================ + ; DATA + ; ================================ + + ; ================================ + ; CODE + ; ================================ + ; consti9 + ; end + + byteCode [2 ^ 2 ^ 2] + ; ================================ + ; DATA + ; ================================ + ; 0: 16 :integer + + ; ================================ + ; CODE + ; ================================ + ; push0 ; end ;***************************************************************** diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 51e79b7f46..12305789d7 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -467,32 +467,41 @@ ************************************************** >-------------------------------------------------- - > add (`+`) + > add (`+`) / constant folding >-------------------------------------------------- input: [add 2 3] data: [] - code: [3 2 128 218] (4 bytes) + code: [6 218] (2 bytes) input: [2 + 3] data: [] - code: [3 2 128 218] (4 bytes) + code: [6 218] (2 bytes) - input: [add 1 2] + input: [2 + 3 + 4 + 5] data: [] - code: [2 174 218] (3 bytes) + code: [15 218] (2 bytes) - input: [1 + 2] - data: [] - code: [2 174 218] (3 bytes) + input: [1 + 2 + 3 + 4 + 5 + 6] + data: [21] + code: [32 218] (2 bytes) - input: [add 2 1] - data: [] - code: [2 174 218] (3 bytes) + input: [x: 3 + 7] + data: [x] + code: [11 48 218] (3 bytes) - input: [2 + 1] - data: [] - code: [2 174 218] (3 bytes) + + >-------------------------------------------------- + > add (`+`) / -> inc + >-------------------------------------------------- + + input: [x + 1] + data: [x] + code: [64 136 218] (3 bytes) + + input: [1 + y] + data: [y] + code: [64 136 218] (3 bytes) >-------------------------------------------------- From 7c2ceeea2a781a8fdee69bdca5f1914054b98de3 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:38:08 +0100 Subject: [PATCH 977/984] updated tests --- tests/unittests/evaluator.art | 346 ++++++++++++---------------------- 1 file changed, 125 insertions(+), 221 deletions(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 079bc5f0cc..f76d137eb6 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1731,14 +1731,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; true :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -1746,12 +1740,12 @@ supersection "OPTIMIZATIONS" ; push0 ; print ; load1 - ; jmpifnot #4 - ; push3 + ; jmpifnot @4 + ; push2 ; print ; constbt ; return - ; push4 + ; push3 ; print ; end @@ -1765,14 +1759,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; false :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -1780,12 +1768,12 @@ supersection "OPTIMIZATIONS" ; push0 ; print ; load1 - ; jmpif #4 - ; push3 + ; jmpif @4 + ; push2 ; print ; constbf ; return - ; push4 + ; push3 ; print ; end @@ -1799,14 +1787,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; true :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -1815,12 +1797,12 @@ supersection "OPTIMIZATIONS" ; print ; consti2 ; load1 - ; jmpifne #4 - ; push3 + ; jmpifne @4 + ; push2 ; print ; constbt ; return - ; push4 + ; push3 ; print ; end @@ -1834,14 +1816,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; true :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -1850,12 +1826,12 @@ supersection "OPTIMIZATIONS" ; print ; consti2 ; load1 - ; jmpifle #4 - ; push3 + ; jmpifle @4 + ; push2 ; print ; constbt ; return - ; push4 + ; push3 ; print ; end @@ -1869,14 +1845,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; true :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -1885,12 +1855,12 @@ supersection "OPTIMIZATIONS" ; print ; consti2 ; load1 - ; jmpifgt #4 - ; push3 + ; jmpifgt @4 + ; push2 ; print ; constbt ; return - ; push4 + ; push3 ; print ; end @@ -1908,14 +1878,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; false :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -1923,12 +1887,12 @@ supersection "OPTIMIZATIONS" ; push0 ; print ; load1 - ; jmpif #4 - ; push3 + ; jmpif @4 + ; push2 ; print ; constbf ; return - ; push4 + ; push3 ; print ; end @@ -1942,14 +1906,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; true :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -1957,12 +1915,12 @@ supersection "OPTIMIZATIONS" ; push0 ; print ; load1 - ; jmpifnot #4 - ; push3 + ; jmpifnot @4 + ; push2 ; print ; constbt ; return - ; push4 + ; push3 ; print ; end @@ -1976,14 +1934,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; false :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -1992,12 +1944,12 @@ supersection "OPTIMIZATIONS" ; print ; consti2 ; load1 - ; jmpifeq #4 - ; push3 + ; jmpifeq @4 + ; push2 ; print ; constbf ; return - ; push4 + ; push3 ; print ; end @@ -2011,14 +1963,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; false :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -2027,12 +1973,12 @@ supersection "OPTIMIZATIONS" ; print ; consti2 ; load1 - ; jmpifgt #4 - ; push3 + ; jmpifgt @4 + ; push2 ; print ; constbf ; return - ; push4 + ; push3 ; print ; end @@ -2046,14 +1992,8 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: x :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; false :word - ; ] - ; 3: here :string - ; 4: after :string + ; 2: here :string + ; 3: after :string ; ================================ ; CODE @@ -2062,17 +2002,17 @@ supersection "OPTIMIZATIONS" ; print ; consti2 ; load1 - ; jmpifle #4 - ; push3 + ; jmpifle @4 + ; push2 ; print ; constbf ; return - ; push4 + ; push3 ; print ; end ;***************************************************************** - topic "if-else" + topic "if?-else" ;***************************************************************** byteCode [ @@ -2083,23 +2023,15 @@ supersection "OPTIMIZATIONS" ; DATA ; ================================ ; 0: x :word - ; 1: [ :block - ; return :word - ; true :word - ; ] - ; 2: [ :block - ; return :word - ; false :word - ; ] ; ================================ ; CODE ; ================================ ; load0 - ; jmpifnot #5 + ; jmpifnot @4 ; constbt ; return - ; goto #2 + ; goto @2 ; constbf ; return ; end @@ -2115,42 +2047,28 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: a :word - ; 2: [ :block - ; print :word - ; here :string - ; return :word - ; true :word - ; ] - ; 3: here :string - ; 4: [ :block - ; print :word - ; there :string - ; return :word - ; false :word - ; ] - ; 5: there :string - ; 6: after :string + ; 2: here :string + ; 3: there :string + ; 4: after :string ; ================================ ; CODE ; ================================ ; push0 ; print - ; consti2 - ; consti1 - ; add + ; consti3 ; load1 - ; jmpifeq #7 - ; push3 + ; jmpifeq @6 + ; push2 ; print ; constbt ; return - ; goto #4 - ; push5 + ; goto @4 + ; push3 ; print ; constbf ; return - ; push6 + ; push4 ; print ; end @@ -2168,13 +2086,7 @@ supersection "OPTIMIZATIONS" ; ================================ ; 0: before :string ; 1: a :word - ; 2: [ :block - ; 1 :integer - ; ] - ; 3: [ :block - ; 2 :integer - ; ] - ; 4: after :string + ; 2: after :string ; ================================ ; CODE @@ -2182,11 +2094,11 @@ supersection "OPTIMIZATIONS" ; push0 ; print ; load1 - ; jmpifnot #4 + ; jmpifnot @3 ; consti1 - ; goto #1 + ; goto @1 ; consti2 - ; push4 + ; push2 ; print ; end @@ -2195,21 +2107,15 @@ supersection "OPTIMIZATIONS" ; DATA ; ================================ ; 0: x :word - ; 1: [ :block - ; 1 :integer - ; ] - ; 2: [ :block - ; 2 :integer - ; ] ; ================================ ; CODE ; ================================ ; consti1 ; load0 - ; jmpifne #4 + ; jmpifne @3 ; consti1 - ; goto #1 + ; goto @1 ; consti2 ; end @@ -2222,13 +2128,13 @@ supersection "OPTIMIZATIONS" ; DATA ; ================================ ; 0: before :string - ; 1: x :word + ; 1: [ :block + ; false :word + ; ] ; 2: [ :block ; true :word ; ] - ; 3: [ :block - ; false :word - ; ] + ; 3: x :word ; 4: after :string ; ================================ @@ -2236,12 +2142,12 @@ supersection "OPTIMIZATIONS" ; ================================ ; push0 ; print + ; push1 + ; push2 ; consti1 - ; load1 - ; jmpifge #4 - ; constbt - ; goto #1 - ; constbf + ; load3 + ; lt + ; switch ; return ; push4 ; print @@ -2256,14 +2162,14 @@ supersection "OPTIMIZATIONS" ; DATA ; ================================ ; 0: before :string - ; 1: z :label - ; 2: x :word - ; 3: [ :block - ; true :word - ; ] - ; 4: [ :block + ; 1: [ :block ; false :word ; ] + ; 2: [ :block + ; true :word + ; ] + ; 3: x :word + ; 4: z :label ; 5: after :string ; ================================ @@ -2271,13 +2177,13 @@ supersection "OPTIMIZATIONS" ; ================================ ; push0 ; print + ; push1 + ; push2 ; consti1 - ; load2 - ; jmpifge #4 - ; constbt - ; goto #1 - ; constbf - ; store1 + ; load3 + ; lt + ; switch + ; store4 ; push5 ; print ; end @@ -2291,14 +2197,14 @@ supersection "OPTIMIZATIONS" ; DATA ; ================================ ; 0: before :string - ; 1: z :label - ; 2: x :word - ; 3: [ :block - ; 1 :integer - ; ] - ; 4: [ :block + ; 1: [ :block ; 2 :integer ; ] + ; 2: [ :block + ; 1 :integer + ; ] + ; 3: x :word + ; 4: z :label ; 5: after :string ; ================================ @@ -2306,26 +2212,19 @@ supersection "OPTIMIZATIONS" ; ================================ ; push0 ; print + ; push1 + ; push2 ; consti1 - ; load2 - ; jmpiflt #4 - ; consti1 - ; goto #1 - ; consti2 + ; load3 + ; ge + ; switch ; consti3 ; add - ; store1 + ; store4 ; push5 ; print ; end - ; TODO: this is not working!!! (see #817) - ; byteCode [ - ; print "before" - ; return ((x>1)? -> 2 -> 3) + (y<4)? -> 5 -> 6 - ; print "after" - ; ] - ;***************************************************************** topic "while" ;***************************************************************** @@ -2336,30 +2235,35 @@ supersection "OPTIMIZATIONS" ; ================================ ; DATA ; ================================ - ; 0: [ :block - ; x :word - ; = :symbol - ; 1 :integer - ; ] - ; 1: [ :block - ; print :word - ; hello :string - ; ] - ; 2: x :word - ; 3: hello :string + ; 0: x :word + ; 1: hello :string ; ================================ ; CODE ; ================================ ; consti1 - ; load2 - ; jmpifne #5 - ; push3 + ; load0 + ; jmpifne @4 + ; push1 ; print - ; goup #10 + ; goup @6 ; end - ; TODO: this is not working!!! - ; byteCode [ - ; while ΓΈ [print "hello"] - ; ] \ No newline at end of file + byteCode [ + while ΓΈ [print "hello"] + ] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; print :word + ; hello :string + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; constn + ; while + ; end \ No newline at end of file From 7be08ed5befd1a6e255c1a37b41e6927677eedd7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:42:08 +0100 Subject: [PATCH 978/984] added more tests for arrow operators --- tests/unittests/evaluator.art | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index f76d137eb6..5c2c2e42a0 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1168,6 +1168,24 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; print ; end + byteCode [-> 1 -> 2] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 1 :integer + ; ] + ; 1: [ :block + ; 2 :integer + ; ] + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; end + byteCode [ a: -> upper "hello" b: -> "hello " ++ world @@ -1263,6 +1281,57 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; store2 ; end + byteCode [ + subOne: function => [& - 1] + ] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; _0 :word + ; - :symbol + ; 1 :integer + ; ] + ; 1: _0 :literal + ; 2: subOne :label + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; func + ; store2 + ; end + + byteCode [ + mulAddOne: $ => [1 + & * &] + ] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 1 :integer + ; + :symbol + ; _0 :word + ; * :symbol + ; _1 :word + ; ] + ; 1: [ :block + ; _0 :word + ; _1 :word + ; ] + ; 2: mulAddOne :label + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; func + ; store2 + ; end + ;***************************************************************** topic "pipe operator (`|`)" ;***************************************************************** From e2d9a43ee3e5e577b03aeca5867bd37dacd61c87 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:49:11 +0100 Subject: [PATCH 979/984] added better test for pipe operators (with or without also using other syntactic sugar) --- tests/unittests/evaluator.art | 191 ++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 5c2c2e42a0..1ffddae859 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -1363,6 +1363,197 @@ supersection "BLOCKS & SYNTACTIC SUGAR" ; print ; end + byteCode [x: "hello" | upper] + ; ================================ + ; DATA + ; ================================ + ; 0: hello :string + ; 1: upper :word + ; 2: x :label + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; call1 + ; store2 + ; end + + byteCode [1..10 | map 'x -> 2 * x] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 2 :integer + ; * :symbol + ; x :word + ; ] + ; 1: x :literal + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; consti10 + ; consti1 + ; range + ; map + ; end + + byteCode [1..10 | map 'x -> 2 * x | sum] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 2 :integer + ; * :symbol + ; x :word + ; ] + ; 1: x :literal + ; 2: sum :word + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; consti10 + ; consti1 + ; range + ; map + ; call2 + ; end + + byteCode [1..10 | map 'x -> 2 * x | sum | print] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 2 :integer + ; * :symbol + ; x :word + ; ] + ; 1: x :literal + ; 2: sum :word + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; consti10 + ; consti1 + ; range + ; map + ; call2 + ; print + ; end + + byteCode [ + 1..10 | map 'x -> 2 * x + | sum + | print + ] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; 2 :integer + ; * :symbol + ; x :word + ; ] + ; 1: x :literal + ; 2: sum :word + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; consti10 + ; consti1 + ; range + ; map + ; call2 + ; print + ; end + + byteCode [ + filtered: 1..a | map 'x -> 3 * x + | select 'x -> odd? x + print filtered + ] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; odd? :word + ; x :word + ; ] + ; 1: x :literal + ; 2: [ :block + ; 3 :integer + ; * :symbol + ; x :word + ; ] + ; 3: a :word + ; 4: filtered :label + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; push2 + ; push1 + ; load3 + ; consti1 + ; range + ; map + ; select + ; storl4 + ; print + ; end + + byteCode [ + filtered: 1..a | map 'x -> 3 * x + | select => odd? + print filtered + ] + ; ================================ + ; DATA + ; ================================ + ; 0: [ :block + ; odd? :word + ; _0 :word + ; ] + ; 1: _0 :literal + ; 2: [ :block + ; 3 :integer + ; * :symbol + ; x :word + ; ] + ; 3: x :literal + ; 4: a :word + ; 5: filtered :label + + ; ================================ + ; CODE + ; ================================ + ; push0 + ; push1 + ; push2 + ; push3 + ; load4 + ; consti1 + ; range + ; map + ; select + ; storl5 + ; print + ; end + ;///////////////////////////////////////////////////////// supersection "OPTIMIZATIONS" ;///////////////////////////////////////////////////////// From 42ed030027fc30d9568564f213c025c7822c30df Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:49:31 +0100 Subject: [PATCH 980/984] disabled debugging --- tests/unittests/evaluator.art | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/evaluator.art b/tests/unittests/evaluator.art index 1ffddae859..f78876bbc6 100644 --- a/tests/unittests/evaluator.art +++ b/tests/unittests/evaluator.art @@ -24,7 +24,7 @@ byteCode: function [blk][ btc: to.intrepid :bytecode blk ; this little hack is needed to remove newlines from our block ; thus, avoiding all opEol/opEolX bytecode being produced - inspect btc ; uncomment this line to see the bytecode + ;inspect btc ; uncomment this line to see the bytecode ; in a more readable format prints spacer print ["input:" as.code blk] From 89616369be67d57a726bb92bbb1bf5e72385b028 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:50:29 +0100 Subject: [PATCH 981/984] updated expected result --- tests/unittests/evaluator.res | 263 +++++++++++++++++++++++++++------- 1 file changed, 213 insertions(+), 50 deletions(-) diff --git a/tests/unittests/evaluator.res b/tests/unittests/evaluator.res index 12305789d7..208cecbc71 100644 --- a/tests/unittests/evaluator.res +++ b/tests/unittests/evaluator.res @@ -279,7 +279,7 @@ input: [to :string 5] data: [] - code: [6 172 218] (3 bytes) + code: [6 171 218] (3 bytes) >-------------------------------------------------- @@ -348,8 +348,8 @@ code: [1 64 153 218] (4 bytes) input: [user\name] - data: [user name] - code: [33 65 153 218] (4 bytes) + data: [name user] + code: [32 65 153 218] (4 bytes) input: [user\grades\0] data: [grades user] @@ -425,6 +425,10 @@ data: [[print hello] do done] code: [32 97 34 189 218] (5 bytes) + input: [-> 1 -> 2] + data: [[1] [2]] + code: [32 33 218] (3 bytes) + input: [a: -> upper "hello" b: -> "hello " ++ world] data: [[upper hello] a [hello ++ world] b] code: [32 49 34 51 218] (5 bytes) @@ -446,6 +450,14 @@ data: [[add _0 _1] [_0 _1] adder] code: [32 33 178 50 218] (5 bytes) + input: [subOne: function => [& - 1]] + data: [[_0 - 1] _0 subOne] + code: [32 33 178 50 218] (5 bytes) + + input: [mulAddOne: $ => [1 + & * &]] + data: [[1 + _0 * _1] [_0 _1] mulAddOne] + code: [32 33 178 50 218] (5 bytes) + >-------------------------------------------------- > pipe operator (`|`) @@ -459,6 +471,34 @@ data: [hello upper] code: [32 97 189 218] (4 bytes) + input: [x: "hello" | upper] + data: [hello upper x] + code: [32 97 50 218] (4 bytes) + + input: [1 .. 10 | map 'x -> 2 * x] + data: [[2 * x] x] + code: [32 33 11 2 179 181 218] (7 bytes) + + input: [1 .. 10 | map 'x -> 2 * x | sum] + data: [[2 * x] x sum] + code: [32 33 11 2 179 181 98 218] (8 bytes) + + input: [1 .. 10 | map 'x -> 2 * x | sum | print] + data: [[2 * x] x sum] + code: [32 33 11 2 179 181 98 189 218] (9 bytes) + + input: [1 .. 10 | map 'x -> 2 * x | sum | print] + data: [[2 * x] x sum] + code: [32 33 11 2 179 181 98 189 218] (9 bytes) + + input: [filtered: 1 .. a | map 'x -> 3 * x | select 'x -> odd? x print filtered] + data: [[odd? x] x [3 * x] a filtered] + code: [32 33 34 33 67 2 179 181 182 84 189 218] (12 bytes) + + input: [filtered: 1 .. a | map 'x -> 3 * x | select => odd? print filtered] + data: [[odd? _0] _0 [3 * x] x a filtered] + code: [32 33 34 35 68 2 179 181 182 85 189 218] (12 bytes) + ************************************************** * @@ -480,7 +520,7 @@ input: [2 + 3 + 4 + 5] data: [] - code: [15 218] (2 bytes) + code: [15 218] (2 bytes) input: [1 + 2 + 3 + 4 + 5 + 6] data: [21] @@ -505,24 +545,143 @@ >-------------------------------------------------- - > sub (`-`) + > add (`+`) / distributive + >-------------------------------------------------- + + input: [X + X * Y] + data: [Y X] + code: [64 2 128 65 130 218] (6 bytes) + + input: [(X * Y) + X] + data: [X Y] + code: [64 65 2 128 130 218] (6 bytes) + + + >-------------------------------------------------- + > sub (`-`) / constant folding + >-------------------------------------------------- + + input: [sub 2 3] + data: [] + code: [0 218] (2 bytes) + + input: [2 - 3] + data: [] + code: [0 218] (2 bytes) + + input: [8 - 2 - 1] + data: [] + code: [8 218] (2 bytes) + + input: [30 - 10 - 1] + data: [21] + code: [32 218] (2 bytes) + + + >-------------------------------------------------- + > sub (`-`) / -> dec + >-------------------------------------------------- + + input: [x - 1] + data: [x] + code: [64 137 218] (3 bytes) + + + >-------------------------------------------------- + > mul (`*`) / constant folding + >-------------------------------------------------- + + input: [mul 2 3] + data: [] + code: [7 218] (2 bytes) + + input: [2 * 3] + data: [] + code: [7 218] (2 bytes) + + input: [2 * 2 * 3] + data: [] + code: [13 218] (2 bytes) + + input: [2 * 3 * 4 * 5] + data: [120] + code: [32 218] (2 bytes) + + + >-------------------------------------------------- + > div (`/`) / constant folding >-------------------------------------------------- - input: [sub 3 2] + input: [div 6 3] data: [] - code: [2 3 129 218] (4 bytes) + code: [3 218] (2 bytes) + + input: [6 / 3] + data: [] + code: [3 218] (2 bytes) + + input: [6 / 6 / 3] + data: [] + code: [4 218] (2 bytes) + + input: [50 / 4 / 4 / 2] + data: [25] + code: [32 218] (2 bytes) + + + >-------------------------------------------------- + > fdiv (`//`) / constant folding + >-------------------------------------------------- - input: [3 - 2] + input: [fdiv 6 3] data: [] - code: [2 3 129 218] (4 bytes) + code: [20 218] (2 bytes) - input: [sub 2 1] + input: [6 // 3] data: [] - code: [2 175 218] (3 bytes) + code: [20 218] (2 bytes) - input: [2 - 1] + input: [4 // 8 // 2] data: [] - code: [2 175 218] (3 bytes) + code: [19 218] (2 bytes) + + input: [55 // 4 // 4 // 2] + data: [27.5] + code: [32 218] (2 bytes) + + + >-------------------------------------------------- + > mod (`%`) / constant folding + >-------------------------------------------------- + + input: [mod 6 3] + data: [] + code: [1 218] (2 bytes) + + input: [6 % 3] + data: [] + code: [1 218] (2 bytes) + + input: [20 % 15 % 6] + data: [] + code: [3 218] (2 bytes) + + + >-------------------------------------------------- + > pow (`^`) / constant folding + >-------------------------------------------------- + + input: [pow 3 2] + data: [] + code: [10 218] (2 bytes) + + input: [3 ^ 2] + data: [] + code: [10 218] (2 bytes) + + input: [2 ^ 2 ^ 2] + data: [16] + code: [32 218] (2 bytes) >-------------------------------------------------- @@ -530,24 +689,24 @@ >-------------------------------------------------- input: [print "before" if x [print "here" return true] print "after"] - data: [before x [print here return true] here after] - code: [32 176 65 198 0 4 35 176 21 156 36 176 218] (13 bytes) + data: [before x here after] + code: [32 189 65 199 4 34 189 21 167 35 189 218] (12 bytes) input: [print "before" if not? x [print "here" return false] print "after"] - data: [before x [print here return false] here after] - code: [32 176 65 197 0 4 35 176 22 156 36 176 218] (13 bytes) + data: [before x here after] + code: [32 189 65 197 4 34 189 22 167 35 189 218] (12 bytes) input: [print "before" if x = 2 [print "here" return true] print "after"] - data: [before x [print here return true] here after] - code: [32 176 2 65 200 0 4 35 176 21 156 36 176 218] (14 bytes) + data: [before x here after] + code: [32 189 3 65 203 4 34 189 21 167 35 189 218] (13 bytes) input: [print "before" if x > 2 [print "here" return true] print "after"] - data: [before x [print here return true] here after] - code: [32 176 2 65 204 0 4 35 176 21 156 36 176 218] (14 bytes) + data: [before x here after] + code: [32 189 3 65 211 4 34 189 21 167 35 189 218] (13 bytes) input: [print "before" if x =< 2 [print "here" return true] print "after"] - data: [before x [print here return true] here after] - code: [32 176 2 65 201 0 4 35 176 21 156 36 176 218] (14 bytes) + data: [before x here after] + code: [32 189 3 65 205 4 34 189 21 167 35 189 218] (13 bytes) >-------------------------------------------------- @@ -555,37 +714,37 @@ >-------------------------------------------------- input: [print "before" unless x [print "here" return false] print "after"] - data: [before x [print here return false] here after] - code: [32 176 65 197 0 4 35 176 22 156 36 176 218] (13 bytes) + data: [before x here after] + code: [32 189 65 197 4 34 189 22 167 35 189 218] (12 bytes) input: [print "before" unless not? x [print "here" return true] print "after"] - data: [before x [print here return true] here after] - code: [32 176 65 198 0 4 35 176 21 156 36 176 218] (13 bytes) + data: [before x here after] + code: [32 189 65 199 4 34 189 21 167 35 189 218] (12 bytes) input: [print "before" unless x = 2 [print "here" return false] print "after"] - data: [before x [print here return false] here after] - code: [32 176 2 65 199 0 4 35 176 22 156 36 176 218] (14 bytes) + data: [before x here after] + code: [32 189 3 65 201 4 34 189 22 167 35 189 218] (13 bytes) input: [print "before" unless x > 2 [print "here" return false] print "after"] - data: [before x [print here return false] here after] - code: [32 176 2 65 201 0 4 35 176 22 156 36 176 218] (14 bytes) + data: [before x here after] + code: [32 189 3 65 205 4 34 189 22 167 35 189 218] (13 bytes) input: [print "before" unless x =< 2 [print "here" return false] print "after"] - data: [before x [print here return false] here after] - code: [32 176 2 65 204 0 4 35 176 22 156 36 176 218] (14 bytes) + data: [before x here after] + code: [32 189 3 65 211 4 34 189 22 167 35 189 218] (13 bytes) >-------------------------------------------------- - > if-else + > if?-else >-------------------------------------------------- input: [if? x [return true] else [return false]] - data: [x [return true] [return false]] - code: [64 198 0 5 21 156 208 0 2 22 156 218] (12 bytes) + data: [x] + code: [64 199 4 21 167 213 2 22 167 218] (10 bytes) input: [print "before" if? a <> 1 + 2 [print "here" return true] else [print "there" return false] print "after"] - data: [before a [print here return true] here [print there return false] there after] - code: [32 176 2 1 128 65 199 0 7 35 176 21 156 208 0 4 37 176 22 156 38 176 218] (23 bytes) + data: [before a here there after] + code: [32 189 4 65 201 6 34 189 21 167 213 4 35 189 22 167 36 189 218] (19 bytes) >-------------------------------------------------- @@ -593,24 +752,24 @@ >-------------------------------------------------- input: [print "before" switch a [1] [2] print "after"] - data: [before a [1] [2] after] - code: [32 176 65 198 0 4 1 208 0 1 2 36 176 218] (14 bytes) + data: [before a after] + code: [32 189 65 199 3 2 213 1 3 34 189 218] (12 bytes) input: [(x = 1) ? -> 1 -> 2] - data: [x [1] [2]] - code: [1 64 200 0 4 1 208 0 1 2 218] (11 bytes) + data: [x] + code: [2 64 203 3 2 213 1 3 218] (9 bytes) input: [print "before" return (x < 1) ? -> true -> false print "after"] - data: [before x [true] [false] after] - code: [32 176 1 65 202 0 4 21 208 0 1 22 156 36 176 218] (16 bytes) + data: [before [false] [true] x after] + code: [32 189 33 34 2 67 151 165 167 36 189 218] (12 bytes) input: [print "before" z: (x < 1) ? -> true -> false print "after"] - data: [before z x [true] [false] after] - code: [32 176 1 66 202 0 4 21 208 0 1 22 49 37 176 218] (16 bytes) + data: [before [false] [true] x z after] + code: [32 189 33 34 2 67 151 165 52 37 189 218] (12 bytes) input: [print "before" z: 3 + (x >= 1) ? -> 1 -> 2 print "after"] - data: [before z x [1] [2] after] - code: [32 176 1 66 203 0 4 1 208 0 1 2 3 128 49 37 176 218] (18 bytes) + data: [before [2] [1] x z after] + code: [32 189 33 34 2 67 150 165 4 128 52 37 189 218] (14 bytes) >-------------------------------------------------- @@ -618,5 +777,9 @@ >-------------------------------------------------- input: [while [x = 1] [print "hello"]] - data: [[x = 1] [print hello] x hello] - code: [1 66 200 0 5 35 176 209 0 10 218] (11 bytes) \ No newline at end of file + data: [x hello] + code: [2 64 203 4 33 189 215 6 218] (9 bytes) + + input: [while βˆ… [print "hello"]] + data: [[print hello]] + code: [32 27 166 218] (4 bytes) \ No newline at end of file From ff220f70f584e9342e5056bd567664e0f66cddbc Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:50:40 +0100 Subject: [PATCH 982/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index ca1c19b140..5b83e45fdc 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4050 \ No newline at end of file +4051 \ No newline at end of file From 21909d58f631810b62c79f42eb9c413d6dc697f1 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:51:08 +0100 Subject: [PATCH 983/984] VM/eval: removed unused import --- src/vm/eval.nim | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/vm/eval.nim b/src/vm/eval.nim index 7e089a9a7a..db507f495a 100644 --- a/src/vm/eval.nim +++ b/src/vm/eval.nim @@ -26,8 +26,6 @@ import vm/values/custom/[vbinary, vlogical] import vm/profiler -import vm/values/printable - #======================================= # Variables #======================================= From f34e268ef94574fdd4c58c8668e5e4b3f9de6e72 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Thu, 26 Jan 2023 14:51:18 +0100 Subject: [PATCH 984/984] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 5b83e45fdc..cc3c8d5704 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -4051 \ No newline at end of file +4052 \ No newline at end of file