Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't preprocess "statement replacement macros" while unrolling #131

Closed
Andre-LA opened this issue Sep 24, 2021 · 1 comment
Closed

can't preprocess "statement replacement macros" while unrolling #131

Andre-LA opened this issue Sep 24, 2021 · 1 comment
Labels

Comments

@Andre-LA
Copy link
Contributor

Andre-LA commented Sep 24, 2021

Bug description

The compiler can't generate code with statement replacement macros inside a loop unrolling scope

Code example

## local function macrox(x)
  print(#[x]#)
## end

## for i = 1, 20 do
  #[macrox]#(10)
## end

output:

$ nelua test.nelua 
test.nelua:7:3: error: cannot convert preprocess value of type "function" to an AST node
  #[macrox]#(10)
  ^~~~~~~~~~

Expected behavior

The same behaviour as repeating the code manually.

Workaround

Wrap the statement replacement macro with a runtime function:

## local function macrox(x)
  print(#[x]#)
## end

local function macro_x(x: auto)
  #[macrox]#(x)
end

## for i = 1, 20 do
  macro_x(10)
## end

Environment

Provide relevant information about your environment:

  • Nelua version: 0.2.0-dev.1365+e6a91c19
  • Pop!_OS 21.04 (Ubuntu)
  • Architecture: x86_64
@edubart
Copy link
Owner

edubart commented Sep 24, 2021

You have discovered a flaw in the replacement macro system, thanks for reporting this. I've fixed in commit 7096f16

@edubart edubart closed this as completed Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants