Add math stdlib with formulas/plots and polish the docs view.
Ship Num/Formula runtime, bilingual math libs, SVG plots with axes/grid, and view UX for collapsible folders plus centered plots. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a53ebb65ee
commit
dcd0cdb8f7
40 files changed
+3553
-276
No files matched your search
@@ -206,7 +206,7 @@ impl<'a> FnCompiler<'a> {
|
||||
|
||||
fn compile_stmt(&mut self, stmt: &Stmt) -> Result<()> {
|
||||
match stmt {
|
||||
Stmt::Assign { name, value, span } => {
|
||||
Stmt::Assign { name, value, span, .. } => {
|
||||
self.stmt_span = *span;
|
||||
self.compile_expr(value)?;
|
||||
let slot = self.local_slot(name);
|
||||
@@ -637,6 +637,10 @@ impl<'a> FnCompiler<'a> {
|
||||
}
|
||||
self.emit(Op::BuildList(items.len() as u16));
|
||||
}
|
||||
Expr::Formula(e) => {
|
||||
let i = self.add_const(Value::Formula(e.clone()));
|
||||
self.emit(Op::Constant(i));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+13
-2
@@ -69,6 +69,10 @@ impl Vm {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn take_plots(&mut self) -> Vec<crate::host::PlotArtifact> {
|
||||
std::mem::take(&mut self.host.plots)
|
||||
}
|
||||
|
||||
fn emit_line(&mut self, text: &str) {
|
||||
if self.capture {
|
||||
self.captured_stdout.push_str(text);
|
||||
@@ -312,7 +316,7 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
let result =
|
||||
call_host(&self.host, hf, &bound).map_err(|m| self.err_at(span, m))?;
|
||||
call_host(&mut self.host, hf, &bound).map_err(|m| self.err_at(span, m))?;
|
||||
stack.push(result);
|
||||
}
|
||||
Op::Call(fid, argc) => {
|
||||
@@ -380,8 +384,15 @@ fn cmp(stack: &mut Vec<Value>, pred: impl Fn(std::cmp::Ordering) -> bool) -> Res
|
||||
let a = pop(stack)?;
|
||||
let ord = match (&a, &b) {
|
||||
(Value::Int(x), Value::Int(y)) => x.cmp(y),
|
||||
(Value::Num(x), Value::Num(y)) => x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal),
|
||||
(Value::Int(x), Value::Num(y)) => {
|
||||
(*x as f64).partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal)
|
||||
}
|
||||
(Value::Num(x), Value::Int(y)) => {
|
||||
x.partial_cmp(&(*y as f64)).unwrap_or(std::cmp::Ordering::Equal)
|
||||
}
|
||||
(Value::Text(x), Value::Text(y)) => x.cmp(y),
|
||||
_ => return Err("comparison needs two ints or two texts".into()),
|
||||
_ => return Err("comparison needs two ints/nums or two texts".into()),
|
||||
};
|
||||
stack.push(Value::Bool(pred(ord)));
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user