From 4299f6e24305d61e6c63b6312af1db887bfa864c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 5 Apr 2025 02:26:18 -0400 Subject: [PATCH] More fixes --- examples/base64/base64.tm | 7 +++---- examples/log/log.tm | 2 +- src/compile.c | 2 +- src/typecheck.c | 4 +++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/base64/base64.tm b/examples/base64/base64.tm index fadfed2..e2f5ea1 100644 --- a/examples/base64/base64.tm +++ b/examples/base64/base64.tm @@ -4,8 +4,7 @@ _enc := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/":bytes _EQUAL_BYTE := Byte(0x3D) -_dec := [ - :Byte +_dec : [Byte] = [ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, @@ -32,7 +31,7 @@ lang Base64: output := &[Byte(0) for _ in bytes.length * 4 / 3 + 4] src := Int64(1) dest := Int64(1) - while src + 2 <= bytes.length: + while src + 2 <= Int64(bytes.length): chunk24 := ( (Int32(bytes[src]) <<< 16) or (Int32(bytes[src+1]) <<< 8) or Int32(bytes[src+2]) ) @@ -69,7 +68,7 @@ lang Base64: output := &[Byte(0) for _ in bytes.length/4 * 3] src := Int64(1) dest := Int64(1) - while src + 3 <= bytes.length: + while src + 3 <= Int64(bytes.length): chunk24 := ( (Int32(_dec[1+bytes[src]]) <<< 18) or (Int32(_dec[1+bytes[src+1]]) <<< 12) or diff --git a/examples/log/log.tm b/examples/log/log.tm index f4b0b39..3aa45e7 100644 --- a/examples/log/log.tm +++ b/examples/log/log.tm @@ -3,7 +3,7 @@ use timestamp_format := CString("%F %T") -logfiles : @{Path} = @{} +logfiles : @{Path} = @{/} func _timestamp(->Text): c_str := inline C:CString { diff --git a/src/compile.c b/src/compile.c index c7e02b3..688901a 100644 --- a/src/compile.c +++ b/src/compile.c @@ -4098,7 +4098,7 @@ CORD compile_top_level_code(env_t *env, ast_t *ast) auto decl = Match(ast, Declare); const char *decl_name = Match(decl->var, Var)->name; CORD full_name = CORD_all(namespace_prefix(env, env->namespace), decl_name); - type_t *t = get_type(env, decl->value); + type_t *t = decl->type ? parse_type_ast(env, decl->type) : get_type(env, decl->value); if (t->tag == AbortType || t->tag == VoidType || t->tag == ReturnType) code_err(ast, "You can't declare a variable with a ", type_to_str(t), " value"); diff --git a/src/typecheck.c b/src/typecheck.c index 7b86ec6..bc9ae07 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -892,7 +892,9 @@ type_t *get_type(env_t *env, ast_t *ast) if (streq(call->name, "serialized")) // Data serialization return Type(ArrayType, Type(ByteType)); - type_t *self_value_t = value_type(get_type(env, call->self)); + type_t *self_value_t = get_type(env, call->self); + if (!self_value_t) code_err(call->self, "Couldn't get the type of this value"); + self_value_t = value_type(self_value_t); switch (self_value_t->tag) { case ArrayType: { type_t *item_type = Match(self_value_t, ArrayType)->item_type;