Clean globals, build debug
This commit is contained in:
parent
2278f0e49d
commit
4784616d98
10 changed files with 54 additions and 42 deletions
|
|
@ -24,7 +24,7 @@ task buildToast, "build toast":
|
||||||
execCmd("nim c --hints:off nimterop/toast.nim")
|
execCmd("nim c --hints:off nimterop/toast.nim")
|
||||||
|
|
||||||
task buildTimeit, "build timer":
|
task buildTimeit, "build timer":
|
||||||
exec "nim c -d:danger tests/timeit"
|
exec "nim c --hints:off -d:danger tests/timeit"
|
||||||
|
|
||||||
task bt, "build toast":
|
task bt, "build toast":
|
||||||
execCmd("nim c --hints:off -d:danger nimterop/toast.nim")
|
execCmd("nim c --hints:off -d:danger nimterop/toast.nim")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import compiler/[ast, idents, lineinfos, modulegraphs, msgs, options, renderer]
|
||||||
|
|
||||||
import "."/treesitter/api
|
import "."/treesitter/api
|
||||||
|
|
||||||
import "."/[globals, getters, exprparser, comphelp, tshelp]
|
import "."/[comphelp, exprparser, globals, getters, tshelp]
|
||||||
|
|
||||||
proc getPtrType*(str: string): string =
|
proc getPtrType*(str: string): string =
|
||||||
result = case str:
|
result = case str:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,18 @@ import os except findExe, sleep
|
||||||
|
|
||||||
import regex
|
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 =
|
proc fixCmd(cmd: string): string =
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
# Replace 'cd d:\abc' with 'd: && cd d:\abc`
|
# Replace 'cd d:\abc' with 'd: && cd d:\abc`
|
||||||
|
|
@ -461,7 +473,7 @@ proc configure*(path, check: string, flags = "") =
|
||||||
if fileExists(path / i):
|
if fileExists(path / i):
|
||||||
echo "# Running autogen.sh"
|
echo "# Running autogen.sh"
|
||||||
|
|
||||||
echo execAction(
|
echoDebug execAction(
|
||||||
&"cd {(path / i).parentDir().sanitizePath} && bash ./autogen.sh").output
|
&"cd {(path / i).parentDir().sanitizePath} && bash ./autogen.sh").output
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
@ -471,7 +483,7 @@ proc configure*(path, check: string, flags = "") =
|
||||||
if fileExists(path / i):
|
if fileExists(path / i):
|
||||||
echo "# Running autoreconf"
|
echo "# Running autoreconf"
|
||||||
|
|
||||||
echo execAction(&"cd {path.sanitizePath} && autoreconf -fi").output
|
echoDebug execAction(&"cd {path.sanitizePath} && autoreconf -fi").output
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -483,7 +495,7 @@ proc configure*(path, check: string, flags = "") =
|
||||||
if flags.len != 0:
|
if flags.len != 0:
|
||||||
cmd &= &" {flags}"
|
cmd &= &" {flags}"
|
||||||
|
|
||||||
echo execAction(cmd).output
|
echoDebug execAction(cmd).output
|
||||||
|
|
||||||
doAssert (path / check).fileExists(), "# Configure failed"
|
doAssert (path / check).fileExists(), "# Configure failed"
|
||||||
|
|
||||||
|
|
@ -577,10 +589,10 @@ proc cmake*(path, check, flags: string) =
|
||||||
|
|
||||||
mkDir(path)
|
mkDir(path)
|
||||||
|
|
||||||
var
|
let
|
||||||
cmd = &"cd {path.sanitizePath} && cmake {flags}"
|
cmd = &"cd {path.sanitizePath} && cmake {flags}"
|
||||||
|
|
||||||
echo execAction(cmd).output
|
echoDebug execAction(cmd).output
|
||||||
|
|
||||||
doAssert (path / check).fileExists(), "# cmake failed"
|
doAssert (path / check).fileExists(), "# cmake failed"
|
||||||
|
|
||||||
|
|
@ -616,7 +628,7 @@ proc make*(path, check: string, flags = "", regex = false) =
|
||||||
if flags.len != 0:
|
if flags.len != 0:
|
||||||
cmd &= &" {flags}"
|
cmd &= &" {flags}"
|
||||||
|
|
||||||
echo execAction(cmd).output
|
echoDebug execAction(cmd).output
|
||||||
|
|
||||||
doAssert findFile(check, path, regex = regex).len != 0, "# make failed"
|
doAssert findFile(check, path, regex = regex).len != 0, "# make failed"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,9 @@ All `{.compileTime.}` procs must be used in a compile time context, e.g. using:
|
||||||
|
|
||||||
import hashes, macros, os, strformat, strutils
|
import hashes, macros, os, strformat, strutils
|
||||||
|
|
||||||
const CIMPORT {.used.} = 1
|
import regex
|
||||||
|
|
||||||
include "."/globals
|
import "."/[build, globals, paths, types]
|
||||||
|
|
||||||
import "."/[build, paths, types]
|
|
||||||
export types
|
export types
|
||||||
|
|
||||||
proc interpPath(dir: string): string=
|
proc interpPath(dir: string): string=
|
||||||
|
|
@ -393,6 +391,7 @@ proc cSearchPath*(path: string): string {.compileTime.}=
|
||||||
proc cDebug*() {.compileTime.} =
|
proc cDebug*() {.compileTime.} =
|
||||||
## Enable debug messages and display the generated Nim code
|
## Enable debug messages and display the generated Nim code
|
||||||
gStateCT.debug = true
|
gStateCT.debug = true
|
||||||
|
build.gDebugCT = true
|
||||||
|
|
||||||
proc cDisableCaching*() {.compileTime.} =
|
proc cDisableCaching*() {.compileTime.} =
|
||||||
## Disable caching of generated Nim code - useful during wrapper development
|
## Disable caching of generated Nim code - useful during wrapper development
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ import regex
|
||||||
|
|
||||||
import "."/plugin
|
import "."/plugin
|
||||||
|
|
||||||
when not declared(CIMPORT):
|
when defined(TOAST):
|
||||||
import compiler/[ast, idents, modulegraphs, options]
|
import compiler/[ast, idents, modulegraphs, options]
|
||||||
|
|
||||||
import "."/treesitter/api
|
import "."/treesitter/api
|
||||||
|
|
||||||
const
|
const
|
||||||
gAtoms {.used.} = @[
|
gAtoms* {.used.} = @[
|
||||||
"field_identifier",
|
"field_identifier",
|
||||||
"identifier",
|
"identifier",
|
||||||
"number_literal",
|
"number_literal",
|
||||||
|
|
@ -21,7 +21,7 @@ const
|
||||||
"type_identifier"
|
"type_identifier"
|
||||||
].toHashSet()
|
].toHashSet()
|
||||||
|
|
||||||
gExpressions {.used.} = @[
|
gExpressions* {.used.} = @[
|
||||||
"parenthesized_expression",
|
"parenthesized_expression",
|
||||||
"bitwise_expression",
|
"bitwise_expression",
|
||||||
"shift_expression",
|
"shift_expression",
|
||||||
|
|
@ -29,32 +29,32 @@ const
|
||||||
"escape_sequence"
|
"escape_sequence"
|
||||||
].toHashSet()
|
].toHashSet()
|
||||||
|
|
||||||
gEnumVals {.used.} = @[
|
gEnumVals* {.used.} = @[
|
||||||
"identifier",
|
"identifier",
|
||||||
"number_literal",
|
"number_literal",
|
||||||
"char_literal"
|
"char_literal"
|
||||||
].concat(toSeq(gExpressions.items))
|
].concat(toSeq(gExpressions.items))
|
||||||
|
|
||||||
type
|
type
|
||||||
Kind = enum
|
Kind* = enum
|
||||||
exactlyOne
|
exactlyOne
|
||||||
oneOrMore # +
|
oneOrMore # +
|
||||||
zeroOrMore # *
|
zeroOrMore # *
|
||||||
zeroOrOne # ?
|
zeroOrOne # ?
|
||||||
orWithNext # !
|
orWithNext # !
|
||||||
|
|
||||||
Ast = object
|
Ast* = object
|
||||||
name*: string
|
name*: string
|
||||||
kind*: Kind
|
kind*: Kind
|
||||||
recursive*: bool
|
recursive*: bool
|
||||||
children*: seq[ref Ast]
|
children*: seq[ref Ast]
|
||||||
when not declared(CIMPORT):
|
when defined(TOAST):
|
||||||
tonim*: proc (ast: ref Ast, node: TSNode, gState: State)
|
tonim*: proc (ast: ref Ast, node: TSNode, gState: State)
|
||||||
regex*: Regex
|
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]
|
compile*, defines*, headers*, includeDirs*, searchDirs*, prefix*, suffix*, symOverride*: seq[string]
|
||||||
|
|
||||||
debug*, includeHeader*, nocache*, nocomments*, past*, preprocess*, pnim*, recurse*: bool
|
debug*, includeHeader*, nocache*, nocomments*, past*, preprocess*, pnim*, recurse*: bool
|
||||||
|
|
@ -87,7 +87,7 @@ type
|
||||||
commentStr*, debugStr*, skipStr*: string
|
commentStr*, debugStr*, skipStr*: string
|
||||||
|
|
||||||
# Nim compiler objects
|
# Nim compiler objects
|
||||||
when not declared(CIMPORT):
|
when defined(TOAST):
|
||||||
constSection*, enumSection*, pragmaSection*, procSection*, typeSection*, varSection*: PNode
|
constSection*, enumSection*, pragmaSection*, procSection*, typeSection*, varSection*: PNode
|
||||||
identCache*: IdentCache
|
identCache*: IdentCache
|
||||||
config*: ConfigRef
|
config*: ConfigRef
|
||||||
|
|
@ -109,24 +109,21 @@ type
|
||||||
ast1, ast2
|
ast1, ast2
|
||||||
|
|
||||||
var
|
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)
|
(s.len != 0)
|
||||||
|
|
||||||
template Bl(s: typed): untyped {.used.} =
|
template Bl*(s: typed): untyped {.used.} =
|
||||||
(s.len == 0)
|
(s.len == 0)
|
||||||
|
|
||||||
when not declared(CIMPORT):
|
# Redirect output to file when required
|
||||||
export gAtoms, gExpressions, gEnumVals, Kind, Ast, AstTable, State, nBl, Bl
|
template gecho*(args: string) =
|
||||||
|
if gState.outputHandle.isNil:
|
||||||
|
stdout.writeLine(args)
|
||||||
|
else:
|
||||||
|
gState.outputHandle.writeLine(args)
|
||||||
|
|
||||||
# Redirect output to file when required
|
template decho*(args: varargs[string, `$`]): untyped =
|
||||||
template gecho*(args: string) =
|
if gState.debug:
|
||||||
if gState.outputHandle.isNil:
|
gecho join(args, "").getCommented()
|
||||||
stdout.writeLine(args)
|
|
||||||
else:
|
|
||||||
gState.outputHandle.writeLine(args)
|
|
||||||
|
|
||||||
template decho*(args: varargs[string, `$`]): untyped =
|
|
||||||
if gState.debug:
|
|
||||||
gecho join(args, "").getCommented()
|
|
||||||
|
|
@ -16,4 +16,3 @@ proc toastExePath*(): string =
|
||||||
|
|
||||||
proc testsIncludeDir*(): string =
|
proc testsIncludeDir*(): string =
|
||||||
nimteropRoot() / "tests" / "include"
|
nimteropRoot() / "tests" / "include"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import os, osproc, strformat, strutils, tables, times
|
||||||
|
|
||||||
import "."/treesitter/[api, c, cpp]
|
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) =
|
proc process(gState: State, path: string, astTable: AstTable) =
|
||||||
doAssert existsFile(path), &"Invalid path {path}"
|
doAssert existsFile(path), &"Invalid path {path}"
|
||||||
|
|
@ -81,6 +81,9 @@ proc main(
|
||||||
doAssert not (includeHeader == true and dynlib.nBl),
|
doAssert not (includeHeader == true and dynlib.nBl),
|
||||||
"`includeHeader` and `dynlib` cannot be used simultaneously"
|
"`includeHeader` and `dynlib` cannot be used simultaneously"
|
||||||
|
|
||||||
|
# Set gDebug in build.nim
|
||||||
|
build.gDebug = debug
|
||||||
|
|
||||||
# Split some arguments with ,
|
# Split some arguments with ,
|
||||||
gState.symOverride = gState.symOverride.getSplitComma()
|
gState.symOverride = gState.symOverride.getSplitComma()
|
||||||
gState.prefix = gState.prefix.getSplitComma()
|
gState.prefix = gState.prefix.getSplitComma()
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,7 @@ when not defined(danger):
|
||||||
switch("define", "nimOldCaseObjects")
|
switch("define", "nimOldCaseObjects")
|
||||||
|
|
||||||
# Prevent outdir override
|
# 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")
|
||||||
|
|
@ -14,7 +14,7 @@ proc testCall(cmd, output: string, exitCode: int, delete = true) =
|
||||||
doAssert outp.contains(output), outp
|
doAssert outp.contains(output), outp
|
||||||
|
|
||||||
var
|
var
|
||||||
cmd = "nim c -f"
|
cmd = "nim c -f --hints:off"
|
||||||
lrcmd = " -r lzma.nim"
|
lrcmd = " -r lzma.nim"
|
||||||
zrcmd = " -r zlib.nim"
|
zrcmd = " -r zlib.nim"
|
||||||
lexp = "liblzma version = "
|
lexp = "liblzma version = "
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ const
|
||||||
|
|
||||||
static:
|
static:
|
||||||
gitPull("https://github.com/jarikomppa/soloud", baseDir, "include/*\nsrc/*\n", checkout = "RELEASE_20200207")
|
gitPull("https://github.com/jarikomppa/soloud", baseDir, "include/*\nsrc/*\n", checkout = "RELEASE_20200207")
|
||||||
cDebug()
|
|
||||||
cDisableCaching()
|
cDisableCaching()
|
||||||
|
|
||||||
cOverride:
|
cOverride:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue