diff --git a/schala-lang/language/src/visitor.rs b/schala-lang/language/src/visitor.rs index 73453ed..bd077d8 100644 --- a/schala-lang/language/src/visitor.rs +++ b/schala-lang/language/src/visitor.rs @@ -1,33 +1,41 @@ use std::rc::Rc; use crate::builtin::{BinOp, PrefixOp}; -use crate::ast::{Expression, ExpressionKind}; +use crate::ast::{Expression, ExpressionKind, InvocationArgument, Meta}; pub trait ExpressionKindVisitor { fn nat_literal(&mut self, n: &u64) -> T; + fn float_literal(&mut self, f: &f64) -> T; fn string_literal(&mut self, s: Rc) -> T; + fn bool_literal(&mut self, b: &bool) -> T; fn binexp(&mut self, op: &BinOp, lhs: &Expression, rhs: &Expression) -> T; + fn prefix_exp(&mut self, op: &PrefixOp, arg: &Expression) -> T; + fn value(&mut self, value_name: Rc) -> T; + fn call_expression(&mut self, f: &Expression, arguments: &Vec>) -> T; } pub fn dispatch(input: &ExpressionKind, visitor: &mut dyn ExpressionKindVisitor) -> T { use ExpressionKind::*; match input { NatLiteral(n) => visitor.nat_literal(n), + FloatLiteral(f) => visitor.float_literal(f), StringLiteral(s) => visitor.string_literal(s.clone()), + BoolLiteral(b) => visitor.bool_literal(b), BinExp(op, box lhs, box rhs) => visitor.binexp(op, lhs.node(), rhs.node()), + PrefixExp(op, box arg) => visitor.prefix_exp(op, arg.node()), + Value(val_name) => visitor.value(val_name.clone()), + Call { box f, arguments } => visitor.call_expression(f.node(), arguments), _ => panic!() } } +/* struct NumberSummer; impl ExpressionKindVisitor for NumberSummer { - fn nat_literal(&mut self, n: &u64) -> u64 { - n.clone() - } - fn string_literal(&mut self, s: Rc) -> u64 { - 0 - } + fn nat_literal(&mut self, n: &u64) -> u64 { n.clone() } + fn float_literal(&mut self, f: &f64) -> u64 + fn string_literal(&mut self, s: Rc) -> u64 { 0 } fn binexp(&mut self, op: &BinOp, lhs: &Expression, rhs: &Expression) -> u64 { let lhs = dispatch(&lhs.kind, self); let rhs = dispatch(&rhs.kind, self); @@ -46,3 +54,4 @@ fn yolo_swagg() { let result = dispatch(&x, &mut t); assert_eq!(result, 4); } +*/