1
0
Fork 0
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:
Étienne Fildadut 2020-12-24 17:25:28 +01:00
parent bf4cadc349
commit 7e4b46ba7d
6 changed files with 1359 additions and 279 deletions

View file

@ -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
View 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

View file

@ -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 })

View file

@ -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