feat: build a resizable native developer workspace with console and network inspection
Verify Tessera GUI / verify (push) Failing after 7m12s
Verify Tessera GUI / verify (push) Failing after 7m12s
This commit is contained in:
@@ -101,6 +101,44 @@ pub fn compile(source: &str, namespace: &str, submission: u64) -> Result<RenderD
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluate exactly one expression in a disposable VM; never touch the published page.
|
||||
pub fn evaluate(source: &str) -> Result<String> {
|
||||
if source.len() > MAX_SOURCE_BYTES {
|
||||
bail!("expression exceeds the 1 MiB limit");
|
||||
}
|
||||
let source = EndorReader::from_text("console expression", source);
|
||||
let ast = frontend::parse_source_ast(&source, frontend::ParseMode::Expression)?;
|
||||
AstBudget::default().visit_ast_root(&ast)?;
|
||||
let compiled = compiler::compile_ast(&ast, &source, &compiler::CompileOptions::default())
|
||||
.map_err(|error| source.annotate(error))?;
|
||||
let mut candidate = Candidate::new()?;
|
||||
let result = (|| {
|
||||
let globals = candidate.vm.new_dict()?;
|
||||
candidate.globals = Some(globals);
|
||||
candidate.roots.push(globals);
|
||||
let code = compiled.load(&mut candidate.vm)?;
|
||||
candidate.roots.push(code);
|
||||
let value = candidate
|
||||
.vm
|
||||
.execute_with_limits(code, globals, LIMITS)
|
||||
.map_err(|error| runtime_error(&candidate.vm, error))?;
|
||||
let rendered = match &value {
|
||||
Value::Nil => "nil".to_owned(),
|
||||
Value::Bool(v) => v.to_string(),
|
||||
Value::Text(v) => format!("{v:?}"),
|
||||
Value::Number(v) => v.to_string(),
|
||||
Value::Object(v) => candidate.vm.repr(*v)?,
|
||||
};
|
||||
candidate.vm.release_value(value)?;
|
||||
Ok(rendered)
|
||||
})();
|
||||
let cleanup = candidate.close();
|
||||
match (result, cleanup) {
|
||||
(Ok(value), Ok(())) => Ok(value),
|
||||
(Err(e), _) | (_, Err(e)) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn compile_plan(source: &SourceUnit, plan: &SourcePlan) -> Result<Vec<compiler::CompiledCode>> {
|
||||
let mut globals = BTreeSet::from(["ui".to_owned()]);
|
||||
// Match Aster module behavior for function forward references. Bindings are
|
||||
|
||||
Reference in New Issue
Block a user