refine language a bit

This commit is contained in:
zongor 2025-05-17 22:37:45 -04:00
parent 52c33178d3
commit ffbf044734
5 changed files with 95 additions and 141 deletions

View File

@ -6,11 +6,9 @@
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: what-is-ztl :CUSTOM_ID: what-is-ztl
:END: :END:
/ztl/ is an language transpiler with C/Lua style syntax. The transpiler /ztl/ is an domain specific language for 3d games with C/Lua style syntax.
bootstrap is written in Lua which should make it easy to port to other The compiler is written in C which should make it easy to port to other
systems. /ztl/ also can "run" standalone inside of a lua vm for systems.
debugging purposes, it could be used for small scripting tasks or the
like.
* /ZTL/ Grammar and Specification * /ZTL/ Grammar and Specification
:PROPERTIES: :PROPERTIES:
@ -41,10 +39,12 @@ type «token» {
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: numeric :CUSTOM_ID: numeric
:END: :END:
- =byte= - =real=
- unsigned 8 bit integer (uint8_t) - 64 bit floating point (Double)
- =number= - Is it slow and takes up a lot of space? yeah it does,
- 64 bit floating point (double) but because it is the only numeric type it makes it so that you do not have to worry about type casting which actually ends up speeding up processing
This is also how Lua, Lox, and Wren programming language handles numbers. Also because ZTL is intended to be used for Games, floats are used more for
3D graphics than other numeric types.
** string ** string
:PROPERTIES: :PROPERTIES:
@ -61,16 +61,19 @@ string interpolation
="«utf8 encoded characters» ${some_var}"= ="«utf8 encoded characters» ${some_var}"=
** binary
:PROPERTIES:
:CUSTOM_ID: binary
:END:
- =byte=
- same as uint8 or c char, used for interop
** logical ** logical
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: logical :CUSTOM_ID: logical
:END: :END:
=bool= - =bool=
- =true= / =false=
=true= / =false=
Also follows the style boolean 'c' rules of nonzero / zero, but the
compiler will make fun of you
** error ** error
:PROPERTIES: :PROPERTIES:
@ -106,10 +109,10 @@ syntax (yes I was nice and kept the syntax the same as most C like
langs) langs)
#+begin_src ztl #+begin_src ztl
// array same as a map of int to «type» /* array same as a map of int to «type» */
let «variable» = [val1, val2, ...]; let «variable» = [val1, val2, ...];
// or as a map /* or as a map */
let «variable» = {key1: val1, key2: val2, ...}; let «variable» = {key1: val1, key2: val2, ...};
#+end_src ztl #+end_src ztl
@ -125,49 +128,47 @@ described in "tunnel" section
:END: :END:
The following is a list of global operators and their effect: The following is a list of global operators and their effect:
- =//= - //
- comment - comment
- =??= - ??
- unwrap or - unwrap or
- =+= - +
- addition - addition
- =-= - -
- subtraction - subtraction
- negation - negation
- =*= - *
- multiplication - multiplication
- =/= - /
- divisor - divisor
- =**= - ^
- power - power
- ==== - ==
- equals - equals
- =<= - <
- less than - less than
- =>= - >
- greater than - greater than
- =>== - >=
- greater than or equals - greater than or equals
- =<== - <=
- less than or equals - less than or equals
- =|>= - |>
- curry a function into another function (like haskell shove) - curry a function into another function (like haskell shove)
- =.= - .
- accessor - accessor
- =++= - ++
- inline add 1 - inline add 1
- =--= - --
- inline subtract 1 - inline subtract 1
- =+== - +=
- inline add n - inline add n
- =-== - -=
- inline subtract n - inline subtract n
- =*== - *=
- inline multiply n - inline multiply n
- =\== - \=
- inline divide n - inline divide n
- =**==
- inline power n
*** logical / bitwise operators *** logical / bitwise operators
:PROPERTIES: :PROPERTIES:
@ -202,7 +203,7 @@ The following is a list of global operators and their effect:
let operator let operator
#+begin_src ztl #+begin_src ztl
let «token» = 0; let «token» = true;
#+end_src ztl #+end_src ztl
=is= =is=
@ -210,8 +211,8 @@ let «token» = 0;
checks if a object is of that type checks if a object is of that type
#+begin_src ztl #+begin_src ztl
if («token» is i32) { if («token» is real) {
print("hello yes self is i32?"); print("hello yes self is a real?");
} }
#+end_src ztl #+end_src ztl
@ -222,8 +223,8 @@ also used for letting constants
coerces a type as another type if possible coerces a type as another type if possible
#+begin_src ztl #+begin_src ztl
let «token» = 0; // default is i32 let «token» = 0; /* default is real */
some_functon(«token» as i8); // needs an i8 some_functon(«token» as byte); /* needs an byte */
#+end_src ztl #+end_src ztl
=in= =in=
@ -305,12 +306,20 @@ connected tunnel
filesystem or through the graph filesystem or through the graph
#+begin_src ztl #+begin_src ztl
let endpoint = Tunnel("protocol://path/to/source"); /* client */
let endpoint = `protocol://path/to/source`;
let tunnel = endpoint.attach(user, auth); let tunnel = endpoint.attach(user, auth);
let data = tunnel.open("/some/resource").read(); let data = tunnel.open("/some/resource").read();
std.write(data); //print(data); std.write(data); //print(data);
data.flush(); data.flush();
endpoint.clunk(); endpoint.clunk();
/* server */
let server = `protocol://ip`;
s.bind("/some/resource", fn () str {
return "hello world";
})
server.start();
#+end_src ztl #+end_src ztl
** Functions ** Functions
@ -362,7 +371,7 @@ loop { «body» }
loops infinitely until break or return loops infinitely until break or return
#+begin_src ztl #+begin_src ztl
do (let «variable» = initial_value, end_value, increment) { «body» } do («variable» = initial_value, end_value, increment) { «body» }
#+end_src ztl #+end_src ztl
loops from initial value to end value by increment value loops from initial value to end value by increment value
@ -428,11 +437,11 @@ everything is lazily compiled jit anyways it (in theory) doesn't hurt
pertypeance much pertypeance much
#+begin_src ztl #+begin_src ztl
use "https://git.alfrescocavern.com/some_library/some_file.ztl" use `https://example.com/some_library/some_file.ztl`
#+end_src ztl #+end_src ztl
#+begin_src ztl #+begin_src ztl
use "./some_local_file.ztl" use `./some_local_file.ztl`
#+end_src ztl #+end_src ztl
** Testing ** Testing
@ -444,7 +453,7 @@ use "./some_local_file.ztl"
:CUSTOM_ID: assertion :CUSTOM_ID: assertion
:END: :END:
#+begin_src ztl #+begin_src ztl
assert(«expression», «expected output») //returns «error or none» assert(«expression», «expected output») /* returns «error or none» */
#+end_src ztl #+end_src ztl
** Measurements ** Measurements

