aboutsummaryrefslogtreecommitdiff
path: root/mod/mem.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-05-07 21:22:38 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-05-07 21:22:38 +0300
commit0e0c41af58a0f4ec5a39ce77822de71e5523fcba (patch)
tree4a02b2f93e61411cbfc6084b0855dba51b326cd9 /mod/mem.c
parent1fadcec6d7b26d34edf3b5b3a293deea0edb4139 (diff)
downloadfwd-gnc.tar.gz
fwd-gnc.zip
implement enough type analysis for vector examplegnc
+ Big commit, scary + Some details still a bit up in the air, mainly about move checking structure member access ('register' types are freely copied I guess, same as in rust? How about user types?)
Diffstat (limited to 'mod/mem.c')
-rw-r--r--mod/mem.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/mod/mem.c b/mod/mem.c
new file mode 100644
index 0000000..5303ffa
--- /dev/null
+++ b/mod/mem.c
@@ -0,0 +1,38 @@
+#include <fwd/mod.h>
+
+long fwdmalloc(fwd_extern_args_t args)
+{
+ assert(args.argc == 1);
+ size_t n = FWD_ARG_T(args, 0, size_t);
+ FWD_RET(FWD_PTR, malloc(n));
+ return 0;
+}
+
+long fwdrealloc(fwd_extern_args_t args)
+{
+ assert(args.argc == 2);
+ void *ptr = FWD_ARG(args, 0, void *, FWD_PTR);
+ size_t n = FWD_ARG_T(args, 1, size_t);
+ FWD_RET(FWD_PTR, realloc(ptr, n));
+ return 0;
+}
+
+long fwdfree(fwd_extern_args_t args)
+{
+ assert(args.argc == 1);
+ void *ptr = FWD_ARG(args, 0, void *, FWD_PTR);
+ return 0;
+}
+
+int fwdopen(fwd_state_t *state)
+{
+ FWD_REGISTER(state, fwdmalloc,
+ FWD_PTR, FWD_T(size_t));
+
+ FWD_REGISTER(state, fwdrealloc,
+ FWD_PTR, FWD_PTR, FWD_T(size_t));
+
+ FWD_REGISTER(state, fwdfree,
+ FWD_VOID, FWD_PTR);
+ return 0;
+}