Skip to content

Add rust-style tuples? #48

@Gankra

Description

@Gankra

Now that we have more emphasis on testing rust <-> rust, we should support more builtin rust concepts. Tuples are a relatively easy one to start with.

If you want to do this, then I suggest adding a new case to Tydent in the parser, and then chasing the compiler errors (i like using exhaustive matches to make this kind of change accessible):

/// A type "name" (which may be structural like `[u32; 4]`).
///
/// It's like an ident but, for types -- a tydent!
#[derive(Debug, Clone)]
pub enum Tydent {
/// A named type (the type checker will resolve this)
Name(Ident),
/// A fixed length array
Array(Box<Spanned<Tydent>>, u64),
/// A by-reference type
Ref(Box<Spanned<Tydent>>),
/// The empty tuple -- `()`
Empty,
}

Tuples are essentially analogous to arrays, except "get the element type" is done inside the loop instead of outside the loop. So I think everywhere you need to change you'll find some code for handling arrays you can copy and tweak.

You would roughly need to:

  • Update the parser to make it a Tydent, parse it
  • Update the type system to make it a Ty, type it
  • Bonus Chore: update the meme kdlscript interpreter to handle it?
  • Update the ValueTree system to spider its fields and generate values for it
  • Update the rust backend to initialize/read it
  • Update the c backend to bail if it sees it

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions