Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cimp_2018
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
Per Lindgren
cimp_2018
Commits
9b126046
Commit
9b126046
authored
6 years ago
by
nilfit
Browse files
Options
Downloads
Patches
Plain Diff
fix unify
parent
779d9ba9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
T_Check.ml
+33
-18
33 additions, 18 deletions
T_Check.ml
with
33 additions
and
18 deletions
T_Check.ml
+
33
−
18
View file @
9b126046
...
...
@@ -32,7 +32,7 @@ let of_idt ch (id, (t,s)) =
of_id
id
^
":"
^
of_types
t
^
of_span
ch
s
let
tc_unify
ch
t1
s1
t2
s2
:
types
=
let
tc_unify
ch
t1
t2
s2
:
types
=
match
t1
,
t2
with
|
Tsint
,
Tsint
->
Tsint
|
Tuint32
,
Tuint32
->
Tuint32
...
...
@@ -40,9 +40,19 @@ let tc_unify ch t1 s1 t2 s2 : types =
|
t
,
Tint
->
t
|
_
,
_
->
raise
(
TypeError
(
"Type error: "
^
of_span
ch
s1
^
" : "
^
of_types
t1
^
", does not match "
^
of_span
ch
s2
^
" : "
^
of_types
t2
))
"Type error: Expected "
^
of_types
t1
^
" got "
^
of_types
t2
^
" in:"
^
of_span
ch
s2
))
let
tc_unify2
ch
t1
s1
t2
s2
:
types
=
match
t1
,
t2
with
|
Tsint
,
Tsint
->
Tsint
|
Tuint32
,
Tuint32
->
Tuint32
|
Tint
,
t
->
t
|
t
,
Tint
->
t
|
_
,
_
->
raise
(
TypeError
(
"Type error: "
^
of_types
t1
^
" in:"
^
of_span
ch
s1
^
" does not match "
^
of_types
t2
^
" in:"
^
of_span
ch
s2
))
let
get_id_type
itl
(
id
:
id
)
:
types
*
span
=
try
...
...
@@ -58,37 +68,34 @@ let rec tc_aexpr ch itl (a, span) : Imp.aexpr * types =
let
(
t
,
_
)
=
get_id_type
itl
id
in
(
Imp
.
Avar
id
,
t
)
|
Aadd
((
a1
,
a1_span
)
,
(
a2
,
a2_span
))
->
(* type check a1 against Tsint *)
let
(
ai1
,
t1
)
=
tc_aexpr
ch
itl
(
a1
,
a1_span
)
in
let
_
=
tc_unify
ch
Tsint
(
0
,
0
)
t1
a1_span
in
let
_
=
tc_unify
ch
Tsint
t1
a1_span
in
(* type check a2 against Tsint *)
let
(
ai2
,
t2
)
=
tc_aexpr
ch
itl
(
a2
,
a2_span
)
in
let
_
=
tc_unify
ch
Tsint
(
0
,
0
)
t2
a2_span
in
let
_
=
tc_unify
ch
Tsint
t2
a2_span
in
(
Imp
.
Aadd
(
ai1
,
ai2
)
,
t
1
)
(
Imp
.
Aadd
(
ai1
,
ai2
)
,
Tsin
t
)
|
Aaddu
((
a1
,
a1_span
)
,
(
a2
,
a2_span
))
->
(* type check a1 against Tuint32 *)
let
(
ai1
,
t1
)
=
tc_aexpr
ch
itl
(
a1
,
a1_span
)
in
let
_
=
tc_unify
ch
Tuint32
(
0
,
0
)
t1
a1_span
in
let
_
=
tc_unify
ch
Tuint32
t1
a1_span
in
(* type check a2 against Tuint32 *)
let
(
ai2
,
t2
)
=
tc_aexpr
ch
itl
(
a2
,
a2_span
)
in
let
_
=
tc_unify
ch
Tuint32
(
0
,
0
)
t2
a2_span
in
let
_
=
tc_unify
ch
Tuint32
t2
a2_span
in
(
Imp
.
Aaddu
(
ai1
,
ai2
)
,
t1
)
|
Asub
((
a1
,
a1_span
)
,
(
a2
,
a2_span
))
->
(* type check a1 against Tsint *)
let
(
ai1
,
t1
)
=
tc_aexpr
ch
itl
(
a1
,
a1_span
)
in
let
_
=
tc_unify
ch
Tsint
(
0
,
0
)
t1
a1_span
in
let
_
=
tc_unify
ch
Tsint
t1
a1_span
in
(* type check a2 against Tsint *)
let
(
ai2
,
t2
)
=
tc_aexpr
ch
itl
(
a2
,
a2_span
)
in
let
_
=
tc_unify
ch
Tsint
(
0
,
0
)
t2
a2_span
in
let
_
=
tc_unify
ch
Tsint
t2
a2_span
in
(
Imp
.
Asub
(
ai1
,
ai2
)
,
t1
)
(* with
...
...
@@ -104,9 +111,17 @@ let rec tc_bexpr ch itl (b, span) =
|
Beq
((
a1
,
a1_span
)
,
(
a2
,
a2_span
))
->
let
(
a1
,
t1
)
=
tc_aexpr
ch
itl
(
a1
,
a1_span
)
in
let
(
a2
,
t2
)
=
tc_aexpr
ch
itl
(
a2
,
a2_span
)
in
let
_
=
tc_unify
ch
t1
a1_span
t2
a2_span
in
let
_
=
tc_unify
2
ch
t1
a1_span
t2
a2_span
in
Imp
.
Beq
(
a1
,
a2
)
|
Ble
(
a1
,
a2
)
->
Imp
.
Ble
(
imp_of_aexpr_span
a1
,
imp_of_aexpr_span
a2
)
|
Ble
((
a1
,
a1_span
)
,
(
a2
,
a2_span
))
->
(* type check a1 against Tsint *)
let
(
a1
,
t1
)
=
tc_aexpr
ch
itl
(
a1
,
a1_span
)
in
let
_
=
tc_unify
ch
Tsint
t1
a1_span
in
(* type check a2 against Tsint *)
let
(
a2
,
t2
)
=
tc_aexpr
ch
itl
(
a2
,
a2_span
)
in
let
_
=
tc_unify
ch
Tsint
t2
a2_span
in
Imp
.
Ble
(
a1
,
a2
)
with
|
TypeError
msg
->
raise
(
TypeError
(
msg
^
nl
^
"in expression:"
^
of_span
ch
span
))
...
...
@@ -119,7 +134,7 @@ let rec tc_com ch itl span com =
let
(
_
,
a_span
)
=
a
in
let
(
a
,
ta
)
=
tc_aexpr
ch
itl
a
in
let
(
tid
,
tid_span
)
=
get_id_type
itl
id
in
let
_
=
tc_unify
ch
ta
a_span
tid
tid_span
in
let
_
=
tc_unify
2
ch
ta
a_span
tid
tid_span
in
Imp
.
Cassign
(
id
,
a
)
|
Cif
(
b
,
c1
,
c2
)
->
Imp
.
Cif
(
tc_bexpr
ch
itl
b
,
tc_com_span
ch
itl
c1
,
tc_com_span
ch
itl
c2
)
|
Cwhile
(
b
,
c
)
->
Imp
.
Cwhile
(
tc_bexpr
ch
itl
b
,
tc_com_span
ch
itl
c
)
...
...
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