mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Fix issue #94
This commit is contained in:
+14
-10
@@ -13,17 +13,21 @@ c_ushort :: i16;
|
|||||||
c_int :: i32;
|
c_int :: i32;
|
||||||
c_uint :: u32;
|
c_uint :: u32;
|
||||||
|
|
||||||
c_long :: ODIN_OS == "windows" ?
|
when ODIN_OS == "windows" {
|
||||||
i32 :
|
c_long :: i32;
|
||||||
(size_of(int) == 4) ?
|
} else when size_of(int) == 4 {
|
||||||
i32 :
|
c_long :: i32;
|
||||||
i64;
|
} else {
|
||||||
|
c_long :: i64;
|
||||||
|
}
|
||||||
|
|
||||||
c_ulong :: ODIN_OS == "windows" ?
|
when ODIN_OS == "windows" {
|
||||||
u32 :
|
c_long :: u32;
|
||||||
(size_of(int) == 4) ?
|
} else when size_of(uint) == 4 {
|
||||||
u32 :
|
c_long :: u32;
|
||||||
u64;
|
} else {
|
||||||
|
c_long :: u64;
|
||||||
|
}
|
||||||
|
|
||||||
c_longlong :: i64;
|
c_longlong :: i64;
|
||||||
c_ulonglong :: u64;
|
c_ulonglong :: u64;
|
||||||
|
|||||||
+2
-2
@@ -3,9 +3,9 @@ foreign_system_library libc "c";
|
|||||||
|
|
||||||
import "core:strings.odin";
|
import "core:strings.odin";
|
||||||
|
|
||||||
Handle :: i32;
|
Handle :: i32;
|
||||||
File_Time :: u64;
|
File_Time :: u64;
|
||||||
Errno :: i32;
|
Errno :: i32;
|
||||||
|
|
||||||
|
|
||||||
O_RDONLY :: 0x00000;
|
O_RDONLY :: 0x00000;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import win32 "core:sys/windows.odin";
|
import win32 "core:sys/windows.odin";
|
||||||
import "core:mem.odin";
|
import "core:mem.odin";
|
||||||
|
|
||||||
Handle :: int;
|
Handle :: int;
|
||||||
File_Time :: u64;
|
File_Time :: u64;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -3,9 +3,9 @@ foreign_system_library libc "c";
|
|||||||
|
|
||||||
import "core:strings.odin";
|
import "core:strings.odin";
|
||||||
|
|
||||||
Handle :: i32;
|
Handle :: i32;
|
||||||
File_Time :: u64;
|
File_Time :: u64;
|
||||||
Errno :: int;
|
Errno :: int;
|
||||||
|
|
||||||
|
|
||||||
O_RDONLY :: 0x00000;
|
O_RDONLY :: 0x00000;
|
||||||
|
|||||||
+38
-44
@@ -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 {
|
match s {
|
||||||
case "1", "t", "T", "true", "TRUE", "True":
|
case "1", "t", "T", "true", "TRUE", "True":
|
||||||
return true, true;
|
return true, true;
|
||||||
case "0", "f", "F", "false", "FALSE", "False":
|
case "0", "f", "F", "false", "FALSE", "False":
|
||||||
return false, true;
|
return false, true;
|
||||||
}
|
}
|
||||||
return false, false;
|
return ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_digit_value :: proc(r: rune) -> int {
|
_digit_value :: proc(r: rune) -> int {
|
||||||
ri := int(r);
|
ri := int(r);
|
||||||
v: int = 16;
|
v: int = 16;
|
||||||
match r {
|
match r {
|
||||||
case '0'..'9': v = ri-'0';
|
case '0'...'9': v = ri-'0';
|
||||||
case 'a'..'z': v = ri-'a'+10;
|
case 'a'...'z': v = ri-'a'+10;
|
||||||
case 'A'..'Z': v = ri-'A'+10;
|
case 'A'...'Z': v = ri-'A'+10;
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ parse_f64 :: proc(s: string) -> f64 {
|
|||||||
value += f64(v);
|
value += f64(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
if s[i] == '.' {
|
if i < len(s) && s[i] == '.' {
|
||||||
pow10: f64 = 10;
|
pow10: f64 = 10;
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
||||||
@@ -149,28 +149,30 @@ parse_f64 :: proc(s: string) -> f64 {
|
|||||||
frac := false;
|
frac := false;
|
||||||
scale: f64 = 1;
|
scale: f64 = 1;
|
||||||
|
|
||||||
if s[i] == 'e' || s[i] == 'E' {
|
if i < len(s) && (s[i] == 'e' || s[i] == 'E') {
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
||||||
match s[i] {
|
if i < len(s) {
|
||||||
case '-': i += 1; frac = true;
|
match s[i] {
|
||||||
case '+': i += 1;
|
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;
|
||||||
|
|
||||||
|
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; }
|
||||||
}
|
}
|
||||||
|
|
||||||
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; }
|
|
||||||
|
|
||||||
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);
|
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 {
|
append_bool :: proc(buf: []u8, b: bool) -> string {
|
||||||
if b {
|
if b do append(&buf, "true");
|
||||||
append(&buf, "true");
|
else do append(&buf, "false");
|
||||||
} else {
|
|
||||||
append(&buf, "false");
|
|
||||||
}
|
|
||||||
return string(buf);
|
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 {
|
append_int :: proc(buf: []u8, i: i64, base: int) -> string {
|
||||||
return append_bits(buf, u128(i), base, true, 8*size_of(int), digits, 0);
|
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 {
|
append_float :: proc(buf: []u8, f: f64, fmt: u8, prec, bit_size: int) -> string {
|
||||||
return string(generic_ftoa(buf, f, fmt, prec, bit_size));
|
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_down := l != m || inclusive && i+1 == lower.count;
|
||||||
ok_round_up := m != u && (inclusive || m+1 < u || i+1 < upper.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);
|
round(d, i+1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ok_round_down) {
|
if ok_round_down {
|
||||||
round_down(d, i+1);
|
round_down(d, i+1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ok_round_up) {
|
if ok_round_up {
|
||||||
round_up(d, i+1);
|
round_up(d, i+1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -416,28 +415,23 @@ is_integer_negative :: proc(u: u128, is_signed: bool, bit_size: int) -> (unsigne
|
|||||||
case 8:
|
case 8:
|
||||||
i := i8(u);
|
i := i8(u);
|
||||||
neg = i < 0;
|
neg = i < 0;
|
||||||
if neg { i = -i; }
|
u = u128(abs(i));
|
||||||
u = u128(i);
|
|
||||||
case 16:
|
case 16:
|
||||||
i := i16(u);
|
i := i16(u);
|
||||||
neg = i < 0;
|
neg = i < 0;
|
||||||
if neg { i = -i; }
|
u = u128(abs(i));
|
||||||
u = u128(i);
|
|
||||||
case 32:
|
case 32:
|
||||||
i := i32(u);
|
i := i32(u);
|
||||||
neg = i < 0;
|
neg = i < 0;
|
||||||
if neg { i = -i; }
|
u = u128(abs(i));
|
||||||
u = u128(i);
|
|
||||||
case 64:
|
case 64:
|
||||||
i := i64(u);
|
i := i64(u);
|
||||||
neg = i < 0;
|
neg = i < 0;
|
||||||
if neg { i = -i; }
|
u = u128(abs(i));
|
||||||
u = u128(i);
|
|
||||||
case 128:
|
case 128:
|
||||||
i := i128(u);
|
i := i128(u);
|
||||||
neg = i < 0;
|
neg = i < 0;
|
||||||
if neg { i = -i; }
|
u = u128(abs(i));
|
||||||
u = u128(i);
|
|
||||||
case:
|
case:
|
||||||
panic("is_integer_negative: Unknown integer size");
|
panic("is_integer_negative: Unknown integer size");
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ CONTEXT_FORWARD_COMPATIBLE_BIT_ARB :: 0x0002;
|
|||||||
CONTEXT_CORE_PROFILE_BIT_ARB :: 0x00000001;
|
CONTEXT_CORE_PROFILE_BIT_ARB :: 0x00000001;
|
||||||
CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002;
|
CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002;
|
||||||
|
|
||||||
Hglrc :: Handle;
|
Hglrc :: Handle;
|
||||||
Color_Ref :: u32;
|
Color_Ref :: u32;
|
||||||
|
|
||||||
Layer_Plane_Descriptor :: struct {
|
Layer_Plane_Descriptor :: struct {
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,8 @@
|
|||||||
_ :: compile_assert(ODIN_OS == "windows");
|
_ :: compile_assert(ODIN_OS == "windows");
|
||||||
|
|
||||||
import win32 "core:sys/windows.odin";
|
when ODIN_OS == "windows" {
|
||||||
|
import win32 "core:sys/windows.odin";
|
||||||
|
}
|
||||||
|
|
||||||
Thread :: struct {
|
Thread :: struct {
|
||||||
using specific: Os_Specific;
|
using specific: Os_Specific;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ when ODIN_OS == "windows" {
|
|||||||
import win32 "core:sys/windows.odin";
|
import win32 "core:sys/windows.odin";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
general_stuff :: proc() {
|
general_stuff :: proc() {
|
||||||
{ // `do` for inline statmes rather than block
|
{ // `do` for inline statmes rather than block
|
||||||
foo :: proc() do fmt.println("Foo!");
|
foo :: proc() do fmt.println("Foo!");
|
||||||
|
|||||||
+6
-11
@@ -264,11 +264,6 @@ i32 is_scope_an_ancestor(Scope *parent, Scope *child) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct DelayedDecl {
|
|
||||||
Scope * parent;
|
|
||||||
AstNode *decl;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct EntityGraphNode;
|
struct EntityGraphNode;
|
||||||
typedef PtrSet<EntityGraphNode *> EntityGraphNodeSet;
|
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);
|
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(Checker *c, Array<AstNode *> nodes);
|
||||||
void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws);
|
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) {
|
bool check_is_entity_overloaded(Entity *e) {
|
||||||
if (e->kind != Entity_Procedure) {
|
if (e->kind != Entity_Procedure) {
|
||||||
@@ -1966,7 +1961,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c->context.allow_file_when_statement) {
|
if (c->context.allow_file_when_statement) {
|
||||||
check_delayed_file_import_entities(c, decl);
|
check_delayed_file_import_entity(c, decl);
|
||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
@@ -1978,7 +1973,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c->context.allow_file_when_statement) {
|
if (c->context.allow_file_when_statement) {
|
||||||
check_delayed_file_import_entities(c, decl);
|
check_delayed_file_import_entity(c, decl);
|
||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
@@ -1990,7 +1985,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c->context.allow_file_when_statement) {
|
if (c->context.allow_file_when_statement) {
|
||||||
check_delayed_file_import_entities(c, decl);
|
check_delayed_file_import_entity(c, decl);
|
||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
@@ -2410,7 +2405,7 @@ Array<Scope *> find_import_path(Map<Scope *> *file_scopes, Scope *start, Scope *
|
|||||||
return empty_path;
|
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);
|
GB_ASSERT(c->context.allow_file_when_statement);
|
||||||
|
|
||||||
Scope *parent_scope = c->context.scope;
|
Scope *parent_scope = c->context.scope;
|
||||||
@@ -2636,7 +2631,7 @@ void check_import_entities(Checker *c) {
|
|||||||
c->context.allow_file_when_statement = true;
|
c->context.allow_file_when_statement = true;
|
||||||
|
|
||||||
for_array(i, f->decls) {
|
for_array(i, f->decls) {
|
||||||
check_delayed_file_import_entities(c, f->decls[i]);
|
check_delayed_file_import_entity(c, f->decls[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user