simon816 / Command-Block-Assembly

Compile high-level code into Minecraft commands
https://www.simon816.com/minecraft/assembler
MIT License
272 stars 29 forks source link

Possible bug in #include_h assembly directive #20

Closed sarahmence closed 4 years ago

sarahmence commented 4 years ago

I'm trying out assembly for my current project and am running into a strange error. I have a file (regs.asm) with several constants defined in order to emulate registers, and I'm using the #include_h directive to load that file into my main file (main.asm). When I try to assemble my project, I get this error:

Traceback (most recent call last):
  File "[redacted]/Command-Block-Assembly/mcc.py", line 4, in <module>
    start()
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 353, in start
    run_with_args(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 360, in run_with_args
    main(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 275, in main
    top = dispatcher.make_top(args)
  File "[redacted]/Command-Block-Assembly/mcc/cli.py", line 132, in make_top
    assembler.parse(self.text_file().read(), self.infile.name)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 47, in parse
    self.consume_reader(AsmReader(text, self.filename))
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 54, in consume_reader
    self.handle_token(token, arg)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 69, in handle_token
    self.handle_directive(*arg)
  File "[redacted]/Command-Block-Assembly/asm/assembler.py", line 135, in handle_directive
    if isinstance(val, Variable) and val.owner:
AttributeError: 'GlobalVariable' object has no attribute 'owner'

Here's my source code:

regs.asm:

.r0: 0x00
.r1: 0x01
.r2: 0x02
[.r3 - .rE omitted for brevity]
.rF: 0x0F

main.asm:

#include_h regs.asm

main:
    MOV #0, r0
    MOV #1, r1
    MOV #1, r2
    MOV #0, r3
    _fibloop:
        PRINT "fib(", r2, ") = ", r0
        SYNC
        ADD #1, r2
        MOV r0, r3
        MOV r1, r0
        ADD r3, r1
        CMP #0, r0
        JGE _fibloop

Is this a bug in the assembler, and if not, how do I fix my code? Thanks in advance!

simon816 commented 4 years ago

Yep, looks like a bug in the assembler when using #include_h. I've pushed a fix so should work now