diff --git a/_site/essays/2018-01-16-how-to-prove-a-compiler-correct.html b/_site/essays/2018-01-16-how-to-prove-a-compiler-correct.html index 8936417..9f2da97 100644 --- a/_site/essays/2018-01-16-how-to-prove-a-compiler-correct.html +++ b/_site/essays/2018-01-16-how-to-prove-a-compiler-correct.html @@ -64,7 +64,7 @@

DSL & Compiler

compile (Plus a1 a2) = compile a2 ++ compile a1 ++ [SPlus] compile (Minus a1 a2) = compile a2 ++ compile a1 ++ [SMinus] compile (Times a1 a2) = compile a2 ++ compile a1 ++ [STimes] -

The cases for plus/minus/times are the cases that are slightly non-obvious, because they can contain further recursive expressions, but if you think about what the eval function is doing, once the stack machine finishes evaluating everything that a1 compiled to, the number that the left branch evaluated to should be on the top of the stack. Then once it finishes evaluating what a2 compiles to the number that the right branch evaluated to should be on the top of the stack. This means that evaluating e.g. SPlus will put the sum on the top of the stack, as expected. That’s a pretty informal argument about correctness, but we’ll have a chance to get more formal later.

+

The cases for plus/minus/times are the cases that are slightly non-obvious, because they can contain further recursive expressions, but if you think about what the eval function is doing, once the stack machine finishes evaluating everything that a2 compiled to, the number that the left branch evaluated to should be on the top of the stack. Then once it finishes evaluating what a1 compiles to the number that the right branch evaluated to should be on the top of the stack (the reversal is so that they are in the right order when popped off). This means that evaluating e.g. SPlus will put the sum on the top of the stack, as expected. That’s a pretty informal argument about correctness, but we’ll have a chance to get more formal later.

Formalizing

Now that we have a Haskell compiler, we want to prove it correct! So what do we do? First, we want to convert this to Coq using the hs-to-coq tool. There are full instructions at https://github.com/dbp/howtoproveacompiler, but the main command that will convert src/Compiler.hs to src/Compiler.v:

STACK_YAML=hs-to-coq/stack.yaml stack exec hs-to-coq -- -o src/ src/Compiler.hs -e hs-to-coq/base/edits
diff --git a/_site/rss.xml b/_site/rss.xml index 14b40d3..a7c2271 100644 --- a/_site/rss.xml +++ b/_site/rss.xml @@ -51,7 +51,7 @@ compile (Num n) = [Plus a1 a2) = compile a2 ++ compile a1 ++ [SPlus] compile (Minus a1 a2) = compile a2 ++ compile a1 ++ [SMinus] compile (Times a1 a2) = compile a2 ++ compile a1 ++ [STimes] -

The cases for plus/minus/times are the cases that are slightly non-obvious, because they can contain further recursive expressions, but if you think about what the eval function is doing, once the stack machine finishes evaluating everything that a1 compiled to, the number that the left branch evaluated to should be on the top of the stack. Then once it finishes evaluating what a2 compiles to the number that the right branch evaluated to should be on the top of the stack. This means that evaluating e.g. SPlus will put the sum on the top of the stack, as expected. That’s a pretty informal argument about correctness, but we’ll have a chance to get more formal later.

+

The cases for plus/minus/times are the cases that are slightly non-obvious, because they can contain further recursive expressions, but if you think about what the eval function is doing, once the stack machine finishes evaluating everything that a2 compiled to, the number that the left branch evaluated to should be on the top of the stack. Then once it finishes evaluating what a1 compiles to the number that the right branch evaluated to should be on the top of the stack (the reversal is so that they are in the right order when popped off). This means that evaluating e.g. SPlus will put the sum on the top of the stack, as expected. That’s a pretty informal argument about correctness, but we’ll have a chance to get more formal later.

Formalizing

Now that we have a Haskell compiler, we want to prove it correct! So what do we do? First, we want to convert this to Coq using the hs-to-coq tool. There are full instructions at https://github.com/dbp/howtoproveacompiler, but the main command that will convert src/Compiler.hs to src/Compiler.v:

STACK_YAML=hs-to-coq/stack.yaml stack exec hs-to-coq -- -o src/ src/Compiler.hs -e hs-to-coq/base/edits
diff --git a/essays/2018-01-16-how-to-prove-a-compiler-correct.markdown b/essays/2018-01-16-how-to-prove-a-compiler-correct.markdown index 32dc594..c200508 100644 --- a/essays/2018-01-16-how-to-prove-a-compiler-correct.markdown +++ b/essays/2018-01-16-how-to-prove-a-compiler-correct.markdown @@ -112,13 +112,13 @@ compile (Times a1 a2) = compile a2 ++ compile a1 ++ [STimes] The cases for plus/minus/times are the cases that are slightly non-obvious, because they can contain further recursive expressions, but if you think about what the `eval` function is doing, once the stack machine _finishes_ evaluating -everything that `a1` compiled to, the number that the left branch evaluated to -should be on the top of the stack. Then once it finishes evaluating what `a2` +everything that `a2` compiled to, the number that the left branch evaluated to +should be on the top of the stack. Then once it finishes evaluating what `a1` compiles to the number that the right branch evaluated to should be on the top -of the stack. This means that evaluating e.g. `SPlus` will put the -sum on the top of the stack, as expected. That's a pretty informal -argument about correctness, but we'll have a chance to get more formal -later. +of the stack (the reversal is so that they are in the right order when popped +off). This means that evaluating e.g. `SPlus` will put the sum on the top of the +stack, as expected. That's a pretty informal argument about correctness, but +we'll have a chance to get more formal later. ## Formalizing