Skip to content

Instantly share code, notes, and snippets.

@ZeWaka
Created January 3, 2023 00:23
Show Gist options
  • Save ZeWaka/9997fdfa85d1e901f1e017713c5831dc to your computer and use it in GitHub Desktop.
Save ZeWaka/9997fdfa85d1e901f1e017713c5831dc to your computer and use it in GitHub Desktop.
general arch for a shitty java compiler i worked on
1. lexer - braindead
2. parser - generates shitty ast
3. first ast pass
a. store class decls
b. store method decls
c. store instance variable decls
d. ditto for builtins
4. second ast pass
a. link class decls to parent
b. link class decls to children
c. detect cycles
5. third ast pass
a. link variables to their decls
b. link types to their class decls
c. link breaks to their while/switch stmts
d. detect param/variable name conflicts
6. fourth ast pass
a. eval types for each expr
b. ensure exprs, methods, and vars follow type rules
c. check bullshit like method overrides and return types
7. fifth ast pass
a. detect unreachable code
b. basic constant-eval of exprs
8. first code generation pass
a. annotate vars, methods, and params with offsets
b. generate static shit like all the vtables
9. second code generation pass
a. shit out string literals
10. third code generation pass
a. basically all codegen, shit everything out
i. try to constant-eval binary and unary exprs first
ii. also do stuff like dead branch deletion
That's it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment