Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bytecode save/load #40

Merged
merged 6 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add save/load bytecode to http frontend
  • Loading branch information
Riey committed Oct 14, 2022
commit 5a70e580bb2436f88db5c09a14e1f639f3fc4ab4
22 changes: 18 additions & 4 deletions crates/erars-http/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
mod http_frontend;

use erars_ast::Value;
use erars_loader::run_script;
use erars_loader::{load_script, run_script, save_script};

#[derive(clap::Parser)]
#[clap(author, version, about)]
Expand All @@ -28,6 28,12 @@ struct Args {

#[clap(long, help = "HTTP port number", default_value = "8000")]
port: u16,

#[clap(long, help = "Save bytecode")]
save: bool,

#[clap(long, help = "Load bytecode")]
load: bool,
}

fn main() {
Expand Down Expand Up @@ -64,8 70,16 @@ fn main() {
None => Vec::new(),
};

let (vm, ctx, vconsole) = run_script(args.target_path, inputs).unwrap();
let (vm, ctx, vconsole) = if args.load {
unsafe { load_script(args.target_path, inputs).unwrap() }
} else {
run_script(args.target_path, inputs).unwrap()
};

let mut frontend = http_frontend::HttpFrontend::new(args.port);
frontend.run(vm, ctx, vconsole).unwrap();
if args.save {
save_script(vm, ctx).unwrap();
} else {
let mut frontend = http_frontend::HttpFrontend::new(args.port);
frontend.run(vm, ctx, vconsole).unwrap();
}
}
6 changes: 2 additions & 4 deletions crates/erars-loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 114,8 @@ pub unsafe fn load_script(
let dic = erars_bytecode::read_from(&mut read)?;

log::info!("Load game data");
let (header, local_infos): (
HeaderInfo,
HashMap<StrKey, Vec<(StrKey, VariableInfo)>>,
) = rmp_serde::decode::from_read(&mut read)?;
let (header, local_infos): (HeaderInfo, HashMap<StrKey, Vec<(StrKey, VariableInfo)>>) =
rmp_serde::decode::from_read(&mut read)?;
let mut vconsole = VirtualConsole::new(config.printc_width);

let elapsed = start.elapsed();
Expand Down