Merge branch 'master' of github.com:h3rald/min
h3rald h3rald@h3rald.com
Fri, 22 Jan 2021 20:54:50 +0000
14 files changed,
274 insertions(+),
8 deletions(-)
A
Dockerfile
@@ -0,0 +1,32 @@
+# use Alpine+Nim as a basis +FROM frolvlad/alpine-nim + +# install necessary packages +RUN apk update +RUN apk add curl git + +# clone repository +RUN git clone https://github.com/h3rald/min.git + +# install nifty +RUN nimble install -y nifty + +# set path to nifty +# (for some reason it doesn't pick it up by itself) +ENV PATH="/root/.nimble/pkgs/nifty-1.2.2:${PATH}" + +# install dependencies with nifty +RUN cd min && nifty install + +# build min +RUN cd min && nim c -d:release -d:ssl -o:min min + +# set our PATH to the min's location +ENV PATH="/min:${PATH}" + +# set our workdir to /home +# (where our local files will be mirrored) +WORKDIR /home + +# start up the main binary +ENTRYPOINT [ "/min/min" ]
M
README.md
→
README.md
@@ -1,10 +1,14 @@
-min -===== -A tiny concatenative programming language and shell. +<p align="center"><img align="center" width="350" src="logo_darker.svg"/></p> +<p align="center"> + <b>A tiny concatenative<br>programming language and shell</b> + <br><br> + <img src="https://img.shields.io/badge/nim-powered-yellow.svg?link=https://nim-lang-org"> + <img src="https://img.shields.io/github/release/h3rald/min/all.svg"> + <img src="https://img.shields.io/github/license/h3rald/min.svg"> +</p> -For more info, go to <https://min-lang.org>. +--- + +► For more info, go to <https://min-lang.org>. -![nim](https://img.shields.io/badge/nim-powered-yellow.svg?link=https://nim-lang-org) -![release](https://img.shields.io/github/release/h3rald/min/all.svg) -![license](https://img.shields.io/github/license/h3rald/min.svg)
A
logo.svg
@@ -0,0 +1,15 @@
+<svg width="588" height="588" xmlns="http://www.w3.org/2000/svg"> + <!-- Created with Method Draw - http://github.com/duopixel/Method-Draw/ --> + <g> + <title>Layer 1</title> + <g id="widget" transform="rotate(-0.0926624983549118 294.3764648437568,302.3101196289116) matrix(7.224760791089692,0,0,7.224760791089692,1091.8911354197558,1091.8773791888611) "> + + <path d="m-110.235944,-85.470377l-36.91286,6.2079l36.91286,6.1644l36.61214,-6.1644l-36.61214,-6.2079z" fill="#36a631" id="svg_2"/> + <path d="m-110.235944,-91.847177l-36.91286,6.2079l36.91286,6.1644l36.61214,-6.1644l-36.61214,-6.2079z" fill="#6bbc57" id="svg_3"/> + <path d="m-110.235944,-97.842677l-36.91286,6.2079l36.91286,6.1644l36.61214,-6.1644l-36.61214,-6.2079z" fill="#8dd97f" id="svg_4"/> + <path d="m-147.148804,-129.159877l5.5719,0l0,2.2288q1.6097,-1.684 2.7489,-2.2784q1.2134,-0.6191 3.046,-0.6191q4.0861,0 6.4634,3.5661q2.625,-3.5661 7.1074,-3.5661q8.14741,0 8.14741,9.881l0,14.90805l-5.59672,0l0,-13.39746q0,-3.46699 -0.84199,-4.90329q-0.8667,-1.4611 -2.8479,-1.4611q-2.3031,0 -3.3555,1.7335q-1.0525,1.7335 -1.0525,5.57193l0,12.45642l-5.5967,0l0,-13.32317q0,-6.43868 -3.7147,-6.43868q-2.3526,0 -3.4298,1.7582q-1.0773,1.7583 -1.0773,5.54723l0,12.45642l-5.5719,0l0,-24.12035z" fill="#bde9b7" id="svg_5"/> + <path d="m-101.458794,-129.159877l0,24.12035l-5.57195,0l0,-24.12035l5.57195,0zm-6.41394,-10.0296q0,-1.461 1.06486,-2.5259q1.06487,-1.0649 2.55072,-1.0649q1.51062,0 2.57548,1.0649q1.06487,1.0401 1.06487,2.5507q0,1.5106 -1.06487,2.5755q-1.04009,1.0649 -2.55071,1.0649q-1.51062,0 -2.57549,-1.0649q-1.06486,-1.0649 -1.06486,-2.6003z" fill="#bde9b7" id="svg_6"/> + <path d="m-94.401004,-129.159877l5.5967,0l0,2.2288q2.9222,-2.8975 6.5873,-2.8975q4.21,0 6.5626,2.6498q2.0306,2.2536 2.0306,7.355l0,14.78425l-5.5967,0l0,-13.47175q0,-3.5661 -0.9906,-4.9281q-0.9658,-1.3868 -3.5165,-1.3868q-2.7736,0 -3.9375,1.8326q-1.1392,1.8078 -1.1392,6.31485l0,11.6392l-5.5967,0l0,-24.12035z" fill="#bde9b7" id="svg_7"/> + </g> + </g> +</svg>
A
logo_darker.svg
@@ -0,0 +1,15 @@
+<svg width="588" height="588" xmlns="http://www.w3.org/2000/svg"> + <!-- Created with Method Draw - http://github.com/duopixel/Method-Draw/ --> + <g> + <title>Layer 1</title> + <g id="widget" transform="rotate(-0.0926624983549118 294.3764648437568,302.3101196289116) matrix(7.224760791089692,0,0,7.224760791089692,1091.8911354197558,1091.8773791888611) "> + + <path d="m-110.235944,-85.470377l-36.91286,6.2079l36.91286,6.1644l36.61214,-6.1644l-36.61214,-6.2079z" fill="#64b558" id="svg_2"/> + <path d="m-110.235944,-91.847177l-36.91286,6.2079l36.91286,6.1644l36.61214,-6.1644l-36.61214,-6.2079z" fill="#4a923b" id="svg_3"/> + <path d="m-110.235944,-97.842677l-36.91286,6.2079l36.91286,6.1644l36.61214,-6.1644l-36.61214,-6.2079z" fill="#247b1f" id="svg_4"/> + <path d="m-147.148804,-129.159877l5.5719,0l0,2.2288q1.6097,-1.684 2.7489,-2.2784q1.2134,-0.6191 3.046,-0.6191q4.0861,0 6.4634,3.5661q2.625,-3.5661 7.1074,-3.5661q8.14741,0 8.14741,9.881l0,14.90805l-5.59672,0l0,-13.39746q0,-3.46699 -0.84199,-4.90329q-0.8667,-1.4611 -2.8479,-1.4611q-2.3031,0 -3.3555,1.7335q-1.0525,1.7335 -1.0525,5.57193l0,12.45642l-5.5967,0l0,-13.32317q0,-6.43868 -3.7147,-6.43868q-2.3526,0 -3.4298,1.7582q-1.0773,1.7583 -1.0773,5.54723l0,12.45642l-5.5719,0l0,-24.12035z" fill="#93cd8d" id="svg_5"/> + <path d="m-101.458794,-129.159877l0,24.12035l-5.57195,0l0,-24.12035l5.57195,0zm-6.41394,-10.0296q0,-1.461 1.06486,-2.5259q1.06487,-1.0649 2.55072,-1.0649q1.51062,0 2.57548,1.0649q1.06487,1.0401 1.06487,2.5507q0,1.5106 -1.06487,2.5755q-1.04009,1.0649 -2.55071,1.0649q-1.51062,0 -2.57549,-1.0649q-1.06486,-1.0649 -1.06486,-2.6003z" fill="#93cd8d" id="svg_6"/> + <path d="m-94.401004,-129.159877l5.5967,0l0,2.2288q2.9222,-2.8975 6.5873,-2.8975q4.21,0 6.5626,2.6498q2.0306,2.2536 2.0306,7.355l0,14.78425l-5.5967,0l0,-13.47175q0,-3.5661 -0.9906,-4.9281q-0.9658,-1.3868 -3.5165,-1.3868q-2.7736,0 -3.9375,1.8326q-1.1392,1.8078 -1.1392,6.31485l0,11.6392l-5.5967,0l0,-24.12035z" fill="#93cd8d" id="svg_7"/> + </g> + </g> +</svg>
M
min.nim
→
min.nim
@@ -41,6 +41,7 @@ minpkg/lib/min_fs
when not defined(lite) and not defined(mini): import + minpkg/lib/min_binary, minpkg/lib/min_http, minpkg/lib/min_net, minpkg/lib/min_crypto,@@ -165,6 +166,7 @@ i.fs_module
i.dstore_module i.io_module when not defined(lite) and not defined(mini): + i.binary_module i.crypto_module i.net_module i.math_module
A
minpkg/lib/min_binary.nim
@@ -0,0 +1,52 @@
+import + ../core/parser, + ../core/value, + ../core/interpreter, + ../core/utils + +proc binary_module*(i: In)= + + let def = i.define() + + def.symbol("bitand") do (i: In): + let vals = i.expect("int","int") + let b = vals[0] + let a = vals[1] + + i.push newVal(a.intVal and b.intVal) + + def.symbol("bitnot") do (i: In): + let vals = i.expect("int") + let a = vals[0] + + i.push newVal(not a.intVal) + + def.symbol("bitor") do (i: In): + let vals = i.expect("int","int") + let b = vals[0] + let a = vals[1] + + i.push newVal(a.intVal or b.intVal) + + def.symbol("bitxor") do (i: In): + let vals = i.expect("int","int") + let b = vals[0] + let a = vals[1] + + i.push newVal(a.intVal xor b.intVal) + + def.symbol("shl") do (i: In): + let vals = i.expect("int","int") + let b = vals[0] + let a = vals[1] + + i.push newVal(a.intVal shl b.intVal) + + def.symbol("shr") do (i: In): + let vals = i.expect("int","int") + let b = vals[0] + let a = vals[1] + + i.push newVal(a.intVal shr b.intVal) + + def.finalize("binary")
M
minpkg/lib/min_num.nim
→
minpkg/lib/min_num.nim
@@ -135,4 +135,73 @@ i.push c.int.newVal
else: i.push c.newVal + def.symbol("product") do (i: In): + var s: MinValue + i.reqQuotationOfNumbers s + var c = 1.float + var isInt = true + for n in s.qVal: + if n.isFloat: + isInt = false + c = c * n.floatVal + else: + c = c * n.intVal.float + if isInt: + i.push c.int.newVal + else: + i.push c.newVal + + def.symbol("avg") do (i: In): + var s: MinValue + i.reqQuotationOfNumbers s + var c = 0.float + for n in s.qVal: + if n.isFloat: + c = + n.floatVal + else: + c = c + n.intVal.float + c = c / len(s.qVal).float + i.push c.newVal + + def.symbol("med") do (i: In): + var s: MinValue + i.reqQuotationOfNumbers s + let first = s.qVal[(s.qVal.len-1) div 2] + let second = s.qVal[((s.qVal.len-1) div 2)+1] + if s.qVal.len mod 2 == 1: + i.push first + else: + if first.isFloat: + if second.isFloat: + i.push ((first.floatVal+second.floatVal)/2).newVal + else: + i.push ((first.floatVal+second.intVal.float)/2).newVal + else: + if second.isFloat: + i.push ((first.intVal.float+second.floatVal)/2).newVal + else: + i.push ((first.intVal+second.intVal).float/2).newVal + + def.symbol("range") do (i: In): + var s: MinValue + i.reqQuotationOfNumbers s + var a = s.qVal[0] + var b = s.qVal[1] + var step = 1.newVal + var res = newSeq[MinValue](0) + if len(s.qVal)==3: + a = s.qVal[0] + b = s.qVal[1] + step = s.qVal[2] + var j = a + if a.intVal < b.intVal: + while j.intVal <= b.intVal: + res.add j + j = (j.intVal + step.intVal).newVal + else: + while j.intVal >= b.intVal: + res.add j + j = (j.intVal - step.intVal).newVal + i.push res.newVal + def.finalize("num")
M
prelude.min
→
prelude.min
@@ -16,6 +16,7 @@ ) ROOT with
) unless (lite? mini? or) ( ( + 'binary import 'crypto import 'math import 'net import
A
site/contents/reference-binary.md
@@ -0,0 +1,23 @@
+----- +content-type: "page" +title: "binary Module" +----- +{@ _defs_.md || 0 @} + +{#op||bitand||{{i1}} {{i2}}||{{i3}}|| +Computes the bitwise *and* of numbers {{i1}} and {{i2}}.#} + +{#op||bitnot||{{i1}}||{{i2}}|| +Computes the bitwise *complement* of {{i1}}.#} + +{#op||bitor||{{i1}} {{i2}}||{{i3}}|| +Computes the bitwise *or* of numbers {{i1}} and {{i2}}.#} + +{#op||bitxor||{{i1}} {{i2}}||{{i3}}|| +Computes the bitwise *xor* of numbers {{i1}} and {{i2}}.#} + +{#op||shl||{{i1}} {{i2}}||{{i3}}|| +Computes the *shift left* operation of {{i1}} and {{i2}}.#} + +{#op||shr||{{i1}} {{i2}}||{{i3}}|| +Computes the *shift right* operation of {{i1}} and {{i2}}.#}
M
site/contents/reference-num.md
→
site/contents/reference-num.md
@@ -55,4 +55,16 @@ {#op||succ||{{i1}}||{{i2}}||
Returns the successor of {{i1}}.#} {#op||sum||{{q}}||{{i}}|| -Returns the sum of all items of {{q}}. {{q}} is a quotation of integers. #}+Returns the sum of all items of {{q}}. {{q}} is a quotation of integers. #} + +{#op||product||{{q}}||{{i}}|| +Returns the product of all items of {{q}}. {{q}} is a quotation of integers. #} + +{#op||avg||{{q}}||{{n}}|| +Returns the average of the items of {{q}}. #} + +{#op||med||{{q}}||{{n}}|| +Returns the median of the items of {{q}}. #} + +{#op||range||{{q}}||{{q}}|| +Takes a quotation of integers in the form of {{start}}, {{end}} (,{{step}}), generates the sequence and returns the resulting quotation of integers. #}
M
site/contents/reference.md
→
site/contents/reference.md
@@ -30,6 +30,8 @@ {#link-module||num#}
: Provides operators to perform simple mathematical operations on integer and floating point numbers. {#link-module||time#} : Provides a few basic operators to manage dates, times, and timestamps. +{#link-module||binary#} +: Provides main bitwise operators (and, not, or, etc) {#link-module||crypto#} : Provides operators to compute hashes (MD4, MD5, SHA1, SHA224, SHA256, SHA384, sha512), base64 encoding/decoding, and AES encryption/decryption. {#link-module||math#}
M
tests/all.min
→
tests/all.min
@@ -19,6 +19,7 @@ 'sys load
'time load 'dstore load 'fs load +'binary load 'crypto load 'math load 'http load
A
tests/binary.min
@@ -0,0 +1,19 @@
+'test load +'test import + +"binary" describe + + (2 3 bitand 2 ==) assert + + (123 bitnot -124 ==) assert + + (2 3 bitor 3 ==) assert + + (2 3 bitxor 1 ==) assert + + (2 3 shl 16 ==) assert + + (16 3 shr 2 ==) assert + + report + clear-stack
M
tests/num.min
→
tests/num.min
@@ -32,6 +32,25 @@ (1000 random 1000 <) assert
((1 2 3 4 5) sum 15 ==) assert + ((1 2 3 4 5) product 120 ==) assert + + ((1 2 3 4 5) avg 3.0 ==) assert + ((1 2 3 4 5 6) avg 3.5 ==) assert + + ((1 3 5 7) med 4.0 ==) assert + ((1 3 5 7 9) med 5 ==) assert + + ((1 5) range (1 2 3 4 5) ==) assert + ((5 1) range (5 4 3 2 1) ==) assert + ((4 7) range (4 5 6 7) ==) assert + ((7 4) range (7 6 5 4) ==) assert + ((1 6 2) range (1 3 5) ==) assert + ((1 6 3) range (1 4) ==) assert + ((0 6 2) range (0 2 4 6) ==) assert + ((6 1 2) range (6 4 2) ==) assert + ((6 1 3) range (6 3) ==) assert + ((6 0 2) range (6 4 2 0) ==) assert + (0 :c (c 10 <) (c succ @c) while c 10 ==) assert