luapower / dynasm

DynASM with Lua mode
http://luapower.com/dynasm
103 stars 10 forks source link

pipe character conflicts with lua 5.3 `bor` operator #4

Closed daurnimator closed 5 years ago

daurnimator commented 9 years ago

Lua 5.3 introduces bitwise operators, including |. It's not uncommon to write code like:

if (getsomelongthing:foo(arg1)
    | getsomelongthing:bar()
    & somemask) ~= 0 then
  ......
end

This conflicts with the pipe character as used in dynasm

capr commented 9 years ago

Um, does dynasm work win Lua 5.3? How do you load the linker, with luaffi?

Anyway, I think a "separator" option is in order then. Care to make a pull request?

daurnimator commented 9 years ago

Um, does dynasm work win Lua 5.3? How do you load the linker, with luaffi?

For starters I was just trying the preprocessor with 5.3.

It works with only a couple of changes (the first one obviously hacky):

diff --git a/dynasm.lua b/dynasm.lua
index b66c45d..9478f09 100644
--- a/dynasm.lua
+++ b/dynasm.lua
@@ -1145,11 +1145,15 @@ local function setlang(infile)
   end

   -- Set initial defines only available in Lua mode.
-  local ffi = require'ffi'
-  map_def.ARCH = ffi.arch          --for `.arch ARCH`
-  map_def[upper(ffi.arch)] = 1     --for `.if X86 ...`
-  map_def.OS = ffi.os              --for `.if OS == 'Windows'`
-  map_def[upper(ffi.os)] = 1       --for `.if WINDOWS ...`
+  map_def.ARCH = "x64"             --for `.arch ARCH`
+  map_def[upper(map_def.ARCH)] = 1 --for `.if X86 ...`
+  map_def.OS = "Linux"             --for `.if OS == 'Windows'`
+  map_def[upper(map_def.OS)] = 1   --for `.if WINDOWS ...`
 end

 -- Parse arguments.
@@ -1282,7 +1286,7 @@ if ... == "dynasm" then -- use as module
   end

   -- Register a module loader for *.dasl files.
-  insert(package.loaders, function(modname)
+  insert(package.searchers or package.loaders, function(modname)
     local daslpath = gsub(gsub(package.path, "%.lua;", ".dasl;"), "%.lua$", ".dasl")
     local path, reason = package.searchpath(modname, daslpath)
     if not path then return reason end

Then you can run it with: lua5.3 -e 'bit=require"bit32"' dynasm.lua dynasm_demo_x86.dasl

Anyway, I think a "separator" option is in order then. Care to make a pull request?

I don't have the time to do it myself at the moment (including testing etc). Hence why opening the issue :)

daurnimator commented 8 years ago

@capr was this solved?

capr commented 8 years ago

nop, but dynasm-luamode is not compatible with stock Lua (any version) because it uses the ffi library.

daurnimator commented 8 years ago

dynasm-luamode is not compatible with stock Lua (any version) because it uses the ffi library.

luaffi brings the ffi to all normal lua releases https://github.com/facebook/luaffifb is there some incompatibility?

capr commented 8 years ago

I dunno, I never tried it. Personally I can only support LuaJIT and the platforms listed on the luapower website for the packages that I maintain. I don't want to spread myself too thin. That being said, contributions to support other platform are welcome. If you want you can start another issue titled "add support for Lua 5.3" but I'm affraid it will stay open forever until someone other than me actually does what's necessary to support that platform.

daurnimator commented 8 years ago

Possibly. Can we also keep this issue open as 'Add "separator" option'?