ox

The Ox programming language, compiler and tools (WIP)
Log | Files | Refs | README | LICENSE

commit c45658a06f32412c860b27a90a922ab99aa4064b
parent 6539df07a2178458a893d0ce96ae5efed89b5204
Author: citbl <citbl@citbl.org>
Date:   Mon,  1 Dec 2025 21:02:02 +1000

fix test with variadic implemented

Diffstat:
M.zed/debug.json | 2+-
Asrc/arc_list.h | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/gen/gen.c | 4++--
Mtests/ex-assignment-1.ox | 2+-
Mtests/ex-binop-simple1.ox | 2+-
Mtests/ex-decl-no-init2.ox | 2+-
Mtests/ex-for-advanced2.ox | 4++--
Mtests/ex-for-no-parens.ox | 4++--
Mtests/ex-for-simple1.ox | 2+-
Mtests/ex-subscript-simple.ox | 2+-
Mtests/ex12.ox | 2+-
11 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/.zed/debug.json b/.zed/debug.json @@ -11,7 +11,7 @@ "cwd": "$ZED_WORKTREE_ROOT" }, "program": "$ZED_WORKTREE_ROOT/oxc", - "args": ["$ZED_WORKTREE_ROOT/tests/ex-for-simple2.ox"], + "args": ["$ZED_WORKTREE_ROOT/tests/ex-binop-simple1.ox"], "request": "launch", "adapter": "CodeLLDB" } diff --git a/src/arc_list.h b/src/arc_list.h @@ -0,0 +1,73 @@ + +#pragma once +#include <stdlib.h> +#include <string.h> +#include "utils.h" + +typedef struct ArcList { + size_t refcount; + size_t len; + size_t cap; + size_t element_size; + unsigned char* data; +} ArcList; + +static inline ArcList* +arc_list_new(size_t elem_size) +{ + ArcList* l = calloc(1, sizeof(*l)); + if (!l) panic("arc list cannot alloc"); + l->refcount = 1; + l->len = l->cap = 0; + l->element_size = elem_size; + l->data = NULL; + return l; +} + +static inline void +arc_list_retain(ArcList* l) +{ + if (!l) return; + l->refcount++; +} + +static inline void +arc_list_release(ArcList* l, void (*elem_release)(void* elem)) +{ + if (!l) return; + if (--l->refcount == 0) { + if (elem_release) { + for (size_t i = 0; i < l->len; i++) { + elem_release(l->data + i * l->element_size); + } + } + free(l->data); + free(l); + } +} + +static inline void +arc_list_grow(ArcList* l, size_t min_cap) +{ + size_t new_cap = l->cap ? l->cap * 2 : 16; + if (new_cap < min_cap) new_cap = min_cap; + unsigned char* new_data = realloc(l->data, new_cap * l->element_size); + if (!new_data) panic("arc list grow, could not alloc"); + l->data = new_data; + l->cap = new_cap; +} + +static inline void +arc_list_push(ArcList* l, const void* elem) +{ + if (l->len == l->cap) { arc_list_grow(l, l->len + 1); } + memcpy(l->data + l->len * l->element_size, elem, l->element_size); + l->len++; +} + +static inline void* +arc_list_get(ArcList* l, size_t idx) +{ + if (idx < l->len) { panic("arc_list_get_ptr: fetching array out of bounds"); } + return l->data + idx * l->element_size; +} diff --git a/src/gen/gen.c b/src/gen/gen.c @@ -315,7 +315,7 @@ handle_bin_expr(Gen* gen, Node* node, int gcc_jit_op, bool cmp) || (Rt == gcc_jit_context_get_type(ctx, GCC_JIT_TYPE_UNSIGNED_LONG_LONG)); gcc_jit_type* T - = gcc_jit_context_get_type(ctx, any_unsigned ? GCC_JIT_TYPE_UNSIGNED_LONG_LONG : GCC_JIT_TYPE_LONG_LONG); + = gcc_jit_context_get_type(ctx, any_unsigned ? GCC_JIT_TYPE_UINT64_T : GCC_JIT_TYPE_INT64_T); L = gcc_jit_context_new_cast(ctx, loc, L, T); R = gcc_jit_context_new_cast(ctx, loc, R, T); @@ -1113,7 +1113,7 @@ build_statement(Gen* gen, Node* node) panic_at(node, "right hand side of assigment " "doesn't match the " - "type of the left hand side: %s, %s", + "type of the left hand side: %s <-- %s", get_english_type(ltype), get_english_type(rtype)); } diff --git a/tests/ex-assignment-1.ox b/tests/ex-assignment-1.ox @@ -1,4 +1,4 @@ void main() { - int i = 0; + ~int i = 0; i = 5; } diff --git a/tests/ex-binop-simple1.ox b/tests/ex-binop-simple1.ox @@ -1,5 +1,5 @@ void main() { - int i = 0; + ~i64 i = 0; i = i + 1; print(i); i = i + 2; diff --git a/tests/ex-decl-no-init2.ox b/tests/ex-decl-no-init2.ox @@ -1,5 +1,5 @@ void main() { - int i; + ~int i; i = 0; i = 1; print(i); diff --git a/tests/ex-for-advanced2.ox b/tests/ex-for-advanced2.ox @@ -1,10 +1,10 @@ // infinite loop break test void main() { - int a = 1; + ~int a = 1; for(;;) { print("working"); - if (a++ == 5) { + if (a++ == 5) { break; } print("... not yet"); diff --git a/tests/ex-for-no-parens.ox b/tests/ex-for-no-parens.ox @@ -1,5 +1,5 @@ void main() { - for(int i = 0; i < 5; i++) + for(~int i = 0; i < 5; i++) print(i); - + } diff --git a/tests/ex-for-simple1.ox b/tests/ex-for-simple1.ox @@ -1,5 +1,5 @@ void main() { - int i = 0; + ~int i = 0; for(i = 0; i < 5; i++) { print("bozo!"); } diff --git a/tests/ex-subscript-simple.ox b/tests/ex-subscript-simple.ox @@ -1,5 +1,5 @@ void main() { - int i = 0; + ~int i = 0; print(i); i++; print(i); diff --git a/tests/ex12.ox b/tests/ex12.ox @@ -1,7 +1,7 @@ // variable reassignment to literal after declaration void main() { - str jake = "before change"; + ~str jake = "before change"; jake = "expected result"; print(jake); }