diff --git a/docs/SPECIFICATION.org b/docs/SPECIFICATION.org index 6505828..eb98fd0 100644 --- a/docs/SPECIFICATION.org +++ b/docs/SPECIFICATION.org @@ -6,11 +6,9 @@ :PROPERTIES: :CUSTOM_ID: what-is-ztl :END: -/ztl/ is an language transpiler with C/Lua style syntax. The transpiler -bootstrap is written in Lua which should make it easy to port to other -systems. /ztl/ also can "run" standalone inside of a lua vm for -debugging purposes, it could be used for small scripting tasks or the -like. +/ztl/ is an domain specific language for 3d games with C/Lua style syntax. +The compiler is written in C which should make it easy to port to other +systems. * /ZTL/ Grammar and Specification :PROPERTIES: @@ -41,10 +39,12 @@ type «token» { :PROPERTIES: :CUSTOM_ID: numeric :END: -- =byte= - - unsigned 8 bit integer (uint8_t) -- =number= - - 64 bit floating point (double) +- =real= + - 64 bit floating point (Double) + - Is it slow and takes up a lot of space? yeah it does, + 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 :PROPERTIES: @@ -61,16 +61,19 @@ string interpolation ="«utf8 encoded characters» ${some_var}"= +** binary +:PROPERTIES: +:CUSTOM_ID: binary +:END: +- =byte= + - same as uint8 or c char, used for interop + ** logical :PROPERTIES: :CUSTOM_ID: logical :END: -=bool= - -=true= / =false= - -Also follows the style boolean 'c' rules of nonzero / zero, but the -compiler will make fun of you +- =bool= + - =true= / =false= ** error :PROPERTIES: @@ -106,10 +109,10 @@ syntax (yes I was nice and kept the syntax the same as most C like langs) #+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, ...]; -// or as a map +/* or as a map */ let «variable» = {key1: val1, key2: val2, ...}; #+end_src ztl @@ -125,49 +128,47 @@ described in "tunnel" section :END: The following is a list of global operators and their effect: -- =//= +- // - comment -- =??= +- ?? - unwrap or -- =+= +- + - addition -- =-= +- - - subtraction - negation -- =*= +- * - multiplication -- =/= +- / - divisor -- =**= +- ^ - power -- ==== +- == - equals -- =<= +- < - less than -- =>= +- > - greater than -- =>== +- >= - greater than or equals -- =<== +- <= - less than or equals -- =|>= +- |> - curry a function into another function (like haskell shove) -- =.= +- . - accessor -- =++= +- ++ - inline add 1 -- =--= +- -- - inline subtract 1 -- =+== +- += - inline add n -- =-== +- -= - inline subtract n -- =*== +- *= - inline multiply n -- =\== +- \= - inline divide n -- =**== - - inline power n *** logical / bitwise operators :PROPERTIES: @@ -202,7 +203,7 @@ The following is a list of global operators and their effect: let operator #+begin_src ztl -let «token» = 0; +let «token» = true; #+end_src ztl =is= @@ -210,8 +211,8 @@ let «token» = 0; checks if a object is of that type #+begin_src ztl -if («token» is i32) { - print("hello yes self is i32?"); +if («token» is real) { + print("hello yes self is a real?"); } #+end_src ztl @@ -222,8 +223,8 @@ also used for letting constants coerces a type as another type if possible #+begin_src ztl -let «token» = 0; // default is i32 -some_functon(«token» as i8); // needs an i8 +let «token» = 0; /* default is real */ +some_functon(«token» as byte); /* needs an byte */ #+end_src ztl =in= @@ -305,12 +306,20 @@ connected tunnel filesystem or through the graph #+begin_src ztl -let endpoint = Tunnel("protocol://path/to/source"); +/* client */ +let endpoint = `protocol://path/to/source`; let tunnel = endpoint.attach(user, auth); let data = tunnel.open("/some/resource").read(); std.write(data); //print(data); data.flush(); endpoint.clunk(); + +/* server */ +let server = `protocol://ip`; +s.bind("/some/resource", fn () str { + return "hello world"; +}) +server.start(); #+end_src ztl ** Functions @@ -362,7 +371,7 @@ loop { «body» } loops infinitely until break or return #+begin_src ztl -do (let «variable» = initial_value, end_value, increment) { «body» } +do («variable» = initial_value, end_value, increment) { «body» } #+end_src ztl 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 #+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 #+begin_src ztl -use "./some_local_file.ztl" +use `./some_local_file.ztl` #+end_src ztl ** Testing @@ -444,7 +453,7 @@ use "./some_local_file.ztl" :CUSTOM_ID: assertion :END: #+begin_src ztl -assert(«expression», «expected output») //returns «error or none» +assert(«expression», «expected output») /* returns «error or none» */ #+end_src ztl ** Measurements diff --git a/docs/project-syntax-example/project.ztl b/docs/project-syntax-example/project.ztl deleted file mode 100644 index b492b8d..0000000 --- a/docs/project-syntax-example/project.ztl +++ /dev/null @@ -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(); -} diff --git a/docs/project-syntax-example/src/client.ztl b/docs/project-syntax-example/src/client.ztl index d57e7ed..45d6b81 100644 --- a/docs/project-syntax-example/src/client.ztl +++ b/docs/project-syntax-example/src/client.ztl @@ -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_height = 450; @@ -9,37 +9,34 @@ fn main (argc int, argv str[]) int { let me = Player( username, - Vec3(0.0, 1.0, 2.0), - purple + (0.0, 1.0, 2.0), + PURPLE ); let players = me.login(password); 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() ) { me.update(); - window.begin_drawing(); - window.clear_background(WHITE); - - window.begin_mode_3d(camera); - - window.draw_grid(30, 1.0); - - window.draw_cube(me.pos, 0.5, 0.5, 0.5, me.apperance); + universe.draw_grid(30, 1.0); + universe.draw_cube(me.pos, 0.5, 0.5, 0.5, me.apperance); 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(); window.close(); - return 0; + exits("Client Closed Successfully"); } - diff --git a/docs/project-syntax-example/src/common.ztl b/docs/project-syntax-example/src/common.ztl index 7617838..7e0986c 100644 --- a/docs/project-syntax-example/src/common.ztl +++ b/docs/project-syntax-example/src/common.ztl @@ -1,37 +1,27 @@ -type Vec3 { - init(x real, y real, z real) { - 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; - } -} - +/** + * Camera . + */ type Camera { init(pos Vec3, look Vec3) { this.setting = "CAMERA_PERSPECTIVE"; 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.look = look; } } +/** + * Player . + */ type Player { init (username str, pos Vec3, color Color) { - this.server = Tunnel("localhost:25565"); + this.server = `tcp://localhost:25565`; this.username = username; this.pos = pos; this.color = color; this.camera = Camera( - Vec3(this.pos.x + 10.0, + (this.pos.x + 10.0, this.pos.y + 10.0, this.pos.z), this.pos @@ -73,5 +63,6 @@ type Player { } } -const PURPLE is Color(255, 255, 0); -const WHITE is Color(0, 0, 0); +const RED is [255, 0, 0]; +const WHITE is [0, 0, 0]; +const PURPLE is [255, 255, 0]; diff --git a/docs/project-syntax-example/src/server.ztl b/docs/project-syntax-example/src/server.ztl index 38cd40d..a51f5ab 100644 --- a/docs/project-syntax-example/src/server.ztl +++ b/docs/project-syntax-example/src/server.ztl @@ -1,6 +1,11 @@ -use "common.ztl"; +use `common.ztl`; -fn main (argc i32, argv str[]) i32 { - let s = Server("0.0.0.0:25565"); - return s.start(); +fn main (argc real, argv str[]) { + let s = `tcp://0.0.0.0:25565`; + s.bind("players", fn () Player[] { + let players = [ Player("user", (0, 0, 0), RED) ]; + return players; + }); + s.start(); + exits(nil); }