chneukirchen / yam

Yam, a functional language running as JavaScript

This URL has Read+Write access

yam / test-compiler.js
100644 74 lines (50 sloc) 1.384 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
load('knock.js')
 
load('comp.js')
 
function p_ast(s) {
  var a = CompilationUnit(ps(s)).ast
  diag(a.toSource())
}
 
function compiles(s) {
  try {
    compile(s)
    return true
  } catch(e) {
    ok(0, e)
  }
}
 
 
ok(compiles("a b c"))
 
ok(compiles("a + b + c"))
 
ok(compiles("let a = b in c a"))
 
ok(compiles("let | a = b | b = a in c a"))
 
ok(compiles('fn x -> x + x'))
 
ok(compiles('fn x y -> y + x'))
 
ok(compiles('let pair x y = (x,y) in pair 1 2'))
 
ok(compiles('Cons (a,b)'))
 
ok(compiles('fn | 0 -> 1 | 1 -> 0'))
 
ok(compiles('fn | 0 0 -> 1\
| 0 1 -> 0\
| 1 0 -> 0\
| 1 1 -> 1\
'))
 
ok(compiles('fn | Pair(x,y) -> x | _ -> _'))
ok(compiles('fn | Pair(Pair(x,z),y) -> x | _ -> _'))
 
ok(compiles("fn | x y if x == y -> 1 | _ _ -> 0"))
 
ok(compiles("module z let a = b end"))
 
ok(compiles("module let a = b end"))
 
ok(compiles("a; b a; c"))
 
ok(compiles( "infixl * 6 "
             + "infixl / 6 "
             + "infixl + 7 "
             + "infixl - 7 "
             + "a + b * c"))
ok(compiles( "infixl * 7 "
             + "infixl / 7 "
             + "infixl + 6 "
             + "infixl - 6 "
             + "a + b * c"))
ok(compiles("a.1.A"))
 
ok(compiles("{% print(foo) %} "))
 
ok(compiles("{a: 1, b: 2+2}"))
ok(compiles("{A: 1, 4: 2+2}"))
 
ok(compiles("module let a = 9 end"))
ok(compiles("module z let a = 9 end"))