Stack traces

pub enum ArgValue {
  NullVal,
  BoolVal { b: boolean },
  IntVal { pub n: integer },
  LongVal { pub n: integer },
  FloatVal { f: float },
  SingleVal { f: single },
  CharVal { c: character },
  TextVal { pub t: text },
  RefVal { store: integer, rec: integer, pos: integer },
  FnVal { d_nr: integer },
  OtherVal { description: text },
}

Typed union of inspectable argument/variable values. Each variant wraps one primitive type so that match expressions can recover the concrete value from a StackFrame's argument list.

pub struct ArgInfo {
  pub name: text,
  pub type_name: text,
  pub value: ArgValue,
}

One function argument in a stack frame.

pub struct VarInfo {
  pub name: text,
  type_name: text,
  pub value: ArgValue,
}

One local variable or parameter in a stack frame (see stack_trace).

pub struct StackFrame {
  pub function: text,
  file: text,
  pub line: integer,
  pub arguments: vector<ArgInfo>,
  pub variables: vector<VarInfo>,
}

One call frame in the stack trace.

pub fn stack_trace() -> vector<StackFrame>

Return the current call stack as a vector of frames, outermost first. Each frame's variables holds its parameters and live locals, arguments the parameters alone (typed via ArgValue). Use this to inspect not only the current function's variables but also the variables of any function further up the call stack. Under --native both lists are empty: a compiled frame has no reader for its locals (STACKTRACE.md § Known Limitations, ST-6).

loft fn debug_dump() { for frame in stack_trace() { println("{frame.function}:{frame.line}"); for v in frame.variables { println(" {v.name} = {v.value}"); } } }