From 968a7292f0b88f9485f4511e48acbee36cf71036 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Tue, 14 Apr 2026 12:47:56 -0400 Subject: microscript: add c functions --- uscript/val.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'uscript/val.h') diff --git a/uscript/val.h b/uscript/val.h index 4789973..5140fc2 100644 --- a/uscript/val.h +++ b/uscript/val.h @@ -2,6 +2,7 @@ #define __USCRIPT_VAL_H__ #include "common.h" +#include "uscript.h" #define create_num(n) ((struct us_val){.type=VAL_NUM, .dat={.number=(n)}}) #define create_bool(b) ((struct us_val){.type=VAL_BOOL, .dat={.boolean=(b)}}) @@ -10,6 +11,7 @@ #define wrap_arr(o) ((struct us_val){.type=VAL_ARR, .dat={.arr=(o)}}) #define wrap_proto(o) ((struct us_val){.type=VAL_PROTO, .dat={.proto=(o)}}) #define wrap_func(o) ((struct us_val){.type=VAL_FUNC, .dat={.func=(o)}}) +#define wrap_cfunc(o) ((struct us_val){.type=VAL_CFUNC, .dat={.cfunc=(o)}}) #define wrap_upval(o) ((struct us_val){.type=VAL_UPVAL, .dat={.upval=(o)}}) #define get_num(v) (v.dat.number) @@ -19,6 +21,7 @@ #define get_arr(v) (v.dat.arr) #define get_proto(v) (v.dat.proto) #define get_func(v) (v.dat.func) +#define get_cfunc(v) (v.dat.cfunc) #define get_upval(v) (v.dat.upval) #define val_is_obj(v) (v.type >= VAL_STR) @@ -35,6 +38,7 @@ enum val_type { VAL_ARR, VAL_PROTO, VAL_FUNC, + VAL_CFUNC, VAL_UPVAL, }; @@ -48,6 +52,7 @@ struct us_val { struct us_arr *arr; struct us_proto *proto; struct us_func *func; + struct us_cfunc *cfunc; struct us_upval *upval; } dat; }; @@ -81,6 +86,13 @@ struct us_proto { u8 nconstants; }; +struct us_cfunc { + struct us_obj header; + us_cfunc_sig c; + const struct us_str *name; + int argc; +}; + struct us_func { struct us_obj header; struct us_proto *proto; @@ -99,6 +111,7 @@ struct us_str *copy_str(const char *chars, int len); struct us_arr *create_arr(void); struct us_proto *create_proto(struct us_str *name); struct us_func *create_func(struct us_proto *proto); +struct us_cfunc *create_cfunc(struct us_str *name, us_cfunc_sig func, int argc); struct us_upval *create_upval(struct us_val *val); void free_val(struct us_val v); -- cgit v1.3-2-g0d8e