Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom structs #24

Open
brandonLi8 opened this issue Jan 25, 2023 · 0 comments
Open

Custom structs #24

brandonLi8 opened this issue Jan 25, 2023 · 0 comments

Comments

@brandonLi8
Copy link
Owner

Implement custom structs.

Similar to functions, we have a set of structs that the user defined.

struct A {
   b: int,
   c: bool
}

Type checking is fine, just check for existence inside this set. The set value contains information about the fields, and the type of the fields. For now null pointer is fine.

Then for evaluating: for example let h = a.b. We first evaluate a and put that in rax as a pointer (should be in symbol table at this point). That is evaluating the the id of the . infix operator.

Two ways of thinking about it.
Type check happens at compiler:

  1. a evaluation returns the instructions and the type A
  2. Then at the dot operator call, we have the type and we reference the types set to get the offset and type of b, and evaluate a load and whatever and return the type of b

Type check is a separate pass that already happens:
We need every IR expression (or maybe just ids?) to have a type in the struct that is passed in.

  1. a evaluation returns the instructions
  2. dot operator knows the type of 'a' by looking at struct, then can get the offset
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

No branches or pull requests

1 participant