Ginger Bill 9 years ago
parent
commit
6e39a42c8a
8 changed files with 95 additions and 39 deletions
  1. 4 10
      build.bat
  2. 55 4
      code/demo.odin
  3. 1 1
      core/fmt.odin
  4. 2 2
      core/runtime.odin
  5. 3 1
      src/checker/checker.cpp
  6. 21 19
      src/checker/expr.cpp
  7. 6 0
      src/checker/stmt.cpp
  8. 3 2
      src/main.cpp

+ 4 - 10
build.bat

@@ -4,7 +4,7 @@
 set exe_name=odin.exe
 set exe_name=odin.exe
 
 
 :: Debug = 0, Release = 1
 :: 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-
 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 *.pdb > NUL 2> NUL
 	del *.ilk > 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
-	rem odin run code/demo.odin
+	odin run code/demo.odin
 
 
 
 
 	:do_not_compile_exe
 	:do_not_compile_exe

+ 55 - 4
code/demo.odin

@@ -1,10 +1,61 @@
 #import "fmt.odin"
 #import "fmt.odin"
 #import "utf8.odin"
 #import "utf8.odin"
 #import "hash.odin"
 #import "hash.odin"
+#import "mem.odin"
 
 
 main :: proc() {
 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^)
+		}
+	}
 }
 }

+ 1 - 1
core/fmt.odin

@@ -164,8 +164,8 @@ print_i64_to_buffer :: proc(buffer: ^[]byte, i: i64) {
 	neg := i < 0
 	neg := i < 0
 	if neg {
 	if neg {
 		i = -i
 		i = -i
+		print_rune_to_buffer(buffer, #rune "-")
 	}
 	}
-	print_rune_to_buffer(buffer, #rune "-")
 	print_u64_to_buffer(buffer, i as u64)
 	print_u64_to_buffer(buffer, i as u64)
 }
 }
 
 

+ 2 - 2
core/runtime.odin

@@ -16,8 +16,8 @@ Type_Info :: union {
 		fields:  []Member
 		fields:  []Member
 		packed:  bool
 		packed:  bool
 		ordered: bool
 		ordered: bool
-		size:    int
-		align:   int
+		size:    int // in bytes
+		align:   int // in bytes
 	}
 	}
 
 
 	Named: struct #ordered {
 	Named: struct #ordered {

+ 3 - 1
src/checker/checker.cpp

@@ -256,7 +256,9 @@ struct CycleChecker {
 };
 };
 
 
 CycleChecker *cycle_checker_add(CycleChecker *cc, Entity *e) {
 CycleChecker *cycle_checker_add(CycleChecker *cc, Entity *e) {
-	GB_ASSERT(cc != NULL);
+	if (cc == NULL) {
+		return NULL;
+	}
 	if (cc->path == NULL) {
 	if (cc->path == NULL) {
 		gb_array_init(cc->path, gb_heap_allocator());
 		gb_array_init(cc->path, gb_heap_allocator());
 	}
 	}

+ 21 - 19
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);
 	GB_ASSERT(n->kind == AstNode_Ident);
 	o->mode = Addressing_Invalid;
 	o->mode = Addressing_Invalid;
 	o->expr = n;
 	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);
 	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);
 	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;
 		o->mode = Addressing_Type;
 #if 0
 #if 0
 	// TODO(bill): Fix cyclical dependancy checker
 	// 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
 #endif
@@ -3170,7 +3172,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
 	case_end;
 	case_end;
 
 
 	case_ast_node(i, Ident, node);
 	case_ast_node(i, Ident, node);
-		check_identifier(c, o, node, type_hint);
+		check_identifier(c, o, node, type_hint, NULL);
 	case_end;
 	case_end;
 
 
 	case_ast_node(bl, BasicLit, node);
 	case_ast_node(bl, BasicLit, node);

+ 6 - 0
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");
 		      "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 (pd->body != NULL) {
 		if (is_foreign) {
 		if (is_foreign) {
 			error(ast_node_token(pd->body),
 			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;
 			d = *found;
 		} else {
 		} else {
 			e->type = t_invalid;
 			e->type = t_invalid;
+			set_base_type(named_type, t_invalid);
 			return;
 			return;
 			// GB_PANIC("`%.*s` should been declared!", LIT(e->token.string));
 			// GB_PANIC("`%.*s` should been declared!", LIT(e->token.string));
 		}
 		}

+ 3 - 2
src/main.cpp

@@ -180,8 +180,9 @@ int main(int argc, char **argv) {
 		"%.*sbin/opt %s -o %.*s.bc "
 		"%.*sbin/opt %s -o %.*s.bc "
 		"-mem2reg "
 		"-mem2reg "
 		"-memcpyopt "
 		"-memcpyopt "
-		"-die -dse "
-		"-dce "
+		"-die "
+		// "-dse "
+		// "-dce "
 		// "-S "
 		// "-S "
 		// "-debug-pass=Arguments "
 		// "-debug-pass=Arguments "
 		"",
 		"",