aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Update `run.sh2` to not re-make the C compilerMustafa Quraish2022-02-051-7/+6
|
* [compiler.cup] Add support for function calls!Mustafa Quraish2022-02-054-12/+130
|
* [compiler.cup] codegen for unary ops, short circuiting &&/||Mustafa Quraish2022-02-052-1/+66
|
* [compiler.cup] Add codegen for relational + if/conditional supportMustafa Quraish2022-02-052-2/+96
|
* [compiler.cup] Add support for lexically scoped local variablesMustafa Quraish2022-02-057-20/+177
|
* Add implementation of self-hosted compiler so farMustafa Quraish2022-02-059-0/+1574
| | | | | | | | | There's also a `run.sh2` script which does the following: - Compiles the C compiler `build/cupcc` - Compiles the self-hosted compiler `build/cup.out` (with `cupcc`) - Compiles the specified file on CLI with `build/cup.out` - Runs this exectuable and shows the output
* Remove old test which disallowed initializing globalsMustafa Quraish2022-02-051-8/+0
|
* Some very minor fixes (look at message)Mustafa Quraish2022-02-052-1/+3
| | | | | (1) Add support for escaped single quotes (2) Fix `putu_buffer` in `std/common.cup`
* Allow empty return statements for void functionsMustafa Quraish2022-02-052-4/+15
|
* Fix label counts during code generation for `||` and `&&`Mustafa Quraish2022-02-051-10/+10
|
* Add `lseek` and `mmap` syscall infoMustafa Quraish2022-02-052-1/+24
|
* Allow function declarations without a definitionMustafa Quraish2022-02-053-14/+41
|
* Handle command-line arguments properly on linuxMustafa Quraish2022-02-051-4/+13
| | | | | | | Turns out they're supposed to be accessed on the stack there. For macOS, because 16 byte-alignment is "required", we don't know the exact position of the arguments and that they're also passed in through `rdi` and `rsi`
* Add `OS_IS_MACOS` and `OS_IS_LINUX` constants as builtinsMustafa Quraish2022-02-051-0/+8
|
* Add support for some more binary ops: |, &, ^Mustafa Quraish2022-02-058-18/+98
|
* Miscellaneous stdlib additionsMustafa Quraish2022-02-051-5/+41
| | | | | | - `close()` syscall - `putu_buffer()` - toy `malloc()` which can allocate from a 1gb pool without freeing.
* Add `sizeof(<type>)` operator that can return the size of a type.Mustafa Quraish2022-02-052-0/+9
|
* Add ability to initialize global variablesMustafa Quraish2022-02-053-4/+14
| | | | The code to initialize them is put right before calling `main()`
* Add `void` type and allow void* to be assigned to other ptr typesMustafa Quraish2022-02-055-9/+24
|
* Allow `builtins.c` to inject constants into program, use for syscallsMustafa Quraish2022-02-057-90/+204
| | | | | | We can now directly expose the `syscallN()` APIs to the program and define the `open()`, `write()` etc syscalls in the stdlib. This simplifies the implementation a decent bunch :^)
* Update README.mdMustafa Quraish2022-02-041-2/+2
|
* Add an enum-like-but-not-really structureMustafa Quraish2022-02-042-0/+49
| | | | | | Basically, it looks like an enum but it isn't actually a type. It just behaves like a container to number all the (global) constants defined within it.
* Some minor bug fixesMustafa Quraish2022-02-042-4/+12
| | | | | | (1) Return correct size for unions (2) Make sure function name identifier doesn't exist (3) Assign `<anonymous>` as display name for nested compound types
* Minor fixes, rearranging, whitespace trimming. No functional changes.Mustafa Quraish2022-02-044-25/+28
|
* Don't open/parse a file that's been included more than onceMustafa Quraish2022-02-041-21/+39
| | | | | We don't use absolute paths or anything fancy right now, but it's a basic prototype which can be extended upon.
* Add support for read-only constant expressionsMustafa Quraish2022-02-044-7/+121
| | | | | | | We can now have constant definitions that are read-only, evaluated at compile time and just behave like integer literals when accessed. These are nice because we can now potentially inject syscall numbers/ etc through the compiler.
* Add some simple tests for arrays+stringsMustafa Quraish2022-02-031-0/+131
|
* Add `exit()` syscall builtinMustafa Quraish2022-02-031-0/+3
|
* Modify implementation of structs to support unionsMustafa Quraish2022-02-034-13/+19
| | | | | | This was simple enough, we just needed to change the part where we were computing the offset for each field, and the total size of the compound structure.
* Add support for basic structsMustafa Quraish2022-02-038-6/+192
| | | | | | | | Structs for now (and probably for the near future) are not allowed to be passed by value, and instead you just pass a pointer to it. Nested structs can also be defined, and they can be either anonymous, or named (in which case only the members can access the type).
* Add automatic type inference for initialized variable declarationsMustafa Quraish2022-02-031-17/+27
| | | | | | If we know the type of the expression on the RHS, and no type is specified, then we can just assume that the variable has the same type.
* Add pre-increment and pre-decrement operators.Mustafa Quraish2022-02-032-2/+34
| | | | | | The implementation is very hacky, maybe there's a better way to go about doing this. Maybe just keep it as single AST node and do the work during codegen?
* Add an implicit block around a `for` loop, allow statement initMustafa Quraish2022-02-031-12/+27
| | | | | Now we can have variable declarations as part of the initialization of the for loop, and it can only be accessed within the loop.
* Make `make test` exit early if any of the tests failMustafa Quraish2022-02-031-1/+1
|
* Push `argc` and `argv` to the `main()` functionMustafa Quraish2022-02-032-1/+11
|
* Add helper to create builtins for syscalls + implement `read()`Mustafa Quraish2022-02-036-75/+126
| | | | | | | | | | This was possible, but very tedious to do by hand before. Now we automate it based on the number of arguments. Note that currently we can't just add `syscall3()` etc as builtins because the actual numbers for the system calls vary from one system to another, and we want to maintain support for macOS and Linux (at least for now).
* Check for integer-like types in type-checking instead of exact onesMustafa Quraish2022-02-031-7/+7
| | | | Since we allow implicit conversions now the exact type is less relevant.
* Remove `putc` intrinsic and replace with `write(fd, buf, size)`Mustafa Quraish2022-02-036-50/+47
| | | | | `putc`, `puts`, and `putnum` in `std/common.cup` are now implemented in terms of the `write()` syscall.
* Move builtins to a separate fileMustafa Quraish2022-02-033-28/+54
| | | | | Probably want to add more builtins in the future, so pulling it out of `parser.c` seems like the reasonable thing to do
* Allow implicitly converting between integer-like-typesMustafa Quraish2022-02-034-5/+33
| | | | This design should also be useful for structs down the road.
* Move all common utilities to `std/common.cup`Mustafa Quraish2022-02-032-22/+73
| | | | | | In the future we can split this into multiple files if we need to, after we've added to ability to handle more complex input graphs without parsing the same file twice.
* Avoid pointer-arithmetic multiplications if we have `char*`Mustafa Quraish2022-02-031-24/+34
| | | | Simple optimization, it was just adding extra overhead anyway.
* Add support for `char` type + string/char literalsMustafa Quraish2022-02-028-21/+153
| | | | | | | | | | | This commit does a few things in one go: - Add support for a `char` type + some changes to support the new size - Add support for character literals. We need some escaping here to be able to use `\n` and `\0`, etc. - Add support for string literals. These are all stored in the `.data` section. Fortunately NASM already handles the escape characters. - Fix some bugs with code generation, specifically using `movsx` to sign extend the smaller types into 64-bit registers.
* Remove default initialization to 0 for variable declarationsMustafa Quraish2022-02-023-6/+9
| | | | | | This made sense when all variables were of the same size, but now with arrays we don't initialize them by default. Perhaps we should find a way to 0-initialize all the memory?
* Handle OP_ASSIGN in `print_ast()`Mustafa Quraish2022-02-021-0/+6
|
* Add initial support for arrays (also no testing)Mustafa Quraish2022-02-026-10/+95
| | | | | | Usual disclaimer at this point: Quick&Dirty implementation, hasn't been tested other than basic sanity checks. Arrays are automatically decayed into pointers when the identifier is accessed.
* Move type-related stuff to a separate fileMustafa Quraish2022-02-025-194/+217
| | | | | | It was getting a bit unwieldy in `parser.c`, and this will potentially help when we start dealing with more complex type-stuff such as casting / conversions / etc.
* Fix examples to include return type on main functionMustafa Quraish2022-02-026-6/+6
| | | | With the fancy new type checking these are now required.
* Type checking of expressions / functions!Mustafa Quraish2022-02-0211-131/+327
| | | | | | | | | | | | | | | | | This is a bit of a chonky commit, but it adds in the basics of checking the types of expressions / function calls / return types. There's still a lot of work to be done, including: (1) Adding new core types, and casting between allowed types automatically (2) Picking the corrent output type based on input types (for instance float+int == float) (3) We need much better error reporting, the error messages are really vague and unhelpful as-is (4) We also need to work to ensure that a function with a return type actually returns (5) Possible re-factoring to make stuff less hacky when we have more types / structs / arrays / etc.
* Use `type*` instead of `type&` to denote a pointer type (for now)Mustafa Quraish2022-02-021-1/+1
| | | | | | While I prefer the latter, the lexer/parser cannot correctly parse `type&&` since it thinks `&&` is `TOKEN_AND`. Perhaps how these cases are handled can be changed in the future.