| Commit message (Collapse) | Author | Age | Files | Lines |
| ... | |
| |
|
|
|
|
|
| |
Apparently the standard library had LazyLock which is enough for what I
wanted to achieve with lazy_static.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
This allows users to define variables directly from the command line,
which is useful for testing purposes.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When I introduced this dependency it looked like a good idea to have a
better-looking replacement to cl65's cfg format. That being said, the
end result wasn't *much* prettier either, and the end result could be
even bigger and equally confusing.
Since 5f48de69f46d ("Add support for cfg files") there is quite the
framework in order to support regular cl65's cfg files. Hence, this
commit takes another approach: let's tune this format to a more
compressed and simplified one. This is now the current "nasm cfg"
format, and it allowed us to re-use a lot of code while also being more
to the point for NES/Famicom development than the original cfg format.
With this new format, we can now remove the dependency on TOML and all
of the inner dependencies which were quite a lot.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
This dependency was easily avoidable and it brought with it a lot of
inner dependencies of its own, most notably 'zerocopy-derive', which
forbid us to compile the affected programs purely statically.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
If the programmer only wrote a single special character for an
identifier, then we will consider it empty to avoid shenanigans.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
In fact, they were always allowed, but they were in kind of grey area,
as they could be defined but not used, and sometimes they could be used
in the middle of identifiers, which was unexpected.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
There were certain situations in which syntax ambiguity could arise. For
example, the parser as it stood could treat a valid expression such as
'lda #$80 >> 2' in an unexpected 'lda #$(80 >> 2)'.
This is of course bad, and it came from the fact that literals don't
have enclosing characters, and white spaces are not enough to provide
disambiguation in some cases. Because of this fact, the parser now has a
"look ahead" capability similar to many other parsers, and it's applied
for now only to literals. This looking ahead actually honors
parenthesis, so these can be added if the programmer wants to
explicitely disambiguate an expression.
This involved quite the heavy lifting, and some functions like
'parse_expression_with_identifier' had to be removed with the rewrite.
This had the side effect of having (hopefully) more sane functions all
around, and the parser also has a better capability to differentiate
between regular Values and Calls.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
| |
This is in preparation to some heavy lifting that is to be done to the
parser so it more properly handles nested expressions, but in general
it's a good idea to have some limits to functions that expect to be
called recursively quite heavily.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
Instead of making up a list of characters that end an identifier, do the
other way around since it's far less cumbersome and it prevents from
silly bugs such as "var+1" being considered a single identifier.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
| |
As a remnant of old code, the 'parse_decimal' function was not allowing
for decimal values larger than 8-bits. This was not the case in other
areas such as 'parse_hexadecimal', and in the rest of the code we
already cover that immediates are not too big in instructions. Hence,
this restriction can be lift up and allow up to 16-bit decimal literals.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
They are just synonyms for ".if .defined" and ".if !.defined"
respectively.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
This can be combined with .if/.elsif statements just like any other
expression.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
| |
Allow for expressions that evaluate to a boolean expression. This in
turn mean that the value is just set to 0 or 1 depending on the given
condition. As with other assemblers, only a value of 0 evaluates to 0,
and others go to 1. So, something like "1 && 2" evaluates to 1 even if
it doesn't make much sense at first glance (as an assembler we just
assume that the programmer knows what it's doing).
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
| |
As with e27a1593c8d8 ("Allow semicolons inside of strings"), the parser
was too naive and regarded any '=' operator as part of an assignment,
despite that it could be art of string literal.
Luckily the fix was already done inside of the parsing of assignments,
we just needed to move it up.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
| |
The parser was too naive and assumed that a semicolon immediately
implied an inline comment, and that might not just be the case as it is
with string literals.
Hence, the end of each semantic line has to consider not only whether
there is an inline comment, but also if a string literal is being used
and whether it surrounds or not the given semicolon.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
| |
Some control statements (e.g. '.incbin', '.asciiz') only require a
double-quoted string as an argument. In fact, for these functions
there's only one argument required, which is this string one. Given this
fact, the parsing on these functions don't have to go through
the (expensive) general argument parsing function, and they can simply
assume that a double-quoted string will be provided.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
Some operators like '<' and '<<' could be mistakingly be treated as the
other. Let's remove this ambiguity when checking for unary operators.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
The other cases in which fetching an "identifier" is not needed were
starting to pile up. Hence, split them into separate functions and allow
'parse_expression' to be more simple.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
| |
Before this it was left to the `parse_identifier` to figure things out,
but this was prone to silly errors like "a: b", in which it would
mistake it as the start of a label. Instead of any of this, just consume
a string literal if it has been detected.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
| |
Not that I like it, but there are existing code which already uses this.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
Similarly to other assemblers, this allows the programmer to write a
definite amount of bytes with the same values.
Compared to other assemblers there are two things to notice. First,
there is a limit to it (i.e. whatever can fit in 2 bytes). Second, if
the fill value is not provided, then it will default to the current
mapping's fill value, or just 0x00 if the current mapping doesn't define
one of its own.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
| |
Update the underlying code.nes test data so it uses a tighter
configuration for NROM which in turn frees nasm from complaining about
empty segments. This makes room to allo for -Werror so we catch warnings
that might appear in the future.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
In order to make tools like `xa65` work seamlessly with existing
configurations, allow this format too instead of making developers
switch to a new file with TOML syntax.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
| |
Also remove some pending TODOs.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
When calling `force_context_switch` the stack was mindlessly pushing the
given name without taking into consideration how scopes are to be laid
out. This made some variables/addresses that were previously preserved
no longer reachable when crunching pending nodes.
This patch also makes `force_context_switch` reset the stack before
doing anything at all, which means that `force_context_pop` was no
longer relevant.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
| |
It is a really weird thing to do, but on a twisted way I can see how
someone could think of such a monstrosity. Panicking on such a case is
not valid because that's not the fault from the assembler but from the
programmer, and so a proper message should be displayed instead.
This was detected via the fuzzer, but it was a side effect from
e7c5e63d04f6 ("Evaluate bare numbers as decimal values").
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
| |
In places like macro calls, the programmer might actually prefer to pass
a numeric argument as is, without any prefixes. In these cases, just
evaluate it as a decimal. In fact, this was already covered when
evaluating the context because the same thing happens to assignments.
Hence, I just needed to expand the scope of this.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
| |
Also documented the struct as it is exported.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
They started with good intentions, but in the end they were all pretty
much alike. Hence, it makes sense to simplify everything and provide a
single struct.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
This needed some heavy lifting when it comes to how files were located.
This means that statements like .include/.incbin now take into
consideration a new list made out of SourceInfo, which holds enough
information to translate from which file a node comes from. This has
also been added into errors, so they are more informative on what went
wrong.
In order to tests this, besides all the regular unit tests, a new e2e
test has been added.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
| |
In bad314e1cfbf ("Prevent numeric literals from having spaces") it was
added already the restriction on not having whitespace characters in
literal expressions. Here we go a step further and we more explicitely
limit which symbol combinations can go into a literal declaration (e.g.
"#$2" is valid but "##2" is not).
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
It has been found that having literals like "# 20" can potentially be
troublesome and even introduce crashes. Hence, as it's done in other
assemblers, disallow this kind of syntax.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Sometimes, out of clarity, the programmer may have written something
along the lines of:
lda $40, y
This is invalid because the `lda` instruction does not allow zeropage
y-indexing addressing mode. That being said, it does allow for absolute
y-indexing addressing mode. This commit allows this syntax by
transforming code like the previous one into:
lda $0040, y
This cannot always be done, but the assembler should at least try if
it's possible and not trouble the programmer.
That being said, this is otherwise a bit shady since the programmer
might think that it's a 2-byte instruction when it's a 3-byte one.
Hence, maybe a future linter can pick up code like this and suggest a
more explicit writing.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is a control statement which acts similarly as .proc/.macro/.scope,
in which an inner block is allocated for it. Hence, all the previous
work from 1f8a6becc7cd ("parser: Implement block bodies") and
ec8b709fa24c ("Implement block bodies inside of the assembler") make
this one out possible, as .repeat statements don't have an identifier
that can be used for hashing.
From the parser perspective this introduction raises two new things.
First of all this control statement also needed a differentiation
between the amount of required arguments, and the allowed ones, since
there is a second optional argument to it. And second, even the
identifier is not given, we have to generate one so to add a context for
it. This was at first not needed, but introducing .repeat-only variables
means that we have to have inner contexts which need to be named somehow
so we can retrieve the context later when picking up the value for them
again.
This last thing brought the need for a new dependency: rand. This is
used to generate a random string to identify the .repeat block.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
It is not safe to store a node index for macros since the list of nodes
that is passed down during assembly might change depending on whether an
inner block is being evaluated. Hence, the previous implementation would
break on a simple macro call inside of a .proc.
This also raised some concerns on the design around the API, since the
lifetime of references for internal assembler data needed an explicit
lifetime now, and as a side-effect functions like `assemble` had to be
moved out of the inner impl Assembler. This is in retrospect also a
better design choice.
Fixes: ec8b709fa24c ("Implement block bodies inside of the assembler").
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
| |
The parsing of control statements have become more complex since the
introduction of block bodies in 1f8a6becc7cd ("parser: Implement block
bodies"); so it makes sense to move it into its own thing and keep
`parse_statement` more clear.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
| |
Following 1f8a6becc7cd ("parser: Implement block bodies"), the support
for the new way of managing block bodies have also been added into the
assembler.
There are still some things to iron out, but they will be fixed in later
commits.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
| |
These are bodies which are the right node of some proc controls. This
way the parser comes back to sanity for statements like .macro and the
likes, and behaves more like a usual parser. This was not done in the
past because I thought things could have been simpler this way, but it
ended up making the assembler way more complicated that it needed to.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
Instead of calling `evaluate_node` for each node on a macro, just call
`Assembler::bundle` for the list of nodes so the context is preserved
and labels and other statements can be catched as usual.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
This is just prone to errors and it is confusing all around. Just
prohibit developers doing that.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|