From 254576dcc81cec952d11e35038f816925e1671ab Mon Sep 17 00:00:00 2001 From: David Ellis Date: Sun, 22 Dec 2024 13:48:30 -0600 Subject: [PATCH] Rearrange the monorepo and add a very basic web compiler --- Cargo.lock | 38 ++- Cargo.toml | 2 +- alan/Cargo.toml | 7 +- alan/src/compile/integration_tests.rs | 40 +-- alan/src/compile/mod.rs | 6 +- alan/src/main.rs | 6 +- alan_compiler/Cargo.toml | 16 + {alan => alan_compiler}/src/lib.rs | 1 - .../src/lntojs/function.rs | 0 {alan => alan_compiler}/src/lntojs/mod.rs | 0 {alan => alan_compiler}/src/lntojs/typen.rs | 0 .../src/lntors/function.rs | 0 {alan => alan_compiler}/src/lntors/mod.rs | 0 {alan => alan_compiler}/src/lntors/typen.rs | 0 {alan => alan_compiler}/src/parse.rs | 0 .../src/program/argkind.rs | 0 {alan => alan_compiler}/src/program/constn.rs | 0 {alan => alan_compiler}/src/program/ctype.rs | 0 {alan => alan_compiler}/src/program/export.rs | 0 {alan => alan_compiler}/src/program/fnkind.rs | 0 .../src/program/function.rs | 0 .../src/program/microstatement.rs | 0 {alan => alan_compiler}/src/program/mod.rs | 0 .../src/program/operatormapping.rs | 0 .../src/program/program.rs | 0 {alan => alan_compiler}/src/program/scope.rs | 0 .../src/program/typeoperatormapping.rs | 0 {alan => alan_compiler}/src/std/README.md | 0 {alan => alan_compiler}/src/std/fs.ln | 0 {alan => alan_compiler}/src/std/root.ln | 0 {alan => alan_compiler}/src/std/seq.ln | 0 {alan => web_compiler}/Cargo.lock | 301 +++++++++--------- web_compiler/Cargo.toml | 17 + web_compiler/src/lib.rs | 22 ++ 34 files changed, 256 insertions(+), 200 deletions(-) create mode 100644 alan_compiler/Cargo.toml rename {alan => alan_compiler}/src/lib.rs (79%) rename {alan => alan_compiler}/src/lntojs/function.rs (100%) rename {alan => alan_compiler}/src/lntojs/mod.rs (100%) rename {alan => alan_compiler}/src/lntojs/typen.rs (100%) rename {alan => alan_compiler}/src/lntors/function.rs (100%) rename {alan => alan_compiler}/src/lntors/mod.rs (100%) rename {alan => alan_compiler}/src/lntors/typen.rs (100%) rename {alan => alan_compiler}/src/parse.rs (100%) rename {alan => alan_compiler}/src/program/argkind.rs (100%) rename {alan => alan_compiler}/src/program/constn.rs (100%) rename {alan => alan_compiler}/src/program/ctype.rs (100%) rename {alan => alan_compiler}/src/program/export.rs (100%) rename {alan => alan_compiler}/src/program/fnkind.rs (100%) rename {alan => alan_compiler}/src/program/function.rs (100%) rename {alan => alan_compiler}/src/program/microstatement.rs (100%) rename {alan => alan_compiler}/src/program/mod.rs (100%) rename {alan => alan_compiler}/src/program/operatormapping.rs (100%) rename {alan => alan_compiler}/src/program/program.rs (100%) rename {alan => alan_compiler}/src/program/scope.rs (100%) rename {alan => alan_compiler}/src/program/typeoperatormapping.rs (100%) rename {alan => alan_compiler}/src/std/README.md (100%) rename {alan => alan_compiler}/src/std/fs.ln (100%) rename {alan => alan_compiler}/src/std/root.ln (100%) rename {alan => alan_compiler}/src/std/seq.ln (100%) rename {alan => web_compiler}/Cargo.lock (71%) create mode 100644 web_compiler/Cargo.toml create mode 100644 web_compiler/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 8b30b6b74..838f592cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ab_glyph" @@ -35,10 +35,17 @@ dependencies = [ name = "alan" version = "0.2.0" dependencies = [ + "alan_compiler", "clap", "dirs", "divan", "fs2", +] + +[[package]] +name = "alan_compiler" +version = "0.2.0" +dependencies = [ "nom", "ordered_hash_map", ] @@ -1935,9 +1942,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", @@ -1946,13 +1953,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn", @@ -1973,9 +1979,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1983,9 +1989,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", @@ -1996,9 +2002,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "wayland-backend" @@ -2129,6 +2135,14 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web_compiler" +version = "0.2.0" +dependencies = [ + "alan_compiler", + "wasm-bindgen", +] + [[package]] name = "wgpu" version = "23.0.1" diff --git a/Cargo.toml b/Cargo.toml index ac478fe66..7796f6d33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ [workspace] -members = [ "alan", "alan_std" ] +members = [ "alan", "alan_compiler", "alan_std", "web_compiler" ] resolver = "2" \ No newline at end of file diff --git a/alan/Cargo.toml b/alan/Cargo.toml index 67d6fb096..88d74c0f3 100644 --- a/alan/Cargo.toml +++ b/alan/Cargo.toml @@ -12,11 +12,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +alan_compiler = { path = "../alan_compiler" } clap = { version = "4.5.23", features = ["derive"] } dirs = "5.0.1" fs2 = "0.4.3" -nom = "7.1.3" -ordered_hash_map = "0.4.0" [dev-dependencies] divan = "0.1.17" @@ -28,7 +27,3 @@ harness = false [[bench]] name = "fill" harness = false - -[[bin]] -name = "alan" -test = false diff --git a/alan/src/compile/integration_tests.rs b/alan/src/compile/integration_tests.rs index 9f7cc4717..e49ffb7b6 100644 --- a/alan/src/compile/integration_tests.rs +++ b/alan/src/compile/integration_tests.rs @@ -17,7 +17,7 @@ macro_rules! test { mod $rule { #[test] fn $rule() -> Result<(), Box> { - crate::program::Program::set_target_lang_rs(); + alan_compiler::program::Program::set_target_lang_rs(); let filename = format!("{}.ln", stringify!($rule)); match std::fs::write(&filename, $code) { Ok(_) => { /* Do nothing */ } @@ -25,9 +25,9 @@ macro_rules! test { return Err(format!("Unable to write {} to disk. {:?}", filename, e).into()); } }; - let mut program = crate::program::Program::get_program(); + let mut program = alan_compiler::program::Program::get_program(); program.env.insert("ALAN_TARGET".to_string(), "test".to_string()); - crate::program::Program::return_program(program); + alan_compiler::program::Program::return_program(program); match crate::compile::build(filename.to_string()) { Ok(_) => { /* Do nothing */ } Err(e) => { @@ -49,10 +49,10 @@ macro_rules! test { Ok(a) => Ok(a), Err(e) => Err(format!("Could not remove the test binary {:?}", e)), }?; - crate::program::Program::set_target_lang_js(); - let mut program = crate::program::Program::get_program(); + alan_compiler::program::Program::set_target_lang_js(); + let mut program = alan_compiler::program::Program::get_program(); program.env.insert("ALAN_TARGET".to_string(), "test".to_string()); - crate::program::Program::return_program(program); + alan_compiler::program::Program::return_program(program); match crate::compile::web(filename.to_string()) { Ok(_) => { /* Do nothing */ } Err(e) => { @@ -84,16 +84,16 @@ macro_rules! test { mod $rule { #[test] fn $rule() -> Result<(), Box> { - crate::program::Program::set_target_lang_rs(); + alan_compiler::program::Program::set_target_lang_rs(); $( match std::fs::write($filename, $code) { Ok(_) => { /* Do nothing */ } Err(e) => { return Err(format!("Unable to write {} to disk. {:?}", $filename, e).into()); } })+ - let mut program = crate::program::Program::get_program(); + let mut program = alan_compiler::program::Program::get_program(); program.env.insert("ALAN_TARGET".to_string(), "test".to_string()); - crate::program::Program::return_program(program); + alan_compiler::program::Program::return_program(program); match crate::compile::build(format!("{}.ln", $entryfile)) { Ok(_) => { /* Do nothing */ } Err(e) => { @@ -115,10 +115,10 @@ macro_rules! test { Ok(a) => Ok(a), Err(e) => Err(format!("Could not remove the test binary {:?}", e)), }?; - crate::program::Program::set_target_lang_js(); - let mut program = crate::program::Program::get_program(); + alan_compiler::program::Program::set_target_lang_js(); + let mut program = alan_compiler::program::Program::get_program(); program.env.insert("ALAN_TARGET".to_string(), "test".to_string()); - crate::program::Program::return_program(program); + alan_compiler::program::Program::return_program(program); match crate::compile::web(format!("{}.ln", $entryfile)) { Ok(_) => { /* Do nothing */ } Err(e) => { @@ -152,7 +152,7 @@ macro_rules! test_gpgpu { mod $rule { #[test] fn $rule() -> Result<(), Box> { - crate::program::Program::set_target_lang_rs(); + alan_compiler::program::Program::set_target_lang_rs(); let filename = format!("{}.ln", stringify!($rule)); match std::fs::write(&filename, $code) { Ok(_) => { /* Do nothing */ } @@ -160,9 +160,9 @@ macro_rules! test_gpgpu { return Err(format!("Unable to write {} to disk. {:?}", filename, e).into()); } }; - let mut program = crate::program::Program::get_program(); + let mut program = alan_compiler::program::Program::get_program(); program.env.insert("ALAN_TARGET".to_string(), "test".to_string()); - crate::program::Program::return_program(program); + alan_compiler::program::Program::return_program(program); match crate::compile::build(filename.to_string()) { Ok(_) => { /* Do nothing */ } Err(e) => { @@ -191,10 +191,10 @@ macro_rules! test_gpgpu { // to just MacOS to test this on. // if cfg!(windows) || cfg!(macos) { if cfg!(target_os = "macos") { - crate::program::Program::set_target_lang_js(); - let mut program = crate::program::Program::get_program(); + alan_compiler::program::Program::set_target_lang_js(); + let mut program = alan_compiler::program::Program::get_program(); program.env.insert("ALAN_TARGET".to_string(), "test".to_string()); - crate::program::Program::return_program(program); + alan_compiler::program::Program::return_program(program); match crate::compile::web(filename.to_string()) { Ok(_) => { /* Do nothing */ } Err(e) => { @@ -274,9 +274,9 @@ macro_rules! test_ignore { return Err(format!("Unable to write {} to disk. {:?}", filename, e).into()); } }; - let mut program = crate::program::Program::get_program(); + let mut program = alan_compiler::program::Program::get_program(); program.env.insert("ALAN_TARGET".to_string(), "test".to_string()); - crate::program::Program::return_program(program); + alan_compiler::program::Program::return_program(program); match crate::compile::build(filename.to_string()) { Ok(_) => { /* Do nothing */ } Err(e) => { diff --git a/alan/src/compile/mod.rs b/alan/src/compile/mod.rs index 326ecfebf..47226cb77 100644 --- a/alan/src/compile/mod.rs +++ b/alan/src/compile/mod.rs @@ -8,9 +8,9 @@ use std::time::{Instant, SystemTime, UNIX_EPOCH}; use dirs::config_dir; use fs2::FileExt; -use crate::lntojs::lntojs; -use crate::lntors::lntors; -use crate::program::Program; +use alan_compiler::lntojs::lntojs; +use alan_compiler::lntors::lntors; +use alan_compiler::program::Program; mod integration_tests; diff --git a/alan/src/main.rs b/alan/src/main.rs index ed4459c42..903c88ca7 100644 --- a/alan/src/main.rs +++ b/alan/src/main.rs @@ -1,11 +1,7 @@ use crate::compile::{bundle, compile, test, to_js, to_rs}; use clap::{Parser, Subcommand}; -mod compile; -mod lntojs; -mod lntors; -mod parse; -mod program; +pub mod compile; #[derive(Parser, Debug)] #[command(author, version, about, propagate_version = true)] diff --git a/alan_compiler/Cargo.toml b/alan_compiler/Cargo.toml new file mode 100644 index 000000000..d47d3907f --- /dev/null +++ b/alan_compiler/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "alan_compiler" +description = "The Alan Compiler" +license = "MIT" +homepage = "https://alan-lang.org" +documentation = "https://docs.alan-lang.org" +repository = "https://github.com/alantech/alan" +version = "0.2.0" +authors = ["David Ellis "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +nom = "7.1.3" +ordered_hash_map = "0.4.0" diff --git a/alan/src/lib.rs b/alan_compiler/src/lib.rs similarity index 79% rename from alan/src/lib.rs rename to alan_compiler/src/lib.rs index 5e1486445..baed3350f 100644 --- a/alan/src/lib.rs +++ b/alan_compiler/src/lib.rs @@ -1,4 +1,3 @@ -pub mod compile; pub mod lntojs; pub mod lntors; pub mod parse; diff --git a/alan/src/lntojs/function.rs b/alan_compiler/src/lntojs/function.rs similarity index 100% rename from alan/src/lntojs/function.rs rename to alan_compiler/src/lntojs/function.rs diff --git a/alan/src/lntojs/mod.rs b/alan_compiler/src/lntojs/mod.rs similarity index 100% rename from alan/src/lntojs/mod.rs rename to alan_compiler/src/lntojs/mod.rs diff --git a/alan/src/lntojs/typen.rs b/alan_compiler/src/lntojs/typen.rs similarity index 100% rename from alan/src/lntojs/typen.rs rename to alan_compiler/src/lntojs/typen.rs diff --git a/alan/src/lntors/function.rs b/alan_compiler/src/lntors/function.rs similarity index 100% rename from alan/src/lntors/function.rs rename to alan_compiler/src/lntors/function.rs diff --git a/alan/src/lntors/mod.rs b/alan_compiler/src/lntors/mod.rs similarity index 100% rename from alan/src/lntors/mod.rs rename to alan_compiler/src/lntors/mod.rs diff --git a/alan/src/lntors/typen.rs b/alan_compiler/src/lntors/typen.rs similarity index 100% rename from alan/src/lntors/typen.rs rename to alan_compiler/src/lntors/typen.rs diff --git a/alan/src/parse.rs b/alan_compiler/src/parse.rs similarity index 100% rename from alan/src/parse.rs rename to alan_compiler/src/parse.rs diff --git a/alan/src/program/argkind.rs b/alan_compiler/src/program/argkind.rs similarity index 100% rename from alan/src/program/argkind.rs rename to alan_compiler/src/program/argkind.rs diff --git a/alan/src/program/constn.rs b/alan_compiler/src/program/constn.rs similarity index 100% rename from alan/src/program/constn.rs rename to alan_compiler/src/program/constn.rs diff --git a/alan/src/program/ctype.rs b/alan_compiler/src/program/ctype.rs similarity index 100% rename from alan/src/program/ctype.rs rename to alan_compiler/src/program/ctype.rs diff --git a/alan/src/program/export.rs b/alan_compiler/src/program/export.rs similarity index 100% rename from alan/src/program/export.rs rename to alan_compiler/src/program/export.rs diff --git a/alan/src/program/fnkind.rs b/alan_compiler/src/program/fnkind.rs similarity index 100% rename from alan/src/program/fnkind.rs rename to alan_compiler/src/program/fnkind.rs diff --git a/alan/src/program/function.rs b/alan_compiler/src/program/function.rs similarity index 100% rename from alan/src/program/function.rs rename to alan_compiler/src/program/function.rs diff --git a/alan/src/program/microstatement.rs b/alan_compiler/src/program/microstatement.rs similarity index 100% rename from alan/src/program/microstatement.rs rename to alan_compiler/src/program/microstatement.rs diff --git a/alan/src/program/mod.rs b/alan_compiler/src/program/mod.rs similarity index 100% rename from alan/src/program/mod.rs rename to alan_compiler/src/program/mod.rs diff --git a/alan/src/program/operatormapping.rs b/alan_compiler/src/program/operatormapping.rs similarity index 100% rename from alan/src/program/operatormapping.rs rename to alan_compiler/src/program/operatormapping.rs diff --git a/alan/src/program/program.rs b/alan_compiler/src/program/program.rs similarity index 100% rename from alan/src/program/program.rs rename to alan_compiler/src/program/program.rs diff --git a/alan/src/program/scope.rs b/alan_compiler/src/program/scope.rs similarity index 100% rename from alan/src/program/scope.rs rename to alan_compiler/src/program/scope.rs diff --git a/alan/src/program/typeoperatormapping.rs b/alan_compiler/src/program/typeoperatormapping.rs similarity index 100% rename from alan/src/program/typeoperatormapping.rs rename to alan_compiler/src/program/typeoperatormapping.rs diff --git a/alan/src/std/README.md b/alan_compiler/src/std/README.md similarity index 100% rename from alan/src/std/README.md rename to alan_compiler/src/std/README.md diff --git a/alan/src/std/fs.ln b/alan_compiler/src/std/fs.ln similarity index 100% rename from alan/src/std/fs.ln rename to alan_compiler/src/std/fs.ln diff --git a/alan/src/std/root.ln b/alan_compiler/src/std/root.ln similarity index 100% rename from alan/src/std/root.ln rename to alan_compiler/src/std/root.ln diff --git a/alan/src/std/seq.ln b/alan_compiler/src/std/seq.ln similarity index 100% rename from alan/src/std/seq.ln rename to alan_compiler/src/std/seq.ln diff --git a/alan/Cargo.lock b/web_compiler/Cargo.lock similarity index 71% rename from alan/Cargo.lock rename to web_compiler/Cargo.lock index 6eba02af8..9cef892ed 100644 --- a/alan/Cargo.lock +++ b/web_compiler/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ahash" @@ -17,20 +17,28 @@ dependencies = [ [[package]] name = "alan" version = "0.2.0" +source = "git+https://github.com/alantech/alan#31613bb869c774409e80826a8a8dcede1df31c19" dependencies = [ "clap", "dirs", - "divan", "fs2", "nom", "ordered_hash_map", ] +[[package]] +name = "alan_web" +version = "0.2.0" +dependencies = [ + "alan", + "wasm-bindgen", +] + [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -43,36 +51,36 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -81,6 +89,12 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "cfg-if" version = "1.0.0" @@ -89,9 +103,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.16" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -99,22 +113,21 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.15" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", "clap_lex", "strsim", - "terminal_size", ] [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ "heck", "proc-macro2", @@ -124,21 +137,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "colorchoice" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" - -[[package]] -name = "condtype" -version = "1.3.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "dirs" @@ -161,41 +168,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "divan" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0d567df2c9c2870a43f3f2bd65aaeb18dbce1c18f217c3e564b4fbaeb3ee56c" -dependencies = [ - "cfg-if", - "clap", - "condtype", - "divan-macros", - "libc", - "regex-lite", -] - -[[package]] -name = "divan-macros" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27540baf49be0d484d8f0130d7d8da3011c32a44d4fc873368154f1510e574a2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "fs2" version = "0.4.3" @@ -234,15 +206,15 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libredox" @@ -255,10 +227,10 @@ dependencies = [ ] [[package]] -name = "linux-raw-sys" -version = "0.4.14" +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" @@ -284,9 +256,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "option-ext" @@ -305,52 +277,33 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] [[package]] name = "redox_users" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", "thiserror", ] -[[package]] -name = "regex-lite" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" - -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - [[package]] name = "strsim" version = "0.11.1" @@ -359,39 +312,29 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.68" +version = "2.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "terminal_size" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" -dependencies = [ - "rustix", - "windows-sys 0.48.0", -] - [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -400,9 +343,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "utf8parse" @@ -412,9 +355,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -422,6 +365,60 @@ 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.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" + [[package]] name = "winapi" version = "0.3.9" @@ -455,11 +452,11 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.52.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -479,18 +476,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -501,9 +498,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -513,9 +510,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -525,15 +522,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -543,9 +540,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -555,9 +552,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -567,9 +564,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -579,24 +576,24 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", diff --git a/web_compiler/Cargo.toml b/web_compiler/Cargo.toml new file mode 100644 index 000000000..606455035 --- /dev/null +++ b/web_compiler/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "web_compiler" +description = "A limited version of the Alan Compiler to run inside of the browser" +license = "MIT" +homepage = "https://alan-lang.org" +documentation = "https://docs.alan-lang.org" +repository = "https://github.com/alantech/alan" +version = "0.2.0" +authors = ["David Ellis "] +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +alan_compiler = { path = "../alan_compiler" } +wasm-bindgen = "0.2.99" diff --git a/web_compiler/src/lib.rs b/web_compiler/src/lib.rs new file mode 100644 index 000000000..3e6ffae3f --- /dev/null +++ b/web_compiler/src/lib.rs @@ -0,0 +1,22 @@ +use wasm_bindgen::prelude::*; + +use alan_compiler::lntojs::lntojs; +use alan_compiler::program::Program; +use alan_compiler::program::Scope; + +#[wasm_bindgen] +pub fn compile(src: &str) -> String { + Program::set_target_lang_js(); + match Scope::from_src("program.ln", src.to_string()) { + Err(e) => { + return format!("{:?}", e); + } + Ok(_) => {} + }; + match lntojs("program.ln".to_string()) { + Err(e) => { + return format!("{:?}", e); + } + Ok((js, _)) => js, + } +}