-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lang0]
occurCheck
-- a pass to create FnRecursive
from Fn
- only in the same module for now
- Loading branch information
Showing
7 changed files
with
67 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(import "./nat-church.scm" zero? add mul sub1) | ||
(import "./nat-church.scm" zero one two three four) | ||
(import "./boolean.scm" if true false) | ||
|
||
;; (claim factorial (-> Nat Nat)) | ||
|
||
(define (factorial n) | ||
(if (zero? n) | ||
one | ||
(mul n (factorial (sub1 n))))) | ||
|
||
factorial | ||
|
||
(assert-equal (factorial zero) one) | ||
(assert-equal (factorial one) one) | ||
(assert-equal (factorial two) two) | ||
(assert-equal (factorial three) (mul three two)) | ||
(assert-equal (factorial four) (mul four (mul three two))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,29 @@ | ||
import dedent from "dedent" | ||
import type { Definition } from "../definition/Definition.js" | ||
import { expIndirectFreeNames } from "../exp/expIndirectFreeNames.js" | ||
import * as Exps from "../exp/index.js" | ||
import { formatExp } from "../format/formatExp.js" | ||
import type { Mod } from "../mod/index.js" | ||
|
||
export function occurCheck(mod: Mod, definition: Definition): void { | ||
// TODO | ||
const indirectFreeNames = expIndirectFreeNames(mod, definition.exp) | ||
|
||
if (!indirectFreeNames.has(definition.name)) return | ||
|
||
if (definition.exp["@kind"] !== "Fn") { | ||
throw new Error( | ||
dedent` | ||
[occurCheck] Only function can be recursive | ||
non-function exp: ${formatExp(definition.exp)} | ||
recursive name: ${definition.name} | ||
`, | ||
) | ||
} | ||
|
||
definition.exp = Exps.FnRecursive( | ||
definition.name, | ||
definition.exp.name, | ||
definition.exp.ret, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters