Filename as default import name; as .; as _; panic()

This commit is contained in:
Ginger Bill
2016-09-21 14:46:56 +01:00
parent 31c11a5037
commit 0e2347e582
14 changed files with 313 additions and 167 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
#import "os.odin" as os
#import "os.odin"
PRINT_BUF_SIZE :: 1<<12
+1 -2
View File
@@ -1,4 +1,4 @@
#import "win32.odin" as win32
#import "win32.odin"
File :: type struct {
Handle :: type win32.HANDLE
@@ -50,7 +50,6 @@ stdin := ^__std_files[File_Standard.INPUT]
stdout := ^__std_files[File_Standard.OUTPUT]
stderr := ^__std_files[File_Standard.ERROR]
__set_file_standards :: proc() -> [File_Standard.COUNT as int]File {
return [File_Standard.COUNT as int]File{
File{handle = win32.GetStdHandle(win32.STD_INPUT_HANDLE)},
+99 -89
View File
@@ -1,7 +1,7 @@
#shared_global_scope
#import "os.odin" as os
#import "fmt.odin" as fmt
#import "os.odin"
#import "fmt.odin"
// IMPORTANT NOTE(bill): Do not change the order of any of this data
// The compiler relies upon this _exact_ order
@@ -134,93 +134,6 @@ memory_copy :: proc(dst, src: rawptr, len: int) #inline {
llvm_memmove_64bit(dst, src, len, 1, false)
}
__string_eq :: proc(a, b: string) -> bool {
if a.count != b.count {
return false
}
if ^a[0] == ^b[0] {
return true
}
return memory_compare(^a[0], ^b[0], a.count) == 0
}
__string_cmp :: proc(a, b : string) -> int {
// Translation of http://mgronhol.github.io/fast-strcmp/
n := min(a.count, b.count)
fast := n/size_of(int) + 1
offset := (fast-1)*size_of(int)
curr_block := 0
if n <= size_of(int) {
fast = 0
}
la := slice_ptr(^a[0] as ^int, fast)
lb := slice_ptr(^b[0] as ^int, fast)
for ; curr_block < fast; curr_block++ {
if (la[curr_block] ~ lb[curr_block]) != 0 {
for pos := curr_block*size_of(int); pos < n; pos++ {
if (a[pos] ~ b[pos]) != 0 {
return a[pos] as int - b[pos] as int
}
}
}
}
for ; offset < n; offset++ {
if (a[offset] ~ b[offset]) != 0 {
return a[offset] as int - b[offset] as int
}
}
return 0
}
__string_ne :: proc(a, b : string) -> bool #inline { return !__string_eq(a, b) }
__string_lt :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) < 0 }
__string_gt :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) > 0 }
__string_le :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) <= 0 }
__string_ge :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) >= 0 }
__assert :: proc(msg: string) {
fmt.fprintln(os.stderr, msg)
__debug_trap()
}
__bounds_check_error :: proc(file: string, line, column: int,
index, count: int) {
if 0 <= index && index < count {
return
}
fmt.fprintf(os.stderr, "%(%:%) Index % is out of bounds range [0, %)\n",
file, line, column, index, count)
__debug_trap()
}
__slice_expr_error :: proc(file: string, line, column: int,
low, high, max: int) {
if 0 <= low && low <= high && high <= max {
return
}
fmt.fprintf(os.stderr, "%(%:%) Invalid slice indices: [%:%:%]\n",
file, line, column, low, high, max)
__debug_trap()
}
__substring_expr_error :: proc(file: string, line, column: int,
low, high: int) {
if 0 <= low && low <= high {
return
}
fmt.fprintf(os.stderr, "%(%:%) Invalid substring indices: [%:%:%]\n",
file, line, column, low, high)
__debug_trap()
}
@@ -357,6 +270,103 @@ __default_allocator :: proc() -> Allocator {
}
__string_eq :: proc(a, b: string) -> bool {
if a.count != b.count {
return false
}
if ^a[0] == ^b[0] {
return true
}
return memory_compare(^a[0], ^b[0], a.count) == 0
}
__string_cmp :: proc(a, b : string) -> int {
// Translation of http://mgronhol.github.io/fast-strcmp/
n := min(a.count, b.count)
fast := n/size_of(int) + 1
offset := (fast-1)*size_of(int)
curr_block := 0
if n <= size_of(int) {
fast = 0
}
la := slice_ptr(^a[0] as ^int, fast)
lb := slice_ptr(^b[0] as ^int, fast)
for ; curr_block < fast; curr_block++ {
if (la[curr_block] ~ lb[curr_block]) != 0 {
for pos := curr_block*size_of(int); pos < n; pos++ {
if (a[pos] ~ b[pos]) != 0 {
return a[pos] as int - b[pos] as int
}
}
}
}
for ; offset < n; offset++ {
if (a[offset] ~ b[offset]) != 0 {
return a[offset] as int - b[offset] as int
}
}
return 0
}
__string_ne :: proc(a, b : string) -> bool #inline { return !__string_eq(a, b) }
__string_lt :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) < 0 }
__string_gt :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) > 0 }
__string_le :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) <= 0 }
__string_ge :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) >= 0 }
__assert :: proc(file: string, line, column: int, msg: string) #inline {
fmt.fprintf(os.stderr, "%(%:%) Runtime assertion: %\n",
file, line, column, msg)
__debug_trap()
}
__bounds_check_error :: proc(file: string, line, column: int,
index, count: int) {
if 0 <= index && index < count {
return
}
fmt.fprintf(os.stderr, "%(%:%) Index % is out of bounds range [0, %)\n",
file, line, column, index, count)
__debug_trap()
}
__slice_expr_error :: proc(file: string, line, column: int,
low, high, max: int) {
if 0 <= low && low <= high && high <= max {
return
}
fmt.fprintf(os.stderr, "%(%:%) Invalid slice indices: [%:%:%]\n",
file, line, column, low, high, max)
__debug_trap()
}
__substring_expr_error :: proc(file: string, line, column: int,
low, high: int) {
if 0 <= low && low <= high {
return
}
fmt.fprintf(os.stderr, "%(%:%) Invalid substring indices: [%:%:%]\n",
file, line, column, low, high)
__debug_trap()
}
__enum_to_string :: proc(info: ^Type_Info, value: i64) -> string {
info = type_info_base(info)