conlang: Remove "Identifier" node
It never carried any extra information, and got in the way everywhere it was used.
This commit is contained in:
@@ -110,7 +110,7 @@ impl Interpret for Stmt {
|
||||
}
|
||||
impl Interpret for Let {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Let { mutable: _, name: Identifier(name), ty: _, init } = self;
|
||||
let Let { mutable: _, name, ty: _, init } = self;
|
||||
let init = init.as_ref().map(|i| i.interpret(env)).transpose()?;
|
||||
env.insert(*name, init);
|
||||
Ok(ConValue::Empty)
|
||||
@@ -162,7 +162,7 @@ fn evaluate_place_expr<'e>(
|
||||
match parts.last().expect("parts should not be empty") {
|
||||
PathPart::SuperKw => Err(Error::NotAssignable),
|
||||
PathPart::SelfKw => todo!("Assignment to `self`"),
|
||||
PathPart::Ident(Identifier(s)) => env.get_mut(*s).map(|v| (v, *s)),
|
||||
PathPart::Ident(s) => env.get_mut(*s).map(|v| (v, *s)),
|
||||
}
|
||||
}
|
||||
ExprKind::Index(_) => todo!("Assignment to an index operation"),
|
||||
@@ -340,7 +340,7 @@ impl Interpret for Member {
|
||||
for arg in &args.exprs {
|
||||
values.push(arg.interpret(env)?);
|
||||
}
|
||||
env.call(name.0, &values)
|
||||
env.call(*name, &values)
|
||||
}
|
||||
_ => Err(Error::TypeError)?,
|
||||
}
|
||||
@@ -368,7 +368,7 @@ impl Interpret for Path {
|
||||
if parts.len() == 1 {
|
||||
match parts.last().expect("parts should not be empty") {
|
||||
PathPart::SuperKw | PathPart::SelfKw => todo!("Path navigation"),
|
||||
PathPart::Ident(Identifier(name)) => env.get(*name),
|
||||
PathPart::Ident(name) => env.get(*name),
|
||||
}
|
||||
} else {
|
||||
todo!("Path navigation!")
|
||||
@@ -413,7 +413,7 @@ impl Interpret for AddrOf {
|
||||
match expr.as_ref() {
|
||||
ExprKind::Index(_) => todo!("AddrOf array index"),
|
||||
// ExprKind::Path(Path { absolute: false, parts }) => match parts.as_slice() {
|
||||
// [PathPart::Ident(Identifier(id))] => env.get_ref(id),
|
||||
// [PathPart::Ident(id)] => env.get_ref(id),
|
||||
// _ => todo!("Path traversal in addrof"),
|
||||
// },
|
||||
ExprKind::Path(_) => todo!("Path traversal in addrof"),
|
||||
@@ -492,7 +492,7 @@ impl Interpret for If {
|
||||
}
|
||||
impl Interpret for For {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Self { bind: Identifier(name), cond, pass, fail } = self;
|
||||
let Self { bind: name, cond, pass, fail } = self;
|
||||
// TODO: A better iterator model
|
||||
let mut bounds = match cond.interpret(env)? {
|
||||
ConValue::RangeExc(a, b) => a..=b,
|
||||
|
||||
@@ -311,7 +311,7 @@ pub mod function {
|
||||
//! Represents a block of code which lives inside the Interpreter
|
||||
|
||||
use super::{Callable, ConValue, Environment, Error, IResult, Interpret};
|
||||
use cl_ast::{Function as FnDecl, Identifier, Param, Sym};
|
||||
use cl_ast::{Function as FnDecl, Param, Sym};
|
||||
use std::rc::Rc;
|
||||
/// Represents a block of code which persists inside the Interpreter
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -333,11 +333,11 @@ pub mod function {
|
||||
|
||||
impl Callable for Function {
|
||||
fn name(&self) -> Sym {
|
||||
let FnDecl { name: Identifier(name), .. } = *self.decl;
|
||||
let FnDecl { name, .. } = *self.decl;
|
||||
name
|
||||
}
|
||||
fn call(&self, env: &mut Environment, args: &[ConValue]) -> IResult<ConValue> {
|
||||
let FnDecl { name: Identifier(name), bind, body, sign: _ } = &*self.decl;
|
||||
let FnDecl { name, bind, body, sign: _ } = &*self.decl;
|
||||
// Check arg mapping
|
||||
if args.len() != bind.len() {
|
||||
return Err(Error::ArgNumber { want: bind.len(), got: args.len() });
|
||||
@@ -347,7 +347,7 @@ pub mod function {
|
||||
};
|
||||
// TODO: completely refactor data storage
|
||||
let mut frame = env.frame("fn args");
|
||||
for (Param { mutability: _, name: Identifier(name) }, value) in bind.iter().zip(args) {
|
||||
for (Param { mutability: _, name }, value) in bind.iter().zip(args) {
|
||||
frame.insert(*name, Some(value.clone()));
|
||||
}
|
||||
match body.interpret(&mut frame) {
|
||||
@@ -370,7 +370,7 @@ pub mod env {
|
||||
temp_type_impl::ConValue,
|
||||
BuiltIn, Callable, Interpret,
|
||||
};
|
||||
use cl_ast::{Function as FnDecl, Identifier, Sym};
|
||||
use cl_ast::{Function as FnDecl, Sym};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::Display,
|
||||
@@ -475,7 +475,7 @@ pub mod env {
|
||||
}
|
||||
/// A convenience function for registering a [FnDecl] as a [Function]
|
||||
pub fn insert_fn(&mut self, decl: &FnDecl) {
|
||||
let FnDecl { name: Identifier(name), .. } = decl;
|
||||
let FnDecl { name, .. } = decl;
|
||||
let (name, function) = (name, Some(Function::new(decl).into()));
|
||||
if let Some((frame, _)) = self.frames.last_mut() {
|
||||
frame.insert(*name, function);
|
||||
|
||||
Reference in New Issue
Block a user