From ce5fa17103ef6b3567971fbf8c739a427873f7e1 Mon Sep 17 00:00:00 2001 From: ashn Date: Wed, 1 Feb 2023 14:28:09 -0500 Subject: [PATCH] Update to Sunder version 2022.02.01 --- README.md | 13 +++---------- bpgfx.sunder | 18 +++++++++++------- example.sunder | 11 ++--------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index fc18fda..0320051 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Block](https://en.wikipedia.org/wiki/Braille_Patterns). Ported from the Braille Pattern Graphics [Python 3 library](https://github.com/ashn-dot-dev/braille-pattern-graphics) for [Sunder](https://github.com/ashn-dot-dev/sunder) version -[2022.12.01](https://github.com/ashn-dot-dev/sunder/releases/tag/2022.12.01). +[2023.02.01](https://github.com/ashn-dot-dev/sunder/releases/tag/2023.02.01). ## Example Usage ``` @@ -12,19 +12,12 @@ import "std"; import "bpgfx.sunder"; func main() void { - var allocator = std::general_allocator::init(); - defer { - allocator.fini(); - } - # Create a 40 x 30 canvas of virtual dot pixels. # # Virtual dot-pixels are mapped onto a grid of braille characters when the # canvas is rendered via its format member function. - var canvas = bpgfx::canvas::init(std::allocator::init[[typeof(allocator)]](&allocator), 40, 30); - defer { - canvas.fini(); - } + var canvas = bpgfx::canvas::init(40, 30); + defer canvas.fini(); # Draw a rectangle around the border of the canvas. for x in canvas.width() { diff --git a/bpgfx.sunder b/bpgfx.sunder index f8862a2..ceb8954 100644 --- a/bpgfx.sunder +++ b/bpgfx.sunder @@ -5,7 +5,7 @@ import "std"; # Printing this escape sequence to the terminal will clear the screen and # reposition the cursor on the top-left of the terminal in terminal emulators # with support for ANSI escape codes. -const CLEAR = "\x1B[H\x1B[2J"; +let CLEAR = "\x1B[H\x1B[2J"; struct drawable_itable { var draw: func(*any, *canvas) void; @@ -16,7 +16,7 @@ struct drawable { var object: *any; func init[[T]](object: *T) bpgfx::drawable { - const itable = (:bpgfx::drawable_itable){ + let itable = (:bpgfx::drawable_itable){ .draw = T::draw }; return (:bpgfx::drawable){ @@ -40,7 +40,11 @@ struct canvas { var _height: usize; var _dots: [][]bool; - func init(allocator: std::allocator, width: usize, height: usize) canvas { + func init(width: usize, height: usize) canvas { + return canvas::init_with_allocator(std::global_allocator(), width, height); + } + + func init_with_allocator(allocator: std::allocator, width: usize, height: usize) canvas { var dots_w = width; for dots_w % 2 != 0 { dots_w = dots_w + 1; @@ -51,9 +55,9 @@ struct canvas { dots_h = dots_h + 1; } - var dots = std::slice[[[]bool]]::new(allocator, dots_h); + var dots = std::slice[[[]bool]]::new_with_allocator(allocator, dots_h); for i in countof(dots) { - dots[i] = std::slice[[bool]]::new(allocator, dots_w); + dots[i] = std::slice[[bool]]::new_with_allocator(allocator, dots_w); std::slice[[bool]]::fill(dots[i], false); } @@ -67,9 +71,9 @@ struct canvas { func fini(self: *canvas) void { for i in countof(self.*._dots) { - std::slice[[bool]]::delete(self.*._allocator, self.*._dots[i]); + std::slice[[bool]]::delete_with_allocator(self.*._allocator, self.*._dots[i]); } - std::slice[[[]bool]]::delete(self.*._allocator, self.*._dots); + std::slice[[[]bool]]::delete_with_allocator(self.*._allocator, self.*._dots); } func width(self: *canvas) usize { diff --git a/example.sunder b/example.sunder index 5639dbc..59c7c11 100644 --- a/example.sunder +++ b/example.sunder @@ -2,19 +2,12 @@ import "std"; import "bpgfx.sunder"; func main() void { - var allocator = std::general_allocator::init(); - defer { - allocator.fini(); - } - # Create a 40 x 30 canvas of virtual dot pixels. # # Virtual dot-pixels are mapped onto a grid of braille characters when the # canvas is rendered via its format member function. - var canvas = bpgfx::canvas::init(std::allocator::init[[typeof(allocator)]](&allocator), 40, 30); - defer { - canvas.fini(); - } + var canvas = bpgfx::canvas::init(40, 30); + defer canvas.fini(); # Draw a rectangle around the border of the canvas. for x in canvas.width() { -- 2.45.2