aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-03-02 19:24:34 +0000
committerGinger Bill <bill@gingerbill.org>2017-03-02 19:24:34 +0000
commit9e8c9be1ea825c2b5c66e62724519ae9ab8ab8f6 (patch)
tree2d199c849c7a1d25c533bd96fe1abe883cf00454 /core
parent9bc37f44002d89ed35643b2bfd8c384cb5ff1f48 (diff)
Allow pointers to `append`; Fix strconv stuff; `new_slice` allows for capacity
Diffstat (limited to 'core')
-rw-r--r--core/fmt.odin10
-rw-r--r--core/strconv.odin19
-rw-r--r--core/strings.odin4
-rw-r--r--core/sync.odin62
-rw-r--r--core/sys/windows.odin83
5 files changed, 122 insertions, 56 deletions
diff --git a/core/fmt.odin b/core/fmt.odin
index eb2353b72..abc0d1ac7 100644
--- a/core/fmt.odin
+++ b/core/fmt.odin
@@ -8,10 +8,10 @@
_BUFFER_SIZE :: 1<<12;
write_string :: proc(buf: ^[]byte, s: string) {
- append(buf^, ..cast([]byte)s);
+ append(buf, ..cast([]byte)s);
}
write_byte :: proc(buf: ^[]byte, b: byte) {
- append(buf^, b);
+ append(buf, b);
}
write_rune :: proc(buf: ^[]byte, r: rune) {
if r < utf8.RUNE_SELF {
@@ -20,7 +20,7 @@ write_rune :: proc(buf: ^[]byte, r: rune) {
}
b, n := utf8.encode_rune(r);
- append(buf^, ..b[..n]);
+ append(buf, ..b[..n]);
}
Fmt_Info :: struct {
@@ -431,7 +431,7 @@ fmt_write_padding :: proc(fi: ^Fmt_Info, width: int) {
count := min(width, fi.buf.capacity-fi.buf.count);
for _ in 0..count {
- append(fi.buf^, pad_byte);
+ append(fi.buf, pad_byte);
}
}
@@ -533,8 +533,6 @@ _pad :: proc(fi: ^Fmt_Info, s: string) {
}
fmt_float :: proc(fi: ^Fmt_Info, v: f64, bit_size: int, verb: rune) {
-
-
match verb {
// case 'e', 'E', 'f', 'F', 'g', 'G', 'v':
// case 'f', 'F', 'v':
diff --git a/core/strconv.odin b/core/strconv.odin
index ff78847df..53d890a6b 100644
--- a/core/strconv.odin
+++ b/core/strconv.odin
@@ -109,12 +109,9 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, prec, bit_size: int) -> [
round_shortest(d, mant, exp, flt);
digs = Decimal_Slice{digits = d.digits[..], count = d.count, decimal_point = d.decimal_point};
match fmt {
- case 'e', 'E':
- prec = digs.count-1;
- case 'f', 'F':
- prec = max(digs.count-digs.decimal_point, 0);
- case 'g', 'G':
- prec = digs.count;
+ case 'e', 'E': prec = digs.count-1;
+ case 'f', 'F': prec = max(digs.count-digs.decimal_point, 0);
+ case 'g', 'G': prec = digs.count;
}
} else {
match fmt {
@@ -139,9 +136,10 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slic
case 'f', 'F':
add_bytes :: proc(dst: ^[]byte, w: ^int, bytes: ..byte) {
for b in bytes {
- if dst.count <= w^ {
+ if dst.capacity <= w^ {
break;
}
+ dst.count++;
dst[w^] = b;
w^++;
}
@@ -166,6 +164,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slic
add_bytes(^dst, ^w, '0');
}
+
// fractional part
if prec > 0 {
add_bytes(^dst, ^w, '.');
@@ -181,10 +180,12 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slic
return buf[..w];
case 'e', 'E':
- return nil; // TODO
+ panic("strconv: e/E float printing is not yet supported");
+ return buf; // TODO
case 'g', 'G':
- return nil; // TODO
+ panic("strconv: g/G float printing is not yet supported");
+ return buf; // TODO
}
c: [2]byte;
diff --git a/core/strings.odin b/core/strings.odin
index 7439fff32..7b2f09230 100644
--- a/core/strings.odin
+++ b/core/strings.odin
@@ -1,8 +1,8 @@
new_c_string :: proc(s: string) -> ^byte {
- c := new_c_string(byte, s.count+1);
+ c := new_slice(byte, s.count+1);
copy(c, cast([]byte)s);
c[s.count] = 0;
- return c;
+ return c.data;
}
to_odin_string :: proc(c: ^byte) -> string {
diff --git a/core/sync.odin b/core/sync.odin
index 3126d6882..a2296c3b6 100644
--- a/core/sync.odin
+++ b/core/sync.odin
@@ -2,14 +2,14 @@
#import "atomic.odin";
Semaphore :: struct {
- handle: win32.HANDLE,
+ _handle: win32.HANDLE,
}
Mutex :: struct {
- semaphore: Semaphore,
- counter: i32,
- owner: i32,
- recursion: i32,
+ _semaphore: Semaphore,
+ _counter: i32,
+ _owner: i32,
+ _recursion: i32,
}
current_thread_id :: proc() -> i32 {
@@ -17,74 +17,74 @@ current_thread_id :: proc() -> i32 {
}
semaphore_init :: proc(s: ^Semaphore) {
- s.handle = win32.CreateSemaphoreA(nil, 0, 1<<31-1, nil);
+ s._handle = win32.CreateSemaphoreA(nil, 0, 1<<31-1, nil);
}
semaphore_destroy :: proc(s: ^Semaphore) {
- win32.CloseHandle(s.handle);
+ win32.CloseHandle(s._handle);
}
semaphore_post :: proc(s: ^Semaphore, count: int) {
- win32.ReleaseSemaphore(s.handle, cast(i32)count, nil);
+ win32.ReleaseSemaphore(s._handle, cast(i32)count, nil);
}
semaphore_release :: proc(s: ^Semaphore) #inline { semaphore_post(s, 1); }
semaphore_wait :: proc(s: ^Semaphore) {
- win32.WaitForSingleObject(s.handle, win32.INFINITE);
+ win32.WaitForSingleObject(s._handle, win32.INFINITE);
}
mutex_init :: proc(m: ^Mutex) {
- atomic.store(^m.counter, 0);
- atomic.store(^m.owner, current_thread_id());
- semaphore_init(^m.semaphore);
- m.recursion = 0;
+ atomic.store(^m._counter, 0);
+ atomic.store(^m._owner, current_thread_id());
+ semaphore_init(^m._semaphore);
+ m._recursion = 0;
}
mutex_destroy :: proc(m: ^Mutex) {
- semaphore_destroy(^m.semaphore);
+ semaphore_destroy(^m._semaphore);
}
mutex_lock :: proc(m: ^Mutex) {
thread_id := current_thread_id();
- if atomic.fetch_add(^m.counter, 1) > 0 {
- if thread_id != atomic.load(^m.owner) {
- semaphore_wait(^m.semaphore);
+ if atomic.fetch_add(^m._counter, 1) > 0 {
+ if thread_id != atomic.load(^m._owner) {
+ semaphore_wait(^m._semaphore);
}
}
- atomic.store(^m.owner, thread_id);
- m.recursion++;
+ atomic.store(^m._owner, thread_id);
+ m._recursion++;
}
mutex_try_lock :: proc(m: ^Mutex) -> bool {
thread_id := current_thread_id();
- if atomic.load(^m.owner) == thread_id {
- atomic.fetch_add(^m.counter, 1);
+ if atomic.load(^m._owner) == thread_id {
+ atomic.fetch_add(^m._counter, 1);
} else {
expected: i32 = 0;
- if atomic.load(^m.counter) != 0 {
+ if atomic.load(^m._counter) != 0 {
return false;
}
- if atomic.compare_exchange(^m.counter, expected, 1) == 0 {
+ if atomic.compare_exchange(^m._counter, expected, 1) == 0 {
return false;
}
- atomic.store(^m.owner, thread_id);
+ atomic.store(^m._owner, thread_id);
}
- m.recursion++;
+ m._recursion++;
return true;
}
mutex_unlock :: proc(m: ^Mutex) {
recursion: i32;
thread_id := current_thread_id();
- assert(thread_id == atomic.load(^m.owner));
+ assert(thread_id == atomic.load(^m._owner));
- m.recursion--;
- recursion = m.recursion;
+ m._recursion--;
+ recursion = m._recursion;
if recursion == 0 {
- atomic.store(^m.owner, thread_id);
+ atomic.store(^m._owner, thread_id);
}
- if atomic.fetch_add(^m.counter, -1) > 1 {
+ if atomic.fetch_add(^m._counter, -1) > 1 {
if recursion == 0 {
- semaphore_release(^m.semaphore);
+ semaphore_release(^m._semaphore);
}
}
}
diff --git a/core/sys/windows.odin b/core/sys/windows.odin
index 6d6059214..708c9c84d 100644
--- a/core/sys/windows.odin
+++ b/core/sys/windows.odin
@@ -40,14 +40,19 @@ WS_CAPTION :: 0x00C00000;
WS_VISIBLE :: 0x10000000;
WS_OVERLAPPEDWINDOW :: WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX;
-WM_DESTROY :: 0x0002;
-WM_SIZE :: 0x0005;
-WM_CLOSE :: 0x0010;
-WM_ACTIVATEAPP :: 0x001C;
-WM_QUIT :: 0x0012;
-WM_KEYDOWN :: 0x0100;
-WM_KEYUP :: 0x0101;
-WM_SIZING :: 0x0214;
+WM_DESTROY :: 0x0002;
+WM_SIZE :: 0x0005;
+WM_CLOSE :: 0x0010;
+WM_ACTIVATEAPP :: 0x001C;
+WM_QUIT :: 0x0012;
+WM_KEYDOWN :: 0x0100;
+WM_KEYUP :: 0x0101;
+WM_SIZING :: 0x0214;
+WM_MOUSEWHEEL :: 0x020A;
+WM_SYSKEYDOWN :: 0x0104;
+WM_WINDOWPOSCHANGED :: 0x0047;
+WM_SETCURSOR :: 0x0020;
+WM_CHAR :: 0x0102;
PM_REMOVE :: 1;
@@ -300,6 +305,68 @@ ReadBarrier :: proc() #foreign kernel32;
+
+
+HMONITOR :: HANDLE;
+
+GWL_STYLE :: -16;
+
+HWND_TOP :: cast(HWND)cast(uint)0;
+
+MONITOR_DEFAULTTONULL :: 0x00000000;
+MONITOR_DEFAULTTOPRIMARY :: 0x00000001;
+MONITOR_DEFAULTTONEAREST :: 0x00000002;
+
+SWP_FRAMECHANGED :: 0x0020;
+SWP_NOOWNERZORDER :: 0x0200;
+SWP_NOZORDER :: 0x0004;
+SWP_NOSIZE :: 0x0001;
+SWP_NOMOVE :: 0x0002;
+
+
+MONITORINFO :: struct #ordered {
+ size: u32,
+ monitor: RECT,
+ work: RECT,
+ flags: u32,
+}
+
+WINDOWPLACEMENT :: struct #ordered {
+ length: u32,
+ flags: u32,
+ show_cmd: u32,
+ min_pos: POINT,
+ max_pos: POINT,
+ normal_pos: RECT,
+}
+
+GetMonitorInfoA :: proc(monitor: HMONITOR, mi: ^MONITORINFO) -> BOOL #foreign user32;
+MonitorFromWindow :: proc(wnd: HWND, flags : u32) -> HMONITOR #foreign user32;
+
+SetWindowPos :: proc(wnd: HWND, wndInsertAfter: HWND, x, y, width, height: i32, flags: u32) #foreign user32 "SetWindowPos";
+
+GetWindowPlacement :: proc(wnd: HWND, wndpl: ^WINDOWPLACEMENT) -> BOOL #foreign user32;
+SetWindowPlacement :: proc(wnd: HWND, wndpl: ^WINDOWPLACEMENT) -> BOOL #foreign user32;
+
+GetWindowLongPtrA :: proc(wnd: HWND, index: i32) -> i64 #foreign user32;
+SetWindowLongPtrA :: proc(wnd: HWND, index: i32, new: i64) -> i64 #foreign user32;
+
+GetWindowText :: proc(wnd: HWND, str: ^byte, maxCount: i32) -> i32 #foreign user32;
+
+HIWORD :: proc(wParam: WPARAM) -> u16 { return cast(u16)((cast(u32)wParam >> 16) & 0xffff); }
+HIWORD :: proc(lParam: LPARAM) -> u16 { return cast(u16)((cast(u32)lParam >> 16) & 0xffff); }
+LOWORD :: proc(wParam: WPARAM) -> u16 { return cast(u16)wParam; }
+LOWORD :: proc(lParam: LPARAM) -> u16 { return cast(u16)lParam; }
+
+
+
+
+
+
+
+
+
+
BITMAPINFOHEADER :: struct #ordered {
size: u32,
width, height: i32,