Created
February 8, 2019 22:27
-
-
Save elliottslaughter/35f2bf7fc0183c109fe07546f1dd55ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct st {} | |
local iseven = terralib.overloadedfunction("iseven") | |
local isodd = terralib.overloadedfunction("isodd") | |
terra iseven_int :: {st, int} -> bool | |
terra isodd_int :: {st, int} -> bool | |
iseven:adddefinition(iseven_int) | |
isodd:adddefinition(isodd_int) | |
terra iseven_int(self : st, x : int) | |
if x == 0 then | |
return true | |
else | |
return not isodd(self, x - 1) | |
end | |
end | |
terra isodd_int(self : st, x : int) | |
if x == 0 then | |
return true | |
else | |
return not iseven(self, x - 1) | |
end | |
end | |
st.metamethods.__methodmissing = macro(function(method_name, obj, ...) | |
local args = terralib.newlist({...}) | |
if method_name == "iseven" then | |
return `iseven(obj, args) | |
elseif method_name == "isodd" then | |
return `isodd(obj, args) | |
end | |
end) | |
terra main() | |
var x = st {} | |
x:iseven(1) | |
end | |
main:printpretty(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local iseven = terralib.overloadedfunction("iseven") | |
local isodd = terralib.overloadedfunction("isodd") | |
iseven:adddefinition( | |
terra(x : int) | |
if x == 0 then | |
return true | |
else | |
return not isodd(x - 1) | |
end | |
end) | |
isodd:adddefinition( | |
terra(x : int) | |
if x == 0 then | |
return true | |
else | |
return not iseven(x - 1) | |
end | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local iseven = terralib.overloadedfunction("iseven") | |
local isodd = terralib.overloadedfunction("isodd") | |
terra iseven_int :: int -> bool | |
terra isodd_int :: int -> bool | |
iseven:adddefinition(iseven_int) | |
isodd:adddefinition(isodd_int) | |
terra iseven_int(x : int) | |
if x == 0 then | |
return true | |
else | |
return not isodd(x - 1) | |
end | |
end | |
terra isodd_int(x : int) | |
if x == 0 then | |
return true | |
else | |
return not iseven(x - 1) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terra iseven(x : int) | |
if x == 0 then | |
return true | |
else | |
return not isodd(x - 1) | |
end | |
end | |
terra isodd(x : int) | |
if x == 0 then | |
return false | |
else | |
return not iseven(x - 1) | |
end | |
end | |
terra main() | |
iseven(5) | |
end | |
main:compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terra iseven(x : int) : bool | |
if x == 0 then | |
return true | |
else | |
return not isodd(x - 1) | |
end | |
end | |
terra isodd(x : int) : bool | |
if x == 0 then | |
return false | |
else | |
return not iseven(x - 1) | |
end | |
end | |
terra main() | |
iseven(5) | |
end | |
main:compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct st {} | |
terra st:iseven(x : int) | |
if x == 0 then | |
return true | |
else | |
return not self:isodd(x - 1) | |
end | |
end | |
terra st:isodd(x : int) | |
if x == 0 then | |
return false | |
else | |
return not self:iseven(x - 1) | |
end | |
end | |
terra main() | |
var x = st {} | |
x:iseven(5) | |
end | |
main:compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct st {} | |
terra st:iseven(x : int) : bool | |
if x == 0 then | |
return true | |
else | |
return not self:isodd(x - 1) | |
end | |
end | |
terra st:isodd(x : int) : bool | |
if x == 0 then | |
return false | |
else | |
return not self:iseven(x - 1) | |
end | |
end | |
terra main() | |
var x = st {} | |
x:iseven(5) | |
end | |
main:compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct st {} | |
terra st:iseven :: int -> bool | |
-- terra st:isodd :: int -> bool | |
-- terra st:iseven(x : int) | |
-- if x == 0 then | |
-- return true | |
-- else | |
-- return not self:isodd(x - 1) | |
-- end | |
-- end | |
-- terra st:isodd(x : int) | |
-- if x == 0 then | |
-- return false | |
-- else | |
-- return not self:iseven(x - 1) | |
-- end | |
-- end | |
-- terra main() | |
-- var x = st {} | |
-- x:iseven(5) | |
-- end | |
-- main:compile() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment