7 static void free_expression(UwUVMExpression *expr)
9 if (expr->type == EX_FNCALL) {
10 for (size_t i = 0; i < expr->value.cll_value.num_args; i++)
11 free_expression(&expr->value.cll_value.args[i]);
13 free(expr->value.cll_value.args);
16 if (expr->type == EX_STRLIT)
17 free(expr->value.str_value);
20 void vm_run_file(const char *progname, const char *modname)
22 UwUVMProgram program = create_program(progname, modname);
23 UwUVMValue result = ((UwUVMValue (*)(UwUVMFunction *, UwUVMArgs args)) dlsym(program.api_library, "uwuvm_run_function"))(program.main_function, (UwUVMArgs) {.num = 0, .evaluated = NULL, .unevaluated = NULL, .super = NULL});
25 char *str = ((char *(*)(UwUVMValue)) dlsym(program.api_library, "uwustr_get"))(result);
30 ((void (*)(UwUVMValue)) dlsym(program.api_library, "uwuvm_free_value"))(result);
32 for (size_t i = 0; i < program.num_functions; i++) {
33 UwUVMFunction *function = program.functions[i];
35 if (function->type == MODULE_PLAIN) {
36 free_expression(function->value.plain);
37 free(function->value.plain);
43 free(program.functions);
45 for (size_t i = 0; i < program.num_libraries; i++)
46 dlclose(program.libraries[i]);
48 if (program.libraries)
49 free(program.libraries);
51 dlclose(program.api_library);