all repos — min @ 71e268a39ed32c7bd4726d966660617fda11dc21

A small but practical concatenative programming language.

Added tests for bitwise operations.
h3rald h3rald@h3rald.com
Sat, 07 Oct 2023 16:12:06 +0200
commit

71e268a39ed32c7bd4726d966660617fda11dc21

parent

1456f290e02e96e6641c042ff229a7e3f52e4db2

4 files changed, 27 insertions(+), 26 deletions(-)

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

@@ -278,39 +278,38 @@ 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 + i.push (bitxor(args[1].intVal, args[0].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: + var q: MinValue + i.reqQuotationOfIntegers(q) + var vals = i.expect("int") + var val = vals[0].intVal + for n in q.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: + var q: MinValue + i.reqQuotationOfIntegers(q) + var vals = i.expect("int") + var val = vals[0].intVal + for n in q.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: + var q: MinValue + i.reqQuotationOfIntegers(q) + var vals = i.expect("int") + var val = vals[0].intVal + for n in q.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")
M minpkg/lib/min_str.nimminpkg/lib/min_str.nim

@@ -296,12 +296,12 @@

def.symbol("to-hex") do (i: In): let vals = i.expect("int") let v = vals[0].intVal - i.push (v.toHex(sizeof(v)).newVal) + i.push (("0x"&v.toHex(sizeof(v))).newVal) def.symbol("to-oct") do (i: In): let vals = i.expect("int") let v = vals[0].intVal - i.push (v.toOct(sizeof(v)).newVal) + i.push (("0o"&v.toOct(sizeof(v))).newVal) def.symbol("to-dec") do (i: In): let vals = i.expect("int")

@@ -311,7 +311,7 @@

def.symbol("to-bin") do (i: In): let vals = i.expect("int") let v = vals[0].intVal - i.push (v.toBin(sizeof(v)).newVal) + i.push (("0b"&v.toBin(sizeof(v))).newVal) def.symbol("from-hex") do (i: In): let vals = i.expect("'sym")
M next-release.mdnext-release.md

@@ -2,7 +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. +* Added `bitand`, `bitor`, `bitxor`, `bitparity`, `bitclear`, `bitflip`, `bitset`, `bitmask` symbols for biwise operations. * Added `to-(hex|bin|dec|oct)` and `from-(hex|bin|dec|oct)` symbols to convert integers to and from different string representations. ### Fixes and Improvements
M tests/num.mintests/num.min

@@ -74,14 +74,16 @@

((2 4 6 8) (even?) all?) *test/assert (base? "dec" ==) *test/assert - ('bin base "bin" base? == 'dec base) *test/assert - (0b10010 18 ==) *test/assert - - (0b101010 0b100110 bitand 0b100010 ==) *test/assert - + (0b101010 0b010101 bitand 0b000000 ==) *test/assert (0b101010 0b010101 bitor 0b111111 ==) *test/assert + (0b101010 0b010101 bitxor 0b111111 ==) *test/assert + (0b111000 (0 2) bitflip 0b111101 ==) *test/assert + (0b111001 (0) bitclear 0b111000 ==) *test/assert + (0b111000 (0 1) bitset 0b111011 ==) *test/assert + (0b111000 bitparity 1 ==) *test/assert + (0b111001 0b101010 bitmask 0b101000 ==) *test/assert *test/report clear-stack