duskos

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

commit 7ddac090d31a00d3c9f1902a3088b3bd2311da68
parent 50d22c9a5b6739ab41a7b6d0178435f875c85214
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sat, 25 Mar 2023 21:12:37 -0400

halcc: get8b()

Diffstat:
Mfs/comp/c/expr.fs | 1+
Mfs/comp/c/type.fs | 3++-
Mfs/tests/comp/c/cc.fs | 2+-
Mfs/tests/comp/c/test2.c | 6++++++
4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/comp/c/expr.fs b/fs/comp/c/expr.fs @@ -68,6 +68,7 @@ struct[ Result : :cdecl# dup :iscdecl? _assert arg ; : :opsz ( halop self -- halop ) + \ TODO: this logic is the same as in CDecl :halop. deduplicate. bi+ lvl | blvl = if basesz case 1 of = 8b) endof 2 of = 16b) endof endcase else drop then ; diff --git a/fs/comp/c/type.fs b/fs/comp/c/type.fs @@ -89,7 +89,8 @@ struct[ CDecl STORAGE_PS of = PSP+) endof STORAGE_MEM of = over :funcsig? if i) else m) then endof _err endcase ( self operand ) - swap type _typesize case 1 of = 8b) endof 2 of = 16b) endof endcase ; + over lvl if nip else + swap type _typesize case 1 of = 8b) endof 2 of = 16b) endof endcase then ; \ Combined size of all fields in the LL. : :size ( self -- size ) diff --git a/fs/tests/comp/c/cc.fs b/fs/tests/comp/c/cc.fs @@ -57,9 +57,9 @@ forempty \ no crash -1 0 ltu not # 0 boolnot 1 #eq 42 boolnot 0 #eq -testend \s S" foobar" 2 get8b 'o' #eq S" foobar" 4 get8b 'b' #eq +testend \s S" foobar" dup 2 'X' set8b S" fXobar" #s= S" foobar" dup 6 'X' set8b S" foobaX" #s= typecast 1 #eq diff --git a/fs/tests/comp/c/test2.c b/fs/tests/comp/c/test2.c @@ -224,3 +224,9 @@ int ltu(unsigned int a, unsigned int b) { int boolnot(int x) { return !x; } +char get8b(char *s, int i) { + return s[i]; // 0th is length +} +void set8b(char *s, int i, char c) { + s[i] = c; +}