mirror of
https://github.com/edg-l/edlang.git
synced 2024-11-22 07:58:24 +00:00
nice
This commit is contained in:
parent
962233f269
commit
ccc70b9122
|
@ -194,7 +194,7 @@ pub struct StructInitField {
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct StructInitExpr {
|
pub struct StructInitExpr {
|
||||||
pub name: Ident,
|
pub name: Type,
|
||||||
pub fields: BTreeMap<Ident, StructInitField>,
|
pub fields: BTreeMap<Ident, StructInitField>,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ pub enum TypeKind {
|
||||||
FnDef(DefId, Vec<TypeInfo>), // The vec are generic types, not arg types
|
FnDef(DefId, Vec<TypeInfo>), // The vec are generic types, not arg types
|
||||||
Ptr(Box<TypeInfo>),
|
Ptr(Box<TypeInfo>),
|
||||||
Ref(bool, Box<TypeInfo>),
|
Ref(bool, Box<TypeInfo>),
|
||||||
Struct(DefId),
|
Struct(DefId), // todo, add generics
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TypeKind {
|
impl TypeKind {
|
||||||
|
|
|
@ -496,7 +496,7 @@ fn find_expr_type(builder: &mut BodyBuilder, info: &ast::Expression) -> Option<T
|
||||||
.get_module_body()
|
.get_module_body()
|
||||||
.symbols
|
.symbols
|
||||||
.structs
|
.structs
|
||||||
.get(&info.name.name)
|
.get(&info.name.name.name)
|
||||||
.expect("struct not found");
|
.expect("struct not found");
|
||||||
ir::TypeKind::Struct(id)
|
ir::TypeKind::Struct(id)
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ fn lower_expr(
|
||||||
.get_module_body()
|
.get_module_body()
|
||||||
.symbols
|
.symbols
|
||||||
.structs
|
.structs
|
||||||
.get(&info.name.name)
|
.get(&info.name.name.name)
|
||||||
.expect("struct not found");
|
.expect("struct not found");
|
||||||
let struct_body = builder.ctx.body.structs.get(&id).unwrap().clone();
|
let struct_body = builder.ctx.body.structs.get(&id).unwrap().clone();
|
||||||
let ty = TypeKind::Struct(id);
|
let ty = TypeKind::Struct(id);
|
||||||
|
|
|
@ -155,6 +155,22 @@ pub(crate) Type: ast::Type = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// For things like A::<T> { a: value }
|
||||||
|
pub(crate) IdentWithOptionalType: ast::Type = {
|
||||||
|
<lo:@L> <name:Ident> <hi:@R> => ast::Type {
|
||||||
|
name,
|
||||||
|
generics: vec![],
|
||||||
|
is_ref: None,
|
||||||
|
span: ast::Span::new(lo, hi),
|
||||||
|
},
|
||||||
|
<lo:@L> <name:Ident> "::" "<" <generics:Comma<Type>> ">" <hi:@R> => ast::Type {
|
||||||
|
name,
|
||||||
|
generics,
|
||||||
|
is_ref: None,
|
||||||
|
span: ast::Span::new(lo, hi),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) PathExpr: ast::PathExpr = {
|
pub(crate) PathExpr: ast::PathExpr = {
|
||||||
<lo:@L> <first:Ident> <extra:PathSegments?> <hi:@R> => ast::PathExpr {
|
<lo:@L> <first:Ident> <extra:PathSegments?> <hi:@R> => ast::PathExpr {
|
||||||
first,
|
first,
|
||||||
|
@ -212,7 +228,7 @@ pub(crate) LetStmt: ast::LetStmt = {
|
||||||
value,
|
value,
|
||||||
span: ast::Span::new(lo, hi),
|
span: ast::Span::new(lo, hi),
|
||||||
},
|
},
|
||||||
<lo:@L> "let" <is_mut:"mut"?> <name:Ident> ":" <target_type:Type> "=" <value:StructInitExpr> <hi:@R> => ast::LetStmt {
|
<lo:@L> "let" <is_mut:"mut"?> <name:Ident> ":" <target_type:Type> "=" <value:StructInitExpr> <hi:@R> => ast::LetStmt {
|
||||||
is_mut: is_mut.is_some(),
|
is_mut: is_mut.is_some(),
|
||||||
name,
|
name,
|
||||||
r#type: target_type,
|
r#type: target_type,
|
||||||
|
@ -381,7 +397,7 @@ pub(crate) StructInitField: (ast::Ident, ast::StructInitField) = {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) StructInitExpr: ast::StructInitExpr = {
|
pub(crate) StructInitExpr: ast::StructInitExpr = {
|
||||||
<lo:@L> <name:Ident> "{" <fields:Comma<StructInitField>> "}" <hi:@R> => ast::StructInitExpr {
|
<lo:@L> <name:IdentWithOptionalType> "{" <fields:Comma<StructInitField>> "}" <hi:@R> => ast::StructInitExpr {
|
||||||
name,
|
name,
|
||||||
fields: fields.into_iter().collect(),
|
fields: fields.into_iter().collect(),
|
||||||
span: ast::Span::new(lo, hi),
|
span: ast::Span::new(lo, hi),
|
||||||
|
|
Loading…
Reference in a new issue