wip new project example

This commit is contained in:
zongor 2025-01-05 16:58:55 -05:00
parent 8c9e574a5e
commit 73e2ddae69
6 changed files with 84 additions and 114 deletions

View File

@ -6,30 +6,6 @@ _ztl_ is an language transpiler with C/Zig/Rust/Lua/Fortran/Javascript/Elixir st
# _ztl_ Grammar and Specification
## Trait
Describes an interface that can be applied to a type, collisions are not important as the names of traits only carry what needs to be implemented a not any implementation itself. for people coming from OOP you can think of traits similar to an abstract class.
```
trait Hashable {
fn hash(self) -> u64
}
struct Vec {
x: f32,
y: f32,
z: f32,
}
! maybe the worst hash function ever?
impl Hashable Vec {
fn hash(self: Vec) -> u64 {
return (self.x bxor (self.y sll 16) bxor (self.z sll 32) bor (self.z sll 48))
}
}
```
## Types
- Types can be either structs, enums, or unions.
@ -42,15 +18,7 @@ impl Hashable Vec {
- there are also a list of "substantial types" which come with the language which are the building blocks for more complex types. If you are coming from object oriented languages you can think of self as "primitive types"
```
struct «type_token» {
! values
}
enum «type_token» {
! values
}
union «type_token» {
type «type_token» {
! values
}
```
@ -111,12 +79,11 @@ Also follows the style boolean 'c' rules of nonzero / zero, but the compiler wil
## null values
```
let a = 3
let b = nil
let c = #"nope!"
let a:i8 = 3
let b:i8
let x = a
let y = b ?? 1
let x:i8 = a
let y:i8 = b ?? 1
stdout.write("%d%d\n", x, y) ! outputs 3, 1
```
@ -140,7 +107,7 @@ Much like Lua, zwl only has tables. Lua's tables are amazing and very unique. Wh
syntax (yes I was nice and kept the syntax the same as most C like langs)
```
let «variable» = «type»[] ! same as a map of int->«type»
let «variable»: «type»[] ! same as a map of int->«type»
!or as an array
@ -148,7 +115,7 @@ let «variable» = [val1, val2, ...]
! or as a map
let «variable» = {key1: val1, key2: val2, ...}
let «variable»: «type»->«type» = {key1: val1, key2: val2, ...}
```
### tunnel
@ -331,7 +298,7 @@ in "web mode" the default tunnels are log, info, trace, warn, error, but note th
## Functions
```
fn «token» («type» «parameter», ...) -> «return_type» {
fn «token» («parameter»: «type», ...): «return_type» {
«instructions»
}
```

View File

@ -21,7 +21,7 @@
:str 1 check
(* do the login here *)
} sub
} fn
255 255 0 :purple color
@ -33,15 +33,15 @@
:username str
:password str
username 0.0 f32 1.0 f32 2.0 f32 vec purple :me player
username 0.0 1.0 2.0 purple :me player
password me login :players set
me.pos.x
me.pos.y 10.0 add
me.pos.z 10.0 add vec (* Camera pos *)
me.pos.z 10.0 add (* Camera pos *)
me.pos (* Camera looking at point *)
0.0 1.0 0.0 vec (* Camera up vector(rotation towards target) *)
45.0 f32 (* Camera field - of - view Y *)
0.0 1.0 0.0 (* Camera up vector(rotation towards target) *)
45.0 (* Camera field - of - view Y *)
:CAMERA_PERSPECTIVE (* Camera projection type *)
:camera Camera3D
@ -50,7 +50,6 @@
(* Main game loop *)
{
:KEY_RIGHT is_key_down {
0.2 me.pos.x add :me.pos.x set
true :player_updated set
@ -96,10 +95,10 @@
end_drawing
}
{ window_should_close not } while (* Detect window close button or ESC key *)
{ window_should_close not } loop-if (* Detect window close button or ESC key *)
close_window (*Close window and OpenGL context *)
} sub
} fn
main

View File

