From: Axy Date: Mon, 4 May 2026 02:13:24 +0000 (+0200) Subject: Simple expr checking of right shape X-Git-Url: https://git.uwuaxy.net/sitemap.xml?a=commitdiff_plain;h=ebc9c5944c696cd73192d6c41e2c4762f6d570b1;p=axy%2Fft%2Fc-cera.git Simple expr checking of right shape --- diff --git a/src/ccera.h b/src/ccera.h index 3445dd2..9465c6e 100644 --- a/src/ccera.h +++ b/src/ccera.h @@ -6,7 +6,7 @@ /* By: agilliar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/04/29 16:08:57 by agilliar #+# #+# */ -/* Updated: 2026/05/04 02:35:51 by agilliar ### ########.fr */ +/* Updated: 2026/05/04 03:58:26 by agilliar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,66 +49,59 @@ enum e_value_ptr: t_usize VALUE_PTR_BYTES, }; -struct s_value_builtin +typedef struct s_value_builtin { enum e_value_ptr discrim; t_builtin builtin; -}; +} t_value_builtin; -struct s_value_list +typedef struct s_value_list { t_usize len; enum e_value_ptr discrim; t_value list[0]; -}; +} t_value_list; -struct s_value_bytes +typedef struct s_value_bytes { t_usize len; enum e_value_ptr discrim; char bytes[0]; -}; +} t_value_bytes; -t_value value_builtin_new(t_builtin builtin); -t_value value_list_new(t_usize len); -t_value value_bytes_new(t_usize len); -t_value value_undefined_new(void); -t_value value_int_new(t_isize n); +t_value value_builtin_new(t_builtin builtin); +t_value value_list_new(t_usize len); +t_value value_bytes_new(t_usize len); +t_value value_undefined_new(void); +t_value value_int_new(t_isize n); -struct s_value_builtin *value_builtin_get(t_value value); -struct s_value_list *value_list_get(t_value value); -struct s_value_bytes *value_bytes_get(t_value value); -t_isize value_int_get(t_value value); +t_value_builtin *value_builtin_get(t_value value); +t_value_list *value_list_get(t_value value); +t_value_bytes *value_bytes_get(t_value value); +t_isize value_int_get(t_value value); -void value_destroy(t_value value); +void value_destroy(t_value value); -t_value value_copy(t_value value); -struct s_value_list *value_list_unique(t_value *value); -struct s_value_bytes *value_bytes_unique(t_value *value); +t_value value_copy(t_value value); +t_value_list *value_list_unique(t_value *value); +t_value_bytes *value_bytes_unique(t_value *value); -t_value value_list_new(t_usize len); -t_value value_list_new(t_usize len); +t_value value_list_new(t_usize len); +t_value value_list_new(t_usize len); typedef void *t_arc; typedef void *(*t_unpack)(t_value); typedef void (*t_drop)(void *); -t_arc arc_create(t_usize size); -t_arc arc_copy(t_arc arc); -void arc_destroy(t_arc arc, void (*destructor)(void *)); -bool arc_is_unique(t_arc arc); +t_arc arc_create(t_usize size); +t_arc arc_copy(t_arc arc); +void arc_destroy(t_arc arc, void (*destructor)(void *)); +bool arc_is_unique(t_arc arc); -void noop(void *ptr); +void noop(void *ptr); struct s_exec_context; -typedef struct s_eval_ctx -{ - struct s_eval_ctx *parent; - struct s_value_list *state; - t_usize pos; -} t_eval_ctx; - // The expression value is a tuple of an evaluatable and the argument to give it // // Value-evaluatables are laid out as follows: @@ -127,6 +120,6 @@ typedef struct s_eval_ctx // move is whether said value shall be moved out // // This function takes ownership -t_value expr_eval(t_value expr); +t_value expr_eval(t_value expr); #endif diff --git a/src/eval.c b/src/eval.c index 98e5dd9..597e6ce 100644 --- a/src/eval.c +++ b/src/eval.c @@ -6,27 +6,32 @@ /* By: agilliar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/05/04 01:21:34 by agilliar #+# #+# */ -/* Updated: 2026/05/04 02:51:20 by agilliar ### ########.fr */ +/* Updated: 2026/05/04 04:12:32 by agilliar ### ########.fr */ /* */ /* ************************************************************************** */ #include "ccera.h" #include -static t_value ctx_eval(t_eval_ctx *ctx) +static bool to_state(t_value *value) { - (void) ctx; - return (value_undefined_new()); + t_value_list *expr; + t_value_list *state; + + expr = value_list_unique(value); + if (!expr || expr->len != 2) + return (false); + state = value_list_unique(&expr->list[0]); + if (!state || state->len != 2) + return (false); + if (!value_list_unique(&state->list[0])) + return (false); + return (true); } t_value expr_eval(t_value expr) { - t_eval_ctx *ctx; - - (void) expr; - ctx = malloc(sizeof(t_eval_ctx)); - if (!ctx) - return (value_undefined_new()); - ctx->parent = NULL; - return (ctx_eval(ctx)); + to_state(&expr); + value_destroy(expr); + return (value_undefined_new()); } diff --git a/src/value_lifetime.c b/src/value_lifetime.c index 77b8725..c5ad951 100644 --- a/src/value_lifetime.c +++ b/src/value_lifetime.c @@ -6,7 +6,7 @@ /* By: agilliar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/05/04 02:05:48 by agilliar #+# #+# */ -/* Updated: 2026/05/04 03:21:18 by agilliar ### ########.fr */ +/* Updated: 2026/05/04 03:27:11 by agilliar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,12 +39,12 @@ t_value value_copy(t_value value) return (value_int_new(value_int_get(value))); } -struct s_value_list *value_list_unique(t_value *value) +t_value_list *value_list_unique(t_value *value) { - struct s_value_list *list; - t_value new; - struct s_value_list *new_list; - t_usize i; + t_value_list *list; + t_value new; + t_value_list *new_list; + t_usize i; list = value_list_get(*value); if (!list) @@ -66,11 +66,11 @@ struct s_value_list *value_list_unique(t_value *value) return (new_list); } -struct s_value_bytes *value_bytes_unique(t_value *value) +t_value_bytes *value_bytes_unique(t_value *value) { - struct s_value_bytes *bytes; - t_value new; - struct s_value_bytes *new_bytes; + t_value_bytes *bytes; + t_value new; + t_value_bytes *new_bytes; bytes = value_bytes_get(*value); if (!bytes) diff --git a/test.c b/test.c index a45042f..e15714d 100644 --- a/test.c +++ b/test.c @@ -6,7 +6,7 @@ /* By: agilliar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/04/30 17:19:58 by agilliar #+# #+# */ -/* Updated: 2026/05/04 03:20:35 by agilliar ### ########.fr */ +/* Updated: 2026/05/04 04:13:07 by agilliar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,19 +17,16 @@ int main(void) { char *s = "Hello cera!"; - t_value value = value_bytes_new(strlen(s) + 1); - strcpy(&value_bytes_get(value)->bytes[0], s); - printf("%s\n", &value_bytes_get(value)->bytes[0]); - printf("%p\n", value_bytes_get(value)); - printf("%p\n", value_list_get(value)); - char c = value_bytes_get(value)->bytes[1]; - (void) c; - t_value value_2 = value_copy(value); - value_bytes_unique(&value_2)->bytes[1] = 'f'; - printf("%s\n", &value_bytes_get(value_2)->bytes[0]); - printf("%s\n", &value_bytes_get(value)->bytes[0]); - value_destroy(value); - value_destroy(value_2); - value = value_int_new(128); - printf("%li\n", value_int_get(value)); + t_value arg = value_bytes_new(strlen(s) + 1); + t_value state = value_list_new(0); + t_value idx = value_int_new(0); + t_value fn = value_list_new(2); + t_value expr = value_list_new(2); + value_list_get(fn)->list[0] = state; + value_list_get(fn)->list[1] = idx; + value_list_get(expr)->list[0] = fn; + value_list_get(expr)->list[1] = arg; + t_value val = value_copy(expr); + printf("%p\n", expr_eval(expr).ptr); + value_destroy(val); }