Browse Source

Use const & for Array<AstNode *> parameters

gingerBill 7 years ago
parent
commit
12b870ba66

+ 0 - 2
core/sync/sync.odin

@@ -1,2 +0,0 @@
-when ODIN_OS == "windows" do export "core:sync_windows.odin";
-when ODIN_OS == "linux"   do export "core:sync_linux.odin";

+ 4 - 2
core/sync/sync_linux.odin

@@ -1,5 +1,7 @@
-import "core:atomics.odin"
-import "core:os.odin"
+package sync
+
+import "core:atomics"
+import "core:os"
 
 
 Semaphore :: struct {
 Semaphore :: struct {
 	// _handle: win32.Handle,
 	// _handle: win32.Handle,

+ 4 - 4
core/sync/sync_windows.odin

@@ -1,7 +1,7 @@
-when ODIN_OS == "windows" {
-	import win32 "core:sys/windows.odin";
-}
-import "core:atomics.odin"
+package sync
+
+import "core:sys/win32"
+import "core:atomics"
 
 
 Semaphore :: struct {
 Semaphore :: struct {
 	_handle: win32.Handle,
 	_handle: win32.Handle,

+ 2 - 4
core/sys/win32/wgl.odin

@@ -1,9 +1,7 @@
+// +build windows
 package win32
 package win32
 
 
-// when ODIN_OS == "windows" {
-	foreign import "system:opengl32.lib"
-// }
-
+foreign import "system:opengl32.lib"
 
 
 CONTEXT_MAJOR_VERSION_ARB             :: 0x2091;
 CONTEXT_MAJOR_VERSION_ARB             :: 0x2091;
 CONTEXT_MINOR_VERSION_ARB             :: 0x2092;
 CONTEXT_MINOR_VERSION_ARB             :: 0x2092;

+ 6 - 7
core/sys/win32/windows.odin

@@ -1,12 +1,11 @@
+// +build windows
 package win32
 package win32
 
 
-// when ODIN_OS == "windows" {
-	foreign import "system:kernel32.lib"
-	foreign import "system:user32.lib"
-	foreign import "system:gdi32.lib"
-	foreign import "system:winmm.lib"
-	foreign import "system:shell32.lib"
-// }
+foreign import "system:kernel32.lib"
+foreign import "system:user32.lib"
+foreign import "system:gdi32.lib"
+foreign import "system:winmm.lib"
+foreign import "system:shell32.lib"
 
 
 Handle    :: distinct rawptr;
 Handle    :: distinct rawptr;
 Hwnd      :: distinct Handle;
 Hwnd      :: distinct Handle;

+ 1 - 8
examples/demo/demo.odin

@@ -18,6 +18,7 @@ import "core:c"
 
 
 when os.OS == "windows" {
 when os.OS == "windows" {
 	import "core:atomics"
 	import "core:atomics"
+	import "core:sync"
 	import "core:thread"
 	import "core:thread"
 	import "core:sys/win32"
 	import "core:sys/win32"
 }
 }
@@ -737,14 +738,6 @@ deprecated_attribute :: proc() {
 	// foo_v1(1);
 	// foo_v1(1);
 }
 }
 
 
-A :: struct {x, y, z: int};
-B :: struct {x, y, z: int};
-C :: struct {
-	using a: A,
-	b: B,
-}
-
-
 main :: proc() {
 main :: proc() {
 	when true {
 	when true {
 		general_stuff();
 		general_stuff();

+ 2 - 2
src/check_decl.cpp

@@ -89,7 +89,7 @@ Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, Stri
 	return e->type;
 	return e->type;
 }
 }
 
 
-void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array<AstNode *> inits, String context_name) {
+void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array<AstNode *> const &inits, String context_name) {
 	if ((lhs == nullptr || lhs_count == 0) && inits.count == 0) {
 	if ((lhs == nullptr || lhs_count == 0) && inits.count == 0) {
 		return;
 		return;
 	}
 	}
@@ -661,7 +661,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
 	}
 	}
 }
 }
 
 
-void check_var_decl(CheckerContext *ctx, Entity *e, Entity **entities, isize entity_count, AstNode *type_expr, Array<AstNode *> init_expr_list) {
+void check_var_decl(CheckerContext *ctx, Entity *e, Entity **entities, isize entity_count, AstNode *type_expr, Array<AstNode *> const &init_expr_list) {
 	GB_ASSERT(e->type == nullptr);
 	GB_ASSERT(e->type == nullptr);
 	GB_ASSERT(e->kind == Entity_Variable);
 	GB_ASSERT(e->kind == Entity_Variable);
 
 

+ 4 - 4
src/check_expr.cpp

@@ -72,7 +72,7 @@ void     update_expr_type               (CheckerContext *c, AstNode *e, Type *ty
 bool     check_is_terminating           (AstNode *node);
 bool     check_is_terminating           (AstNode *node);
 bool     check_has_break                (AstNode *stmt, bool implicit);
 bool     check_has_break                (AstNode *stmt, bool implicit);
 void     check_stmt                     (CheckerContext *c, AstNode *node, u32 flags);
 void     check_stmt                     (CheckerContext *c, AstNode *node, u32 flags);
-void     check_stmt_list                (CheckerContext *c, Array<AstNode *> stmts, u32 flags);
+void     check_stmt_list                (CheckerContext *c, Array<AstNode *> const &stmts, u32 flags);
 void     check_init_constant            (CheckerContext *c, Entity *e, Operand *operand);
 void     check_init_constant            (CheckerContext *c, Entity *e, Operand *operand);
 bool     check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value);
 bool     check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value);
 bool     check_procedure_type           (CheckerContext *c, Type *type, AstNode *proc_type_node, Array<Operand> *operands = nullptr);
 bool     check_procedure_type           (CheckerContext *c, Type *type, AstNode *proc_type_node, Array<Operand> *operands = nullptr);
@@ -107,7 +107,7 @@ void error_operand_no_value(Operand *o) {
 }
 }
 
 
 
 
-void check_scope_decls(CheckerContext *c, Array<AstNode *> nodes, isize reserve_size) {
+void check_scope_decls(CheckerContext *c, Array<AstNode *> const &nodes, isize reserve_size) {
 	Scope *s = c->scope;
 	Scope *s = c->scope;
 	GB_ASSERT(s->package == nullptr);
 	GB_ASSERT(s->package == nullptr);
 
 
@@ -4100,7 +4100,7 @@ isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs
 }
 }
 
 
 
 
-void check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array<Operand> *operands, Array<AstNode *> rhs, bool allow_ok, bool *optional_ok_ = nullptr) {
+void check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array<Operand> *operands, Array<AstNode *> const &rhs, bool allow_ok, bool *optional_ok_ = nullptr) {
 	bool optional_ok = false;
 	bool optional_ok = false;
 	isize tuple_index = 0;
 	isize tuple_index = 0;
 	for_array(i, rhs) {
 	for_array(i, rhs) {
@@ -6279,7 +6279,7 @@ void check_expr_or_type(CheckerContext *c, Operand *o, AstNode *e, Type *type_hi
 
 
 gbString write_expr_to_string(gbString str, AstNode *node);
 gbString write_expr_to_string(gbString str, AstNode *node);
 
 
-gbString write_struct_fields_to_string(gbString str, Array<AstNode *> params) {
+gbString write_struct_fields_to_string(gbString str, Array<AstNode *> const &params) {
 	for_array(i, params) {
 	for_array(i, params) {
 		if (i > 0) {
 		if (i > 0) {
 			str = gb_string_appendc(str, ", ");
 			str = gb_string_appendc(str, ", ");

+ 3 - 3
src/check_stmt.cpp

@@ -1,4 +1,4 @@
-void check_stmt_list(CheckerContext *ctx, Array<AstNode *> stmts, u32 flags) {
+void check_stmt_list(CheckerContext *ctx, Array<AstNode *> const &stmts, u32 flags) {
 	if (stmts.count == 0) {
 	if (stmts.count == 0) {
 		return;
 		return;
 	}
 	}
@@ -43,7 +43,7 @@ void check_stmt_list(CheckerContext *ctx, Array<AstNode *> stmts, u32 flags) {
 	}
 	}
 }
 }
 
 
-bool check_is_terminating_list(Array<AstNode *> stmts) {
+bool check_is_terminating_list(Array<AstNode *> const &stmts) {
 	// Iterate backwards
 	// Iterate backwards
 	for (isize n = stmts.count-1; n >= 0; n--) {
 	for (isize n = stmts.count-1; n >= 0; n--) {
 		AstNode *stmt = stmts[n];
 		AstNode *stmt = stmts[n];
@@ -55,7 +55,7 @@ bool check_is_terminating_list(Array<AstNode *> stmts) {
 	return false;
 	return false;
 }
 }
 
 
-bool check_has_break_list(Array<AstNode *> stmts, bool implicit) {
+bool check_has_break_list(Array<AstNode *> const &stmts, bool implicit) {
 	for_array(i, stmts) {
 	for_array(i, stmts) {
 		AstNode *stmt = stmts[i];
 		AstNode *stmt = stmts[i];
 		if (check_has_break(stmt, implicit)) {
 		if (check_has_break(stmt, implicit)) {

+ 1 - 1
src/check_type.cpp

@@ -31,7 +31,7 @@ void populate_using_entity_scope(CheckerContext *ctx, AstNode *node, Type *t) {
 
 
 }
 }
 
 
-void check_struct_fields(CheckerContext *ctx, AstNode *node, Array<Entity *> *fields, Array<AstNode *> params,
+void check_struct_fields(CheckerContext *ctx, AstNode *node, Array<Entity *> *fields, Array<AstNode *> const &params,
                          isize init_field_capacity, Type *named_type, String context) {
                          isize init_field_capacity, Type *named_type, String context) {
 	*fields = array_make<Entity *>(heap_allocator(), 0, init_field_capacity);
 	*fields = array_make<Entity *>(heap_allocator(), 0, init_field_capacity);
 
 

+ 7 - 8
src/checker.cpp

@@ -2233,13 +2233,13 @@ void check_all_global_entities(Checker *c) {
 		GB_ASSERT(ctx.pkg != nullptr);
 		GB_ASSERT(ctx.pkg != nullptr);
 		GB_ASSERT(e->pkg != nullptr);
 		GB_ASSERT(e->pkg != nullptr);
 
 
-		if (e->token.string == "main") {
-			if (e->kind != Entity_Procedure) {
-				if (pkg->kind == Package_Init) {
-					error(e->token, "'main' is reserved as the entry point procedure in the initial scope");
-					continue;
-				}
-			} else if (pkg->kind == Package_Runtime) {
+		if (pkg->kind == Package_Init) {
+			if (e->kind != Entity_Procedure && e->token.string == "main") {
+				error(e->token, "'main' is reserved as the entry point procedure in the initial scope");
+				continue;
+			}
+		} else if (pkg->kind == Package_Runtime) {
+			if (e->token.string == "main") {
 				error(e->token, "'main' is reserved as the entry point procedure in the initial scope");
 				error(e->token, "'main' is reserved as the entry point procedure in the initial scope");
 				continue;
 				continue;
 			}
 			}
@@ -2249,7 +2249,6 @@ void check_all_global_entities(Checker *c) {
 		ctx.scope = d->scope;
 		ctx.scope = d->scope;
 		check_entity_decl(&ctx, e, d, nullptr);
 		check_entity_decl(&ctx, e, d, nullptr);
 
 
-
 		if (pkg->kind != Package_Runtime) {
 		if (pkg->kind != Package_Runtime) {
 			processing_preload = false;
 			processing_preload = false;
 		}
 		}

+ 2 - 2
src/ir.cpp

@@ -2161,7 +2161,7 @@ irValue *ir_map_entries(irProcedure *proc, irValue *value) {
 	GB_ASSERT_MSG(t->kind == Type_Map, "%s", type_to_string(t));
 	GB_ASSERT_MSG(t->kind == Type_Map, "%s", type_to_string(t));
 	init_map_internal_types(t);
 	init_map_internal_types(t);
 	Type *gst = t->Map.generated_struct_type;
 	Type *gst = t->Map.generated_struct_type;
-	isize index = 1;
+	i32 index = 1;
 	irValue *entries = ir_emit(proc, ir_instr_struct_extract_value(proc, value, index, gst->Struct.fields[index]->type));
 	irValue *entries = ir_emit(proc, ir_instr_struct_extract_value(proc, value, index, gst->Struct.fields[index]->type));
 	return entries;
 	return entries;
 }
 }
@@ -2172,7 +2172,7 @@ irValue *ir_map_entries_ptr(irProcedure *proc, irValue *value) {
 	GB_ASSERT_MSG(t->kind == Type_Map, "%s", type_to_string(t));
 	GB_ASSERT_MSG(t->kind == Type_Map, "%s", type_to_string(t));
 	init_map_internal_types(t);
 	init_map_internal_types(t);
 	Type *gst = t->Map.generated_struct_type;
 	Type *gst = t->Map.generated_struct_type;
-	isize index = 1;
+	i32 index = 1;
 	Type *ptr_t = alloc_type_pointer(gst->Struct.fields[index]->type);
 	Type *ptr_t = alloc_type_pointer(gst->Struct.fields[index]->type);
 	irValue *entries = ir_emit(proc, ir_instr_struct_element_ptr(proc, value, index, ptr_t));
 	irValue *entries = ir_emit(proc, ir_instr_struct_element_ptr(proc, value, index, ptr_t));
 	return entries;
 	return entries;

+ 5 - 1
src/ir_print.cpp

@@ -1652,6 +1652,10 @@ void ir_print_type_name(irFileBuffer *f, irModule *m, irValue *v) {
 	ir_write_byte(f, '\n');
 	ir_write_byte(f, '\n');
 }
 }
 
 
+void foo_bar(void) {
+
+}
+
 void print_llvm_ir(irGen *ir) {
 void print_llvm_ir(irGen *ir) {
 	irModule *m = &ir->module;
 	irModule *m = &ir->module;
 
 
@@ -1805,7 +1809,7 @@ void print_llvm_ir(irGen *ir) {
 	if (m->generate_debug_info) {
 	if (m->generate_debug_info) {
 		ir_write_byte(f, '\n');
 		ir_write_byte(f, '\n');
 
 
-		i32 diec = m->debug_info.entries.count;
+		i32 diec = cast(i32)m->debug_info.entries.count;
 
 
 		i32 di_version    = diec+1;
 		i32 di_version    = diec+1;
 		i32 di_debug_info = diec+2;
 		i32 di_debug_info = diec+2;