Commit Graph

38 Commits

Author SHA1 Message Date
Sylvie
57c3d74b9e Use a custom generic tagged union Either instead of std::variant for efficiency (#1476)
* Implement custom generic tagged union `Either`

This should be more efficient than `std::variant`, while still
keeping runtime safety as it `assert`s when `get`ting values.

* Use `Either` for RPN expressions

* Use `Either` for file stack node data

* Use `Either` for `File` buffer

* Use `Either` for `STRFMT` args

* Use `Either` for RGBLINK symbol values

* Support an equivalent of `std::monostate` for `Either`

* Use `Either` for lexer tokens

* Use `Either` for symbol values

* Use `Either` for lexer mmap/buffer state
2024-08-20 21:19:11 +02:00
Sylvie
2d530dbcd6 Fix constant expression detection functions (#1462) 2024-08-09 09:40:53 +02:00
Sylvie
e93190d491 Implement BITWIDTH and TZCOUNT functions (#1450) 2024-08-07 10:39:30 -04:00
Sylvie
7435630d6a Error messages note when a symbol has been purged (#1453) 2024-08-06 15:35:06 -04:00
Sylvie
2706f94788 Multiple fixes and enhancements to RPN behavior: (#1448)
- FIX: `Label & const` was not actually doing the `& const` masking
  (fixes #1446)
- ADD: `LOW(Label)` can be constant if `Label` is aligned to 8 or more bits
  (resolves #1444)
- ADD: `!expr` can be constant 0 if `expr` has any non-zero bits
  (resolves #1447)
- `LOW()` and `HIGH()` have their own RPN operator values
  (resolves #1445)

The change to RPN values means that the object file version was incremented.

This also refactors unary operators and functions, combining their
evaluation similarly to binary ones.
2024-08-06 13:54:55 +02:00
Sylvie
9a5b3f0902 Implement multi-value charmaps (#1429) 2024-08-04 23:32:08 +02:00
Sylvie
dfec7111e2 X && 0 and X & 0 are constant 0; X || 1 is constant 1 (#1399)
Fixes #977
2024-06-13 11:09:39 -04:00
Sylvie
a234da42a6 Replace assert with assume for release build optimization (#1390) 2024-04-02 11:09:31 -04:00
Sylvie
1d39e5ed56 Use std::variant for RPN expression value (#1389) 2024-04-01 16:47:15 +02:00
ISSOtm
e5078aba3b Clean up #includes
Remove unused headers, and avoid relying on transitive inclusions

`include-what-you-use` has been very useful for this!
2024-03-28 01:25:38 +01:00
Rangi42
e9e8915725 Refactor to keep lexerState and lexerStateEOL static
Also run `clang-format` on everything
2024-03-23 19:14:46 -04:00
Sylvie
04405fb444 Use std::shared_ptr for fstack nodes (#1371) 2024-03-22 13:27:21 -04:00
Sylvie
dd43723e20 Use methods for RPN Expression (#1372) 2024-03-22 04:41:04 -04:00
Rangi42
05d79d87f6 Pass std::string references to RPN functions 2024-03-18 14:42:05 -04:00
Rangi42
472d1bde06 Pass std::string references to symbol functions 2024-03-18 14:42:05 -04:00
Sylvie
820f6b5b3c Consistently format type qualifiers like const on the right (#1347) 2024-03-10 12:21:52 -04:00
Rangi42
569b940b82 No need to manually do the Expression destructor's job 2024-03-09 19:33:53 -05:00
Sylvie
17444e825a Reduce the header declarations (#1342)
- Since we have style rules to include foo.hpp at the top of its
  corresponding foo.cpp, this takes any headers included by foo.hpp
  as being also guaranteed for foo.cpp.

- Use C-style <foo.h> instead of <cfoo>, since the latter only
  guarantees putting symbols in the `std` namespace, which we are
  not using for C functions (e.g. `printf` not `std::printf`).

- Remove now-unused `__PRETTY_FUNCTION__` reporting
2024-03-09 14:55:39 -05:00
Sylvie
5681be1fd8 Use automatic allocation and std::move for RPN bytes (#1336) 2024-03-09 11:12:34 -05:00
Sylvie
53537cf9af Remove now-unnecessary enum keyword (#1338)
C++ does not need it
2024-03-08 19:40:41 -05:00
Rangi42
097b7c3baf Use std::string for symbol names 2024-03-07 12:40:33 -05:00
Rangi42
bf45ebb178 Run clang-format to fix some inconsistent style 2024-03-07 11:52:53 -05:00
Rangi42
84bedc7bbe Use automatic allocation for RPN reasons 2024-03-07 09:58:45 -05:00
Rangi42
e5b7e65e91 Use std::nothrow from <new> with every new allocation 2024-03-07 09:56:15 -05:00
Rangi42
75105016f7 Make sure that parsed subexpressions are fully defined
We were not initializing some expressions, and they were using
the values of the previous expressions instead. This just so
happened to not crash the tests, and to sometimes even give valid
results (although `BANK()` of a non-label symbol being $4B4E4142,
the ASCII balue of "BANK", was something we missed).
2024-03-06 16:00:55 -05:00
Sylvie
e74073e480 Run clang-format on everything (#1332) 2024-03-04 14:22:49 -05:00
Rangi42
277ea9be28 Replace RGBASM non-null pointers with references 2024-03-03 00:57:03 -05:00
Sylvie
1ac3c0262f Refactor structs to use methods instead of functions (#1322) 2024-03-01 13:11:45 -05:00
Sylvie
043db49676 Replace NULL with nullptr (#1321) 2024-02-29 15:06:33 -05:00
Sylvie
eff8c324c8 Remove now-unnecessary struct keyword (#1320)
C++ acts like structs are `typedef`ed by default

We do have to keep `struct stat`, since there's ambiguity
with the function also called `stat`.
2024-02-29 14:41:58 -05:00
Rangi42
2ff723f943 Use vec.data() instead of &vec[0]
In general `vec.data()` is always safe, whereas `&vec[0]`
may fail when `vec` is empty.
2024-02-29 13:44:08 -05:00
Rangi42
514044496f Use std::string for RPN error reasons 2024-02-29 13:44:08 -05:00
Rangi42
17861a970f Use std::vector for RPN data 2024-02-29 13:44:08 -05:00
Rangi
6132b77c1e Add more tests for RGBASM code coverage (#1257)
* Add more tests for RGBASM code coverage

* Use C++ unnamed parameters, not `(void)` casting

* Fix crash in `sect_AlignPC` from #1253
2023-12-01 10:21:43 -05:00
Rangi42
482160ea04 Prefer rpn_isKnown(expr) accessor to expr->isKnown directly 2023-11-21 10:46:59 -05:00
Rangi
3c0879a3c6 Fix spurious truncation warning (#1238) 2023-11-20 22:51:51 +01:00
Rangi
dde9f2bb79 Rename some RPN constants for consistency (#1230) 2023-11-08 21:30:27 +01:00
Rangi
1e70e703a7 Build everything as C++ (#1176) 2023-11-07 21:45:56 +01:00