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 to_str { | |
case { _ ($toks ...) } => { | |
return [makeValue(#{ $toks ... }.map(unwrapSyntax).join(''), #{ here })]; | |
} | |
} | |
to_str(1 2 3 4) | |
// '1234' |
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
function test1 { | |
Black(Red(Red(*, *, *), *, *), *, *) => 'balance-1', | |
Black(Red(*, *, Red(*, *, *)), *, *) => 'balance-2', | |
Black(*, *, Red(Red(*, *, *), *, *)) => 'balance-3', | |
Black(*, *, Red(*, *, Red(*, *, *))) => 'balance-4', | |
default => 'balanced' | |
} | |
function test2(tree) { | |
var res; |
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
function balance { | |
['black', ['red', ['red', *, *, *], *, *], *, *] => 'balance-1', | |
['black', ['red', *, *, ['red', *, *, *]], *, *] => 'balance-2', | |
['black', *, *, ['red', ['red', *, *, *], *, *]] => 'balance-3', | |
['black', *, *, ['red', *, *, ['red', *, *, *]]] => 'balance-4', | |
* => 'balanced' | |
} |
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
function balance { | |
Black(Red(Red(a, x, b), y, c), z, d) => Red(Black(a, x, b), y, Black(c, z, d)), | |
Black(Red(a, x, Red(b, y, c)), z, d) => Red(Black(a, x, b), y, Black(c, z, d)), | |
Black(a, x, Red(Red(b, y, c), z, d)) => Red(Black(a, x, b), y, Black(c, z, d)), | |
Black(a, x, Red(b, y, Red(c, z, d))) => Red(Black(a, x, b), y, Black(c, z, d)), | |
t => t | |
} |
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
function test1 { | |
(*, false, true ) => 1, | |
(false, true, * ) => 2, | |
(*, *, false) => 3, | |
(*, *, true ) => 4 | |
} | |
function test2 { | |
(1, { a: 1, b: 2 }) => 1, | |
(*, { a: 1, b: 2 }) => 2 |
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 .. { | |
rule infix { $lhs:expr | $name:ident () } => { | |
$lhs.$name.bind($lhs) | |
} | |
} | |
var a = foo..bar(); |
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 withSyntax_unzip { | |
case { _ $name ($ps ...) ($es ...) ($p = $e:expr , $rest ...) $body } => { | |
return #{ | |
withSyntax_unzip $name ($ps ... ($p)) ($es ... ($e)) ($rest ...) $body | |
} | |
} | |
case { _ $name ($ps ...) ($es ...) ($p = $e:expr) $body } => { | |
return #{ | |
withSyntax_unzip $name ($ps ... ($p)) ($es ... ($e)) () $body | |
} |
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
let let = macro { | |
case { $mac syntax $id:ident $punc = $rhs:expr } => { | |
var mac = #{ $mac }; | |
var id = #{ $id }; | |
var val = #{ $val }; | |
var arg = #{ $($rhs) }; | |
var punc = #{ $punc }; | |
if (punc[0].token.type !== parser.Token.Punctuator || | |
punc[0].token.value !== '...') { |
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
Unoptimized: | |
var r0$689 = Object.prototype.toString; | |
var r6$690 = '[object Array]'; | |
var r12$691 = arguments[0]; | |
if (r0$689.call(r12$691) === r6$690) { | |
if (r12$691.length >= 1) { | |
Optimized: | |
var r0$689 = Object.prototype.toString; | |
var r6$690 = '[object Array]'; |
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 $opt { | |
case { $mac () } => { | |
var mac = #{ $mac }; | |
var a = makeIdent('a', mac); | |
var b = makeIdent('b', mac); | |
var code1 = withSyntax($a = [a], $b = [b]) { | |
return #{ | |
{ | |
if (b == 2) { |