forked from FrankBro/ordo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompiler.fs
38 lines (35 loc) · 1.11 KB
/
Compiler.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Compiler
open System.IO
open Error
open Expr
open Infer
open Parse
let compile (folder: string) (files: string list) =
Infer.resetId ()
let extract state (name: string, expr: Expr) =
let ordoTy =
Infer.infer state expr
|> generalize
let ordoVal = Emit.emit expr
ordoTy, ordoVal
let rec loop (types: Map<string, Ty>) files =
match files with
| [] -> ()
| file :: files ->
let inputFile = sprintf "%s/%s.ordo" folder file
let text =
File.ReadAllLines(inputFile)
|> String.concat "\n"
let expr = parse file text
let ty =
Infer.infer types expr
|> generalize
let output = Emit.emit expr
let outputFile = sprintf "output/%s.lua" file
File.WriteAllText(outputFile, output)
let types = Map.add file ty types
loop types files
Directory.Delete("output", true)
Directory.CreateDirectory("output") |> ignore
File.Copy("std.lua", "output/std.lua")
loop Map.empty files