Merge branch 'master' into next
h3rald h3rald@h3rald.com
Thu, 21 Jan 2021 18:44:35 +0100
7 files changed,
100 insertions(+),
0 deletions(-)
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
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.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