Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Changes that are planned but not implemented yet:
* Added semantic label-usage highlighting in Vim: references to labels defined in the buffer are highlighted distinctly from arbitrary identifiers.
* Added hover-equivalent documentation in Vim: pressing `K` over a mnemonic, register, directive, expression function, or predefined symbol opens its documentation in a preview window. An optional auto-popup variant (vim 8.2+ / Neovim) is available via `g:bespokeasm_<ft>_auto_hover`.
* Improved unit test coverage
* Fixed an `IndexError` crash when compiling a source file with no compilable lines; a clear diagnostic error is now reported instead.

## [0.7.3]
* Added configurable mnemonic decorators (`+`, `-`, `++`, `--`, `!`, `@`) so instruction variants can use prefixed or suffixed decorated mnemonics such as `m+`, `m-`, and `++inc`.
Expand Down
5 changes: 5 additions & 0 deletions src/bespokeasm/assembler/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def assemble_bytecode(self):
compilable_line_obs.extend(predefined_line_obs)

# Sort lines according to their assigned address. This allows for .org directives
if not compilable_line_obs:
diagnostic_reporter.error(
None,
Comment thread
michaelkamprath marked this conversation as resolved.
'source file contains no compilable lines',
)
compilable_line_obs.sort(key=lambda x: x.address)
max_generated_address = compilable_line_obs[-1].address
line_dict = {
Expand Down
28 changes: 28 additions & 0 deletions test/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,34 @@ def test_address_overlap_is_fatal(self):
assembler.assemble_bytecode()
self.assertIn('overlaps', str(ctx.exception))

def test_empty_source_reports_diagnostic(self):
"""An empty source file reports a friendly error instead of IndexError."""
fp = pkg_resources.files(config_files).joinpath('test_instruction_operands.yaml')
config_path = str(fp)
with tempfile.TemporaryDirectory() as temp_dir:
asm_path = os.path.join(temp_dir, 'empty.asm')
with open(asm_path, 'w') as handle:
handle.write('')

assembler = Assembler(
source_file=asm_path,
config_file=config_path,
generate_binary=False,
output_file=None,
binary_start=None,
binary_end=None,
binary_fill_value=0,
enable_pretty_print=False,
pretty_print_format=None,
pretty_print_output=None,
is_verbose=0,
include_paths=[temp_dir],
predefined=[],
)
with self.assertRaises(SystemExit) as ctx:
Comment thread
michaelkamprath marked this conversation as resolved.
assembler.assemble_bytecode()
self.assertIn('no compilable lines', str(ctx.exception))

def test_msb_mismatch_in_second_pass_reports_line_diagnostic(self):
fp = pkg_resources.files(config_files).joinpath('test_valid_address_enforcement.yaml')
config_path = str(fp)
Expand Down