From fbac2d6df371e5fff1dad25d80c36bdba677fd2e Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 27 Feb 2025 20:09:15 +0100 Subject: [PATCH] Formatting updates. --- .../examples/embedded/riscv-qemu/hello.c3 | 9 +-- .../examples/embedded/riscv-qemu/semihost.c3 | 6 +- .../examples/embedded/riscv-qemu/uart.c3 | 23 +++++--- resources/examples/nolibc/hello_world.c3 | 4 +- resources/examples/opengl/src/gl/gl.c3 | 12 ++-- resources/examples/opengl/src/glfw/glfw.c3 | 59 ++++++++----------- resources/examples/opengl/src/triangle.c3 | 7 ++- 7 files changed, 58 insertions(+), 62 deletions(-) diff --git a/resources/examples/embedded/riscv-qemu/hello.c3 b/resources/examples/embedded/riscv-qemu/hello.c3 index 2f4295457..16b055e09 100644 --- a/resources/examples/embedded/riscv-qemu/hello.c3 +++ b/resources/examples/embedded/riscv-qemu/hello.c3 @@ -3,9 +3,10 @@ import semihost; const UART0_BASE = 0x10000000; -fn void main() @export("main") { - Uart* uart0 = (Uart*)UART0_BASE; // Create pointer to UART 0 +fn void main() @export("main") +{ + Uart* uart0 = (Uart*)UART0_BASE; // Create pointer to UART 0 uart0.fcr = uart::UARTFCR_FFENA; // Enable FIFO - uart0.puts("Hello World!\n"); // Write the string to the UART - semihost::exit(0); // Semihosting call to exit host + uart0.puts("Hello World!\n"); // Write the string to the UART + semihost::exit(0); // Semihosting call to exit host } diff --git a/resources/examples/embedded/riscv-qemu/semihost.c3 b/resources/examples/embedded/riscv-qemu/semihost.c3 index 4904bbdd3..c344149e6 100644 --- a/resources/examples/embedded/riscv-qemu/semihost.c3 +++ b/resources/examples/embedded/riscv-qemu/semihost.c3 @@ -4,7 +4,8 @@ module semihost; extern fn int sys_semihost(int operation, SemihostParameters* parms); -struct SemihostParameters { +struct SemihostParameters +{ int field1; int field2; } @@ -12,7 +13,8 @@ struct SemihostParameters { const int SYS_EXIT_EXTENDED = 0x20; const int ADP_STOPPED_APPLICATIONEXIT = 0x20026; -fn void exit(int status) { +fn void exit(int status) +{ SemihostParameters parms; parms.field1 = ADP_STOPPED_APPLICATIONEXIT; parms.field2 = status; diff --git a/resources/examples/embedded/riscv-qemu/uart.c3 b/resources/examples/embedded/riscv-qemu/uart.c3 index 8f05b218f..29056e0cc 100644 --- a/resources/examples/embedded/riscv-qemu/uart.c3 +++ b/resources/examples/embedded/riscv-qemu/uart.c3 @@ -3,7 +3,8 @@ module uart; const UARTFCR_FFENA = 0x01; // UART FIFO Control Register enable bit const UARTLSR_THRE = 0x20; // UART Line Status Register Transmit Hold Register Empty bit -struct Uart { +struct Uart +{ char dr; // UART Data Register char filler1; char fcr; // FIFO Control Register @@ -12,17 +13,21 @@ struct Uart { char lsr; // Line Status Register } -fn bool Uart.uart_ff_thr_empty(Uart* this) { +fn bool Uart.uart_ff_thr_empty(Uart* this) +{ return (bool)($$volatile_load(&this.lsr) & UARTLSR_THRE); } -fn void Uart.putc(Uart* this, char c) { - while (!this.uart_ff_thr_empty()); // Wait until the FIFO holding register is empty - $$volatile_store(&this.dr, c); // Write character to transmit register +fn void Uart.putc(Uart* this, char c) +{ + while (!this.uart_ff_thr_empty()); // Wait until the FIFO holding register is empty + $$volatile_store(&this.dr, c); // Write character to transmit register } -fn void Uart.puts(Uart* this, char *str) { - while (*str) { // Loop until value at string pointer is zero - this.putc(*str++); // Write the character and increment pointer - } +fn void Uart.puts(Uart* this, char *str) +{ + while (*str) // Loop until value at string pointer is zero + { + this.putc(*str++); // Write the character and increment pointer + } } diff --git a/resources/examples/nolibc/hello_world.c3 b/resources/examples/nolibc/hello_world.c3 index 895e64384..53ab2ffbc 100644 --- a/resources/examples/nolibc/hello_world.c3 +++ b/resources/examples/nolibc/hello_world.c3 @@ -1,8 +1,8 @@ fn int main() { String msg = "Hello, C3 World!\n"; - $$syscall(1, 1, (uptr)msg.ptr, msg.len); // __NR_write, STDOUT - return 0; + $$syscall(1, 1, (uptr)msg.ptr, msg.len); // __NR_write, STDOUT + return 0; } fn void _start() @export("_start") diff --git a/resources/examples/opengl/src/gl/gl.c3 b/resources/examples/opengl/src/gl/gl.c3 index 5b2c39684..b21b5aaa3 100644 --- a/resources/examples/opengl/src/gl/gl.c3 +++ b/resources/examples/opengl/src/gl/gl.c3 @@ -2,13 +2,15 @@ module gl; def BitField = int; -enum BufferBit : int(int value) { +enum BufferBit : int (int value) +{ COLOR = 0x00004000, STENCIL = 0x00000400, DEPTH = 0x00000100, } -enum Primitive : int(int value) { +enum Primitive : int (int value) +{ POINTS = 0, LINES = 1, LINE_LOOP = 2, @@ -29,8 +31,6 @@ extern fn void end() @extern("glEnd") @public; extern fn void flush() @extern("glFlush") @public; -extern fn void color3f(float r, float g, float b) - @extern("glColor3f") @public; +extern fn void color3f(float r, float g, float b) @extern("glColor3f") @public; -extern fn void vertex3f(float x, float y, float z) - @extern("glVertex3f") @public; \ No newline at end of file +extern fn void vertex3f(float x, float y, float z) @extern("glVertex3f") @public; \ No newline at end of file diff --git a/resources/examples/opengl/src/glfw/glfw.c3 b/resources/examples/opengl/src/glfw/glfw.c3 index 4a0c2a266..0588a71fd 100644 --- a/resources/examples/opengl/src/glfw/glfw.c3 +++ b/resources/examples/opengl/src/glfw/glfw.c3 @@ -2,40 +2,33 @@ module glfw; import std::io; -distinct Window @public = _Window*; -distinct Monitor @public = _Monitor*; +distinct Window @public = inline _Window*; +distinct Monitor @public = inline _Monitor*; -fn void Window.create( - &self, - int width, - int height, - String title, - Monitor monitor = {}, - Window share = {} -) @public { - *self = (Window)_glfwCreateWindow( - width, - height, - title, - (_Monitor*)monitor, - (_Window*)share - ); +fn void Window.create(&self, int width, int height, String title, Monitor monitor = {}, Window share = {} +) @public +{ + *self = (Window)_glfwCreateWindow(width, height, title, monitor, share); } -fn void Window.destroy(self) @public { - _glfwDestroyWindow((_Window*)self); +fn void Window.destroy(self) @public +{ + _glfwDestroyWindow((_Window*)self); } -fn bool Window.shouldClose(self) @public { - return _glfwWindowShouldClose((_Window*)self); +fn bool Window.shouldClose(self) @public +{ + return _glfwWindowShouldClose((_Window*)self); } -fn void Window.swapBuffers(self) @public { - return _glfwSwapBuffers((_Window*)self); +fn void Window.swapBuffers(self) @public +{ + return _glfwSwapBuffers((_Window*)self); } -fn void Window.makeContextCurrent(self) @public { - return _glfwMakeContextCurrent((_Window*)self); +fn void Window.makeContextCurrent(self) @public +{ + return _glfwMakeContextCurrent((_Window*)self); } extern fn void initialize() @extern("glfwInit") @public; @@ -47,18 +40,12 @@ extern fn void pollEvents() @extern("glfwPollEvents") @public; distinct _Window @private = void; distinct _Monitor @private = void; -extern fn _Window* _glfwCreateWindow( - int width, int height, char* title, _Monitor* monitor, _Window* share -) @extern("glfwCreateWindow") @private; +extern fn _Window* _glfwCreateWindow(int width, int height, char* title, _Monitor* monitor, _Window* share) @extern("glfwCreateWindow") @private; -extern fn bool _glfwWindowShouldClose(_Window* window) - @extern("glfwWindowShouldClose") @private; +extern fn bool _glfwWindowShouldClose(_Window* window) @extern("glfwWindowShouldClose") @private; -extern fn void _glfwDestroyWindow(_Window* window) - @extern("glfwDestroyWindow") @private; +extern fn void _glfwDestroyWindow(_Window* window) @extern("glfwDestroyWindow") @private; -extern fn void _glfwSwapBuffers(_Window* window) - @extern("glfwSwapBuffers") @private; +extern fn void _glfwSwapBuffers(_Window* window) @extern("glfwSwapBuffers") @private; -extern fn void _glfwMakeContextCurrent(_Window* window) - @extern("glfwMakeContextCurrent") @private; \ No newline at end of file +extern fn void _glfwMakeContextCurrent(_Window* window) @extern("glfwMakeContextCurrent") @private; \ No newline at end of file diff --git a/resources/examples/opengl/src/triangle.c3 b/resources/examples/opengl/src/triangle.c3 index c49ac23b0..ef1ed1a99 100644 --- a/resources/examples/opengl/src/triangle.c3 +++ b/resources/examples/opengl/src/triangle.c3 @@ -2,16 +2,17 @@ import std::io; import glfw; import gl; -fn void main() { +fn void main() +{ glfw::initialize(); Window window; window.create(1280, 720, "Triangle example"); window.makeContextCurrent(); - while(!window.shouldClose()) { + while (!window.shouldClose()) + { gl::clear(BufferBit.COLOR.value); - gl::begin(Primitive.TRIANGLES.value); gl::color3f(1, 0, 0); gl::vertex3f(-0.6, -0.75, 0.5); gl::color3f(0, 1, 0); gl::vertex3f(0.6, -0.75, 0);