aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* 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.
* Add support for pointers! (tests missing)Mustafa Quraish2022-02-024-17/+30
| | | | | | | | | | This commit adds initial support for taking pointers / dereferencing. The type system is still a bit of a hot mess, so all type information is actually not looked at, but the functionality still seems to be there. Still need to add some tests for pointers/dereferencing to ensure that it works in some edge cases as well.
* Refactor variable access+assignment in terms of `generate_lvalue()`Mustafa Quraish2022-02-021-20/+21
| | | | This will make it trivial to compute pointers!
* Add `size_for_type()` helper instead of hard-coding variable sizesMustafa Quraish2022-02-023-5/+16
|
* Modify how types are stored.Mustafa Quraish2022-02-024-99/+143
| | | | | | | We now dynamically allocate the type structure, and recursively store a reference to the original type if it's a pointer. For now it's a little bit of a waste but it helps us future-proof stuff for more complex things to come
* Defer: Pop elements off the defer-stack when returningMustafa Quraish2022-02-011-2/+4
| | | | | | | | | | | | | We restore the count later, but this fix makes it so that the compiler doesn't get stuck in an infinite loop when you try to compile the following code: ``` fn main(): int { defer return 5; return 1; } ```
* Add basic `defer` implementation.Mustafa Quraish2022-02-017-1/+104
| | | | | | We don't have any closures yet, so it's essentially the same as just moving the statement after the `defer` keyword to the end of the block/ right before returning from the function.
* Testing: Add support for testing stdout results, check builtinsMustafa Quraish2022-02-012-0/+103
|
* Global variables now supported! + some fixes to OP_ASSIGNMustafa Quraish2022-01-315-63/+157
| | | | | | Previously we weren't creating a new assignment node, and this was causing all sorts of funky errors. This commit also fixes that, and we can now use global variables :^)
* Add .gitattributes to try to highlight code as RustMustafa Quraish2022-01-312-1/+2
|
* Add workflow to run tests on pushMustafa Quraish2022-01-311-0/+17
|
* Move around tests in the categories; Add missing testsMustafa Quraish2022-01-314-179/+197
| | | | | We now also test for local variables in functions, and add a simple test to see if imports work properly.
* Add `std/math.cup` with some common math functionsMustafa Quraish2022-01-311-0/+22
| | | | For now this is very limited, but shows the ability to import files!
* Add ability to import other filesMustafa Quraish2022-01-314-3/+62
| | | | | | This still requires a lot of work to avoid duplicate imports, and handle cyclic imports, but it is a good enough for small examples which just want to include some common definitions from std/
* Minor fixes to code generationMustafa Quraish2022-01-311-11/+11
| | | | | | | (1) Prefix function names with `func_` now, to avoid clasing with possible NASM keywords (such as `abs`). (2) Label numbers are now properly handed for conditional expressions.
* Fix offset for local variablesMustafa Quraish2022-01-311-1/+1
| | | | | | The stack actually grows downwards, so we need to account for that. The previous implementation was incorrect and exploded if you tried to use local variables in other functions except main.
* Make `Lexer_new` return a pointer instead of the object.Mustafa Quraish2022-01-313-8/+8
|
* Add basic builtin-function supportMustafa Quraish2022-01-316-38/+192
| | | | | | | This isn't really super extendible for now, but it's a start and gives us the `print` builtin which allows us to finally actually print out values to the screen, so we can move away from testing with exit codes eventually.
* Put tokens in their own macro to allow looping over themMustafa Quraish2022-01-304-30/+36
|
* Update build system to use MakefileMustafa Quraish2022-01-307-73/+75
| | | | | | | | | `make` to compile the compiler `make XXX.out` to assemble/link `XXX.nasm` into an executable `make test` to run all tests `make tests/XXX` to run `tests/XXX.sh` test file `./run.sh <cupcc args>` to build, compile, run and show exit code
* Rename `cup` directory to `src`Mustafa Quraish2022-01-3015-1/+1
|
* Remove return-0 exampleMustafa Quraish2022-01-301-3/+0
| | | | | The language has progressed enough now to the point where that doesn't do anything meaningful anymore.
* Functions, yay!Mustafa Quraish2022-01-307-19/+259
| | | | | | | | | | | | | | | We now support function calls! We don't have support for forward declaring functions right now though, so no mutual recursion is possible. The arguments are passed via the stack instead of through registers (unlike the x86_64 calling convention, I think). We'll probably need some sort of primitives built into the language for syscalls eventually because of this. Return types are also not checked, and right now it's possible to have a function that doesn't return anything even when the caller expects it to, error checking and reporting definitely needs to be improved.
* Make the compiler / scripts work on Linux too (yay!)Mustafa Quraish2022-01-293-6/+40
|
* Add for and while loop support (w/o declarations in `for`)Mustafa Quraish2022-01-297-14/+230
| | | | | | We can now loop and do stuff, yay! However, we don't yet allow declarations inside the for-loop initializer, since that is a bit more annoying to implement.
* Implement blocks (lexically scoped) and conditionalsMustafa Quraish2022-01-2910-39/+487
|
* Add i64{max,min} helper functionsMustafa Quraish2022-01-292-1/+7
|
* Allow uninitialized variable declarationsMustafa Quraish2022-01-298-37/+88
|
* Add some tests for local variablesMustafa Quraish2022-01-293-0/+54
|
* Now supporting local variables! :^)Mustafa Quraish2022-01-296-29/+92
|
* Restore line/col count in Lexer_peek to get correct locationsMustafa Quraish2022-01-291-0/+4
|
* Add separator in `die_location()`Mustafa Quraish2022-01-291-0/+1
|
* Stop tests if compilation failsMustafa Quraish2022-01-291-0/+2
|
* Add parsing + storing offsets for locals / move around headersMustafa Quraish2022-01-298-24/+114
|
* Add relational and logical operators + refactor binop parserMustafa Quraish2022-01-296-51/+198
| | | | | | | | | We now support OR and AND with short circuiting! (Yet to be tested since we don't yet have local variables to play with). The binop parser took a bit of an overhaul factoring out the common code so that it's easier to describe the operator precendence relationships without being overly repetitive.