https://github.com/xrxr/alang
A toy compiler for a statically typed language
https://github.com/xrxr/alang
compiler programming-language statically-typed
Last synced: 9 months ago
JSON representation
A toy compiler for a statically typed language
- Host: GitHub
- URL: https://github.com/xrxr/alang
- Owner: XrXr
- License: mit
- Created: 2016-08-12T02:35:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-21T00:15:17.000Z (about 7 years ago)
- Last Synced: 2024-12-14T06:31:47.665Z (about 1 year ago)
- Topics: compiler, programming-language, statically-typed
- Language: Go
- Homepage:
- Size: 345 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## `alang`
`alang` is a toy compiler written for a statically typed langugage similar to C in terms of features.
`alang` only targets 64-bit X86-64 Linux and generates free standing binaries that don't depend on libc by default.
## What does the lanaguage look like?
[souvenir](https://github.com/XrXr/souvenir) excersises all of alang's features. Please take a look if you are interested.
## Dependencies
- `import "github.com/davecgh/go-spew/spew"` for printf debugging during development
- `nasm` as a runtime dependency for assembling object files
- `ld` for linking
## Notes
- Run `go test -tags integration` to run integration tests
- Run `go generate parsing/*go` to get proper parse tree printing
- Run `go generate ir/*go` to get proper ir printing
Here is what the compiler does to generate a binary:
`parse into ast -> frontend generates ir -> type check/inference happens on ir -> generate nasm asm -> pass asm to nasm and run ld`
- Instructions from ir operate on variables numbered from 0. Variables can be of any size
- The first few variables are procedure arguments
- While most irs have all the variables they use in the main struct body, there are some exceptions. See `frontend.Prune()`. The Extra field of ir.Inst comes in handy