<html><head><style type="text/css">body{background-color:#202020;}pre {font-family: "Bitstream Vera Sans Mono", monospace; font-size: 13px;}.err{color:#;}.comm{color:#678;}.ident{color:#D0D0D0;}.str{color:#ED9D13;}.int{color:#3677A9;}.float{color:#235741;}.unop{color:#009799;}.binop{color:#F92672;}.delim{color:#D0D0D0;}.kwd{color:#6AB825;}</style></head><body><table class="code_listing" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="listing_lines" align="right"><pre style="color:#777;display:block;margin:0;padding-right:25px;text-align:right;white-space:pre;width:25px;"> 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 </pre> </td> <td class="listing_code"> <pre><span class="kwd">extern</span> <span class="kwd">Fn</span> <span class="ident">malloc</span> <span class="ident">int</span> <span class="kwd">-></span> <span class="ident">void</span><span class="unop">'</span>
<span class="kwd">extern</span> <span class="kwd">Fn</span> <span class="ident">free</span> <span class="ident">void</span><span class="unop">'</span> <span class="kwd">-></span> <span class="ident">void</span>
<span class="kwd">extern</span> <span class="kwd">Fn</span> <span class="ident">realloc</span> <span class="ident">void</span><span class="unop">'</span> <span class="ident">uint</span> <span class="kwd">-></span> <span class="ident">void</span><span class="unop">'</span>
<span class="kwd">extern</span> <span class="kwd">Fn</span> <span class="ident">calloc</span> <span class="ident">uint</span> <span class="ident">uint</span> <span class="kwd">-></span> <span class="ident">void</span><span class="unop">'</span>
<span class="kwd">extern</span> <span class="kwd">Fn</span> <span class="ident">recalloc</span> <span class="ident">void</span><span class="unop">'</span> <span class="ident">uint</span> <span class="ident">uint</span> <span class="kwd">-></span> <span class="ident">void</span><span class="unop">'</span>
<span class="kwd">extern</span> <span class="kwd">Fn</span> <span class="ident">puts</span> <span class="ident">str</span> <span class="kwd">-></span> <span class="ident">int</span>
<span class="comm">;extern Fn itoa int str int -> str</span>
<span class="kwd">fn</span> <span class="ident">fac2</span> <span class="ident">n</span><span class="kwd">:</span><span class="ident">int</span> <span class="kwd">-></span> <span class="ident">int</span> <span class="binop">=</span> <span class="kwd">if</span><span class="delim">(</span><span class="ident">n</span> <span class="binop"><=</span> <span class="int">1</span><span class="delim">)</span> <span class="int">1</span> <span class="kwd">fi</span> <span class="ident">fac</span> <span class="ident">n</span><span class="binop">-</span><span class="int">1</span> <span class="binop">*</span> <span class="ident">n</span>
<span class="kwd">fn</span> <span class="ident">f</span> <span class="binop">=</span> <span class="int">0</span>
<span class="kwd">fn</span> <span class="ident">fff</span> <span class="binop">=</span> <span class="ident">f</span>
<span class="kwd">fn</span> <span class="ident">fac</span> <span class="ident">n</span><span class="kwd">:</span><span class="ident">int</span> <span class="kwd">-></span> <span class="ident">int</span> <span class="binop">=</span> <span class="kwd">if</span><span class="delim">(</span><span class="delim">(</span><span class="ident">fff</span><span class="delim">(</span><span class="delim">)</span><span class="delim">(</span><span class="delim">)</span><span class="delim">)</span><span class="delim">;</span> <span class="ident">n</span> <span class="binop"><=</span> <span class="int">1</span><span class="delim">)</span> <span class="kwd">ret</span> <span class="int">1</span> <span class="kwd">fi</span> <span class="kwd">ret</span> <span class="ident">fac2</span> <span class="ident">n</span><span class="binop">-</span><span class="int">1</span> <span class="binop">*</span> <span class="ident">n</span>
<span class="kwd">fn</span> <span class="ident">caf</span> <span class="ident">n</span><span class="kwd">:</span><span class="ident">int</span> <span class="kwd">-></span> <span class="ident">int</span> <span class="binop">=</span> <span class="kwd">if</span><span class="delim">(</span><span class="unop">-</span><span class="int">1</span> <span class="binop"><=</span> <span class="ident">n</span><span class="delim">)</span> <span class="kwd">ret</span> <span class="int">1</span> <span class="kwd">fi</span> <span class="kwd">ret</span> <span class="ident">caf</span> <span class="ident">n</span><span class="binop">+</span><span class="int">1</span> <span class="binop">*</span> <span class="ident">n</span>
<span class="kwd">fn</span> <span class="ident">get-fac</span> <span class="ident">b</span><span class="kwd">:</span><span class="ident">bool</span> <span class="binop">=</span> <span class="kwd">if</span><span class="delim">(</span><span class="ident">b</span><span class="delim">)</span> <span class="kwd">ret</span> <span class="ident">fac</span> <span class="kwd">fi</span> <span class="kwd">ret</span> <span class="ident">caf</span> <span class="comm">;-> Fn int -> int</span>
<span class="comm">; fn main = argc:int argv:str'</span>
<span class="kwd">rec</span> <span class="ident">vec</span>
<span class="ident">x</span><span class="kwd">:</span> <span class="ident">float</span>
<span class="ident">y</span><span class="kwd">:</span> <span class="ident">float</span>
<span class="kwd">fn</span> <span class="ident">main</span> <span class="ident">argc</span><span class="kwd">:</span><span class="ident">int</span> <span class="ident">argv</span><span class="kwd">:</span><span class="ident">str</span><span class="unop">'</span>
<span class="ident">v</span><span class="kwd">:</span> <span class="ident">vec</span>
<span class="ident">aa</span><span class="kwd">:</span> <span class="ident">char</span><span class="binop">'</span><span class="int">30</span>
<span class="ident">a</span><span class="kwd">:</span> <span class="ident">char</span><span class="unop">'</span>
<span class="ident">a</span> <span class="binop">=</span> <span class="unop">&</span><span class="delim">(</span><span class="ident">aa</span><span class="binop">'</span><span class="delim">(</span><span class="ident">f</span><span class="delim">(</span><span class="delim">)</span><span class="delim">)</span><span class="delim">)</span>
<span class="ident">a</span> <span class="binop">=</span> <span class="ident">aa</span>
<span class="ident">b</span> <span class="kwd">:=</span> <span class="int">5</span>
<span class="ident">bb</span> <span class="kwd">:=</span> <span class="str">"hello"</span>
<span class="ident">c</span> <span class="kwd">:=</span> <span class="ident">a</span><span class="binop">'</span><span class="int">13</span>
<span class="ident">d</span> <span class="kwd">:=</span> <span class="ident">bb</span><span class="unop">'</span>
<span class="ident">e</span> <span class="kwd">:=</span> <span class="str">"f"</span><span class="unop">'</span>
<span class="ident">argc</span> <span class="binop">=</span> <span class="int">6</span>
<span class="ident">aa</span><span class="binop">'</span><span class="int">0</span> <span class="binop">=</span> <span class="str">"h"</span><span class="binop">'</span><span class="int">0</span>
<span class="ident">aa</span><span class="binop">'</span><span class="int">1</span> <span class="binop">=</span> <span class="ident">bb</span><span class="binop">'</span><span class="int">1</span>
<span class="ident">aa</span><span class="binop">'</span><span class="int">2</span> <span class="binop">=</span> <span class="str">"\0"</span><span class="unop">'</span>
<span class="ident">g</span> <span class="kwd">:=</span> <span class="float">3.0e-50</span>
<span class="kwd">if</span><span class="delim">(</span><span class="int">1</span> <span class="binop"><</span> <span class="int">2</span> <span class="binop">and</span> <span class="int">2</span> <span class="binop">></span> <span class="int">3</span><span class="delim">)</span> <span class="ident">puts</span> <span class="ident">aa</span>
<span class="kwd">fi</span> <span class="ident">puts</span> <span class="ident">bb</span>
<span class="ident">itoa</span> <span class="unop">-</span><span class="delim">(</span><span class="delim">(</span><span class="ident">get-fac</span> <span class="kwd">true</span><span class="delim">)</span> <span class="int">14</span><span class="delim">)</span> <span class="ident">a</span> <span class="int">12</span> <span class="int">10</span>
<span class="ident">puts</span> <span class="ident">a</span>
<span class="comm">; puts (itoa 42 a -10)</span>
<span class="ident">puts</span> <span class="ident">argv</span><span class="binop">'</span><span class="int">0</span>
<span class="ident">b</span> <span class="binop">=</span> <span class="int">3</span>
<span class="ident">itoa</span> <span class="ident">b</span> <span class="ident">a</span> <span class="int">30</span> <span class="int">10</span>
<span class="ident">puts</span> <span class="ident">a</span>
<span class="ident">b</span><span class="unop">+</span> <span class="binop">=</span> <span class="int">5</span>
<span class="ident">itoa</span> <span class="ident">b</span> <span class="ident">a</span> <span class="int">30</span> <span class="int">10</span>
<span class="ident">puts</span> <span class="ident">a</span>
<span class="comm">;a2: int = 1</span>
<span class="comm">;p: char'</span>
<span class="ident">p</span> <span class="kwd">:=</span> <span class="ident">malloc</span> <span class="int">1024</span>
<span class="ident">free</span> <span class="ident">p</span>
<span class="kwd">fn</span> <span class="ident">itoa</span> <span class="ident">value</span><span class="kwd">:</span><span class="ident">int</span> <span class="ident">result</span><span class="kwd">:</span><span class="ident">str</span> <span class="ident">size</span><span class="kwd">:</span><span class="ident">int</span> <span class="ident">base</span><span class="kwd">:</span><span class="ident">int</span> <span class="kwd">-></span> <span class="ident">bool</span> <span class="unop">=</span>
<span class="comm">; check that the base if valid</span>
<span class="kwd">if</span> <span class="ident">base</span> <span class="binop"><</span> <span class="int">2</span> <span class="binop">or</span> <span class="ident">base</span> <span class="binop">></span> <span class="int">36</span>
<span class="ident">result</span><span class="unop">'</span> <span class="binop">=</span> <span class="str">"\0"</span><span class="unop">'</span>
<span class="kwd">ret</span> <span class="kwd">false</span>
<span class="ident">ptr</span> <span class="kwd">:=</span> <span class="ident">result</span>
<span class="ident">neg</span> <span class="kwd">:=</span> <span class="ident">value</span> <span class="binop"><</span> <span class="int">0</span>
<span class="kwd">if</span><span class="delim">(</span><span class="ident">neg</span><span class="delim">)</span> <span class="ident">value</span> <span class="binop">=</span> <span class="unop">-</span><span class="ident">value</span>
<span class="kwd">while</span>
<span class="kwd">if</span> <span class="ident">ptr</span> <span class="binop">>=</span> <span class="ident">result</span> <span class="binop">+</span> <span class="ident">size</span> <span class="binop">-</span> <span class="int">1</span>
<span class="ident">result</span><span class="unop">'</span> <span class="binop">=</span> <span class="str">"\0"</span><span class="unop">'</span>
<span class="kwd">ret</span> <span class="kwd">false</span>
<span class="ident">ptr</span><span class="unop">'</span> <span class="binop">=</span> <span class="str">"0123456789abcdefghijklmnopqrstuvwxyz"</span> <span class="binop">'</span> <span class="ident">value</span><span class="binop">%</span><span class="ident">base</span>
<span class="ident">value</span> <span class="binop">=</span> <span class="ident">value</span> <span class="binop">/</span> <span class="ident">base</span>
<span class="ident">ptr</span><span class="unop">+</span>
<span class="ident">value</span> <span class="binop">!=</span> <span class="int">0</span>
<span class="kwd">if</span> <span class="ident">neg</span> <span class="binop">and</span> <span class="ident">base</span> <span class="binop">==</span> <span class="int">10</span>
<span class="kwd">if</span> <span class="ident">ptr</span> <span class="binop">>=</span> <span class="ident">result</span> <span class="binop">+</span> <span class="ident">size</span> <span class="binop">-</span> <span class="int">1</span>
<span class="ident">result</span><span class="unop">'</span> <span class="binop">=</span> <span class="str">"\0"</span><span class="unop">'</span>
<span class="kwd">ret</span> <span class="kwd">false</span>
<span class="ident">ptr</span><span class="unop">'</span> <span class="binop">=</span> <span class="str">"-"</span><span class="unop">'</span>
<span class="ident">ptr</span><span class="unop">+</span>
<span class="ident">ptr</span><span class="unop">'</span> <span class="binop">=</span> <span class="str">"\0"</span><span class="unop">'</span>
<span class="ident">ptr</span><span class="unop">-</span>
<span class="ident">ptr1</span> <span class="kwd">:=</span> <span class="ident">result</span>
<span class="kwd">while</span> <span class="ident">ptr1</span> <span class="binop"><</span> <span class="ident">ptr</span>
<span class="ident">tmp-char</span> <span class="kwd">:=</span> <span class="ident">ptr</span><span class="unop">'</span>
<span class="ident">ptr</span><span class="unop">'</span> <span class="binop">=</span> <span class="ident">ptr1</span><span class="unop">'</span>
<span class="ident">ptr1</span><span class="unop">'</span> <span class="binop">=</span> <span class="ident">tmp-char</span>
<span class="ident">ptr1</span><span class="unop">+</span>
<span class="ident">ptr</span><span class="unop">-</span>
<span class="kwd">true</span>
<span class="comm">; fn fft data:double' nn:uint</span>
<span class="comm">; ; reverse-binary reindexing</span>
<span class="comm">; n := ulong nn<1</span>
<span class="comm">; for (i,j) := (1,1); i < n; i =+ 2</span>
<span class="comm">; if j > i</span>
<span class="comm">; swap data'(j - 1) data'(i - 1)</span>
<span class="comm">; swap data'j data'i</span>
<span class="comm">; m := nn</span>
<span class="comm">; while m >= 2 and j > m</span>
<span class="comm">; j =- m</span>
<span class="comm">; m =>> 1</span>
<span class="comm">; j =+ m</span>
<span class="comm">; ; here begins the Danielson-Lanczos section</span>
<span class="comm">; mx := 2</span>
<span class="comm">; while n > mx</span>
<span class="comm">; istep := mx << 1</span>
<span class="comm">; theta := -2 * PI / mx</span>
<span class="comm">; wtemp := sin 0.5*theta</span>
<span class="comm">; wpr := -2.0 * wtemp^2</span>
<span class="comm">; wpi := sin theta</span>
<span class="comm">; wr := 1.0</span>
<span class="comm">; wi := 0</span>
<span class="comm">; for m := 1; m < mx; m =+ 2</span>
<span class="comm">; for i := m; i <= n; i =+ istep</span>
<span class="comm">; j := i + mx</span>
<span class="comm">; tempr := wr * data'(j-1) - wi * data'j</span>
<span class="comm">; tempi := wr * data'j + wi * data'(j-1)</span>
<span class="comm">; data'(j-1) = data'(i-1) - tempr</span>
<span class="comm">; data'j = data'i - tempi</span>
<span class="comm">; data'(i-1) =+ tempr</span>
<span class="comm">; data'i =+ tempi</span>
<span class="comm">; wtemp = wr</span>
<span class="comm">; wr =+ wr * wpr - wr * wpi</span>
<span class="comm">; wi =+ wi * wpr + wtemp * wpi</span>
<span class="comm">; mx = istep</span>
<span class="comm">; [T] fn swap mod a:T mod b:T</span>
<span class="comm">; tmp := a</span>
<span class="comm">; a = b</span>
; b = tmp</pre></body></html>