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

Enable useBitLib option by default? #56

Open
otommod opened this issue Apr 23, 2022 · 5 comments
Open

Enable useBitLib option by default? #56

otommod opened this issue Apr 23, 2022 · 5 comments

Comments

@otommod
Copy link

otommod commented Apr 23, 2022

Lua 5.3 added bitwise operators (<<, >>, &, |, ~).

LuaJIT has the bit module.

Fennel has the functions lshift, rshift, band, bor, bxor, bnot.

By default, these compile to be Lua 5.3 operators. You can pass the option useBitLib to the Fennel compiler to make it use the bit module. This is not mentioned in the API reference so it may not be considered "stable" but it's what the Fennel CLI uses for the --use-bit-lib argument.

Given that hotpot targets Neovim specifically I think this should always be done.

@rktjmp
Copy link
Owner

rktjmp commented Apr 24, 2022

I don't disagree that it could be enabled by default, but I am hesitant to do it because it isn't a complete compatibility layer: "The integer division operator (//) is only available in Lua 5.3+" and they "cannot be used as higher-order functions".

I think that puts some onus on the user to know what they want to use and how they can use it so it should probably be opt in.

@rktjmp rktjmp changed the title Does not correctly handle bitwise operators Enable useBitLib option by default? Apr 24, 2022
@otommod
Copy link
Author

otommod commented Apr 24, 2022

I was just reading the Fennel reference and saw that passage. I guess useBitLib is documented after all.

cannot be used as higher-order functions

That's always true though, LuaJIT or not.

The integer division operator (//) is only available in Lua 5.3+

There is, indeed, nothing that can be done in this case.

Still, not using the option is definitely the less correct solution for Neovim (at least so long as LuaJIT is the only supported implementation).

@reptee
Copy link

reptee commented Mar 7, 2023

Hello!

Seeing this issue and fennel's supports for bitlib, how do I enable it within hotpot?
fennel.compile doesn't seem to take any related options and passing any of "--use-bit-lib", "use-bit-lib" to hotpotConfig.compiler table doesn't provide support for it

require("hotpot").setup {
  provide_require_fennel = true,
  enable_hotpot_diagnostics = true,
  compiler = {
    ["--use-bit-lib"] = true,
    ["use-bit-lib"] = true,
    "--use-bit-lib",
    "use-bit-lib",
    modules = {
      correlate = true,
    },
  },
}

@rktjmp
Copy link
Owner

rktjmp commented Mar 7, 2023

It needs to go in the modules (and optionally macros) table, the option name is useBitLib per https://fennel-lang.org/reference.

These all work as you would expect, with a few caveats. The bitwise operators are only available in Lua 5.3+, unless you use the --use-bit-lib flag or the useBitLib flag in the options table, which lets them be used in LuaJIT. The integer division operator (//) is only available in Lua 5.3+.

modules = {
  correlate = true,
  useBitLib = true,
},

You might have to touch/save/edit files that you want to use the bit operators in to trigger a recompile with the new options.

@reptee
Copy link

reptee commented Mar 7, 2023

Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants