Added dev? symbol.
h3rald h3rald@h3rald.com
Sat, 13 Nov 2021 21:31:43 +0100
9 files changed,
49 insertions(+),
19 deletions(-)
M
help.json
→
help.json
@@ -26,6 +26,16 @@ "description": "See run",
"kind": "symbol", "name": "&" }, + "&&": { + "description": "See expect-all", + "kind": "symbol", + "name": "&&" + }, + "||": { + "description": "See expect-any", + "kind": "symbol", + "name": "||" + }, "'": { "description": "See quotesym", "kind": "symbol",@@ -44,10 +54,9 @@ "name": "+",
"signature": "num1 num2 ==> num3" }, "-": { - "description": "Subtracts num2 from num1.", + "description": "See dequote", "kind": "symbol", - "name": "-", - "signature": "num1 num2 ==> num3" + "name": "-" }, "-inf": { "description": "Returns negative infinity.",@@ -512,6 +521,12 @@ "kind": "symbol",
"name": "dequote", "signature": "quot ==> a*" }, + "dev?": { + "description": "Returns true if the current program is being executed in development mode.", + "kind": "symbol", + "name": "dev?", + "signature": " ==> bool" + }, "dget": { "description": "Returns the value of key 'sym from dictionary dict.", "kind": "symbol",@@ -717,7 +732,7 @@ "name": "exit",
"signature": "int ==> " }, "expect": { - "description": "Validates the first _n_ elements of the stack against the type descriptions specified in quot1 (_n_ is quot1's length) and if all the elements are valid returns them wrapped in quot2 (in reverse order). \n\n \n Tips\n \n * You can specify a typed dictionary by prepending the type name with dict:. Example: dict:socket\n * You can specify two or more matching types by separating combined together in a logical type expression, e.g.: string|quot\n\n \n Example\n \n Assuming that the following elements are on the stack (from top to bottom): \n \n 1 \"test\" 3.4\n \n the following program evaluates to true:\n \n (int string num) expect (3.4 \"test\" 1) ==", + "description": "If the -d (--dev) flag is specified when running the program, validates the first _n_ elements of the stack against the type descriptions specified in quot1 (_n_ is quot1's length) and if all the elements are valid returns them wrapped in quot2 (in reverse order). If the -d (--dev) flag is not specified when running the program, no validation is performed and all elements are just returned in a quotation in reverse order. \n\n \n Tips\n \n * You can specify a typed dictionary by prepending the type name with dict:. Example: dict:socket\n * You can specify two or more matching types by separating combined together in a logical type expression, e.g.: string|quot\n\n \n Example\n \n Assuming that the following elements are on the stack (from top to bottom): \n \n 1 \"test\" 3.4\n \n the following program evaluates to true:\n \n (int string num) expect (3.4 \"test\" 1) ==", "kind": "symbol", "name": "expect", "signature": "quot1 ==> quot2"@@ -1257,7 +1272,7 @@ "name": "one?",
"signature": "quot1 quot2 ==> bool" }, "operator": { - "description": "Provides a way to define a new operator (symbol, sigil, or typeclass) on the current scope performing additional checks (compared to define and define-sigil), and automatically mapping inputs and outputs.\n \n quot is a quotation containing:\n \n * A symbol identifying the type of operator to define (symbol, sigil, or typeclass).\n * A symbol identifying the name of the operator.\n * A quotation defining the signature of the operatorm containing input and output values identified by their type and a capturing symbol, separated by the == symbol.\n * A quotation identifying the body of the operator.\n\n The main additional features offered by this way of defining operators are the following:\n\n * Both input and output values are checked against a type (like when using the expect operator *and* automatically captured in a symbol that can be referenced in the operator body quotation.\n * The full signature of the operator is declared, making the resulting code easier to understand at quick glance.\n * An exception is automatically raised if the operator body pollutes the stack by adding or removing elementa from the stack (besides adding the declared output values).\n * It is possible to use the return symbol within the body quotation to immediately stop the evaluation of the body quotation and automatically push the output values on the stack.\n \n \n Example\n \n The following program defines a pow operator that calculates the power of a number providing its base and exponent, and handling some NaN results using the return symbol:\n\n (\n symbol pow\n (num :base int :exp == num :result)\n ( \n (base 0 == exp 0 == and)\n (nan @result return)\n when\n (base 1 == exp inf == and)\n (nan @result return)\n when\n (base inf == exp 0 == and)\n (nan @result return)\n when\n exp 1 - :n\n base (dup) n times (*) n times @result\n )\n ) ::", + "description": "Provides a way to define a new operator (symbol, sigil, or typeclass) on the current scope performing additional checks (compared to define and define-sigil), and automatically mapping inputs and outputs.\n \n quot is a quotation containing:\n \n * A symbol identifying the type of operator to define (symbol, sigil, or typeclass).\n * A symbol identifying the name of the operator.\n * A quotation defining the signature of the operatorm containing input and output values identified by their type and a capturing symbol, separated by the == symbol.\n * A quotation identifying the body of the operator.\n\n The main additional features offered by this way of defining operators are the following:\n\n * If in development mode (-d or --dev flag specified at run time), both input and output values are checked against a type (like when using the expect operator *and* automatically captured in a symbol that can be referenced in the operator body quotation.\n * The full signature of the operator is declared, making the resulting code easier to understand at quick glance.\n * An exception is automatically raised if the operator body pollutes the stack by adding or removing elementa from the stack (besides adding the declared output values).\n * It is possible to use the return symbol within the body quotation to immediately stop the evaluation of the body quotation and automatically push the output values on the stack.\n \n \n Example\n \n The following program defines a pow operator that calculates the power of a number providing its base and exponent, and handling some NaN results using the return symbol:\n\n (\n symbol pow\n (num :base int :exp == num :result)\n ( \n (base 0 == exp 0 == and)\n (nan @result return)\n when\n (base 1 == exp inf == and)\n (nan @result return)\n when\n (base inf == exp 0 == and)\n (nan @result return)\n when\n exp 1 - :n\n base (dup) n times (*) n times @result\n )\n ) ::", "kind": "symbol", "name": "operator", "signature": "quot ==> a*"
M
minpkg/core/env.nim
→
minpkg/core/env.nim
@@ -18,6 +18,6 @@ var EDITOR* {.threadvar.}: LineEditor
EDITOR = initEditor(historyFile = MINHISTORY) var MINCOMPILED* {.threadvar.}: bool MINCOMPILED = false -var SAFE* {.threadvar.}: bool -SAFE = false +var DEV* {.threadvar.}: bool +DEV = false
M
minpkg/core/utils.nim
→
minpkg/core/utils.nim
@@ -292,7 +292,7 @@
# The following is used in operator signatures proc expect*(i: var MinInterpreter, elements: varargs[string], generics: var CritBitTree[string]): seq[MinValue] {.gcsafe.}= - if not SAFE: + if not DEV: # Ignore validation, just return elements result = newSeq[MinValue](0) for el in elements:
M
minpkg/lib/min_lang.nim
→
minpkg/lib/min_lang.nim
@@ -993,6 +993,9 @@
def.symbol("compiled?") do (i: In): i.push MINCOMPILED.newVal + def.symbol("dev?") do (i: In): + i.push DEV.newVal + def.symbol("line-info") do (i: In): var d = newDict(i.scope) i.dset(d, "filename", i.currSym.filename.newVal)
M
next-release.md
→
next-release.md
@@ -1,3 +1,4 @@
### BREAKING CHANGES * Runtime checks (expectations) must now be manually activated by specifying `-d` or `--dev`. +* Added **dev?** symbol to check if we are running in development mode.
M
site/contents/get-started.md
→
site/contents/get-started.md
@@ -111,7 +111,7 @@ > [$](class:prompt) cat myfile.min | min
> %tip% > -> You can enable runtime checks and validations by spacifying `-d` (`--dev`) when running a min program. +> You can enable _development mode_ (runtime checks and validations) by spacifying `-d` (`--dev`) when running a min program. If development mode is not enabled, min programs run faster. ## Compiling a min Program
M
site/contents/reference-lang.md
→
site/contents/reference-lang.md
@@ -108,6 +108,9 @@ > Pushes the contents of quotation {{q}} on the stack.
> > Each element is pushed on the stack one by one. If any error occurs, {{q}} is restored on the stack.#} +{#op||dev?||{{none}}||{{b}}|| +Returns {{t}} if the current program is being executed in development mode.#} + {#op||eval||{{s}}||{{a0p}}|| Parses and interprets {{s}}. #}
M
tests/lang.min
→
tests/lang.min
@@ -133,7 +133,10 @@ (sys scope-sigils ("!" "$" "&") ==) *test/assert
({3 :a 5 :b} scope-symbols ("a" "b") ==) *test/assert - (opts {} ==) *test/assert + (dev?) + ((opts {true :d} ==) *test/assert) + ((opts {} ==) *test/assert) + if (args first "\.min$" match?) *test/assert@@ -271,14 +274,19 @@ symbol natural-sum
(natural :n natural :m ==> natural :result) (n m + @result) ) :: - null :err - ( - (3 -3 natural-sum) - (@err) - ) try - pop ;Remove 3 that was left on the stack. - (err format-error "expected: natural natural natural-sum" match?) *test/assert - (2 3 natural-sum 5 ==) *test/assert + (dev?) + ( + null :err + ( + (3 -3 natural-sum) + (@err) + ) try + pop ;Remove 3 that was left on the stack. + (err format-error "expected: natural natural natural-sum" match?) *test/assert + (2 3 natural-sum 5 ==) *test/assert + ) + when + ( constructor test-c