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
12b4adcf
Commit
12b4adcf
authored
Aug 29, 2008
by
Adam Chlipala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start of stack machine example
parent
fca60eb4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
159 additions
and
0 deletions
+159
-0
.hgignore
.hgignore
+1
-0
Makefile
book/Makefile
+17
-0
StackMachine.v
book/StackMachine.v
+115
-0
Tactics.v
book/Tactics.v
+26
-0
No files found.
.hgignore
View file @
12b4adcf
...
@@ -5,3 +5,4 @@ syntax: glob
...
@@ -5,3 +5,4 @@ syntax: glob
*.depend
*.depend
*.vo
*.vo
*/Makefile.coq
*/Makefile.coq
*/.coq_globals
book/Makefile
0 → 100644
View file @
12b4adcf
MODULES
:=
Tactics StackMachine
VS
:=
$
(
MODULES:%
=
%.v
)
GLOBALS
:=
.coq_globals
.PHONY
:
coq clean
coq
:
Makefile.coq
make
-f
Makefile.coq
Makefile.coq
:
Makefile $(VS)
coq_makefile
$(VS)
\
COQC
=
"coqc -impredicative-set -dump-glob
$(GLOBALS)
"
\
-o
Makefile.coq
clean
::
Makefile.coq
make
-f
Makefile.coq clean
rm
-f
Makefile.coq .depend
book/StackMachine.v
0 → 100644
View file @
12b4adcf
(
*
Copyright
(
c
)
2008
,
Adam
Chlipala
*
*
This
work
is
licensed
under
a
*
Creative
Commons
Attribution
-
Noncommercial
-
No
Derivative
Works
3.0
*
Unported
License
.
*
The
license
text
is
available
at
:
*
http
:
//creativecommons.org/licenses/by-nc-nd/3.0/
*
)
Require
Import
List
.
Require
Import
Tactics
.
(
**
*
Arithmetic
expressions
over
natural
numbers
*
)
Module
Nat
.
(
**
**
Source
language
*
)
Inductive
binop
:
Set
:=
Plus
|
Times
.
Inductive
exp
:
Set
:=
|
Const
:
nat
->
exp
|
Binop
:
binop
->
exp
->
exp
->
exp
.
Definition
binopDenote
(
b
:
binop
)
:
nat
->
nat
->
nat
:=
match
b
with
|
Plus
=>
plus
|
Times
=>
mult
end
.
Fixpoint
expDenote
(
e
:
exp
)
:
nat
:=
match
e
with
|
Const
n
=>
n
|
Binop
b
e1
e2
=>
(
binopDenote
b
)
(
expDenote
e1
)
(
expDenote
e2
)
end
.
(
**
**
Target
language
*
)
Inductive
instr
:
Set
:=
|
IConst
:
nat
->
instr
|
IBinop
:
binop
->
instr
.
Definition
prog
:=
list
instr
.
Definition
stack
:=
list
nat
.
Definition
instrDenote
(
i
:
instr
)
(
s
:
stack
)
:
option
stack
:=
match
i
with
|
IConst
n
=>
Some
(
n
::
s
)
|
IBinop
b
=>
match
s
with
|
arg1
::
arg2
::
s
'
=>
Some
((
binopDenote
b
)
arg1
arg2
::
s
'
)
|
_
=>
None
end
end
.
Fixpoint
progDenote
(
p
:
prog
)
(
s
:
stack
)
{
struct
p
}
:
option
stack
:=
match
p
with
|
nil
=>
Some
s
|
i
::
p
'
=>
match
instrDenote
i
s
with
|
None
=>
None
|
Some
s
'
=>
progDenote
p
'
s
'
end
end
.
(
**
**
Translation
*
)
Fixpoint
compile
(
e
:
exp
)
:
prog
:=
match
e
with
|
Const
n
=>
IConst
n
::
nil
|
Binop
b
e1
e2
=>
compile
e2
++
compile
e1
++
IBinop
b
::
nil
end
.
(
**
**
Translation
correctness
*
)
Lemma
compileCorrect
'
:
forall
e
s
p
,
progDenote
(
compile
e
++
p
)
s
=
progDenote
p
(
expDenote
e
::
s
)
.
induction
e
.
intros
.
unfold
compile
.
unfold
expDenote
.
simpl
.
reflexivity
.
intros
.
unfold
compile
.
fold
compile
.
unfold
expDenote
.
fold
expDenote
.
rewrite
app_ass
.
rewrite
IHe2
.
rewrite
app_ass
.
rewrite
IHe1
.
simpl
.
reflexivity
.
Abort
.
Lemma
compileCorrect
'
:
forall
e
s
p
,
progDenote
(
compile
e
++
p
)
s
=
progDenote
p
(
expDenote
e
::
s
)
.
induction
e
;
crush
.
Qed
.
Theorem
compileCorrect
:
forall
e
,
progDenote
(
compile
e
)
nil
=
Some
(
expDenote
e
::
nil
)
.
intro
.
rewrite
(
app_nil_end
(
compile
e
))
.
rewrite
compileCorrect
'
.
reflexivity
.
Qed
.
End
Nat
.
book/Tactics.v
0 → 100644
View file @
12b4adcf
(
*
Copyright
(
c
)
2008
,
Adam
Chlipala
*
*
This
work
is
licensed
under
a
*
Creative
Commons
Attribution
-
Noncommercial
-
No
Derivative
Works
3.0
*
Unported
License
.
*
The
license
text
is
available
at
:
*
http
:
//creativecommons.org/licenses/by-nc-nd/3.0/
*
)
Require
Import
List
.
Ltac
rewriteHyp
:=
match
goal
with
|
[
H
:
_
|-
_
]
=>
rewrite
H
end
.
Ltac
rewriterP
:=
repeat
(
rewriteHyp
;
autorewrite
with
cpdt
in
*
)
.
Ltac
rewriter
:=
autorewrite
with
cpdt
in
*;
rewriterP
.
Hint
Rewrite
app_ass
:
cpdt
.
Ltac
sintuition
:=
simpl
;
intuition
.
Ltac
crush
:=
sintuition
;
rewriter
;
sintuition
.
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