-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from y21/node
initial node-compat mode
- Loading branch information
Showing
15 changed files
with
392 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,9 @@ | ||
use std::cell::OnceCell; | ||
|
||
use anyhow::Context; | ||
use clap::ArgMatches; | ||
use dash_compiler::FunctionCompiler; | ||
use dash_middle::compiler::CompileResult; | ||
use dash_middle::interner::StringInterner; | ||
use dash_optimizer::OptLevel; | ||
use dash_vm::frame::Exports; | ||
use dash_vm::frame::Frame; | ||
use dash_vm::localscope::LocalScope; | ||
use dash_vm::value::ops::abstractions::conversions::ValueConversion; | ||
use dash_vm::value::Value; | ||
|
||
pub fn opt_level_from_matches(args: &ArgMatches) -> anyhow::Result<OptLevel> { | ||
args.value_of("opt") | ||
.and_then(OptLevel::from_level) | ||
.context("Invalid opt level") | ||
} | ||
|
||
pub fn print_value(value: Value, scope: &mut LocalScope) -> Result<(), Value> { | ||
thread_local! { | ||
// Cache bytecode so we can avoid recompiling it every time | ||
// We can be even smarter if we need to -- cache the whole value at callsite | ||
static INSPECT_BC: OnceCell<CompileResult> = const { OnceCell::new() }; | ||
} | ||
|
||
let inspect_bc = INSPECT_BC.with(|tls| { | ||
let inspect = tls.get_or_init(|| { | ||
FunctionCompiler::compile_str( | ||
// TODO: can reuse a string interner if worth it | ||
&mut StringInterner::new(), | ||
include_str!("../../crates/dash_rt/js/inspect.js"), | ||
Default::default(), | ||
) | ||
.unwrap() | ||
}); | ||
inspect.clone() | ||
}); | ||
|
||
let Exports { | ||
default: Some(inspect_fn), | ||
.. | ||
} = scope.execute_module(Frame::from_compile_result(inspect_bc)).unwrap() | ||
else { | ||
panic!("inspect module did not have a default export"); | ||
}; | ||
|
||
let result = inspect_fn | ||
.root(scope) | ||
.apply(scope, Value::undefined(), vec![value]) | ||
.unwrap() | ||
.to_string(scope) | ||
.unwrap(); | ||
|
||
println!("{result}"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "dash_node_impl" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
dash_middle = { path = "../dash_middle" } | ||
dash_vm = { path = "../dash_vm" } | ||
dash_parser = { path = "../dash_parser", features = ["from_string"] } | ||
dash_rt = { path = "../dash_rt" } | ||
dash_optimizer = { path = "../dash_optimizer" } | ||
anyhow = "1.0" | ||
serde_json = "1.0.103" | ||
serde = { version = "1.0", features = ["derive"] } | ||
tokio = { version = "1.24.0", features = ["full"] } | ||
dash_proc_macro = { path = "../dash_proc_macro" } | ||
rustc-hash = "1.1.0" |
Oops, something went wrong.