mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Prefix proc syntax
This commit is contained in:
+46
-46
@@ -107,13 +107,13 @@ const S_ISUID = 0004000; // Set user id on execution
|
||||
const S_ISGID = 0002000; // Set group id on execution
|
||||
const S_ISVTX = 0001000; // Directory restrcted delete
|
||||
|
||||
const S_ISLNK = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFLNK; }
|
||||
const S_ISREG = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFREG; }
|
||||
const S_ISDIR = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFDIR; }
|
||||
const S_ISCHR = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFCHR; }
|
||||
const S_ISBLK = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFBLK; }
|
||||
const S_ISFIFO = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFIFO; }
|
||||
const S_ISSOCK = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFSOCK;}
|
||||
proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
|
||||
proc S_ISREG (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; }
|
||||
proc S_ISDIR (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFDIR; }
|
||||
proc S_ISCHR (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFCHR; }
|
||||
proc S_ISBLK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; }
|
||||
proc S_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
|
||||
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
||||
|
||||
const R_OK = 4; // Test for read permission
|
||||
const W_OK = 2; // Test for write permission
|
||||
@@ -123,29 +123,29 @@ const F_OK = 0; // Test for file existance
|
||||
#foreign_system_library dl "dl";
|
||||
#foreign_system_library libc "c";
|
||||
|
||||
const _unix_open = proc(path: ^u8, mode: int) -> Handle #foreign libc "open";
|
||||
const _unix_close = proc(fd: Handle) -> i32 #foreign libc "close";
|
||||
const _unix_read = proc(fd: Handle, buf: rawptr, size: int) -> int #foreign libc "read";
|
||||
const _unix_write = proc(fd: Handle, buf: rawptr, size: int) -> int #foreign libc "write";
|
||||
const _unix_seek = proc(fd: Handle, offset: i64, whence: i32) -> i64 #foreign libc "lseek64";
|
||||
const _unix_gettid = proc() -> u64 #foreign libc "gettid";
|
||||
const _unix_stat = proc(path: ^u8, stat: ^Stat) -> i32 #foreign libc "stat";
|
||||
const _unix_access = proc(path: ^u8, mask: int) -> i32 #foreign libc "access";
|
||||
proc _unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
|
||||
proc _unix_close (fd: Handle) -> i32 #foreign libc "close";
|
||||
proc _unix_read (fd: Handle, buf: rawptr, size: int) -> int #foreign libc "read";
|
||||
proc _unix_write (fd: Handle, buf: rawptr, size: int) -> int #foreign libc "write";
|
||||
proc _unix_seek (fd: Handle, offset: i64, whence: i32) -> i64 #foreign libc "lseek64";
|
||||
proc _unix_gettid() -> u64 #foreign libc "gettid";
|
||||
proc _unix_stat (path: ^u8, stat: ^Stat) -> i32 #foreign libc "stat";
|
||||
proc _unix_access(path: ^u8, mask: int) -> i32 #foreign libc "access";
|
||||
|
||||
const _unix_malloc = proc(size: int) -> rawptr #foreign libc "malloc";
|
||||
const _unix_free = proc(ptr: rawptr) #foreign libc "free";
|
||||
const _unix_realloc = proc(ptr: rawptr, size: int) -> rawptr #foreign libc "realloc";
|
||||
const _unix_getenv = proc(^u8) -> ^u8 #foreign libc "getenv";
|
||||
proc _unix_malloc (size: int) -> rawptr #foreign libc "malloc";
|
||||
proc _unix_free (ptr: rawptr) #foreign libc "free";
|
||||
proc _unix_realloc(ptr: rawptr, size: int) -> rawptr #foreign libc "realloc";
|
||||
proc _unix_getenv (^u8) -> ^u8 #foreign libc "getenv";
|
||||
|
||||
const _unix_exit = proc(status: int) #foreign libc "exit";
|
||||
proc _unix_exit(status: int) #foreign libc "exit";
|
||||
|
||||
const _unix_dlopen = proc(filename: ^u8, flags: int) -> rawptr #foreign dl "dlopen";
|
||||
const _unix_dlsym = proc(handle: rawptr, symbol: ^u8) -> (proc() #cc_c) #foreign dl "dlsym";
|
||||
const _unix_dlclose = proc(handle: rawptr) -> int #foreign dl "dlclose";
|
||||
const _unix_dlerror = proc() -> ^u8 #foreign dl "dlerror";
|
||||
proc _unix_dlopen (filename: ^u8, flags: int) -> rawptr #foreign dl "dlopen";
|
||||
proc _unix_dlsym (handle: rawptr, symbol: ^u8) -> (proc() #cc_c) #foreign dl "dlsym";
|
||||
proc _unix_dlclose(handle: rawptr) -> int #foreign dl "dlclose";
|
||||
proc _unix_dlerror() -> ^u8 #foreign dl "dlerror";
|
||||
|
||||
// TODO(zangent): Change this to just `open` when Bill fixes overloading.
|
||||
const open_simple = proc(path: string, mode: int) -> (Handle, Errno) {
|
||||
proc open_simple(path: string, mode: int) -> (Handle, Errno) {
|
||||
|
||||
var cstr = strings.new_c_string(path);
|
||||
var handle = _unix_open(cstr, mode);
|
||||
@@ -156,30 +156,30 @@ const open_simple = proc(path: string, mode: int) -> (Handle, Errno) {
|
||||
return handle, 0;
|
||||
}
|
||||
// NOTE(zangent): This is here for compatability reasons. Should this be here?
|
||||
const open = proc(path: string, mode: int, perm: u32) -> (Handle, Errno) {
|
||||
proc open(path: string, mode: int, perm: u32) -> (Handle, Errno) {
|
||||
return open_simple(path, mode);
|
||||
}
|
||||
|
||||
const close = proc(fd: Handle) {
|
||||
proc close(fd: Handle) {
|
||||
_unix_close(fd);
|
||||
}
|
||||
|
||||
const read = proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
proc read(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
var sz = _unix_read(fd, &data[0], len(data));
|
||||
return sz, 0;
|
||||
}
|
||||
|
||||
const write = proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
proc write(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
var sz = _unix_write(fd, &data[0], len(data));
|
||||
return sz, 0;
|
||||
}
|
||||
|
||||
const seek = proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
proc seek(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
var res = _unix_seek(fd, offset, i32(whence));
|
||||
return res, 0;
|
||||
}
|
||||
|
||||
const file_size = proc(fd: Handle) -> (i64, Errno) {
|
||||
proc file_size(fd: Handle) -> (i64, Errno) {
|
||||
var prev, _ = seek(fd, 0, SEEK_CUR);
|
||||
var size, err = seek(fd, 0, SEEK_END);
|
||||
seek(fd, prev, SEEK_SET);
|
||||
@@ -193,11 +193,11 @@ var stdout: Handle = 1;
|
||||
var stderr: Handle = 2;
|
||||
|
||||
/* TODO(zangent): Implement these!
|
||||
const last_write_time = proc(fd: Handle) -> FileTime {}
|
||||
const last_write_time_by_name = proc(name: string) -> FileTime {}
|
||||
proc last_write_time(fd: Handle) -> FileTime {}
|
||||
proc last_write_time_by_name(name: string) -> FileTime {}
|
||||
*/
|
||||
|
||||
const stat = proc(path: string) -> (Stat, int) #inline {
|
||||
proc stat(path: string) -> (Stat, int) #inline {
|
||||
var s: Stat;
|
||||
var cstr = strings.new_c_string(path);
|
||||
defer free(cstr);
|
||||
@@ -205,26 +205,26 @@ const stat = proc(path: string) -> (Stat, int) #inline {
|
||||
return s, int(ret_int);
|
||||
}
|
||||
|
||||
const access = proc(path: string, mask: int) -> bool #inline {
|
||||
proc access(path: string, mask: int) -> bool #inline {
|
||||
var cstr = strings.new_c_string(path);
|
||||
defer free(cstr);
|
||||
return _unix_access(cstr, mask) == 0;
|
||||
}
|
||||
|
||||
const heap_alloc = proc(size: int) -> rawptr {
|
||||
proc heap_alloc(size: int) -> rawptr {
|
||||
assert(size > 0);
|
||||
return _unix_malloc(size);
|
||||
}
|
||||
|
||||
const heap_resize = proc(ptr: rawptr, new_size: int) -> rawptr {
|
||||
proc heap_resize(ptr: rawptr, new_size: int) -> rawptr {
|
||||
return _unix_realloc(ptr, new_size);
|
||||
}
|
||||
|
||||
const heap_free = proc(ptr: rawptr) {
|
||||
proc heap_free(ptr: rawptr) {
|
||||
_unix_free(ptr);
|
||||
}
|
||||
|
||||
const getenv = proc(name: string) -> (string, bool) {
|
||||
proc getenv(name: string) -> (string, bool) {
|
||||
var path_str = strings.new_c_string(name);
|
||||
var cstr: ^u8 = _unix_getenv(path_str);
|
||||
free(path_str);
|
||||
@@ -234,38 +234,38 @@ const getenv = proc(name: string) -> (string, bool) {
|
||||
return strings.to_odin_string(cstr), true;
|
||||
}
|
||||
|
||||
const exit = proc(code: int) {
|
||||
proc exit(code: int) {
|
||||
_unix_exit(code);
|
||||
}
|
||||
|
||||
const current_thread_id = proc() -> int {
|
||||
proc current_thread_id() -> int {
|
||||
// return int(_unix_gettid());
|
||||
return 0;
|
||||
}
|
||||
|
||||
const dlopen = proc(filename: string, flags: int) -> rawptr #inline {
|
||||
proc dlopen(filename: string, flags: int) -> rawptr #inline {
|
||||
var cstr = strings.new_c_string(filename);
|
||||
var handle = _unix_dlopen(cstr, flags);
|
||||
free(cstr);
|
||||
return handle;
|
||||
}
|
||||
const dlsym = proc(handle: rawptr, symbol: string) -> (proc() #cc_c) #inline {
|
||||
proc dlsym(handle: rawptr, symbol: string) -> (proc() #cc_c) #inline {
|
||||
assert(handle != nil);
|
||||
var cstr = strings.new_c_string(symbol);
|
||||
var proc_handle = _unix_dlsym(handle, cstr);
|
||||
free(cstr);
|
||||
return proc_handle;
|
||||
}
|
||||
const dlclose = proc(handle: rawptr) -> bool #inline {
|
||||
proc dlclose(handle: rawptr) -> bool #inline {
|
||||
assert(handle != nil);
|
||||
return _unix_dlclose(handle) == 0;
|
||||
}
|
||||
const dlerror = proc() -> string {
|
||||
proc dlerror() -> string {
|
||||
return strings.to_odin_string(_unix_dlerror());
|
||||
}
|
||||
|
||||
|
||||
const _alloc_command_line_arguments = proc() -> []string {
|
||||
proc _alloc_command_line_arguments() -> []string {
|
||||
// TODO(bill):
|
||||
return nil;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user