all repos — min @ 0ab90668a5850ebe292e222ed776b85c755576d6

A small but practical concatenative programming language.

Implemented bitwise operators.
h3rald h3rald@h3rald.com
Sat, 07 Oct 2023 14:03:25 +0200
commit

0ab90668a5850ebe292e222ed776b85c755576d6

parent

b5d0cb6284267493b524873b7aafc03531c5ebbe

4 files changed, 54 insertions(+), 4 deletions(-)

jump to
M minpkg/lib/min_crypto.nimminpkg/lib/min_crypto.nim

@@ -1,7 +1,6 @@

import std/[base64, strutils, - macros, times] import ../vendor/aes/aes
M minpkg/lib/min_http.nimminpkg/lib/min_http.nim

@@ -1,6 +1,5 @@

import - std/[macros, - httpclient, + std/[httpclient, asynchttpserver, asyncdispatch, strutils,
M minpkg/lib/min_num.nimminpkg/lib/min_num.nim

@@ -1,6 +1,7 @@

import std/[random, - strutils] + strutils, + bitops] import ../core/parser, ../core/value,

@@ -266,5 +267,55 @@ of baseHex:

i.push "hex".newVal of baseBin: i.push "bin".newVal + + def.symbol("bitand") do (i: In): + let args = i.expect("int", "int") + i.push (bitand(args[0].intVal, args[1].intVal)).newVal + + def.symbol("bitor") do (i: In): + let args = i.expect("int", "int") + i.push (bitor(args[0].intVal, args[1].intVal)).newVal + + def.symbol("bitxor") do (i: In): + let args = i.expect("int", "int") + i.push (bitxor(args[0].intVal, args[1].intVal)).newVal + + def.symbol("bitclear") do (i: In): + var args = i.expect("int", "quot") + i.reqQuotationOfIntegers(args[1]) + var val = args[0].intVal + for n in args[1].qVal: + val.clearBits(n.intVal) + i.push val.newVal + + def.symbol("bitset") do (i: In): + var args = i.expect("int", "quot") + i.reqQuotationOfIntegers(args[1]) + var val = args[0].intVal + for n in args[1].qVal: + val.setBits(n.intVal) + i.push val.newVal + + def.symbol("bitflip") do (i: In): + var args = i.expect("int", "quot") + i.reqQuotationOfIntegers(args[1]) + var val = args[0].intVal + for n in args[1].qVal: + val.flipBits(n.intVal) + i.push val.newVal + + def.symbol("bitparity") do (i: In): + let args = i.expect("int") + i.push (args[0].intVal.parityBits).newVal + + def.symbol("bitreverse") do (i: In): + let args = i.expect("int") + i.push (args[0].intVal.uint.reverseBits.int).newVal + + def.symbol("bitmask") do (i: In): + let args = i.expect("int", "int") + var val = args[0].intVal + val.mask(args[1].intVal) + i.push val.newVal def.finalize("num")
M next-release.mdnext-release.md

@@ -2,6 +2,7 @@ ### New Features

* Added support for binary (0b) octal (0o), and hexadecimal (0x) integers in parser. * Added `base` and `base?` symbols to set and get the current number base (dec, hex, bin or oct). +* Added `bitand`, `bitor`, `bitxor`, `bitparity`, `bitreverse`, `bitclear`, `bitflip`, `bitset`, `bitmask` symbols for biwise operations. ### Fixes and Improvements