Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
82e58431
Commit
82e58431
authored
May 06, 2014
by
Julien Lopez
Browse files
[TESTS][TYPED] Update printer and tests; add a new test
parent
47dedbee
Changes
13
Hide whitespace changes
Inline
Side-by-side
tests/typed/src/main.ml
View file @
82e58431
...
...
@@ -34,6 +34,10 @@ let tests = "CDuce runtime tests" >:::
);
"match"
>::
(
fun
test_ctxt
->
assert_equal
~
msg
:
"Test CDuce.runtime.match.hard failed"
~
printer
:
(
fun
x
->
x
)
(
load_file
"tests/match/hard.ref"
)
(
run_test
"(fun ((Int -> Int) -> Int) | f ->
(match f 0 with | 0 -> 0 | _ -> 1)) (fun (Int -> Int) | x -> x+2)"
);
assert_equal
~
msg
:
"Test CDuce.runtime.match.medium failed"
~
printer
:
(
fun
x
->
x
)
(
load_file
"tests/match/medium.ref"
)
(
run_test
"(fun (Int -> Int) | x ->
...
...
@@ -51,7 +55,7 @@ let tests = "CDuce runtime tests" >:::
| y -> [x] @ y)"
);
assert_equal
~
msg
:
"Test CDuce.runtime.list.is_empty failed"
~
printer
:
(
fun
x
->
x
)
(
load_file
"tests/list/is_empty.ref"
)
(
run_test
"fun ([Int] -> Bool) | [] -> `true | _ -> `false"
);
(
run_test
"fun ([Int
*
] -> Bool) | [] -> `true | _ -> `false"
);
assert_equal
~
msg
:
"Test CDuce.runtime.list.tail failed"
~
printer
:
(
fun
x
->
x
)
(
load_file
"tests/list/tail.ref"
)
(
run_test
"fun ([Int*] -> [Int*]) | [_ (rest::(Int*))] -> rest | [] -> []"
);
...
...
tests/typed/src/printer.ml
View file @
82e58431
let
rec
typed_to_string
e
=
"{typ:"
^
(
Types
.
Print
.
to_string
e
.
Typed
.
exp_typ
)
^
"; descr="
^
(
match
e
.
Typed
.
exp_descr
with
|
Typed
.
Forget
(
e
,
_
)
->
"Forget("
^
typed_to_string
e
^
")"
|
Typed
.
Check
(
_
,
e
,
_
)
->
"Check("
^
typed_to_string
e
^
")"
|
Typed
.
Var
(
id
,
name
)
->
"Var("
^
(
string_of_int
(
Upool
.
int
id
))
^
", "
^
(
Encodings
.
Utf8
.
to_string
name
)
^
")"
|
Typed
.
TVar
(
id
,
name
)
->
"TVar("
^
(
string_of_int
(
Upool
.
int
id
))
^
", "
^
(
Encodings
.
Utf8
.
to_string
name
)
^
")"
|
Typed
.
Subst
(
e
,
_
)
->
"Subst("
^
(
typed_to_string
e
)
^
", <sigma>)"
|
Typed
.
ExtVar
(
_
,
(
id
,
name
)
,
_
)
->
"ExtVar("
^
(
string_of_int
(
Upool
.
int
id
))
^
", "
^
(
Encodings
.
Utf8
.
to_string
name
)
^
")"
|
Typed
.
Apply
(
e1
,
e2
)
->
"("
^
typed_to_string
e1
^
").("
^
(
typed_to_string
e2
)
^
")"
|
Typed
.
Abstraction
(
abstr
)
->
"Abstraction("
^
(
abst
abstr
)
^
")"
|
Typed
.
Cst
(
cst
)
->
const
cst
|
Typed
.
Pair
(
e1
,
e2
)
->
"("
^
(
typed_to_string
e1
)
^
", "
^
(
typed_to_string
e2
)
^
")"
|
Typed
.
String
(
_
,
_
,
s
,
_
)
->
"
\"
"
^
(
Encodings
.
Utf8
.
to_string
s
)
^
"
\"
"
|
Typed
.
Match
(
e
,
b
)
->
"Match("
^
(
typed_to_string
e
)
^
","
^
(
branches
b
)
^
")"
|
Typed
.
Map
(
e
,
b
)
->
"Map("
^
(
typed_to_string
e
)
^
","
^
(
branches
b
)
^
")"
|
Typed
.
Transform
(
e
,
b
)
->
"Transform("
^
(
typed_to_string
e
)
^
","
^
(
branches
b
)
^
")"
|
Typed
.
Xtrans
(
e
,
b
)
->
"Xtrans("
^
(
typed_to_string
e
)
^
","
^
(
branches
b
)
^
")"
|
Typed
.
Validate
(
e
,
t
,
_
)
->
"Validate("
^
(
typed_to_string
e
)
^
", "
^
(
Types
.
Print
.
to_string
t
)
^
")"
|
Typed
.
RemoveField
(
e
,
_
)
->
"RemoveField("
^
(
typed_to_string
e
)
^
", <label>)"
|
Typed
.
Dot
(
e
,
_
)
->
"Dot("
^
(
typed_to_string
e
)
^
", <label>)"
|
Typed
.
Xml
(
e1
,
e2
,
_
)
->
"Xml("
^
(
typed_to_string
e1
)
^
", "
^
(
typed_to_string
e2
)
^
")"
|
Typed
.
RecordLitt
(
_
)
->
"RecordLitt()"
|
Typed
.
Op
(
s
,
i
,
l
)
->
"Op("
^
s
^
", "
^
(
string_of_int
i
)
^
", ["
^
typedlist_to_string
l
^
"])"
|
_
->
assert
false
)
^
"}"
and
typedlist_to_string
l
=
let
rec
_typedlist_to_string
l
res
=
match
l
with
|
e
::
[]
->
res
^
(
typed_to_string
e
)
|
e
::
rest
->
_typedlist_to_string
rest
(
res
^
(
typed_to_string
e
)
^
"; "
)
|
[]
->
res
in
_typedlist_to_string
l
""
and
const
cst
=
match
cst
with
|
Types
.
Integer
(
i
)
->
"Integer("
^
(
Intervals
.
V
.
to_string
i
)
^
")"
|
Types
.
Atom
(
a
)
->
"Atom("
^
(
Atoms
.
V
.
to_string
a
)
^
")"
|
Types
.
Char
(
c
)
->
"Char("
^
(
string_of_int
(
Chars
.
V
.
to_int
c
))
^
")"
|
Types
.
Pair
(
c1
,
c2
)
->
"("
^
const
c1
^
", "
^
const
c2
^
")"
|
Types
.
String
(
_
,
_
,
s
,
_
)
->
"
\"
"
^
(
Encodings
.
Utf8
.
to_string
s
)
^
"
\"
"
open
Value
let
print_lst
f
ppf
l
=
let
rec
aux
ppf
=
function
|
[]
->
Format
.
fprintf
ppf
"@."
|
[
h
]
->
Format
.
fprintf
ppf
"%a"
f
h
|
h
::
t
->
Format
.
fprintf
ppf
"%a ,%a"
f
h
aux
t
in
match
l
with
|
[]
->
Format
.
fprintf
ppf
""
|_
->
Format
.
fprintf
ppf
"%a"
aux
l
let
rec
pp_const
ppf
cst
=
match
cst
with
|
Types
.
Integer
(
i
)
->
Format
.
fprintf
ppf
"Integer(%s)"
(
Intervals
.
V
.
to_string
i
)
|
Types
.
Atom
(
a
)
->
Format
.
fprintf
ppf
"Atom(%s)"
(
Atoms
.
V
.
to_string
a
)
|
Types
.
Char
(
c
)
->
Format
.
fprintf
ppf
"Char(%d)"
(
Chars
.
V
.
to_int
c
)
|
Types
.
Pair
(
c1
,
c2
)
->
Format
.
fprintf
ppf
"(%a,%a)"
pp_const
c1
pp_const
c2
|
Types
.
String
(
_
,
_
,
s
,
_
)
->
Format
.
fprintf
ppf
"
\"
%s
\"
"
(
Encodings
.
Utf8
.
to_string
s
)
|
_
->
assert
false
let
rec
pp_typed
ppf
e
=
Format
.
fprintf
ppf
"{typ: %a; descr= %a}"
Types
.
Print
.
print
e
.
Typed
.
exp_typ
pp_typed_aux
e
and
pp_typedsigma
ppf
=
let
rec
aux
ppf
=
function
|
(
v
,
t
)
::
rest
->
Format
.
fprintf
ppf
"(%a, %a)"
Var
.
dump
v
Types
.
Print
.
print
t
|
[]
->
Format
.
fprintf
ppf
""
in
function
|
s
::
rest
->
Format
.
fprintf
ppf
"[%a, %a]"
aux
s
pp_typedsigma
rest
|
[]
->
Format
.
fprintf
ppf
""
and
pp_typed_aux
ppf
e
=
match
e
.
Typed
.
exp_descr
with
|
Typed
.
Forget
(
e
,
_
)
->
Format
.
fprintf
ppf
"Forget(%a)"
pp_typed
e
|
Typed
.
Check
(
_
,
e
,
_
)
->
Format
.
fprintf
ppf
"Check(%a)"
pp_typed
e
|
Typed
.
TVar
(
id
,
name
)
->
Format
.
fprintf
ppf
"TVar(%s,%s)"
(
string_of_int
(
Upool
.
int
id
))
(
Encodings
.
Utf8
.
to_string
name
)
|
Typed
.
Var
(
id
,
name
)
->
Format
.
fprintf
ppf
"Var(%s,%s)"
(
string_of_int
(
Upool
.
int
id
))
(
Encodings
.
Utf8
.
to_string
name
)
|
Typed
.
ExtVar
(
_
,
(
id
,
name
)
,
_
)
->
Format
.
fprintf
ppf
"ExtVar(%s,%s)"
(
string_of_int
(
Upool
.
int
id
))
(
Encodings
.
Utf8
.
to_string
name
)
|
Typed
.
Apply
(
e1
,
e2
)
->
Format
.
fprintf
ppf
"(%a).(%a)"
pp_typed
e1
pp_typed
e2
|
Typed
.
Abstraction
(
abstr
)
->
Format
.
fprintf
ppf
"Abstraction(%a)"
pp_abst
abstr
|
Typed
.
Cst
(
cst
)
->
pp_const
ppf
cst
|
Typed
.
Pair
(
e1
,
e2
)
->
Format
.
fprintf
ppf
"(%a, %a)"
pp_typed
e1
pp_typed
e2
|
Typed
.
String
(
_
,
_
,
s
,
_
)
->
Format
.
fprintf
ppf
"
\"
%s
\"
"
(
Encodings
.
Utf8
.
to_string
s
)
|
Typed
.
Match
(
e
,
b
)
->
Format
.
fprintf
ppf
"Match(%a,%a)"
pp_typed
e
pp_branches
b
|
Typed
.
Subst
(
e
,
s
)
->
Format
.
fprintf
ppf
"Subst(%a,[%a])"
pp_typed
e
pp_typedsigma
s
|
Typed
.
Op
(
s
,
i
,
l
)
->
Format
.
fprintf
ppf
"(%s, %d, "
s
i
;
(
print_lst
pp_typed
ppf
l
);
Format
.
fprintf
ppf
")"
|
_
->
assert
false
and
abst
abstr
=
(
match
abstr
.
Typed
.
fun_name
with
|
Some
(
id
,
name
)
->
"name:("
^
(
string_of_int
(
Upool
.
int
id
))
^
", "
^
(
Encodings
.
Utf8
.
to_string
name
)
^
")"
|
None
->
"name:<none>"
)
^
",
\n
iface:["
^
(
iface
abstr
.
Typed
.
fun_iface
)
^
"],
\n
body:["
^
(
branches
abstr
.
Typed
.
fun_body
)
^
"], "
^
"typ:"
^
(
Types
.
Print
.
to_string
abstr
.
Typed
.
fun_typ
)
^
", fv:["
^
(
fv_to_string
abstr
.
Typed
.
fun_fv
)
^
"]"
and
iface
list
=
match
list
with
|
(
t1
,
t2
)
::
[]
->
"("
^
(
Types
.
Print
.
to_string
t1
)
^
", "
^
(
Types
.
Print
.
to_string
t2
)
^
")"
|
(
t1
,
t2
)
::
rest
->
"("
^
(
Types
.
Print
.
to_string
t1
)
^
", "
^
(
Types
.
Print
.
to_string
t2
)
^
"),"
|
[]
->
""
and
branches
brs
=
"typ:"
^
(
Types
.
Print
.
to_string
brs
.
Typed
.
br_typ
)
^
", accept:"
^
(
Types
.
Print
.
to_string
brs
.
Typed
.
br_accept
)
^
", branches:"
^
(
branch
brs
.
Typed
.
br_branches
)
and
branch
brs
=
match
brs
with
|
br
::
[]
->
"
\n
{used:"
^
(
string_of_bool
br
.
Typed
.
br_used
)
^
"; ghost:"
^
(
string_of_bool
br
.
Typed
.
br_ghost
)
^
"; br_vars_empty:["
^
(
fv_to_string
br
.
Typed
.
br_vars_empty
)
^
"];
\n
pat:{"
^
(
node
br
.
Typed
.
br_pat
)
^
"};
\n
body:{typ:"
^
(
Types
.
Print
.
to_string
br
.
Typed
.
br_body
.
Typed
.
exp_typ
)
^
", descr:"
^
(
typed_to_string
br
.
Typed
.
br_body
)
^
"}}"
|
br
::
rest
->
"
\n
{used:"
^
(
string_of_bool
br
.
Typed
.
br_used
)
^
"; ghost:"
^
(
string_of_bool
br
.
Typed
.
br_ghost
)
^
"; br_vars_empty:["
^
(
fv_to_string
br
.
Typed
.
br_vars_empty
)
^
"];
\n
pat:{"
^
(
node
br
.
Typed
.
br_pat
)
^
"};
\n
body:{typ:"
^
(
Types
.
Print
.
to_string
br
.
Typed
.
br_body
.
Typed
.
exp_typ
)
^
", descr:"
^
(
typed_to_string
br
.
Typed
.
br_body
)
^
"}},"
^
(
branch
rest
)
|
[]
->
""
and
node
node
=
"id:"
^
(
string_of_int
node
.
Patterns
.
id
)
^
"; descr:["
^
(
descr
node
.
Patterns
.
descr
)
^
"]; accept:[id:"
^
(
string_of_int
(
Types
.
id
node
.
Patterns
.
accept
))
^
"; descr:"
^
(
Types
.
Print
.
to_string
(
Types
.
descr
node
.
Patterns
.
accept
))
^
"]; fv:["
^
(
fv_to_string
node
.
Patterns
.
fv
)
^
"]"
and
descr
(
t
,
fv
,
d
)
=
(
Types
.
Print
.
to_string
t
)
^
"; ["
^
(
fv_to_string
fv
)
^
"]; "
^
descr2
d
and
descr2
d
=
match
d
with
|
Patterns
.
Constr
(
t
)
->
"Constr("
^
(
Types
.
Print
.
to_string
t
)
^
")"
|
Patterns
.
Cup
(
d1
,
d2
)
->
"Cup(["
^
(
descr
d1
)
^
"], ["
^
(
descr
d2
)
^
"])"
|
Patterns
.
Cap
(
d1
,
d2
)
->
"Cap(["
^
(
descr
d1
)
^
"], ["
^
(
descr
d2
)
^
"])"
|
Patterns
.
Times
(
n1
,
n2
)
->
"Times({"
^
(
node
n1
)
^
"}, {"
^
(
node
n2
)
^
"})"
|
Patterns
.
Xml
(
n1
,
n2
)
->
"Xml({"
^
(
node
n1
)
^
"}, {"
^
(
node
n2
)
^
"})"
|
Patterns
.
Record
(
l
,
n
)
->
"Record("
^
(
Ns
.
Label
.
string_of_tag
l
)
^
", {"
^
(
node
n
)
^
"})"
|
Patterns
.
Capture
((
id
,
name
))
->
"Capture("
^
(
string_of_int
(
Upool
.
int
id
))
^
", "
^
(
Encodings
.
Utf8
.
to_string
name
)
^
")"
|
Patterns
.
Constant
((
id
,
name
)
,
ct
)
->
"Constant(("
^
(
string_of_int
(
Upool
.
int
id
))
^
", "
^
(
Encodings
.
Utf8
.
to_string
name
)
^
"), "
^
const
ct
^
")"
|
Patterns
.
Dummy
->
"Dummy"
and
fv_to_string
fv
=
match
fv
with
|
(
id
,
name
)
::
[]
->
"("
^
(
string_of_int
(
Upool
.
int
id
))
^
", "
^
(
Encodings
.
Utf8
.
to_string
name
)
^
")"
|
(
id
,
name
)
::
rest
->
"("
^
(
string_of_int
(
Upool
.
int
id
))
^
", "
^
(
Encodings
.
Utf8
.
to_string
name
)
^
"), "
^
(
fv_to_string
rest
)
|
[]
->
""
and
pp_abst
ppf
abstr
=
Format
.
fprintf
ppf
"%a,
\n
iface:[%a],
\n
body:[%a], typ:%a, fv:[%a]"
pp_fun_name
abstr
.
Typed
.
fun_name
pp_iface
abstr
.
Typed
.
fun_iface
pp_branches
abstr
.
Typed
.
fun_body
Types
.
Print
.
print
abstr
.
Typed
.
fun_typ
pp_fv
abstr
.
Typed
.
fun_fv
and
pp_fun_name
ppf
=
function
|
Some
(
id
,
name
)
->
Format
.
fprintf
ppf
"name:(%s, %s)"
(
string_of_int
(
Upool
.
int
id
))
(
Encodings
.
Utf8
.
to_string
name
)
|
None
->
Format
.
fprintf
ppf
"name:<none>"
and
pp_iface
ppf
l
=
let
f
ppf
(
t1
,
t2
)
=
Format
.
fprintf
ppf
"(%a, %a)"
Types
.
Print
.
print
t1
Types
.
Print
.
print
t2
in
print_lst
f
ppf
l
and
pp_branches
ppf
brs
=
Format
.
fprintf
ppf
"typ:%a, accept:%a, branches:%a"
Types
.
Print
.
print
brs
.
Typed
.
br_typ
Types
.
Print
.
print
brs
.
Typed
.
br_accept
pp_branch
brs
.
Typed
.
br_branches
and
pp_branch
ppf
brs
=
let
f
ppf
br
=
Format
.
fprintf
ppf
"
\n
{used:%b; ghost:%b; br_vars_empty:[%a];
\n
pat:{%a};
\n
body:{typ:%a, descr:%a}}"
br
.
Typed
.
br_used
br
.
Typed
.
br_ghost
pp_fv
br
.
Typed
.
br_vars_empty
pp_node
br
.
Typed
.
br_pat
Types
.
Print
.
print
br
.
Typed
.
br_body
.
Typed
.
exp_typ
pp_typed
br
.
Typed
.
br_body
in
print_lst
f
ppf
brs
and
pp_node
ppf
node
=
Format
.
fprintf
ppf
"id:%d; descr:[%a]; accept:[id:%d; descr:%a]; fv:[%a]"
node
.
Patterns
.
id
Patterns
.
print
node
.
Patterns
.
descr
(
Types
.
id
node
.
Patterns
.
accept
)
Types
.
Print
.
print
(
Types
.
descr
node
.
Patterns
.
accept
)
pp_fv
node
.
Patterns
.
fv
(*
and pp_descr ppf (t, fv, d) =
Format.fprintf ppf "%a; [%a]; %a"
Types.Print.print t
pp_fv fv
pp_pattern d
and pp_pattern ppf = function
| Patterns.Constr(t) -> Format.fprintf ppf "Constr(%a)" Types.Print.print t
| Patterns.Cup(d1, d2) -> Format.fprintf ppf "Cup([%a], [%a])" pp_descr d1 pp_descr d2
| Patterns.Cap(d1, d2) -> Format.fprintf ppf "Cap([%a], [%a])" pp_descr d1 pp_descr d2
| Patterns.Times(n1, n2) -> Format.fprintf ppf "Times({%a}, {%a})" pp_node n1 pp_node n2
| Patterns.Xml(n1, n2) -> Format.fprintf ppf "Xml({%a}, {%a})" pp_node n1 pp_node n2
| Patterns.Record(l, n) -> Format.fprintf ppf "Record(%s, {%a})" (Ns.Label.string_of_tag l) pp_node n
| Patterns.Capture((id, name)) ->
Format.fprintf ppf "Capture(%d,%s)"
(Upool.int id)
(Encodings.Utf8.to_string name)
| Patterns.Constant((id, name), ct) -> Format.fprintf ppf "Constant((%d, %s), %a)"
(Upool.int id)
(Encodings.Utf8.to_string name)
pp_const ct
| Patterns.Dummy -> Format.fprintf ppf "Dummy"
*)
and
pp_fv
ppf
fv
=
let
f
ppf
(
id
,
name
)
=
Format
.
fprintf
ppf
"(%d, %s)"
(
Upool
.
int
id
)
(
Encodings
.
Utf8
.
to_string
name
)
in
print_lst
f
ppf
fv
let
pp_vloc
ppf
=
function
|
Lambda
.
Local
(
i
)
->
Format
.
fprintf
ppf
"Local(%d)"
i
|
Lambda
.
Env
(
i
)
->
Format
.
fprintf
ppf
"Env(%d)"
i
|
Lambda
.
Ext
(
_
,
i
)
->
Format
.
fprintf
ppf
"Ext(?, %d)"
i
|
Lambda
.
External
(
_
,
i
)
->
Format
.
fprintf
ppf
"External(?, %d)"
i
|
Lambda
.
Builtin
(
s
)
->
Format
.
fprintf
ppf
"Builtin(%s)"
s
|
Lambda
.
Global
(
i
)
->
Format
.
fprintf
ppf
"Global(%d)"
i
|
Lambda
.
Dummy
->
Format
.
fprintf
ppf
"Dummy"
let
pp_vloc_array
ppf
a
=
print_lst
pp_vloc
ppf
(
Array
.
to_list
a
)
let
pp_binding
ppf
(
id
,
name
)
value
=
Format
.
fprintf
ppf
"((%d, %s),%a)
\n
"
(
Upool
.
int
id
)
(
Encodings
.
Utf8
.
to_string
name
)
pp_vloc
value
let
pp_env
ppf
env
=
if
Ident
.
Env
.
is_empty
env
then
Format
.
fprintf
ppf
"<empty>
\n
"
else
Ident
.
Env
.
iter
(
pp_binding
ppf
)
env
let
rec
pp_sigma
ppf
=
let
pp_aux
ppf
=
print_lst
(
fun
ppf
(
t1
,
t2
)
->
Format
.
fprintf
ppf
"(%a -> %a)"
Types
.
Print
.
print
t1
Types
.
Print
.
print
t2
)
ppf
in
function
|
`List
ll
->
Types
.
Tallying
.
CS
.
pp_sl
ppf
ll
|
`Comp
(
s1
,
s2
)
->
Format
.
fprintf
ppf
"Comp(%a,%a)"
pp_sigma
s1
pp_sigma
s2
|
`Sel
(
x
,
tl
,
s
)
->
Format
.
fprintf
ppf
"Sel(%a,%a,%a)"
pp_fv
x
pp_aux
tl
pp_sigma
s
let
rec
pp_value
ppf
=
function
|
Value
.
Pair
(
v1
,
v2
,
sigma
)
->
Format
.
fprintf
ppf
"(%a, %a, %a)"
pp_value
v1
pp_value
v2
pp_sigma
sigma
|
Xml
(
_
,_,_,
sigma
)
->
Format
.
fprintf
ppf
"Xml(%a)"
pp_sigma
sigma
|
XmlNs
(
_
,_,_,_,
sigma
)
->
Format
.
fprintf
ppf
"XmlNs(%a)"
pp_sigma
sigma
|
Record
(
_
,
sigma
)
->
Format
.
fprintf
ppf
"Record(%a)"
pp_sigma
sigma
|
Atom
(
a
)
->
Format
.
fprintf
ppf
"Atom(%a)"
Atoms
.
V
.
print
a
|
Integer
(
i
)
->
Format
.
fprintf
ppf
"%d"
(
Big_int
.
int_of_big_int
i
)
|
Char
(
i
)
->
Format
.
fprintf
ppf
"Char()"
|
Abstraction
(
None
,
_
,
sigma
)
->
Format
.
fprintf
ppf
"Abstraction(None,%a)"
pp_sigma
sigma
|
Abstraction
(
Some
t
,
_
,
sigma
)
->
Format
.
fprintf
ppf
"Abstraction(%a,%a)"
pp_iface
t
pp_sigma
sigma
|
Abstract
((
name
,
_
))
->
Format
.
fprintf
ppf
"Abstract(%s)"
name
|
String_latin1
(
_
,_,
s
,_
)
->
Format
.
fprintf
ppf
"
\"
%s
\"
"
s
|
String_utf8
(
_
,_,
s
,_
)
->
Format
.
fprintf
ppf
"
\"
%s
\"
"
s
|
Concat
(
v1
,
v2
)
->
Format
.
fprintf
ppf
"Concat(%a, %a)"
pp_value
v1
pp_value
v2
|
Absent
->
Format
.
fprintf
ppf
"Absent"
let
rec
pp_lambda
ppf
=
let
open
Lambda
in
function
|
Var
v
->
Format
.
fprintf
ppf
"Var(%a)"
pp_vloc
v
|
TVar
(
v
,
sigma
)
->
Format
.
fprintf
ppf
"TVar(%a,%a)"
pp_vloc
v
pp_sigma
sigma
|
Apply
(
e1
,
e2
)
->
Format
.
fprintf
ppf
"Apply(%a,%a)"
pp_lambda
e1
pp_lambda
e2
|
Abstraction
(
va
,
l
,
b
,
i
,
true
,
sigma
)
->
Format
.
fprintf
ppf
"PolyAbstraction(%a,,,,%a)"
pp_vloc_array
va
pp_sigma
sigma
|
Abstraction
(
va
,
l
,
b
,
i
,
false
,
sigma
)
->
Format
.
fprintf
ppf
"Abstraction(%a,,,,%a)"
pp_vloc_array
va
pp_sigma
sigma
|
_
->
()
let
print_to_string
f
x
=
let
b
=
Buffer
.
create
1024
in
let
ppf
=
Format
.
formatter_of_buffer
b
in
f
ppf
x
;
Format
.
pp_print_flush
ppf
()
;
Buffer
.
contents
b
let
typed_to_string
=
print_to_string
pp_typed
let
print_env
=
Format
.
printf
"%a"
pp_env
let
print_value
=
Format
.
printf
"%a"
pp_value
let
value_to_string
=
print_to_string
pp_value
let
lambda_to_string
=
print_to_string
pp_lambda
tests/typed/src/printer.mli
View file @
82e58431
val
typed_to_string
:
Typed
.
texpr
->
string
val
print_env
:
Lambda
.
var_loc
Ident
.
Env
.
t
->
unit
val
print_value
:
Value
.
t
->
unit
val
value_to_string
:
Value
.
t
->
string
val
lambda_to_string
:
Lambda
.
expr
->
string
tests/typed/tests/abstr/identity.ref
View file @
82e58431
{typ:Int; descr=({typ:Int -> Int; descr=Abstraction(name:<none>,
iface:[(Int, Int)],
{typ: Int; descr= ({typ: Int -> Int; descr= Abstraction(name:<none>,
iface:[(
Int, Int)],
body:[typ:Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[Any; [(0, x)]; Capture(0, x)]; accept:[id:176; descr:Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ:Int; descr=Var(0, x)}}}], typ:Int -> Int, fv:[])}).({typ:Int; descr=Integer(2)})}
pat:{id:3; descr:[x]; accept:[id:176; descr:
Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ: Int; descr= Var(0,x)}}}], typ:
Int -> Int, fv:[])}).({typ: Int; descr= Integer(2)})}
tests/typed/tests/list/fold.ref
View file @
82e58431
{typ:Int -> X1 -> X1 where X1 = [ Int* ]; descr=Abstraction(name:<none>,
iface:[(Int, X1 -> X1 where X1 = [ Int* ])],
{typ: Int -> X1 -> X1 where X1 = [ Int* ]; descr= Abstraction(name:<none>,
iface:[(
Int, X1 -> X1 where X1 = [ Int* ])],
body:[typ:Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[Any; [(0, x)]; Capture(0, x)]; accept:[id:178; descr:Any]; fv:[(0, x)]};
body:{typ:X1 -> X1 where X1 = [ Int* ], descr:{typ:X1 -> X1 where X1 = [ Int* ]; descr=Abstraction(name:<none>,
iface:[([ Int* ], [ Int* ])],
pat:{id:3; descr:[x]; accept:[id:178; descr:
Any]; fv:[(0, x)]};
body:{typ:X1 -> X1 where X1 = [ Int* ], descr:{typ:
X1 -> X1 where X1 = [ Int* ]; descr= Abstraction(name:<none>,
iface:[(
[ Int* ], [ Int* ])],
body:[typ:[ Int* ], accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:4; descr:[Any; [(0, y)]; Capture(0, y)]; accept:[id:179; descr:Any]; fv:[(0, y)]};
body:{typ:[ Int* ], descr:{typ:[ Int* ]; descr=Op(@, 0, [{typ:[ Int* ]; descr=({typ:Int; descr=Var(0, x)}, {typ:[ Int* ]; descr=Atom(nil)})}; {typ:[ Int* ]; descr=Var(0, y)}])}}}], typ:X1 -> X1 where X1 = [ Int* ], fv:[(0, x)])}}}], typ:Int -> X1 -> X1 where X1 = [ Int* ], fv:[])}
pat:{id:4; descr:[y]; accept:[id:179; descr:
Any]; fv:[(0, y)]};
body:{typ:[ Int* ], descr:{typ: [ Int* ]; descr= (@, 0, {typ:
[ Int* ]; descr= ({typ: Int; descr= Var(0,x)}, {typ: [ Int* ]; descr= Atom(nil)})} ,{typ:
[ Int* ]; descr= Var(0,y)})}}}], typ:X1 -> X1 where X1 = [ Int* ], fv:[(0, x)])}}}], typ:
Int -> X1 -> X1 where X1 = [ Int* ], fv:[])}
tests/typed/tests/list/is_empty.ref
View file @
82e58431
{typ:[ Int ] -> Bool; descr=Abstraction(name:<none>,
iface:[([ Int ], Bool)],
body:[typ:[ Int ], accept:Any, branches:
{used:false; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[[ ]; []; Constr([ ])]; accept:[id:179; descr:[ ]]; fv:[]};
body:{typ:Empty, descr:{typ:Empty; descr=Atom(true)}}},
{typ: [ Int* ] -> Bool; descr= Abstraction(name:<none>,
iface:[([ Int* ],
Bool)],
body:[typ:[ Int* ], accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:4; descr:[Any; []; Constr(Any)]; accept:[id:180; descr:Any]; fv:[]};
body:{typ:Bool, descr:{typ:Bool; descr=Atom(false)}}}], typ:[ Int ] -> Bool, fv:[])}
pat:{id:3; descr:[
[ ]]; accept:[id:178; descr:[ ]]; fv:[]};
body:{typ:Bool, descr:{typ:
Bool; descr= Atom(true)}}} ,
{used:true; ghost:false; br_vars_empty:[];
pat:{id:4; descr:[
Any]; accept:[id:179; descr:Any]; fv:[]};
body:{typ:Bool, descr:{typ:
Bool; descr= Atom(false)}}}], typ:[ Int* ] -> Bool, fv:[])}
tests/typed/tests/list/tail.ref
View file @
82e58431
{typ:X1 -> X1 where X1 = [ Int* ]; descr=Abstraction(name:<none>,
iface:[([ Int* ], [ Int* ])],
{typ: X1 -> X1 where X1 = [ Int* ]; descr= Abstraction(name:<none>,
iface:[(
[ Int* ], [ Int* ])],
body:[typ:[ Int* ], accept:[ (Any Int*)? ], branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[[ Any Int* ]; [(0, rest)]; Times({id:5; descr:[Any; []; Constr(Any)]; accept:[id:179; descr:Any]; fv:[]}, {id:4; descr:[[ Int* ]; [(0, rest)]; Cap([Any; [(0, rest)]; Capture(0, rest)], [[ Int* ]; []; Constr([ Int* ])])]; accept:[id:178; descr:[ Int* ]]; fv:[(0, rest)]})]; accept:[id:177; descr:[ Any Int* ]]; fv:[(0, rest)]};
body:{typ:[ Int* ], descr:{typ:[ Int* ]; descr=Var(0, rest)}}},
pat:{id:3; descr:[(
Any,(rest & [ Int* ]))]; accept:[id:177; descr:[ Any Int* ]]; fv:[(0, rest)]};
body:{typ:
[ Int* ], descr:{typ: [ Int* ]; descr= Var(0,rest)}}} ,
{used:true; ghost:false; br_vars_empty:[];
pat:{id:6; descr:[[ ]; []; Constr([ ])]; accept:[id:180; descr:[ ]]; fv:[]};
body:{typ:[ Int* ], descr:{typ:[ Int* ]; descr=Atom(nil)}}}], typ:X1 -> X1 where X1 = [ Int* ], fv:[])}
pat:{id:6; descr:[
[ ]]; accept:[id:180; descr:[ ]]; fv:[]};
body:{typ:[ Int* ], descr:{typ:
[ Int* ]; descr= Atom(nil)}}}], typ:X1 -> X1 where X1 = [ Int* ], fv:[])}
tests/typed/tests/match/hard.ref
0 → 100644
View file @
82e58431
{typ: Int; descr= ({typ: (Int -> Int) -> Int; descr= Abstraction(name:<none>,
iface:[(
Int -> Int, Int)],
body:[typ:Int -> Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[f]; accept:[id:177; descr:
Any]; fv:[(0, f)]};
body:{typ:Int, descr:{typ: Int; descr= Match({typ:
Int; descr= ({typ: Int -> Int; descr= Var(0,f)}).({typ: Int; descr= Integer(0)})},typ:
Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:4; descr:[
0]; accept:[id:178; descr:0]; fv:[]};
body:{typ:Int, descr:{typ: Int; descr= Integer(0)}}} ,
{used:true; ghost:false; br_vars_empty:[];
pat:{id:5; descr:[
Any]; accept:[id:179; descr:Any]; fv:[]};
body:{typ:Int, descr:{typ:
Int; descr= Integer(1)}}})}}}], typ:(Int -> Int) -> Int, fv:[])}).({typ:
Int -> Int; descr= Abstraction(name:<none>,
iface:[(Int, Int)],
body:[typ:
Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:6; descr:[x]; accept:[id:180; descr:
Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ: Int; descr= (+, 0, {typ:
Int; descr= Var(0,x)} ,{typ: 2; descr= Integer(2)})}}}], typ:Int -> Int, fv:[])})}
tests/typed/tests/match/medium.ref
View file @
82e58431
{typ:Int; descr=({typ:Int -> Int; descr=Abstraction(name:<none>,
iface:[(Int, Int)],
{typ: Int; descr= ({typ: Int -> Int; descr= Abstraction(name:<none>,
iface:[(
Int, Int)],
body:[typ:Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[Any; [(0, x)]; Capture(0, x)]; accept:[id:176; descr:Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ:Int; descr=Match({typ:Int; descr=Var(0, x)},typ:Int, accept:Any, branches:
pat:{id:3; descr:[x]; accept:[id:176; descr:
Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ: Int; descr= Match({typ:
Int; descr= Var(0,x)},typ:Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:4; descr:[1; []; Constr(1)]; accept:[id:177; descr:1]; fv:[]};
body:{typ:Int, descr:{typ:Int; descr=Integer(3)}}},
pat:{id:4; descr:[
1]; accept:[id:177; descr:1]; fv:[]};
body:{typ:Int, descr:{typ: Int; descr= Integer(3)}}} ,
{used:true; ghost:false; br_vars_empty:[];
pat:{id:5; descr:[Any; [(0, x)]; Capture(0, x)]; accept:[id:178; descr:Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ:Int; descr=Var(0, x)}}})}}}], typ:Int -> Int, fv:[])}).({typ:Int; descr=Integer(2)})}
pat:{id:5; descr:[x]; accept:[id:178; descr:
Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ: Int; descr= Var(0,x)}}})}}}], typ:
Int -> Int, fv:[])}).({typ: Int; descr= Integer(2)})}
tests/typed/tests/match/simple.ref
View file @
82e58431
{typ:Int; descr=({typ:Int -> Int; descr=Abstraction(name:<none>,
iface:[(Int, Int)],
{typ: Int; descr= ({typ: Int -> Int; descr= Abstraction(name:<none>,
iface:[(
Int, Int)],
body:[typ:Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[Any; [(0, x)]; Capture(0, x)]; accept:[id:176; descr:Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ:Int; descr=Match({typ:Int; descr=Var(0, x)},typ:Int, accept:Any, branches:
pat:{id:3; descr:[x]; accept:[id:176; descr:
Any]; fv:[(0, x)]};
body:{typ:Int, descr:{typ: Int; descr= Match({typ:
Int; descr= Var(0,x)},typ:Int, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:4; descr:[Any; []; Constr(Any)]; accept:[id:177; descr:Any]; fv:[]};
body:{typ:Int, descr:{typ:Int; descr=Var(0, x)}}})}}}], typ:Int -> Int, fv:[])}).({typ:Int; descr=Integer(2)})}
pat:{id:4; descr:[
Any]; accept:[id:177; descr:Any]; fv:[]};
body:{typ:Int, descr:{typ:
Int; descr= Var(0,x)}}})}}}], typ:Int -> Int, fv:[])}).({typ: Int; descr= Integer(2)})}
tests/typed/tests/misc/firsts.ref
View file @
82e58431
{typ:(Int,Int); descr=({typ:X1 -> X1 where X1 = (Int,Int); descr=({typ:X1 -> X1 -> X1 where X1 = (Int,Int); descr=Abstraction(name:<none>,
iface:[((Int,Int), X1 -> X1 where X1 = (Int,Int))],
body:[typ:(Int,Int), accept:Pair, branches:
{typ: (Int,Int); descr= ({typ: X1 -> X1 where X1 = (Int,Int); descr= ({typ:
X1 -> X1 -> X1 where X1 = (Int,Int); descr= Abstraction(name:<none>,
iface:[(
(Int,Int), X1 -> X1 where X1 = (Int,Int))],
body:[typ:(Int,Int), accept:
Pair, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[Pair; [(0, x)]; Times({id:5; descr:[Any; [(0, x)]; Capture(0, x)]; accept:[id:180; descr:Any]; fv:[(0, x)]}, {id:4; descr:[Any; []; Constr(Any)]; accept:[id:179; descr:Any]; fv:[]})]; accept:[id:178; descr:Pair]; fv:[(0, x)]};
body:{typ:X1 -> X1 where X1 = (Int,Int), descr:{typ:X1 -> X1 where X1 = (Int,Int); descr=Abstraction(name:<none>,
iface:[((Int,Int), (Int,Int))],
pat:{id:3; descr:[(x,
Any)]; accept:[id:178; descr:Pair]; fv:[(0, x)]};
body:{typ:X1 -> X1 where
X1 = (Int,Int), descr:{typ:
X1 -> X1 where X1 = (Int,Int); descr= Abstraction(name:<none>,
iface:[(
(Int,Int), (Int,Int))],
body:[typ:(Int,Int), accept:Pair, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:6; descr:[Pair; [(0, y)]; Times({id:7; descr:[Any; [(0, y)]; Capture(0, y)]; accept:[id:182; descr:Any]; fv:[(0, y)]}, {id:4; descr:[Any; []; Constr(Any)]; accept:[id:179; descr:Any]; fv:[]})]; accept:[id:181; descr:Pair]; fv:[(0, y)]};
body:{typ:(Int,Int), descr:{typ:(Int,Int); descr=({typ:Int; descr=Var(0, x)}, {typ:Int; descr=Var(0, y)})}}}], typ:X1 -> X1 where X1 = (Int,Int), fv:[(0, x)])}}}], typ:X1 -> X1 -> X1 where X1 = (Int,Int), fv:[])}).({typ:(Int,Int); descr=({typ:Int; descr=Integer(2)}, {typ:Int; descr=Integer(3)})})}).({typ:(Int,Int); descr=({typ:Int; descr=Integer(1)}, {typ:Int; descr=Integer(5)})})}
pat:{id:6; descr:[(y,
Any)]; accept:[id:181; descr:Pair]; fv:[(0, y)]};
body:{typ:(Int,Int), descr:{typ:
(Int,Int); descr= ({typ: Int; descr= Var(0,x)}, {typ: Int; descr= Var(0,y)})}}}], typ:
X1 -> X1 where X1 = (Int,Int), fv:[(0, x)])}}}], typ:X1 -> X1 -> X1 where
X1 = (Int,Int), fv:[])}).({typ:
(Int,Int); descr= ({typ: Int; descr= Integer(2)}, {typ: Int; descr= Integer(3)})})}).({typ:
(Int,Int); descr= ({typ: Int; descr= Integer(1)}, {typ: Int; descr= Integer(5)})})}
tests/typed/tests/union/is_string.ref
View file @
82e58431
{typ:([ Char* ] | Int | `true | `false) -> Bool; descr=Abstraction(name:<none>,
iface:[([ Char* ] | Int | `true | `false, Bool)],
body:[typ:[ Char* ] | Int | `true | `false, accept:Any, branches:
{typ: ([ Char* ] | Int | `true | `false) -> Bool; descr= Abstraction(name:<none>,
iface:[(
[ Char* ] | Int | `true | `false, Bool)],
body:[typ:[ Char* ] | Int | `true |
`false, accept:Any, branches:
{used:true; ghost:false; br_vars_empty:[];
pat:{id:3; descr:[String; []; Constr(String)]; accept:[id:177; descr:String]; fv:[]};
body:{typ:Bool, descr:{typ:Bool; descr=Atom(true)}}},
pat:{id:3; descr:[
String]; accept:[id:177; descr:String]; fv:[]};
body:{typ:Bool, descr:{typ:
Bool; descr= Atom(true)}}} ,