Skip to content

Commit 7875f69

Browse files
committed
cli commands - generate binary ast
Signed-off-by: George Lemon <georgelemon@protonmail.com>
1 parent a038fb2 commit 7875f69

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/tim.nim

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ when isMainModule:
1313
import ./tim/app/[build, dev]
1414

1515
commands:
16+
#
17+
# Source to Source commands
18+
# Used to transpile `timl` code to a specific target source
19+
# Planning to support: HTML, Nim, JS, PHP, Python, Ruby and more
20+
#
1621
-- "Source to Source"
17-
# transpile `timl` code to a specific target source.
18-
# Default `html`
1922
src path(`timl`),
2023
string(-t), # choose a target (default target `html`)
2124
string(-o), # save output to file
@@ -26,9 +29,13 @@ when isMainModule:
2629
bool(--watch): # enable browser sync on live changes
2730
## Transpile `timl` to specific target source
2831

29-
# -- "VM"
30-
# Runs the `timl` code in a virtual machine.
32+
ast path(`timl`):
33+
## Transpile timl code to AST representation
3134

35+
#
36+
# Development commands
37+
# Used to manage Tim Engine packages locally
38+
#
3239
-- "Development"
3340
init:
3441
## Initializes a new Tim Engine package

src/tim/app/build.nim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ proc srcCommand*(v: Values) =
5454
var compiler = codegen.initCodeGen(script, module, mainChunk)
5555

5656
try:
57-
compiler.genScript(program)
57+
compiler.genScript(program, isMainScript = true)
5858
let vmInstance = newVm()
5959
let output = vmInstance.interpret(script, mainChunk)
6060

@@ -70,4 +70,18 @@ proc srcCommand*(v: Values) =
7070

7171
except TimCompileError as e:
7272
echo e.msg
73-
73+
74+
75+
76+
#
77+
# AST
78+
#
79+
proc astCommand*(v: Values) =
80+
## Generate the AST representation of a `timl` script
81+
let
82+
srcPath = getCurrentDir() / $(v.get("timl").getPath)
83+
timlCode = readFile(srcPath)
84+
85+
var program: Ast # the AST representation of the script
86+
parser.parseScript(program, timlCode)
87+
writeFile(srcPath & ".ast", toFlatty(program))

src/tim/engine/stdlib/libsystem.nim

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ proc initSystemOps(script: Script, module: Module) =
4646
# number type operators
4747

4848
for T in [(tyInt, tyFloat), (tyFloat, tyInt)]:
49-
# XXX: this is perhaps a bit inefficient, optimizing this could help
50-
5149
script.addProc(module, "+", @[paramDef("a", T[0])], T[0])
5250
script.addProc(module, "-", @[paramDef("a", T[0])], T[0])
5351

@@ -80,16 +78,6 @@ proc modSystem*(script: Script): Module =
8078
result.initSystemTypes()
8179
script.initSystemOps(result)
8280

83-
# discard result.add(genType(tyHtmlElement, "h1"))
84-
85-
# script.addProc(result, ">", @[paramDef("a", tyHtmlElement, kindStr = "div"), paramDef("b", tyHtmlElement, kindStr = "div")], tyString,
86-
# proc (args: StackView): Value =
87-
# result = initValue("ayayay"))
88-
89-
# script.addProc(result, "h1", @[], tyString,
90-
# proc (args: StackView): Value =
91-
# result = initValue("<h1></h1>"))
92-
9381
# string operators
9482
script.addProc(result, "==", @[paramDef("a", tyString), paramDef("b", tyString)], tyBool,
9583
proc (args: StackView): Value =

0 commit comments

Comments
 (0)