From c6932f6b76b7af45fd7a616c0688ac5285195f29 Mon Sep 17 00:00:00 2001 From: Victor Taelin Date: Thu, 22 Feb 2024 16:11:51 -0300 Subject: [PATCH] hvm.load default empty string --- Cargo.toml | 2 +- src/runtime/base/precomp.rs | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5af0f994..c033361e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/runtime/base/precomp.rs b/src/runtime/base/precomp.rs index 078d2455..8193d854 100644 --- a/src/runtime/base/precomp.rs +++ b/src/runtime/base/precomp.rs @@ -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, &[]));