Ginger Bill 8 years ago
parent
commit
cbcf4b6071
9 changed files with 68 additions and 72 deletions
  1. 15 11
      core/c.odin
  2. 2 2
      core/os_linux.odin
  3. 1 1
      core/os_windows.odin
  4. 3 3
      core/os_x.odin
  5. 36 42
      core/strconv.odin
  6. 1 1
      core/sys/wgl.odin
  7. 3 1
      core/thread.odin
  8. 1 0
      examples/demo.odin
  9. 6 11
      src/checker.cpp

+ 15 - 11
core/c.odin

@@ -13,17 +13,21 @@ c_ushort         :: i16;
 c_int            :: i32;
 c_uint           :: u32;
 
-c_long  :: ODIN_OS == "windows" ?
-	i32 :
-	(size_of(int) == 4) ?
-		i32 :
-		i64;
-
-c_ulong :: ODIN_OS == "windows" ?
-	u32 :
-	(size_of(int) == 4) ?
-		u32 :
-		u64;
+when ODIN_OS == "windows" {
+	c_long :: i32;
+} else when size_of(int) == 4 {
+	c_long :: i32;
+} else {
+	c_long :: i64;
+}
+
+when ODIN_OS == "windows" {
+	c_long :: u32;
+} else when size_of(uint) == 4 {
+	c_long :: u32;
+} else {
+	c_long :: u64;
+}
 
 c_longlong       :: i64;
 c_ulonglong      :: u64;

+ 2 - 2
core/os_linux.odin

@@ -3,9 +3,9 @@ foreign_system_library libc "c";
 
 import "core:strings.odin";
 
-Handle   :: i32;
+Handle    :: i32;
 File_Time :: u64;
-Errno    :: i32;
+Errno     :: i32;
 
 
 O_RDONLY   :: 0x00000;

+ 1 - 1
core/os_windows.odin

@@ -1,7 +1,7 @@
 import win32 "core:sys/windows.odin";
 import "core:mem.odin";
 
-Handle   :: int;
+Handle    :: int;
 File_Time :: u64;
 
 

+ 3 - 3
core/os_x.odin

@@ -3,9 +3,9 @@ foreign_system_library libc "c";
 
 import "core:strings.odin";
 
-Handle      :: i32;
-File_Time    :: u64;
-Errno       :: int;
+Handle    :: i32;
+File_Time :: u64;
+Errno     :: int;
 
 
 O_RDONLY   :: 0x00000;

+ 36 - 42
core/strconv.odin

@@ -7,23 +7,23 @@ Int_Flag :: enum {
 }
 
 
