From 698fcb7813dd391de76a5663ee64c48ce4f7d067 Mon Sep 17 00:00:00 2001 From: hikari Date: Wed, 6 Apr 2022 18:44:43 +0300 Subject: [PATCH 1/3] mem: replace size procedures with constants --- core/mem/mem.odin | 11 ++++++----- core/odin/printer/printer.odin | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/mem/mem.odin b/core/mem/mem.odin index 817c0ea5f..a5252d950 100644 --- a/core/mem/mem.odin +++ b/core/mem/mem.odin @@ -3,6 +3,12 @@ package mem import "core:runtime" import "core:intrinsics" +Byte :: 1 +Kilobyte :: 1024 * Byte +Megabyte :: 1024 * Kilobyte +Gigabyte :: 1024 * Megabyte +Terabyte :: 1024 * Gigabyte + set :: proc "contextless" (data: rawptr, value: byte, len: int) -> rawptr { return runtime.memset(data, i32(value), len) } @@ -192,11 +198,6 @@ any_to_bytes :: proc "contextless" (val: any) -> []byte { } -kilobytes :: proc "contextless" (x: int) -> int { return (x) * 1024 } -megabytes :: proc "contextless" (x: int) -> int { return kilobytes(x) * 1024 } -gigabytes :: proc "contextless" (x: int) -> int { return megabytes(x) * 1024 } -terabytes :: proc "contextless" (x: int) -> int { return gigabytes(x) * 1024 } - is_power_of_two :: proc "contextless" (x: uintptr) -> bool { if x <= 0 { return false diff --git a/core/odin/printer/printer.odin b/core/odin/printer/printer.odin index abda44fa2..807cc99bd 100644 --- a/core/odin/printer/printer.odin +++ b/core/odin/printer/printer.odin @@ -151,7 +151,7 @@ print :: proc(p: ^Printer, file: ^ast.File) -> string { fix_lines(p) - builder := strings.make_builder(0, mem.megabytes(5), p.allocator) + builder := strings.make_builder(0, 5 * mem.Megabyte, p.allocator) last_line := 0 From ad90f416a59be22dbf8fca89890a70407dc5826c Mon Sep 17 00:00:00 2001 From: hikari Date: Thu, 7 Apr 2022 12:24:53 +0300 Subject: [PATCH 2/3] runtime: fix typo --- core/runtime/core.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/runtime/core.odin b/core/runtime/core.odin index a5a190a9c..4ab21d8cf 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -565,7 +565,7 @@ __init_context :: proc "contextless" (c: ^Context) { return } - // NOTE(bill): Do not initialize these procedures with a call as they are not defined with the "contexless" calling convention + // NOTE(bill): Do not initialize these procedures with a call as they are not defined with the "contextless" calling convention c.allocator.procedure = default_allocator_proc c.allocator.data = nil From c4a7739d13d386743a53ebe3371e8061310ea2cb Mon Sep 17 00:00:00 2001 From: hikari Date: Thu, 7 Apr 2022 19:28:24 +0300 Subject: [PATCH 3/3] sys/windows: add a couple macros --- core/sys/windows/util.odin | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin index d464007d3..f448f6bc5 100644 --- a/core/sys/windows/util.odin +++ b/core/sys/windows/util.odin @@ -15,6 +15,14 @@ HIWORD :: #force_inline proc "contextless" (x: DWORD) -> WORD { return WORD(x >> 16) } +GET_X_LPARAM :: #force_inline proc "contextless" (lp: LPARAM) -> c_int { + return cast(c_int)cast(c_short)LOWORD(cast(DWORD)lp) +} + +GET_Y_LPARAM :: #force_inline proc "contextless" (lp: LPARAM) -> c_int { + return cast(c_int)cast(c_short)HIWORD(cast(DWORD)lp) +} + utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 { if len(s) < 1 { return nil