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 *, size_t, UwUVMExpression *, UwUVMArgs *)) dlsym(program.api_library, "uwuvm_call_function"))(program.main_function, 0, NULL, NULL);
25 char *str = ((char *(*)(UwUVMValue)) dlsym(program.api_library, "uwuvm_print_value"))(result);
30 ((void (*)(UwUVMValue)) dlsym(program.api_library, "uwuvm_delet_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);