summaryrefslogtreecommitdiff
path: root/src/symbol_resolver.rs
Commit message (Collapse)AuthorAge
* Don't merge empty source filesBen Bridle2024-11-01
| | | | | | | | When a library contains only macro definitions, the definitions will be kept in the .head.brc file and the main .brc file will be empty. To prevent from cluttering the merged source file with path comments for empty files, the contents of the file are first checked, and if the file contains only whitespace it will not be merged.
* Fix reported source location in symbol redefinition errorsBen Bridle2024-10-31
| | | | | | | | | | | | | | The reported location of the original definition of a redefined symbol was incorrect. The index stored alongside a redefined symbol was the ID of the source unit which owns the original definition, but in the error printing code it was being treated as the index of the original definition of that symbol in the definitions list of the resolver. This was causing the reported location of the original definition to be that of an unrelated symbol. To fix this issue, the index stored alongside a redefined symbol is now the index of the original definition of that symbol in the definitions list of the resolver.
* Ensure the root source unit is always merged lastBen Bridle2024-10-31
| | | | | | | | | | This is to prevent the main source of another zero-dependency source unit from being merged before the main source of the root source unit, which would cause a program to immediately enter into library code when run. The root source unit is always the main source code, and other source units are library code.
* Implement an intelligent source merging strategyBen Bridle2024-10-30
| | | | | | | | | | | | | | | | | | | The previous source merging strategy was to concatenate source units in the reverse order that they were added to the resolver, which generally only worked when each source unit had at most one macro-resolving parent. An issue arose when some macros in a source unit were resolved by a source unit which had been added earlier in the order, as the required macro definitions would then be merged after they were referenced, preventing the program from assembling. The new source merging strategy finds an optimal merge order by first recording for a given source unit the ID of each unit which resolves a macro referenced by the given unit, and then only merging those source units whose macro-defining dependencies have already been merged. In the case that a cycle is detected, where two or more source units depend on one another, a message is printed and the assembly is aborted.
* Rewrite assemblerBen Bridle2024-10-28
This is an almost complete rewrite of the entire assembler from the ground up, with a different parsing strategy and a whole new symbol resolution mechanism for automatically including library files. The assembly syntax has also been slightly modified, with padding tokens now being prefixed with '#' instead of '$', and a block-style anonymous-label syntax which uses the '{' and '}' characters.