| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
| |
Iterating via `bytes()` on a file is inefficient as the default
implementation calls `read` on each byte, which can be costly on bytes
which are not in memory like files. This is extra important for
statements like `incbin` as included files can be rather big.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Arguments can be put inside of enclosing parenthesis, but the parser was
assuming that if an opening paren was found when parsing the first
argument on an argument list, then that was all it was needed to be
parsed. This though conflicts with situations like:
.byte ($01 << 2) | ($01 << 1)
In this case, the parser would have ignored everything past the first
closing paren.
This commit provides a fix in which if an operation is found past the
first enclosing parenthesis, then this assumption is discarded in favor
of a parenthesis being used for disambiguating on an
arithmetical/logical expression.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
This allows to compare both binaries more easily with tools such as
vimdiff and the likes.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
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>
|
| |
|
|
| |
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>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
All three binaries (i.e. readrom, nasm and xa65) used it, and to be
honest rolling our own argument parsing was actually pretty easy to
achieve. This frees us from a big dependency and it also frees us from
inner dependencies such as 'clap_derive' which prevented us from being
able to build binaries purely statically.
As a side effect, we can now display help/version messages which are
more like I'm used to, and certain checks can be moved in the parsing
directly instead of having to be done later. As a cherry on top, there
is some type masturbation that gets removed along the way.
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>
|
| |
|
|
| |
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>
|
| |
|
|
| |
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>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
For compatibility with cl65, it's preferrable to keep the short version
of the flag as with cl65.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
| |
This is meant for compatibility with ca65.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
This allows us to statically build the 'readrom' binary, as that feature
from clap prevented that option.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
Following in the footsteps of c20c991dded8 ("Make errors from nasm
itself more cohesive"), 'anyhow' might provide an easy framework, but it
lends towards a less cohesive experience.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
The errors reported from the library had a slightly different format
than those that happened in the main file for nasm. This is because in
these cases we were just returning an Err type and Rust handles that
through a special impl.
Instead of going the route of type masturbation, let's go the C route
and have a 'die' function that simply prints the message and calls
exit(1),
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
This is a bridge between 'nasm' and 'cl65'. That is, it runs the same
command on both 'nasm' and 'cl65', compares the resulting binaries, and
gives back the binary from 'cl65'.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
| |
Also remove some pending TODOs.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
This way I can simply compress all the examples to traverse with a
single file, and thus no longer polluting this repository from code from
other repositories.
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>
|