Scrap Virtual Machine and begin again

I just didn't like the style of it.
This commit is contained in:
Ginger Bill
2016-11-03 16:26:22 +00:00
parent 8534e064b9
commit 6c2772d093
7 changed files with 1358 additions and 1194 deletions

View File

@@ -23,5 +23,10 @@ main :: proc() {
}
foo()
x := test("Hello")
x = test("Hello").count as i64
xp := ^x
p := xp^
z := [..]i64{1, 2, 3, 4}
z[0] = p
}

View File

@@ -482,6 +482,20 @@ b32 is_type_float(Type *t) {
}
return false;
}
b32 is_type_f32(Type *t) {
t = base_type(t);
if (t->kind == Type_Basic) {
return t->Basic.kind == Basic_f32;
}
return false;
}
b32 is_type_f64(Type *t) {
t = base_type(t);
if (t->kind == Type_Basic) {
return t->Basic.kind == Basic_f64;
}
return false;
}
b32 is_type_pointer(Type *t) {
t = base_type(t);
if (t->kind == Type_Basic) {
@@ -1188,6 +1202,17 @@ i64 type_size_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
return align_formula(size, align);
}
case Type_Tuple: {
i64 count = t->Tuple.variable_count;
if (count == 0) {
return 0;
}
type_set_offsets(s, allocator, t);
i64 size = t->Tuple.offsets[count-1] + type_size_of(s, allocator, t->Tuple.variables[count-1]->type);
i64 align = type_align_of(s, allocator, t);
return align_formula(size, align);
} break;
case Type_Record: {
switch (t->Record.kind) {
case TypeRecord_Struct: {
@@ -1196,7 +1221,6 @@ i64 type_size_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
return 0;
}
type_set_offsets(s, allocator, t);
// TODO(bill): Is this how it should work?
i64 size = t->Record.struct_offsets[count-1] + type_size_of(s, allocator, t->Record.fields[count-1]->type);
i64 align = type_align_of(s, allocator, t);
return align_formula(size, align);

View File

@@ -166,15 +166,13 @@ int main(int argc, char **argv) {
ssa_gen_tree(&ssa);
#if 1
{
VirtualMachine vm = {};
vm_init(&vm, &ssa.module);
defer (vm_destroy(&vm));
#if 0
VirtualMachine vm = {};
vm_init(&vm, &ssa.module);
// defer (vm_destroy(&vm));
Array<vmValue> args = {}; // Empty
vm_call_proc_by_name(&vm, make_string("main"), args);
}
Array<vmValue> main_args = {}; // Empty
vm_call_proc_by_name(&vm, make_string("main"), main_args);
#endif
{

1305
src/old_vm.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1146,9 +1146,11 @@ ssaDefer ssa_add_defer_instr(ssaProcedure *proc, isize scope_index, ssaValue *in
ssaValue *ssa_add_module_constant(ssaModule *m, Type *type, ExactValue value) {
gbAllocator a = m->allocator;
// gbAllocator a = gb_heap_allocator();
if (is_type_slice(type)) {
ast_node(cl, CompoundLit, value.value_compound);
gbAllocator a = m->allocator;
isize count = cl->elems.count;
if (count == 0) {
@@ -1174,11 +1176,14 @@ ssaValue *ssa_add_module_constant(ssaModule *m, Type *type, ExactValue value) {
return ssa_make_value_constant_slice(a, type, g, count);
}
return ssa_make_value_constant(m->allocator, type, value);
return ssa_make_value_constant(a, type, value);
}
ssaValue *ssa_add_global_string_array(ssaModule *m, String string) {
// TODO(bill): Should this use the arena allocator or the heap allocator?
// Strings could be huge!
gbAllocator a = m->allocator;
// gbAllocator a = gb_heap_allocator();
isize max_len = 6+8+1;
u8 *str = cast(u8 *)gb_alloc_array(a, u8, max_len);
@@ -5334,6 +5339,13 @@ void ssa_gen_tree(ssaGen *s) {
ssa_build_proc(m->procs[i], m->procs[i]->Proc.parent);
}
// {
// DWORD old_protect = 0;
// DWORD new_protect = PAGE_READONLY;
// BOOL ok = VirtualProtect(m->arena.physical_start, m->arena.total_size, new_protect, &old_protect);
// }
// m->layout = make_string("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64");
}

View File

@@ -175,7 +175,7 @@ void ssa_print_type(ssaFileBuffer *f, ssaModule *m, Type *t) {
case Type_Named:
if (is_type_struct(t) || is_type_union(t)) {
String *name = map_get(&m->type_names, hash_pointer(t));
GB_ASSERT(name != NULL);
GB_ASSERT_MSG(name != NULL, "%.*s", LIT(t->Named.name));
ssa_print_encoded_local(f, *name);
// ssa_print_encoded_local(f, t->Named.name);
} else {

1182
src/vm.cpp

File diff suppressed because it is too large Load Diff