Remove RuntimeSpanError and just incorporate it into RuntimeError; add Span information to compiled instructions
* RuntimeSpanError was an extraneous solution to adding spans to the errors; so instead this behavior has been delegated to the RuntimeError itself. * Usage of Inst has mostly been replaced with SpInst so if an error is encountered, we can spit out where it happened in the source code (hopefully with a stack trace). Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
use crate::syn::ast::SpStmt;
|
||||
use crate::vm::{error::Result, machine::Machine};
|
||||
use crate::{scope::Scope, syn::span::Span, vm::inst::Inst};
|
||||
use crate::{scope::Scope, syn::span::Span, vm::inst::SpInst};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::fmt::{self, Debug, Display};
|
||||
@@ -33,7 +33,7 @@ impl Quote {
|
||||
/// A table of compiled quotes, their expression trees, and their spans.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct QuoteTable {
|
||||
table: Vec<(Span, Scope, Vec<SpStmt>, Rc<Vec<Inst>>)>,
|
||||
table: Vec<(Span, Scope, Vec<SpStmt>, Rc<Vec<SpInst>>)>,
|
||||
}
|
||||
|
||||
impl QuoteTable {
|
||||
@@ -46,14 +46,14 @@ impl QuoteTable {
|
||||
span: Span,
|
||||
scope: Scope,
|
||||
quote: Vec<SpStmt>,
|
||||
compiled: Rc<Vec<Inst>>,
|
||||
compiled: Rc<Vec<SpInst>>,
|
||||
) -> Quote {
|
||||
let next = Quote(self.table.len());
|
||||
self.table.push((span, scope, quote, compiled));
|
||||
next
|
||||
}
|
||||
|
||||
pub fn get(&self, quote: Quote) -> &(Span, Scope, Vec<SpStmt>, Rc<Vec<Inst>>) {
|
||||
pub fn get(&self, quote: Quote) -> &(Span, Scope, Vec<SpStmt>, Rc<Vec<SpInst>>) {
|
||||
&self.table[quote.0]
|
||||
}
|
||||
}
|
||||
@@ -136,15 +136,21 @@ pub enum BuiltinExit {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BuiltinFn(Rc<BuiltinFnPtr>);
|
||||
pub struct BuiltinFn {
|
||||
name: Rc<String>,
|
||||
fun: Rc<BuiltinFnPtr>,
|
||||
}
|
||||
|
||||
impl BuiltinFn {
|
||||
pub fn new(fun: Rc<BuiltinFnPtr>) -> Self {
|
||||
BuiltinFn(fun)
|
||||
pub fn new(name: String, fun: Rc<BuiltinFnPtr>) -> Self {
|
||||
BuiltinFn {
|
||||
name: Rc::new(name),
|
||||
fun,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn call(&self, machine: &mut Machine, reentry: usize) -> Result<BuiltinExit> {
|
||||
(self.0)(machine, reentry)
|
||||
(self.fun)(machine, reentry)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +162,7 @@ impl Debug for BuiltinFn {
|
||||
write!(
|
||||
fmt,
|
||||
"builtin function at {:#x}",
|
||||
(&self.0 as *const _ as usize)
|
||||
(&self.fun as *const _ as usize)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user