Infix proc calling convention proc "std" (...)

This commit is contained in:
gingerBill
2017-10-29 16:44:44 +00:00
parent 1eb9994d88
commit d2588f9d1d
12 changed files with 300 additions and 397 deletions

View File

@@ -236,28 +236,28 @@ type_info_base_without_enum :: proc(info: ^Type_Info) -> ^Type_Info {
foreign __llvm_core {
@(link_name="llvm.assume")
assume :: proc(cond: bool) #cc_c ---;
assume :: proc "c" (cond: bool) ---;
@(link_name="llvm.debugtrap")
__debug_trap :: proc() #cc_c ---;
__debug_trap :: proc "c" () ---;
@(link_name="llvm.trap")
__trap :: proc() #cc_c ---;
__trap :: proc "c" () ---;
@(link_name="llvm.readcyclecounter")
read_cycle_counter :: proc() -> u64 #cc_c ---;
read_cycle_counter :: proc "c" () -> u64 ---;
}
make_source_code_location :: inline proc(file: string, line, column: i64, procedure: string) -> Source_Code_Location #cc_contextless {
make_source_code_location :: inline proc "contextless" (file: string, line, column: i64, procedure: string) -> Source_Code_Location {
return Source_Code_Location{file, line, column, procedure};
}
__init_context_from_ptr :: proc(c: ^Context, other: ^Context) #cc_contextless {
__init_context_from_ptr :: proc "contextless" (c: ^Context, other: ^Context) {
if c == nil do return;
c^ = other^;
@@ -269,7 +269,7 @@ __init_context_from_ptr :: proc(c: ^Context, other: ^Context) #cc_contextless {
}
}
__init_context :: proc(c: ^Context) #cc_contextless {
__init_context :: proc "contextless" (c: ^Context) {
if c == nil do return;
if c.allocator.procedure == nil {
@@ -319,7 +319,7 @@ copy :: proc(dst, src: $T/[]$E) -> int {
}
append :: proc(array: ^$T/[]$E, args: ...E) -> int #cc_contextless {
append :: proc "contextless" (array: ^$T/[]$E, args: ...E) -> int {
if array == nil do return 0;
arg_len := len(args);
@@ -373,7 +373,7 @@ append :: proc(array: ^$T/[dynamic]u8, args: ...string) -> int {
return len(array);
}
pop :: proc(array: ^$T/[]$E) -> E #cc_contextless {
pop :: proc "contextless" (array: ^$T/[]$E) -> E {
if array == nil do return E{};
assert(len(array) > 0);
res := array[len(array)-1];
@@ -381,7 +381,7 @@ pop :: proc(array: ^$T/[]$E) -> E #cc_contextless {
return res;
}
pop :: proc(array: ^$T/[dynamic]$E) -> E #cc_contextless {
pop :: proc "contextless" (array: ^$T/[dynamic]$E) -> E {
if array == nil do return E{};
assert(len(array) > 0);
res := array[len(array)-1];
@@ -389,13 +389,13 @@ pop :: proc(array: ^$T/[dynamic]$E) -> E #cc_contextless {
return res;
}
clear :: inline proc(slice: ^$T/[]$E) #cc_contextless {
clear :: inline proc "contextless" (slice: ^$T/[]$E) {
if slice != nil do (cast(^raw.Slice)slice).len = 0;
}
clear :: inline proc(array: ^$T/[dynamic]$E) #cc_contextless {
clear :: inline proc "contextless" (array: ^$T/[dynamic]$E) {
if array != nil do (cast(^raw.Dynamic_Array)array).len = 0;
}
clear :: inline proc(m: ^$T/map[$K]$V) #cc_contextless {
clear :: inline proc "contextless" (m: ^$T/map[$K]$V) {
if m == nil do return;
raw_map := cast(^raw.Map)m;
hashes := cast(^raw.Dynamic_Array)&raw_map.hashes;
@@ -428,7 +428,7 @@ reserve :: proc(array: ^$T/[dynamic]$E, capacity: int) -> bool {
}
__get_map_header :: proc(m: ^$T/map[$K]$V) -> __Map_Header #cc_contextless {
__get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> __Map_Header {
header := __Map_Header{m = cast(^raw.Map)m};
Entry :: struct {
key: __Map_Key,
@@ -445,7 +445,7 @@ __get_map_header :: proc(m: ^$T/map[$K]$V) -> __Map_Header #cc_contextless {
return header;
}
__get_map_key :: proc(key: $K) -> __Map_Key #cc_contextless {
__get_map_key :: proc "contextless" (key: $K) -> __Map_Key {
map_key: __Map_Key;
ti := type_info_base_without_enum(type_info_of(K));
switch _ in ti.variant {
@@ -607,7 +607,7 @@ default_allocator :: proc() -> Allocator {
}
assert :: proc(condition: bool, message := "", using location := #caller_location) -> bool #cc_contextless {
assert :: proc "contextless" (condition: bool, message := "", using location := #caller_location) -> bool {
if !condition {
if len(message) > 0 {
fmt.fprintf(os.stderr, "%s(%d:%d) Runtime assertion: %s\n", file_path, line, column, message);
@@ -619,7 +619,7 @@ assert :: proc(condition: bool, message := "", using location := #caller_locatio
return condition;
}
panic :: proc(message := "", using location := #caller_location) #cc_contextless {
panic :: proc "contextless" (message := "", using location := #caller_location) {
if len(message) > 0 {
fmt.fprintf(os.stderr, "%s(%d:%d) Panic: %s\n", file_path, line, column, message);
} else {
@@ -629,7 +629,7 @@ panic :: proc(message := "", using location := #caller_location) #cc_contextless
}
__string_eq :: proc(a, b: string) -> bool #cc_contextless {
__string_eq :: proc "contextless" (a, b: string) -> bool {
switch {
case len(a) != len(b): return false;
case len(a) == 0: return true;
@@ -638,66 +638,66 @@ __string_eq :: proc(a, b: string) -> bool #cc_contextless {
return __string_cmp(a, b) == 0;
}
__string_cmp :: proc(a, b: string) -> int #cc_contextless {
__string_cmp :: proc "contextless" (a, b: string) -> int {
return __mem_compare(&a[0], &b[0], min(len(a), len(b)));
}
__string_ne :: inline proc(a, b: string) -> bool #cc_contextless { return !__string_eq(a, b); }
__string_lt :: inline proc(a, b: string) -> bool #cc_contextless { return __string_cmp(a, b) < 0; }
__string_gt :: inline proc(a, b: string) -> bool #cc_contextless { return __string_cmp(a, b) > 0; }
__string_le :: inline proc(a, b: string) -> bool #cc_contextless { return __string_cmp(a, b) <= 0; }
__string_ge :: inline proc(a, b: string) -> bool #cc_contextless { return __string_cmp(a, b) >= 0; }
__string_ne :: inline proc "contextless" (a, b: string) -> bool { return !__string_eq(a, b); }
__string_lt :: inline proc "contextless" (a, b: string) -> bool { return __string_cmp(a, b) < 0; }
__string_gt :: inline proc "contextless" (a, b: string) -> bool { return __string_cmp(a, b) > 0; }
__string_le :: inline proc "contextless" (a, b: string) -> bool { return __string_cmp(a, b) <= 0; }
__string_ge :: inline proc "contextless" (a, b: string) -> bool { return __string_cmp(a, b) >= 0; }
__complex64_eq :: inline proc (a, b: complex64) -> bool #cc_contextless { return real(a) == real(b) && imag(a) == imag(b); }
__complex64_ne :: inline proc (a, b: complex64) -> bool #cc_contextless { return real(a) != real(b) || imag(a) != imag(b); }
__complex64_eq :: inline proc "contextless" (a, b: complex64) -> bool { return real(a) == real(b) && imag(a) == imag(b); }
__complex64_ne :: inline proc "contextless" (a, b: complex64) -> bool { return real(a) != real(b) || imag(a) != imag(b); }
__complex128_eq :: inline proc(a, b: complex128) -> bool #cc_contextless { return real(a) == real(b) && imag(a) == imag(b); }
__complex128_ne :: inline proc(a, b: complex128) -> bool #cc_contextless { return real(a) != real(b) || imag(a) != imag(b); }
__complex128_eq :: inline proc "contextless" (a, b: complex128) -> bool { return real(a) == real(b) && imag(a) == imag(b); }
__complex128_ne :: inline proc "contextless" (a, b: complex128) -> bool { return real(a) != real(b) || imag(a) != imag(b); }
__bounds_check_error :: proc(file: string, line, column: int, index, count: int) #cc_contextless {
__bounds_check_error :: proc "contextless" (file: string, line, column: int, index, count: int) {
if 0 <= index && index < count do return;
fmt.fprintf(os.stderr, "%s(%d:%d) Index %d is out of bounds range 0..%d\n",
file, line, column, index, count);
__debug_trap();
}
__slice_expr_error :: proc(file: string, line, column: int, low, high, max: int) #cc_contextless {
__slice_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
if 0 <= low && low <= high && high <= max do return;
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid slice indices: [%d..%d..%d]\n",
file, line, column, low, high, max);
__debug_trap();
}
__substring_expr_error :: proc(file: string, line, column: int, low, high: int) #cc_contextless {
__substring_expr_error :: proc "contextless" (file: string, line, column: int, low, high: int) {
if 0 <= low && low <= high do return;
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid substring indices: [%d..%d]\n",
file, line, column, low, high);
__debug_trap();
}
__type_assertion_check :: proc(ok: bool, file: string, line, column: int, from, to: ^Type_Info) #cc_contextless {
__type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: ^Type_Info) {
if ok do return;
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid type_assertion from %T to %T\n",
file, line, column, from, to);
__debug_trap();
}
__string_decode_rune :: inline proc(s: string) -> (rune, int) #cc_contextless {
__string_decode_rune :: inline proc "contextless" (s: string) -> (rune, int) {
return utf8.decode_rune(s);
}
__bounds_check_error_loc :: proc(using loc := #caller_location, index, count: int) #cc_contextless {
__bounds_check_error_loc :: proc "contextless" (using loc := #caller_location, index, count: int) {
__bounds_check_error(file_path, int(line), int(column), index, count);
}
__slice_expr_error_loc :: proc(using loc := #caller_location, low, high, max: int) #cc_contextless {
__slice_expr_error_loc :: proc "contextless" (using loc := #caller_location, low, high, max: int) {
__slice_expr_error(file_path, int(line), int(column), low, high, max);
}
__substring_expr_error_loc :: proc(using loc := #caller_location, low, high: int) #cc_contextless {
__substring_expr_error_loc :: proc "contextless" (using loc := #caller_location, low, high: int) {
__substring_expr_error(file_path, int(line), int(column), low, high);
}
__mem_set :: proc(data: rawptr, value: i32, len: int) -> rawptr #cc_contextless {
__mem_set :: proc "contextless" (data: rawptr, value: i32, len: int) -> rawptr {
if data == nil do return nil;
foreign __llvm_core {
when size_of(rawptr) == 8 {
@@ -711,10 +711,10 @@ __mem_set :: proc(data: rawptr, value: i32, len: int) -> rawptr #cc_contextless
llvm_memset(data, u8(value), len, 1, false);
return data;
}
__mem_zero :: proc(data: rawptr, len: int) -> rawptr #cc_contextless {
__mem_zero :: proc "contextless" (data: rawptr, len: int) -> rawptr {
return __mem_set(data, 0, len);
}
__mem_copy :: proc(dst, src: rawptr, len: int) -> rawptr #cc_contextless {
__mem_copy :: proc "contextless" (dst, src: rawptr, len: int) -> rawptr {
if src == nil do return dst;
// NOTE(bill): This _must_ be implemented like C's memmove
foreign __llvm_core {
@@ -729,7 +729,7 @@ __mem_copy :: proc(dst, src: rawptr, len: int) -> rawptr #cc_contextless {
llvm_memmove(dst, src, len, 1, false);
return dst;
}
__mem_copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr #cc_contextless {
__mem_copy_non_overlapping :: proc "contextless" (dst, src: rawptr, len: int) -> rawptr {
if src == nil do return dst;
// NOTE(bill): This _must_ be implemented like C's memcpy
foreign __llvm_core {
@@ -745,7 +745,7 @@ __mem_copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr #cc_con
return dst;
}
__mem_compare :: proc(a, b: ^u8, n: int) -> int #cc_contextless {
__mem_compare :: proc "contextless" (a, b: ^u8, n: int) -> int {
for i in 0..n do switch {
case (a+i)^ < (b+i)^: return -1;
case (a+i)^ > (b+i)^: return +1;
@@ -769,11 +769,11 @@ foreign __llvm_core {
@(link_name="llvm.fmuladd.f32") fmuladd32 :: proc(a, b, c: f32) -> f32 ---;
@(link_name="llvm.fmuladd.f64") fmuladd64 :: proc(a, b, c: f64) -> f64 ---;
}
__abs_complex64 :: inline proc(x: complex64) -> f32 #cc_contextless {
__abs_complex64 :: inline proc "contextless" (x: complex64) -> f32 {
r, i := real(x), imag(x);
return __sqrt_f32(r*r + i*i);
}
__abs_complex128 :: inline proc(x: complex128) -> f64 #cc_contextless {
__abs_complex128 :: inline proc "contextless" (x: complex128) -> f64 {
r, i := real(x), imag(x);
return __sqrt_f64(r*r + i*i);
}

View File

@@ -1,7 +1,7 @@
#shared_global_scope
@(link_name="__multi3")
__multi3 :: proc(a, b: u128) -> u128 #cc_c {
__multi3 :: proc "c" (a, b: u128) -> u128 {
bits_in_dword_2 :: size_of(i64) * 4;
lower_mask :: u128(~u64(0) >> bits_in_dword_2);
@@ -37,31 +37,31 @@ __multi3 :: proc(a, b: u128) -> u128 #cc_c {
}
@(link_name="__umodti3")
__u128_mod :: proc(a, b: u128) -> u128 #cc_c {
__u128_mod :: proc "c" (a, b: u128) -> u128 {
r: u128;
__u128_quo_mod(a, b, &r);
return r;
}
@(link_name="__udivti3")
__u128_quo :: proc(a, b: u128) -> u128 #cc_c {
__u128_quo :: proc "c" (a, b: u128) -> u128 {
return __u128_quo_mod(a, b, nil);
}
@(link_name="__modti3")
__i128_mod :: proc(a, b: i128) -> i128 #cc_c {
__i128_mod :: proc "c" (a, b: i128) -> i128 {
r: i128;
__i128_quo_mod(a, b, &r);
return r;
}
@(link_name="__divti3")
__i128_quo :: proc(a, b: i128) -> i128 #cc_c {
__i128_quo :: proc "c" (a, b: i128) -> i128 {
return __i128_quo_mod(a, b, nil);
}
@(link_name="__divmodti4")
__i128_quo_mod :: proc(a, b: i128, rem: ^i128) -> (quo: i128) #cc_c {
__i128_quo_mod :: proc "c" (a, b: i128, rem: ^i128) -> (quo: i128) {
s: i128;
s = b >> 127;
b = (b~s) - s;
@@ -81,7 +81,7 @@ __i128_quo_mod :: proc(a, b: i128, rem: ^i128) -> (quo: i128) #cc_c {
@(link_name="__udivmodti4")
__u128_quo_mod :: proc(a, b: u128, rem: ^u128) -> (quo: u128) #cc_c {
__u128_quo_mod :: proc "c" (a, b: u128, rem: ^u128) -> (quo: u128) {
alo := u64(a);
blo := u64(b);
if b == 0 {
@@ -108,130 +108,3 @@ __u128_quo_mod :: proc(a, b: u128, rem: ^u128) -> (quo: u128) #cc_c {
if rem != nil do rem^ = r;
return q;
}
/*
@(link_name="__gnu_h2f_ieee")
__f16_to_f32 :: proc(f: f16) -> f32 #cc_c #no_inline {
when true {
// Source: https://fgiesen.wordpress.com/2012/03/28/half-to-float-done-quic/
FP32 :: struct #raw_union {u: u32, f: f32};
magic, was_infnan: FP32;
magic.u = (254-15) << 23;
was_infnan.u = (127+16) << 23;
hu := transmute(u16, f);
o := FP32{};
o.u = u32(hu & 0x7fff) << 13);
o.f *= magic.f;
if o.f >= was_infnan.f {
o.u |= 255 << 23;
}
o.u |= u32(hu & 0x8000) << 16;
return o.f;
} else {
return 0;
}
}
@(link_name="__gnu_f2h_ieee")
__f32_to_f16 :: proc(f_: f32) -> f16 #cc_c #no_inline {
when false {
// Source: https://gist.github.com/rygorous/2156668
FP16 :: struct #raw_union {u: u16, f: f16};
FP32 :: struct #raw_union {u: u32, f: f32};
f32infty, f16infty, magic: FP32;
f32infty.u = 255<<23;
f16infty.u = 31<<23;
magic.u = 15<<23;
sign_mask :: u32(0x80000000);
round_mask :: ~u32(0x0fff);
f := transmute(FP32, f_);
o: FP16;
sign := f.u & sign_mask;
f.u ~= sign;
// NOTE all the integer compares in this function can be safely
// compiled into signed compares since all operands are below
// 0x80000000. Important if you want fast straight SSE2 code
// (since there's no unsigned PCMPGTD).
if f.u >= f32infty.u { // Inf or NaN (all exponent bits set)
o.u = f.u > f32infty.u ? 0x7e00 : 0x7c00; // NaN->qNaN and Inf->Inf
} else { // (De)normalized number or zero
f.u &= round_mask;
f.f *= magic.f;
f.u -= round_mask;
if f.u > f16infty.u {
f.u = f16infty.u; // Clamp to signed infinity if overflowed
}
o.u = u16(f.u >> 13); // Take the bits!
}
o.u |= u16(sign >> 16);
return o.f;
} else {
f := transmute(u32, f_);
h: u16;
hs, he, hf: u16;
fs := (f >> 31) & 1;
fe := (f >> 23) & 0b1111_1111;
ff := (f >> 0) & 0b0111_1111_1111_1111_1111_1111;
add_one := false;
if (fe == 0) {
he = 0;
} else if (fe == 255) {
he = 31;
hf = ff != 0 ? 0x200 : 0;
} else {
ne := fe - 127 + 15;
if ne >= 31 {
he = 31;
} else if ne <= 0 {
if (14-ne) <= 24 {
mant := ff | 0x800000;
hf = u16(mant >> (14-ne));
if (mant >> (13-ne)) & 1 != 0 {
add_one = true;
}
}
} else {
he = u16(ne);
hf = u16(ff >> 13);
if ff&0x1000 != 0 {
add_one = true;
}
}
}
hs = u16(hs);
h |= (he&0b0001_1111)<<10;
h |= (hf&0b0011_1111_1111);
if add_one {
h++;
}
h |= (hs&1) << 15;
return transmute(f16, h);
}
}
@(link_name="__truncdfhf2")
__f64_to_f16 :: proc(f: f64) -> f16 #cc_c #no_inline {
return __f32_to_f16(f32(f));
}
__f16_to_f64 :: proc(f: f16) -> f64 #cc_c #no_inline {
return f64(__f16_to_f32(f));
}
*/

View File

@@ -22,16 +22,16 @@ I32_MAX :: i32(0x7fff_ffff);
I64_MAX :: i64(0x7fff_ffff_ffff_ffff);
I128_MAX :: i128(0x7fff_ffff_ffff_ffff_ffff_ffff_ffff_ffff);
count_ones :: proc(i: u8) -> u8 { foreign __llvm_core @(link_name="llvm.ctpop.i8") __llvm_ctpop :: proc(u8) -> u8 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: i8) -> i8 { foreign __llvm_core @(link_name="llvm.ctpop.i8") __llvm_ctpop :: proc(i8) -> i8 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: u8) -> u8 { foreign __llvm_core @(link_name="llvm.ctpop.i8") __llvm_ctpop :: proc(u8) -> u8 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: i8) -> i8 { foreign __llvm_core @(link_name="llvm.ctpop.i8") __llvm_ctpop :: proc(i8) -> i8 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: u16) -> u16 { foreign __llvm_core @(link_name="llvm.ctpop.i16") __llvm_ctpop :: proc(u16) -> u16 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: i16) -> i16 { foreign __llvm_core @(link_name="llvm.ctpop.i16") __llvm_ctpop :: proc(i16) -> i16 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: u32) -> u32 { foreign __llvm_core @(link_name="llvm.ctpop.i32") __llvm_ctpop :: proc(u32) -> u32 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: i32) -> i32 { foreign __llvm_core @(link_name="llvm.ctpop.i32") __llvm_ctpop :: proc(i32) -> i32 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: u64) -> u64 { foreign __llvm_core @(link_name="llvm.ctpop.i64") __llvm_ctpop :: proc(u64) -> u64 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: i64) -> i64 { foreign __llvm_core @(link_name="llvm.ctpop.i64") __llvm_ctpop :: proc(i64) -> i64 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: u128) -> u128 { foreign __llvm_core @(link_name="llvm.ctpop.i128") __llvm_ctpop :: proc(u128) -> u128 ---;return __llvm_ctpop(i); }
count_ones :: proc(i: i128) -> i128 { foreign __llvm_core @(link_name="llvm.ctpop.i128") __llvm_ctpop :: proc(i128) -> i128 ---;return __llvm_ctpop(i); }
count_ones :: proc(i: u128) -> u128 { foreign __llvm_core @(link_name="llvm.ctpop.i128") __llvm_ctpop :: proc(u128) -> u128 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: i128) -> i128 { foreign __llvm_core @(link_name="llvm.ctpop.i128") __llvm_ctpop :: proc(i128) -> i128 ---; return __llvm_ctpop(i); }
count_ones :: proc(i: uint) -> uint { when size_of(uint) == size_of(u32) { return uint(count_ones(u32(i))); } else { return uint(count_ones(u64(i))); } }
count_ones :: proc(i: int) -> int { when size_of(int) == size_of(i32) { return int(count_ones(i32(i))); } else { return int(count_ones(i64(i))); } }

View File

@@ -6,35 +6,35 @@ foreign __llvm_core {
@(link_name = "llvm.bswap.i64") swap :: proc(b: u64) -> u64 ---;
}
set :: proc(data: rawptr, value: i32, len: int) -> rawptr #cc_contextless {
set :: proc "contextless" (data: rawptr, value: i32, len: int) -> rawptr {
return __mem_set(data, value, len);
}
zero :: proc(data: rawptr, len: int) -> rawptr #cc_contextless {
zero :: proc "contextless" (data: rawptr, len: int) -> rawptr {
return __mem_zero(data, len);
}
copy :: proc(dst, src: rawptr, len: int) -> rawptr #cc_contextless {
copy :: proc "contextless" (dst, src: rawptr, len: int) -> rawptr {
return __mem_copy(dst, src, len);
}
copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr #cc_contextless {
copy_non_overlapping :: proc "contextless" (dst, src: rawptr, len: int) -> rawptr {
return __mem_copy_non_overlapping(dst, src, len);
}
compare :: proc(a, b: []u8) -> int #cc_contextless {
compare :: proc "contextless" (a, b: []u8) -> int {
return __mem_compare(&a[0], &b[0], min(len(a), len(b)));
}
slice_ptr :: proc(ptr: ^$T, len: int) -> []T #cc_contextless {
slice_ptr :: proc "contextless" (ptr: ^$T, len: int) -> []T {
assert(len >= 0);
slice := raw.Slice{data = ptr, len = len, cap = len};
return (cast(^[]T)&slice)^;
}
slice_ptr :: proc(ptr: ^$T, len, cap: int) -> []T #cc_contextless {
slice_ptr :: proc "contextless" (ptr: ^$T, len, cap: int) -> []T {
assert(0 <= len && len <= cap);
slice := raw.Slice{data = ptr, len = len, cap = cap};
return (cast(^[]T)&slice)^;
}
slice_to_bytes :: proc(slice: []$T) -> []u8 #cc_contextless {
slice_to_bytes :: proc "contextless" (slice: []$T) -> []u8 {
s := cast(^raw.Slice)&slice;
s.len *= size_of(T);
s.cap *= size_of(T);
@@ -42,10 +42,10 @@ slice_to_bytes :: proc(slice: []$T) -> []u8 #cc_contextless {
}
kilobytes :: inline proc(x: int) -> int #cc_contextless do return (x) * 1024;
megabytes :: inline proc(x: int) -> int #cc_contextless do return kilobytes(x) * 1024;
gigabytes :: inline proc(x: int) -> int #cc_contextless do return megabytes(x) * 1024;
terabytes :: inline proc(x: int) -> int #cc_contextless do return gigabytes(x) * 1024;
kilobytes :: inline proc "contextless" (x: int) -> int do return (x) * 1024;
megabytes :: inline proc "contextless" (x: int) -> int do return kilobytes(x) * 1024;
gigabytes :: inline proc "contextless" (x: int) -> int do return megabytes(x) * 1024;
terabytes :: inline proc "contextless" (x: int) -> int do return gigabytes(x) * 1024;
is_power_of_two :: proc(x: uintptr) -> bool {
if x <= 0 do return false;

View File

@@ -57,65 +57,65 @@ get_proc_address :: proc(name: string) -> rawptr {
}
// Procedures
GenBuffers: proc(count: i32, buffers: ^u32) #cc_c;
GenVertexArrays: proc(count: i32, buffers: ^u32) #cc_c;
GenSamplers: proc(count: i32, buffers: ^u32) #cc_c;
DeleteBuffers: proc(count: i32, buffers: ^u32) #cc_c;
BindBuffer: proc(target: i32, buffer: u32) #cc_c;
BindVertexArray: proc(buffer: u32) #cc_c;
DeleteVertexArrays: proc(count: i32, arrays: ^u32) #cc_c;
BindSampler: proc(position: i32, sampler: u32) #cc_c;
BufferData: proc(target: i32, size: int, data: rawptr, usage: i32) #cc_c;
BufferSubData: proc(target: i32, offset, size: int, data: rawptr) #cc_c;
GenBuffers: proc "c" (count: i32, buffers: ^u32);
GenVertexArrays: proc "c" (count: i32, buffers: ^u32);
GenSamplers: proc "c" (count: i32, buffers: ^u32);
DeleteBuffers: proc "c" (count: i32, buffers: ^u32);
BindBuffer: proc "c" (target: i32, buffer: u32);
BindVertexArray: proc "c" (buffer: u32);
DeleteVertexArrays: proc "c" (count: i32, arrays: ^u32);
BindSampler: proc "c" (position: i32, sampler: u32);
BufferData: proc "c" (target: i32, size: int, data: rawptr, usage: i32);
BufferSubData: proc "c" (target: i32, offset, size: int, data: rawptr);
DrawArrays: proc(mode, first: i32, count: u32) #cc_c;
DrawElements: proc(mode: i32, count: u32, type_: i32, indices: rawptr) #cc_c;
DrawArrays: proc "c" (mode, first: i32, count: u32);
DrawElements: proc "c" (mode: i32, count: u32, type_: i32, indices: rawptr);
MapBuffer: proc(target, access: i32) -> rawptr #cc_c;
UnmapBuffer: proc(target: i32) #cc_c;
MapBuffer: proc "c" (target, access: i32) -> rawptr;
UnmapBuffer: proc "c" (target: i32);
VertexAttribPointer: proc(index: u32, size, type_: i32, normalized: i32, stride: u32, pointer: rawptr) #cc_c;
EnableVertexAttribArray: proc(index: u32) #cc_c;
VertexAttribPointer: proc "c" (index: u32, size, type_: i32, normalized: i32, stride: u32, pointer: rawptr);
EnableVertexAttribArray: proc "c" (index: u32);
CreateShader: proc(shader_type: i32) -> u32 #cc_c;
ShaderSource: proc(shader: u32, count: u32, str: ^^u8, length: ^i32) #cc_c;
CompileShader: proc(shader: u32) #cc_c;
CreateProgram: proc() -> u32 #cc_c;
AttachShader: proc(program, shader: u32) #cc_c;
DetachShader: proc(program, shader: u32) #cc_c;
DeleteShader: proc(shader: u32) #cc_c;
LinkProgram: proc(program: u32) #cc_c;
UseProgram: proc(program: u32) #cc_c;
DeleteProgram: proc(program: u32) #cc_c;
CreateShader: proc "c" (shader_type: i32) -> u32;
ShaderSource: proc "c" (shader: u32, count: u32, str: ^^u8, length: ^i32);
CompileShader: proc "c" (shader: u32);
CreateProgram: proc "c" () -> u32;
AttachShader: proc "c" (program, shader: u32);
DetachShader: proc "c" (program, shader: u32);
DeleteShader: proc "c" (shader: u32);
LinkProgram: proc "c" (program: u32);
UseProgram: proc "c" (program: u32);
DeleteProgram: proc "c" (program: u32);
GetShaderiv: proc(shader: u32, pname: i32, params: ^i32) #cc_c;
GetProgramiv: proc(program: u32, pname: i32, params: ^i32) #cc_c;
GetShaderInfoLog: proc(shader: u32, max_length: u32, length: ^u32, info_long: ^u8) #cc_c;
GetProgramInfoLog: proc(program: u32, max_length: u32, length: ^u32, info_long: ^u8) #cc_c;
GetShaderiv: proc "c" (shader: u32, pname: i32, params: ^i32);
GetProgramiv: proc "c" (program: u32, pname: i32, params: ^i32);
GetShaderInfoLog: proc "c" (shader: u32, max_length: u32, length: ^u32, info_long: ^u8);
GetProgramInfoLog: proc "c" (program: u32, max_length: u32, length: ^u32, info_long: ^u8);
ActiveTexture: proc(texture: i32) #cc_c;
GenerateMipmap: proc(target: i32) #cc_c;
ActiveTexture: proc "c" (texture: i32);
GenerateMipmap: proc "c" (target: i32);
SamplerParameteri: proc(sampler: u32, pname: i32, param: i32) #cc_c;
SamplerParameterf: proc(sampler: u32, pname: i32, param: f32) #cc_c;
SamplerParameteriv: proc(sampler: u32, pname: i32, params: ^i32) #cc_c;
SamplerParameterfv: proc(sampler: u32, pname: i32, params: ^f32) #cc_c;
SamplerParameterIiv: proc(sampler: u32, pname: i32, params: ^i32) #cc_c;
SamplerParameterIuiv: proc(sampler: u32, pname: i32, params: ^u32) #cc_c;
SamplerParameteri: proc "c" (sampler: u32, pname: i32, param: i32);
SamplerParameterf: proc "c" (sampler: u32, pname: i32, param: f32);
SamplerParameteriv: proc "c" (sampler: u32, pname: i32, params: ^i32);
SamplerParameterfv: proc "c" (sampler: u32, pname: i32, params: ^f32);
SamplerParameterIiv: proc "c" (sampler: u32, pname: i32, params: ^i32);
SamplerParameterIuiv: proc "c" (sampler: u32, pname: i32, params: ^u32);
Uniform1i: proc(loc: i32, v0: i32) #cc_c;
Uniform2i: proc(loc: i32, v0, v1: i32) #cc_c;
Uniform3i: proc(loc: i32, v0, v1, v2: i32) #cc_c;
Uniform4i: proc(loc: i32, v0, v1, v2, v3: i32) #cc_c;
Uniform1f: proc(loc: i32, v0: f32) #cc_c;
Uniform2f: proc(loc: i32, v0, v1: f32) #cc_c;
Uniform3f: proc(loc: i32, v0, v1, v2: f32) #cc_c;
Uniform4f: proc(loc: i32, v0, v1, v2, v3: f32) #cc_c;
UniformMatrix4fv: proc(loc: i32, count: u32, transpose: i32, value: ^f32) #cc_c;
Uniform1i: proc "c" (loc: i32, v0: i32);
Uniform2i: proc "c" (loc: i32, v0, v1: i32);
Uniform3i: proc "c" (loc: i32, v0, v1, v2: i32);
Uniform4i: proc "c" (loc: i32, v0, v1, v2, v3: i32);
Uniform1f: proc "c" (loc: i32, v0: f32);
Uniform2f: proc "c" (loc: i32, v0, v1: f32);
Uniform3f: proc "c" (loc: i32, v0, v1, v2: f32);
Uniform4f: proc "c" (loc: i32, v0, v1, v2, v3: f32);
UniformMatrix4fv: proc "c" (loc: i32, count: u32, transpose: i32, value: ^f32);
GetUniformLocation: proc(program: u32, name: ^u8) -> i32 #cc_c;
GetUniformLocation: proc "c" (program: u32, name: ^u8) -> i32;
init :: proc() {

View File

@@ -252,7 +252,7 @@ dlopen :: inline proc(filename: string, flags: int) -> rawptr {
free(cstr);
return handle;
}
dlsym :: inline proc(handle: rawptr, symbol: string) -> (proc() #cc_c) {
dlsym :: inline proc(handle: rawptr, symbol: string) -> rawptr {
assert(handle != nil);
cstr := strings.new_c_string(symbol);
proc_handle := _unix_dlsym(handle, cstr);

View File

@@ -142,7 +142,7 @@ foreign libc {
foreign dl {
@(link_name="dlopen") _unix_dlopen :: proc(filename: ^u8, flags: int) -> rawptr ---;
@(link_name="dlsym") _unix_dlsym :: proc(handle: rawptr, symbol: ^u8) -> (proc() #cc_c) ---;
@(link_name="dlsym") _unix_dlsym :: proc(handle: rawptr, symbol: ^u8) -> rawptr ---;
@(link_name="dlclose") _unix_dlclose :: proc(handle: rawptr) -> int ---;
@(link_name="dlerror") _unix_dlerror :: proc() -> ^u8 ---;
}

View File

@@ -52,10 +52,10 @@ Glyph_Metrics_Float :: struct {
cell_inc_y: f32,
}
Create_Context_Attribs_ARB_Type :: #type proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc;
Choose_Pixel_Format_ARB_Type :: #type proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c;
Swap_Interval_EXT_Type :: #type proc(interval: i32) -> bool #cc_c;
Get_Extensions_String_ARB_Type :: #type proc(Hdc) -> ^u8 #cc_c;
Create_Context_Attribs_ARB_Type :: #type proc "c" (hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc;
Choose_Pixel_Format_ARB_Type :: #type proc "c" (hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool;
Swap_Interval_EXT_Type :: #type proc "c" (interval: i32) -> bool;
Get_Extensions_String_ARB_Type :: #type proc "c" (Hdc) -> ^u8;
// Procedures
create_context_attribs_arb: Create_Context_Attribs_ARB_Type;

View File

@@ -22,7 +22,7 @@ HKL :: Handle;
Wparam :: uint;
Lparam :: int;
Lresult :: int;
Wnd_Proc :: #type proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c;
Wnd_Proc :: #type proc "c" (Hwnd, u32, Wparam, Lparam) -> Lresult;
Long_Ptr :: int;
@@ -433,217 +433,220 @@ GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS : 1;
foreign kernel32 {
@(link_name="GetLastError") get_last_error :: proc() -> i32 #cc_std ---;
@(link_name="ExitProcess") exit_process :: proc(exit_code: u32) #cc_std ---;
@(link_name="GetModuleHandleA") get_module_handle_a :: proc(module_name: ^u8) -> Hinstance #cc_std ---;
@(link_name="GetModuleHandleW") get_module_handle_w :: proc(module_name: ^u16) -> Hinstance #cc_std ---;
@(link_name="Sleep") sleep :: proc(ms: i32) -> i32 #cc_std ---;
@(link_name="QueryPerformanceFrequency") query_performance_frequency :: proc(result: ^i64) -> i32 #cc_std ---;
@(link_name="QueryPerformanceCounter") query_performance_counter :: proc(result: ^i64) -> i32 #cc_std ---;
@(link_name="OutputDebugStringA") output_debug_string_a :: proc(c_str: ^u8) #cc_std ---;
@(link_name="GetLastError") get_last_error :: proc "std" () -> i32 ---;
@(link_name="ExitProcess") exit_process :: proc "std" (exit_code: u32) ---;
@(link_name="GetModuleHandleA") get_module_handle_a :: proc "std" (module_name: ^u8) -> Hinstance ---;
@(link_name="GetModuleHandleW") get_module_handle_w :: proc "std" (module_name: ^u16) -> Hinstance ---;
@(link_name="Sleep") sleep :: proc "std" (ms: i32) -> i32 ---;
@(link_name="QueryPerformanceFrequency") query_performance_frequency :: proc "std" (result: ^i64) -> i32 ---;
@(link_name="QueryPerformanceCounter") query_performance_counter :: proc "std" (result: ^i64) -> i32 ---;
@(link_name="OutputDebugStringA") output_debug_string_a :: proc "std" (c_str: ^u8) ---;
@(link_name="GetCommandLineA") get_command_line_a :: proc() -> ^u8 #cc_std ---;
@(link_name="GetCommandLineW") get_command_line_w :: proc() -> ^u16 #cc_std ---;
@(link_name="GetSystemMetrics") get_system_metrics :: proc(index: i32) -> i32 #cc_std ---;
@(link_name="GetCurrentThreadId") get_current_thread_id :: proc() -> u32 #cc_std ---;
@(link_name="GetCommandLineA") get_command_line_a :: proc "std" () -> ^u8 ---;
@(link_name="GetCommandLineW") get_command_line_w :: proc "std" () -> ^u16 ---;
@(link_name="GetSystemMetrics") get_system_metrics :: proc "std" (index: i32) -> i32 ---;
@(link_name="GetCurrentThreadId") get_current_thread_id :: proc "std" () -> u32 ---;
@(link_name="GetSystemTimeAsFileTime") get_system_time_as_file_time :: proc(system_time_as_file_time: ^Filetime) #cc_std ---;
@(link_name="FileTimeToLocalFileTime") file_time_to_local_file_time :: proc(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool #cc_std ---;
@(link_name="FileTimeToSystemTime") file_time_to_system_time :: proc(file_time: ^Filetime, system_time: ^Systemtime) -> Bool #cc_std ---;
@(link_name="SystemTimeToFileTime") system_time_to_file_time :: proc(system_time: ^Systemtime, file_time: ^Filetime) -> Bool #cc_std ---;
@(link_name="GetSystemTimeAsFileTime") get_system_time_as_file_time :: proc "std" (system_time_as_file_time: ^Filetime) ---;
@(link_name="FileTimeToLocalFileTime") file_time_to_local_file_time :: proc "std" (file_time: ^Filetime, local_file_time: ^Filetime) -> Bool ---;
@(link_name="FileTimeToSystemTime") file_time_to_system_time :: proc "std" (file_time: ^Filetime, system_time: ^Systemtime) -> Bool ---;
@(link_name="SystemTimeToFileTime") system_time_to_file_time :: proc "std" (system_time: ^Systemtime, file_time: ^Filetime) -> Bool ---;
@(link_name="CloseHandle") close_handle :: proc(h: Handle) -> i32 #cc_std ---;
@(link_name="GetStdHandle") get_std_handle :: proc(h: i32) -> Handle #cc_std ---;
@(link_name="CloseHandle") close_handle :: proc "std" (h: Handle) -> i32 ---;
@(link_name="GetStdHandle") get_std_handle :: proc "std" (h: i32) -> Handle ---;
@(link_name="CreateFileA")
create_file_a :: proc(filename: ^u8, desired_access, share_mode: u32,
security: rawptr,
creation, flags_and_attribs: u32, template_file: Handle) -> Handle #cc_std ---;
create_file_a :: proc "std" (filename: ^u8, desired_access, share_module: u32,
security: rawptr,
creation, flags_and_attribs: u32, template_file: Handle) -> Handle ---;
@(link_name="ReadFile") read_file :: proc(h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> Bool #cc_std ---;
@(link_name="WriteFile") write_file :: proc(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool #cc_std ---;
@(link_name="ReadFile") read_file :: proc "std" (h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> Bool ---;
@(link_name="WriteFile") write_file :: proc "std" (h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool ---;
@(link_name="GetFileSizeEx") get_file_size_ex :: proc(file_handle: Handle, file_size: ^i64) -> Bool #cc_std ---;
@(link_name="GetFileAttributesA") get_file_attributes_a :: proc(filename: ^u8) -> u32 #cc_std ---;
@(link_name="GetFileAttributesExA") get_file_attributes_ex_a :: proc(filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #cc_std ---;
@(link_name="GetFileInformationByHandle") get_file_information_by_handle :: proc(file_handle: Handle, file_info: ^By_Handle_File_Information) -> Bool #cc_std ---;
@(link_name="GetFileSizeEx") get_file_size_ex :: proc "std" (file_handle: Handle, file_size: ^i64) -> Bool ---;
@(link_name="GetFileAttributesA") get_file_attributes_a :: proc "std" (filename: ^u8) -> u32 ---;
@(link_name="GetFileAttributesExA") get_file_attributes_ex_a :: proc "std" (filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool ---;
@(link_name="GetFileInformationByHandle") get_file_information_by_handle :: proc "std" (file_handle: Handle, file_info: ^By_Handle_File_Information) -> Bool ---;
@(link_name="GetFileType") get_file_type :: proc(file_handle: Handle) -> u32 #cc_std ---;
@(link_name="SetFilePointer") set_file_pointer :: proc(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 #cc_std ---;
@(link_name="GetFileType") get_file_type :: proc "std" (file_handle: Handle) -> u32 ---;
@(link_name="SetFilePointer") set_file_pointer :: proc "std" (file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 ---;
@(link_name="SetHandleInformation") set_handle_information :: proc(obj: Handle, mask, flags: u32) -> Bool #cc_std ---;
@(link_name="SetHandleInformation") set_handle_information :: proc "std" (obj: Handle, mask, flags: u32) -> Bool ---;
@(link_name="FindFirstFileA") find_first_file_a :: proc(file_name : ^u8, data : ^Find_Data) -> Handle #cc_std ---;
@(link_name="FindNextFileA") find_next_file_a :: proc(file : Handle, data : ^Find_Data) -> Bool #cc_std ---;
@(link_name="FindClose") find_close :: proc(file : Handle) -> Bool #cc_std ---;
@(link_name="FindFirstFileA") find_first_file_a :: proc "std" (file_name : ^u8, data : ^Find_Data) -> Handle ---;
@(link_name="FindNextFileA") find_next_file_a :: proc "std" (file : Handle, data : ^Find_Data) -> Bool ---;
@(link_name="FindClose") find_close :: proc "std" (file : Handle) -> Bool ---;
@(link_name="HeapAlloc") heap_alloc :: proc(h: Handle, flags: u32, bytes: int) -> rawptr #cc_std ---;
@(link_name="HeapReAlloc") heap_realloc :: proc(h: Handle, flags: u32, memory: rawptr, bytes: int) -> rawptr #cc_std ---;
@(link_name="HeapFree") heap_free :: proc(h: Handle, flags: u32, memory: rawptr) -> Bool #cc_std ---;
@(link_name="GetProcessHeap") get_process_heap :: proc() -> Handle #cc_std ---;
@(link_name="HeapAlloc") heap_alloc :: proc "std" (h: Handle, flags: u32, bytes: int) -> rawptr ---;
@(link_name="HeapReAlloc") heap_realloc :: proc "std" (h: Handle, flags: u32, memory: rawptr, bytes: int) -> rawptr ---;
@(link_name="HeapFree") heap_free :: proc "std" (h: Handle, flags: u32, memory: rawptr) -> Bool ---;
@(link_name="GetProcessHeap") get_process_heap :: proc "std" () -> Handle ---;
@(link_name="CreateSemaphoreA") create_semaphore_a :: proc(attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^u8) -> Handle #cc_std ---;
@(link_name="ReleaseSemaphore") release_semaphore :: proc(semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool #cc_std ---;
@(link_name="WaitForSingleObject") wait_for_single_object :: proc(handle: Handle, milliseconds: u32) -> u32 #cc_std ---;
@(link_name="CreateSemaphoreA") create_semaphore_a :: proc "std" (attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^u8) -> Handle ---;
@(link_name="ReleaseSemaphore") release_semaphore :: proc "std" (semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool ---;
@(link_name="WaitForSingleObject") wait_for_single_object :: proc "std" (handle: Handle, milliseconds: u32) -> u32 ---;
}
foreign kernel32 {
@(link_name="InterlockedCompareExchange") interlocked_compare_exchange :: proc "c" (dst: ^i32, exchange, comparand: i32) -> i32 ---;
@(link_name="InterlockedExchange") interlocked_exchange :: proc "c" (dst: ^i32, desired: i32) -> i32 ---;
@(link_name="InterlockedExchangeAdd") interlocked_exchange_add :: proc "c" (dst: ^i32, desired: i32) -> i32 ---;
@(link_name="InterlockedAnd") interlocked_and :: proc "c" (dst: ^i32, desired: i32) -> i32 ---;
@(link_name="InterlockedOr") interlocked_or :: proc "c" (dst: ^i32, desired: i32) -> i32 ---;
@(link_name="InterlockedCompareExchange") interlocked_compare_exchange :: proc(dst: ^i32, exchange, comparand: i32) -> i32 #cc_c ---;
@(link_name="InterlockedExchange") interlocked_exchange :: proc(dst: ^i32, desired: i32) -> i32 #cc_c ---;
@(link_name="InterlockedExchangeAdd") interlocked_exchange_add :: proc(dst: ^i32, desired: i32) -> i32 #cc_c ---;
@(link_name="InterlockedAnd") interlocked_and :: proc(dst: ^i32, desired: i32) -> i32 #cc_c ---;
@(link_name="InterlockedOr") interlocked_or :: proc(dst: ^i32, desired: i32) -> i32 #cc_c ---;
@(link_name="InterlockedCompareExchange64") interlocked_compare_exchange64 :: proc "c" (dst: ^i64, exchange, comparand: i64) -> i64 ---;
@(link_name="InterlockedExchange64") interlocked_exchange64 :: proc "c" (dst: ^i64, desired: i64) -> i64 ---;
@(link_name="InterlockedExchangeAdd64") interlocked_exchange_add64 :: proc "c" (dst: ^i64, desired: i64) -> i64 ---;
@(link_name="InterlockedAnd64") interlocked_and64 :: proc "c" (dst: ^i64, desired: i64) -> i64 ---;
@(link_name="InterlockedOr64") interlocked_or64 :: proc "c" (dst: ^i64, desired: i64) -> i64 ---;
}
@(link_name="InterlockedCompareExchange64") interlocked_compare_exchange64 :: proc(dst: ^i64, exchange, comparand: i64) -> i64 #cc_c ---;
@(link_name="InterlockedExchange64") interlocked_exchange64 :: proc(dst: ^i64, desired: i64) -> i64 #cc_c ---;
@(link_name="InterlockedExchangeAdd64") interlocked_exchange_add64 :: proc(dst: ^i64, desired: i64) -> i64 #cc_c ---;
@(link_name="InterlockedAnd64") interlocked_and64 :: proc(dst: ^i64, desired: i64) -> i64 #cc_c ---;
@(link_name="InterlockedOr64") interlocked_or64 :: proc(dst: ^i64, desired: i64) -> i64 #cc_c ---;
@(link_name="_mm_pause") mm_pause :: proc() #cc_std ---;
@(link_name="ReadWriteBarrier") read_write_barrier :: proc() #cc_std ---;
@(link_name="WriteBarrier") write_barrier :: proc() #cc_std ---;
@(link_name="ReadBarrier") read_barrier :: proc() #cc_std ---;
foreign kernel32 {
@(link_name="_mm_pause") mm_pause :: proc "std" () ---;
@(link_name="ReadWriteBarrier") read_write_barrier :: proc "std" () ---;
@(link_name="WriteBarrier") write_barrier :: proc "std" () ---;
@(link_name="ReadBarrier") read_barrier :: proc "std" () ---;
@(link_name="CreateThread")
create_thread :: proc(thread_attributes: ^Security_Attributes, stack_size: int, start_routine: rawptr,
parameter: rawptr, creation_flags: u32, thread_id: ^u32) -> Handle #cc_std ---;
@(link_name="ResumeThread") resume_thread :: proc(thread: Handle) -> u32 #cc_std ---;
@(link_name="GetThreadPriority") get_thread_priority :: proc(thread: Handle) -> i32 #cc_std ---;
@(link_name="SetThreadPriority") set_thread_priority :: proc(thread: Handle, priority: i32) -> Bool #cc_std ---;
@(link_name="GetExitCodeThread") get_exit_code_thread :: proc(thread: Handle, exit_code: ^u32) -> Bool #cc_std ---;
create_thread :: proc "std" (thread_attributes: ^Security_Attributes, stack_size: int, start_routine: rawptr,
parameter: rawptr, creation_flags: u32, thread_id: ^u32) -> Handle ---;
@(link_name="ResumeThread") resume_thread :: proc "std" (thread: Handle) -> u32 ---;
@(link_name="GetThreadPriority") get_thread_priority :: proc "std" (thread: Handle) -> i32 ---;
@(link_name="SetThreadPriority") set_thread_priority :: proc "std" (thread: Handle, priority: i32) -> Bool ---;
@(link_name="GetExitCodeThread") get_exit_code_thread :: proc "std" (thread: Handle, exit_code: ^u32) -> Bool ---;
@(link_name="InitializeCriticalSection") initialize_critical_section :: proc(critical_section: ^Critical_Section) #cc_std ---;
@(link_name="InitializeCriticalSectionAndSpinCount") initialize_critical_section_and_spin_count :: proc(critical_section: ^Critical_Section, spin_count: u32) #cc_std ---;
@(link_name="DeleteCriticalSection") delete_critical_section :: proc(critical_section: ^Critical_Section) #cc_std ---;
@(link_name="SetCriticalSectionSpinCount") set_critical_section_spin_count :: proc(critical_section: ^Critical_Section, spin_count: u32) -> u32 #cc_std ---;
@(link_name="TryEnterCriticalSection") try_enter_critical_section :: proc(critical_section: ^Critical_Section) -> Bool #cc_std ---;
@(link_name="EnterCriticalSection") enter_critical_section :: proc(critical_section: ^Critical_Section) #cc_std ---;
@(link_name="LeaveCriticalSection") leave_critical_section :: proc(critical_section: ^Critical_Section) #cc_std ---;
@(link_name="InitializeCriticalSection") initialize_critical_section :: proc "std" (critical_section: ^Critical_Section) ---;
@(link_name="InitializeCriticalSectionAndSpinCount") initialize_critical_section_and_spin_count :: proc "std" (critical_section: ^Critical_Section, spin_count: u32) ---;
@(link_name="DeleteCriticalSection") delete_critical_section :: proc "std" (critical_section: ^Critical_Section) ---;
@(link_name="SetCriticalSectionSpinCount") set_critical_section_spin_count :: proc "std" (critical_section: ^Critical_Section, spin_count: u32) -> u32 ---;
@(link_name="TryEnterCriticalSection") try_enter_critical_section :: proc "std" (critical_section: ^Critical_Section) -> Bool ---;
@(link_name="EnterCriticalSection") enter_critical_section :: proc "std" (critical_section: ^Critical_Section) ---;
@(link_name="LeaveCriticalSection") leave_critical_section :: proc "std" (critical_section: ^Critical_Section) ---;
@(link_name="CreateEventA") create_event_a :: proc(event_attributes: ^Security_Attributes, manual_reset, initial_state: Bool, name: ^u8) -> Handle #cc_std ---;
@(link_name="CreateEventA") create_event_a :: proc "std" (event_attributes: ^Security_Attributes, manual_reset, initial_state: Bool, name: ^u8) -> Handle ---;
@(link_name="LoadLibraryA") load_library_a :: proc(c_str: ^u8) -> Hmodule #cc_std ---;
@(link_name="LoadLibraryW") load_library_a :: proc(c_str: ^u16) -> Hmodule #cc_std ---;
@(link_name="FreeLibrary") free_library :: proc(h: Hmodule) #cc_std ---;
@(link_name="GetProcAddress") get_proc_address :: proc(h: Hmodule, c_str: ^u8) -> rawptr #cc_std ---;
@(link_name="LoadLibraryA") load_library_a :: proc "std" (c_str: ^u8) -> Hmodule ---;
@(link_name="LoadLibraryW") load_library_a :: proc "std" (c_str: ^u16) -> Hmodule ---;
@(link_name="FreeLibrary") free_library :: proc "std" (h: Hmodule) ---;
@(link_name="GetProcAddress") get_proc_address :: proc "std" (h: Hmodule, c_str: ^u8) -> rawptr ---;
}
foreign user32 {
@(link_name="GetDesktopWindow") get_desktop_window :: proc() -> Hwnd #cc_std ---;
@(link_name="ShowCursor") show_cursor :: proc(show : Bool) #cc_std ---;
@(link_name="GetCursorPos") get_cursor_pos :: proc(p: ^Point) -> Bool #cc_std ---;
@(link_name="SetCursorPos") set_cursor_pos :: proc(x, y: i32) -> Bool #cc_std ---;
@(link_name="ScreenToClient") screen_to_client :: proc(h: Hwnd, p: ^Point) -> Bool #cc_std ---;
@(link_name="ClientToScreen") client_to_screen :: proc(h: Hwnd, p: ^Point) -> Bool #cc_std ---;
@(link_name="PostQuitMessage") post_quit_message :: proc(exit_code: i32) #cc_std ---;
@(link_name="SetWindowTextA") set_window_text_a :: proc(hwnd: Hwnd, c_string: ^u8) -> Bool #cc_std ---;
@(link_name="RegisterClassExA") register_class_ex_a :: proc(wc: ^Wnd_Class_Ex_A) -> i16 #cc_std ---;
@(link_name="RegisterClassExW") register_class_ex_w :: proc(wc: ^Wnd_Class_Ex_W) -> i16 #cc_std ---;
@(link_name="GetDesktopWindow") get_desktop_window :: proc "std" () -> Hwnd ---;
@(link_name="ShowCursor") show_cursor :: proc "std" (show : Bool) ---;
@(link_name="GetCursorPos") get_cursor_pos :: proc "std" (p: ^Point) -> Bool ---;
@(link_name="SetCursorPos") set_cursor_pos :: proc "std" (x, y: i32) -> Bool ---;
@(link_name="ScreenToClient") screen_to_client :: proc "std" (h: Hwnd, p: ^Point) -> Bool ---;
@(link_name="ClientToScreen") client_to_screen :: proc "std" (h: Hwnd, p: ^Point) -> Bool ---;
@(link_name="PostQuitMessage") post_quit_message :: proc "std" (exit_code: i32) ---;
@(link_name="SetWindowTextA") set_window_text_a :: proc "std" (hwnd: Hwnd, c_string: ^u8) -> Bool ---;
@(link_name="RegisterClassExA") register_class_ex_a :: proc "std" (wc: ^Wnd_Class_Ex_A) -> i16 ---;
@(link_name="RegisterClassExW") register_class_ex_w :: proc "std" (wc: ^Wnd_Class_Ex_W) -> i16 ---;
@(link_name="CreateWindowExA")
create_window_ex_a :: proc(ex_style: u32,
class_name, title: ^u8,
style: u32,
x, y, w, h: i32,
parent: Hwnd, menu: Hmenu, instance: Hinstance,
param: rawptr) -> Hwnd #cc_std ---;
create_window_ex_a :: proc "std" (ex_style: u32,
class_name, title: ^u8,
style: u32,
x, y, w, h: i32,
parent: Hwnd, menu: Hmenu, instance: Hinstance,
param: rawptr) -> Hwnd ---;
@(link_name="CreateWindowExW")
create_window_ex_w :: proc(ex_style: u32,
class_name, title: ^u16,
style: u32,
x, y, w, h: i32,
parent: Hwnd, menu: Hmenu, instance: Hinstance,
param: rawptr) -> Hwnd #cc_std ---;
create_window_ex_w :: proc "std" (ex_style: u32,
class_name, title: ^u16,
style: u32,
x, y, w, h: i32,
parent: Hwnd, menu: Hmenu, instance: Hinstance,
param: rawptr) -> Hwnd ---;
@(link_name="ShowWindow") show_window :: proc(hwnd: Hwnd, cmd_show: i32) -> Bool #cc_std ---;
@(link_name="TranslateMessage") translate_message :: proc(msg: ^Msg) -> Bool #cc_std ---;
@(link_name="DispatchMessageA") dispatch_message_a :: proc(msg: ^Msg) -> Lresult #cc_std ---;
@(link_name="DispatchMessageW") dispatch_message_w :: proc(msg: ^Msg) -> Lresult #cc_std ---;
@(link_name="UpdateWindow") update_window :: proc(hwnd: Hwnd) -> Bool #cc_std ---;
@(link_name="GetMessageA") get_message_a :: proc(msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max : u32) -> Bool #cc_std ---;
@(link_name="GetMessageW") get_message_w :: proc(msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max : u32) -> Bool #cc_std ---;
@(link_name="ShowWindow") show_window :: proc "std" (hwnd: Hwnd, cmd_show: i32) -> Bool ---;
@(link_name="TranslateMessage") translate_message :: proc "std" (msg: ^Msg) -> Bool ---;
@(link_name="DispatchMessageA") dispatch_message_a :: proc "std" (msg: ^Msg) -> Lresult ---;
@(link_name="DispatchMessageW") dispatch_message_w :: proc "std" (msg: ^Msg) -> Lresult ---;
@(link_name="UpdateWindow") update_window :: proc "std" (hwnd: Hwnd) -> Bool ---;
@(link_name="GetMessageA") get_message_a :: proc "std" (msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max : u32) -> Bool ---;
@(link_name="GetMessageW") get_message_w :: proc "std" (msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max : u32) -> Bool ---;
@(link_name="PeekMessageA") peek_message_a :: proc(msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool #cc_std ---;
@(link_name="PeekMessageW") peek_message_w :: proc(msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool #cc_std ---;
@(link_name="PeekMessageA") peek_message_a :: proc "std" (msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool ---;
@(link_name="PeekMessageW") peek_message_w :: proc "std" (msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool ---;
@(link_name="PostMessageA") post_message :: proc(hwnd: Hwnd, msg, wparam, lparam : u32) -> Bool #cc_std ---;
@(link_name="PostMessageA") post_message :: proc "std" (hwnd: Hwnd, msg, wparam, lparam : u32) -> Bool ---;
@(link_name="DefWindowProcA") def_window_proc_a :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult #cc_std ---;
@(link_name="DefWindowProcA") def_window_proc_a :: proc "std" (hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult ---;
@(link_name="AdjustWindowRect") adjust_window_rect :: proc(rect: ^Rect, style: u32, menu: Bool) -> Bool #cc_std ---;
@(link_name="GetActiveWindow") get_active_window :: proc() -> Hwnd #cc_std ---;
@(link_name="AdjustWindowRect") adjust_window_rect :: proc "std" (rect: ^Rect, style: u32, menu: Bool) -> Bool ---;
@(link_name="GetActiveWindow") get_active_window :: proc "std" () -> Hwnd ---;
@(link_name="DestroyWindow") destroy_window :: proc(wnd: Hwnd) -> Bool #cc_std ---;
@(link_name="DescribePixelFormat") describe_pixel_format :: proc(dc: Hdc, pixel_format: i32, bytes: u32, pfd: ^Pixel_Format_Descriptor) -> i32 #cc_std ---;
@(link_name="DestroyWindow") destroy_window :: proc "std" (wnd: Hwnd) -> Bool ---;
@(link_name="DescribePixelFormat") describe_pixel_format :: proc "std" (dc: Hdc, pixel_format: i32, bytes: u32, pfd: ^Pixel_Format_Descriptor) -> i32 ---;
@(link_name="GetMonitor_InfoA") get_monitor_info_a :: proc(monitor: Hmonitor, mi: ^Monitor_Info) -> Bool #cc_std ---;
@(link_name="MonitorFromWindow") monitor_from_window :: proc(wnd: Hwnd, flags : u32) -> Hmonitor #cc_std ---;
@(link_name="GetMonitor_InfoA") get_monitor_info_a :: proc "std" (monitor: Hmonitor, mi: ^Monitor_Info) -> Bool ---;
@(link_name="MonitorFromWindow") monitor_from_window :: proc "std" (wnd: Hwnd, flags : u32) -> Hmonitor ---;
@(link_name="SetWindowPos") set_window_pos :: proc(wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) #cc_std ---;
@(link_name="SetWindowPos") set_window_pos :: proc "std" (wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) ---;
@(link_name="GetWindowPlacement") get_window_placement :: proc(wnd: Hwnd, wndpl: ^Window_Placement) -> Bool #cc_std ---;
@(link_name="SetWindowPlacement") set_window_placement :: proc(wnd: Hwnd, wndpl: ^Window_Placement) -> Bool #cc_std ---;
@(link_name="GetWindowRect") get_window_rect :: proc(wnd: Hwnd, rect: ^Rect) -> Bool #cc_std ---;
@(link_name="GetWindowPlacement") get_window_placement :: proc "std" (wnd: Hwnd, wndpl: ^Window_Placement) -> Bool ---;
@(link_name="SetWindowPlacement") set_window_placement :: proc "std" (wnd: Hwnd, wndpl: ^Window_Placement) -> Bool ---;
@(link_name="GetWindowRect") get_window_rect :: proc "std" (wnd: Hwnd, rect: ^Rect) -> Bool ---;
@(link_name="GetWindowLongPtrA") get_window_long_ptr_a :: proc(wnd: Hwnd, index: i32) -> Long_Ptr #cc_std ---;
@(link_name="SetWindowLongPtrA") set_window_long_ptr_a :: proc(wnd: Hwnd, index: i32, new: Long_Ptr) -> Long_Ptr #cc_std ---;
@(link_name="GetWindowLongPtrW") get_window_long_ptr_w :: proc(wnd: Hwnd, index: i32) -> Long_Ptr #cc_std ---;
@(link_name="SetWindowLongPtrW") set_window_long_ptr_w :: proc(wnd: Hwnd, index: i32, new: Long_Ptr) -> Long_Ptr #cc_std ---;
@(link_name="GetWindowLongPtrA") get_window_long_ptr_a :: proc "std" (wnd: Hwnd, index: i32) -> Long_Ptr ---;
@(link_name="SetWindowLongPtrA") set_window_long_ptr_a :: proc "std" (wnd: Hwnd, index: i32, new: Long_Ptr) -> Long_Ptr ---;
@(link_name="GetWindowLongPtrW") get_window_long_ptr_w :: proc "std" (wnd: Hwnd, index: i32) -> Long_Ptr ---;
@(link_name="SetWindowLongPtrW") set_window_long_ptr_w :: proc "std" (wnd: Hwnd, index: i32, new: Long_Ptr) -> Long_Ptr ---;
@(link_name="GetWindowText") get_window_text :: proc(wnd: Hwnd, str: ^u8, maxCount: i32) -> i32 #cc_std ---;
@(link_name="GetWindowText") get_window_text :: proc "std" (wnd: Hwnd, str: ^u8, maxCount: i32) -> i32 ---;
@(link_name="GetClientRect") get_client_rect :: proc(hwnd: Hwnd, rect: ^Rect) -> Bool #cc_std ---;
@(link_name="GetClientRect") get_client_rect :: proc "std" (hwnd: Hwnd, rect: ^Rect) -> Bool ---;
@(link_name="GetDC") get_dc :: proc(h: Hwnd) -> Hdc #cc_std ---;
@(link_name="ReleaseDC") release_dc :: proc(wnd: Hwnd, hdc: Hdc) -> i32 #cc_std ---;
@(link_name="GetDC") get_dc :: proc "std" (h: Hwnd) -> Hdc ---;
@(link_name="ReleaseDC") release_dc :: proc "std" (wnd: Hwnd, hdc: Hdc) -> i32 ---;
@(link_name="MapVirtualKeyA") map_virtual_key_a :: proc(scancode : u32, map_type : u32) -> u32 #cc_std ---;
@(link_name="MapVirtualKeyW") map_virtual_key_w :: proc(scancode : u32, map_type : u32) -> u32 #cc_std ---;
@(link_name="MapVirtualKeyA") map_virtual_key_a :: proc "std" (scancode : u32, map_type : u32) -> u32 ---;
@(link_name="MapVirtualKeyW") map_virtual_key_w :: proc "std" (scancode : u32, map_type : u32) -> u32 ---;
@(link_name="GetKeyState") get_key_state :: proc(v_key: i32) -> i16 #cc_std ---;
@(link_name="GetAsyncKeyState") get_async_key_state :: proc(v_key: i32) -> i16 #cc_std ---;
@(link_name="GetKeyState") get_key_state :: proc "std" (v_key: i32) -> i16 ---;
@(link_name="GetAsyncKeyState") get_async_key_state :: proc "std" (v_key: i32) -> i16 ---;
@(link_name="SetForegroundWindow") set_foreground_window :: proc(h: Hwnd) -> Bool #cc_std ---;
@(link_name="SetFocus") set_focus :: proc(h: Hwnd) -> Hwnd #cc_std ---;
@(link_name="SetForegroundWindow") set_foreground_window :: proc "std" (h: Hwnd) -> Bool ---;
@(link_name="SetFocus") set_focus :: proc "std" (h: Hwnd) -> Hwnd ---;
@(link_name="RegisterRawInputDevices") register_raw_input_devices :: proc(raw_input_device: ^Raw_Input_Device, num_devices, size: u32) -> Bool #cc_std ---;
@(link_name="RegisterRawInputDevices") register_raw_input_devices :: proc "std" (raw_input_device: ^Raw_Input_Device, num_devices, size: u32) -> Bool ---;
@(link_name="GetRawInputData") get_raw_input_data :: proc(raw_input: Hrawinput, command: u32, data: rawptr, size: ^u32, size_header: u32) -> u32 #cc_std ---;
@(link_name="GetRawInputData") get_raw_input_data :: proc "std" (raw_input: Hrawinput, command: u32, data: rawptr, size: ^u32, size_header: u32) -> u32 ---;
@(link_name="MapVirtualKeyExW") map_virtual_key_ex_w :: proc(code, map_type: u32, hkl: HKL) #cc_std ---;
@(link_name="MapVirtualKeyExA") map_virtual_key_ex_a :: proc(code, map_type: u32, hkl: HKL) #cc_std ---;
@(link_name="MapVirtualKeyExW") map_virtual_key_ex_w :: proc "std" (code, map_type: u32, hkl: HKL) ---;
@(link_name="MapVirtualKeyExA") map_virtual_key_ex_a :: proc "std" (code, map_type: u32, hkl: HKL) ---;
}
foreign gdi32 {
@(link_name="GetStockObject") get_stock_object :: proc(fn_object: i32) -> Hgdiobj #cc_std ---;
@(link_name="GetStockObject") get_stock_object :: proc "std" (fn_object: i32) -> Hgdiobj ---;
@(link_name="StretchDIBits")
stretch_dibits :: proc(hdc: Hdc,
x_dst, y_dst, width_dst, height_dst: i32,
x_src, y_src, width_src, header_src: i32,
bits: rawptr, bits_info: ^Bitmap_Info,
usage: u32,
rop: u32) -> i32 #cc_std ---;
stretch_dibits :: proc "std" (hdc: Hdc,
x_dst, y_dst, width_dst, height_dst: i32,
x_src, y_src, width_src, header_src: i32,
bits: rawptr, bits_info: ^Bitmap_Info,
usage: u32,
rop: u32) -> i32 ---;
@(link_name="SetPixelFormat") set_pixel_format :: proc(hdc: Hdc, pixel_format: i32, pfd: ^Pixel_Format_Descriptor) -> Bool #cc_std ---;
@(link_name="ChoosePixelFormat") choose_pixel_format :: proc(hdc: Hdc, pfd: ^Pixel_Format_Descriptor) -> i32 #cc_std ---;
@(link_name="SwapBuffers") swap_buffers :: proc(hdc: Hdc) -> Bool #cc_std ---;
@(link_name="SetPixelFormat") set_pixel_format :: proc "std" (hdc: Hdc, pixel_format: i32, pfd: ^Pixel_Format_Descriptor) -> Bool ---;
@(link_name="ChoosePixelFormat") choose_pixel_format :: proc "std" (hdc: Hdc, pfd: ^Pixel_Format_Descriptor) -> i32 ---;
@(link_name="SwapBuffers") swap_buffers :: proc "std" (hdc: Hdc) -> Bool ---;
}
foreign shell32 {
@(link_name="CommandLineToArgvW") command_line_to_argv_w :: proc(cmd_list: ^u16, num_args: ^i32) -> ^^u16 #cc_std ---;
@(link_name="CommandLineToArgvW") command_line_to_argv_w :: proc "std" (cmd_list: ^u16, num_args: ^i32) -> ^^u16 ---;
}
foreign winmm {
@(link_name="timeGetTime") time_get_time :: proc() -> u32 #cc_std ---;
@(link_name="timeGetTime") time_get_time :: proc "std" () -> u32 ---;
}

View File

@@ -25,7 +25,7 @@ Thread :: struct {
create :: proc(procedure: Thread_Proc) -> ^Thread {
win32_thread_id: u32;
__windows_thread_entry_proc :: proc(data: rawptr) -> i32 #cc_c {
__windows_thread_entry_proc :: proc "c" (data: rawptr) -> i32 {
if data == nil do return 0;
t := cast(^Thread)data;

View File

@@ -8264,7 +8264,6 @@ void ir_gen_tree(irGen *s) {
if (e->kind == Entity_Procedure && e->Procedure.is_export) {
} else if (e->kind == Entity_Procedure && e->Procedure.link_name.len > 0) {
// Handle later
// } else if (scope->is_init && e->kind == Entity_Procedure && name == "main") {
} else {
name = ir_mangle_name(s, e->token.pos.file, e);
}

View File

@@ -2098,6 +2098,7 @@ void parse_proc_tags(AstFile *f, u64 *tags, ProcCallingConvention *calling_conve
GB_ASSERT(tags != nullptr);
ProcCallingConvention cc = ProcCC_Invalid;
if (calling_convention) cc = *calling_convention;
while (f->curr_token.kind == Token_Hash) {
AstNode *tag_expr = parse_tag_expr(f, nullptr);
@@ -3299,13 +3300,40 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token) {
AstNode *params = nullptr;
AstNode *results = nullptr;
ProcCallingConvention cc = ProcCC_Invalid;
if (f->curr_token.kind == Token_String) {
Token token = expect_token(f, Token_String);
String conv = token.string;
if (conv == "odin") {
cc = ProcCC_Odin;
} else if (conv == "contextless") {
cc = ProcCC_Contextless;
} else if (conv == "cdecl" || conv == "c") {
cc = ProcCC_C;
} else if (conv == "stdcall" || conv == "std") {
cc = ProcCC_Std;
} else if (conv == "fastcall" || conv == "fast") {
cc = ProcCC_Fast;
} else {
syntax_error(token, "Unknown procedure tag #%.*s\n", LIT(conv));
}
if (cc == ProcCC_Invalid) {
if (f->in_foreign_block) {
cc = ProcCC_C;
} else {
cc = ProcCC_Odin;
}
}
}
expect_token(f, Token_OpenParen);
params = parse_field_list(f, nullptr, FieldFlag_Signature, Token_CloseParen, true, true);
expect_token_after(f, Token_CloseParen, "parameter list");
results = parse_results(f);
u64 tags = 0;
ProcCallingConvention cc = ProcCC_Invalid;
parse_proc_tags(f, &tags, &cc);
bool is_generic = false;