main: remove all non-platform-specific code
This commit is contained in:
parent
b78d4408f1
commit
af87766f50
55
c/frame.c
55
c/frame.c
@ -9,6 +9,7 @@
|
||||
#include "frame.h"
|
||||
#include "class_resolver.h"
|
||||
#include "printf.h"
|
||||
#include "string.h"
|
||||
|
||||
struct Code_attribute * get_code_attribute(int code_name_index,
|
||||
int attributes_count,
|
||||
@ -388,3 +389,57 @@ void vm_execute(struct vm * vm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vm_start(int class_hash_table_length,
|
||||
struct hash_table_entry * class_hash_table,
|
||||
const uint8_t * main_class,
|
||||
int main_class_length)
|
||||
{
|
||||
struct class_entry * class_entry = class_resolver_lookup_class(class_hash_table_length,
|
||||
class_hash_table,
|
||||
main_class,
|
||||
main_class_length);
|
||||
assert(class_entry != nullptr);
|
||||
|
||||
const char * method_name = "main";
|
||||
int method_name_length = string_length(method_name);
|
||||
const char * method_descriptor = "()V";
|
||||
int method_descriptor_length = string_length(method_descriptor);
|
||||
|
||||
int methods_hash_table_length = class_entry->methods.length;
|
||||
struct hash_table_entry * methods_hash_table = class_entry->methods.entry;
|
||||
|
||||
struct method_info * method_info = class_resolver_lookup_method(methods_hash_table_length,
|
||||
methods_hash_table,
|
||||
(const uint8_t *)method_name,
|
||||
method_name_length,
|
||||
(const uint8_t *)method_descriptor,
|
||||
method_descriptor_length);
|
||||
assert(method_info != nullptr);
|
||||
|
||||
struct vm vm;
|
||||
vm.class_hash_table.entry = class_hash_table;
|
||||
vm.class_hash_table.length = class_hash_table_length;
|
||||
|
||||
vm.frame_stack.ix = 0;
|
||||
vm.frame_stack.capacity = 1024;
|
||||
struct frame frames[vm.frame_stack.capacity];
|
||||
vm.frame_stack.frame = frames;
|
||||
|
||||
vm.data_stack.ix = 0;
|
||||
vm.data_stack.capacity = 0x100000;
|
||||
uint32_t data[vm.data_stack.capacity];
|
||||
vm.data_stack.data = data;
|
||||
|
||||
struct frame * entry_frame = stack_push_frame(&vm.frame_stack, 1);
|
||||
struct Code_attribute code;
|
||||
code.max_locals = 0;
|
||||
code.max_stack = 0;
|
||||
entry_frame->code = &code;
|
||||
entry_frame->local_variable = 0;
|
||||
entry_frame->operand_stack = 0;
|
||||
entry_frame->operand_stack_ix = 0;
|
||||
|
||||
vm_static_method_call(&vm, class_entry, method_info);
|
||||
vm_execute(&vm);
|
||||
}
|
||||
|
@ -153,3 +153,7 @@ void vm_special_method_call(struct vm * vm, struct class_entry * class_entry, st
|
||||
void vm_static_method_call(struct vm * vm, struct class_entry * class_entry, struct method_info * method_info);
|
||||
void vm_method_return(struct vm * vm);
|
||||
void vm_execute(struct vm * vm);
|
||||
void vm_start(int class_hash_table_length,
|
||||
struct hash_table_entry * class_hash_table,
|
||||
const uint8_t * main_class,
|
||||
int main_class_length);
|
||||
|
52
c/main.c
52
c/main.c
@ -47,7 +47,8 @@ int main(int argc, const char * argv[])
|
||||
{
|
||||
assert(argc >= 3);
|
||||
|
||||
const char * main_class = argv[1];
|
||||
const uint8_t * main_class = (const uint8_t *)argv[1];
|
||||
int main_class_length = string_length((const char *)main_class);
|
||||
|
||||
const char ** class_filenames = &argv[2];
|
||||
int num_class_filenames = argc - 2;
|
||||
@ -55,51 +56,8 @@ int main(int argc, const char * argv[])
|
||||
int class_hash_table_length;
|
||||
struct hash_table_entry * class_hash_table = load_from_filenames(class_filenames, num_class_filenames, &class_hash_table_length);
|
||||
|
||||
struct class_entry * class_entry = class_resolver_lookup_class(class_hash_table_length,
|
||||
vm_start(class_hash_table_length,
|
||||
class_hash_table,
|
||||
(const uint8_t *)main_class,
|
||||
string_length(main_class));
|
||||
assert(class_entry != nullptr);
|
||||
|
||||
const char * method_name = "main";
|
||||
int method_name_length = string_length(method_name);
|
||||
const char * method_descriptor = "()V";
|
||||
int method_descriptor_length = string_length(method_descriptor);
|
||||
|
||||
int methods_hash_table_length = class_entry->methods.length;
|
||||
struct hash_table_entry * methods_hash_table = class_entry->methods.entry;
|
||||
|
||||
struct method_info * method_info = class_resolver_lookup_method(methods_hash_table_length,
|
||||
methods_hash_table,
|
||||
(const uint8_t *)method_name,
|
||||
method_name_length,
|
||||
(const uint8_t *)method_descriptor,
|
||||
method_descriptor_length);
|
||||
assert(method_info != nullptr);
|
||||
|
||||
struct vm vm;
|
||||
vm.class_hash_table.entry = class_hash_table;
|
||||
vm.class_hash_table.length = class_hash_table_length;
|
||||
|
||||
vm.frame_stack.ix = 0;
|
||||
vm.frame_stack.capacity = 1024;
|
||||
struct frame frames[vm.frame_stack.capacity];
|
||||
vm.frame_stack.frame = frames;
|
||||
|
||||
vm.data_stack.ix = 0;
|
||||
vm.data_stack.capacity = 0x100000;
|
||||
uint32_t data[vm.data_stack.capacity];
|
||||
vm.data_stack.data = data;
|
||||
|
||||
struct frame * entry_frame = stack_push_frame(&vm.frame_stack, 1);
|
||||
struct Code_attribute code;
|
||||
code.max_locals = 0;
|
||||
code.max_stack = 0;
|
||||
entry_frame->code = &code;
|
||||
entry_frame->local_variable = 0;
|
||||
entry_frame->operand_stack = 0;
|
||||
entry_frame->operand_stack_ix = 0;
|
||||
|
||||
vm_static_method_call(&vm, class_entry, method_info);
|
||||
vm_execute(&vm);
|
||||
main_class,
|
||||
main_class_length);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user