duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit e96060d72c5b57dcef7f25da7d16bb9343cec11a
parent 5febd7d20590f533b394aa1d396320e0adbd89c0
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Tue, 12 Jul 2022 11:50:50 -0400

lib/crc: working!

I've compared the result of "thisisatest" with output from a posix machine, and
they match.

Diffstat:
Mfs/asm.fs | 2+-
Mfs/cc/gen.fs | 2+-
Mfs/doc/cc.txt | 2++
Mfs/lib/crc.c | 15++++++++++-----
Mfs/lib/crc.fs | 2+-
Mfs/tests/cc/cc.fs | 1+
Mfs/tests/cc/test.c | 6++++++
Mfs/tests/lib/all.fs | 1+
Mfs/tests/lib/crc.fs | 1+
9 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/fs/asm.fs b/fs/asm.fs @@ -111,7 +111,7 @@ $e9 4 op jmp, $e8 2 op call, dup 1+ c@ ( immreg ) swap 2 + c@ ( immreg immop ) modrm<imm, else c@ src swap ( reg regop ) modrm2, then ; $81 0 $01 op add, $81 7 $39 op cmp, $81 5 $29 op sub, $f7 0 $85 op test, -$81 4 $21 op and, $81 1 $09 op or, $81 6 $33 op xor, +$81 4 $21 op and, $81 1 $09 op or, $81 6 $31 op xor, \ tgt or-ed in : op ( op -- ) doer c, does> ( a -- ) c@ tgtid or c, asm$ ; diff --git a/fs/cc/gen.fs b/fs/cc/gen.fs @@ -203,7 +203,7 @@ ASTIDCNT wordtbl gentbl ( node -- ) ast.pop.opid popgentbl swap wexec ; \ See "Binary op resolution strategy" in opening comment :w ( BinaryOp ) - _debug if ." binop: " dup printast nl> .ops then + _debug if ." binop: " dup printast nl> then selectedop >r ( node ) >r r@ bopgentblpre r@ ast.bop.opid wexec ( node ) firstchild dup nextsibling swap ( n2 n1 ) diff --git a/fs/doc/cc.txt b/fs/doc/cc.txt @@ -38,6 +38,8 @@ For this reason, the core of the language is very close to ANSI. yields 0. * Number literals are the same as Dusk OS, so 12345, $1234 and 'X'. No 0x1234 or 0o777. +* string literals are not null-terminated, but "counted strings". The exact same + format as system strings. ## Caller save diff --git a/fs/lib/crc.c b/fs/lib/crc.c @@ -1,11 +1,16 @@ -// TODO: make this work. Theoretically, CC can compile this -unsigned int crc32(unsigned int crc, char c) { - unsigned int i, b; +// TODO: use char for "c" +// TODO: declare i and b on the same line +// TODO: use >>= +// TODO: replace if (b==1) with if (b) - for (i=0;i<8;i++) { +unsigned int crc32(unsigned int crc, int c) { + unsigned int i; + unsigned int b; + + for (i=0; i<8; i++) { b = (c ^ crc) & 1; crc = crc >> 1; - if (b) { + if (b==1) { crc = crc ^ $EDB88320; } c = c >> 1; diff --git a/fs/lib/crc.fs b/fs/lib/crc.fs @@ -4,4 +4,4 @@ cc<< lib/crc.c \ Computes CRC32 over range "a u". -: crc32[] ( a u -- crc ) A>r >r >A $ffffffff begin ( n ) Ac@+ crc32 next r>A ; +: crc32[] ( a u -- crc ) A>r >r >A -1 begin ( n ) Ac@+ crc32 next -1 xor r>A ; diff --git a/fs/tests/cc/cc.fs b/fs/tests/cc/cc.fs @@ -12,6 +12,7 @@ binopor 42 #eq binopxor 42 #eq binopshl 336 #eq binopshr 10 #eq +2 3 binop1 1 #eq boolops 0 #eq variables 82 #eq funcall 42 #eq diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c @@ -27,6 +27,12 @@ int binopshl() { int binopshr() { return 42 >> 2; } +// test some bug I was having +int binop1(int a, int b) { + int c; + c = a ^ b; + return c; +} int boolops() { return 66 < 54 && 2 == 2; } diff --git a/fs/tests/lib/all.fs b/fs/tests/lib/all.fs @@ -4,3 +4,4 @@ f<< tests/lib/str.fs f<< tests/lib/xdict.fs f<< tests/lib/struct.fs f<< tests/lib/with.fs +f<< tests/lib/crc.fs diff --git a/fs/tests/lib/crc.fs b/fs/tests/lib/crc.fs @@ -2,4 +2,5 @@ ?f<< lib/crc.fs testbegin \ Tests for crc.fs +S" thisisatest" c@+ crc32[] $fba2fc21 #eq testend