From 264fc2ae58f186bf4cc9020776d0399891058f53 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Tue, 26 Oct 2021 15:30:42 -0700 Subject: [PATCH] Start work on named struct --- schala-lang/language/src/reduced_ir/mod.rs | 23 ++++++++++++++++++- schala-lang/language/src/reduced_ir/types.rs | 4 ++++ .../language/src/tree_walk_eval/mod.rs | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/schala-lang/language/src/reduced_ir/mod.rs b/schala-lang/language/src/reduced_ir/mod.rs index 2e607d7..cc50ca2 100644 --- a/schala-lang/language/src/reduced_ir/mod.rs +++ b/schala-lang/language/src/reduced_ir/mod.rs @@ -136,7 +136,28 @@ impl<'a> Reducer<'a> { body: self.function_internal_block(body), }) }, - NamedStruct { .. } => Expression::ReductionError("NamedStruct not implemented".to_string()), //self.reduce_named_struct(name, fields), + NamedStruct { name, fields } => { + let symbol = self.symbol_table.lookup_symbol(&name.id).unwrap(); + let constructor = match symbol.spec() { + SymbolSpec::RecordConstructor { index, members: _, type_id } => Expression::Callable(Callable::RecordConstructor { + type_id, + tag: index as u32, + }), + e => return Expression::ReductionError(format!("Bad symbol for NamedStruct: {:?}", e)), + }; + + //TODO need to order the fields correctly, which needs symbol table information + // Until this happens, NamedStructs won't work + let mut ordered_args = vec![]; + for (_name, _type_id) in fields { + unimplemented!() + } + + Expression::Call { + f: Box::new(constructor), + args: ordered_args, + } + }, Index { .. } => Expression::ReductionError("Index expr not implemented".to_string()), WhileExpression { .. } => Expression::ReductionError("While expr not implemented".to_string()), ForExpression { .. } => Expression::ReductionError("For expr not implemented".to_string()), diff --git a/schala-lang/language/src/reduced_ir/types.rs b/schala-lang/language/src/reduced_ir/types.rs index 6999056..2a85521 100644 --- a/schala-lang/language/src/reduced_ir/types.rs +++ b/schala-lang/language/src/reduced_ir/types.rs @@ -98,6 +98,10 @@ pub enum Callable { arity: u32, tag: u32 }, + RecordConstructor { + type_id: TypeId, + tag: u32, + }, } #[derive(Debug, Clone)] diff --git a/schala-lang/language/src/tree_walk_eval/mod.rs b/schala-lang/language/src/tree_walk_eval/mod.rs index a5c5301..42cdebe 100644 --- a/schala-lang/language/src/tree_walk_eval/mod.rs +++ b/schala-lang/language/src/tree_walk_eval/mod.rs @@ -358,6 +358,9 @@ impl<'a> State<'a> { items: evaluated_args }) } + Callable::RecordConstructor { type_id: _, tag: _ } => { + unimplemented!() + } } }