all repos — min @ 5df355178418e67da56d7645306d5604b1fe0eaa

A small but practical concatenative programming language.

Implemented safe mode.
h3rald h3rald@h3rald.com
Sat, 13 Nov 2021 19:14:19 +0100
commit

5df355178418e67da56d7645306d5604b1fe0eaa

parent

8d587ea8cd918353cabda2058531240749490d94

M min.nimmin.nim

@@ -343,6 +343,7 @@ -a, --asset-path Specify a directory containing the asset files to include in the

compiled executable (if -c is set) -c, --compile Compile the specified file -e, --evaluate Evaluate a $exe program inline + -s, --safe Enable runtime checks -h, --help Print this help$iOpt -j, --interactive-simple Start $exe shell (without advanced prompt) -l, --log Set log level (debug|info|notice|warn|error|fatal)

@@ -378,6 +379,8 @@ of "asset-path", "a":

ASSETPATH = val of "prelude", "p": customPrelude = val + of "runtime-checks", "r": + SAFE = true of "log", "l": if file == "": var val = val
M minpkg/core/env.nimminpkg/core/env.nim

@@ -18,3 +18,6 @@ var EDITOR* {.threadvar.}: LineEditor

EDITOR = initEditor(historyFile = MINHISTORY) var MINCOMPILED* {.threadvar.}: bool MINCOMPILED = false +var SAFE* {.threadvar.}: bool +SAFE = false +
M minpkg/core/utils.nimminpkg/core/utils.nim

@@ -7,6 +7,7 @@ parser,

value, json, scope, + env, interpreter # Library methods

@@ -291,6 +292,12 @@

# 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: + # Ignore validation, just return elements + result = newSeq[MinValue](0) + for el in elements: + result.add i.pop + return result let sym = i.currSym.getString var valid = newSeq[string](0) result = newSeq[MinValue](0)
M next-release.mdnext-release.md

@@ -1,1 +1,3 @@

+### BREAKING CHANGES +* Runtime checks (expectations) must now be manually activated by specifying `-s` or `--safe`.
M site/contents/get-started.mdsite/contents/get-started.md

@@ -109,6 +109,10 @@ > %min-terminal%

> > [$](class:prompt) cat myfile.min | min +> %tip% +> +> You can enable runtime checks and validations by spacifying `-s` or `--safe` when running a min program. + ## Compiling a min Program min programs can be compiled to a single executable simply by specifying the `-c` (or `--compile`) flag when executing a min file:
M site/contents/reference-lang.mdsite/contents/reference-lang.md

@@ -115,7 +115,7 @@ {#op||exit||{{i}}||{{none}}||

Exits the program or shell with {{i}} as return code. #} {#op||expect||{{q1}}||{{q2}}|| -> Validates the first _n_ elements of the stack against the type descriptions specified in {{q1}} (_n_ is {{q1}}'s length) and if all the elements are valid returns them wrapped in {{q2}} (in reverse order). +> If the `-s` or `--safe` is specified when running the program, validates the first _n_ elements of the stack against the type descriptions specified in {{q1}} (_n_ is {{q1}}'s length) and if all the elements are valid returns them wrapped in {{q2}} (in reverse order). If the neither `-s` nor `--safe` is specified when running the program, no validation is performed and all elements are just returned in a quotation in reverse order. > > %tip% > > Tips

@@ -286,7 +286,7 @@ > * A quotation identifying the body of the operator.

> > The main additional features offered by this way of defining operators are the following: > -> * 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. +> * (if the `-s` or `--safe` is specified when running the program) 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. > * The full signature of the operator is declared, making the resulting code easier to understand at quick glance. > * 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). > * 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.