Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
why3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nils Fitinghoff
why3
Commits
18255260
Commit
18255260
authored
Sep 19, 2018
by
nilfit
Browse files
Options
Downloads
Patches
Plain Diff
simplify detection of functions when translating types
parent
239eff71
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
drivers/rust.drv
+0
-2
0 additions, 2 deletions
drivers/rust.drv
src/mlw/rust_printer.ml
+16
-27
16 additions, 27 deletions
src/mlw/rust_printer.ml
with
16 additions
and
29 deletions
drivers/rust.drv
+
0
−
2
View file @
18255260
...
@@ -7,8 +7,6 @@ theory BuiltIn
...
@@ -7,8 +7,6 @@ theory BuiltIn
end
end
module HighOrd
module HighOrd
(* used by the printer to safely detect function types *)
syntax type (->) "FUNCTION_ARROW"
(* TODO this does not work when there are multiple @ *)
(* TODO this does not work when there are multiple @ *)
syntax val ( @ ) "%1(%2)"
syntax val ( @ ) "%1(%2)"
end
end
...
...
This diff is collapsed.
Click to expand it.
src/mlw/rust_printer.ml
+
16
−
27
View file @
18255260
...
@@ -135,19 +135,20 @@ module MLToRust = struct
...
@@ -135,19 +135,20 @@ module MLToRust = struct
(* TODO make sure we don't extract any ghosts *)
(* TODO make sure we don't extract any ghosts *)
let
id_is_func
=
id_equal
ts_func
.
ts_name
let
rec
translate_ty
info
(
t
:
ty
)
:
Rust
.
ty
=
let
rec
translate_ty
info
(
t
:
ty
)
:
Rust
.
ty
=
match
t
with
match
t
with
|
Tvar
tvs
->
Rust
.
Tvar
tvs
|
Tvar
tvs
->
Rust
.
Tvar
tvs
|
Ttuple
tl
->
Rust
.
Ttuple
(
List
.
map
(
translate_ty
info
)
tl
)
|
Ttuple
tl
->
Rust
.
Ttuple
(
List
.
map
(
translate_ty
info
)
tl
)
(* specialization of a generic type *)
(* function *)
|
Tapp
(
ts
,
tl
)
->
|
Tapp
(
ts
,
tl
)
when
id_is_func
ts
->
let
syn
=
query_syntax
info
.
syntax
ts
in
match
syn
with
|
Some
"FUNCTION_ARROW"
->
(* recursively look for multi-argument functions *)
let
args_and_res
=
function_sig
info
t
in
let
args_and_res
=
function_sig
info
t
in
let
args
,
res
=
Lists
.
chop_last
args_and_res
in
let
args
,
res
=
Lists
.
chop_last
args_and_res
in
Rust
.
Tfn
(
args
,
res
)
Rust
.
Tfn
(
args
,
res
)
(* specialization of a generic type *)
|
Tapp
(
ts
,
tl
)
->
match
query_syntax
info
.
syntax
ts
with
|
Some
s
->
Rust
.
Tsyn
(
s
,
List
.
map
(
translate_ty
info
)
tl
)
|
Some
s
->
Rust
.
Tsyn
(
s
,
List
.
map
(
translate_ty
info
)
tl
)
|
None
->
|
None
->
let
tl
=
List
.
map
(
translate_ty
info
)
tl
in
let
tl
=
List
.
map
(
translate_ty
info
)
tl
in
...
@@ -155,13 +156,10 @@ module MLToRust = struct
...
@@ -155,13 +156,10 @@ module MLToRust = struct
and
function_sig
info
(
t
:
ty
)
:
Rust
.
ty
list
=
and
function_sig
info
(
t
:
ty
)
:
Rust
.
ty
list
=
match
t
with
match
t
with
|
Tapp
(
ts
,
tl
)
->
|
Tapp
(
ts
,
tl
)
when
id_is_func
ts
->
(
match
query_syntax
info
.
syntax
ts
with
|
Some
"FUNCTION_ARROW"
->
(
match
tl
with
(
match
tl
with
|
[
ta
;
tb
]
->
translate_ty
info
ta
::
function_sig
info
tb
|
[
ta
;
tb
]
->
translate_ty
info
ta
::
function_sig
info
tb
|
_
->
assert
false
)
|
_
->
assert
false
)
|
_
->
[
translate_ty
info
t
])
|
_
->
[
translate_ty
info
t
]
|
_
->
[
translate_ty
info
t
]
let
translate_var
(
info
:
info
)
((
id
,
ty
,
_ghost
)
:
var
)
:
Rust
.
var
=
let
translate_var
(
info
:
info
)
((
id
,
ty
,
_ghost
)
:
var
)
:
Rust
.
var
=
...
@@ -207,15 +205,6 @@ module MLToRust = struct
...
@@ -207,15 +205,6 @@ module MLToRust = struct
exception
MissingSyntaxLiteral
exception
MissingSyntaxLiteral
let
get_record
info
rs
=
match
Mid
.
find_opt
rs
.
rs_name
info
.
mo_known_map
with
|
Some
{
pd_node
=
PDtype
itdl
}
->
let
eq_rs
{
itd_constructors
}
=
List
.
exists
(
rs_equal
rs
)
itd_constructors
in
let
itd
=
List
.
find
eq_rs
itdl
in
List
.
filter
(
fun
e
->
not
(
rs_ghost
e
))
itd
.
itd_fields
|
_
->
[]
let
box_expr
(
e
:
Rust
.
expr
)
=
Rust
.
Esyntax
(
"Box::new(%1)"
,
[
e
])
let
box_expr
(
e
:
Rust
.
expr
)
=
Rust
.
Esyntax
(
"Box::new(%1)"
,
[
e
])
let
rec
translate_expr
(
info
:
info
)
(
e
:
expr
)
:
Rust
.
expr
=
let
rec
translate_expr
(
info
:
info
)
(
e
:
expr
)
:
Rust
.
expr
=
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment