Closed liquidev closed 4 years ago
Maybe the intermediate structure idea isn't going to pass, but as a first effort the following can be done:
foreign
,ref object
finalizer handle everything.I'm also thinking about changing the syntax of foreign()
to be a lot more clean and readable:
wren.foreign("module"):
Greeter:
# regular procs would work as usual
greet
# * would declare a static proc
*newGreeter -> new
# ? would declare a getter
?greeting
# *? or ?* would declare a static getter
*?world
This would solve issues #4 and #10, which I'm unable to solve with the current DSL.
Why is it more readable? I always find things that are right below each other, with little to no column variation much easier to read. Consider this:
wren.foreign("module"):
Greeter:
greet
[new] newGreeter -> new
[get] greeting
[genStatic, get] world
versus the above example:
wren.foreign("module"):
Greeter:
greet
*newGreeter -> new
?greeting
*?world
As one can see, the sudden jumps between columns in the first example make reading harder. You don't see what's bound, you see how it's bound, and that doesn't aid readability (users should see what they bind first and foremost). It may seem more readable at first, but ultimately some limitations of Nim identifiers cannot be overcome (keywords are a PITA).
Fixed in 0.11.0.
Turns out generating code directly from the input AST passed to
foreign()
is very messy. Instead, an intermediate structure should be created first, and code should be generated using that.