From 4c892e1d65996c094debf5d2065900d971a359f2 Mon Sep 17 00:00:00 2001 From: Ivory Date: Sat, 27 May 2023 03:10:31 -0400 Subject: [PATCH] init stuff --- Cargo.lock | 267 +++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/lang.bnf | 44 +++++++ src/main.rs | 42 ++++++- src/person.vm | 1 + src/scene.rs | 34 ++++++ test/modules/person.vm | 5 + vlib/Ticker.vm | 30 +++++ vlib/Time.vm | 4 + 9 files changed, 427 insertions(+), 1 deletion(-) create mode 100644 src/lang.bnf create mode 100644 src/person.vm create mode 100644 src/scene.rs create mode 100644 test/modules/person.vm create mode 100644 vlib/Ticker.vm create mode 100644 vlib/Time.vm diff --git a/Cargo.lock b/Cargo.lock index c87459a..25ff8d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,273 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "bnf" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c09ea5795b3dd735ff47c4b8adf64c46e3ce056fa3c4880b865a352e4c40a2" +dependencies = [ + "getrandom", + "nom", + "rand", + "serde", + "serde_json", +] + +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "js-sys" +version = "0.3.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.144" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa1fb82fc0c281dd9671101b66b771ebbe1eaf967b96ac8740dcba4b70005ca8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "rgraph" version = "0.1.0" +dependencies = [ + "bnf", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "serde" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" diff --git a/Cargo.toml b/Cargo.toml index 486b90d..5c3a352 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bnf = "0.5.0" diff --git a/src/lang.bnf b/src/lang.bnf new file mode 100644 index 0000000..f78b86e --- /dev/null +++ b/src/lang.bnf @@ -0,0 +1,44 @@ + ::= + | + + ::= + | + + + + + + ::= "handle" + ::= "use" + + + + + + ::= "{ }" + ::= "()" + + + + ::= | "::" + ::= "$" + + ::= + | + | + + ::= + | + + ::= | + ::= | | + + ::= | + ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" + ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" + ::= "" + ::= " " + ::= " +" | " +" + ::= " " \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e7a11a9..fd521c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,43 @@ +// mod scene; + +// use crate::scene::Scene; +use bnf::Grammar; + + fn main() { - println!("Hello, world!"); + + let input = include_str!("lang.bnf"); + let grammar: Grammar = input.parse().unwrap(); + + let vm_file = include_str!("person.vm"); + + let parsed = grammar.parse_input(vm_file); + + println!("---"); + println!("{}", vm_file); + println!("---"); + + for tree in parsed { + println!("{}", tree.lhs); + } + + println!("---"); + + // println!("{:?}", ); + + // let sentence = grammar.generate(); + // match sentence { + // Ok(s) => println!(" --- random program\n{}\n ---", s), + // Err(e) => println!("something went wrong: {}!", e) + // } + + // let scene = Scene::new(); } + +struct Program { + declarations: Vec<&dyn Declaration> +} + +trait Declaration { + +} \ No newline at end of file diff --git a/src/person.vm b/src/person.vm new file mode 100644 index 0000000..d6e9cc4 --- /dev/null +++ b/src/person.vm @@ -0,0 +1 @@ +use vlib::Console \ No newline at end of file diff --git a/src/scene.rs b/src/scene.rs new file mode 100644 index 0000000..add43d5 --- /dev/null +++ b/src/scene.rs @@ -0,0 +1,34 @@ + + +pub struct Scene { + +} + +impl Scene { + pub fn new () -> Self { + return Self { + + }; + } + + pub fn loadDirectory() { + + } +} + + + + + + +struct Module { + +} + +impl Module { + pub fn new () -> Self { + return Self { + + } + } +} \ No newline at end of file diff --git a/test/modules/person.vm b/test/modules/person.vm new file mode 100644 index 0000000..52461f5 --- /dev/null +++ b/test/modules/person.vm @@ -0,0 +1,5 @@ +use vlib::Console + +handle start() { + Console.log("Hello World"); +} \ No newline at end of file diff --git a/vlib/Ticker.vm b/vlib/Ticker.vm new file mode 100644 index 0000000..94f2fb1 --- /dev/null +++ b/vlib/Ticker.vm @@ -0,0 +1,30 @@ +use vlib::Console; + +Set tickables +f64 lastTick + +interface Tickable { + handle tick(f64 dTime) +} + +handle start() { + defer(tick) +} + +handle added(Tickable e) { + tickables.add(e) +} + +handle removed(Tickable e) { + tickables.remove(e) +} + +handle internal tick() { + f64 time = $Time.sinceStart() + f64 dTime = time - lastTick + for(Tickable t : tickables) { + t.tick() + } + lastTick = time + defer(tick) +} \ No newline at end of file diff --git a/vlib/Time.vm b/vlib/Time.vm new file mode 100644 index 0000000..2335591 --- /dev/null +++ b/vlib/Time.vm @@ -0,0 +1,4 @@ +// use vlib::Time::getTimeSinceStart; + +// mode entry; +