Created
October 16, 2012 21:19
-
-
Save disnet/3902112 to your computer and use it in GitHub Desktop.
parameter annotations (type, contract, etc.) in sweet.js
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
macro def { | |
case $name:ident ( $($params:ident : $type:ident) (,) ...) $body => { | |
// just throwing away the type annotation. The semantics of type | |
// annotations left as an exercise to the reader :) | |
function $name ($params (,) ...) $body | |
} | |
} | |
def add (a : Number, b : Number) { | |
return a + b; | |
} | |
add(1,2) |
For closure compiler annotations, the macro needs the ability to output a comment. Currently, it seems that the literal comment is interpreted as a comment by sjs and thus not output. Is there a workaround for this?
It'd be nice if this could be used to write pretty asm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that making annotations optional are currently hampered by a bug, though there might be some clever workaround.