nooc

nooc programming language compiler
git clone git://git.nihaljere.xyz/nooc
Log | Files | Refs | LICENSE

commit 2927ef3df25f495a4c4c30c6764c02c10fc98780
parent da9d21d34fa4f9e474e59a9b77faf7622e3619cd
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Thu, 30 Dec 2021 19:19:31 -0600

add reference type and class to replace str

Diffstat:
Mmain.c | 5++++-
Mnooc.h | 4++--
Mparse.c | 1-
Mtest/exitwrite.pass.nooc | 4++--
Mtest/ident_type_mismatch.fail.nooc | 2+-
Mtest/proc_type_mismatch.fail.nooc | 2+-
Mtype.c | 14++++++++------
7 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/main.c b/main.c @@ -299,11 +299,14 @@ check: if (expr->class != C_INT) error(line, col, "expected integer expression for integer declaration"); break; - case TYPE_STR: case TYPE_ARRAY: if (expr->class != C_STR) error(line, col, "expected string expression for array declaration"); break; + case TYPE_REF: + if (expr->class != C_REF) + error(line, col, "expected reference expression for reference declaration"); + break; case TYPE_PROC: if (expr->class != C_PROC) error(line, col, "expected proc expression for proc declaration"); diff --git a/nooc.h b/nooc.h @@ -64,8 +64,8 @@ struct typelist { }; enum typeclass { - TYPE_INT = 1, - TYPE_STR, + TYPE_NONE, + TYPE_INT, TYPE_ARRAY, TYPE_REF, TYPE_PROC, diff --git a/parse.c b/parse.c @@ -114,7 +114,6 @@ typetoclass(struct type *type) switch (type->class) { case TYPE_INT: return C_INT; - case TYPE_STR: case TYPE_ARRAY: return C_STR; case TYPE_REF: diff --git a/test/exitwrite.pass.nooc b/test/exitwrite.pass.nooc @@ -1,5 +1,5 @@ -let write proc(i64, str, i64) (i64) = proc(fd i64, string str, len i64) (out i64) { - out = syscall(1, fd, string, len) +let write proc(i64, $i8, i64) (i64) = proc(fd i64, data $i8, len i64) (out i64) { + out = syscall(1, fd, data, len) return } diff --git a/test/ident_type_mismatch.fail.nooc b/test/ident_type_mismatch.fail.nooc @@ -1,4 +1,4 @@ let main proc() = proc() { let a i64 = 5 - let b str = a + let b $i8 = a } \ No newline at end of file diff --git a/test/proc_type_mismatch.fail.nooc b/test/proc_type_mismatch.fail.nooc @@ -1,4 +1,4 @@ -let exit proc(str) = proc(code i64) { +let exit proc($i8) = proc(code i64) { syscall(60, code) return } diff --git a/type.c b/type.c @@ -62,17 +62,12 @@ inittypes() idx = type_put(&type); mapkey(&key, "i8", 2); mapput(typesmap, &key)->n = idx; - - type.class = TYPE_STR; - type.size = 8; - idx = type_put(&type); - mapkey(&key, "str", 3); - mapput(typesmap, &key)->n = idx; } static void hashtype(struct type *type, uint8_t *out) { + static bool empty_found = false; struct blake3 b3; blake3_init(&b3); @@ -80,6 +75,9 @@ hashtype(struct type *type, uint8_t *out) blake3_update(&b3, &type->class, sizeof(type->class)); blake3_update(&b3, &type->size, sizeof(type->size)); switch (type->class) { + case TYPE_INT: + case TYPE_REF: + break; case TYPE_PROC: blake3_update(&b3, type->d.params.in.data, type->d.params.in.len * sizeof(*type->d.params.in.data)); blake3_update(&b3, type->d.params.out.data, type->d.params.out.len * sizeof(*type->d.params.out.data)); @@ -88,6 +86,10 @@ hashtype(struct type *type, uint8_t *out) blake3_update(&b3, &type->d.arr, sizeof(type->d.arr)); break; default: + if (empty_found) + die("hashtype: unhandled type class"); + else + empty_found = true; } blake3_out(&b3, out, 16);