diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-02-21 21:21:54 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-02-21 21:21:54 +0000 |
| commit | 047c0e4bcc415a1f0e7b55afd57900319e43dbef (patch) | |
| tree | 7aa26b8a59cb8634cc309a299a8076aa708967ea /code | |
| parent | a94dfdf21d798bc72bbee0cc04b80149f0d4b8d2 (diff) | |
A decent union type with common fields and variants
Diffstat (limited to 'code')
| -rw-r--r-- | code/demo.odin | 100 |
1 files changed, 95 insertions, 5 deletions
diff --git a/code/demo.odin b/code/demo.odin index df740c1c2..c88e5477a 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -7,12 +7,102 @@ #import "os.odin"; // #import "halloc.odin"; +Token_Kind :: enum { +} +Token_Pos :: struct { + file: string, + line: int, + column: int, +} +Token :: struct { + kind: Token_Kind, + name: string, + using pos: Token_Pos, +} + +Exact_Value :: union { + Boolean {b: bool}, + String {s: string}, + Integer {i: i64}, + Float {f: f64}, + Pointer {p: i64}, + Compound{c: rawptr}, +} +Overload_Kind :: enum { + UNKNOWN, + NO, + YES, +} +Scope :: struct { + parent: ^Scope, + prev, next: ^Scope, + first_child, last_child: ^Scope, + elements: map[string]^Entity, + implicit: map[^Entity]bool, + + shared: [dynamic]^Scope, + imported: [dynamic]^Scope, + is_proc: bool, + is_global: bool, + is_file: bool, + is_init: bool, + has_been_imported: bool, // This is only applicable to file scopes + file: rawptr, +} + +Type :: struct { +} + +Entity :: union { +// Common Fields + flags: u32, + using token: Token, + scope: ^Scope, // Parent's scope + type: ^Type, + // identifier: ^ast.Node, + + using_parent: ^Entity, + // using_expr: ^ast.Node, + +// Variants + Constant{value: Exact_Value}, + Variable{ + field_index, field_src_index: int, + is_immutable, is_thread_local: bool, + }, + Type_Name{}, + Procedure{ + is_foreign: bool, + foreign_name: string, + foreign_library: ^Entity, + link_name: string, + tags: u64, + overload_kind: Overload_Kind, + }, + Builtin{id: int}, + Import_Name{ + import_path: string, + import_name: string, + import_scope: ^Scope, + used: bool, + }, + Library_Name{ + library_path: string, + library_name: string, + used: bool, + }, + Nil{}, +} + main :: proc() { - m: map[int]int; - m[123] = 312; - fmt.println(m[123]); - delete(m, 123); - fmt.println(m[123]); + e: Entity; + u := union_cast(^Type_Info.Union)type_info_base(type_info_of_val(e)); + + + fmt.println(type_info_base(type_info(Entity))); + + + // e.flags = 123; /* |