feat: only compute all free variables during a-conversion
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -26,3 +26,5 @@ go.work.sum
|
||||
.env
|
||||
|
||||
*.log
|
||||
|
||||
profile/
|
||||
8
Makefile
8
Makefile
@@ -13,5 +13,13 @@ thunk: it
|
||||
saccharine: it
|
||||
@ ./lambda.exe - < ./samples/saccharine.txt
|
||||
|
||||
prof:
|
||||
@ go tool pprof -top profile/cpu.prof
|
||||
|
||||
graph:
|
||||
@ go tool pprof -raw -output=profile/cpu.raw profile/cpu.prof
|
||||
@ go tool pprof -svg profile/cpu.prof > profile/cpu.svg
|
||||
@ open profile/cpu.svg
|
||||
|
||||
saccharineX: it
|
||||
@ ./lambda.exe -x - < ./samples/saccharine.txt > saccharine.out
|
||||
BIN
cmd/.DS_Store
vendored
Normal file
BIN
cmd/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"time"
|
||||
|
||||
"git.maximhutz.com/max/lambda/internal/cli"
|
||||
@@ -14,6 +15,14 @@ import (
|
||||
|
||||
// Run main application.
|
||||
func main() {
|
||||
f, err := os.Create("profile/cpu.prof")
|
||||
cli.HandleError(err)
|
||||
defer f.Close()
|
||||
|
||||
err = pprof.StartCPUProfile(f)
|
||||
cli.HandleError(err)
|
||||
defer pprof.StopCPUProfile()
|
||||
|
||||
options, err := config.FromArgs()
|
||||
cli.HandleError(err)
|
||||
|
||||
|
||||
BIN
internal/.DS_Store
vendored
Normal file
BIN
internal/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
pkg/.DS_Store
vendored
Normal file
BIN
pkg/.DS_Store
vendored
Normal file
Binary file not shown.
14
pkg/lambda/is_free_variable.go
Normal file
14
pkg/lambda/is_free_variable.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package lambda
|
||||
|
||||
func IsFreeVariable(n string, e Expression) bool {
|
||||
switch e := e.(type) {
|
||||
case *Variable:
|
||||
return e.Value == n
|
||||
case *Abstraction:
|
||||
return e.Parameter != n && IsFreeVariable(n, e.Body)
|
||||
case *Application:
|
||||
return IsFreeVariable(n, e.Abstraction) || IsFreeVariable(n, e.Argument)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,12 @@ func Substitute(e *Expression, target string, replacement Expression) {
|
||||
return
|
||||
}
|
||||
|
||||
replacementFreeVars := GetFreeVariables(replacement)
|
||||
if !replacementFreeVars.Has(typed.Parameter) {
|
||||
if !IsFreeVariable(typed.Parameter, replacement) {
|
||||
Substitute(&typed.Body, target, replacement)
|
||||
return
|
||||
}
|
||||
|
||||
replacementFreeVars := GetFreeVariables(replacement)
|
||||
used := GetFreeVariables(typed.Body)
|
||||
used.Merge(replacementFreeVars)
|
||||
freshVar := GenerateFreshName(used)
|
||||
|
||||
BIN
pkg/saccharine/.DS_Store
vendored
Normal file
BIN
pkg/saccharine/.DS_Store
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user