-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemily.em
More file actions
133 lines (103 loc) · 2.46 KB
/
emily.em
File metadata and controls
133 lines (103 loc) · 2.46 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Self-hosting interpreter for e2
profile experimental
from project.util import *
from project import (reader, parser, execution)
from project.compiler import
cs.CsCompiler, cpp.CppCompiler, js.JsCompiler, debug.TypePrinter
let cmdAst = false
let cmdAst2 = false
let cmdExported = false
let cmdExecute = null
let cmdTarget = null
let cmdValid = false
let cmdOutput = null
let cmdDriver = "interpreter"
let scriptArgv = array()
# --- Parse arguments ---
do
let i = argv.iter
let nextArg = function(expect)
if (!i.more)
stderr.println
"Missing argument for -" + expect
exit 2
i.next
while (i.more)
let arg = i.next
with arg match
"--ast" =
cmdAst = true
"--ast2" =
cmdAst2 = true
"--exported" =
cmdExported = true
"-e" =
cmdExecute = nextArg "e"
"-d" = # TODO: Or "driver"
cmdDriver = nextArg "d"
"-o" =
cmdOutput = nextArg "o"
_ = do
if ("-" == arg 0)
stderr.print "Unrecognized argument" arg ln
exit 2
cmdTarget = arg
if (cmdExecute || cmdTarget)
while (i.more)
scriptArgv.append(i.next)
cmdValid = true
if (!cmdValid)
stderr.println "Must supply either file name or -e"
exit 2
# --- Run ---
let codeIter = do
if cmdTarget
file.in cmdTarget
else
cmdExecute.iter
let ast = reader.makeAst codeIter null
if cmdTarget
execution.setEntryFile cmdTarget
codeIter.close
if cmdAst
println (ast.toString)
else
let exe = parser.exeFromAst ast
if cmdAst2
println (exe.toString)
else
let exePrint = function(s)
if (cmdOutput == null || cmdOutput == "-")
println s
else
let x = file.out cmdOutput
x.write s
x.close
with cmdDriver match
"interpreter" = do
if (cmdOutput)
stderr.println "-o not understood when running interpreter"
exit 2
from execution import (ObjectValue, StringValue, ArrayValue, defaultScope)
let scope = new ObjectValue(defaultScope)
let scriptArgvValue = array()
let i = scriptArgv.iter
while (i.more)
scriptArgvValue.append (new StringValue(i.next))
scope.atoms.set "argv" (new ArrayValue(scriptArgvValue))
let exportScope = new ObjectValue
exe.evalSequence(scope, exportScope)
if cmdExported
execution.debugScopeDump(exportScope)
"cs" = do
let x = CsCompiler.build exe
exePrint x
"cpp" = do
let x = CppCompiler.build exe
exePrint x
"js" = do
let x = JsCompiler.build exe
exePrint x
"type" = do
let x = TypePrinter.build exe
exePrint x