-
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.
Merge pull request #10 from FrankBro/compiler
Compiler
- Loading branch information
Showing
11 changed files
with
186 additions
and
85 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 |
---|---|---|
@@ -1,6 +1,39 @@ | ||
module Compiler | ||
|
||
// Project management is files in the program themselves | ||
open Error | ||
open Expr | ||
open Infer | ||
|
||
// ordo compile a program by compiling 1 file that opens a bunch of files | ||
// same for a lib, it returns a record with all the sub modules | ||
type State = { | ||
Types: Map<string, Ty> | ||
Values: Map<string, Value> | ||
} | ||
with | ||
static member New = { | ||
Types = Map.empty | ||
Values = Map.empty | ||
} | ||
|
||
let compileExprs (exprs: (string * Expr) list) = | ||
Infer.resetId () | ||
let extract state (name: string, expr: Expr) = | ||
let ordoTy = | ||
Infer.infer state.Types expr | ||
|> generalize | ||
let ordoVal = Eval.eval state.Values expr | ||
ordoTy, ordoVal | ||
let rec loop (state: State) exprs = | ||
match exprs with | ||
| [] -> raise (compilerError NoExprsProvided) | ||
| [x] -> extract state x | ||
| x :: xs -> | ||
let ordoTy, ordoVal = extract state x | ||
let name = fst x | ||
printfn "%s = %s : %s" name (stringOfValue ordoVal) (stringOfTy ordoTy) | ||
let state = | ||
{ state with | ||
Types = Map.add name ordoTy state.Types | ||
Values = Map.add name ordoVal state.Values | ||
} | ||
loop state xs | ||
loop State.New exprs |
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
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.