@ -1,43 +1,47 @@
fn build(c: ProjectConfig) {
c.name("MMO Project");
c.client("src/", {
"c":{
"ffi": [
{
c.client([
LanguageSettings {
lang: "c",
file: "src/client.ztl",
outpath: "client/",
ffi: [
FFISetting {
"name":"raylib",
"library":"$RAYLIB_PATH/libraylib.a",
"path":"",
"build": "make build",
}
],
"out": "client/"
]
}
})
])
c.server("src/",{
"javascript":{
"out":"server/"
c.server([
LanguageSettings {
lang: "javascript",
file: "src/server.ztl",
outpath: "server/"
}
});
]);
c.database("src/",{
"sqlite":{
"out":"db/"
}
});
c.common("src/",{
"c":{
"out":"server/"
c.common([
LanguageSettings {
lang: "c",
file: "src/common.ztl",
outpath: "client/"
},
"javascript":{
"out":"client/"
LanguageSettings {
lang: "javascript",
file: "src/common.ztl",
outpath: "server/"
},
"sqlite":{
"out":"db/"
LanguageSettings {
lang: "sqlite",
file: "src/common.ztl",
outpath: "db/"
}
});
]);
c.build();
}

View File

@ -1,19 +1,19 @@
use "common.ztl"
fn login(s: tunnel, p: Player, password: str)->Player[] {
s.auth(p.username, password);
fn login(s: 9p, p: Player, password: str): []Player {
s.auth(p.username, password)
return s.read("players")
}
fn main(argc: int, argv: str[]) {
const screen_width: i32 = 800;
const screen_height: i32 = 450;
fn main(argc: i32, argv: []str): i32 {
const screen_width = 800;
const screen_height = 450;
let username = argv[0];
let password = argv[1];
let s = tunnel();
s.attach("localhost:25565");
let s = tunnel("localhost:25565");
s.attach();
let me = Player(
username,
@ -35,28 +35,28 @@ fn main(argc: int, argv: str[]) {
);
init_window("zwl client : raylib", screen_width, screen_height);
set_target_fps(60)
set_target_fps(60);
(* Main game loop *)
while ( not window_should_close() ) {
let player_updated = false
let player_updated = false;
if (is_key_down(:KEY_RIGHT)) {
if (is_key_down(KEY_RIGHT)) {
me.pos.x = me.pos.x + 0.2;
player_updated = true;
}
if (is_key_down(:KEY_LEFT)) {
if (is_key_down(KEY_LEFT)) {
me.pos.x = me.pos.x - 0.2;
player_updated = true;
}
if (is_key_down(:KEY_DOWN)) {
if (is_key_down(KEY_DOWN)) {
me.pos.z = me.pos.z + 0.2;
player_updated = true;
}
if (is_key_down(:KEY_UP)) {
if (is_key_down(KEY_UP)) {
me.pos.z = me.pos.z - 0.2;
player_updated = true;
}
@ -70,7 +70,7 @@ fn main(argc: int, argv: str[]) {
}
begin_drawing();
clear_background(:RAYWHITE);
clear_background(RAYWHITE);
begin_mode_3d(camera);

View File

@ -5,9 +5,9 @@ type Vec {
}
type Color {
r: i8,
g: i8,
b: i8,
r: u8,
g: u8,
b: u8,
}
type Player {
@ -16,4 +16,4 @@ type Player {
color: Color,
}
const purple = Color(255, 255, 0);
const purple = Color{255, 255, 0};

View File

@ -1,7 +1,7 @@
use "common.ztl"
fn main(argc, argv) {
tunnel s();
fn main(argc: i32, argv: []str): i32 {
let s = tunnel();
s.host("0.0.0.0:25565",
version,
auth,
@ -18,42 +18,42 @@ fn main(argc, argv) {
stat);
}
fn version(m) {
fn version(m : 9pmsg) {
}
fn auth(m) {
fn auth(m : 9pmsg) {
}
fn error(m) {
fn error(m : 9pmsg) {
}
fn flush(m) {
fn flush(m : 9pmsg) {
}
fn attach(m) {
fn attach(m : 9pmsg) {
}
fn walk(m) {
fn walk(m : 9pmsg) {
}
fn open(m) {
fn open(m : 9pmsg) {
}
fn create(m) {
fn create(m : 9pmsg) {
}
fn read(m) {
fn read(m : 9pmsg) {
}
fn write(m) {
fn write(m : 9pmsg) {
}
fn clunk(m) {
fn clunk(m : 9pmsg) {
}
fn remove(m) {
fn remove(m : 9pmsg) {
}
fn stat(m) {
fn stat(m : 9pmsg) {
}