Skip to content

Commit

Permalink
Rearrange the monorepo and add a very basic web compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
dfellis committed Dec 22, 2024
1 parent 31613bb commit 254576d
Show file tree
Hide file tree
Showing 34 changed files with 256 additions and 200 deletions.
38 changes: 26 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[workspace]

members = [ "alan", "alan_std" ]
members = [ "alan", "alan_compiler", "alan_std", "web_compiler" ]
resolver = "2"
7 changes: 1 addition & 6 deletions alan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,7 +27,3 @@ harness = false
[[bench]]
name = "fill"
harness = false

[[bin]]
name = "alan"
test = false
40 changes: 20 additions & 20 deletions alan/src/compile/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ macro_rules! test {
mod $rule {
#[test]
fn $rule() -> Result<(), Box<dyn std::error::Error>> {
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 */ }
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(filename.to_string()) {
Ok(_) => { /* Do nothing */ }
Err(e) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -84,16 +84,16 @@ macro_rules! test {
mod $rule {
#[test]
fn $rule() -> Result<(), Box<dyn std::error::Error>> {
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) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -152,17 +152,17 @@ macro_rules! test_gpgpu {
mod $rule {
#[test]
fn $rule() -> Result<(), Box<dyn std::error::Error>> {
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 */ }
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(filename.to_string()) {
Ok(_) => { /* Do nothing */ }
Err(e) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions alan/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 1 addition & 5 deletions alan/src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
16 changes: 16 additions & 0 deletions alan_compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
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"
1 change: 0 additions & 1 deletion alan/src/lib.rs → alan_compiler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod compile;
pub mod lntojs;
pub mod lntors;
pub mod parse;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 254576d

Please sign in to comment.