mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-15 18:05:03 +01:00
more work
This commit is contained in:
parent
c6765d7da6
commit
ebbc675ffd
2 changed files with 26 additions and 6 deletions
|
|
@ -187,12 +187,16 @@ impl Compiler {
|
||||||
|
|
||||||
fn lookup_local(&self, name: &Ident) -> CResult<usize> {
|
fn lookup_local(&self, name: &Ident) -> CResult<usize> {
|
||||||
for locals in self.locals.iter().rev() {
|
for locals in self.locals.iter().rev() {
|
||||||
|
dbg!("searching");
|
||||||
if let Some(&position) = locals.get(name) {
|
if let Some(&position) = locals.get(name) {
|
||||||
return Ok(position);
|
return Ok(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(CompileError)
|
Err(CompileError::new(
|
||||||
|
name.span,
|
||||||
|
format!("variable {} not found", name.sym),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_stack_top(&self) -> usize {
|
fn current_stack_top(&self) -> usize {
|
||||||
|
|
@ -221,18 +225,32 @@ enum StackChange {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct CompileError;
|
pub struct CompileError {
|
||||||
|
span: Span,
|
||||||
|
message: String,
|
||||||
|
note: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CompileError {
|
||||||
|
fn new(span: Span, message: String) -> Self {
|
||||||
|
Self {
|
||||||
|
span,
|
||||||
|
message,
|
||||||
|
note: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl CompilerError for CompileError {
|
impl CompilerError for CompileError {
|
||||||
fn span(&self) -> Span {
|
fn span(&self) -> Span {
|
||||||
todo!()
|
self.span
|
||||||
}
|
}
|
||||||
|
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
todo!()
|
self.message.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn note(&self) -> Option<String> {
|
fn note(&self) -> Option<String> {
|
||||||
todo!()
|
self.note.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
test.sl
4
test.sl
|
|
@ -1 +1,3 @@
|
||||||
let x = 2 * 3;
|
let x = 2 * 3;
|
||||||
|
|
||||||
|
let tz = x * 5;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue