mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-28 18:30:06 +00:00
Merge branch 'master' of github.com:odin-lang/Odin
This commit is contained in:
@@ -17,7 +17,7 @@ unload_library :: proc(library: Library) -> bool {
|
||||
}
|
||||
|
||||
symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) {
|
||||
c_str := strings.new_cstring(symbol, context.temp_allocator);
|
||||
c_str := strings.clone_to_cstring(symbol, context.temp_allocator);
|
||||
ptr = win32.get_proc_address(cast(win32.Hmodule)library, c_str);
|
||||
found == ptr != nil;
|
||||
return;
|
||||
|
||||
+6
-6
@@ -59,12 +59,12 @@ fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
|
||||
|
||||
|
||||
// print* procedures return the number of bytes written
|
||||
print :: proc(args: ..any) -> int { return fprint(os.stdout, ..args); }
|
||||
print_err :: proc(args: ..any) -> int { return fprint(os.stderr, ..args); }
|
||||
println :: proc(args: ..any) -> int { return fprintln(os.stdout, ..args); }
|
||||
println_err :: proc(args: ..any) -> int { return fprintln(os.stderr, ..args); }
|
||||
printf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stdout, fmt, ..args); }
|
||||
printf_err :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stderr, fmt, ..args); }
|
||||
print :: proc(args: ..any) -> int { return fprint(context.stdout, ..args); }
|
||||
print_err :: proc(args: ..any) -> int { return fprint(context.stderr, ..args); }
|
||||
println :: proc(args: ..any) -> int { return fprintln(context.stdout, ..args); }
|
||||
println_err :: proc(args: ..any) -> int { return fprintln(context.stderr, ..args); }
|
||||
printf :: proc(fmt: string, args: ..any) -> int { return fprintf(context.stdout, fmt, ..args); }
|
||||
printf_err :: proc(fmt: string, args: ..any) -> int { return fprintf(context.stderr, fmt, ..args); }
|
||||
|
||||
|
||||
// aprint* procedures return a string that was allocated with the current context
|
||||
|
||||
@@ -69,7 +69,7 @@ file_console_logger_proc :: proc(logger_data: rawptr, level: Level, text: string
|
||||
|
||||
h : os.Handle;
|
||||
if(data.file_handle != os.INVALID_HANDLE) do h = data.file_handle;
|
||||
else do h = level <= Level.Error ? os.stdout : os.stderr;
|
||||
else do h = level <= Level.Error ? context.stdout : context.stderr;
|
||||
backing: [1024]byte; //NOTE(Hoej): 1024 might be too much for a header backing, unless somebody has really long paths.
|
||||
buf := strings.builder_from_slice(backing[:]);
|
||||
|
||||
|
||||
@@ -1528,6 +1528,8 @@ parse_field_list :: proc(p: ^Parser, follow: token.Kind, allowed_flags: ast.Fiel
|
||||
return ok;
|
||||
}
|
||||
|
||||
is_signature := (allowed_flags & Field_Flags_Signature_Params) == Field_Flags_Signature_Params;
|
||||
|
||||
any_polymorphic_names := check_procedure_name_list(p, names);
|
||||
set_flags = check_field_flag_prefixes(p, len(names), allowed_flags, set_flags);
|
||||
|
||||
@@ -1538,7 +1540,7 @@ parse_field_list :: proc(p: ^Parser, follow: token.Kind, allowed_flags: ast.Fiel
|
||||
if p.curr_tok.kind != token.Eq {
|
||||
type = parse_var_type(p, allowed_flags);
|
||||
tt := ast.unparen_expr(type);
|
||||
if !any_polymorphic_names {
|
||||
if is_signature && !any_polymorphic_names {
|
||||
if ti, ok := tt.derived.(ast.Typeid_Type); ok && ti.specialization != nil {
|
||||
error(p, tt.pos, "specialization of typeid is not allowed without polymorphic names");
|
||||
}
|
||||
|
||||
+6
-6
@@ -153,7 +153,7 @@ foreign dl {
|
||||
}
|
||||
|
||||
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Errno) {
|
||||
cstr := strings.new_cstring(path);
|
||||
cstr := strings.clone_to_cstring(path);
|
||||
handle := _unix_open(cstr, flags, mode);
|
||||
delete(cstr);
|
||||
if handle == -1 {
|
||||
@@ -221,14 +221,14 @@ is_path_separator :: proc(r: rune) -> bool {
|
||||
|
||||
stat :: inline proc(path: string) -> (Stat, bool) {
|
||||
s: Stat;
|
||||
cstr := strings.new_cstring(path);
|
||||
cstr := strings.clone_to_cstring(path);
|
||||
defer delete(cstr);
|
||||
ret_int := _unix_stat(cstr, &s);
|
||||
return s, ret_int==0;
|
||||
}
|
||||
|
||||
access :: inline proc(path: string, mask: int) -> bool {
|
||||
cstr := strings.new_cstring(path);
|
||||
cstr := strings.clone_to_cstring(path);
|
||||
defer delete(cstr);
|
||||
return _unix_access(cstr, mask) == 0;
|
||||
}
|
||||
@@ -245,7 +245,7 @@ heap_free :: inline proc(ptr: rawptr) {
|
||||
}
|
||||
|
||||
getenv :: proc(name: string) -> (string, bool) {
|
||||
path_str := strings.new_cstring(name);
|
||||
path_str := strings.clone_to_cstring(name);
|
||||
defer delete(path_str);
|
||||
cstr := _unix_getenv(path_str);
|
||||
if cstr == nil {
|
||||
@@ -265,14 +265,14 @@ current_thread_id :: proc "contextless" () -> int {
|
||||
}
|
||||
|
||||
dlopen :: inline proc(filename: string, flags: int) -> rawptr {
|
||||
cstr := strings.new_cstring(filename);
|
||||
cstr := strings.clone_to_cstring(filename);
|
||||
defer delete(cstr);
|
||||
handle := _unix_dlopen(cstr, flags);
|
||||
return handle;
|
||||
}
|
||||
dlsym :: inline proc(handle: rawptr, symbol: string) -> rawptr {
|
||||
assert(handle != nil);
|
||||
cstr := strings.new_cstring(symbol);
|
||||
cstr := strings.clone_to_cstring(symbol);
|
||||
defer delete(cstr);
|
||||
proc_handle := _unix_dlsym(handle, cstr);
|
||||
return proc_handle;
|
||||
|
||||
+14
-5
@@ -213,9 +213,14 @@ Context :: struct {
|
||||
assertion_failure_proc: Assertion_Failure_Proc,
|
||||
logger: log.Logger,
|
||||
|
||||
stdin: os.Handle,
|
||||
stdout: os.Handle,
|
||||
stderr: os.Handle,
|
||||
|
||||
thread_id: int,
|
||||
|
||||
user_data: any,
|
||||
user_ptr: rawptr,
|
||||
user_index: int,
|
||||
|
||||
derived: any, // May be used for derived data types
|
||||
@@ -350,6 +355,10 @@ __init_context :: proc "contextless" (c: ^Context) {
|
||||
|
||||
c.logger.procedure = log.nil_logger_proc;
|
||||
c.logger.data = nil;
|
||||
|
||||
c.stdin = os.stdin;
|
||||
c.stdout = os.stdout;
|
||||
c.stderr = os.stderr;
|
||||
}
|
||||
|
||||
@builtin
|
||||
@@ -358,7 +367,7 @@ init_global_temporary_allocator :: proc(data: []byte, backup_allocator := contex
|
||||
}
|
||||
|
||||
default_assertion_failure_proc :: proc(prefix, message: string, loc: Source_Code_Location) {
|
||||
fd := os.stderr;
|
||||
fd := context.stderr;
|
||||
print_caller_location(fd, loc);
|
||||
os.write_string(fd, " ");
|
||||
os.write_string(fd, prefix);
|
||||
@@ -653,7 +662,7 @@ card :: proc(s: $S/bit_set[$E; $U]) -> int {
|
||||
|
||||
|
||||
@builtin
|
||||
assert :: proc "contextless" (condition: bool, message := "", loc := #caller_location) -> bool {
|
||||
assert :: proc(condition: bool, message := "", loc := #caller_location) -> bool {
|
||||
if !condition {
|
||||
p := context.assertion_failure_proc;
|
||||
if p == nil {
|
||||
@@ -665,7 +674,7 @@ assert :: proc "contextless" (condition: bool, message := "", loc := #caller_loc
|
||||
}
|
||||
|
||||
@builtin
|
||||
panic :: proc "contextless" (message: string, loc := #caller_location) -> ! {
|
||||
panic :: proc(message: string, loc := #caller_location) -> ! {
|
||||
p := context.assertion_failure_proc;
|
||||
if p == nil {
|
||||
p = default_assertion_failure_proc;
|
||||
@@ -674,7 +683,7 @@ panic :: proc "contextless" (message: string, loc := #caller_location) -> ! {
|
||||
}
|
||||
|
||||
@builtin
|
||||
unimplemented :: proc "contextless" (message := "", loc := #caller_location) -> ! {
|
||||
unimplemented :: proc(message := "", loc := #caller_location) -> ! {
|
||||
p := context.assertion_failure_proc;
|
||||
if p == nil {
|
||||
p = default_assertion_failure_proc;
|
||||
@@ -683,7 +692,7 @@ unimplemented :: proc "contextless" (message := "", loc := #caller_location) ->
|
||||
}
|
||||
|
||||
@builtin
|
||||
unreachable :: proc "contextless" (message := "", loc := #caller_location) -> ! {
|
||||
unreachable :: proc(message := "", loc := #caller_location) -> ! {
|
||||
p := context.assertion_failure_proc;
|
||||
if p == nil {
|
||||
p = default_assertion_failure_proc;
|
||||
|
||||
+31
-27
@@ -223,6 +223,21 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) {
|
||||
print_type(fd, info.underlying);
|
||||
}
|
||||
os.write_byte(fd, ']');
|
||||
|
||||
case Type_Info_Opaque:
|
||||
os.write_string(fd, "opaque ");
|
||||
print_type(fd, info.elem);
|
||||
|
||||
case Type_Info_Simd_Vector:
|
||||
if info.is_x86_mmx {
|
||||
os.write_string(fd, "intrinsics.x86_mmx");
|
||||
} else {
|
||||
os.write_string(fd, "intrinsics.vector(");
|
||||
print_u64(fd, u64(info.count));
|
||||
os.write_string(fd, ", ");
|
||||
print_type(fd, info.elem);
|
||||
os.write_byte(fd, ')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,38 +300,27 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index
|
||||
handle_error(file, line, column, index, count);
|
||||
}
|
||||
|
||||
slice_handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
||||
fd := os.stderr;
|
||||
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
|
||||
os.write_string(fd, " Invalid slice indices: ");
|
||||
print_i64(fd, i64(lo));
|
||||
os.write_string(fd, ":");
|
||||
print_i64(fd, i64(hi));
|
||||
os.write_string(fd, ":");
|
||||
print_i64(fd, i64(len));
|
||||
os.write_byte(fd, '\n');
|
||||
debug_trap();
|
||||
}
|
||||
|
||||
slice_expr_error_hi :: proc "contextless" (file: string, line, column: int, hi: int, len: int) {
|
||||
if 0 <= hi && hi <= len do return;
|
||||
handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
||||
fd := os.stderr;
|
||||
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
|
||||
os.write_string(fd, " Invalid slice indices: ");
|
||||
print_i64(fd, i64(lo));
|
||||
os.write_string(fd, ":");
|
||||
print_i64(fd, i64(hi));
|
||||
os.write_string(fd, ":");
|
||||
print_i64(fd, i64(len));
|
||||
os.write_byte(fd, '\n');
|
||||
debug_trap();
|
||||
}
|
||||
handle_error(file, line, column, 0, hi, len);
|
||||
slice_handle_error(file, line, column, 0, hi, len);
|
||||
}
|
||||
|
||||
slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
||||
if 0 <= lo && lo < len && lo <= hi && hi <= len do return;
|
||||
handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
||||
fd := os.stderr;
|
||||
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
|
||||
os.write_string(fd, " Invalid slice indices: ");
|
||||
print_i64(fd, i64(lo));
|
||||
os.write_string(fd, ":");
|
||||
print_i64(fd, i64(hi));
|
||||
os.write_string(fd, ":");
|
||||
print_i64(fd, i64(len));
|
||||
os.write_byte(fd, '\n');
|
||||
debug_trap();
|
||||
}
|
||||
handle_error(file, line, column, lo, hi, len);
|
||||
if 0 <= lo && lo <= len && lo <= hi && hi <= len do return;
|
||||
slice_handle_error(file, line, column, lo, hi, len);
|
||||
}
|
||||
|
||||
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
|
||||
|
||||
@@ -236,8 +236,8 @@ quote :: proc(buf: []byte, s: string) -> string {
|
||||
write_byte(buf, &i, digits[s[0]&0xf]);
|
||||
}
|
||||
if i < len(buf) {
|
||||
s2 := quote_rune(buf[i:], r);
|
||||
i += len(s2);
|
||||
x := quote_rune(buf[i:], r);
|
||||
i += len(x);
|
||||
}
|
||||
}
|
||||
write_byte(buf, &i, c);
|
||||
|
||||
Reference in New Issue
Block a user