From 1ec9d0fd46d0e7175f34fae64011eed1b364ea57 Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 21 Dec 2024 19:28:10 +0000 Subject: [PATCH] printf, various syntax updates, better string manipulation miscellaneous changes --- Cargo.lock | 6 +- sysdata/libraries/stn/src/fmt.hb | 64 +++++- sysdata/libraries/stn/src/hash/foldhash.hb | 16 +- sysdata/libraries/stn/src/lib.hb | 10 +- sysdata/libraries/stn/src/log.hb | 13 +- sysdata/libraries/stn/src/string.hb | 216 +++++++----------- sysdata/programs/ps2_driver/src/main.hb | 4 +- sysdata/programs/ps2_driver/src/port.hb | 4 +- .../render_example/src/examples/text.hb | 2 +- sysdata/programs/test/src/main.hb | 2 +- sysdata/programs/test/src/tests/stn/dt.hb | 15 +- sysdata/programs/test/src/tests/stn/fmt.hb | 1 + .../programs/test/src/tests/stn/hashers.hb | 16 +- sysdata/programs/vfsaur/src/main.hb | 18 +- sysdata/system_config.toml | 22 +- 15 files changed, 194 insertions(+), 215 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 416542e..108c3ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4b3b6af70eb84d513b9fa926dd8c36e1dba88713" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#418fd0039eda7fd4052c8086373b1e1257d573c8" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4b3b6af70eb84d513b9fa926dd8c36e1dba88713" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#418fd0039eda7fd4052c8086373b1e1257d573c8" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4b3b6af70eb84d513b9fa926dd8c36e1dba88713" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#418fd0039eda7fd4052c8086373b1e1257d573c8" dependencies = [ "hbbytecode", ] diff --git a/sysdata/libraries/stn/src/fmt.hb b/sysdata/libraries/stn/src/fmt.hb index 87ae5e3..78294ce 100644 --- a/sysdata/libraries/stn/src/fmt.hb +++ b/sysdata/libraries/stn/src/fmt.hb @@ -1,4 +1,4 @@ -.{Kind, usize, string, signed_int, float, integer, memory, panic, log: .{LogLevel}} := @use("stn") +.{Kind, usize, string, signed_int, panic, float, integer, memory, log: .{LogLevel}} := @use("stn") fmt_int := fn(v: @Any(), str: ^u8, radix: @TypeOf(v)): uint { is_negative := signed_int(@TypeOf(v)) & v < 0 @@ -199,7 +199,14 @@ FormatOptions := struct { format := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint { T := @TypeOf(v) match Kind.of(T) { - .Pointer => return @inline(fmt_int, @as(uint, @bitcast(v)), str, 16), + .Pointer => if T != ^u8 return @inline(fmt_int, @as(uint, @bitcast(v)), str, 16) else { + i := 0 + loop if *(v + i) == '\0' break else { + *(str + i) = *(v + i) + i += 1 + } + return i + }, .Builtin => { if integer(T) { return @inline(fmt_int, v, str, @intcast(opts.radix)) @@ -216,4 +223,57 @@ format := fn(v: @Any(), str: ^u8, opts: FormatOptions): uint { .Slice => return @inline(fmt_container, v, str, opts), _ => @error("Type: \"\0", T, "\" is not supported.\0"), } +} + +format_with_str := fn(v: @Any(), read: ^u8, write: ^u8, opts: FormatOptions): uint { + T := @TypeOf(v) + n := string.count(read, '{') + if n != string.count(read, '}') panic("Missing closing '}' in format string.\0") + if Kind.of(T) == .Tuple { + if @lenof(T) != n panic("Format string has different number of '{}' than args given.\0") + m := 0 + i := 0 + j := 0 + $loop if m > @lenof(T) break else { + if m == @lenof(T) { + loop if *(read + i) == '\0' break else { + *(write + j) = *(read + i) + i += 1 + j += 1 + } + m += 1 + } else { + v2 := v[m] + loop if *(read + i) == '\0' break else { + if *(read + i) == '{' & *(read + i + 1) == '}' { + j += format(v2, write + j, opts) + 1 + i += 2 + break + } else { + *(write + j) = *(read + i) + i += 1 + j += 1 + } + } + m += 1 + } + } + return j + } else if n > 1 { + panic("Format string has multiple '{}' but value provided is not a tuple.\0") + } else { + i := 0 + j := 0 + loop if *(read + i) == '\0' break else { + if *(read + i) == '{' & *(read + i + 1) == '}' { + j += format(v, write + j, opts) + 1 + i += 2 + } else { + *(write + j) = *(read + i) + i += 1 + j += 1 + } + } + return j + } } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/hash/foldhash.hb b/sysdata/libraries/stn/src/hash/foldhash.hb index 2aa9e1b..4183112 100644 --- a/sysdata/libraries/stn/src/hash/foldhash.hb +++ b/sysdata/libraries/stn/src/hash/foldhash.hb @@ -38,7 +38,7 @@ $ARBITRARY6 := 0xC0AC29B7C97C50DD $ARBITRARY7 := 0x3F84D5B5B5470917 $ARBITRARY8 := 0x9216D5D98979FB1B $ARBITRARY9 := 0xD1310BA698DFB5AC -$FIXED_GLOBAL_SEED := [uint].(ARBITRARY4, ARBITRARY5, ARBITRARY6, ARBITRARY7) +$FIXED_GLOBAL_SEED := uint.[ARBITRARY4, ARBITRARY5, ARBITRARY6, ARBITRARY7] global_seed := 0 @@ -103,7 +103,7 @@ hash_bytes_long := fn(bytes: ^u8, len: uint, s0: uint, s1: uint, s2: uint, s3: u if remainder > 0 { remainder_start := bytes + len - math.max(uint, remainder, 16) - return hash_bytes_medium(remainder_start, math.max(uint, remainder, 16), s0, s1, fold_seed) + return @inline(hash_bytes_medium, remainder_start, math.max(uint, remainder, 16), s0, s1, fold_seed) } return s0 ^ s1 @@ -159,17 +159,9 @@ FoldHasher := struct { } self.accumulator = folded_multiply(s0, s1) } else if len < 256 { - self.accumulator = hash_bytes_medium(bytes, len, s0, s1, self.fold_seed) + self.accumulator = @inline(hash_bytes_medium, bytes, len, s0, s1, self.fold_seed) } else { - self.accumulator = hash_bytes_long( - bytes, - len, - s0, - s1, - self.expand_seed2, - self.expand_seed3, - self.fold_seed, - ) + self.accumulator = @inline(hash_bytes_long, bytes, len, s0, s1, self.expand_seed2, self.expand_seed3, self.fold_seed) } } diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index 73fec4a..e5108b8 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -13,14 +13,8 @@ dt := @use("dt.hb") process := @use("process.hb") sleep := @use("sleep.hb") -// todo: replace with comptime message (for zero cost) panic := fn(message: ?^u8): never { - log.error("Error: Panic Called, Message:\0") - if message == null { - log.error("None\0") - } else { - log.error(message) - } + log.printf("HBLang Panic: {}\0", message, .{log: .Error}) die } @@ -69,4 +63,4 @@ $bits := fn($T: type): usize(T) { $bitmask := fn($T: type): usize(T) { return -1 -} +} \ No newline at end of file diff --git a/sysdata/libraries/stn/src/log.hb b/sysdata/libraries/stn/src/log.hb index 8420e79..483c742 100644 --- a/sysdata/libraries/stn/src/log.hb +++ b/sysdata/libraries/stn/src/log.hb @@ -23,14 +23,19 @@ trace := fn(message: ^u8): void return @inline(log, LogLevel.Trace, message) print_buffer := memory.dangling(u8) print := fn(v: @Any(), opts: fmt.FormatOptions): void { - if @TypeOf(v) == ^u8 { - @inline(log, opts.log, v) - return - } if print_buffer == memory.dangling(u8) { print_buffer = memory.request_page(1) } len := @inline(fmt.format, v, print_buffer, opts) @eca(3, 1, LogMsg.(opts.log, print_buffer, len), @sizeof(LogMsg)) memory.set(u8, &0, print_buffer, memory.PAGE_SIZE) +} + +printf := fn(str: ^u8, v: @Any(), opts: fmt.FormatOptions): void { + if print_buffer == memory.dangling(u8) { + print_buffer = memory.request_page(1) + } + len := @inline(fmt.format_with_str, v, str, print_buffer, opts) + @eca(3, 1, LogMsg.(opts.log, print_buffer, len), @sizeof(LogMsg)) + memory.set(u8, &0, print_buffer, memory.PAGE_SIZE) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/string.hb b/sysdata/libraries/stn/src/string.hb index cb78cd4..b57b918 100644 --- a/sysdata/libraries/stn/src/string.hb +++ b/sysdata/libraries/stn/src/string.hb @@ -1,41 +1,10 @@ +.{log, memory} := @use("stn") + length := fn(ptr: ^u8): uint { len := 0 loop if *(ptr + len) == 0 return len else len += 1 } -display_int := fn(num: int, p: ^u8, radix: uint): ^u8 { - is_negative := num < 0 - if is_negative num = -num - - ptr := p - - if num == 0 { - *ptr = 0x30; - *(ptr + 1) = 0 - return p - } - - loop if num == 0 break else { - remainder := num % @bitcast(radix) - num /= @bitcast(radix); - *ptr = @intcast(remainder + 0x30) - if remainder > 9 { - *ptr = @intcast(remainder - 10 + 0x41) - } - ptr += 1 - } - - if is_negative { - *ptr = 0x2D - ptr += 1 - } - // ! it gets broked when you do this ?? - // *ptr = 0 - - @inline(reverse, p) - return p -} - reverse := fn(s: ^u8): void { j := s + @inline(length, s) - 1 temp := @as(u8, 0) @@ -69,132 +38,109 @@ clear := fn(ptr: ^u8): void { } } -split_once := fn(haystack: ^u8, needle: u8): ?^u8 { - loop if *haystack == needle return haystack else if *haystack == 0 return null else haystack += 1 -} +split_buffer := memory.dangling(u8) -split_once_str := fn(haystack: ^u8, needle: ^u8): ?^u8 { - if *needle == 0 return null +split_once := fn(haystack: ^u8, needle: @Any()): ?^u8 { + T := @TypeOf(needle) + if T == ^u8 { + if *needle == 0 return null - loop if *haystack == 0 return null else { - if *haystack == *needle { - h := haystack - n := needle + loop if *haystack == 0 return null else { + if *haystack == *needle { + h := haystack + n := needle - loop { - n += 1 - h += 1 - if *n == 0 { - return haystack - } else if *h == 0 | *h != *n { - break + loop { + n += 1 + h += 1 + if *n == 0 { + return haystack + } else if *h == 0 | *h != *n { + break + } } } + haystack += 1 } - haystack += 1 + } else if T == u8 { + loop if *haystack == needle return haystack else if *haystack == 0 return null else haystack += 1 + } else { + @error("Type of needle must be string or char.\0") } } -Split := struct { - str: ^u8, - needle: u8, - done: bool, -} +SplitIter := fn($T: type): type { + return struct { + str: ^u8, + needle: T, + done: bool, -split := fn(iter: ^u8, needle: u8): Split { - return .( - iter, - needle, - false, - ) -} + next := fn(self: ^Self): ?^u8 { + if self.done | *self.str == 0 { + return null + } -iter_split := fn(iter: ^Split): ?^u8 { - if iter.done | *iter.str == 0 { - return null + next0 := split_once(self.str, self.needle) + + if next0 == null { + self.done = true + return self.str + } + s := self.str + if T == ^u8 { + self.str = next0 + length(self.needle) + } else if T == u8 { + self.str = next0 + 1 + } + + return s + } } +} - next := split_once(iter.str + 1, iter.needle) - - if next == null { - iter.done = true - return iter.str +split := fn(iter: ^u8, needle: @Any()): SplitIter(@TypeOf(needle)) { + T := @TypeOf(needle) + if T != ^u8 & T != u8 { + @error("Type of needle must be string or char.\0") } - s := iter.str - iter.str = next + 1 - - return s + return .(iter, needle, false) } -SplitStr := struct { - str: ^u8, - needle: ^u8, - done: bool, -} - -split_str := fn(iter: ^u8, needle: ^u8): SplitStr { - return .( - iter, - needle, - false, - ) -} - -iter_split_str := fn(iter: ^SplitStr): ?^u8 { - if iter.done | *iter.str == 0 { - return null - } - - next := split_once_str(iter.str, iter.needle) - - if next == null { - iter.done = true - return iter.str - } - - s := iter.str - - iter.str = next + length(iter.needle) - - return s -} - -find_once := fn(haystack: ^u8, needle: u8): ?uint { +find_once := fn(haystack: ^u8, needle: @Any()): ?uint { return @bitcast(@inline(split_once, haystack, needle) - haystack) } -find_once_str := fn(haystack: ^u8, needle: ^u8): ?uint { - return @bitcast(@inline(split_once_str, haystack, needle) - haystack) -} - -count := fn(haystack: ^u8, needle: ^u8): uint { +count := fn(haystack: ^u8, needle: @Any()): uint { + T := @TypeOf(needle) + if T != ^u8 & T != u8 { + @error("Type of needle must be string or char.\0") + } c := 0 - loop if *haystack == needle { - c += 1 - haystack += 1 - } else if *haystack == 0 return c else haystack += 1 -} + if T == u8 { + loop if *haystack == needle { + c += 1 + haystack += 1 + } else if *haystack == 0 return c else haystack += 1 + } else if T == ^u8 { + if *needle == 0 return 0 + loop if *haystack == 0 return c else { + if *haystack == *needle { + h := haystack + n := needle -count_str := fn(haystack: ^u8, needle: ^u8): uint { - if *needle == 0 return 0 - c := 0 - loop if *haystack == 0 return c else { - if *haystack == *needle { - h := haystack - n := needle - - loop { - n += 1 - h += 1 - if *n == 0 { - c += 1 - break - } else if *h == 0 | *h != *n { - break + loop { + n += 1 + h += 1 + if *n == 0 { + c += 1 + break + } else if *h == 0 | *h != *n { + break + } } } + haystack += 1 } - haystack += 1 } } diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index edca6d4..b07c9c3 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -5,7 +5,6 @@ devices := @use("devices.hb") controller := @use("controller.hb"); .{Info, Port} := controller mouse := @use("mouse.hb") -format_page := memory.dangling(u8) mouse_buffer := 0 keyboard_buffer := 0 @@ -73,7 +72,7 @@ process := fn(port: ^controller.Port): void { enable_streaming(port) } log.info("Identified device!\0") - log.info(string.display_int(port.device.value, format_page, 16)) + log.print(port.device.value, .{radix: 16}) } else { log.info("KEY PRESSED\0") } @@ -109,7 +108,6 @@ check_complete := fn(port: ^controller.Port): bool { main := fn(): void { mouse_buffer = buffer.create("PS/2 Mouse\0") - format_page = memory.alloc(u8, 1024) controller.init() diff --git a/sysdata/programs/ps2_driver/src/port.hb b/sysdata/programs/ps2_driver/src/port.hb index b00c52a..b06b1cd 100644 --- a/sysdata/programs/ps2_driver/src/port.hb +++ b/sysdata/programs/ps2_driver/src/port.hb @@ -15,7 +15,7 @@ Port := packed struct { $PORT_AT_STARTUP := Port.( true, NO_DEVICE, - .(0, 0, 0, 0, 0, 0, 0, 0), + .[0, 0, 0, 0, 0, 0, 0, 0], 0, true, -) +) \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/text.hb b/sysdata/programs/render_example/src/examples/text.hb index 0e89eb4..67db901 100644 --- a/sysdata/programs/render_example/src/examples/text.hb +++ b/sysdata/programs/render_example/src/examples/text.hb @@ -240,4 +240,4 @@ map_keys := fn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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \ No newline at end of file diff --git a/sysdata/programs/test/src/main.hb b/sysdata/programs/test/src/main.hb index f1bff3c..4995e0c 100644 --- a/sysdata/programs/test/src/main.hb +++ b/sysdata/programs/test/src/main.hb @@ -3,5 +3,5 @@ serial_driver := @use("./tests/serial_driver.hb") main := fn(): uint { // return serial_driver.test() - return stn.fmt.test() + return stn.hashers.test() } \ No newline at end of file diff --git a/sysdata/programs/test/src/tests/stn/dt.hb b/sysdata/programs/test/src/tests/stn/dt.hb index e331f33..b536c9b 100644 --- a/sysdata/programs/test/src/tests/stn/dt.hb +++ b/sysdata/programs/test/src/tests/stn/dt.hb @@ -1,18 +1,15 @@ -.{dt, memory, string, log} := @use("../../../../../libraries/stn/src/lib.hb") +.{dt, log} := @use("stn") test := fn(): uint { - buffer := memory.request_page(1) - - log.info(string.display_int(dt.get(int, "framebuffer/fb0/width\0"), buffer, 10)) - string.clear(buffer) - - log.info(string.display_int(dt.get(int, "cpu/cpu0/architecture\0"), buffer, 10)) - string.clear(buffer) + log.print(dt.get(int, "framebuffer/fb0/width\0"), .{}) + log.print(dt.get(int, "framebuffer/fb0/height\0"), .{}) + log.print(dt.get(^uint, "framebuffer/fb0/ptr\0"), .{}) + log.print(dt.get(int, "cpu/cpu0/architecture\0"), .{}) // 0 -> memory mapped // 1 -> port mapped - log.info(string.display_int(dt.get(int, "serial_ports/sp0/mapping\0"), buffer, 10)) + log.print(dt.get(int, "serial_ports/sp0/mapping\0"), .{}) return 0 } \ No newline at end of file diff --git a/sysdata/programs/test/src/tests/stn/fmt.hb b/sysdata/programs/test/src/tests/stn/fmt.hb index 661d638..a6f5753 100644 --- a/sysdata/programs/test/src/tests/stn/fmt.hb +++ b/sysdata/programs/test/src/tests/stn/fmt.hb @@ -30,6 +30,7 @@ test := fn(): uint { log.print(@as(?u32, null), .{}) log.print(@as(?u32, 200), .{}) log.print(.(@as(?u32, null), 200, 3.14), .{}) + log.printf("{}, {}, {}\0", .("Hello\0", math.PI, Color.{r: 101, g: 102, b: 103, a: 104}), .{}) return 0 } \ No newline at end of file diff --git a/sysdata/programs/test/src/tests/stn/hashers.hb b/sysdata/programs/test/src/tests/stn/hashers.hb index a1052d6..c68e779 100644 --- a/sysdata/programs/test/src/tests/stn/hashers.hb +++ b/sysdata/programs/test/src/tests/stn/hashers.hb @@ -1,9 +1,8 @@ -.{hashers, log, memory, string} := @use("../../../../../libraries/stn/src/lib.hb") +.{hashers, log, memory, string} := @use("stn") test := fn(): uint { - buffer := memory.request_page(1) target := "abcdefghijklmnop\0" - strings := [^u8].("abcdefshijklmnop\0", "abcdefghijklnnop\0", "abcdefshijklmnop\0", "abcdefghijklmnop\0", "abcdefghijflmnop\0", "dbcdefghijklmnop\0", "abcdefghijklmnop\0") + strings := .["abcdefshijklmnop\0", "abcdefghijklnnop\0", "abcdefshijklmnop\0", "abcdefghijklmnop\0", "abcdefghijflmnop\0", "dbcdefghijklmnop\0", "abcdefghijklmnop\0"] len := @sizeof(@TypeOf(strings)) / @sizeof(^u8) strlen := string.length(target) @@ -12,21 +11,16 @@ test := fn(): uint { hasher.write(target, strlen) correct := hasher.finish() - log.warn("target:\0") - log.warn(target) + log.printf("target string: {}, target hash: {}\0", .(target, correct), .{radix: 16}) i := 0 loop if i == len break else { defer i += 1 + hasher.reset() hasher.write(strings[i], strlen) d := hasher.finish() - if d == correct { - log.warn("match found\0") - } - log.info(strings[i]) - log.debug(string.display_int(@bitcast(d), buffer, 16)) - string.clear(buffer) + log.printf("matches: {}, string: {}, hash: {}\0", .(d == correct, strings[i], d), .{radix: 16}) } return 0 } \ No newline at end of file diff --git a/sysdata/programs/vfsaur/src/main.hb b/sysdata/programs/vfsaur/src/main.hb index c3c1faa..53a6ea4 100644 --- a/sysdata/programs/vfsaur/src/main.hb +++ b/sysdata/programs/vfsaur/src/main.hb @@ -1,22 +1,16 @@ stn := @use("stn"); -.{log} := stn; -.{info} := log; - -.{string} := stn; -.{split_str, iter_split_str} := string; -.{split, iter_split} := string; - -.{buffer} := stn +.{string, buffer, log} := stn; +.{info} := log main := fn(): int { log.info("VFSaur starting.\0") vfs_buff := buffer.create("VFS\0") full_path := "acs:/path/to/a/file\0" - splt := split(full_path, ':') - root := iter_split(&splt) - path := iter_split(&splt) + split := string.split(full_path, '/') + root := split.next() + path := split.next() if root == null { return 1 @@ -29,4 +23,4 @@ main := fn(): int { log.info(path) return 0 -} +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 37b428a..fe4f69a 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -23,15 +23,14 @@ resolution = "1024x768x24" [boot.limine.ableos.modules] +# [boot.limine.ableos.modules.render_example] +# path = "boot:///render_example.hbf" -[boot.limine.ableos.modules.render_example] -path = "boot:///render_example.hbf" +# [boot.limine.ableos.modules.sunset_server] +# path = "boot:///sunset_server.hbf" -[boot.limine.ableos.modules.sunset_server] -path = "boot:///sunset_server.hbf" - -[boot.limine.ableos.modules.ps2_mouse_driver] -path = "boot:///ps2_mouse_driver.hbf" +# [boot.limine.ableos.modules.ps2_mouse_driver] +# path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" @@ -51,9 +50,8 @@ path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.angels_halo] # path = "boot:///angels_halo.hbf" +[boot.limine.ableos.modules.test] +path = "boot:///test.hbf" -# [boot.limine.ableos.modules.test] -# path = "boot:///test.hbf" -# -[boot.limine.ableos.modules.vfsaur] -path = "boot:///vfsaur.hbf" +# [boot.limine.ableos.modules.vfsaur] +# path = "boot:///vfsaur.hbf"