From 6e39a42c8a090d6e32231872cc292c90de6b304e Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Wed, 28 Sep 2016 21:25:14 +0100 Subject: [PATCH] Demo 004 --- build.bat | 14 +++------- code/demo.odin | 59 ++++++++++++++++++++++++++++++++++++++--- core/fmt.odin | 2 +- core/runtime.odin | 4 +-- src/checker/checker.cpp | 4 ++- src/checker/expr.cpp | 40 +++++++++++++++------------- src/checker/stmt.cpp | 6 +++++ src/main.cpp | 5 ++-- 8 files changed, 95 insertions(+), 39 deletions(-) diff --git a/build.bat b/build.bat index f6653e051..0114637b6 100644 --- a/build.bat +++ b/build.bat @@ -4,7 +4,7 @@ set exe_name=odin.exe :: Debug = 0, Release = 1 -set release_mode=0 +set release_mode=1 set compiler_flags= -nologo -Oi -TP -W4 -fp:fast -fp:except- -Gm- -MP -FC -GS- -EHsc- -GR- @@ -44,16 +44,10 @@ rem pushd %build_dir% del *.pdb > NUL 2> NUL del *.ilk > NUL 2> NUL - cl %compiler_settings% "src\main.cpp" ^ - /link %linker_settings% -OUT:%exe_name% ^ - && odin run code/demo.odin - rem clang++ src\main.cpp -o %exe_name% ^ - rem -Wno-deprecated-declarations ^ - rem -Wno-unused-value ^ - rem -Wno-switch ^ - rem -Wno-writable-strings + rem cl %compiler_settings% "src\main.cpp" ^ + rem /link %linker_settings% -OUT:%exe_name% ^ rem && odin run code/demo.odin - rem odin run code/demo.odin + odin run code/demo.odin :do_not_compile_exe diff --git a/code/demo.odin b/code/demo.odin index ba6532286..14f9f5b54 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,10 +1,61 @@ #import "fmt.odin" #import "utf8.odin" #import "hash.odin" +#import "mem.odin" main :: proc() { - s := "Hello" - fmt.println(s, - utf8.valid_string(s), - hash.murmur64(s.data, s.count)) + { // New Standard Library stuff + s := "Hello" + fmt.println(s, + utf8.valid_string(s), + hash.murmur64(s.data, s.count)) + + // utf8.odin + // hash.odin + // - crc, fnv, fnva, murmur + // mem.odin + // - Custom allocators + // - Helpers + } + + { + arena: mem.Arena + mem.init_arena_from_context(^arena, mem.megabytes(16)) // Uses default allocator + defer mem.free_arena(^arena) + + push_allocator mem.arena_allocator(^arena) { + x := new(int) + x^ = 1337 + + fmt.println(x^) + } + + /* + push_allocator x { + ... + } + + is equivalent to this: + + { + prev_allocator := current_context().allocator + current_context().allocator = x + defer current_context().allocator = prev_allocator + + ... + } + */ + + // You can also "push" a context + + c := current_context() + c.allocator = mem.arena_allocator(^arena) + + push_context c { + x := new(int) + x^ = 365 + + fmt.println(x^) + } + } } diff --git a/core/fmt.odin b/core/fmt.odin index 62f5569cd..ce19bacae 100644 --- a/core/fmt.odin +++ b/core/fmt.odin @@ -164,8 +164,8 @@ print_i64_to_buffer :: proc(buffer: ^[]byte, i: i64) { neg := i < 0 if neg { i = -i + print_rune_to_buffer(buffer, #rune "-") } - print_rune_to_buffer(buffer, #rune "-") print_u64_to_buffer(buffer, i as u64) } diff --git a/core/runtime.odin b/core/runtime.odin index 6df76d381..4789fa8f9 100644 --- a/core/runtime.odin +++ b/core/runtime.odin @@ -16,8 +16,8 @@ Type_Info :: union { fields: []Member packed: bool ordered: bool - size: int - align: int + size: int // in bytes + align: int // in bytes } Named: struct #ordered { diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp index c5b9d3c44..7d32f4cce 100644 --- a/src/checker/checker.cpp +++ b/src/checker/checker.cpp @@ -256,7 +256,9 @@ struct CycleChecker { }; CycleChecker *cycle_checker_add(CycleChecker *cc, Entity *e) { - GB_ASSERT(cc != NULL); + if (cc == NULL) { + return NULL; + } if (cc->path == NULL) { gb_array_init(cc->path, gb_heap_allocator()); } diff --git a/src/checker/expr.cpp b/src/checker/expr.cpp index 658584ba4..964e268fa 100644 --- a/src/checker/expr.cpp +++ b/src/checker/expr.cpp @@ -796,7 +796,7 @@ void check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node) { } -void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, CycleChecker *cycle_checker = NULL) { +void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, CycleChecker *cycle_checker) { GB_ASSERT(n->kind == AstNode_Ident); o->mode = Addressing_Invalid; o->expr = n; @@ -816,13 +816,13 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl } add_entity_use(c, n, e); - CycleChecker local_cycle_checker = {}; - if (cycle_checker == NULL) { - cycle_checker = &local_cycle_checker; - } - defer (if (local_cycle_checker.path != NULL) { - gb_array_free(local_cycle_checker.path); - }); + // CycleChecker local_cycle_checker = {}; + // if (cycle_checker == NULL) { + // cycle_checker = &local_cycle_checker; + // } + // defer (if (local_cycle_checker.path != NULL) { + // gb_array_free(local_cycle_checker.path); + // }); check_entity_decl(c, e, NULL, named_type, cycle_checker); @@ -857,17 +857,19 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl o->mode = Addressing_Type; #if 0 // TODO(bill): Fix cyclical dependancy checker - gb_for_array(i, cycle_checker->path) { - Entity *prev = cycle_checker->path[i]; - if (prev == e) { - error(e->token, "Illegal declaration cycle for %.*s", LIT(e->token.string)); - for (isize j = i; j < gb_array_count(cycle_checker->path); j++) { - Entity *ref = cycle_checker->path[j]; - error(ref->token, "\t%.*s refers to", LIT(ref->token.string)); + if (cycle_checker != NULL) { + gb_for_array(i, cycle_checker->path) { + Entity *prev = cycle_checker->path[i]; + if (prev == e) { + error(e->token, "Illegal declaration cycle for %.*s", LIT(e->token.string)); + for (isize j = i; j < gb_array_count(cycle_checker->path); j++) { + Entity *ref = cycle_checker->path[j]; + error(ref->token, "\t%.*s refers to", LIT(ref->token.string)); + } + error(e->token, "\t%.*s", LIT(e->token.string)); + type = t_invalid; + break; } - error(e->token, "\t%.*s", LIT(e->token.string)); - type = t_invalid; - break; } } #endif @@ -3170,7 +3172,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint case_end; case_ast_node(i, Ident, node); - check_identifier(c, o, node, type_hint); + check_identifier(c, o, node, type_hint, NULL); case_end; case_ast_node(bl, BasicLit, node); diff --git a/src/checker/stmt.cpp b/src/checker/stmt.cpp index 89af771db..c1ca1858b 100644 --- a/src/checker/stmt.cpp +++ b/src/checker/stmt.cpp @@ -590,6 +590,11 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) { "You cannot apply both `inline` and `no_inline` to a procedure"); } + if (is_foreign && is_link_name) { + error(ast_node_token(pd->type), + "You cannot apply both `foreign` and `link_name` to a procedure"); + } + if (pd->body != NULL) { if (is_foreign) { error(ast_node_token(pd->body), @@ -695,6 +700,7 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type, Cyc d = *found; } else { e->type = t_invalid; + set_base_type(named_type, t_invalid); return; // GB_PANIC("`%.*s` should been declared!", LIT(e->token.string)); } diff --git a/src/main.cpp b/src/main.cpp index 7e4b708dd..cb4605e15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,8 +180,9 @@ int main(int argc, char **argv) { "%.*sbin/opt %s -o %.*s.bc " "-mem2reg " "-memcpyopt " - "-die -dse " - "-dce " + "-die " + // "-dse " + // "-dce " // "-S " // "-debug-pass=Arguments " "",