-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- basic cli usage - basic typechecking abilities (incomplete)
- Loading branch information
1 parent
d4b7134
commit b34eeb7
Showing
7 changed files
with
427 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { parseArgs } from "https://deno.land/std@0.209.0/cli/mod.ts"; | ||
|
||
const { _, ...args } = parseArgs(Deno.args, { | ||
string: ["_", "out"], | ||
alias: { "out": ["-o", "--out"] }, | ||
}); | ||
|
||
const [command, file, ...rest] = _; | ||
const out = args.out ?? "compiled.rkt"; | ||
|
||
// commands: compile, check | ||
|
||
switch (command) { | ||
case "compile": { | ||
const { tokenize, parse } = await import("./main.ts"); | ||
const { compile } = await import("./compile.ts"); | ||
const source = await Deno.readTextFile(file); | ||
const tokens = tokenize(source); | ||
const ast = parse(tokens); | ||
const compiled = compile(ast); | ||
await Deno.writeTextFile(out, compiled); | ||
break; | ||
} | ||
case "check": { | ||
const { tokenize, parse } = await import("./main.ts"); | ||
const { typecheck } = await import("./typecheck.ts"); | ||
const source = await Deno.readTextFile(file); | ||
const tokens = tokenize(source); | ||
const ast = parse(tokens); | ||
const errors = typecheck(ast); | ||
if (errors.length > 0) { | ||
console.error(errors); | ||
Deno.exit(1); | ||
} | ||
break; | ||
} | ||
default: | ||
console.error(`Unknown command: ${command}`); | ||
Deno.exit(1); | ||
} |
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,30 @@ | ||
#lang htdp/isl+ | ||
;; k : Number Number -> Number | ||
(define (k x y) | ||
"") | ||
;; v : String -> Number | ||
(define (v u) | ||
(string->number | ||
u | ||
)) | ||
(+ | ||
(k | ||
1 | ||
2 | ||
) | ||
(v | ||
"" | ||
) | ||
) | ||
(+ | ||
(v | ||
1 | ||
) | ||
(k | ||
2 | ||
) | ||
) | ||
(k | ||
3 | ||
"" | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
(define (k x : Number & y : Number -> Number) | ||
"") | ||
(define (v u : String -> Number) | ||
(string->number u)) | ||
(+ (k 1 2) (v "3")) | ||
;; wrong example | ||
(+ (v 1) (k 2)) | ||
(k 3 "4") |
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
Oops, something went wrong.