summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..78d1822
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,65 @@
+use std::fs::File;
+use std::io;
+use std::io::prelude::*;
+use std::path::Path;
+
+use boa_interner::Interner;
+use boa_parser::Parser;
+use boa_parser::Source;
+use ion::IonValue;
+use runtime::Runtime;
+
+mod ion;
+mod runtime;
+
+#[derive(Debug)]
+pub enum RelJsError {
+ IoError(io::Error),
+ JsParseError(boa_parser::Error),
+ BytecodeEOF,
+}
+
+impl From<io::Error> for RelJsError {
+ fn from(value: io::Error) -> Self {
+ RelJsError::IoError(value)
+ }
+}
+
+impl From<boa_parser::Error> for RelJsError {
+ fn from(value: boa_parser::Error) -> Self {
+ RelJsError::JsParseError(value)
+ }
+}
+
+
+
+fn main() -> Result<(), RelJsError> {
+ //let src = Source::from_filepath(Path::new("script.js"))?;
+ //let mut parser = Parser::new(src);
+ //let mut interner = Interner::new();
+ //let script = parser.parse_script(&mut interner)?;
+
+ let mut bin = File::open("demo/test-1.bin")?;
+ let mut data = Vec::new();
+ bin.read_to_end(&mut data)?;
+
+ let mut runtime = Runtime::new();
+ let fnref = runtime.load_bytecode(data);
+
+ let mut args = Vec::with_capacity(3);
+ args.push(IonValue::new_null());
+ args.push(IonValue::new_null());
+ args.push(IonValue::new_null());
+
+ let result = runtime.invoke(fnref, args);
+
+ for (i, v) in result.iter().enumerate() {
+ println!("Result {i}:");
+ for b in v.bytes() {
+ print!("{b:02x} ");
+ }
+ println!("\n");
+ }
+
+ Ok(())
+}