diff --git a/compiler/cl-ast/src/ast.rs b/compiler/cl-ast/src/ast.rs index 08eaa0c..dea9579 100644 --- a/compiler/cl-ast/src/ast.rs +++ b/compiler/cl-ast/src/ast.rs @@ -183,7 +183,7 @@ pub struct Variant { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum VariantKind { Plain, - CLike(u128), + CLike(Box), Tuple(Ty), Struct(Vec), } diff --git a/compiler/cl-ast/src/ast_impl/convert.rs b/compiler/cl-ast/src/ast_impl/convert.rs index 8f98da2..c4e755e 100644 --- a/compiler/cl-ast/src/ast_impl/convert.rs +++ b/compiler/cl-ast/src/ast_impl/convert.rs @@ -40,7 +40,6 @@ impl_from! { // TODO: Struct members in struct } impl From for VariantKind { - u128 => VariantKind::CLike, Ty => VariantKind::Tuple, // TODO: enum struct variants } diff --git a/compiler/cl-interpret/src/interpret.rs b/compiler/cl-interpret/src/interpret.rs index fdb0795..1320a2f 100644 --- a/compiler/cl-interpret/src/interpret.rs +++ b/compiler/cl-interpret/src/interpret.rs @@ -159,7 +159,10 @@ impl Interpret for Enum { for (idx, Variant { name, kind }) in variants.iter().enumerate() { match kind { VariantKind::Plain => env.insert(*name, Some(ConValue::Int(idx as _))), - VariantKind::CLike(idx) => env.insert(*name, Some(ConValue::Int(*idx as _))), + VariantKind::CLike(idx) => { + let idx = idx.interpret(env)?; + env.insert(*name, Some(idx)) + } VariantKind::Tuple(ty) => eprintln!("TODO: Enum-tuple variants: {ty}"), VariantKind::Struct(_) => eprintln!("TODO: Enum-struct members: {kind}"), } diff --git a/compiler/cl-parser/src/parser.rs b/compiler/cl-parser/src/parser.rs index 58d6dc6..abf5292 100644 --- a/compiler/cl-parser/src/parser.rs +++ b/compiler/cl-parser/src/parser.rs @@ -603,13 +603,8 @@ impl Parse<'_> for VariantKind { const P: Parsing = Parsing::VariantKind; Ok(match p.peek_kind(P)? { TokenKind::Eq => { - p.match_type(TokenKind::Eq, P)?; - let tok = p.match_type(TokenKind::Literal, P)?; - - VariantKind::CLike(match tok.data() { - TokenData::Integer(i) => *i, - _ => panic!("Expected token data for {tok:?} while parsing {P}"), - }) + p.consume_peeked(); + VariantKind::CLike(Box::new(p.parse()?)) } TokenKind::LCurly => VariantKind::Struct(delim( sep(StructMember::parse, TokenKind::Comma, TokenKind::RCurly, P),