Browse Source

Fix anonymous procedures

gingerBill 7 years ago
parent
commit
9bef5ec01a
4 changed files with 30 additions and 9 deletions
  1. 1 1
      build.bat
  2. 25 7
      core/bits/bits.odin
  3. 1 1
      src/ir.cpp
  4. 3 0
      src/parser.cpp

+ 1 - 1
build.bat

@@ -18,7 +18,7 @@ set compiler_warnings= ^
 	-W4 -WX ^
 	-W4 -WX ^
 	-wd4100 -wd4101 -wd4127 -wd4189 ^
 	-wd4100 -wd4101 -wd4127 -wd4189 ^
 	-wd4201 -wd4204 ^
 	-wd4201 -wd4204 ^
-	-wd4456 -wd4457 ^
+	-wd4456 -wd4457 -wd4480 ^
 	-wd4512
 	-wd4512
 
 
 set compiler_includes=
 set compiler_includes=

+ 25 - 7
core/bits/bits.odin

@@ -43,21 +43,39 @@ foreign {
 	@(link_name="llvm.bitreverse.i32")  reverse_bits32 :: proc(i: u32) -> u32 ---
 	@(link_name="llvm.bitreverse.i32")  reverse_bits32 :: proc(i: u32) -> u32 ---
 	@(link_name="llvm.bitreverse.i64")  reverse_bits64 :: proc(i: u64) -> u64 ---
 	@(link_name="llvm.bitreverse.i64")  reverse_bits64 :: proc(i: u64) -> u64 ---
 
 
-	@(link_name="llvm.bswap.i16")       byte_swap16 :: proc(u16) -> u16 ---
-	@(link_name="llvm.bswap.i32")       byte_swap32 :: proc(u32) -> u32 ---
-	@(link_name="llvm.bswap.i64")       byte_swap64 :: proc(u64) -> u64 ---
+	@(link_name="llvm.bswap.i16")       byte_swap_u16 :: proc(u16) -> u16 ---
+	@(link_name="llvm.bswap.i32")       byte_swap_u32 :: proc(u32) -> u32 ---
+	@(link_name="llvm.bswap.i64")       byte_swap_u64 :: proc(u64) -> u64 ---
+	@(link_name="llvm.bswap.i16")       byte_swap_i16 :: proc(i16) -> i16 ---
+	@(link_name="llvm.bswap.i32")       byte_swap_i32 :: proc(i32) -> i32 ---
+	@(link_name="llvm.bswap.i64")       byte_swap_i64 :: proc(i64) -> i64 ---
 }
 }
 
 
 byte_swap_uint :: proc(i: uint) -> uint {
 byte_swap_uint :: proc(i: uint) -> uint {
 	when size_of(uint) == size_of(u32) {
 	when size_of(uint) == size_of(u32) {
-		return uint(byte_swap32(u32(i)));
+		return uint(byte_swap_u32(u32(i)));
 	} else {
 	} else {
-		return uint(byte_swap64(u64(i)));
+		return uint(byte_swap_u64(u64(i)));
+	}
+}
+byte_swap_int :: proc(i: int) -> int {
+	when size_of(int) == size_of(i32) {
+		return int(byte_swap_i32(i32(i)));
+	} else {
+		return int(byte_swap_i64(i64(i)));
 	}
 	}
 }
 }
 
 
-byte_swap :: proc[byte_swap16, byte_swap32, byte_swap64, byte_swap_uint];
-
+byte_swap :: proc[
+	byte_swap_u16,
+	byte_swap_u32,
+	byte_swap_u64,
+	byte_swap_i16,
+	byte_swap_i32,
+	byte_swap_i64,
+	byte_swap_uint,
+	byte_swap_int,
+];
 
 
 count_zeros8   :: proc(i:   u8) ->   u8 { return   8 - count_ones8(i); }
 count_zeros8   :: proc(i:   u8) ->   u8 { return   8 - count_ones8(i); }
 count_zeros16  :: proc(i:  u16) ->  u16 { return  16 - count_ones16(i); }
 count_zeros16  :: proc(i:  u16) ->  u16 { return  16 - count_ones16(i); }

+ 1 - 1
src/ir.cpp

@@ -1578,7 +1578,7 @@ void ir_emit_zero_init(irProcedure *p, irValue *address, Ast *expr) {
 	args[0] = ir_emit_conv(p, address, t_rawptr);
 	args[0] = ir_emit_conv(p, address, t_rawptr);
 	args[1] = ir_const_int(a, type_size_of(t));
 	args[1] = ir_const_int(a, type_size_of(t));
 	AstPackage *pkg = get_core_package(p->module->info, str_lit("mem"));
 	AstPackage *pkg = get_core_package(p->module->info, str_lit("mem"));
-	if (p->entity->token.string != "zero" && p->entity->pkg != pkg) {
+	if (p->entity != nullptr && p->entity->token.string != "zero" && p->entity->pkg != pkg) {
 		ir_emit_package_call(p, "mem", "zero", args, expr);
 		ir_emit_package_call(p, "mem", "zero", args, expr);
 	}
 	}
 	ir_emit(p, ir_instr_zero_init(p, address));
 	ir_emit(p, ir_instr_zero_init(p, address));

+ 3 - 0
src/parser.cpp

@@ -4292,6 +4292,9 @@ bool parse_file(Parser *p, AstFile *f) {
 	CommentGroup *docs = f->lead_comment;
 	CommentGroup *docs = f->lead_comment;
 
 
 	f->package_token = expect_token(f, Token_package);
 	f->package_token = expect_token(f, Token_package);
+	if (f->error_count > 0) {
+		return false;
+	}
 	Token package_name = expect_token_after(f, Token_Ident, "package");
 	Token package_name = expect_token_after(f, Token_Ident, "package");
 	if (package_name.kind == Token_Ident) {
 	if (package_name.kind == Token_Ident) {
 		if (package_name.string == "_") {
 		if (package_name.string == "_") {