cl-interpret: Interpret items in a file in a particular order
1) mod 2) use 3) enum, struct, type 4) fn 5) impl 6) const | static This is a stopgap until names are statically resolved
This commit is contained in:
parent
772286eefa
commit
0fd9c002fc
@ -8,7 +8,7 @@
|
|||||||
use std::{borrow::Borrow, rc::Rc};
|
use std::{borrow::Borrow, rc::Rc};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use cl_ast::*;
|
use cl_ast::{ast_visitor::Visit, *};
|
||||||
use cl_structures::intern::interned::Interned;
|
use cl_structures::intern::interned::Interned;
|
||||||
/// A work-in-progress tree walk interpreter for Conlang
|
/// A work-in-progress tree walk interpreter for Conlang
|
||||||
pub trait Interpret {
|
pub trait Interpret {
|
||||||
@ -20,9 +20,29 @@ pub trait Interpret {
|
|||||||
|
|
||||||
impl Interpret for File {
|
impl Interpret for File {
|
||||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||||
for item in &self.items {
|
/// Sorts items
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
struct ItemSorter<'ast>(pub [Vec<&'ast Item>; 6]);
|
||||||
|
impl<'ast> Visit<'ast> for ItemSorter<'ast> {
|
||||||
|
fn visit_item(&mut self, i: &'ast Item) {
|
||||||
|
self.0[match &i.kind {
|
||||||
|
ItemKind::Module(_) => 0,
|
||||||
|
ItemKind::Use(_) => 1,
|
||||||
|
ItemKind::Enum(_) | ItemKind::Struct(_) | ItemKind::Alias(_) => 2,
|
||||||
|
ItemKind::Function(_) => 3,
|
||||||
|
ItemKind::Impl(_) => 4,
|
||||||
|
ItemKind::Const(_) | ItemKind::Static(_) => 5,
|
||||||
|
}]
|
||||||
|
.push(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut items = ItemSorter::default();
|
||||||
|
items.visit_file(self);
|
||||||
|
for item in items.0.into_iter().flatten() {
|
||||||
item.interpret(env)?;
|
item.interpret(env)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ConValue::Empty)
|
Ok(ConValue::Empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user