mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Scrap Virtual Machine and begin again
I just didn't like the style of it.
This commit is contained in:
+6
-1
@@ -23,5 +23,10 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
foo()
|
foo()
|
||||||
x := test("Hello")
|
x = test("Hello").count as i64
|
||||||
|
xp := ^x
|
||||||
|
p := xp^
|
||||||
|
|
||||||
|
z := [..]i64{1, 2, 3, 4}
|
||||||
|
z[0] = p
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-1
@@ -482,6 +482,20 @@ b32 is_type_float(Type *t) {
|
|||||||
}
|
}
|
||||||
return false;
|
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) {
|
b32 is_type_pointer(Type *t) {
|
||||||
t = base_type(t);
|
t = base_type(t);
|
||||||
if (t->kind == Type_Basic) {
|
if (t->kind == Type_Basic) {
|
||||||
@@ -1188,6 +1202,17 @@ i64 type_size_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
|
|||||||
return align_formula(size, align);
|
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: {
|
case Type_Record: {
|
||||||
switch (t->Record.kind) {
|
switch (t->Record.kind) {
|
||||||
case TypeRecord_Struct: {
|
case TypeRecord_Struct: {
|
||||||
@@ -1196,7 +1221,6 @@ i64 type_size_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
type_set_offsets(s, allocator, t);
|
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 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);
|
i64 align = type_align_of(s, allocator, t);
|
||||||
return align_formula(size, align);
|
return align_formula(size, align);
|
||||||
|
|||||||
+6
-8
@@ -166,15 +166,13 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
ssa_gen_tree(&ssa);
|
ssa_gen_tree(&ssa);
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
{
|
VirtualMachine vm = {};
|
||||||
VirtualMachine vm = {};
|
vm_init(&vm, &ssa.module);
|
||||||
vm_init(&vm, &ssa.module);
|
// defer (vm_destroy(&vm));
|
||||||
defer (vm_destroy(&vm));
|
|
||||||
|
|
||||||
Array<vmValue> args = {}; // Empty
|
Array<vmValue> main_args = {}; // Empty
|
||||||
vm_call_proc_by_name(&vm, make_string("main"), args);
|
vm_call_proc_by_name(&vm, make_string("main"), main_args);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
+1305
File diff suppressed because it is too large
Load Diff
+14
-2
@@ -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) {
|
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)) {
|
if (is_type_slice(type)) {
|
||||||
ast_node(cl, CompoundLit, value.value_compound);
|
ast_node(cl, CompoundLit, value.value_compound);
|
||||||
gbAllocator a = m->allocator;
|
|
||||||
|
|
||||||
isize count = cl->elems.count;
|
isize count = cl->elems.count;
|
||||||
if (count == 0) {
|
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_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) {
|
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 = m->allocator;
|
||||||
|
// gbAllocator a = gb_heap_allocator();
|
||||||
|
|
||||||
isize max_len = 6+8+1;
|
isize max_len = 6+8+1;
|
||||||
u8 *str = cast(u8 *)gb_alloc_array(a, u8, max_len);
|
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);
|
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");
|
// 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");
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -175,7 +175,7 @@ void ssa_print_type(ssaFileBuffer *f, ssaModule *m, Type *t) {
|
|||||||
case Type_Named:
|
case Type_Named:
|
||||||
if (is_type_struct(t) || is_type_union(t)) {
|
if (is_type_struct(t) || is_type_union(t)) {
|
||||||
String *name = map_get(&m->type_names, hash_pointer(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, *name);
|
||||||
// ssa_print_encoded_local(f, t->Named.name);
|
// ssa_print_encoded_local(f, t->Named.name);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1181
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user