From 55959845a266477396aaea89de2d55a1f20498b3 Mon Sep 17 00:00:00 2001 From: Shaw Summa Date: Thu, 25 Jul 2024 03:52:47 -0400 Subject: [PATCH] tmp Signed-off-by: Shaw Summa --- .gitmodules | 8 +------- main/minivm.c | 2 +- vendor/mimalloc | 1 - vendor/raylib | 1 - vm/ast/print.c | 2 +- vm/io.c | 18 +++++++++--------- vm/io.h | 15 ++++++++------- vm/ir.c | 2 +- vm/lua/repl.c | 2 +- vm/std.c | 12 ++++++------ vm/std.h | 2 +- vm/vm.c | 4 ++-- vm/vm.h | 4 ++-- 13 files changed, 33 insertions(+), 40 deletions(-) delete mode 160000 vendor/mimalloc delete mode 160000 vendor/raylib diff --git a/.gitmodules b/.gitmodules index 9a9b342f..085016aa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,10 +3,4 @@ url = https://github.com/fastvm/minivm-tree-sitter [submodule "vendor/isocline"] path = vendor/isocline - url = https://github.com/fastvm/minivm-isocline -[submodule "vendor/raylib"] - path = vendor/raylib - url = https://github.com/FastVM/minivm-raylib -[submodule "vendor/mimalloc"] - path = vendor/mimalloc - url = https://github.com/shawsumma/mimalloc + url = https://github.com/fastvm/minivm-isocline \ No newline at end of file diff --git a/main/minivm.c b/main/minivm.c index 43410671..6b3d59a3 100644 --- a/main/minivm.c +++ b/main/minivm.c @@ -78,7 +78,7 @@ __attribute__((no_instrument_function)) int main(int argc, char **argv) { } if (echo) { vm_io_buffer_t buf = {0}; - vm_io_debug(&buf, 0, "", value, NULL); + vm_io_buffer_obj_debug(&buf, 0, "", value, NULL); printf("%.*s", (int)buf.len, buf.buf); } diff --git a/vendor/mimalloc b/vendor/mimalloc deleted file mode 160000 index dccc8545..00000000 --- a/vendor/mimalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dccc8545a8b5c9da44cf764ee3237aed99c883da diff --git a/vendor/raylib b/vendor/raylib deleted file mode 160000 index b4fbdc02..00000000 --- a/vendor/raylib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b4fbdc028302f9a697f196e8d02a7dca28912f59 diff --git a/vm/ast/print.c b/vm/ast/print.c index 7d976776..9c2f3ffc 100644 --- a/vm/ast/print.c +++ b/vm/ast/print.c @@ -158,7 +158,7 @@ void vm_ast_print_node(vm_io_buffer_t *out, size_t indent, const char *prefix, v break; } case VM_AST_NODE_LITERAL: { - vm_io_debug(out, indent, prefix, node.value.literal, NULL); + vm_io_buffer_obj_debug(out, indent, prefix, node.value.literal, NULL); break; } } diff --git a/vm/io.c b/vm/io.c index f8e7e598..4f2fa482 100644 --- a/vm/io.c +++ b/vm/io.c @@ -92,7 +92,7 @@ static void vm_indent(vm_io_buffer_t *out, size_t indent, const char *prefix) { vm_io_buffer_format(out, "%s", prefix); } -void vm_io_print_lit(vm_io_buffer_t *out, vm_obj_t value) { +void vm_io_buffer_print_lit(vm_io_buffer_t *out, vm_obj_t value) { if (vm_obj_is_nil(value)) { vm_io_buffer_format(out, "nil"); } @@ -110,7 +110,7 @@ void vm_io_print_lit(vm_io_buffer_t *out, vm_obj_t value) { } } -void vm_io_debug(vm_io_buffer_t *out, size_t indent, const char *prefix, vm_obj_t value, vm_io_debug_t *link) { +void vm_io_buffer_obj_debug(vm_io_buffer_t *out, size_t indent, const char *prefix, vm_obj_t value, vm_io_debug_t *link) { size_t up = 1; while (link != NULL) { if (vm_obj_eq(value, link->value)) { @@ -168,25 +168,25 @@ void vm_io_debug(vm_io_buffer_t *out, size_t indent, const char *prefix, vm_obj_ // no print for empty keys } else if (vm_obj_is_boolean(value)) { if (vm_obj_get_boolean(value)) { - vm_io_debug(out, indent + 1, "true = ", p.value, &next); + vm_io_buffer_obj_debug(out, indent + 1, "true = ", p.value, &next); } else { - vm_io_debug(out, indent + 1, "false = ", p.value, &next); + vm_io_buffer_obj_debug(out, indent + 1, "false = ", p.value, &next); } } else if (vm_obj_is_number(value)) { char buf[64]; snprintf(buf, 63, VM_FORMAT_FLOAT " = ", vm_obj_get_number(p.key)); - vm_io_debug(out, indent + 1, buf, p.value, &next); + vm_io_buffer_obj_debug(out, indent + 1, buf, p.value, &next); } else if (vm_obj_is_string(value)) { vm_io_buffer_t buf = {0}; vm_io_buffer_format(&buf, "%s = ", vm_obj_get_string(p.key)->buf); - vm_io_debug(out, indent + 1, buf.buf, p.value, &next); + vm_io_buffer_obj_debug(out, indent + 1, buf.buf, p.value, &next); vm_free(buf.buf); } else { vm_indent(out, indent + 1, ""); vm_io_buffer_format(out, "pair {\n"); - vm_io_debug(out, indent + 2, "key = ", p.key, &next); - vm_io_debug(out, indent + 2, "val = ", p.value, &next); + vm_io_buffer_obj_debug(out, indent + 2, "key = ", p.key, &next); + vm_io_buffer_obj_debug(out, indent + 2, "val = ", p.value, &next); vm_indent(out, indent + 1, ""); vm_io_buffer_format(out, "}\n"); } @@ -201,7 +201,7 @@ void vm_io_debug(vm_io_buffer_t *out, size_t indent, const char *prefix, vm_obj_ } } -void vm_value_buffer_tostring(vm_io_buffer_t *buf, vm_obj_t value) { +void vm_io_buffer_object_tostring(vm_io_buffer_t *buf, vm_obj_t value) { if (vm_obj_is_nil(value)) { vm_io_buffer_format(buf, "nil"); } diff --git a/vm/io.h b/vm/io.h index 2d74ba00..40474146 100644 --- a/vm/io.h +++ b/vm/io.h @@ -13,15 +13,16 @@ struct vm_io_debug_t { }; vm_io_buffer_t *vm_io_buffer_new(void); +vm_io_buffer_t *vm_io_buffer_from_str(const char *str); char *vm_io_buffer_get(vm_io_buffer_t *buf); -void vm_io_print_lit(vm_io_buffer_t *out, vm_obj_t value); -void vm_io_debug(vm_io_buffer_t *out, size_t indent, const char *prefix, vm_obj_t value, vm_io_debug_t *link); + +char *vm_io_format(const char *fmt, ...); char *vm_io_read(const char *filename); -void vm_io_buffer_vformat(vm_io_buffer_t *buf, const char *fmt, va_list ap); -void vm_io_buffer_format(vm_io_buffer_t *buf, const char *fmt, ...); char *vm_io_vformat(const char *fmt, va_list ap); -char *vm_io_format(const char *fmt, ...); -void vm_value_buffer_tostring(vm_io_buffer_t *buf, vm_obj_t value); -vm_io_buffer_t *vm_io_buffer_from_str(const char *str); +void vm_io_buffer_format(vm_io_buffer_t *buf, const char *fmt, ...); +void vm_io_buffer_obj_debug(vm_io_buffer_t *out, size_t indent, const char *prefix, vm_obj_t value, vm_io_debug_t *link); +void vm_io_buffer_object_tostring(vm_io_buffer_t *buf, vm_obj_t value); +void vm_io_buffer_print_lit(vm_io_buffer_t *out, vm_obj_t value); +void vm_io_buffer_vformat(vm_io_buffer_t *buf, const char *fmt, va_list ap); #endif diff --git a/vm/ir.c b/vm/ir.c index 9c9294e1..dc2418ec 100644 --- a/vm/ir.c +++ b/vm/ir.c @@ -14,7 +14,7 @@ void vm_block_realloc(vm_block_t *block, vm_instr_t instr) { void vm_io_format_arg(vm_io_buffer_t *out, vm_arg_t val) { switch (val.type) { case VM_ARG_LIT: { - vm_io_print_lit(out, val.lit); + vm_io_buffer_print_lit(out, val.lit); break; } case VM_ARG_REG: { diff --git a/vm/lua/repl.c b/vm/lua/repl.c index 7e4742c3..2516eeb2 100644 --- a/vm/lua/repl.c +++ b/vm/lua/repl.c @@ -155,7 +155,7 @@ void vm_repl(vm_t *vm) { vm_error_report(vm_obj_get_error(value), stderr); } else if (!vm_obj_is_nil(value)) { vm_io_buffer_t buf = {0}; - vm_io_debug(&buf, 0, "", value, NULL); + vm_io_buffer_obj_debug(&buf, 0, "", value, NULL); printf("%.*s", (int)buf.len, buf.buf); } } diff --git a/vm/std.c b/vm/std.c index 1a10bae7..d49546cf 100644 --- a/vm/std.c +++ b/vm/std.c @@ -54,7 +54,7 @@ void vm_std_assert(vm_t *vm, vm_obj_t *args) { if (vm_obj_is_nil(val) || (vm_obj_is_boolean(val) && !vm_obj_get_boolean(val))) { vm_obj_t msg = args[1]; vm_io_buffer_t buf = {0}; - vm_io_debug(&buf, 0, "assert failed with mesage: ", msg, NULL); + vm_io_buffer_obj_debug(&buf, 0, "assert failed with mesage: ", msg, NULL); *args = vm_str(vm, buf.buf); vm_free(buf.buf); return; @@ -71,7 +71,7 @@ void vm_std_error(vm_t *vm, vm_obj_t *args) { } vm_obj_t msg = args[0]; vm_io_buffer_t buf = {0}; - vm_io_debug(&buf, 0, "", msg, NULL); + vm_io_buffer_obj_debug(&buf, 0, "", msg, NULL); *args = vm_str(vm, buf.buf); vm_free(buf.buf); return; @@ -107,7 +107,7 @@ void vm_std_vm_print(vm_t *vm, vm_obj_t *args) { (void)vm; for (size_t i = 0; !vm_obj_is_empty(args[i]); i++) { vm_io_buffer_t buf = {0}; - vm_io_debug(&buf, 0, "", args[i], NULL); + vm_io_buffer_obj_debug(&buf, 0, "", args[i], NULL); printf("%.*s", (int)buf.len, buf.buf); } *args = vm_obj_of_nil(); @@ -162,7 +162,7 @@ void vm_std_type(vm_t *vm, vm_obj_t *args) { void vm_std_tostring(vm_t *vm, vm_obj_t *args) { (void)vm; vm_io_buffer_t out = {0}; - vm_value_buffer_tostring(&out, *args); + vm_io_buffer_object_tostring(&out, *args); *args = vm_str(vm, out.buf); vm_free(out.buf); } @@ -190,7 +190,7 @@ void vm_std_print(vm_t *vm, vm_obj_t *args) { if (!first) { vm_io_buffer_format(&out, "\t"); } - vm_value_buffer_tostring(&out, *args++); + vm_io_buffer_object_tostring(&out, *args++); first = false; } fprintf(stdout, "%.*s\n", (int)out.len, out.buf); @@ -204,7 +204,7 @@ void vm_std_io_write(vm_t *vm, vm_obj_t *args) { vm_obj_t *ret = args; vm_io_buffer_t out = {0}; while (!vm_obj_is_empty(args[0])) { - vm_value_buffer_tostring(&out, *args++); + vm_io_buffer_object_tostring(&out, *args++); } fprintf(stdout, "%.*s", (int)out.len, out.buf); *ret = vm_obj_of_nil(); diff --git a/vm/std.h b/vm/std.h index 95f08d21..5e494eb5 100644 --- a/vm/std.h +++ b/vm/std.h @@ -5,7 +5,7 @@ #define VM_STD_REF(vm, x) (vm_config_add_extern((vm), &(x)), &(x)) -void vm_value_buffer_tostring(vm_io_buffer_t *buf, vm_obj_t value); +void vm_io_buffer_object_tostring(vm_io_buffer_t *buf, vm_obj_t value); void vm_std_set_arg(vm_t *vm, const char *prog, const char *file, int argc, char **argv); void vm_std_new(vm_t *vm); diff --git a/vm/vm.c b/vm/vm.c index 721bb202..ce6c78a9 100644 --- a/vm/vm.c +++ b/vm/vm.c @@ -35,8 +35,8 @@ void vm_state_delete(vm_t *vm) { vm_free(vm); } -vm_obj_t vm_str(vm_t *vm, const char *str) { - vm_obj_t ret = vm_obj_of_string(vm_io_buffer_from_str(str)); +vm_obj_t vm_obj_of_gc_str(vm_t *vm, const char *str) { + vm_obj_t ret = vm_obj_of_buffer(vm_io_buffer_from_str(str)); vm_gc_add(vm, ret); return ret; } diff --git a/vm/vm.h b/vm/vm.h index df62faaa..ee88f444 100644 --- a/vm/vm.h +++ b/vm/vm.h @@ -59,7 +59,7 @@ typedef void vm_ffi_t(vm_t *closure, vm_obj_t *args); #define vm_obj_of_nil() nanbox_undefined() #define vm_obj_of_boolean(b) ((b) ? nanbox_true() : nanbox_false()) #define vm_obj_of_number(n) nanbox_from_double(n) -#define vm_obj_of_string(s) nanbox_from_aux1(s) +#define vm_obj_of_buffer(s) nanbox_from_aux1(s) #define vm_obj_of_table(o) nanbox_from_aux2(o) #define vm_obj_of_closure(o) nanbox_from_aux3(o) #define vm_obj_of_ffi(o) nanbox_from_aux4(o) @@ -182,7 +182,7 @@ vm_t *vm_state_new(void); void vm_state_delete(vm_t *vm); void vm_repl(vm_t *vm); -vm_obj_t vm_str(vm_t *vm, const char *str); +vm_obj_t vm_obj_of_string(vm_t *vm, const char *str); #if VM_OBJ_FAST #else