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
#!/bin/bash | |
#usage: ./require.sh <root_dir> <main_file> [<output_file>] | |
cd $1 | |
ftype=`echo $2 | awk -F . '{print $NF}'` | |
files="" | |
function parsedeps { | |
files="$1 $files" | |
deps=`egrep '^(#|//|/\*)= require .*$' $1 | awk "{print \\$3 \".$ftype\"}" | tail -r` | |
for dep in $deps; do parsedeps $dep; done | |
} |
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
{data, any, only} = require 'adt' | |
# List definition using `any`. While we can restrict the tail to be a only List types, | |
# we can't restrict the head to be a specific type. | |
List = data -> | |
Nil: null | |
Cons: | |
head: any | |
tail: only this | |
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 $testadd { | |
case { $$mac $expr } => { | |
var ident = makeIdent('test', #{ $$mac }); | |
return withSyntax ($ident = [ident]) { | |
return #{ | |
return $expr + $ident; | |
} | |
} | |
} | |
} |
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) { |
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
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
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
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
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
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 | |
} |
OlderNewer