Clean globals, build debug

This commit is contained in:
Ganesh Viswanathan 2020-04-30 08:54:18 -05:00
commit 4784616d98
10 changed files with 54 additions and 42 deletions

View file

@ -24,7 +24,7 @@ task buildToast, "build toast":
execCmd("nim c --hints:off nimterop/toast.nim")
task buildTimeit, "build timer":
exec "nim c -d:danger tests/timeit"
exec "nim c --hints:off -d:danger tests/timeit"
task bt, "build toast":
execCmd("nim c --hints:off -d:danger nimterop/toast.nim")

View file

@ -6,7 +6,7 @@ import compiler/[ast, idents, lineinfos, modulegraphs, msgs, options, renderer]
import "."/treesitter/api
import "."/[globals, getters, exprparser, comphelp, tshelp]
import "."/[comphelp, exprparser, globals, getters, tshelp]
proc getPtrType*(str: string): string =
result = case str:

View file

@ -4,6 +4,18 @@ import os except findExe, sleep
import regex
# build specific debug since we cannot import globals (yet)
var
gDebug* = false
gDebugCT* {.compileTime.} = false
proc echoDebug(str: string) =
let str = "\n# " & str.strip().replace("\n", "\n# ")
when nimvm:
if gDebugCT: echo str
else:
if gDebug: echo str
proc fixCmd(cmd: string): string =
when defined(Windows):
# Replace 'cd d:\abc' with 'd: && cd d:\abc`
@ -461,7 +473,7 @@ proc configure*(path, check: string, flags = "") =
if fileExists(path / i):
echo "# Running autogen.sh"
echo execAction(
echoDebug execAction(
&"cd {(path / i).parentDir().sanitizePath} && bash ./autogen.sh").output
break
@ -471,7 +483,7 @@ proc configure*(path, check: string, flags = "") =
if fileExists(path / i):
echo "# Running autoreconf"
echo execAction(&"cd {path.sanitizePath} && autoreconf -fi").output
echoDebug execAction(&"cd {path.sanitizePath} && autoreconf -fi").output
break
@ -483,7 +495,7 @@ proc configure*(path, check: string, flags = "") =
if flags.len != 0:
cmd &= &" {flags}"
echo execAction(cmd).output
echoDebug execAction(cmd).output
doAssert (path / check).fileExists(), "# Configure failed"
@ -577,10 +589,10 @@ proc cmake*(path, check, flags: string) =
mkDir(path)
var
let
cmd = &"cd {path.sanitizePath} && cmake {flags}"
echo execAction(cmd).output
echoDebug execAction(cmd).output
doAssert (path / check).fileExists(), "# cmake failed"
@ -616,7 +628,7 @@ proc make*(path, check: string, flags = "", regex = false) =
if flags.len != 0:
cmd &= &" {flags}"
echo execAction(cmd).output
echoDebug execAction(cmd).output
doAssert findFile(check, path, regex = regex).len != 0, "# make failed"

View file

@ -17,11 +17,9 @@ All `{.compileTime.}` procs must be used in a compile time context, e.g. using:
import hashes, macros, os, strformat, strutils
const CIMPORT {.used.} = 1
import regex
include "."/globals
import "."/[build, paths, types]
import "."/[build, globals, paths, types]
export types
proc interpPath(dir: string): string=
@ -393,6 +391,7 @@ proc cSearchPath*(path: string): string {.compileTime.}=
proc cDebug*() {.compileTime.} =
## Enable debug messages and display the generated Nim code
gStateCT.debug = true
build.gDebugCT = true
proc cDisableCaching*() {.compileTime.} =
## Disable caching of generated Nim code - useful during wrapper development

View file

@ -4,13 +4,13 @@ import regex
import "."/plugin
when not declared(CIMPORT):
when defined(TOAST):
import compiler/[ast, idents, modulegraphs, options]
import "."/treesitter/api
const
gAtoms {.used.} = @[
gAtoms* {.used.} = @[
"field_identifier",
"identifier",
"number_literal",
@ -21,7 +21,7 @@ const
"type_identifier"
].toHashSet()
gExpressions {.used.} = @[
gExpressions* {.used.} = @[
"parenthesized_expression",
"bitwise_expression",
"shift_expression",
@ -29,32 +29,32 @@ const
"escape_sequence"
].toHashSet()
gEnumVals {.used.} = @[
gEnumVals* {.used.} = @[
"identifier",
"number_literal",
"char_literal"
].concat(toSeq(gExpressions.items))
type
Kind = enum
Kind* = enum
exactlyOne
oneOrMore # +
zeroOrMore # *
zeroOrOne # ?
orWithNext # !
Ast = object
Ast* = object
name*: string
kind*: Kind
recursive*: bool
children*: seq[ref Ast]
when not declared(CIMPORT):
when defined(TOAST):
tonim*: proc (ast: ref Ast, node: TSNode, gState: State)
regex*: Regex
AstTable {.used.} = TableRef[string, seq[ref Ast]]
AstTable* {.used.} = TableRef[string, seq[ref Ast]]
State = ref object
State* = ref object
compile*, defines*, headers*, includeDirs*, searchDirs*, prefix*, suffix*, symOverride*: seq[string]
debug*, includeHeader*, nocache*, nocomments*, past*, preprocess*, pnim*, recurse*: bool
@ -87,7 +87,7 @@ type
commentStr*, debugStr*, skipStr*: string
# Nim compiler objects
when not declared(CIMPORT):
when defined(TOAST):
constSection*, enumSection*, pragmaSection*, procSection*, typeSection*, varSection*: PNode
identCache*: IdentCache
config*: ConfigRef
@ -109,24 +109,21 @@ type
ast1, ast2
var
gStateCT {.compiletime, used.} = new(State)
gStateCT* {.compiletime, used.} = new(State)
template nBl(s: typed): untyped {.used.} =
template nBl*(s: typed): untyped {.used.} =
(s.len != 0)
template Bl(s: typed): untyped {.used.} =
template Bl*(s: typed): untyped {.used.} =
(s.len == 0)
when not declared(CIMPORT):
export gAtoms, gExpressions, gEnumVals, Kind, Ast, AstTable, State, nBl, Bl
# Redirect output to file when required
template gecho*(args: string) =
if gState.outputHandle.isNil:
stdout.writeLine(args)
else:
gState.outputHandle.writeLine(args)
# Redirect output to file when required
template gecho*(args: string) =
if gState.outputHandle.isNil:
stdout.writeLine(args)
else:
gState.outputHandle.writeLine(args)
template decho*(args: varargs[string, `$`]): untyped =
if gState.debug:
gecho join(args, "").getCommented()
template decho*(args: varargs[string, `$`]): untyped =
if gState.debug:
gecho join(args, "").getCommented()

View file

@ -16,4 +16,3 @@ proc toastExePath*(): string =
proc testsIncludeDir*(): string =
nimteropRoot() / "tests" / "include"

View file

@ -2,7 +2,7 @@ import os, osproc, strformat, strutils, tables, times
import "."/treesitter/[api, c, cpp]
import "."/[ast, ast2, globals, getters, grammar, build, tshelp]
import "."/[ast, ast2, build, globals, getters, grammar, tshelp]
proc process(gState: State, path: string, astTable: AstTable) =
doAssert existsFile(path), &"Invalid path {path}"
@ -81,6 +81,9 @@ proc main(
doAssert not (includeHeader == true and dynlib.nBl),
"`includeHeader` and `dynlib` cannot be used simultaneously"
# Set gDebug in build.nim
build.gDebug = debug
# Split some arguments with ,
gState.symOverride = gState.symOverride.getSplitComma()
gState.prefix = gState.prefix.getSplitComma()

View file

@ -22,4 +22,7 @@ when not defined(danger):
switch("define", "nimOldCaseObjects")
# Prevent outdir override
switch("out", currentSourcePath.parentDir() / "toast".addFileExt(ExeExt))
switch("out", currentSourcePath.parentDir() / "toast".addFileExt(ExeExt))
# Define TOAST for globals.nim
switch("define", "TOAST")

View file

@ -14,7 +14,7 @@ proc testCall(cmd, output: string, exitCode: int, delete = true) =
doAssert outp.contains(output), outp
var
cmd = "nim c -f"
cmd = "nim c -f --hints:off"
lrcmd = " -r lzma.nim"
zrcmd = " -r zlib.nim"
lexp = "liblzma version = "

View file

@ -7,7 +7,6 @@ const
static:
gitPull("https://github.com/jarikomppa/soloud", baseDir, "include/*\nsrc/*\n", checkout = "RELEASE_20200207")
cDebug()
cDisableCaching()
cOverride: