Skip to content

Commit

Permalink
wip 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 8, 2024
1 parent d83b36d commit 900b069
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 18 deletions.
53 changes: 40 additions & 13 deletions src/tim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,16 @@ when defined napibuild:
return %*(x)

elif not isMainModule:
# Expose Tim Engine API for Nim development (as a Nimble librayr)
# Expose Tim Engine API for Nim development
# as a Nimble library
import std/enumutils
import tim/engine/ast

export ast, parser, html, json, stdlib
export meta except TimEngine
export localModule, SourceCode, Arg, NodeType

proc initModule(modules: NimNode): NimNode =
proc initLocalModule(modules: NimNode): NimNode =
result = newStmtList()
var functions: seq[string]
modules.expectKind nnkArgList
Expand Down Expand Up @@ -456,17 +457,43 @@ elif not isMainModule:
)

macro initModule*(x: varargs[untyped]): untyped =
initModule(x)
initLocalModule(x)

else:
# Build Tim Engine as a standalone CLI application
discard # todo
# import pkg/kapsis
# import ./tim/app/[runCommand]

# App:
# about:
# "Tim Engine CLI application"
# commands:
# --- "Main Commands"
# $ run
import std/[os, strutils]
import pkg/[kapsis, flatty]
import pkg/kapsis/[runtime, cli]
import tim/engine/ast
# todo move commands
proc cCommand(v: Values) =
## Transpiles a `.timl` file to a target source
let fpath = v.get("timl").getPath.path
let p = parseSnippet(fpath, readFile(getCurrentDir() / fpath))
if likely(not p.hasErrors):
let c = newCompiler(parser.getAst(p), false)
display(c.getHtml().strip)

proc astCommand(v: Values) =
## Build binary AST from a `timl` file
let fpath = v.get("timl").getPath.path
let opath = normalizedPath(getCurrentDir() / v.get("output").getFilename)
let p = parseSnippet(fpath, readFile(getCurrentDir() / fpath))
if likely(not p.hasErrors):
writeFile(opath, flatty.toFlatty(parser.getAst(p)))

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)

commands:
-- "Main Commands"
c path(`timl`):
## Transpile `.timl` file to a target source
ast path(`timl`), filename(`output`):
## Build binary AST for a `timl` file
repr path(`ast`):
## Read from a binary AST to target source
12 changes: 11 additions & 1 deletion src/tim.nims
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@
when defined napibuild:
--define:napiOrWasm
--noMain:on
--passC:"-I/usr/include/node -I/usr/local/include/node"
--passC:"-I/usr/include/node -I/usr/local/include/node"

when isMainModule:
when defined release:
--opt:speed
--define:useMalloc
--define:danger
--checks:off
--passC:"-flto"
--passL:"-flto"
--define:nimAllocPagesViaMalloc
15 changes: 11 additions & 4 deletions tim.nimble
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Package

version = "0.1.0"
author = "George Lemon"
author = "OpenPeeps"
description = "A super fast template engine for cool kids!"
license = "MIT"
srcDir = "src"
skipDirs = @["example", "editors"]
# installExt = @["nim"]
# bin = @["tim"]

installExt = @["nim"]
bin = @["tim"]
binDir = "bin"

# Dependencies

Expand All @@ -23,6 +23,7 @@ requires "checksums"
requires "flatty#head"
requires "malebolgia"
requires "nyml"
requires "kapsis"
# requires "bro"

task node, "Build a NODE addon":
Expand All @@ -41,3 +42,9 @@ task example, "example httpbeast + tim":

task bench, "run some benchmarks":
exec "nim c --threads:on -d:danger --opt:speed --mm:arc -o:./bin/bench example/benchmark.nim"

task dev, "build a dev cli":
exec "nimble build"

task prod, "build a prod cli":
exec "nimble build -d:release"

0 comments on commit 900b069

Please sign in to comment.