From 486a634ea1b0ca9c9e0e050f4557297e7db827dd Mon Sep 17 00:00:00 2001 From: Janis Date: Thu, 6 Mar 2025 18:40:17 +0100 Subject: [PATCH] more fixes --- src/ast2/ir.rs | 11 ++++++++--- src/ast2/mod.rs | 44 ++++++++++++++++++++++++++++++++------------ src/ast2/visitor.rs | 2 ++ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/ast2/ir.rs b/src/ast2/ir.rs index 860cf37..6f87d6b 100644 --- a/src/ast2/ir.rs +++ b/src/ast2/ir.rs @@ -1041,7 +1041,7 @@ impl<'a> AstVisitorTrait<&'a mut Ast> for PlacenessSolver { let func = ast.convert_to_value_expr(func); let arguments = self.visit_argument_list(ast, arguments)?; - ast.datas[idx] = Data::two_indices(func, arguments); + ast.datas[idx] = Data::two_indices(func, arguments.into_index()); Ok(PlaceOrValue::Value(idx)) } @@ -1085,7 +1085,8 @@ impl<'a> AstVisitorTrait<&'a mut Ast> for PlacenessSolver { fn visit_any(&mut self, ast: &'a mut Ast, idx: Index) -> Result { let tag = ast.tags[idx]; - match tag { + + let idx = match tag { Tag::Parameter => self.visit_parameter(ast, idx)?, Tag::VarDecl | Tag::MutVarDecl | Tag::VarDeclAssignment | Tag::MutVarDeclAssignment => { self.visit_var_decl_common(ast, idx)? @@ -1142,10 +1143,14 @@ impl<'a> AstVisitorTrait<&'a mut Ast> for PlacenessSolver { Tag::ArrayType => todo!(), Tag::Error => todo!(), Tag::Undefined => todo!(), + Tag::FunctionProto => todo!(), + Tag::FunctionProtoInterned => todo!(), + Tag::StructDeclInterned => todo!(), + Tag::ParameterList => todo!(), }; //_ => Err(())?, - Ok(todo!()) + Ok(idx) } } diff --git a/src/ast2/mod.rs b/src/ast2/mod.rs index 791d987..cc81b49 100644 --- a/src/ast2/mod.rs +++ b/src/ast2/mod.rs @@ -27,6 +27,8 @@ pub enum Tag { File, /// `data` is an intern to a name, and an index into extra of [index: return_type, index: ParameterList] FunctionProto, + /// `data` is an intern to a name, and an intern to the function type + FunctionProtoInterned, /// `data` is an index to a FunctionProto and an index to a Block FunctionDecl, /// `data` is a range from a..b into extra of indices to parameters @@ -57,6 +59,8 @@ pub enum Tag { GlobalDecl, /// `data` is an intern to a name, and an offset into extra of `[flags, type0 ,..., typeN ,name0 ,..., nameN]` StructDecl, + /// `data` is an intern to a name, and an intern to the type of the struct + StructDeclInterned, /// `data` is an index to a type, and an intern to a name FieldDecl, /// `data` is an index to a VarDecl, GlobalDecl or FunctionDecl, and an opaque DeclKind @@ -131,6 +135,7 @@ impl Tag { | Tag::PointerType | Tag::InternedType | Tag::ArrayType + | Tag::StructDeclInterned | Tag::StructDecl => true, _ => false, } @@ -165,6 +170,8 @@ impl Tag { | Tag::SubscriptExpr | Tag::IfExpr | Tag::IfElseExpr + | Tag::PlaceToValueConversion + | Tag::ValueToPlaceConversion | Tag::Block | &Tag::BlockTrailingExpr => true, _ => false, @@ -368,6 +375,7 @@ impl From<(Tag, Data)> for ExpandedData { | Tag::CallExpr | Tag::ArrayType | Tag::FunctionDecl => Self::from_two_indices(data), + Tag::StructDeclInterned | Tag::FunctionProtoInterned => Self::from_two_interns(data), Tag::ReturnExprStmt | Tag::DeclRef | Tag::TypeDeclRef @@ -489,7 +497,7 @@ impl Data { } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -enum PlaceOrValue { +pub enum PlaceOrValue { Value(index::Index), Place(index::Index), } @@ -1415,6 +1423,11 @@ impl Ast { ip.as_mut().get_function_type(return_type, parameters) } + Tag::FunctionProtoInterned | Tag::StructDeclInterned => { + let (_, ty) = data.as_two_interns(); + + ty + } Tag::BlockTrailingExpr => { let (_a, b) = data.as_extra_range(); self.get_type_of_node(ip, cache, Index::from_u32(self.extra[b - 1]).unwrap()) @@ -1491,6 +1504,7 @@ impl Ast { // TODO: find out of the expression is const, volatile for flags // ip.try_get_pointer_type(ty, None).unwrap() + // note: because of value-to-place and place-to-value, // this is actually the same type. ty @@ -1585,6 +1599,9 @@ impl Ast { .map(|&i| Index::from_u32(i).unwrap()) .collect() } + Tag::FunctionProtoInterned => { + vec![] + } Tag::FunctionDecl => { let (a, b) = data.as_two_indices(); vec![a, b] @@ -1684,6 +1701,7 @@ impl Ast { let (a, _) = data.as_index_and_extra_offset(); vec![a] } + Tag::StructDeclInterned => vec![], Tag::StructDecl => { let (_a, offset) = data.as_intern_and_extra_offset(); let flags = StructFlags::unpack(self.extra[offset]); @@ -1731,15 +1749,16 @@ impl Ast { let is_comptime = match tag { Tag::Parameter => false, // TODO: figure out if there are function protos that arent const - // Tag::FunctionProto | Tag::FunctionDecl | Tag::Block | Tag::BlockTrailingExpr => { - // are_children_comptime(self, cache) - // } + Tag::FunctionProto | Tag::FunctionProtoInterned| Tag::FunctionDecl | Tag::Block | Tag::BlockTrailingExpr => { + //are_children_comptime(self, cache) + false + } Tag::Constant => true, Tag::ReturnStmt => true, Tag::ReturnExprStmt => are_children_comptime(self, cache), Tag::MutVarDecl | Tag::MutVarDeclAssignment => false, - // Tag::VarDecl => true, - // Tag::ValueToPlaceConversion => false, + Tag::VarDecl => false, + Tag::ValueToPlaceConversion => false, Tag::PlaceToValueConversion | Tag::VarDeclAssignment => { are_children_comptime(self, cache) } @@ -1748,12 +1767,13 @@ impl Ast { Tag::FieldDecl => true, Tag::DeclRef => self.tags[data.as_index()] == Tag::GlobalDecl, Tag::InternedType | Tag::PointerType | Tag::ArrayType | Tag::TypeDeclRef => true, - // Tag::CallExpr => are_children_comptime(self, cache), - // Tag::FieldAccess => { + Tag::CallExpr => false, // are_children_comptime(self, cache), + Tag::FieldAccess => { // let parent = data.as_index_intern().0; // cache.mark_as_dominated_by(index, parent); - // self.is_node_comptime_evaluable(cache, parent) - // } + // self.is_node_comptime_evaluable(cache, parent) + false + } Tag::ArgumentList => are_children_comptime(self, cache), Tag::Argument => self.is_node_comptime_evaluable(cache, data.as_index()), Tag::NamedArgument => { @@ -1782,14 +1802,14 @@ impl Ast { | Tag::Sub | Tag::Mul | Tag::Div - | Tag::SubscriptExpr // TODO: add array decl expression + | Tag::SubscriptExpr // TODO: add array decl expression | Tag::Rem => are_children_comptime(self, cache), Tag::Assign => { let (left, _) = data.as_two_indices(); cache.mark_as_dominated_by(index, left); are_children_comptime(self, cache) } - // Tag::IfExpr | Tag::IfElseExpr => are_children_comptime(self, cache), + Tag::IfExpr | Tag::IfElseExpr => false, // are_children_comptime(self, cache), Tag::Root | Tag::File | Tag::ParameterList diff --git a/src/ast2/visitor.rs b/src/ast2/visitor.rs index 1f760f0..f3a37b2 100644 --- a/src/ast2/visitor.rs +++ b/src/ast2/visitor.rs @@ -517,6 +517,8 @@ pub trait AstVisitorTrait { Tag::MutVarDeclAssignment => self.visit_mut_var_assign_decl(ast, idx), Tag::GlobalDecl => self.visit_global_decl(ast, idx), Tag::StructDecl => todo!(), + Tag::StructDeclInterned => todo!(), + Tag::FunctionProtoInterned => todo!(), Tag::FieldDecl => todo!(), Tag::DeclRef => self.visit_decl_ref(ast, idx), Tag::DeclRefUnresolved => todo!(),