-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from craigthomas/add-unit-tests
Refactor assembler for Python 3.6
- Loading branch information
Showing
14 changed files
with
1,084 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.pyc | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: python | ||
sudo: false | ||
python: | ||
- 3.6 | ||
addons: | ||
apt: | ||
packages: | ||
- python-dev | ||
virtalenv: | ||
system_site_packages: true | ||
script: | ||
- coverage run -m nose | ||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Copyright (C) 2014-2018 Craig Thomas | ||
This project uses an MIT style license - see LICENSE for details. | ||
A Chip 8 assembler - see the README.md file for details. | ||
""" | ||
# I M P O R T S ############################################################### | ||
|
||
import argparse | ||
|
||
from chip8asm.program import Program | ||
|
||
# F U N C T I O N S ########################################################### | ||
|
||
|
||
def parse_arguments(): | ||
""" | ||
Parses the command-line arguments passed to the assembler. | ||
""" | ||
parser = argparse.ArgumentParser( | ||
description="Assemble or disassemble " | ||
"machine language code for the Chip8. See README.md for more " | ||
"information, and LICENSE for terms of use." | ||
) | ||
parser.add_argument("filename", help="the name of the file to examine") | ||
parser.add_argument( | ||
"--symbols", action="store_true", help="print out the symbol table" | ||
) | ||
parser.add_argument( | ||
"--print", action="store_true", | ||
help="print out the assembled statements when finished" | ||
) | ||
parser.add_argument( | ||
"--output", metavar="FILE", help="stores the assembled program in FILE") | ||
return parser.parse_args() | ||
|
||
|
||
def main(args): | ||
""" | ||
Runs the assembler with the specified arguments. | ||
@param args: the arguments to the main function | ||
@type: namedtuple | ||
""" | ||
program = Program() | ||
program.parse_file(args.filename) | ||
program.translate_statements() | ||
program.set_addresses() | ||
program.fix_opcodes() | ||
|
||
if args.symbols: | ||
print("-- Symbol Table --") | ||
for symbol, value in program.get_symbol_table().items(): | ||
print("0x{} {}".format(value[2:].rjust(4, '0').upper(), symbol)) | ||
|
||
if args.print: | ||
print("-- Assembled Statements --") | ||
for statement in program.get_statements(): | ||
print(statement) | ||
|
||
if args.output: | ||
program.save_binary_file(args.output) | ||
|
||
|
||
main(parse_arguments()) | ||
|
||
# E N D O F F I L E ####################################################### |
Oops, something went wrong.