From 4a3684c5e8f890f1638acf320a33597f5dc3dc68 Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Tue, 18 Jun 2024 11:35:35 -0400
Subject: [PATCH 01/25] Rename `write_ascii_table` to `write_plain_table`
---
core/text/table/doc.odin | 2 +-
core/text/table/table.odin | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/core/text/table/doc.odin b/core/text/table/doc.odin
index 76886bdea..cd14ab98f 100644
--- a/core/text/table/doc.odin
+++ b/core/text/table/doc.odin
@@ -59,7 +59,7 @@ This outputs:
build(tbl)
- write_ascii_table(stdio_writer(), tbl)
+ write_plain_table(stdio_writer(), tbl)
write_markdown_table(stdio_writer(), tbl)
This outputs:
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 5423519d3..d6e392a78 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -254,7 +254,7 @@ write_html_table :: proc(w: io.Writer, tbl: ^Table) {
io.write_string(w, "\n")
}
-write_ascii_table :: proc(w: io.Writer, tbl: ^Table) {
+write_plain_table :: proc(w: io.Writer, tbl: ^Table) {
if tbl.dirty {
build(tbl)
}
From b66b960e7eba25796f9d53b4110a91fc1c08d422 Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Tue, 18 Jun 2024 11:46:19 -0400
Subject: [PATCH 02/25] Don't `build` HTML tables
`build` only recalculates length and width information, and this is not
needed for HTML tables.
---
core/text/table/table.odin | 4 ----
1 file changed, 4 deletions(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index d6e392a78..91a0de35d 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -198,10 +198,6 @@ build :: proc(tbl: ^Table) {
}
write_html_table :: proc(w: io.Writer, tbl: ^Table) {
- if tbl.dirty {
- build(tbl)
- }
-
io.write_string(w, "
\n")
if tbl.caption != "" {
io.write_string(w, "")
From 2241ca8e72783d3010ca9515f72830c174d05e2a Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Tue, 18 Jun 2024 12:07:45 -0400
Subject: [PATCH 03/25] Use tabs to indent HTML tables
---
core/text/table/table.odin | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 91a0de35d..ac2d12a76 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -200,7 +200,7 @@ build :: proc(tbl: ^Table) {
write_html_table :: proc(w: io.Writer, tbl: ^Table) {
io.write_string(w, "\n")
if tbl.caption != "" {
- io.write_string(w, "")
+ io.write_string(w, "\t")
io.write_string(w, tbl.caption)
io.write_string(w, "\n")
}
@@ -215,37 +215,37 @@ write_html_table :: proc(w: io.Writer, tbl: ^Table) {
}
if tbl.has_header_row {
- io.write_string(w, "\n")
- io.write_string(w, " \n")
+ io.write_string(w, "\t\n")
+ io.write_string(w, "\t\t\n")
for col in 0..")
io.write_string(w, cell.text)
io.write_string(w, "\n")
}
- io.write_string(w, "
\n")
- io.write_string(w, "\n")
+ io.write_string(w, "\t\t
\n")
+ io.write_string(w, "\t\n")
}
- io.write_string(w, "\n")
+ io.write_string(w, "\t\n")
for row in 0..\n")
+ io.write_string(w, "\t\t\n")
for col in 0..")
io.write_string(w, cell.text)
io.write_string(w, "\n")
}
- io.write_string(w, "
\n")
+ io.write_string(w, "\t\t\n")
}
- io.write_string(w, " \n")
+ io.write_string(w, "\t\n")
io.write_string(w, "
\n")
}
From dd099d9dd6b565d1fe5c1d8ee89156cee358a051 Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Thu, 20 Jun 2024 14:38:20 -0400
Subject: [PATCH 04/25] Add Unicode support to `core:text/table`
---
core/text/table/table.odin | 69 ++++++++++++++++++++++----------------
1 file changed, 41 insertions(+), 28 deletions(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index ac2d12a76..1fbd665ef 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -4,6 +4,7 @@
List of contributors:
oskarnp: Initial implementation.
+ Feoramund: Unicode support.
*/
package text_table
@@ -12,10 +13,12 @@ import "core:io"
import "core:fmt"
import "core:mem"
import "core:mem/virtual"
+import "core:unicode/utf8"
import "base:runtime"
Cell :: struct {
text: string,
+ width: int,
alignment: Cell_Alignment,
}
@@ -25,6 +28,9 @@ Cell_Alignment :: enum {
Right,
}
+// Determines the width of a string used in the table for alignment purposes.
+Width_Proc :: #type proc(str: string) -> int
+
Table :: struct {
lpad, rpad: int, // Cell padding (left/right)
cells: [dynamic]Cell,
@@ -37,10 +43,19 @@ Table :: struct {
dirty: bool, // True if build() needs to be called before rendering
// The following are computed on build()
- colw: [dynamic]int, // Width of each column (including padding, excluding borders)
+ colw: [dynamic]int, // Width of each column (excluding padding and borders)
tblw: int, // Width of entire table (including padding, excluding borders)
}
+ascii_width_proc :: proc(str: string) -> int {
+ return len(str)
+}
+
+unicode_width_proc :: proc(str: string) -> (width: int) {
+ _, _, width = #force_inline utf8.grapheme_count(str)
+ return
+}
+
init :: proc{init_with_allocator, init_with_virtual_arena, init_with_mem_arena}
init_with_allocator :: proc(tbl: ^Table, format_allocator := context.temp_allocator, table_allocator := context.allocator) -> ^Table {
@@ -165,7 +180,7 @@ first_row :: proc(tbl: ^Table) -> int {
return header_row(tbl)+1 if tbl.has_header_row else 0
}
-build :: proc(tbl: ^Table) {
+build :: proc(tbl: ^Table, width_proc: Width_Proc) {
tbl.dirty = false
resize(&tbl.colw, tbl.nr_cols)
@@ -174,18 +189,17 @@ build :: proc(tbl: ^Table) {
for row in 0.. tbl.colw[col] {
- tbl.colw[col] = w
- }
+ cell.width = width_proc(cell.text)
+ tbl.colw[col] = max(tbl.colw[col], cell.width)
}
}
colw_sum := 0
for v in tbl.colw {
- colw_sum += v
+ colw_sum += v + tbl.lpad + tbl.rpad
}
- tbl.tblw = max(colw_sum, len(tbl.caption) + tbl.lpad + tbl.rpad)
+ tbl.tblw = max(colw_sum, width_proc(tbl.caption) + tbl.lpad + tbl.rpad)
// Resize columns to match total width of table
remain := tbl.tblw-colw_sum
@@ -251,8 +265,10 @@ write_html_table :: proc(w: io.Writer, tbl: ^Table) {
}
write_plain_table :: proc(w: io.Writer, tbl: ^Table) {
+ WIDTH_PROC :: unicode_width_proc
+
if tbl.dirty {
- build(tbl)
+ build(tbl, WIDTH_PROC)
}
write_caption_separator :: proc(w: io.Writer, tbl: ^Table) {
@@ -267,7 +283,7 @@ write_plain_table :: proc(w: io.Writer, tbl: ^Table) {
if col == 0 {
io.write_byte(w, '+')
}
- write_byte_repeat(w, tbl.colw[col], '-')
+ write_byte_repeat(w, tbl.colw[col] + tbl.lpad + tbl.rpad, '-')
io.write_byte(w, '+')
}
io.write_byte(w, '\n')
@@ -276,8 +292,8 @@ write_plain_table :: proc(w: io.Writer, tbl: ^Table) {
if tbl.caption != "" {
write_caption_separator(w, tbl)
io.write_byte(w, '|')
- write_text_align(w, tbl.tblw - tbl.lpad - tbl.rpad + tbl.nr_cols - 1,
- tbl.lpad, tbl.rpad, tbl.caption, .Center)
+ write_text_align(w, tbl.caption, .Center,
+ tbl.lpad, tbl.rpad, tbl.tblw + tbl.nr_cols - 1 - WIDTH_PROC(tbl.caption) - tbl.lpad - tbl.rpad)
io.write_byte(w, '|')
io.write_byte(w, '\n')
}
@@ -302,19 +318,20 @@ write_plain_table :: proc(w: io.Writer, tbl: ^Table) {
// Renders table according to GitHub Flavored Markdown (GFM) specification
write_markdown_table :: proc(w: io.Writer, tbl: ^Table) {
// NOTE(oskar): Captions or colspans are not supported by GFM as far as I can tell.
+ WIDTH_PROC :: unicode_width_proc
if tbl.dirty {
- build(tbl)
+ build(tbl, WIDTH_PROC)
}
for row in 0..
Date: Thu, 20 Jun 2024 14:59:46 -0400
Subject: [PATCH 05/25] Optimize printing of markdown tables
Check only once if the table has a header row, instead of every row.
---
core/text/table/table.odin | 57 +++++++++++++++++++++++---------------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 1fbd665ef..d555c3fe8 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -324,9 +324,8 @@ write_markdown_table :: proc(w: io.Writer, tbl: ^Table) {
build(tbl, WIDTH_PROC)
}
- for row in 0..
Date: Thu, 20 Jun 2024 15:26:00 -0400
Subject: [PATCH 06/25] Remove unneeded `loc` argument
---
core/text/table/table.odin | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index d555c3fe8..91094d985 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -127,7 +127,7 @@ set_cell_alignment :: proc(tbl: ^Table, row, col: int, alignment: Cell_Alignment
tbl.dirty = true
}
-format :: proc(tbl: ^Table, _fmt: string, args: ..any, loc := #caller_location) -> string {
+format :: proc(tbl: ^Table, _fmt: string, args: ..any) -> string {
context.allocator = tbl.format_allocator
return fmt.aprintf(_fmt, ..args)
}
From 585747bbbf1e78317efed4a038f763756f70809f Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Thu, 20 Jun 2024 15:27:06 -0400
Subject: [PATCH 07/25] Clarify error message
---
core/text/table/table.odin | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 91094d985..90f759c8a 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -155,7 +155,7 @@ header :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
row :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
if tbl.nr_cols == 0 {
if len(values) == 0 {
- panic("Cannot create row without values unless knowing amount of columns in advance")
+ panic("Cannot create empty row unless the number of columns is known in advance")
} else {
tbl.nr_cols = len(values)
}
From b81458073e119e08d7d14c39995731741e23e4f3 Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Thu, 20 Jun 2024 17:15:34 -0400
Subject: [PATCH 08/25] Add new API to `core:text/table`
- `header/row_of_values`, same `header/row`, more verbose name
- `aligned_header/row_of_values`, set alignment for an entire row
- `header/row_of_aligned_values`, set alignment per value
---
core/text/table/table.odin | 150 +++++++++++++++++++++++++++++++------
1 file changed, 128 insertions(+), 22 deletions(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 90f759c8a..7b8e654ce 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -28,6 +28,11 @@ Cell_Alignment :: enum {
Right,
}
+Aligned_Value :: struct {
+ alignment: Cell_Alignment,
+ value: any,
+}
+
// Determines the width of a string used in the table for alignment purposes.
Width_Proc :: #type proc(str: string) -> int
@@ -96,28 +101,27 @@ get_cell :: proc(tbl: ^Table, row, col: int, loc := #caller_location) -> ^Cell {
return &tbl.cells[row*tbl.nr_cols + col]
}
-set_cell_value_and_alignment :: proc(tbl: ^Table, row, col: int, value: string, alignment: Cell_Alignment) {
- cell := get_cell(tbl, row, col)
- cell.text = format(tbl, "%v", value)
- cell.alignment = alignment
- tbl.dirty = true
+@private
+to_string :: #force_inline proc(tbl: ^Table, value: any, loc := #caller_location) -> (result: string) {
+ switch val in value {
+ case nil:
+ result = ""
+ case string:
+ result = val
+ case cstring:
+ result = cast(string)val
+ case:
+ result = format(tbl, "%v", val)
+ if result == "" {
+ fmt.eprintf("{} text/table: format() resulted in empty string (arena out of memory?)\n", loc)
+ }
+ }
+ return
}
set_cell_value :: proc(tbl: ^Table, row, col: int, value: any, loc := #caller_location) {
cell := get_cell(tbl, row, col, loc)
- switch val in value {
- case nil:
- cell.text = ""
- case string:
- cell.text = string(val)
- case cstring:
- cell.text = string(val)
- case:
- cell.text = format(tbl, "%v", val)
- if cell.text == "" {
- fmt.eprintf("{} text/table: format() resulted in empty string (arena out of memory?)\n", loc)
- }
- }
+ cell.text = to_string(tbl, value, loc)
tbl.dirty = true
}
@@ -127,12 +131,20 @@ set_cell_alignment :: proc(tbl: ^Table, row, col: int, alignment: Cell_Alignment
tbl.dirty = true
}
+set_cell_value_and_alignment :: proc(tbl: ^Table, row, col: int, value: any, alignment: Cell_Alignment, loc := #caller_location) {
+ cell := get_cell(tbl, row, col, loc)
+ cell.text = to_string(tbl, value, loc)
+ cell.alignment = alignment
+ tbl.dirty = true
+}
+
format :: proc(tbl: ^Table, _fmt: string, args: ..any) -> string {
context.allocator = tbl.format_allocator
return fmt.aprintf(_fmt, ..args)
}
-header :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
+header :: header_of_values
+header_of_values :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
if (tbl.has_header_row && tbl.nr_rows != 1) || (!tbl.has_header_row && tbl.nr_rows != 0) {
panic("Cannot add headers after rows have been added", loc)
}
@@ -152,7 +164,48 @@ header :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
tbl.dirty = true
}
-row :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
+aligned_header_of_values :: proc(tbl: ^Table, alignment: Cell_Alignment, values: ..any, loc := #caller_location) {
+ if (tbl.has_header_row && tbl.nr_rows != 1) || (!tbl.has_header_row && tbl.nr_rows != 0) {
+ panic("Cannot add headers after rows have been added", loc)
+ }
+
+ if tbl.nr_rows == 0 {
+ tbl.nr_rows += 1
+ tbl.has_header_row = true
+ }
+
+ col := tbl.nr_cols
+ tbl.nr_cols += len(values)
+ for val in values {
+ set_cell_value_and_alignment(tbl, header_row(tbl), col, val, alignment, loc)
+ col += 1
+ }
+
+ tbl.dirty = true
+}
+
+header_of_aligned_values :: proc(tbl: ^Table, aligned_values: []Aligned_Value, loc := #caller_location) {
+ if (tbl.has_header_row && tbl.nr_rows != 1) || (!tbl.has_header_row && tbl.nr_rows != 0) {
+ panic("Cannot add headers after rows have been added", loc)
+ }
+
+ if tbl.nr_rows == 0 {
+ tbl.nr_rows += 1
+ tbl.has_header_row = true
+ }
+
+ col := tbl.nr_cols
+ tbl.nr_cols += len(aligned_values)
+ for av in aligned_values {
+ set_cell_value_and_alignment(tbl, header_row(tbl), col, av.value, av.alignment, loc)
+ col += 1
+ }
+
+ tbl.dirty = true
+}
+
+row :: row_of_values
+row_of_values :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
if tbl.nr_cols == 0 {
if len(values) == 0 {
panic("Cannot create empty row unless the number of columns is known in advance")
@@ -160,14 +213,67 @@ row :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
tbl.nr_cols = len(values)
}
}
+
tbl.nr_rows += 1
- for col in 0.. int {
return tbl.nr_rows - 1
}
From 82d92dc46c6ef2a8f1b833efd487c5829673a2ed Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Thu, 20 Jun 2024 17:20:21 -0400
Subject: [PATCH 09/25] Use `log.error` instead of `eprintf`
---
core/text/table/table.odin | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 7b8e654ce..99f4180a3 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -11,6 +11,7 @@ package text_table
import "core:io"
import "core:fmt"
+import "core:log"
import "core:mem"
import "core:mem/virtual"
import "core:unicode/utf8"
@@ -113,7 +114,7 @@ to_string :: #force_inline proc(tbl: ^Table, value: any, loc := #caller_location
case:
result = format(tbl, "%v", val)
if result == "" {
- fmt.eprintf("{} text/table: format() resulted in empty string (arena out of memory?)\n", loc)
+ log.error("text/table.format() resulted in empty string (arena out of memory?)", location = loc)
}
}
return
From bf44a94065f30e3f0aa4f68d69646d63e72a08dd Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Thu, 20 Jun 2024 18:22:03 -0400
Subject: [PATCH 10/25] Update `core:text/table` documentation
---
core/text/table/doc.odin | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/core/text/table/doc.odin b/core/text/table/doc.odin
index cd14ab98f..fc87c59b1 100644
--- a/core/text/table/doc.odin
+++ b/core/text/table/doc.odin
@@ -1,5 +1,5 @@
/*
-The package `table` implements ASCII/markdown/HTML/custom rendering of tables.
+The package `table` implements plain-text/markdown/HTML/custom rendering of tables.
**Custom rendering example:**
@@ -7,7 +7,7 @@ The package `table` implements ASCII/markdown/HTML/custom rendering of tables.
padding(tbl, 0, 1)
row(tbl, "A_LONG_ENUM", "= 54,", "// A comment about A_LONG_ENUM")
row(tbl, "AN_EVEN_LONGER_ENUM", "= 1,", "// A comment about AN_EVEN_LONGER_ENUM")
- build(tbl)
+ build(tbl, table.unicode_width_proc)
for row in 0..
Date: Sun, 23 Jun 2024 22:19:29 +0200
Subject: [PATCH 11/25] wgpu import
---
vendor/wgpu/wgpu.odin | 2 ++
1 file changed, 2 insertions(+)
diff --git a/vendor/wgpu/wgpu.odin b/vendor/wgpu/wgpu.odin
index 1a89c9132..a2b24fb7a 100644
--- a/vendor/wgpu/wgpu.odin
+++ b/vendor/wgpu/wgpu.odin
@@ -25,6 +25,8 @@ when ODIN_OS == .Windows {
"system:ntdll.lib",
"system:opengl32.lib",
"system:advapi32.lib",
+ "system:user32.lib",
+ "system:gdi32.lib",
}
} else when ODIN_OS == .Darwin {
@(private) ARCH :: "x86_64" when ODIN_ARCH == .amd64 else "aarch64" when ODIN_ARCH == .arm64 else #panic("unsupported WGPU Native architecture")
From 67b4cb003892903df70e78ce0960fb96ad1c6df0 Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Mon, 24 Jun 2024 13:18:54 -0400
Subject: [PATCH 12/25] Crunch the ranges
---
core/text/table/table.odin | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 99f4180a3..4233902c8 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -217,7 +217,7 @@ row_of_values :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
tbl.nr_rows += 1
- for col in 0 ..< tbl.nr_cols {
+ for col in 0..
Date: Mon, 24 Jun 2024 13:38:59 -0400
Subject: [PATCH 13/25] Let `WIDTH_PROC` be specified as proc argument to
`write_*_table`
---
core/text/table/table.odin | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 4233902c8..881af1fb5 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -371,11 +371,9 @@ write_html_table :: proc(w: io.Writer, tbl: ^Table) {
io.write_string(w, "
\n")
}
-write_plain_table :: proc(w: io.Writer, tbl: ^Table) {
- WIDTH_PROC :: unicode_width_proc
-
+write_plain_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc = unicode_width_proc) {
if tbl.dirty {
- build(tbl, WIDTH_PROC)
+ build(tbl, width_proc)
}
write_caption_separator :: proc(w: io.Writer, tbl: ^Table) {
@@ -400,7 +398,7 @@ write_plain_table :: proc(w: io.Writer, tbl: ^Table) {
write_caption_separator(w, tbl)
io.write_byte(w, '|')
write_text_align(w, tbl.caption, .Center,
- tbl.lpad, tbl.rpad, tbl.tblw + tbl.nr_cols - 1 - WIDTH_PROC(tbl.caption) - tbl.lpad - tbl.rpad)
+ tbl.lpad, tbl.rpad, tbl.tblw + tbl.nr_cols - 1 - width_proc(tbl.caption) - tbl.lpad - tbl.rpad)
io.write_byte(w, '|')
io.write_byte(w, '\n')
}
@@ -423,12 +421,10 @@ write_plain_table :: proc(w: io.Writer, tbl: ^Table) {
}
// Renders table according to GitHub Flavored Markdown (GFM) specification
-write_markdown_table :: proc(w: io.Writer, tbl: ^Table) {
+write_markdown_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc = unicode_width_proc) {
// NOTE(oskar): Captions or colspans are not supported by GFM as far as I can tell.
- WIDTH_PROC :: unicode_width_proc
-
if tbl.dirty {
- build(tbl, WIDTH_PROC)
+ build(tbl, width_proc)
}
write_row :: proc(w: io.Writer, tbl: ^Table, row: int, alignment: Cell_Alignment = .Left) {
From 7da96c484d34a1c3b8747a2db89b504fb7bab79c Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Mon, 24 Jun 2024 14:28:05 -0400
Subject: [PATCH 14/25] Remove `table.dirty`
---
core/text/table/table.odin | 29 ++---------------------------
1 file changed, 2 insertions(+), 27 deletions(-)
diff --git a/core/text/table/table.odin b/core/text/table/table.odin
index 881af1fb5..7b4942478 100644
--- a/core/text/table/table.odin
+++ b/core/text/table/table.odin
@@ -46,8 +46,6 @@ Table :: struct {
table_allocator: runtime.Allocator, // Used for allocating cells/colw
format_allocator: runtime.Allocator, // Used for allocating Cell.text when applicable
- dirty: bool, // True if build() needs to be called before rendering
-
// The following are computed on build()
colw: [dynamic]int, // Width of each column (excluding padding and borders)
tblw: int, // Width of entire table (including padding, excluding borders)
@@ -86,13 +84,11 @@ destroy :: proc(tbl: ^Table) {
caption :: proc(tbl: ^Table, value: string) {
tbl.caption = value
- tbl.dirty = true
}
padding :: proc(tbl: ^Table, lpad, rpad: int) {
tbl.lpad = lpad
tbl.rpad = rpad
- tbl.dirty = true
}
get_cell :: proc(tbl: ^Table, row, col: int, loc := #caller_location) -> ^Cell {
@@ -123,20 +119,17 @@ to_string :: #force_inline proc(tbl: ^Table, value: any, loc := #caller_location
set_cell_value :: proc(tbl: ^Table, row, col: int, value: any, loc := #caller_location) {
cell := get_cell(tbl, row, col, loc)
cell.text = to_string(tbl, value, loc)
- tbl.dirty = true
}
set_cell_alignment :: proc(tbl: ^Table, row, col: int, alignment: Cell_Alignment, loc := #caller_location) {
cell := get_cell(tbl, row, col, loc)
cell.alignment = alignment
- tbl.dirty = true
}
set_cell_value_and_alignment :: proc(tbl: ^Table, row, col: int, value: any, alignment: Cell_Alignment, loc := #caller_location) {
cell := get_cell(tbl, row, col, loc)
cell.text = to_string(tbl, value, loc)
cell.alignment = alignment
- tbl.dirty = true
}
format :: proc(tbl: ^Table, _fmt: string, args: ..any) -> string {
@@ -161,8 +154,6 @@ header_of_values :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
set_cell_value(tbl, header_row(tbl), col, val, loc)
col += 1
}
-
- tbl.dirty = true
}
aligned_header_of_values :: proc(tbl: ^Table, alignment: Cell_Alignment, values: ..any, loc := #caller_location) {
@@ -181,8 +172,6 @@ aligned_header_of_values :: proc(tbl: ^Table, alignment: Cell_Alignment, values:
set_cell_value_and_alignment(tbl, header_row(tbl), col, val, alignment, loc)
col += 1
}
-
- tbl.dirty = true
}
header_of_aligned_values :: proc(tbl: ^Table, aligned_values: []Aligned_Value, loc := #caller_location) {
@@ -201,8 +190,6 @@ header_of_aligned_values :: proc(tbl: ^Table, aligned_values: []Aligned_Value, l
set_cell_value_and_alignment(tbl, header_row(tbl), col, av.value, av.alignment, loc)
col += 1
}
-
- tbl.dirty = true
}
row :: row_of_values
@@ -221,8 +208,6 @@ row_of_values :: proc(tbl: ^Table, values: ..any, loc := #caller_location) {
val := values[col] if col < len(values) else nil
set_cell_value(tbl, last_row(tbl), col, val, loc)
}
-
- tbl.dirty = true
}
aligned_row_of_values :: proc(tbl: ^Table, alignment: Cell_Alignment, values: ..any, loc := #caller_location) {
@@ -240,8 +225,6 @@ aligned_row_of_values :: proc(tbl: ^Table, alignment: Cell_Alignment, values: ..
val := values[col] if col < len(values) else nil
set_cell_value_and_alignment(tbl, last_row(tbl), col, val, alignment, loc)
}
-
- tbl.dirty = true
}
row_of_aligned_values :: proc(tbl: ^Table, aligned_values: []Aligned_Value, loc := #caller_location) {
@@ -264,8 +247,6 @@ row_of_aligned_values :: proc(tbl: ^Table, aligned_values: []Aligned_Value, loc
set_cell_value_and_alignment(tbl, last_row(tbl), col, "", .Left, loc)
}
}
-
- tbl.dirty = true
}
// TODO: This should work correctly when #3262 is fixed.
@@ -288,8 +269,6 @@ first_row :: proc(tbl: ^Table) -> int {
}
build :: proc(tbl: ^Table, width_proc: Width_Proc) {
- tbl.dirty = false
-
resize(&tbl.colw, tbl.nr_cols)
mem.zero_slice(tbl.colw[:])
@@ -372,9 +351,7 @@ write_html_table :: proc(w: io.Writer, tbl: ^Table) {
}
write_plain_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc = unicode_width_proc) {
- if tbl.dirty {
- build(tbl, width_proc)
- }
+ build(tbl, width_proc)
write_caption_separator :: proc(w: io.Writer, tbl: ^Table) {
io.write_byte(w, '+')
@@ -423,9 +400,7 @@ write_plain_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc = un
// Renders table according to GitHub Flavored Markdown (GFM) specification
write_markdown_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc = unicode_width_proc) {
// NOTE(oskar): Captions or colspans are not supported by GFM as far as I can tell.
- if tbl.dirty {
- build(tbl, width_proc)
- }
+ build(tbl, width_proc)
write_row :: proc(w: io.Writer, tbl: ^Table, row: int, alignment: Cell_Alignment = .Left) {
for col in 0..
Date: Mon, 24 Jun 2024 14:37:02 -0400
Subject: [PATCH 15/25] Add `Width_Proc` documentation
---
core/text/table/doc.odin | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/core/text/table/doc.odin b/core/text/table/doc.odin
index fc87c59b1..952412f82 100644
--- a/core/text/table/doc.odin
+++ b/core/text/table/doc.odin
@@ -91,5 +91,36 @@ constructing a table, you can use `aligned_row_of_values` or
table.aligned_row_of_values(&tbl, .Center, "Foo", "Bar")
table.row_of_aligned_values(&tbl, {{.Center, "Foo"}, {.Right, "Bar"}})
+**Regarding `Width_Procs`:**
+
+If you know ahead of time that all the text you're parsing is ASCII, instead of
+Unicode, it is more efficient to use `table.ascii_width_proc` instead of the
+default `unicode_width_proc`, as that procedure has to perform in-depth lookups
+to determine multiple Unicode characteristics of the codepoints parsed in order
+to get the proper alignment for a variety of different scripts.
+
+For example, you may do this instead:
+
+ table.write_plain_table(stdout, tbl, table.ascii_width_proc)
+ table.write_markdown_table(stdout, tbl, table.ascii_width_proc)
+
+The output will still be the same, but the preprocessing is much faster.
+
+
+You may also supply your own `Width_Proc`s, if you know more about how the text
+is structured than what we can assume.
+
+ simple_cjk_width_proc :: proc(str: string) -> (result: int) {
+ for r in str {
+ result += 2
+ }
+ return
+ }
+
+ table.write_plain_table(stdout, tbl, simple_cjk_width_proc)
+
+This procedure will output 2 times the number of UTF-8 runes in a string, a
+simple heuristic for CJK-only wide text.
+
*/
package text_table
From f325a08e57e78a66bb3fc56b8e26e33468b7107c Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Mon, 24 Jun 2024 14:45:38 -0400
Subject: [PATCH 16/25] Make `core:text/table` examples more complete
They should be completely copy-and-paste friendly now, without the
assumption of someone using `using table`.
---
core/text/table/doc.odin | 100 +++++++++++++++++++++++----------------
1 file changed, 60 insertions(+), 40 deletions(-)
diff --git a/core/text/table/doc.odin b/core/text/table/doc.odin
index 952412f82..8bcd04ceb 100644
--- a/core/text/table/doc.odin
+++ b/core/text/table/doc.odin
@@ -3,16 +3,25 @@ The package `table` implements plain-text/markdown/HTML/custom rendering of tabl
**Custom rendering example:**
- tbl := init(&Table{})
- padding(tbl, 0, 1)
- row(tbl, "A_LONG_ENUM", "= 54,", "// A comment about A_LONG_ENUM")
- row(tbl, "AN_EVEN_LONGER_ENUM", "= 1,", "// A comment about AN_EVEN_LONGER_ENUM")
- build(tbl, table.unicode_width_proc)
- for row in 0..
Date: Mon, 24 Jun 2024 14:50:49 -0400
Subject: [PATCH 17/25] Add complete example showcasing Unicode support
---
core/text/table/doc.odin | 81 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/core/text/table/doc.odin b/core/text/table/doc.odin
index 8bcd04ceb..877970a35 100644
--- a/core/text/table/doc.odin
+++ b/core/text/table/doc.odin
@@ -142,5 +142,86 @@ is structured than what we can assume.
This procedure will output 2 times the number of UTF-8 runes in a string, a
simple heuristic for CJK-only wide text.
+**Unicode Support:**
+
+This package makes use of the `grapheme_count` procedure from the
+`core:unicode/utf8` package. It is a complete, standards-compliant
+implementation for counting graphemes and calculating visual width of a Unicode
+grapheme cluster in monospace cells.
+
+Here is a full example of how well-supported Unicode is with this package:
+
+ package main
+
+ import "core:fmt"
+ import "core:io"
+ import "core:os"
+ import "core:text/table"
+
+ scripts :: proc(w: io.Writer) {
+ t: table.Table
+ table.init(&t)
+ table.caption(&t, "Tést Suite")
+ table.padding(&t, 1, 3)
+ table.header_of_aligned_values(&t, {{.Left, "Script"}, {.Center, "Sample"}})
+
+ table.row(&t, "Latin", "At vero eos et accusamus et iusto odio dignissimos ducimus,")
+ table.row(&t, "Cyrillic", "Ру́сский язы́к — язык восточнославянской группы славянской")
+ table.row(&t, "Greek", "Η ελληνική γλώσσα ανήκει στην ινδοευρωπαϊκή οικογένεια")
+ table.row(&t, "Younger Futhark", "ᚴᚢᚱᛘᛦ ᚴᚢᚾᚢᚴᛦ ᚴᛅᚱᚦᛁ ᚴᚢᛒᛚ ᚦᚢᛋᛁ ᛅᚠᛏ ᚦᚢᚱᚢᛁ ᚴᚢᚾᚢ ᛋᛁᚾᛅ ᛏᛅᚾᛘᛅᚱᚴᛅᛦ ᛒᚢᛏ")
+ table.row(&t, "Chinese hanzi", "官話為汉语的一支,主體分布在中国北部和西南部的大部分地区。")
+ table.row(&t, "Japanese kana", "いろはにほへとちりぬるをわかよたれそつねならむ")
+ table.row(&t, "Korean hangul", "한글, 조선글은 한국어의 공식문자로서, 세종이 한국어를")
+ table.row(&t, "Thai", "ภาษาไทย หรือ ภาษาไทยกลาง เป็นภาษาในกลุ่มภาษาไท ซึ่งเป็นกลุ่มย่อยของตระกูลภาษาขร้า-ไท")
+ table.row(&t, "Georgian", "ქართული ენა — ქართველურ ენათა ოჯახის ენა. ქართველების მშობლიური ენა,")
+ table.row(&t, "Armenian", "Իր շուրջ հինգհազարամյա գոյության ընթացքում հայերենը շփվել է տարբեր")
+ table.row(&t)
+ table.row_of_aligned_values(&t, {{.Left, "Arabic"}, {.Right, "ٱللُّغَةُ ٱلْعَرَبِيَّة هي أكثر اللغات السامية تحدثًا، وإحدى أكثر"}})
+ table.row_of_aligned_values(&t, {{.Left, "Hebrew"}, {.Right, "עִבְרִית היא שפה שמית, ממשפחת השפות האפרו-אסייתיות, הידועה"}})
+ table.row(&t)
+ table.row(&t, "Swedish", "Växjö [ˈvɛkːˌɧøː] är en tätort i södra Smålands inland samt centralort i Växjö kommun")
+ table.row(&t, "Saxon", "Hwæt! We Gardena in geardagum, þeodcyninga, þrym gefrunon, hu ða æþelingas ellen fremedon.")
+ table.row(&t)
+ table.aligned_row_of_values(&t, .Center, "Emoji (Single codepoints)", "\U0001f4ae \U0001F600 \U0001F201 \U0001F21A")
+ table.row(&t, "Excessive Diacritics", "H̷e̶l̵l̸o̴p̵e̷ ̸w̶o̸r̵l̶d̵!̴")
+
+ table.write_plain_table(w, &t)
+ fmt.println()
+ }
+
+ main :: proc() {
+ stdout := os.stream_from_handle(os.stdout)
+
+ scripts(stdout)
+ }
+
+This will print out:
+
+ +----------------------------------------------------------------------------------------------------------------------------+
+ | Tést Suite |
+ +-----------------------------+----------------------------------------------------------------------------------------------+
+ | Script | Sample |
+ +-----------------------------+----------------------------------------------------------------------------------------------+
+ | Latin | At vero eos et accusamus et iusto odio dignissimos ducimus, |
+ | Cyrillic | Ру́сский язы́к — язык восточнославянской группы славянской |
+ | Greek | Η ελληνική γλώσσα ανήκει στην ινδοευρωπαϊκή οικογένεια |
+ | Younger Futhark | ᚴᚢᚱᛘᛦ ᚴᚢᚾᚢᚴᛦ ᚴᛅᚱᚦᛁ ᚴᚢᛒᛚ ᚦᚢᛋᛁ ᛅᚠᛏ ᚦᚢᚱᚢᛁ ᚴᚢᚾᚢ ᛋᛁᚾᛅ ᛏᛅᚾᛘᛅᚱᚴᛅᛦ ᛒᚢᛏ |
+ | Chinese hanzi | 官話為汉语的一支,主體分布在中国北部和西南部的大部分地区。 |
+ | Japanese kana | いろはにほへとちりぬるをわかよたれそつねならむ |
+ | Korean hangul | 한글, 조선글은 한국어의 공식문자로서, 세종이 한국어를 |
+ | Thai | ภาษาไทย หรือ ภาษาไทยกลาง เป็นภาษาในกลุ่มภาษาไท ซึ่งเป็นกลุ่มย่อยของตระกูลภาษาขร้า-ไท |
+ | Georgian | ქართული ენა — ქართველურ ენათა ოჯახის ენა. ქართველების მშობლიური ენა, |
+ | Armenian | Իր շուրջ հինգհազարամյա գոյության ընթացքում հայերենը շփվել է տարբեր |
+ | | |
+ | Arabic | ٱللُّغَةُ ٱلْعَرَبِيَّة هي أكثر اللغات السامية تحدثًا، وإحدى أكثر |
+ | Hebrew | עִבְרִית היא שפה שמית, ממשפחת השפות האפרו-אסייתיות, הידועה |
+ | | |
+ | Swedish | Växjö [ˈvɛkːˌɧøː] är en tätort i södra Smålands inland samt centralort i Växjö kommun |
+ | Saxon | Hwæt! We Gardena in geardagum, þeodcyninga, þrym gefrunon, hu ða æþelingas ellen fremedon. |
+ | | |
+ | Emoji (Single codepoints) | 💮 😀 🈁 🈚 |
+ | Excessive Diacritics | H̷e̶l̵l̸o̴p̵e̷ ̸w̶o̸r̵l̶d̵!̴ |
+ +-----------------------------+----------------------------------------------------------------------------------------------+
+
*/
package text_table
From 8b05ec17652543fce3bd0fc66b48c0489a5b8740 Mon Sep 17 00:00:00 2001
From: Feoramund <161657516+Feoramund@users.noreply.github.com>
Date: Mon, 24 Jun 2024 15:00:21 -0400
Subject: [PATCH 18/25] Add string caching example documentation
---
core/text/table/doc.odin | 42 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/core/text/table/doc.odin b/core/text/table/doc.odin
index 877970a35..30358f31e 100644
--- a/core/text/table/doc.odin
+++ b/core/text/table/doc.odin
@@ -111,6 +111,48 @@ constructing a table, you can use `aligned_row_of_values` or
table.aligned_row_of_values(tbl, .Center, "Foo", "Bar")
table.row_of_aligned_values(tbl, {{.Center, "Foo"}, {.Right, "Bar"}})
+**Caching Results:**
+
+If you only need to build a table once but display it potentially many times,
+it may be more efficient to cache the results of your write into a string.
+
+Here's an example of how you can do that:
+
+ package main
+
+ import "core:fmt"
+ import "core:strings"
+ import "core:text/table"
+
+ main :: proc() {
+ string_buffer := strings.builder_make()
+ defer strings.builder_destroy(&string_buffer)
+
+ {
+ tbl: table.Table
+ table.init(&tbl)
+ defer table.destroy(&tbl)
+ table.caption(&tbl, "Hellope!")
+ table.row(&tbl, "Hellope", "World")
+
+ builder_writer := strings.to_writer(&string_buffer)
+
+ // The written table will be cached into the string builder after this call.
+ table.write_plain_table(builder_writer, &tbl)
+ }
+ // The table is inaccessible, now that we're back in the first-level scope.
+
+ // But now the results are stored in the string builder, which can be converted to a string.
+ my_table_string := strings.to_string(string_buffer)
+
+ // Remember that the string's allocated backing data lives in the
+ // builder and must still be freed.
+ //
+ // The deferred call to `builder_destroy` will take care of that for us
+ // in this simple example.
+ fmt.println(my_table_string)
+ }
+
**Regarding `Width_Procs`:**
If you know ahead of time that all the text you're parsing is ASCII, instead of
From d3d73590d3a393756ce39920cce3f9b02705d95d Mon Sep 17 00:00:00 2001
From: Jeroen van Rijn
Date: Mon, 24 Jun 2024 22:43:14 +0200
Subject: [PATCH 19/25] Fix CSV comments.
---
core/encoding/csv/reader.odin | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/core/encoding/csv/reader.odin b/core/encoding/csv/reader.odin
index 200bf43ea..b0a5d82ed 100644
--- a/core/encoding/csv/reader.odin
+++ b/core/encoding/csv/reader.odin
@@ -138,7 +138,9 @@ iterator_next :: proc(r: ^Reader) -> (record: []string, idx: int, err: Error, mo
return record, r.line_count - 1, r.last_iterator_error, r.last_iterator_error == nil
}
-// Get last error if we the iterator
+// Get last CSV parse error if we ignored it in the iterator loop
+//
+// for record, row_idx in csv.iterator_next(&r) { ... }
iterator_last_error :: proc(r: Reader) -> (err: Error) {
return r.last_iterator_error
}
@@ -169,7 +171,7 @@ is_io_error :: proc(err: Error, io_err: io.Error) -> bool {
// read_all reads all the remaining records from r.
// Each record is a slice of fields.
-// read_all is defined to read until an EOF, and does not treat, and does not treat EOF as an error
+// read_all is defined to read until an EOF, and does not EOF as an error
@(require_results)
read_all :: proc(r: ^Reader, allocator := context.allocator) -> ([][]string, Error) {
context.allocator = allocator
From d97fe41834c7030dfc4f975200a084f6cdd3d317 Mon Sep 17 00:00:00 2001
From: Jeroen van Rijn
Date: Mon, 24 Jun 2024 22:45:12 +0200
Subject: [PATCH 20/25] Mark deux
---
core/encoding/csv/reader.odin | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/encoding/csv/reader.odin b/core/encoding/csv/reader.odin
index b0a5d82ed..ebc7b39a0 100644
--- a/core/encoding/csv/reader.odin
+++ b/core/encoding/csv/reader.odin
@@ -171,7 +171,7 @@ is_io_error :: proc(err: Error, io_err: io.Error) -> bool {
// read_all reads all the remaining records from r.
// Each record is a slice of fields.
-// read_all is defined to read until an EOF, and does not EOF as an error
+// read_all is defined to read until an EOF, and does not treat EOF as an error
@(require_results)
read_all :: proc(r: ^Reader, allocator := context.allocator) -> ([][]string, Error) {
context.allocator = allocator
From e42029c5ed8543f65077bd92e0db88aa4c68c5a4 Mon Sep 17 00:00:00 2001
From: Jeroen van Rijn
Date: Tue, 25 Jun 2024 01:35:26 +0200
Subject: [PATCH 21/25] wgpu ld -> dl
---
vendor/wgpu/wgpu.odin | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/vendor/wgpu/wgpu.odin b/vendor/wgpu/wgpu.odin
index a2b24fb7a..15d7fd61c 100644
--- a/vendor/wgpu/wgpu.odin
+++ b/vendor/wgpu/wgpu.odin
@@ -54,7 +54,7 @@ when ODIN_OS == .Windows {
foreign import libwgpu {
LIB,
- "system:ld",
+ "system:dl",
"system:m",
}
} else when ODIN_OS == .JS {
From c0987394840d63fae627c1623ea2661c31adc9b9 Mon Sep 17 00:00:00 2001
From: gingerBill
Date: Tue, 25 Jun 2024 09:36:59 +0100
Subject: [PATCH 22/25] Remove `@(warning)` and `#warning(...)`
---
core/odin/parser/parser.odin | 2 +-
src/check_builtin.cpp | 20 --------------------
src/checker.cpp | 14 --------------
src/parser.cpp | 2 +-
4 files changed, 2 insertions(+), 36 deletions(-)
diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin
index 7edd509d0..6b0aa2888 100644
--- a/core/odin/parser/parser.odin
+++ b/core/odin/parser/parser.odin
@@ -1438,7 +1438,7 @@ parse_stmt :: proc(p: ^Parser) -> ^ast.Stmt {
case: error(p, stmt.pos, "#partial can only be applied to a switch statement")
}
return stmt
- case "assert", "panic", "warning":
+ case "assert", "panic":
bd := ast.new(ast.Basic_Directive, tok.pos, end_pos(tag))
bd.tok = tok
bd.name = name
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index e85981911..47abd42cf 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -1714,26 +1714,6 @@ gb_internal bool check_builtin_procedure_directive(CheckerContext *c, Operand *o
operand->type = t_untyped_bool;
operand->mode = Addressing_Constant;
- } else if (name == "warning") {
- ERROR_BLOCK();
- if (ce->args.count != 1) {
- error(call, "'#warning' expects 1 argument, got %td", ce->args.count);
- return false;
- }
- if (!is_type_string(operand->type) && operand->mode != Addressing_Constant) {
- gbString str = expr_to_string(ce->args[0]);
- error(call, "'%s' is not a constant string", str);
- gb_string_free(str);
- return false;
- }
- warning(call, "%.*s", LIT(operand->value.value_string));
- if (c->proc_name != "") {
- gbString str = type_to_string(c->curr_proc_sig);
- error_line("\tCalled within '%.*s' :: %s\n", LIT(c->proc_name), str);
- gb_string_free(str);
- }
- operand->type = t_invalid;
- operand->mode = Addressing_NoValue;
} else if (name == "panic") {
ERROR_BLOCK();
if (ce->args.count != 1) {
diff --git a/src/checker.cpp b/src/checker.cpp
index 4945b3810..fdf5a8b7d 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -3493,20 +3493,6 @@ gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
error(elem, "Expected a string value for '%.*s'", LIT(name));
}
return true;
- } else if (name == "warning") {
- ExactValue ev = check_decl_attribute_value(c, value);
-
- if (ev.kind == ExactValue_String) {
- String msg = ev.value_string;
- if (msg.len == 0) {
- error(elem, "Warning message cannot be an empty string");
- } else {
- ac->warning_message = msg;
- }
- } else {
- error(elem, "Expected a string value for '%.*s'", LIT(name));
- }
- return true;
} else if (name == "require_results") {
if (value != nullptr) {
error(elem, "Expected no value for '%.*s'", LIT(name));
diff --git a/src/parser.cpp b/src/parser.cpp
index 7383c3360..0cd96f5b5 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -5167,7 +5167,7 @@ gb_internal Ast *parse_stmt(AstFile *f) {
break;
}
return s;
- } else if (tag == "assert" || tag == "panic" || tag == "warning") {
+ } else if (tag == "assert" || tag == "panic") {
Ast *t = ast_basic_directive(f, hash_token, name);
Ast *stmt = ast_expr_stmt(f, parse_call_expr(f, t));
expect_semicolon(f);
From 93441a043a3857c1eb7f7ed5e52db62275e865c4 Mon Sep 17 00:00:00 2001
From: gingerBill
Date: Tue, 25 Jun 2024 09:38:49 +0100
Subject: [PATCH 23/25] Make `runtime.heap_alloc` `contextless`
---
base/runtime/heap_allocator.odin | 6 +++---
base/runtime/heap_allocator_orca.odin | 6 +++---
base/runtime/heap_allocator_other.odin | 6 +++---
base/runtime/heap_allocator_unix.odin | 6 +++---
base/runtime/heap_allocator_windows.odin | 6 +++---
5 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/base/runtime/heap_allocator.odin b/base/runtime/heap_allocator.odin
index 75f79ab77..cdad8690e 100644
--- a/base/runtime/heap_allocator.odin
+++ b/base/runtime/heap_allocator.odin
@@ -97,14 +97,14 @@ heap_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
}
-heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
+heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
return _heap_alloc(size, zero_memory)
}
-heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
+heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
return _heap_resize(ptr, new_size)
}
-heap_free :: proc(ptr: rawptr) {
+heap_free :: proc "contextless" (ptr: rawptr) {
_heap_free(ptr)
}
\ No newline at end of file
diff --git a/base/runtime/heap_allocator_orca.odin b/base/runtime/heap_allocator_orca.odin
index c22a67ca1..9e719bcd0 100644
--- a/base/runtime/heap_allocator_orca.odin
+++ b/base/runtime/heap_allocator_orca.odin
@@ -9,7 +9,7 @@ foreign {
@(link_name="realloc") _orca_realloc :: proc "c" (ptr: rawptr, size: int) -> rawptr ---
}
-_heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
+_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
if size <= 0 {
return nil
}
@@ -20,10 +20,10 @@ _heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
}
}
-_heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
+_heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
return _orca_realloc(ptr, new_size)
}
-_heap_free :: proc(ptr: rawptr) {
+_heap_free :: proc "contextless" (ptr: rawptr) {
_orca_free(ptr)
}
diff --git a/base/runtime/heap_allocator_other.odin b/base/runtime/heap_allocator_other.odin
index 74536ada9..d387aada2 100644
--- a/base/runtime/heap_allocator_other.odin
+++ b/base/runtime/heap_allocator_other.odin
@@ -2,14 +2,14 @@
//+private
package runtime
-_heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
+_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
unimplemented("base:runtime 'heap_alloc' procedure is not supported on this platform")
}
-_heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
+_heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
unimplemented("base:runtime 'heap_resize' procedure is not supported on this platform")
}
-_heap_free :: proc(ptr: rawptr) {
+_heap_free :: proc "contextless" (ptr: rawptr) {
unimplemented("base:runtime 'heap_free' procedure is not supported on this platform")
}
diff --git a/base/runtime/heap_allocator_unix.odin b/base/runtime/heap_allocator_unix.odin
index a8a4e9169..60af9e761 100644
--- a/base/runtime/heap_allocator_unix.odin
+++ b/base/runtime/heap_allocator_unix.odin
@@ -16,7 +16,7 @@ foreign libc {
@(link_name="realloc") _unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr ---
}
-_heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
+_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
if size <= 0 {
return nil
}
@@ -27,12 +27,12 @@ _heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
}
}
-_heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
+_heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
// NOTE: _unix_realloc doesn't guarantee new memory will be zeroed on
// POSIX platforms. Ensure your caller takes this into account.
return _unix_realloc(ptr, new_size)
}
-_heap_free :: proc(ptr: rawptr) {
+_heap_free :: proc "contextless" (ptr: rawptr) {
_unix_free(ptr)
}
diff --git a/base/runtime/heap_allocator_windows.odin b/base/runtime/heap_allocator_windows.odin
index 2097c3671..e07df7559 100644
--- a/base/runtime/heap_allocator_windows.odin
+++ b/base/runtime/heap_allocator_windows.odin
@@ -14,11 +14,11 @@ foreign kernel32 {
HeapFree :: proc(hHeap: rawptr, dwFlags: u32, lpMem: rawptr) -> b32 ---
}
-_heap_alloc :: proc(size: int, zero_memory := true) -> rawptr {
+_heap_alloc :: proc "contextless" (size: int, zero_memory := true) -> rawptr {
HEAP_ZERO_MEMORY :: 0x00000008
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY if zero_memory else 0, uint(size))
}
-_heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
+_heap_resize :: proc "contextless" (ptr: rawptr, new_size: int) -> rawptr {
if new_size == 0 {
_heap_free(ptr)
return nil
@@ -30,7 +30,7 @@ _heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
HEAP_ZERO_MEMORY :: 0x00000008
return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ptr, uint(new_size))
}
-_heap_free :: proc(ptr: rawptr) {
+_heap_free :: proc "contextless" (ptr: rawptr) {
if ptr == nil {
return
}
From 845613c4046fc0f46e647cb40c1ee26b8800da7f Mon Sep 17 00:00:00 2001
From: NicknEma <62065135+NicknEma@users.noreply.github.com>
Date: Tue, 25 Jun 2024 12:10:17 +0200
Subject: [PATCH 24/25] Update CommandLineToArgvW return type
It now returns a multi-pointer so it can be iterated without any casting.
---
core/sys/windows/shell32.odin | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/sys/windows/shell32.odin b/core/sys/windows/shell32.odin
index 358b8482f..4ec6e8b02 100644
--- a/core/sys/windows/shell32.odin
+++ b/core/sys/windows/shell32.odin
@@ -5,7 +5,7 @@ foreign import shell32 "system:Shell32.lib"
@(default_calling_convention="system")
foreign shell32 {
- CommandLineToArgvW :: proc(cmd_list: wstring, num_args: ^c_int) -> ^wstring ---
+ CommandLineToArgvW :: proc(cmd_list: wstring, num_args: ^c_int) -> [^]wstring ---
ShellExecuteW :: proc(
hwnd: HWND,
lpOperation: LPCWSTR,
From 4e2d12c5400bbc789a9573dd4806ea308b40bb5c Mon Sep 17 00:00:00 2001
From: Karl Zylinski
Date: Tue, 25 Jun 2024 22:32:20 +0200
Subject: [PATCH 25/25] Added fmt.ctprint
---
core/fmt/fmt.odin | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin
index b1c95866f..424e4e6e8 100644
--- a/core/fmt/fmt.odin
+++ b/core/fmt/fmt.odin
@@ -368,6 +368,25 @@ caprintf :: proc(format: string, args: ..any, newline := false) -> cstring {
caprintfln :: proc(format: string, args: ..any) -> cstring {
return caprintf(format, ..args, newline=true)
}
+// Creates a formatted C string
+//
+// *Allocates Using Context's Temporary Allocator*
+//
+// Inputs:
+// - args: A variadic list of arguments to be formatted.
+// - sep: An optional separator string (default is a single space).
+//
+// Returns: A formatted C string.
+//
+@(require_results)
+ctprint :: proc(args: ..any, sep := " ") -> cstring {
+ str: strings.Builder
+ strings.builder_init(&str, context.temp_allocator)
+ sbprint(&str, ..args, sep=sep)
+ strings.write_byte(&str, 0)
+ s := strings.to_string(str)
+ return cstring(raw_data(s))
+}
// Creates a formatted C string
//
// *Allocates Using Context's Temporary Allocator*