Fix parameter/field lists and #import #include syntax

This commit is contained in:
Ginger Bill
2017-01-02 00:26:28 +00:00
parent 9202bd1b06
commit ce89a1428e
17 changed files with 623 additions and 788 deletions
+36 -38
View File
@@ -1,12 +1,10 @@
import {
"os.odin";
"mem.odin";
"utf8.odin";
}
#import "os.odin";
#import "mem.odin";
#import "utf8.odin";
PRINT_BUF_SIZE :: 1<<12;
fprint :: proc(fd os.Handle, args ..any) -> int {
fprint :: proc(fd: os.Handle, args: ..any) -> int {
data: [PRINT_BUF_SIZE]byte;
buf := data[:0];
bprint(^buf, ..args);
@@ -14,14 +12,14 @@ fprint :: proc(fd os.Handle, args ..any) -> int {
return buf.count;
}
fprintln :: proc(fd os.Handle, args ..any) -> int {
fprintln :: proc(fd: os.Handle, args: ..any) -> int {
data: [PRINT_BUF_SIZE]byte;
buf := data[:0];
bprintln(^buf, ..args);
os.write(fd, buf);
return buf.count;
}
fprintf :: proc(fd os.Handle, fmt string, args ..any) -> int {
fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
data: [PRINT_BUF_SIZE]byte;
buf := data[:0];
bprintf(^buf, fmt, ..args);
@@ -30,19 +28,19 @@ fprintf :: proc(fd os.Handle, fmt string, args ..any) -> int {
}
print :: proc(args ..any) -> int {
print :: proc(args: ..any) -> int {
return fprint(os.stdout, ..args);
}
println :: proc(args ..any) -> int {
println :: proc(args: ..any) -> int {
return fprintln(os.stdout, ..args);
}
printf :: proc(fmt string, args ..any) -> int {
printf :: proc(fmt: string, args: ..any) -> int {
return fprintf(os.stdout, fmt, ..args);
}
fprint_type :: proc(fd os.Handle, info ^Type_Info) {
fprint_type :: proc(fd: os.Handle, info: ^Type_Info) {
data: [PRINT_BUF_SIZE]byte;
buf := data[:0];
bprint_type(^buf, info);
@@ -51,7 +49,7 @@ fprint_type :: proc(fd os.Handle, info ^Type_Info) {
print_byte_buffer :: proc(buf ^[]byte, b []byte) {
print_byte_buffer :: proc(buf: ^[]byte, b: []byte) {
if buf.count < buf.capacity {
n := min(buf.capacity-buf.count, b.count);
if n > 0 {
@@ -61,29 +59,29 @@ print_byte_buffer :: proc(buf ^[]byte, b []byte) {
}
}
bprint_string :: proc(buf ^[]byte, s string) {
bprint_string :: proc(buf: ^[]byte, s: string) {
print_byte_buffer(buf, s as []byte);
}
byte_reverse :: proc(b []byte) {
byte_reverse :: proc(b: []byte) {
n := b.count;
for i := 0; i < n/2; i++ {
b[i], b[n-1-i] = b[n-1-i], b[i];
}
}
bprint_rune :: proc(buf ^[]byte, r rune) {
bprint_rune :: proc(buf: ^[]byte, r: rune) {
b, n := utf8.encode_rune(r);
bprint_string(buf, b[:n] as string);
}
bprint_space :: proc(buf ^[]byte) { bprint_rune(buf, ' '); }
bprint_nl :: proc (buf ^[]byte) { bprint_rune(buf, '\n'); }
bprint_space :: proc(buf: ^[]byte) { bprint_rune(buf, ' '); }
bprint_nl :: proc (buf: ^[]byte) { bprint_rune(buf, '\n'); }
__NUM_TO_CHAR_TABLE := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@$";
bprint_bool :: proc(buffer ^[]byte, b bool) {
bprint_bool :: proc(buffer: ^[]byte, b: bool) {
if b {
bprint_string(buffer, "true");
} else {
@@ -91,15 +89,15 @@ bprint_bool :: proc(buffer ^[]byte, b bool) {
}
}
bprint_pointer :: proc(buffer ^[]byte, p rawptr) #inline {
bprint_pointer :: proc(buffer: ^[]byte, p: rawptr) #inline {
bprint_string(buffer, "0x");
bprint_u64(buffer, p as uint as u64);
}
bprint_f16 :: proc (buffer ^[]byte, f f32) #inline { print__f64(buffer, f as f64, 4); }
bprint_f32 :: proc (buffer ^[]byte, f f32) #inline { print__f64(buffer, f as f64, 7); }
bprint_f64 :: proc (buffer ^[]byte, f f64) #inline { print__f64(buffer, f as f64, 16); }
bprint_u64 :: proc(buffer ^[]byte, value u64) {
// bprint_f16 :: proc (buffer: ^[]byte, f: f32) #inline { print__f64(buffer, f as f64, 4); }
bprint_f32 :: proc (buffer: ^[]byte, f: f32) #inline { print__f64(buffer, f as f64, 7); }
bprint_f64 :: proc (buffer: ^[]byte, f: f64) #inline { print__f64(buffer, f as f64, 16); }
bprint_u64 :: proc(buffer: ^[]byte, value: u64) {
i := value;
buf :[20]byte;
len := 0;
@@ -115,7 +113,7 @@ bprint_u64 :: proc(buffer ^[]byte, value u64) {
byte_reverse(buf[:len]);
bprint_string(buffer, buf[:len] as string);
}
bprint_i64 :: proc(buffer ^[]byte, value i64) {
bprint_i64 :: proc(buffer: ^[]byte, value: i64) {
// TODO(bill): Cleanup printing
i := value;
if i < 0 {
@@ -126,14 +124,14 @@ bprint_i64 :: proc(buffer ^[]byte, value i64) {
}
/*
bprint_u128 :: proc(buffer ^[]byte, value u128) {
bprint_u128 :: proc(buffer: ^[]byte, value u128) {
a := value transmute [2]u64;
if a[1] != 0 {
bprint_u64(buffer, a[1]);
}
bprint_u64(buffer, a[0]);
}
bprint_i128 :: proc(buffer ^[]byte, value i128) {
bprint_i128 :: proc(buffer: ^[]byte, value i128) {
i := value;
if i < 0 {
i = -i;
@@ -144,7 +142,7 @@ bprint_i128 :: proc(buffer ^[]byte, value i128) {
*/
print__f64 :: proc(buffer ^[]byte, value f64, decimal_places int) {
print__f64 :: proc(buffer: ^[]byte, value: f64, decimal_places: int) {
f := value;
if f == 0 {
bprint_rune(buffer, '0');
@@ -170,7 +168,7 @@ print__f64 :: proc(buffer ^[]byte, value f64, decimal_places int) {
}
}
bprint_type :: proc(buf ^[]byte, ti ^Type_Info) {
bprint_type :: proc(buf: ^[]byte, ti: ^Type_Info) {
if ti == nil {
return;
}
@@ -302,14 +300,14 @@ bprint_type :: proc(buf ^[]byte, ti ^Type_Info) {
}
make_any :: proc(type_info ^Type_Info, data rawptr) -> any {
make_any :: proc(type_info: ^Type_Info, data: rawptr) -> any {
a :any;
a.type_info = type_info;
a.data = data;
return a;
}
bprint_any :: proc(buf ^[]byte, arg any) {
bprint_any :: proc(buf: ^[]byte, arg: any) {
if arg.type_info == nil {
bprint_string(buf, "<nil>");
return;
@@ -423,7 +421,7 @@ bprint_any :: proc(buf ^[]byte, arg any) {
}
case Vector:
is_bool :: proc(type_info ^Type_Info) -> bool {
is_bool :: proc(type_info: ^Type_Info) -> bool {
match type info : type_info {
case Named:
return is_bool(info.base);
@@ -481,12 +479,12 @@ bprint_any :: proc(buf ^[]byte, arg any) {
}
bprintf :: proc(buf ^[]byte, fmt string, args ..any) -> int {
is_digit :: proc(r rune) -> bool #inline {
bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
is_digit :: proc(r: rune) -> bool #inline {
return '0' <= r && r <= '9';
}
parse_int :: proc(s string, offset int) -> (int, int) {
parse_int :: proc(s: string, offset: int) -> (int, int) {
result := 0;
for ; offset < s.count; offset++ {
@@ -546,8 +544,8 @@ bprintf :: proc(buf ^[]byte, fmt string, args ..any) -> int {
}
bprint :: proc(buf ^[]byte, args ..any) -> int {
is_type_string :: proc(info ^Type_Info) -> bool {
bprint :: proc(buf: ^[]byte, args: ..any) -> int {
is_type_string :: proc(info: ^Type_Info) -> bool {
using Type_Info;
if info == nil {
return false;
@@ -574,7 +572,7 @@ bprint :: proc(buf ^[]byte, args ..any) -> int {
return buf.count;
}
bprintln :: proc(buf ^[]byte, args ..any) -> int {
bprintln :: proc(buf: ^[]byte, args: ..any) -> int {
for i := 0; i < args.count; i++ {
if i > 0 {
append(buf, ' ');