From cbca1696bd65432261f8d75859682eb063731b6d Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:30:40 +0200 Subject: [PATCH 01/17] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index c99bf43de1..1275ac80ab 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -858 \ No newline at end of file +859 \ No newline at end of file From 852f7900753c273992ccf3793e7131b0dd87859b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:35:47 +0200 Subject: [PATCH 02/17] System/arg: converted to built-in --- src/library/System.nim | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/library/System.nim b/src/library/System.nim index 8e67dc857e..70bc996331 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -54,10 +54,27 @@ proc defineSymbols*() = # but that doesn't mean they should be considered as such. # labels: library, enhancement - constant "arg", - alias = unaliased, - description = "access command-line arguments as a list": - getCmdlineArgumentArray() + builtin "arg", + alias = unaliased, + op = opNop, + rule = PrefixPrecedence, + description = "access command-line arguments as a list", + args = NoArgs, + attrs = NoAttrs, + returns = {Block}, + example = """ + ; called with no parameters + arg ; => [] + + ; called with: 1 two 3 + arg ; => ["1" "two" "3"] + """: + push(getCmdlineArgumentArray()) + + # constant "arg", + # alias = unaliased, + # description = "access command-line arguments as a list": + # getCmdlineArgumentArray() constant "args", alias = unaliased, From 7d1b8241e0d1d651b54559479198152897e191bb Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:41:27 +0200 Subject: [PATCH 03/17] System\args: converte to builtin + added documentation example --- src/library/System.nim | 54 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/src/library/System.nim b/src/library/System.nim index 70bc996331..c67cdf5f73 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -76,10 +76,56 @@ proc defineSymbols*() = # description = "access command-line arguments as a list": # getCmdlineArgumentArray() - constant "args", - alias = unaliased, - description = "a dictionary with all command-line arguments parsed": - newDictionary(parseCmdlineArguments()) + builtin "args", + alias = unaliased, + op = opNop, + rule = PrefixPrecedence, + description = "access all command-line arguments parsed as a dictionary", + args = NoArgs, + attrs = NoAttrs, + returns = {Dictionary}, + example = """ + ; called with no parameters + args ; => #[ values: [] ] + + ; called with: 1 two 3 + args + ; => #[ + ; 1 + ; "two" + ; 3 + ; ] + .......... + ; called with switches: -c -b + args + ; => #[ + ; c : true + ; b : true + ; values: [] + ; ] + + ; called with switches: -c -b and values: 1 two 3 + args + ; => #[ + ; c : true + ; b : true + ; values: [1 "two" 3] + ; ] + .......... + ; called with named parameters: -c:2 --name:newname myfile.txt + args + ; => #[ + ; c : 2 + ; name : "newname" + ; values: ["myfile.txt"] + ; ] + """: + push(newDictionary(parseCmdlineArguments())) + + # constant "args", + # alias = unaliased, + # description = "a dictionary with all command-line arguments parsed": + # newDictionary(parseCmdlineArguments()) when not defined(WEB): From 0c3a38bea893f1d0cfe6155a2154f4d215801c53 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:44:13 +0200 Subject: [PATCH 04/17] System\config: converted to builtin --- src/library/System.nim | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/library/System.nim b/src/library/System.nim index c67cdf5f73..a404913d8d 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -58,7 +58,7 @@ proc defineSymbols*() = alias = unaliased, op = opNop, rule = PrefixPrecedence, - description = "access command-line arguments as a list", + description = "get command-line arguments as a list", args = NoArgs, attrs = NoAttrs, returns = {Block}, @@ -80,7 +80,7 @@ proc defineSymbols*() = alias = unaliased, op = opNop, rule = PrefixPrecedence, - description = "access all command-line arguments parsed as a dictionary", + description = "get all command-line arguments parsed as a dictionary", args = NoArgs, attrs = NoAttrs, returns = {Dictionary}, @@ -128,11 +128,18 @@ proc defineSymbols*() = # newDictionary(parseCmdlineArguments()) when not defined(WEB): - - constant "config", - alias = unaliased, - description = "access global configuration": - Config + + builtin "config", + alias = unaliased, + op = opNop, + rule = PrefixPrecedence, + description = "get global configuration", + args = NoArgs, + attrs = NoAttrs, + returns = {Store}, + example = """ + """: + push(Config) # TODO(System\env) could it be used for Web/JS builds too? # and what type of environment variables could be served or would be useful serve? From bf342d0ef7c7b97a115eb9399a5d22a11435816f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:45:41 +0200 Subject: [PATCH 05/17] System\script: converted to builtin --- src/library/System.nim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/library/System.nim b/src/library/System.nim index a404913d8d..e34abdfb65 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -378,11 +378,19 @@ proc defineSymbols*() = # TODO(System/script) also add information about the current script being executed # another location could also be Paths/path # labels: library,enhancement - constant "script", - alias = unaliased, - description = "embedded information about the current script": - getScriptInfo() + builtin "script", + alias = unaliased, + op = opNop, + rule = PrefixPrecedence, + description = "get embedded information about the current script", + args = NoArgs, + attrs = NoAttrs, + returns = {Dictionary}, + example = """ + """: + push(getScriptInfo()) + when not defined(WEB): builtin "superuser?", alias = unaliased, From a4a100b3fe71703c9aaf3c78fe0b694f62f21f14 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:46:21 +0200 Subject: [PATCH 06/17] removed TODO --- src/library/System.nim | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/library/System.nim b/src/library/System.nim index e34abdfb65..8abc802832 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -48,12 +48,6 @@ when not defined(WEB): proc defineSymbols*() = - # TODO(System) Convert constants to methods - # None of the supposed constants here is actually a constant. - # All of them return something that doesn't change on one hand, - # but that doesn't mean they should be considered as such. - # labels: library, enhancement - builtin "arg", alias = unaliased, op = opNop, @@ -390,7 +384,7 @@ proc defineSymbols*() = example = """ """: push(getScriptInfo()) - + when not defined(WEB): builtin "superuser?", alias = unaliased, From 0328d8c90fc43c46f61b36c9da368d395694f93f Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:47:41 +0200 Subject: [PATCH 07/17] removed leftovers --- src/library/System.nim | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/library/System.nim b/src/library/System.nim index 8abc802832..4480984c5b 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -65,11 +65,6 @@ proc defineSymbols*() = """: push(getCmdlineArgumentArray()) - # constant "arg", - # alias = unaliased, - # description = "access command-line arguments as a list": - # getCmdlineArgumentArray() - builtin "args", alias = unaliased, op = opNop, @@ -116,11 +111,6 @@ proc defineSymbols*() = """: push(newDictionary(parseCmdlineArguments())) - # constant "args", - # alias = unaliased, - # description = "a dictionary with all command-line arguments parsed": - # newDictionary(parseCmdlineArguments()) - when not defined(WEB): builtin "config", From 37e404e2236ed9b1da6474ba2b8e617a6ce11756 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:48:32 +0200 Subject: [PATCH 08/17] System\config: added TODO --- src/library/System.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/library/System.nim b/src/library/System.nim index 4480984c5b..bde81dccfe 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -113,6 +113,8 @@ proc defineSymbols*() = when not defined(WEB): + # TODO(System\config) add documentation example + # labels: library, documentation, easy builtin "config", alias = unaliased, op = opNop, From 9d8487618d466fc042eb15562581dbae483e6153 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:49:03 +0200 Subject: [PATCH 09/17] System\script: added TODO --- src/library/System.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/library/System.nim b/src/library/System.nim index bde81dccfe..902ecf8b2f 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -365,6 +365,9 @@ proc defineSymbols*() = # another location could also be Paths/path # labels: library,enhancement + # TODO(System\script) add documentation example + # labels: library, documentation, easy + builtin "script", alias = unaliased, op = opNop, From b8e573b07bf5f9e7e30617276972e87ae7309f86 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 13:50:19 +0200 Subject: [PATCH 10/17] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index 1275ac80ab..a0e999ab28 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -859 \ No newline at end of file +860 \ No newline at end of file From 00ca417f487ba4d1d53e576416c59625249da631 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 14:41:00 +0200 Subject: [PATCH 11/17] build update --- version/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/build b/version/build index a0e999ab28..bbf2b7302e 100644 --- a/version/build +++ b/version/build @@ -1 +1 @@ -860 \ No newline at end of file +861 \ No newline at end of file From 6889dfce6546657ec2a6feb03c95f525eb5c3b57 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 16:45:41 +0200 Subject: [PATCH 12/17] minor fix --- examples/rosetta/call a function.art | 4 ++-- examples/rosetta/variadic function.art | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/rosetta/call a function.art b/examples/rosetta/call a function.art index cb6c877eb3..6466e43d3d 100644 --- a/examples/rosetta/call a function.art +++ b/examples/rosetta/call a function.art @@ -7,8 +7,8 @@ sayHello: $[name][ ] printAll: $[args][ - loop args [arg][ - print arg + loop args [argv][ + print argv ] ] diff --git a/examples/rosetta/variadic function.art b/examples/rosetta/variadic function.art index 3f2fdf242c..0e4350c3e5 100644 --- a/examples/rosetta/variadic function.art +++ b/examples/rosetta/variadic function.art @@ -2,8 +2,8 @@ ; a quasi-variadic function ;------------------------------------------- variadic: function [args][ - loop args 'arg [ - print arg + loop args 'argv [ + print argv ] ] From c82b7e439caccb30f10ed8e3fa5a31f63b296170 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 16:46:58 +0200 Subject: [PATCH 13/17] cleanup --- src/library/Sets.nim | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/library/Sets.nim b/src/library/Sets.nim index 94a6bf0f30..c323bb3c12 100644 --- a/src/library/Sets.nim +++ b/src/library/Sets.nim @@ -25,30 +25,6 @@ import helpers/sets import vm/lib -# proc intersection*[A](s1, s2: OrderedSet[A]): OrderedSet[A] = -# ## Returns the intersection of the sets `s1` and `s2`. -# ## -# ## The same as `s1 * s2 <#*,HashSet[A],HashSet[A]>`_. -# ## -# ## The intersection of two sets is represented mathematically as *A ∩ B* and -# ## is the set of all objects that are members of `s1` and `s2` at the same -# ## time. -# ## -# ## See also: -# ## * `union proc <#union,HashSet[A],HashSet[A]>`_ -# ## * `difference proc <#difference,HashSet[A],HashSet[A]>`_ -# ## * `symmetricDifference proc <#symmetricDifference,HashSet[A],HashSet[A]>`_ - -# result = initOrderedSet[A](max(min(s1.len, s2.len), 2)) - -# # iterate over the elements of the smaller set -# if s1.len < s2.len: -# for item in s1: -# if item in s2: incl(result, item) -# else: -# for item in s2: -# if item in s1: incl(result, item) - #======================================= # Methods #======================================= From 27c1d02e77e196361bc7ae93ecf5814135805b41 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 16:52:01 +0200 Subject: [PATCH 14/17] added TODO --- src/vm/exec.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/vm/exec.nim b/src/vm/exec.nim index c1cd1b7d32..074be54093 100644 --- a/src/vm/exec.nim +++ b/src/vm/exec.nim @@ -155,6 +155,20 @@ template callInternal*(fname: string, getValue: bool, args: varargs[Value]): unt when getValue: pop() +# TODO(VM/exec) Leakless blocks not working properly with pre-defined functions +# Let's say we have a pre-defined function (e.g. `arg`) and this symbol is used +# as an iterator variable - which is precisely where leakless blocks come into play - +# this creates a total mess, since their arities are not properly handled. +# e.g. +# ``` +# for arr 'arg [ +# ; do sth +# ] +# ``` +# Also see: https://github.com/arturo-lang/arturo/blob/master/examples/rosetta/call%20a%20function.art +# and https://github.com/arturo-lang/arturo/blob/master/examples/rosetta/variadic%20function.art +# labels: bugs, critical, library, vm, execution + template prepareLeakless*(protected: seq[string] | ValueArray): untyped = ## Prepare for leak-less block execution From d389ac57ac978e246893ad91ddde86dbddcf7cf7 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 16:53:20 +0200 Subject: [PATCH 15/17] updated documentation example --- src/library/System.nim | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/library/System.nim b/src/library/System.nim index 902ecf8b2f..56423c3e39 100644 --- a/src/library/System.nim +++ b/src/library/System.nim @@ -74,9 +74,6 @@ proc defineSymbols*() = attrs = NoAttrs, returns = {Dictionary}, example = """ - ; called with no parameters - args ; => #[ values: [] ] - ; called with: 1 two 3 args ; => #[ From b2910b4991d630b62b9a18a4d01f5c4de9637844 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 16:54:13 +0200 Subject: [PATCH 16/17] updated changelog --- version/changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/version/changelog.md b/version/changelog.md index 46b70ba9cd..fb535fa6f2 100644 --- a/version/changelog.md +++ b/version/changelog.md @@ -47,6 +47,10 @@ v0.9.84 - Numbers\clamp: made to work with Range values instead of lower/upper limits + better type support - Statistics\median: fixed bug + better and more efficient implementation - Strings\match: added support for Char values as needle +- System\arg: converted to built-in method +- System\args: converted to built-in method +- System\config: converted to built-in method +- System\script: converted to built-in method - System\sys: added info about CPU endianess, current hostname and re-organized returned information ### Misc From 66757822f1b836a4cd801da2cffbae9dd443b25b Mon Sep 17 00:00:00 2001 From: drkameleon Date: Wed, 14 Jun 2023 16:57:28 +0200 Subject: [PATCH 17/17] added TODO --- src/vm/env.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vm/env.nim b/src/vm/env.nim index c9185cba0c..7118cac837 100644 --- a/src/vm/env.nim +++ b/src/vm/env.nim @@ -72,6 +72,11 @@ proc parseCmdlineValue(v: string): Value = # TODO(Env\parseCmdlineArguments) verify it's working right # labels: vm,library,language,unit-test + +# TODO(Env\parseCmdlineArguments) should return empty values array when no arguments are given +# currently, calling `args` from a script with no arguments returns a values block with the +# script name as the first and only "argument" (which it's not) +# labels: vm,library,language,enhancement proc parseCmdlineArguments*(): ValueDict = ## parse command-line arguments and return ## result as a Dictionary value