From: Brendan Hansen Date: Sun, 21 Feb 2021 22:37:13 +0000 (-0600) Subject: bugfix with assigning to struct parameters X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=249ae76c20ca2403a4f8f2679e04363f442ad9c0;p=onyx.git bugfix with assigning to struct parameters --- diff --git a/bin/onyx b/bin/onyx index 5e1cdfbd..59479302 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/conv.onyx b/core/conv.onyx index a389df6a..6bfab2af 100644 --- a/core/conv.onyx +++ b/core/conv.onyx @@ -1,5 +1,28 @@ package core.conv +str_to_i64 :: (s: str) -> i64 { + use package core + + value: i64 = 0; + mul := 1; + + if s[0] == #char "-" { + mul = -1; + s = string.advance(s, 1); + } + + for c: s do switch c { + case #char "0" .. #char "9" { + value *= 10; + value += ~~(c - #char "0"); + } + + case #default do break break; + } + + return value * ~~mul; +} + i64_to_str :: (n: i64, base: u64, buf: [] u8, min_length := 0) -> str { is_neg := false; if n < 0 && base == 10 { diff --git a/core/string.onyx b/core/string.onyx index d8976b83..ab8949d5 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -1,5 +1,7 @@ package core.string +use package core + make :: (s: cstr) -> str { len := length(s); @@ -143,6 +145,26 @@ strip_trailing_whitespace :: (s: ^str) { } } +advance :: proc { + // Inplace version + (s: ^str, chars := 1) { + chars = math.min(chars, s.count); + + s.data += chars; + s.count -= chars; + }, + + // Out of place version + (s: str, chars := 1) -> str { + chars = math.min(chars, s.count); + out := s; + + out.data += chars; + out.count -= chars; + + return out; + } +} read_u32 :: (s: ^str, out: ^u32) { n := 0; diff --git a/src/onyxwasm.c b/src/onyxwasm.c index a9742e80..7b533f83 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -402,7 +402,14 @@ EMIT_FUNC(assignment, AstBinaryOp* assign) { emit_expression(mod, &code, assign->right); u64 localidx = bh_imap_get(&mod->local_map, (u64) lval); - WIL(WI_LOCAL_SET, localidx); + + if (lval->kind == Ast_Kind_Param && type_is_structlike_strict(lval->type)) { + u32 mem_count = type_structlike_mem_count(lval->type); + fori (i, 0, mem_count) WIL(WI_LOCAL_SET, localidx + i); + + } else { + WIL(WI_LOCAL_SET, localidx); + } *pcode = code; return;