From abda8d00117072f7c03f57eaeca9cf44427078dc Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Mon, 11 May 2026 08:34:22 +0300 Subject: Replace generic list AST with typed expression tree Each form (fn, let, for, set, do, call) now has its own variant with named fields instead of being a plain list. --- compiler/src/ast/models.rs | 48 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'compiler/src/ast/models.rs') diff --git a/compiler/src/ast/models.rs b/compiler/src/ast/models.rs index 2a8c5ae..64fec19 100644 --- a/compiler/src/ast/models.rs +++ b/compiler/src/ast/models.rs @@ -2,22 +2,56 @@ use std::rc::Rc; use crate::span::Spanned; -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct LetVar { + pub name: Spanned>, + pub expr: Spanned, +} + +#[derive(Clone, Debug, PartialEq, Eq)] pub enum Atom { - Integer(i64), - String(Rc), - Symbol(Rc), + Int(i64), + Str(Rc), + Sym(Rc), Bool(bool), Nil, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum Expr { + Fn { + name: Spanned>, + args: Vec>>, + body: Vec>, + }, + Const { + vars: Vec>, + }, + Let { + vars: Vec>, + body: Vec>, + }, + For { + loop_var: Spanned>, + from: Spanned>, + to: Spanned>, + body: Vec>, + }, + Set { + target_var: Spanned>, + expr: Spanned>, + }, + Do { + body: Vec>, + }, + Call { + fn_name: Spanned>, + args: Vec>, + }, Atom(Atom), - List(Vec>), } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Ast(Vec>); impl Ast { -- cgit v1.3