SLVAL sl_do_string(sl_vm_t* vm, uint8_t* src, size_t src_len, char* filename, int start_in_slash) { size_t token_count; sl_token_t* tokens; sl_node_base_t* ast; sl_vm_exec_ctx_t* ctx = sl_alloc(vm->arena, sizeof(sl_vm_exec_ctx_t)); sl_vm_section_t* section; tokens = sl_lex(vm, (uint8_t*)filename, src, src_len, &token_count, start_in_slash); ast = sl_parse(vm, tokens, token_count, (uint8_t*)filename); section = sl_compile(vm, ast, (uint8_t*)filename); ctx->vm = vm; ctx->section = section; ctx->registers = sl_alloc(vm->arena, sizeof(SLVAL) * section->max_registers); ctx->self = vm->lib.Object; ctx->parent = NULL; return sl_vm_exec(ctx, 0); }
int main(int argc, char** argv) { sl_static_init(); sl_vm_t* vm = sl_init("disasm"); if(argc < 1) { fprintf(stderr, "Usage: slash-dis <source file>\n"); exit(1); } FILE* f = fopen(argv[1], "r"); if(!f) { fprintf(stderr, "Could not open %s for reading.\n", argv[1]); exit(1); } fseek(f, 0, SEEK_END); size_t size = ftell(f); fseek(f, 0, SEEK_SET); char* source = sl_alloc_buffer(vm->arena, size + 1); fread(source, size, 1, f); fclose(f); SLVAL err; sl_vm_frame_t frame; SL_TRY(frame, SL_UNWIND_ALL, { size_t token_count; sl_token_t* tokens = sl_lex(vm, (uint8_t*)argv[1], (uint8_t*)source, size, &token_count, 0); sl_node_base_t* ast = sl_parse(vm, tokens, token_count, (uint8_t*)argv[1]); sl_vm_section_t* section = sl_compile(vm, ast, (uint8_t*)argv[1]); disassemble(vm, section); while(section_j < section_i) { disassemble(vm, section_queue[++section_j]); } }, err, {