Skip to content

Commit

Permalink
hvm.load default empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTaelin committed Feb 22, 2024
1 parent 9420e05 commit c6932f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hvm1"
version = "1.0.13"
version = "1.0.14"
edition = "2021"
description = "A massively parallel functional runtime."
repository = "https://github.com/HigherOrderCO/HVM1"
Expand Down
23 changes: 11 additions & 12 deletions src/runtime/base/precomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,18 +462,17 @@ fn hvm_load_visit(ctx: ReduceCtx) -> bool {

fn hvm_load_apply(ctx: ReduceCtx) -> bool {
if let Some(key) = crate::language::readback::as_string(ctx.heap, ctx.prog, &[ctx.tid], get_loc(ctx.term, 0)) {
if let Ok(file) = std::fs::read(key) {
if let Ok(file) = std::str::from_utf8(&file) {
let cont = load_arg(ctx.heap, ctx.term, 1);
let text = make_string(ctx.heap, ctx.tid, file);
let app0 = alloc(ctx.heap, ctx.tid, 2);
link(ctx.heap, app0 + 0, cont);
link(ctx.heap, app0 + 1, text);
free(ctx.heap, 0, get_loc(ctx.term, 0), 2);
let done = App(app0);
link(ctx.heap, *ctx.host, done);
return true;
}
let file = std::fs::read(key).unwrap_or_else(|_| Vec::new());
if let Ok(file) = std::str::from_utf8(&file) {
let cont = load_arg(ctx.heap, ctx.term, 1);
let text = make_string(ctx.heap, ctx.tid, file);
let app0 = alloc(ctx.heap, ctx.tid, 2);
link(ctx.heap, app0 + 0, cont);
link(ctx.heap, app0 + 1, text);
free(ctx.heap, 0, get_loc(ctx.term, 0), 2);
let done = App(app0);
link(ctx.heap, *ctx.host, done);
return true;
}
}
println!("Runtime failure on: {}", show_at(ctx.heap, ctx.prog, *ctx.host, &[]));
Expand Down

0 comments on commit c6932f6

Please sign in to comment.