Add host stdlib modules and unify view/run capabilities.
Ship fs/time/sys/json/net L1 libs (plus existing text/table), default-on host caps with soft exit under view, bilingual public/stdlib docs, and design notes for deferred math/foreign. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a5d30c00b3
commit
a53ebb65ee
66 files changed
+2703
-45
No files matched your search
@@ -13,6 +13,7 @@ use crate::builtin::{
|
||||
};
|
||||
use crate::debug::emit_trace;
|
||||
use crate::diagnostics::{bail_at, Span};
|
||||
use crate::host::{call_host, HostContext, HostFn};
|
||||
use crate::input_feed::InputFeed;
|
||||
use crate::value::Value;
|
||||
|
||||
@@ -23,6 +24,7 @@ pub struct Interpreter {
|
||||
pub captured_stdout: String,
|
||||
current_span: Span,
|
||||
input: InputFeed,
|
||||
host: HostContext,
|
||||
}
|
||||
|
||||
struct Env {
|
||||
@@ -59,6 +61,7 @@ impl Interpreter {
|
||||
captured_stdout: String::new(),
|
||||
current_span: Span::new(1, 1),
|
||||
input: InputFeed::new(false, Vec::new()),
|
||||
host: HostContext::for_run(path, Default::default(), Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +73,7 @@ impl Interpreter {
|
||||
captured_stdout: String::new(),
|
||||
current_span: Span::new(1, 1),
|
||||
input: InputFeed::new(true, Vec::new()),
|
||||
host: HostContext::for_capture(path, Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +82,11 @@ impl Interpreter {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_host(mut self, host: HostContext) -> Self {
|
||||
self.host = host;
|
||||
self
|
||||
}
|
||||
|
||||
fn err(&self, message: impl Into<String>) -> anyhow::Error {
|
||||
bail_at(self.path.as_deref(), self.current_span, message)
|
||||
}
|
||||
@@ -517,6 +526,21 @@ impl Interpreter {
|
||||
.ok_or_else(|| self.err("at requires index"))?;
|
||||
return builtin_at(value, index).map_err(|m| self.err(m));
|
||||
}
|
||||
other if HostFn::from_name(other).is_some() => {
|
||||
let hf = HostFn::from_name(other).unwrap();
|
||||
let mut params: Vec<String> =
|
||||
hf.required_params().iter().map(|s| (*s).to_string()).collect();
|
||||
for p in hf.optional_params() {
|
||||
params.push((*p).to_string());
|
||||
}
|
||||
let bound = bind_args(¶ms, &ev_args, true).map_err(|m| self.err(m))?;
|
||||
for req in hf.required_params() {
|
||||
if !bound.contains_key(*req) {
|
||||
return Err(self.err(format!("{} requires `{req}`", hf.name())));
|
||||
}
|
||||
}
|
||||
return call_host(&self.host, hf, &bound).map_err(|m| self.err(m));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user