Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
cpdt
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
research
cpdt
Commits
ec72cd0d
Commit
ec72cd0d
authored
Sep 03, 2008
by
Adam Chlipala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Translation
parent
40f0d583
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
StackMachine.v
src/StackMachine.v
+48
-0
No files found.
src/StackMachine.v
View file @
ec72cd0d
...
@@ -720,12 +720,16 @@ Fixpoint tprogDenote ts ts' (p : tprog ts ts') {struct p} : vstack ts -> vstack
...
@@ -720,12 +720,16 @@ Fixpoint tprogDenote ts ts' (p : tprog ts ts') {struct p} : vstack ts -> vstack
(
**
**
Translation
*
)
(
**
**
Translation
*
)
(
**
To
define
our
compilation
,
it
is
useful
to
have
an
auxiliary
function
for
concatenating
two
stack
machine
programs
.
*
)
Fixpoint
tconcat
ts
ts
'
ts
''
(
p
:
tprog
ts
ts
'
)
{
struct
p
}
:
tprog
ts
'
ts
''
->
tprog
ts
ts
''
:=
Fixpoint
tconcat
ts
ts
'
ts
''
(
p
:
tprog
ts
ts
'
)
{
struct
p
}
:
tprog
ts
'
ts
''
->
tprog
ts
ts
''
:=
match
p
in
(
tprog
ts
ts
'
)
return
(
tprog
ts
'
ts
''
->
tprog
ts
ts
''
)
with
match
p
in
(
tprog
ts
ts
'
)
return
(
tprog
ts
'
ts
''
->
tprog
ts
ts
''
)
with
|
TNil
_
=>
fun
p
'
=>
p
'
|
TNil
_
=>
fun
p
'
=>
p
'
|
TCons
_
_
_
i
p1
=>
fun
p
'
=>
TCons
i
(
tconcat
p1
p
'
)
|
TCons
_
_
_
i
p1
=>
fun
p
'
=>
TCons
i
(
tconcat
p1
p
'
)
end
.
end
.
(
**
With
that
function
in
place
,
the
compilation
is
defined
very
similarly
to
how
it
was
before
,
modulo
the
use
of
dependent
typing
.
*
)
Fixpoint
tcompile
t
(
e
:
texp
t
)
(
ts
:
tstack
)
{
struct
e
}
:
tprog
ts
(
t
::
ts
)
:=
Fixpoint
tcompile
t
(
e
:
texp
t
)
(
ts
:
tstack
)
{
struct
e
}
:
tprog
ts
(
t
::
ts
)
:=
match
e
in
(
texp
t
)
return
(
tprog
ts
(
t
::
ts
))
with
match
e
in
(
texp
t
)
return
(
tprog
ts
(
t
::
ts
))
with
|
TNConst
n
=>
TCons
(
TINConst
_
n
)
(
TNil
_
)
|
TNConst
n
=>
TCons
(
TINConst
_
n
)
(
TNil
_
)
...
@@ -734,8 +738,52 @@ Fixpoint tcompile t (e : texp t) (ts : tstack) {struct e} : tprog ts (t :: ts) :
...
@@ -734,8 +738,52 @@ Fixpoint tcompile t (e : texp t) (ts : tstack) {struct e} : tprog ts (t :: ts) :
(
tconcat
(
tcompile
e1
_
)
(
TCons
(
TIBinop
_
b
)
(
TNil
_
)))
(
tconcat
(
tcompile
e1
_
)
(
TCons
(
TIBinop
_
b
)
(
TNil
_
)))
end
.
end
.
(
**
One
interesting
feature
of
the
definition
is
the
underscores
appearing
to
the
right
of
[
=>
]
arrows
.
Haskell
and
ML
programmers
are
quite
familiar
with
compilers
that
infer
type
parameters
to
polymorphic
values
.
In
Coq
,
it
is
possible
to
go
even
further
and
ask
the
system
to
infer
arbitary
terms
,
by
writing
underscores
in
place
of
specific
values
.
You
may
have
noticed
that
we
have
been
calling
functions
without
specifying
all
of
their
arguments
.
For
instance
,
the
recursive
calls
here
to
[
tcompile
]
omit
the
[
t
]
argument
.
Coq
'
s
%
\
textit
{%
#
<
i
>
#
implicit
argument
#
</
i
>
#
%}%
mechanism
automatically
inserts
underscores
for
arguments
that
it
will
probably
be
able
to
infer
.
Inference
of
such
values
is
far
from
complete
,
though
;
generally
,
it
only
works
in
cases
similar
to
those
encountered
with
polymorphic
type
instantiation
in
Haskell
and
ML
.
The
underscores
here
are
being
filled
in
with
stack
types
.
That
is
,
the
Coq
type
inferencer
is
,
in
a
sense
,
inferring
something
about
the
flow
of
control
in
the
translated
programs
.
We
can
take
a
look
at
exactly
which
values
are
filled
in
:
*
)
Print
tcompile
.
Print
tcompile
.
(
**
[[
tcompile
=
fix
tcompile
(
t
:
type
)
(
e
:
texp
t
)
(
ts
:
tstack
)
{
struct
e
}
:
tprog
ts
(
t
::
ts
)
:=
match
e
in
(
texp
t0
)
return
(
tprog
ts
(
t0
::
ts
))
with
|
TNConst
n
=>
TCons
(
TINConst
ts
n
)
(
TNil
(
Nat
::
ts
))
|
TBConst
b
=>
TCons
(
TIBConst
ts
b
)
(
TNil
(
Bool
::
ts
))
|
TBinop
arg1
arg2
res
b
e1
e2
=>
tconcat
(
tcompile
arg2
e2
ts
)
(
tconcat
(
tcompile
arg1
e1
(
arg2
::
ts
))
(
TCons
(
TIBinop
ts
b
)
(
TNil
(
res
::
ts
))))
end
:
forall
t
:
type
,
texp
t
->
forall
ts
:
tstack
,
tprog
ts
(
t
::
ts
)
]]
*
)
(
**
We
can
check
that
the
compiler
generates
programs
that
behave
appropriately
on
our
sample
programs
from
above
:
*
)
Eval
simpl
in
tprogDenote
(
tcompile
(
TNConst
42
)
nil
)
tt
.
(
**
[[
=
(
42
,
tt
)
:
vstack
(
Nat
::
nil
)
]]
*
)
Eval
simpl
in
tprogDenote
(
tcompile
(
TBConst
true
)
nil
)
tt
.
(
**
[[
=
(
true
,
tt
)
:
vstack
(
Bool
::
nil
)
]]
*
)
Eval
simpl
in
tprogDenote
(
tcompile
(
TBinop
TTimes
(
TBinop
TPlus
(
TNConst
2
)
(
TNConst
2
))
(
TNConst
7
))
nil
)
tt
.
(
**
[[
=
(
28
,
tt
)
:
vstack
(
Nat
::
nil
)
]]
*
)
Eval
simpl
in
tprogDenote
(
tcompile
(
TBinop
(
TEq
Nat
)
(
TBinop
TPlus
(
TNConst
2
)
(
TNConst
2
))
(
TNConst
7
))
nil
)
tt
.
(
**
[[
=
(
false
,
tt
)
:
vstack
(
Bool
::
nil
)
]]
*
)
Eval
simpl
in
tprogDenote
(
tcompile
(
TBinop
TLt
(
TBinop
TPlus
(
TNConst
2
)
(
TNConst
2
))
(
TNConst
7
))
nil
)
tt
.
(
**
[[
=
(
true
,
tt
)
:
vstack
(
Bool
::
nil
)
]]
*
)
(
**
**
Translation
correctness
*
)
(
**
**
Translation
correctness
*
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment