simon816 / Command-Block-Assembly

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

Bug involving #include and #include_h assembler directives while using relative paths #21

Closed sarahmence closed 4 years ago

sarahmence commented 4 years ago

I am working on a project with this file structure:

In init.asm, I have this code:

#include_h ../util/regs.asm

init:
    [routine body omitted for brevity]

In main.asm, I have this code:

#include_h setup/init.asm

main:
    CALL init

When I try to assemble main.asm, 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 133, in handle_directive
    self.top.include_from(assembler.top)
  File "[redacted]/Command-Block-Assembly/cmd_ir/core.py", line 355, in include_from
    self.scope[name] = ExternFunction(var.global_name.name, self)
  File "[redacted]/Command-Block-Assembly/cmd_ir/core.py", line 641, in __init__
    super().__init__(NSName(name), params, returns)
  File "[redacted]/Command-Block-Assembly/cmd_ir/core.py", line 598, in __init__
    self.params = list(params or [])
TypeError: 'TopLevel' object is not iterable

It seems that relative paths don't work properly when used in #include_h or #include directives. Can this be fixed? Thanks in advance!

simon816 commented 4 years ago

Ah, another bug with #include_h, this is caused when trying to include subroutines from another file. I should write tests for these features but haven't gotten around to doing so. All current progress is going into developing CBL so the assembler hasn't had much attention.

sarahmence commented 4 years ago

Is it fixable? I've found that assembly is the most stable and usable language that MCC supports.

simon816 commented 4 years ago

Should be fixed now