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
|
<span class="hljs-comment">/**
* An example of Flix for syntax highlighting.
*/</span>
<span class="hljs-comment">// Here is a namespace.</span>
<span class="hljs-keyword">namespace</span> a.b.c {
<span class="hljs-comment">// Here are some literals.</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">b</span></span>: Bool = <span class="hljs-literal">true</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">c</span></span>: Char = <span class="hljs-string">'a'</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span></span>: Float = <span class="hljs-number">1.23</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">i</span></span>: Int = <span class="hljs-number">42</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">s</span></span>: Str = <span class="hljs-string">"string"</span>
<span class="hljs-comment">// Here are some relations.</span>
<span class="hljs-keyword">rel</span> LitStm(r: Str, c: Int)
<span class="hljs-keyword">rel</span> AddStm(r: Str, x: Str, y: Str)
<span class="hljs-keyword">rel</span> DivStm(r: Str, x: Str, y: Str)
<span class="hljs-comment">// Here is a lattice.</span>
<span class="hljs-keyword">lat</span> LocalVar(k: Str, v: Constant)
<span class="hljs-comment">// Here is an index.</span>
<span class="hljs-keyword">index</span> LitStm{{r}, {r, c}}
<span class="hljs-comment">// Here is an enum.</span>
<span class="hljs-keyword">enum</span> Constant {
<span class="hljs-keyword">case</span> Top,
<span class="hljs-keyword">case</span> Cst(Int),
<span class="hljs-keyword">case</span> Bot
}
<span class="hljs-comment">// Here is a function.</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">leq</span></span>(e1: Constant, e2: Constant): Bool = <span class="hljs-keyword">match</span> (e1, e2) <span class="hljs-keyword">with</span> {
<span class="hljs-keyword">case</span> (Constant.Bot, _) => <span class="hljs-literal">true</span>
<span class="hljs-keyword">case</span> (Constant.Cst(n1), Constant.Cst(n2)) => n1 == n2
<span class="hljs-keyword">case</span> (_, Constant.Top) => <span class="hljs-literal">true</span>
<span class="hljs-keyword">case</span> _ => <span class="hljs-literal">false</span>
}
<span class="hljs-comment">// Here are some rules.</span>
LocalVar(r, alpha(c)) :- LitStm(r, c).
LocalVar(r, sum(v1, v2)) :- AddStm(r, x, y),
LocalVar(x, v1),
LocalVar(y, v2).
}
|