1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2025-10-27 09:59:29 +00:00

Add constexpr and __STR__ default macros

This commit is contained in:
Étienne Fildadut 2021-06-11 14:17:55 +02:00
parent 496a4ddafd
commit ea54376aa6
3 changed files with 736 additions and 287 deletions

View file

@ -1,5 +1,6 @@
#import("candran.util")
#import("candran.cmdline")
#import("candran.serpent")
#import("compiler.lua54")
#import("compiler.lua53")
@ -176,6 +177,14 @@ function candran.preprocess(input, options={})
end
end
-- default macros
-- TODO make it optional
env.define("__STR__(x)", function(x) return ("%q"):format(x) end)
local s = require("candran.serpent")
env.define("constexpr(expr)", function(expr)
return s.block(assert(candran.load(expr))(), {fatal = true})
end)
-- compile & load preprocessor
local preprocess, err = candran.compile(preprocessor, options)
if not preprocess then