ox

The Ox programming language, compiler and tools (WIP)
Log | Files | Refs | README | LICENSE

commit a66ba77a44ea79e58078811d8731b83d18752966
parent f9905fcc9613004d0b3f8b2c1218688ebcb40f2b
Author: citbl <citbl@citbl.org>
Date:   Thu, 20 Nov 2025 22:57:30 +1000

semicols

Diffstat:
Moxdesign.ox | 138++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 69 insertions(+), 69 deletions(-)

diff --git a/oxdesign.ox b/oxdesign.ox @@ -1,9 +1,9 @@ -i32 ~x = 42 // make a integer 32bit that is a variable (can be updated) `~` initialised with 2. -i32 x = 42 // like a "let" statement or final variable, runtime constant. -i32 #x = 42 // compile time constant +i32 ~x = 42; // make a integer 32bit that is a variable (can be updated) `~` initialised with 2. +i32 x = 42; // like a "let" statement or final variable, runtime constant. +i32 #x = 42; // compile time constant // give me the raw pointer of x and assign it to y -i32* y = &x +i32* y = &x; // default types @@ -13,27 +13,27 @@ i32* y = &x // str, chr, bool, // arrays (fixed) and lists (dynamic) -arr<i32>[16] ages // fixed slice of 16 -vec<i32> bobs // dynamic list -set<str> names // sets +arr<i32>[16] ages; // fixed slice of 16 +vec<i32> bobs; // dynamic list +set<str> names; // sets type Person { - i32 age - str name + i32 age, + str name, } fn say_hello () void { - print("hello") // print is part of stdlib.local which is auto imported - warn("hello") // this print to stderr instead - print_("hello\n") // all of the above but with `_` won't insert a trailing \n - fatal("hello") // fatal print, returning non-zero + print("hello"); // print is part of stdlib.local which is auto imported + warn("hello"); // this print to stderr instead + print_("hello\n"); // all of the above but with `_` won't insert a trailing \n + fatal("hello"); // fatal print, returning non-zero } // strings are really arrays of special u32, aka vec<chr> -typedef chr u32 // (but u32 is not a rune/chr, as the whole UTF-16 range does not cover u32) +typedef chr u32; // (but u32 is not a rune/chr, as the whole UTF-16 range does not cover u32) // exported function returns one i32 -fx add (i32 a, b) i32 => a + b +fx add (i32 a, b) i32 => a + b; // fx = function is exported // fn = function is static @@ -44,24 +44,24 @@ fn mutate (Person~ p) {} // borrowed and mutable fn unsafe (Person* p) unsafe {} // C style passing of pointer, must tag `unsafe` // lambda style function definition -fx add = (i32 a, b) i32 => a + b +fx add = (i32 a, b) i32 => a + b; // void return is implicit, so is void type arg fx say_hello() { - print("hello") + print("hello"); } // multiple return values go into parens -fx flip(i32 a, b) (i32, i32) => b, a +fx flip(i32 a, b) (i32, i32) => b, a; struct Person { - str name - i16 age - i32 number - str street - str suburb - str postcode - str country + str name, + i16 age, + i32 number, + str street, + str suburb, + str postcode, + str country, // string interpolation `$.` is identifying a type component fx address () str => "$.number, $.street, $.suburb $.postcode\n$.country" } @@ -71,15 +71,15 @@ extend Person { } // lambda style main function -fn main => print("hello world") +fn main => print("hello world"); fn main(i32 argc, arr<str> argv) int = { if argc != 0 { - print("usage...") - return 0 + print("usage..."); + return 0; } - print("hello world! $argc") // string interpolation similar to Dart's - return 0 + print("hello world! $argc"); // string interpolation similar to Dart's + return 0; } fn rename({str name}) str {} // enforce the label to be passed: rename(name:"jack") @@ -95,10 +95,10 @@ if a == b { } // inline if can be done as is -if cache_miss() { print("cached missed!") } +if cache_miss() { print("cached missed!"); } // ternary if -i32 bla = cond ? 42 : 420 +i32 bla = cond ? 42 : 420; // for statements // classic for statement use commas separated init, cond and modifier @@ -121,9 +121,9 @@ loop {} // switch switch (action.key) { KEY_ENTER { - open_door() + open_door(); } - KEY_UP { move_up() } + KEY_UP { move_up(); } default { warn("unsupported!") } @@ -131,47 +131,47 @@ switch (action.key) { // match expr chr c = match key { - 61 => 'a' - 62 => 'b' - default => '_' + 61 => 'a'; + 62 => 'b'; + default => '_'; } // dealing with nil values. They're not allowed unless unsafe in play. -Person? p = find("jack") +Person? p = find("jack"); if Person x = p { - print("found jack of ${x.age} age") // safe usage + print("found jack of ${x.age} age"); // safe usage } if p { - print("found jack of ${p!.age} age") // force unwrap + print("found jack of ${p!.age} age"); // force unwrap } -Person* p = NULL // is allowed. NULL is a constant 0xffffff of some kind. +Person* p = NULL; // is allowed. NULL is a constant 0xffffff of some kind. // not allowed: Person&? Person~? // null coalescing of maybes -print("jack may be of ${p?.age ?? \"some unknown\"}") +print("jack may be of ${p?.age ?? \"some unknown\"}"); -i32 res = some_test() ?? 42 +i32 res = some_test() ?? 42; // namespacing -ns main // is default and not required, this unit will require a main function -ns tools // loosely required to be in tools/ +ns main; // is default and not required, this unit will require a main function +ns tools; // loosely required to be in tools/ // using namespaces, importing, namespaces are forced lowercase to not impact types -use math // bring all of math functions in, to be prefixed by math.something -use math { random, sin, cos } // limit the import to these symbols, directly accessible: sin() -use math as mth // alias math to `mth` +use math; // bring all of math functions in, to be prefixed by math.something +use math { random, sin, cos }; // limit the import to these symbols, directly accessible: sin() +use math as mth; // alias math to `mth` // async operations using the Aloha assignment operator `~=` -i32? response = await some_long_action() +i32? response = await some_long_action(); // error handling @@ -179,16 +179,16 @@ fn fetch_data({str url}) async str! { // fetch the data of the website, parse the body content // return the body content await ... - return content + return content; } struct Error { - u16 code - str message + u16 code, + str message, Error? cause } -str website_data = await try fetch_data(url: "fleacebook.com") or Error e => print("could not fetch data ${e.message}") +str website_data = await try fetch_data(url: "fleacebook.com") or Error e => print("could not fetch data ${e.message}"); fx flip(i32 a, b) (i32, i32)! { @@ -212,20 +212,20 @@ fx flip(i32 a, b) (i32, i32)! { // FFI interaction with C and C types // core FFI aliases -typedef voidptr = void* -typedef cstr = char* -typedef ccstr = const char* +typedef voidptr = void*; +typedef cstr = char*; +typedef ccstr = const char*; -use math -use c <stdio.h> -use c <stdlib.h> -use c <stdint.h> -use c "include/termbox2.h" +use math; +use c <stdio.h>; +use c <stdlib.h>; +use c <stdint.h>; +use c "include/termbox2.h"; extern c { - fn printf(ccstr, ...) int - fn free(voidptr) - fn malloc(size_t) voidptr + fn printf(ccstr, ...) int; + fn free(voidptr); + fn malloc(size_t) voidptr; fn tb_print(i32, i32, u16, u16, cstr); // x, y, fg, bg, text // NOTES @@ -236,13 +236,13 @@ extern c { } fn main() { - voidptr ptr = malloc(65128) + voidptr ptr = malloc(65128); // invalid: *ptr = 420 // voidptr should be undereferenceable // no deref of voidptr without a cast - ptr<u8> bytes = cast(ptr<u8> p) - bytes[0] = 42 - free(ptr) + ptr<u8> bytes = cast(ptr<u8> p); + bytes[0] = 42; + free(ptr); // presume init called etc. - tb_print(12, 12, TB_MAGENTA, TB_BLACK, c_const_str("some words of wisdom")) + tb_print(12, 12, TB_MAGENTA, TB_BLACK, c_const_str("some words of wisdom")); }