Mercurial > emacs
annotate test/indent/prolog.prolog @ 110563:5b5c2cab9a6a
Merge changes made in Gnus.tranck
gnus-art.el: Remove useless gnus-treat-translate.
gnus-gravatar.el (gnus-gravatar-transform-address): Use gnus-gravatar-size.
gnus.el: Remove useless gnus-local-domain.
mml-smime.el: Remove useless mml-smime-verbose.
mml2015.el: Remove useless mml2015-verbose.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Sat, 25 Sep 2010 12:49:02 +0000 |
parents | f81447dd641c |
children | 7e39a17684f8 |
rev | line source |
---|---|
108864
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 %% -*- mode: prolog; coding: utf-8 -*- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
3 %% wf(+E) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
4 %% Vérifie que E est une expression syntaxiquement correcte. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 wf(X) :- atom(X); integer(X); var(X). %Une variable ou un entier. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 wf(lambda(X, T, B)) :- atom(X), wf(T), wf(B). %Une fonction. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 wf(app(E1, E2)) :- wf(E1), wf(E2). %Un appel de fonction. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 wf(pi(X, T, B)) :- atom(X), wf(T), wf(B). %Le type d'une fonction. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 %% Éléments additionnels utilisés dans le langage source. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11 wf(lambda(X, B)) :- atom(X), wf(B). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 wf(let(X, E1, E2)) :- atom(X), wf(E1), wf(E2). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 wf(let(X, T, E1, E2)) :- atom(X), wf(T), wf(E1), wf(E2). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 wf((T1 -> T2)) :- wf(T1), wf(T2). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 wf(forall(X, T, B)) :- atom(X), wf(T), wf(B). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16 wf(fix(X,T,E1,E2)) :- atom(X), wf(T), wf(E1), wf(E2). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 wf(fix(X,E1,E2)) :- atom(X), wf(E1), wf(E2). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 wf(app(E1,E2,E3)) :- wf(E1), wf(E2), wf(E3). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 wf(app(E1,E2,E3,E4)) :- wf(E1), wf(E2), wf(E3), wf(E4). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 %% subst(+X, +V, +FV, +Ei, -Eo) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 %% Remplace X par V dans Ei. Les variables qui apparaissent libres dans |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 %% V et peuvent aussi apparaître dans Ei doivent toutes être inclues |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 %% dans l'environnement FV. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 subst(X, V, _, X, E) :- !, E = V. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 subst(_, _, _, Y, Y) :- atom(Y); integer(Y). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 %% Residualize the substitution when applied to an uninstantiated variable. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 %% subst(X, V, _, Y, app(lambda(X,_,Y),V)) :- var(Y). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 %% Rather than residualize and leave us with unifications that fail, let's |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 %% rather assume that Y will not refer to X. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 subst(X, V, _, Y, Y) :- var(Y). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 subst(X, V, FV, lambda(Y, Ti, Bi), lambda(Y1, To, Bo)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 subst(X, V, FV, Ti, To), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 (X = Y -> |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 %% If X is equal to Y, X is shadowed, so no subst can take place. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 Y1 = Y, Bo = Bi; |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 (member((Y, _), FV) -> |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 %% If Y appears in FV, it can appear in V, so we need to |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 %% rename it to avoid name capture. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 new_atom(Y, Y1), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 subst(Y, Y1, [], Bi, Bi1); |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 Y1 = Y, Bi1 = Bi), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 %% Perform substitution on the body. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 subst(X, V, FV, Bi1, Bo)). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 subst(X, V, FV, pi(Y, Ti, Bi), pi(Y1, To, Bo)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 subst(X, V, FV, lambda(Y, Ti, Bi), lambda(Y1, To, Bo)). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 subst(X, V, FV, forall(Y, Ti, Bi), forall(Y1, To, Bo)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 subst(X, V, FV, lambda(Y, Ti, Bi), lambda(Y1, To, Bo)). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 subst(X, V, FV, app(E1i, E2i), app(E1o, E2o)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 subst(X, V, FV, E1i, E1o), subst(X, V, FV, E2i, E2o). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 %% apply(+F, +Arg, +Env, -E) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 apply(lambda(X, _, B), Arg, Env, E) :- \+ var(B), subst(X, Arg, Env, B, E). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 apply(app(plus, N1), N2, _, N) :- integer(N1), integer(N2), N is N1 + N2. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 apply(app(minus, N1), N2, _, N) :- integer(N1), integer(N2), N is N1 - N2. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 %% normalize(+E1, +Env, -E2) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 %% Applique toutes les réductions possibles sur E1. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 normalize(X, _, X) :- integer(X); var(X); atom(X). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 %% normalize(X, Env, E) :- atom(X), member((X, E), Env). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 normalize(lambda(X, T, B), Env, lambda(X, Tn, Bn)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 normalize(T, [(X,T)|Env], Tn), normalize(B, [(X,T)|Env], Bn). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 normalize(pi(X, T, B), Env, pi(X, Tn, Bn)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 normalize(T, [(X,T)|Env], Tn), normalize(B, [(X,T)|Env], Bn). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 normalize(forall(X, T, B), Env, forall(X, Tn, Bn)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 normalize(T, [(X,T)|Env], Tn), normalize(B, [(X,T)|Env], Bn). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 normalize(app(E1, E2), Env, En) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 normalize(E1, Env, E1n), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 normalize(E2, Env, E2n), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 (apply(E1n, E2n, Env, E) -> |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 normalize(E, Env, En); |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 En = app(E1n, E2n)). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 %% infer(+E, +Env, -T) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 %% Infère le type de E dans Env. On essaie d'être permissif, dans le sens |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 %% que l'on présume que l'expression est typée correctement. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 infer(X, _, int) :- integer(X). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 infer(X, _, _) :- var(X). %Une expression encore inconnue. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 infer(X, Env, T) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 atom(X), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 (member((X, T1), Env) -> |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 %% X est déjà dans Env: vérifie que le type est correct. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 T = T1; |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 %% X est une variable libre. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 true). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 infer(lambda(X,T,B), Env, pi(Y,T,TB)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88 infer(B, [(X,T)|Env], TBx), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 (var(Y) -> |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 Y = X, TB = TBx; |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 subst(X, Y, Env, TBx, TB)). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 infer(app(E1, E2), Env, Tn) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93 infer(E1, Env, T1), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 (T1 = pi(X,T2,B); T1 = forall(X,T2,B)), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 infer(E2, Env, T2), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 subst(X, E2, Env, B, T), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 normalize(T, Env, Tn). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 infer(pi(X,T1,T2), Env, type) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 infer(T1, Env, type), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 infer(T2, [(X,T1)|Env], type). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 infer(forall(X,T1,T2), Env, type) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 infer(T1, Env, type), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 infer(T2, [(X,T1)|Env], type). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 %% freevars(+E, +Env, -Vs) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 %% Renvoie les variables libres de E. Vs est une liste associative |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 %% où chaque élément est de la forme (X,T) où X est une variable et T est |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 %% son type. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 freevars(X, _, []) :- integer(X). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 freevars(X, Env, Vs) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 atom(X), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 (member((X,_), Env) -> |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 %% Variable liée. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 Vs = []; |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 %% Variable libre. Type inconnu :-( |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116 Vs = [(X,_)]). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 %% Les variables non-instanciées peuvent être remplacées par des paramètres |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 %% qui seront liés par `closetype' selon le principe de Hindley-Milner. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 freevars(X, _, [(X, _)]) :- var(X), new_atom(X). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
120 freevars(app(E1, E2), Env, Vs) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 freevars(E1, Env, Vs1), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 append(Vs1, Env, Env1), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 freevars(E2, Env1, Vs2), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 append(Vs1, Vs2, Vs). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 freevars(lambda(X, T, B), Env, Vs) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 freevars(T, Env, TVs), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 append(TVs, Env, Env1), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 freevars(B, [(X,T)|Env1], BVs), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 append(TVs, BVs, Vs). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
130 freevars(pi(X, T, B), Env, Vs) :- freevars(lambda(X, T, B), Env, Vs). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 freevars(forall(X, T, B), Env, Vs) :- freevars(lambda(X, T, B), Env, Vs). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
132 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
133 %% close(+Eo, +To, +Vs, -Ec, -Tc) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 %% Ferme un type ouvert To en liant chaque variable libre (listées dans Vs) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
135 %% avec `forall'. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
136 closetype(E, T, [], E, T). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
137 closetype(Eo, To, [(X,T)|Vs], lambda(X, T, Ec), forall(X, T, Tc)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
138 closetype(Eo, To, Vs, Ec, Tc). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
139 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
140 %% elab_type(+Ee, +Te, +Env, -Eg, -Tg) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
141 %% Ajoute les arguments implicites de E:T. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
142 generalize(Ee, Te, Env, Eg, Tg) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
143 freevars(Te, Env, Vs), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
144 append(Vs, Env, EnvX), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145 %% Essaie d'instancier les types des paramètres que `generalize' vient |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
146 %% d'ajouter. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147 infer(Te, EnvX, type), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
148 closetype(Ee, Te, Vs, Eg, Tg). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
149 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
150 %% instantiate(+X, +T, -E) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
151 %% Utilise la variable X de type T. Le résultat E est X auquel on ajoute |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
152 %% tous les arguments implicites (de valeur inconnue). |
110446
f81447dd641c
* lisp/progmodes/prolog.el (prolog-smie-forward-token)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108864
diff
changeset
|
153 instantiate(X, T, X) :- var(T), !. |
108864
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
154 instantiate(X, forall(_, _, T), app(E, _)) :- !, instantiate(X, T, E). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
155 instantiate(X, _, X). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
156 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
157 %% elaborate(+E1, +Env, -E2) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
158 %% Transforme E1 en une expression E2 où le sucre syntaxique a été éliminé |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 %% et où les arguments implicites ont été rendus explicites. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
160 elaborate(X, _, X) :- integer(X); var(X). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
161 elaborate(X, Env, E) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 atom(X), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
163 (member((X, T), Env) -> |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
164 instantiate(X, T, E); |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
165 %% Si X n'est pas dans l'environnement, c'est une variable libre que |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
166 %% l'on voudra probablement généraliser. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
167 X = E). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
168 elaborate(lambda(X, T, B), Env, lambda(X, Te, Be)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
169 elaborate(T, Env, Te), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
170 elaborate(B, [(X,Te)|Env], Be). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
171 elaborate(pi(X, T, B), Env, pi(X, Te, Be)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
172 elaborate(T, Env, Te), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
173 elaborate(B, [(X,Te)|Env], Be). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
174 elaborate(app(E1, E2), Env, app(E1e, E2e)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
175 elaborate(E1, Env, E1e), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
176 elaborate(E2, Env, E2e). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
177 elaborate(let(X, T, E1, E2), Env, app(lambda(X, Tg, E2e), E1g)) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
178 elaborate(E1, Env, E1e), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
179 elaborate(T, Env, Te), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
180 infer(E1e, Env, Te), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
181 generalize(E1e, Te, Env, E1g, Tg), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
182 elaborate(E2, [(X,Te)|Env], E2e). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183 %% Expansion du sucre syntaxique. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
184 elaborate((T1 -> T2), Env, Ee) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
185 new_atom(X), elaborate(pi(X, T1, T2), Env, Ee). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
186 elaborate(app(E1, E2, E3, E4), Env, Ee) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
187 elaborate(app(app(E1,E2,E3),E4), Env, Ee). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
188 elaborate(app(E1, E2, E3), Env, Ee) :- elaborate(app(app(E1,E2),E3), Env, Ee). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
189 elaborate(lambda(X, B), Env, Ee) :- elaborate(lambda(X, _, B), Env, Ee). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
190 elaborate(let(X, E1, E2), Env, Ee) :- elaborate(let(X, _, E1, E2), Env, Ee). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
191 elaborate(fix(F,B,E), Env, Ee) :- elaborate(fix(F,_,B,E), Env, Ee). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
192 elaborate(fix(F,T,B,E), Env, Ee) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
193 elaborate(let(F,T,app(fix,lambda(F,T,B)),E), Env, Ee). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
194 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
195 %% elab_bindings(+TS, +Env, -TS). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
196 %% Applique `elaborate' sur l'environnment de type TS. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
197 elab_tenv([], _, []). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
198 elab_tenv([(X,T)|TS], Env, [(X, Tg)|TSe]) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
199 elaborate(T, Env, Te), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
200 infer(Te, Env, type), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
201 generalize(_, Te, Env, _, Tg), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
202 elab_tenv(TS, [(X, Tg)|Env], TSe). |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
203 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
204 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
205 %% elaborate(+E1, -E2) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
206 %% Comme le `elaborate' ci-dessus, mais avec un environnement par défaut. |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
207 elaborate(SRC, E) :- |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
208 elab_tenv([(int, type), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
209 (fix, ((t -> t) -> t)), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
210 %% list: type → int → type |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
211 (list, (type -> int -> type)), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
212 %% plus: int → int → int |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
213 (plus, (int -> int -> int)), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
214 %% minus: int → int → int |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
215 (minus, (int -> int -> int)), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
216 %% nil: list t 0 |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
217 (nil, app(app(list,t),0)), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
218 %% cons: t -> list t n → list t (n + 1) |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
219 (cons, (t -> app(app(list,t),n) -> |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
220 app(app(list,t), app(app(plus,n),1)))) %fixindent |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
221 ], |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
222 [(type,type)], |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
223 Env), |
f241d9fe71fe
* lisp/emacs-lisp/smie.el (smie-indent-calculate): Simplify and cleanup.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
224 elaborate(SRC, Env, E). |