View File

@ -1,48 +0,0 @@
fn build(ProjectConfig c) {
c.name("MMO Project");
c.mode("dev");
c.client([
LanguageSettings(
"c", // lang
"src/client.ztl", // file
"client/", // out path
[ // ffi settings
FFISetting (
"raylib", // libary name
"$RAYLIB_PATH/libraylib.a", // path
"./", // local path
"make build", // build command
)
]
)
]);
c.server([
LanguageSettings(
"javascript",
"src/server.ztl",
"server/"
)
]);
c.common([
LanguageSettings(
"c",
"src/common.ztl",
"client/"
),
LanguageSettings(
"javascript",
"src/common.ztl",
"server/"
),
LanguageSettings(
"sqlite",
"src/common.ztl",
"db/"
)
]);
c.build();
}

View File

@ -1,6 +1,6 @@
use "common.ztl"; use `common.ztl`;
fn main (argc int, argv str[]) int { fn main (argc real, argv str[]) {
let screen_width = 800; let screen_width = 800;
let screen_height = 450; let screen_height = 450;
@ -9,37 +9,34 @@ fn main (argc int, argv str[]) int {
let me = Player( let me = Player(
username, username,
Vec3(0.0, 1.0, 2.0), (0.0, 1.0, 2.0),
purple PURPLE
); );
let players = me.login(password); let players = me.login(password);
let window = Window("zwl client", screen_width, screen_height); let window = Window("zwl client", screen_width, screen_height);
let splitbox = window.split("vertical", 0.75); /* vertical split 75% left */
let universe = Universe();
let canvas = Canvas();
canvas.append(Button("logout", fn () {
window.close = true;
}))
splitbox.left.append(universe);
splitbox.right.append(canvas);
while ( not window.should_close() ) { while ( not window.should_close() ) {
me.update(); me.update();
window.begin_drawing(); universe.draw_grid(30, 1.0);
window.clear_background(WHITE); universe.draw_cube(me.pos, 0.5, 0.5, 0.5, me.apperance);
window.begin_mode_3d(camera);
window.draw_grid(30, 1.0);
window.draw_cube(me.pos, 0.5, 0.5, 0.5, me.apperance);
for (player in players) { for (player in players) {
window.draw_cube(player.pos, 0.5, 0.5, 0.5, player.apperance); universe.draw_cube(player.pos, 0.5, 0.5, 0.5, player.apperance);
} }
window.end_mode_3d();
window.end_drawing();
} }
me.logout(); me.logout();
window.close(); window.close();
return 0; exits("Client Closed Successfully");
} }

View File

@ -1,37 +1,27 @@
type Vec3 { /**
init(x real, y real, z real) { * Camera .
this.x = x; */
this.y = y;
this.z = z;
}
}
type Color {
init(r i8, g i8, b i8) {
this.r = r;
this.g = g;
this.b = b;
}
}
type Camera { type Camera {
init(pos Vec3, look Vec3) { init(pos Vec3, look Vec3) {
this.setting = "CAMERA_PERSPECTIVE"; this.setting = "CAMERA_PERSPECTIVE";
this.pov = 45.0; this.pov = 45.0;
this.up = Vec3(0.0, 1.0, 0.0); this.up = (0.0, 1.0, 0.0);
this.pos = pos; this.pos = pos;
this.look = look; this.look = look;
} }
} }
/**
* Player .
*/
type Player { type Player {
init (username str, pos Vec3, color Color) { init (username str, pos Vec3, color Color) {
this.server = Tunnel("localhost:25565"); this.server = `tcp://localhost:25565`;
this.username = username; this.username = username;
this.pos = pos; this.pos = pos;
this.color = color; this.color = color;
this.camera = Camera( this.camera = Camera(
Vec3(this.pos.x + 10.0, (this.pos.x + 10.0,
this.pos.y + 10.0, this.pos.y + 10.0,
this.pos.z), this.pos.z),
this.pos this.pos
@ -73,5 +63,6 @@ type Player {
} }
} }
const PURPLE is Color(255, 255, 0); const RED is [255, 0, 0];
const WHITE is Color(0, 0, 0); const WHITE is [0, 0, 0];
const PURPLE is [255, 255, 0];

View File

@ -1,6 +1,11 @@
use "common.ztl"; use `common.ztl`;
fn main (argc i32, argv str[]) i32 { fn main (argc real, argv str[]) {
let s = Server("0.0.0.0:25565"); let s = `tcp://0.0.0.0:25565`;
return s.start(); s.bind("players", fn () Player[] {
let players = [ Player("user", (0, 0, 0), RED) ];
return players;
});
s.start();
exits(nil);
} }