mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 09:59:29 +00:00
Add Lua 5.2 target
This commit is contained in:
parent
bf4cadc349
commit
7e4b46ba7d
6 changed files with 1359 additions and 279 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#import("compiler.lua54")
|
||||
#import("compiler.lua53")
|
||||
#import("compiler.lua52")
|
||||
#import("compiler.luajit")
|
||||
#import("compiler.lua51")
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ if _VERSION == "Lua 5.1" then
|
|||
candran.default.target = "lua51"
|
||||
end
|
||||
elseif _VERSION == "Lua 5.2" then
|
||||
candran.default.target = "lua51"
|
||||
candran.default.target = "lua52"
|
||||
elseif _VERSION == "Lua 5.3" then
|
||||
candran.default.target = "lua53"
|
||||
end
|
||||
|
|
|
|||
1576
candran.lua
1576
candran.lua
File diff suppressed because it is too large
Load diff
|
|
@ -22,8 +22,14 @@ tags.Break = ()
|
|||
end
|
||||
|
||||
-- Unsuported features
|
||||
tags.Goto = nil
|
||||
tags.Label = nil
|
||||
tags.Goto = ()
|
||||
error("target "..targetName.." does not support gotos")
|
||||
end
|
||||
tags.Label = ()
|
||||
error("target "..targetName.." does not support goto labels")
|
||||
end
|
||||
|
||||
#placeholder("patch")
|
||||
|
||||
#local patch = output
|
||||
#output = ""
|
||||
|
|
|
|||
35
compiler/lua52.can
Normal file
35
compiler/lua52.can
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
targetName = "Lua 5.2"
|
||||
|
||||
APPEND = (t, toAppend)
|
||||
return "do" .. indent() .. "local "..var("a")..", "..var("p").." = { " .. toAppend .. " }, #" .. t .. "+1" .. newline() .. "for i=1, #"..var("a").." do" .. indent() .. t .. "["..var("p").."] = "..var("a").."[i]" .. newline() .. ""..var("p").." = "..var("p").." + 1" .. unindent() .. "end" .. unindent() .. "end"
|
||||
end
|
||||
|
||||
tags._opid.idiv = (left, right)
|
||||
return "math.floor(" .. lua(left) .. " / " .. lua(right) .. ")"
|
||||
end
|
||||
tags._opid.band = (left, right)
|
||||
return "bit32.band(" .. lua(left) .. ", " .. lua(right) .. ")"
|
||||
end
|
||||
tags._opid.bor = (left, right)
|
||||
return "bit32.bor(" .. lua(left) .. ", " .. lua(right) .. ")"
|
||||
end
|
||||
tags._opid.bxor = (left, right)
|
||||
return "bit32.bxor(" .. lua(left) .. ", " .. lua(right) .. ")"
|
||||
end
|
||||
tags._opid.shl = (left, right)
|
||||
return "bit32.lshift(" .. lua(left) .. ", " .. lua(right) .. ")"
|
||||
end
|
||||
tags._opid.shr = (left, right)
|
||||
return "bit32.rshift(" .. lua(left) .. ", " .. lua(right) .. ")"
|
||||
end
|
||||
tags._opid.bnot = (right)
|
||||
return "bit32.bnot(" .. lua(right) .. ")"
|
||||
end
|
||||
|
||||
#placeholder("patch")
|
||||
|
||||
#local patch = output
|
||||
#output = ""
|
||||
#import("compiler.lua53", { patch = patch, loadPackage = false })
|
||||
|
||||
return lua53
|
||||
|
|
@ -3,12 +3,14 @@ targetName = "Lua 5.3"
|
|||
-- Unsuported features
|
||||
tags.AttributeId = (t)
|
||||
if t[2] then
|
||||
error("target does not support variable attributes")
|
||||
error("target "..targetName.." does not support variable attributes")
|
||||
else
|
||||
return t[1]
|
||||
end
|
||||
end
|
||||
|
||||
#placeholder("patch")
|
||||
|
||||
#local patch = output
|
||||
#output = ""
|
||||
#import("compiler.lua54", { patch = patch, loadPackage = false })
|
||||
|
|
|
|||
|
|
@ -3,13 +3,7 @@ targetName = "LuaJIT"
|
|||
UNPACK = (list, i, j)
|
||||
return "unpack(" .. list .. (i and (", " .. i .. (j and (", " .. j) or "")) or "") .. ")"
|
||||
end
|
||||
APPEND = (t, toAppend)
|
||||
return "do" .. indent() .. "local "..var("a")..", "..var("p").." = { " .. toAppend .. " }, #" .. t .. "+1" .. newline() .. "for i=1, #"..var("a").." do" .. indent() .. t .. "["..var("p").."] = "..var("a").."[i]" .. newline() .. ""..var("p").." = "..var("p").." + 1" .. unindent() .. "end" .. unindent() .. "end"
|
||||
end
|
||||
|
||||
tags._opid.idiv = (left, right)
|
||||
return "math.floor(" .. lua(left) .. " / " .. lua(right) .. ")"
|
||||
end
|
||||
tags._opid.band = (left, right)
|
||||
addRequire("bit", "band", "band")
|
||||
return var("band") .. "(" .. lua(left) .. ", " .. lua(right) .. ")"
|
||||
|
|
@ -39,6 +33,6 @@ end
|
|||
|
||||
#local patch = output
|
||||
#output = ""
|
||||
#import("compiler.lua53", { patch = patch, loadPackage = false })
|
||||
#import("compiler.lua52", { patch = patch, loadPackage = false })
|
||||
|
||||
return lua53
|
||||
return lua52
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue