tsoding / porth

It's like Forth but in Python
628 stars 50 forks source link

Unable to use control flow in macros #44

Closed Mm2PL closed 2 years ago

Mm2PL commented 2 years ago

It's impossible to use an if or while block inside of a macro, as it results in a compiler error. Simulation or compile doesn't matter, it's broken in both.

Example

macro test
    2 1 < if
        12 print
    end
end

Compile result

$ python porth.py sim borked.porth
Traceback (most recent call last):
  File "porth.py", line 924, in <module>
    program = compile_file_to_program(program_path, include_paths);
  File "porth.py", line 862, in compile_file_to_program
    return compile_tokens_to_program(lex_file(file_path), include_paths)
  File "porth.py", line 709, in compile_tokens_to_program
    block_ip = stack.pop()
IndexError: pop from empty list

Version d7ecaa221a791616e2c76989feaf65a9cdf42e0c

rexim commented 2 years ago

@Mm2PL yep! It's a known issue! Thanks for reporting it, I'll fix it in the near future.

ap29600 commented 2 years ago

45 fixes this, unless @rexim wants to do it on stream.

rexim commented 2 years ago

@Mm2PL I merged the PR. Please check the latest version.