Skip to content

Conversation

@mohitk05
Copy link
Contributor

Tuples & Complex Types

Tuples can be defined using type <name> = { ... }, similar to structs. In Gom, there is no explicit struct keyword but the syntax differentiates them from tuples. When defined with keys and values, it's a struct. When only with type fields, it's a tuple. Tuple literals can be defined inline to create a tuple immediately.

type HttpResponse = { int, bool };

fn process_http(url: str): HttpResponse {
  if(url == "http://www.example.com") {
    return { 200, true };
  }
  
  return { 401, false };
}

Codegen for structs and tuples using sret

LLVM IR for struct and tuple code uses sret instruction.
https://llvm.org/docs/LangRef.html#id1969

@mohitk05 mohitk05 merged commit 10d9f8d into main May 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants