| Commit message (Collapse) | Author | Age | Files | Lines |
| | |
|
| | |
|
| | |
|
| | |
|
| |
|
|
| |
The code to initialize them is put right before calling `main()`
|
| | |
|
| |
|
|
|
|
| |
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 :^)
|
| |
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
(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
|
| | |
|
| |
|
|
|
| |
We don't use absolute paths or anything fancy right now, but it's
a basic prototype which can be extended upon.
|
| |
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
| |
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).
|
| |
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
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?
|
| |
|
|
|
| |
Now we can have variable declarations as part of the initialization
of the for loop, and it can only be accessed within the loop.
|
| |
|
|
|
| |
Probably want to add more builtins in the future, so pulling it out
of `parser.c` seems like the reasonable thing to do
|
| |
|
|
| |
This design should also be useful for structs down the road.
|
| |
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
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?
|
| |
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
| |
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.
|
| | |
|
| |
|
|
|
|
|
| |
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
|
| |
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
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 :^)
|
| |
|
|
|
|
| |
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/
|
| |
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
| |
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.
|
| |
|