aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-09-19 23:59:26 +0100
committerGinger Bill <bill@gingerbill.org>2016-09-19 23:59:26 +0100
commit59b0cf61efdccc44efafda24ff59399dde6afc4d (patch)
tree35162a81623e3482929f7c6e3415d517cdf478eb /core
parent3b266b194f36507208b6f90145475d93b53896ee (diff)
fmt improvement; Minor refactoring
Diffstat (limited to 'core')
-rw-r--r--core/fmt.odin72
-rw-r--r--core/runtime.odin12
2 files changed, 67 insertions, 17 deletions
diff --git a/core/fmt.odin b/core/fmt.odin
index cd8c45434..1864b0e5c 100644
--- a/core/fmt.odin
+++ b/core/fmt.odin
@@ -2,42 +2,47 @@
PRINT_BUF_SIZE :: 1<<12
-fprint :: proc(f: ^os.File, args: ..any) {
- data: [PRINT_BUF_SIZE]byte
- buf := data[:0]
+bprint :: proc(buf: ^[]byte, args: ..any) {
prev_string := false
for i := 0; i < args.count; i++ {
arg := args[i]
is_string := arg.data != null && type_info_is_string(arg.type_info)
- if i > 0 && is_string && !prev_string {
- print_space_to_buffer(^buf)
+ if i > 0 && !is_string && !prev_string {
+ print_space_to_buffer(buf)
}
- print_any_to_buffer(^buf, arg)
+ print_any_to_buffer(buf, arg)
prev_string = is_string;
}
-
- os.write(f, buf)
}
-fprintln :: proc(f: ^os.File, args: ..any) {
- data: [PRINT_BUF_SIZE]byte
- buf := data[:0]
-
+bprintln :: proc(buf: ^[]byte, args: ..any) {
for i := 0; i < args.count; i++ {
if i > 0 {
- append(^buf, #rune " ")
+ append(buf, #rune " ")
}
- print_any_to_buffer(^buf, args[i])
+ print_any_to_buffer(buf, args[i])
}
+ print_nl_to_buffer(buf)
+}
- print_nl_to_buffer(^buf)
+fprint :: proc(f: ^os.File, args: ..any) {
+ data: [PRINT_BUF_SIZE]byte
+ buf := data[:0]
+ bprint(^buf, ..args)
+ os.write(f, buf)
+}
+
+fprintln :: proc(f: ^os.File, args: ..any) {
+ data: [PRINT_BUF_SIZE]byte
+ buf := data[:0]
+ bprintln(^buf, ..args)
os.write(f, buf)
}
fprintf :: proc(f: ^os.File, fmt: string, args: ..any) {
data: [PRINT_BUF_SIZE]byte
buf := data[:0]
- printf_to_buffer(^buf, fmt, ..args)
+ bprintf(^buf, fmt, ..args)
os.write(f, buf)
}
@@ -52,6 +57,39 @@ printf :: proc(fmt: string, args: ..any) {
fprintf(os.stdout, fmt, ..args)
}
+sprint :: proc(args: ..any) -> string {
+ data: [PRINT_BUF_SIZE]byte
+ buf := data[:0]
+ bprint(^buf, ..args)
+ s := new_slice(byte, buf.count)
+ copy(s, buf)
+ return s as string
+}
+sprintln :: proc(args: ..any) -> string {
+ data: [PRINT_BUF_SIZE]byte
+ buf := data[:0]
+ bprintln(^buf, ..args)
+ s := new_slice(byte, buf.count)
+ copy(s, buf)
+ return s as string
+}
+sprintf :: proc(fmt: string, args: ..any) -> string {
+ data: [PRINT_BUF_SIZE]byte
+ buf := data[:0]
+ bprintf(^buf, fmt, ..args)
+ s := new_slice(byte, buf.count)
+ copy(s, buf)
+ return s as string
+}
+
+
+
+fprint_type :: proc(f: ^os.File, info: ^Type_Info) {
+ data: [PRINT_BUF_SIZE]byte
+ buf := data[:0]
+ print_type_to_buffer(^buf, info)
+ os.write(f, buf)
+}
@@ -561,7 +599,7 @@ type_info_is_string :: proc(info: ^Type_Info) -> bool {
}
-printf_to_buffer :: proc(buf: ^[]byte, fmt: string, args: ..any) {
+bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) {
is_digit :: proc(r: rune) -> bool #inline {
return r >= #rune "0" && r <= #rune "9"
}
diff --git a/core/runtime.odin b/core/runtime.odin
index 8fa840597..52c3f68a0 100644
--- a/core/runtime.odin
+++ b/core/runtime.odin
@@ -63,6 +63,18 @@ Type_Info :: union {
}
}
+type_info_base :: proc(info: ^Type_Info) -> ^Type_Info {
+ for {
+ match type i : info {
+ case Type_Info.Named:
+ info = i.base
+ continue
+ }
+
+ return info
+ }
+}
+
assume :: proc(cond: bool) #foreign "llvm.assume"