Nearly finished Jai-like declarations

This commit is contained in:
Ginger Bill
2017-01-01 20:41:10 +00:00
parent a48e0c7179
commit 9202bd1b06
18 changed files with 858 additions and 1074 deletions
+18 -20
View File
@@ -4,11 +4,9 @@ import {
}
type {
Handle uint;
File_Time u64;
Error int;
}
Handle :: uint;
File_Time :: u64;
Error :: int;
INVALID_HANDLE: Handle : ~(0 as Handle);
@@ -56,7 +54,7 @@ ERROR_FILE_IS_PIPE : Error : 1<<29 + 0;
proc open(path string, mode int, perm u32) -> (Handle, Error) {
open :: proc(path string, mode int, perm u32) -> (Handle, Error) {
using win32;
if path.count == 0 {
return INVALID_HANDLE, ERROR_FILE_NOT_FOUND;
@@ -109,11 +107,11 @@ proc open(path string, mode int, perm u32) -> (Handle, Error) {
return INVALID_HANDLE, err as Error;
}
proc close(fd Handle) {
close :: proc(fd Handle) {
win32.CloseHandle(fd as win32.HANDLE);
}
proc write(fd Handle, data []byte) -> (int, Error) {
write :: proc(fd Handle, data []byte) -> (int, Error) {
bytes_written: i32;
e := win32.WriteFile(fd as win32.HANDLE, data.data, data.count as i32, ^bytes_written, nil);
if e != 0 {
@@ -122,7 +120,7 @@ proc write(fd Handle, data []byte) -> (int, Error) {
return bytes_written as int, ERROR_NONE;
}
proc read(fd Handle, data []byte) -> (int, Error) {
read :: proc(fd Handle, data []byte) -> (int, Error) {
bytes_read: i32;
e := win32.ReadFile(fd as win32.HANDLE, data.data, data.count as u32, ^bytes_read, nil);
if e != win32.FALSE {
@@ -132,7 +130,7 @@ proc read(fd Handle, data []byte) -> (int, Error) {
return bytes_read as int, ERROR_NONE;
}
proc seek(fd Handle, offset i64, whence int) -> (i64, Error) {
seek :: proc(fd Handle, offset i64, whence int) -> (i64, Error) {
using win32;
w: u32;
match whence {
@@ -161,7 +159,7 @@ stdout := get_std_handle(win32.STD_OUTPUT_HANDLE);
stderr := get_std_handle(win32.STD_ERROR_HANDLE);
proc get_std_handle(h int) -> Handle {
get_std_handle :: proc(h int) -> Handle {
fd := win32.GetStdHandle(h as i32);
win32.SetHandleInformation(fd, win32.HANDLE_FLAG_INHERIT, 0);
return fd as Handle;
@@ -172,7 +170,7 @@ proc get_std_handle(h int) -> Handle {
proc last_write_time(fd Handle) -> File_Time {
last_write_time :: proc(fd Handle) -> File_Time {
file_info: win32.BY_HANDLE_FILE_INFORMATION;
win32.GetFileInformationByHandle(fd as win32.HANDLE, ^file_info);
lo := file_info.last_write_time.lo as File_Time;
@@ -180,7 +178,7 @@ proc last_write_time(fd Handle) -> File_Time {
return lo | hi << 32;
}
proc last_write_time_by_name(name string) -> File_Time {
last_write_time_by_name :: proc(name string) -> File_Time {
last_write_time: win32.FILETIME;
data: win32.FILE_ATTRIBUTE_DATA;
buf: [1024]byte;
@@ -202,7 +200,7 @@ proc last_write_time_by_name(name string) -> File_Time {
proc read_entire_file(name string) -> ([]byte, bool) {
read_entire_file :: proc(name string) -> ([]byte, bool) {
buf: [300]byte;
copy(buf[:], name as []byte);
@@ -250,25 +248,25 @@ proc read_entire_file(name string) -> ([]byte, bool) {
proc heap_alloc(size int) -> rawptr {
heap_alloc :: proc(size int) -> rawptr {
return win32.HeapAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, size);
}
proc heap_resize(ptr rawptr, new_size int) -> rawptr {
heap_resize :: proc(ptr rawptr, new_size int) -> rawptr {
return win32.HeapReAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, ptr, new_size);
}
proc heap_free(ptr rawptr) {
heap_free :: proc(ptr rawptr) {
win32.HeapFree(win32.GetProcessHeap(), 0, ptr);
}
proc exit(code int) {
exit :: proc(code int) {
win32.ExitProcess(code as u32);
}
proc current_thread_id() -> int {
proc GetCurrentThreadId() -> u32 #foreign #dll_import
current_thread_id :: proc() -> int {
GetCurrentThreadId :: proc() -> u32 #foreign #dll_import
return GetCurrentThreadId() as int;
}