mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Implement constant value generation from ExactValue
This commit is contained in:
@@ -2,29 +2,44 @@ package demo
|
|||||||
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
|
|
||||||
|
// Foo :: struct {
|
||||||
|
// x, y: int,
|
||||||
|
// };
|
||||||
|
// foo :: proc(x: int) -> (f: Foo) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
Foo :: struct {
|
Foo :: enum {A=1, B, C, D};
|
||||||
x, y: int,
|
Foo_Set :: bit_set[Foo];
|
||||||
};
|
x := Foo_Set{.A, .C};
|
||||||
|
|
||||||
x := i32(1);
|
y := [4]int{3 = 1, 0 .. 1 = 3, 2 = 9};
|
||||||
y := i32(2);
|
z := []int{1, 2, 3, 4};
|
||||||
z := x + y;
|
|
||||||
w := z - 2;
|
// @thread_local a: int;
|
||||||
|
|
||||||
|
// x := i32(1);
|
||||||
|
// y := i32(2);
|
||||||
|
// z := x + y;
|
||||||
|
// w := z - 2;
|
||||||
|
|
||||||
|
// foo(123);
|
||||||
|
|
||||||
|
|
||||||
c := 1 + 2i;
|
// c := 1 + 2i;
|
||||||
q := 1 + 2i + 3j + 4k;
|
// q := 1 + 2i + 3j + 4k;
|
||||||
|
|
||||||
s := "Hellope";
|
// s := "Hellope";
|
||||||
|
|
||||||
f: Foo;
|
// f := Foo{1, 2};
|
||||||
pc: proc "contextless" (x: i32) -> Foo;
|
// pc: proc "contextless" (x: i32) -> Foo;
|
||||||
po: proc "odin" (x: i32) -> Foo;
|
// po: proc "odin" (x: i32) -> Foo;
|
||||||
e: enum{A, B, C};
|
// e: enum{A, B, C};
|
||||||
u: union{i32, bool};
|
// u: union{i32, bool};
|
||||||
u1: union{i32};
|
// u1: union{i32};
|
||||||
um: union #maybe {^int};
|
// um: union #maybe {^int};
|
||||||
|
|
||||||
// os.write_string(os.stdout, "Hellope\n");
|
// os.write_string(os.stdout, "Hellope\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
-28
@@ -5911,34 +5911,6 @@ irValue *ir_type_info(irProcedure *proc, Type *type) {
|
|||||||
return ir_emit_array_ep(proc, ir_global_type_info_data, ir_const_i32(id));
|
return ir_emit_array_ep(proc, ir_global_type_info_data, ir_const_i32(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMPORTANT NOTE(bill): This must match the same as the in core.odin
|
|
||||||
enum Typeid_Kind : u8 {
|
|
||||||
Typeid_Invalid,
|
|
||||||
Typeid_Integer,
|
|
||||||
Typeid_Rune,
|
|
||||||
Typeid_Float,
|
|
||||||
Typeid_Complex,
|
|
||||||
Typeid_Quaternion,
|
|
||||||
Typeid_String,
|
|
||||||
Typeid_Boolean,
|
|
||||||
Typeid_Any,
|
|
||||||
Typeid_Type_Id,
|
|
||||||
Typeid_Pointer,
|
|
||||||
Typeid_Procedure,
|
|
||||||
Typeid_Array,
|
|
||||||
Typeid_Enumerated_Array,
|
|
||||||
Typeid_Dynamic_Array,
|
|
||||||
Typeid_Slice,
|
|
||||||
Typeid_Tuple,
|
|
||||||
Typeid_Struct,
|
|
||||||
Typeid_Union,
|
|
||||||
Typeid_Enum,
|
|
||||||
Typeid_Map,
|
|
||||||
Typeid_Bit_Field,
|
|
||||||
Typeid_Bit_Set,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
irValue *ir_typeid(irModule *m, Type *type) {
|
irValue *ir_typeid(irModule *m, Type *type) {
|
||||||
type = default_type(type);
|
type = default_type(type);
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1014,8 +1014,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
|
|||||||
} else if (is_type_enumerated_array(type)) {
|
} else if (is_type_enumerated_array(type)) {
|
||||||
ast_node(cl, CompoundLit, value.value_compound);
|
ast_node(cl, CompoundLit, value.value_compound);
|
||||||
|
|
||||||
Type *index_type = type->EnumeratedArray.elem;
|
Type *elem_type = type->EnumeratedArray.elem;
|
||||||
Type *elem_type = type->Array.elem;
|
|
||||||
isize elem_count = cl->elems.count;
|
isize elem_count = cl->elems.count;
|
||||||
if (elem_count == 0) {
|
if (elem_count == 0) {
|
||||||
ir_write_str_lit(f, "zeroinitializer");
|
ir_write_str_lit(f, "zeroinitializer");
|
||||||
|
|||||||
+916
-193
File diff suppressed because it is too large
Load Diff
@@ -305,6 +305,34 @@ struct Type {
|
|||||||
bool failure;
|
bool failure;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// IMPORTANT NOTE(bill): This must match the same as the in core.odin
|
||||||
|
enum Typeid_Kind : u8 {
|
||||||
|
Typeid_Invalid,
|
||||||
|
Typeid_Integer,
|
||||||
|
Typeid_Rune,
|
||||||
|
Typeid_Float,
|
||||||
|
Typeid_Complex,
|
||||||
|
Typeid_Quaternion,
|
||||||
|
Typeid_String,
|
||||||
|
Typeid_Boolean,
|
||||||
|
Typeid_Any,
|
||||||
|
Typeid_Type_Id,
|
||||||
|
Typeid_Pointer,
|
||||||
|
Typeid_Procedure,
|
||||||
|
Typeid_Array,
|
||||||
|
Typeid_Enumerated_Array,
|
||||||
|
Typeid_Dynamic_Array,
|
||||||
|
Typeid_Slice,
|
||||||
|
Typeid_Tuple,
|
||||||
|
Typeid_Struct,
|
||||||
|
Typeid_Union,
|
||||||
|
Typeid_Enum,
|
||||||
|
Typeid_Map,
|
||||||
|
Typeid_Bit_Field,
|
||||||
|
Typeid_Bit_Set,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO(bill): Should I add extra information here specifying the kind of selection?
|
// TODO(bill): Should I add extra information here specifying the kind of selection?
|
||||||
|
|||||||
Reference in New Issue
Block a user