tvm_t* tvm_create(char* filename) { tvm_t* vm = (tvm_t*)malloc(sizeof(tvm_t)); if(!vm) return NULL; vm->pMemory = create_memory(MIN_MEMORY_SIZE); if(!vm->pMemory) { free(vm); return NULL; } vm->pProgram = create_program(); if(!vm->pProgram) { destroy_memory(vm->pMemory); free(vm); return NULL; } create_stack(vm->pMemory, MIN_STACK_SIZE); if(interpret_program(vm->pProgram, filename, vm->pMemory) != 0) { // avoid memory leak when the interpret_program failed! tvm_destroy(vm); return NULL; } //if(!vm || !vm->pMemory || !vm->pProgram) return NULL; return vm; }
int main(int argc, char** argv) { tvm_t* vm = tvm_create(argv[1]); if(vm) { tdb_shell(vm); tvm_destroy(vm); } return 0; }