conlang: Remove "Identifier" node

It never carried any extra information, and got in the way everywhere it was used.
This commit is contained in:
2024-05-19 14:41:31 -05:00
parent f330a7eaa5
commit 0cc0cb5cfb
15 changed files with 115 additions and 139 deletions

View File

@@ -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);