erde-lang / erde

A programming language that compiles to Lua.
https://erde-lang.github.io
MIT License
39 stars 4 forks source link

Inconsistent target behavior in CLI #11

Closed tp86 closed 1 year ago

tp86 commented 1 year ago

Reproduce steps:

$ cat test.erde
local C = require('erde.constants')
print(C.LUA_TARGET)
goto x
::x::
$ erde test.erde
5.4
$ erde compile test.erde
test.erde => ERROR
erde: test.erde:3: 'goto' statements only compatibly with lua targets 5.2+, jit
$ erde compile --target 5.4 test.erde 
test.erde => test.lua
$ lua test.lua
5.1+ # I know that 'erde.constants' is internal module and you aren't supposed to `require` it, but maybe it should also be consistent here...

So it seems that compile does not infer correct Lua target (5.4 in my case) - you need to provide it explicitly with --target flag.

Also, run ignores --target flag completely (not sure if it's by design or it should be passed as well...).

I can try to take care of it if you want but I cannot predict when I have some time, so it may be delayed.

bsuth commented 1 year ago

So it seems that compile does not infer correct Lua target (5.4 in my case) - you need to provide it explicitly with --target flag.

This is by design, I figured that erde compile should default Lua target to 5.1+ and erde run / REPL to the current Lua version, as I thought those would be the most common use cases respectively. However, I'm also completely okay with changing this behavior to be a little more intuitive or adding some more documentation on this :eyes:

Also, run ignores --target flag completely (not sure if it's by design or it should be passed as well...).

Definitely a bug, it looks like lib.load() is overriding any specified targets in the cli (which also affects the REPL). This should be fixed with https://github.com/erde-lang/erde/commit/a2e8aa5b4127dbe5f69f6418dabaffbdfac6153b

tp86 commented 1 year ago

This is by design, I figured that erde compile should default Lua target to 5.1+ and erde run / REPL to the current Lua version, as I thought those would be the most common use cases respectively.

I see, seems reasonable to compile with maximum compatibility by default.

Definitely a bug, it looks like lib.load() is overriding any specified targets in the cli (which also affects the REPL).

Speaking of REPL, I have prepare PR #12 with some improvements in displaying results (should be now consistent with Lua REPL).

This should be fixed with https://github.com/erde-lang/erde/commit/a2e8aa5b4127dbe5f69f6418dabaffbdfac6153b

I think this issue can be closed then.