-parse_bool :: proc(s: string) -> (result: bool, ok: bool) {
+parse_bool :: proc(s: string) -> (result: bool = false, ok: bool) {
 	match s {
 	case "1", "t", "T", "true", "TRUE", "True":
 		return true, true;
 	case "0", "f", "F", "false", "FALSE", "False":
 		return false, true;
 	}
-	return false, false;
+	return ok = false;
 }
 
 _digit_value :: proc(r: rune) -> int {
 	ri := int(r);
 	v: int = 16;
 	match r {
-	case '0'..'9': v = ri-'0';
-	case 'a'..'z': v = ri-'a'+10;
-	case 'A'..'Z': v = ri-'A'+10;
+	case '0'...'9': v = ri-'0';
+	case 'a'...'z': v = ri-'a'+10;
+	case 'A'...'Z': v = ri-'A'+10;
 	}
 	return v;
 }
@@ -131,7 +131,7 @@ parse_f64 :: proc(s: string) -> f64 {
 		value += f64(v);
 	}
 
-	if s[i] == '.' {
+	if i < len(s) && s[i] == '.' {
 		pow10: f64 = 10;
 		i += 1;
 
@@ -149,28 +149,30 @@ parse_f64 :: proc(s: string) -> f64 {
 	frac := false;
 	scale: f64 = 1;
 
-	if s[i] == 'e' || s[i] == 'E' {
+	if i < len(s) && (s[i] == 'e' || s[i] == 'E') {
 		i += 1;
 
-		match s[i] {
-		case '-': i += 1; frac = true;
-		case '+': i += 1;
-		}
+		if i < len(s) {
+			match s[i] {
+			case '-': i += 1; frac = true;
+			case '+': i += 1;
+			}
 
-		exp: u32 = 0;
-		for ; i < len(s); i += 1 {
-			r := rune(s[i]);
-			if r == '_' do continue;
+			exp: u32 = 0;
+			for ; i < len(s); i += 1 {
+				r := rune(s[i]);
+				if r == '_' do continue;
 
-			d := u32(_digit_value(r));
-			if d >= 10 do break;
-			exp = exp * 10 + d;
-		}
-		if exp > 308 { exp = 308; }
+				d := u32(_digit_value(r));
+				if d >= 10 do break;
+				exp = exp * 10 + d;
+			}
+			if exp > 308 { exp = 308; }
 
-		for exp >= 50 { scale *= 1e50; exp -= 50; }
-		for exp >=  8 { scale *=  1e8; exp -=  8; }
-		for exp >   0 { scale *=   10; exp -=  1; }
+			for exp >= 50 { scale *= 1e50; exp -= 50; }
+			for exp >=  8 { scale *=  1e8; exp -=  8; }
+			for exp >   0 { scale *=   10; exp -=  1; }
+		}
 	}
 
 	if frac do return sign * (value/scale);
@@ -179,11 +181,8 @@ parse_f64 :: proc(s: string) -> f64 {
 
 
 append_bool :: proc(buf: []u8, b: bool) -> string {
-	if b {
-		append(&buf, "true");
-	} else {
-		append(&buf, "false");
-	}
+	if b do append(&buf, "true");
+	else do append(&buf, "false");
 	return string(buf);
 }
 
@@ -193,7 +192,7 @@ append_uint :: proc(buf: []u8, u: u64, base: int) -> string {
 append_int :: proc(buf: []u8, i: i64, base: int) -> string {
 	return append_bits(buf, u128(i), base, true, 8*size_of(int), digits, 0);
 }
-itoa :: proc(buf: []u8, i: int) -> string { return append_int(buf, i64(i), 10); }
+itoa :: proc(buf: []u8, i: int) -> string do return append_int(buf, i64(i), 10);
 
 append_float :: proc(buf: []u8, f: f64, fmt: u8, prec, bit_size: int) -> string {
 	return string(generic_ftoa(buf, f, fmt, prec, bit_size));
@@ -389,15 +388,15 @@ round_shortest :: proc(d: ^Decimal, mant: u64, exp: int, flt: ^FloatInfo) {
 		ok_round_down := l != m || inclusive && i+1 == lower.count;
 		ok_round_up   := m != u && (inclusive || m+1 < u || i+1 < upper.count);
 
-		if (ok_round_down && ok_round_up) {
+		if ok_round_down && ok_round_up {
 			round(d, i+1);
 			return;
 		}
-		if (ok_round_down) {
+		if ok_round_down {
 			round_down(d, i+1);
 			return;
 		}
-		if (ok_round_up) {
+		if ok_round_up {
 			round_up(d, i+1);
 			return;
 		}
@@ -416,28 +415,23 @@ is_integer_negative :: proc(u: u128, is_signed: bool, bit_size: int) -> (unsigne
 		case 8:
 			i := i8(u);
 			neg = i < 0;
-			if neg { i = -i; }
-			u = u128(i);
+			u = u128(abs(i));
 		case 16:
 			i := i16(u);
 			neg = i < 0;
-			if neg { i = -i; }
-			u = u128(i);
+			u = u128(abs(i));
 		case 32:
 			i := i32(u);
 			neg = i < 0;
-			if neg { i = -i; }
-			u = u128(i);
+			u = u128(abs(i));
 		case 64:
 			i := i64(u);
 			neg = i < 0;
-			if neg { i = -i; }
-			u = u128(i);
+			u = u128(abs(i));
 		case 128:
 			i := i128(u);
 			neg = i < 0;
-			if neg { i = -i; }
-			u = u128(i);
+			u = u128(abs(i));
 		case:
 			panic("is_integer_negative: Unknown integer size");
 		}

+ 1 - 1
core/sys/wgl.odin

@@ -10,7 +10,7 @@ CONTEXT_FORWARD_COMPATIBLE_BIT_ARB    :: 0x0002;
 CONTEXT_CORE_PROFILE_BIT_ARB          :: 0x00000001;
 CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002;
 
-Hglrc    :: Handle;
+Hglrc     :: Handle;
 Color_Ref :: u32;
 
 Layer_Plane_Descriptor :: struct {

+ 3 - 1
core/thread.odin

@@ -1,6 +1,8 @@
 _ :: compile_assert(ODIN_OS == "windows");
 
-import win32 "core:sys/windows.odin";
+when ODIN_OS == "windows" {
+	import win32 "core:sys/windows.odin";
+}
 
 Thread :: struct {
 	using specific:   Os_Specific;

+ 1 - 0
examples/demo.odin

@@ -20,6 +20,7 @@ when ODIN_OS == "windows" {
 	import win32 "core:sys/windows.odin";
 }
 
+
 general_stuff :: proc() {
 	{ // `do` for inline statmes rather than block
 		foo :: proc() do fmt.println("Foo!");

+ 6 - 11
src/checker.cpp

@@ -264,11 +264,6 @@ i32 is_scope_an_ancestor(Scope *parent, Scope *child) {
 }
 
 
-struct DelayedDecl {
-	Scope *  parent;
-	AstNode *decl;
-};
-
 struct EntityGraphNode;
 typedef PtrSet<EntityGraphNode *> EntityGraphNodeSet;
 
@@ -1617,7 +1612,7 @@ void init_preload(Checker *c) {
 bool check_arity_match(Checker *c, AstNodeValueDecl *vd, bool is_global = false);
 void check_collect_entities(Checker *c, Array<AstNode *> nodes);
 void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws);
-void check_delayed_file_import_entities(Checker *c, AstNode *decl);
+void check_delayed_file_import_entity(Checker *c, AstNode *decl);
 
 bool check_is_entity_overloaded(Entity *e) {
 	if (e->kind != Entity_Procedure) {
@@ -1966,7 +1961,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes) {
 				continue;
 			}
 			if (c->context.allow_file_when_statement) {
-				check_delayed_file_import_entities(c, decl);
+				check_delayed_file_import_entity(c, decl);
 			}
 		case_end;
 
@@ -1978,7 +1973,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes) {
 				continue;
 			}
 			if (c->context.allow_file_when_statement) {
-				check_delayed_file_import_entities(c, decl);
+				check_delayed_file_import_entity(c, decl);
 			}
 		case_end;
 
@@ -1990,7 +1985,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes) {
 				continue;
 			}
 			if (c->context.allow_file_when_statement) {
-				check_delayed_file_import_entities(c, decl);
+				check_delayed_file_import_entity(c, decl);
 			}
 		case_end;
 
@@ -2410,7 +2405,7 @@ Array<Scope *> find_import_path(Map<Scope *> *file_scopes, Scope *start, Scope *
 	return empty_path;
 }
 
-void check_delayed_file_import_entities(Checker *c, AstNode *decl) {
+void check_delayed_file_import_entity(Checker *c, AstNode *decl) {
 	GB_ASSERT(c->context.allow_file_when_statement);
 
 	Scope *parent_scope = c->context.scope;
@@ -2636,7 +2631,7 @@ void check_import_entities(Checker *c) {
 		c->context.allow_file_when_statement = true;
 
 		for_array(i, f->decls) {
-			check_delayed_file_import_entities(c, f->decls[i]);
+			check_delayed_file_import_entity(c, f->decls[i]);
 		}
 	}
 }