all repos — min @ 5800edc1b6dac3d6cf21f6461c84c342ddc1069b

A small but practical concatenative programming language.

Merged binary module into num
h3rald h3rald@h3rald.com
Fri, 22 Jan 2021 22:00:25 +0000
commit

5800edc1b6dac3d6cf21f6461c84c342ddc1069b

parent

ab455edbaff6ba083df1154078e2eaaef624fcfb

M min.nimmin.nim

@@ -41,7 +41,6 @@ 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,

@@ -166,7 +165,6 @@ 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
D minpkg/lib/min_binary.nim

@@ -1,52 +0,0 @@

-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.nimminpkg/lib/min_num.nim

@@ -118,6 +118,41 @@ def.symbol("odd?") do (i: In):

let vals = i.expect("int") let n = vals[0] i.push newVal(n.intVal mod 2 != 0) + + 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.symbol("sum") do (i: In): var s: MinValue
M next-release.mdnext-release.md

@@ -4,5 +4,6 @@ * **BREAKING CHANGE** -- **?** is now used as a sigil for **help**, not **dget**.

* Added **help** (and also **?** alias and **?** sigil), **symbol-help**, **sigil-help** * Added **replace-apply**. * Refactored tasks as required modules. -* Added **binary** module (thanks @drkameleon!). +* Added binary operators to num module (thanks @drkameleon!). +* Added **product**, **med**, **avg** and **range** operators to num module (thanks @drkameleon!). * Added Dockerfile (thanks @drkameleon!).
M prelude.minprelude.min

@@ -16,7 +16,6 @@ ) ROOT with

) unless (lite? mini? or) ( ( - 'binary import 'crypto import 'math import 'net import
D site/contents/reference-binary.md

@@ -1,23 +0,0 @@

------ -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.mdsite/contents/reference-num.md

@@ -19,6 +19,21 @@

{#op||/||{{n1}} {{n2}}||{{n3}}|| Divides {{n1}} by {{n2}}. #} +{#op||avg||{{q}}||{{n}}|| +Returns the average of the items of {{q}}. #} + +{#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||even?||{{i}}||{{b}}|| Returns {{t}} if {{i}} is even, {{f}} otherwise. #}

@@ -28,6 +43,9 @@

{#op||inf||{{none}}||{{n}}|| Returns infinity. #} +{#op||med||{{q}}||{{n}}|| +Returns the median of the items of {{q}}. #} + {#op||mod||{{i1}} {{i2}}||{{i3}}|| Returns the integer module of {{i1}} divided by {{i2}}. #}

@@ -39,6 +57,9 @@ Returns {{t}} if {{i}} is odd, {{f}} otherwise. #}

{#op||pred||{{i1}}||{{i2}}|| Returns the predecessor of {{i1}}.#} + +{#op||product||{{q}}||{{i}}|| +Returns the product of all items of {{q}}. {{q}} is a quotation of integers. #} {#op||random||{{i1}}||{{i2}}|| > Returns a random number {{i2}} between 0 and {{i1}}-1.

@@ -51,20 +72,18 @@

{#op||randomize||{{none}}||{{null}|| Initializes the random number generator using a seed based on the current timestamp. #} +{#op||range||{{q2}}||{{q2}}|| +Takes a quotation {{q1}} of two or three integers in the form of *start*, *end* and an optional *step* (1 if not specified) and generates the sequence and returns the resulting quotation of integers {{q2}}. #} + +{#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}}.#} + {#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. #} -{#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.mdsite/contents/reference.md

@@ -30,8 +30,6 @@ {#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.mintests/all.min

@@ -19,7 +19,6 @@ 'sys load

'time load 'dstore load 'fs load -'binary load 'crypto load 'math load 'http load
D tests/binary.min

@@ -1,19 +0,0 @@

-'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.mintests/num.min

@@ -51,6 +51,18 @@ ((6 1 2) range (6 4 2) ==) assert

((6 1 3) range (6 3) ==) assert ((6 0 2) range (6 4 2 0) ==) assert + (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 + (0 :c (c 10 <) (c succ @c) while c 10 ==) assert

@@ -62,4 +74,4 @@

((2 4 6 8) (even?) all?) assert report - clear-stack+ clear-stack