/* By: agilliar <agilliar@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
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:
// 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
/* By: agilliar <agilliar@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
-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());
}
/* By: agilliar <agilliar@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
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)
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)
/* By: agilliar <agilliar@student.42mulhouse.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
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);
}