Skip to content

Commit

Permalink
update compilers/nimc and cli
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Apr 24, 2024
1 parent 10e7cb1 commit 04d48e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
28 changes: 25 additions & 3 deletions src/tim/app/compileCmd.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import std/[os, strutils]
import pkg/kapsis/[cli, runtime]
import ../engine/[parser, compilers/html]
import ../engine/parser
import ../engine/logging
import ../engine/compilers/[html, nimc]

proc cCommand*(v: Values) =
## Transpiles a `.timl` file to a target source
let fpath = v.get("timl").getPath.path
let ext = v.get("ext").getStr
let pretty = v.has("pretty")
let p = parseSnippet(fpath, readFile(getCurrentDir() / fpath))
if likely(not p.hasErrors):
let c = newCompiler(parser.getAst(p), false)
display(c.getHtml().strip)
if ext == "html":
let c = newCompiler(parser.getAst(p), pretty == false)
if likely(not c.hasErrors):
display c.getHtml().strip
else:
for err in c.logger.errors:
display err
displayInfo c.logger.filePath
quit(1)
elif ext == "nim":
let c = nimc.newCompiler(parser.getAst(p))
display c.exportCode()
else:
displayError("Unknown target `" & ext & "`")
quit(1)
else:
for err in p.logger.errors:
display(err)
displayInfo p.logger.filePath
quit(1)
17 changes: 13 additions & 4 deletions src/tim/app/reprCmd.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import std/[os, strutils]
import pkg/flatty
import pkg/kapsis/[cli, runtime]
import ../engine/[parser, ast, compilers/html]
import ../engine/[parser, ast]
import ../engine/compilers/[html, nimc]

proc reprCommand*(v: Values) =
## Read a binary AST to target source
let fpath = v.get("ast").getPath.path
let c = newCompiler(flatty.fromFlatty(readFile(fpath), Ast), false)
if likely(not c.hasErrors):
display(c.getHtml().strip)
let ext = v.get("ext").getStr
let pretty = v.has("pretty")
if ext == "html":
let c = html.newCompiler(flatty.fromFlatty(readFile(fpath), Ast), pretty == false)
display c.getHtml().strip
elif ext == "nim":
let c = nimc.newCompiler(flatty.fromFlatty(readFile(fpath), Ast))
display c.exportCode()
else:
displayError("Unknown target `" & ext & "`")
quit(1)
1 change: 0 additions & 1 deletion src/tim/engine/compilers/nimc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ proc getVar(c: var NimCompiler, node: Node): string =
of true:
writeToResult(newConst, 0, args = [node.varName, c.getValue(node.varValue)])


proc getAttrs(c: var NimCompiler, attrs: HtmlAttributes): string =
## Write HTMLAttributes
var i = 0
Expand Down
1 change: 0 additions & 1 deletion tim.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ requires "checksums"
requires "flatty#head"
requires "malebolgia"
requires "nyml"
requires "kapsis#head"
# requires "bro"

task node, "Build a NODE addon":
Expand Down

0 comments on commit 04d48e4

Please sign in to comment.