Skip to content

Commit

Permalink
Add native cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
Quaqqer committed May 1, 2024
1 parent bdf1f75 commit 1f2096f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[workspace]
resolver = "2"
members = [
"crates/saft",
"crates/saft-bytecode", "crates/saft-cli",
"crates/saft-ir",
"crates/saft-macro",
"crates/saft-syntax",
"tests",
"crates/saft",
"crates/saft-bytecode",
"crates/saft-cli",
"crates/saft-ir",
"crates/saft-macro",
"crates/saft-syntax",
"tests",
]
default-members = ["crates/saft-cli"]

Expand Down
2 changes: 1 addition & 1 deletion crates/saft-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Args {
fn main() {
let args = Args::parse();

let mut saft = Saft::new();
let mut saft = Saft::new_with_std();

match args.script {
Some(path) => {
Expand Down
21 changes: 12 additions & 9 deletions crates/saft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,8 @@ pub struct Saft {
#[allow(clippy::new_without_default)]
impl Saft {
pub fn new() -> Self {
let mut lowerer = Lowerer::new();

let mut add_native = |native: bytecode::value::NativeFunction| {
lowerer.add_item(native.name.to_string(), ir::Item::Builtin(native));
};

add_native(natives::print);

Self {
lowerer,
lowerer: Lowerer::new(),
compiler: bytecode::compiler::Compiler::new(),
vm: Vm::new(),
diagnostic_writer: codespan_reporting::term::termcolor::StandardStream::stdout(
Expand All @@ -42,6 +34,17 @@ impl Saft {
}
}

pub fn new_with_std() -> Self {
let mut saft = Self::new();
saft.add_native(saft_bytecode::natives::print);
saft
}

fn add_native(&mut self, native: saft_bytecode::value::NativeFunction) {
self.lowerer
.add_item(native.name.to_string(), ir::Item::Builtin(native));
}

fn try_parse(&mut self, fname: &str, s: &str) -> Option<ast::Module> {
let mut files = SimpleFiles::new();
let id = files.add(fname, s);
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
assert_cmd = { version = "2.0.12", features = [ "color-auto" ] }
assert_cmd = { version = "2.0.12", features = ["color-auto"] }
pretty_assertions = "1.4.0"
saft-macro = { version = "0.1.0", path = "../crates/saft-macro" }

0 comments on commit 1f2096f

Please sign in to comment.