aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2020-04-30 08:54:18 -0500
committerGanesh Viswanathan <dev@genotrance.com>2020-04-30 08:54:18 -0500
commit4784616d987c3b7c73125af44bec999184444a22 (patch)
tree6f504622e4baa82f3b7cd0494243b5d811e77e1c
parent2278f0e49d4da012370bb8e907640b9d89ae54fa (diff)
downloadnimterop-ast1quiet.tar.gz
nimterop-ast1quiet.zip
Clean globals, build debugast1quiet
-rw-r--r--nimterop.nimble2
-rw-r--r--nimterop/ast2.nim2
-rw-r--r--nimterop/build.nim24
-rw-r--r--nimterop/cimport.nim7
-rw-r--r--nimterop/globals.nim47
-rw-r--r--nimterop/paths.nim1
-rw-r--r--nimterop/toast.nim5
-rw-r--r--nimterop/toast.nims5
-rw-r--r--tests/getheader.nims2
-rw-r--r--tests/tsoloud.nim1
10 files changed, 54 insertions, 42 deletions
diff --git a/nimterop.nimble b/nimterop.nimble
index 579d315..a6ece7c 100644
--- a/nimterop.nimble
+++ b/nimterop.nimble
@@ -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")
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim
index 474ec69..13f2ba2 100644
--- a/nimterop/ast2.nim
+++ b/nimterop/ast2.nim
@@ -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:
diff --git a/nimterop/build.nim b/nimterop/build.nim
index 5bfec76..6fa44cb 100644
--- a/nimterop/build.nim
+++ b/nimterop/build.nim
@@ -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"
diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim
index 4cb364d..e081633 100644
--- a/nimterop/cimport.nim
+++ b/nimterop/cimport.nim
@@ -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
diff --git a/nimterop/globals.nim b/nimterop/globals.nim
index b9352a4..ae9a6d0 100644
--- a/nimterop/globals.nim
+++ b/nimterop/globals.nim
@@ -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() \ No newline at end of file
+template decho*(args: varargs[string, `$`]): untyped =
+ if gState.debug:
+ gecho join(args, "").getCommented() \ No newline at end of file
diff --git a/nimterop/paths.nim b/nimterop/paths.nim
index 0ae461f..fa245b3 100644
--- a/nimterop/paths.nim
+++ b/nimterop/paths.nim
@@ -16,4 +16,3 @@ proc toastExePath*(): string =
proc testsIncludeDir*(): string =
nimteropRoot() / "tests" / "include"
-
diff --git a/nimterop/toast.nim b/nimterop/toast.nim
index 7a41874..78708f5 100644
--- a/nimterop/toast.nim
+++ b/nimterop/toast.nim
@@ -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()
diff --git a/nimterop/toast.nims b/nimterop/toast.nims
index 94c9f20..83d5cf4 100644
--- a/nimterop/toast.nims
+++ b/nimterop/toast.nims
@@ -22,4 +22,7 @@ when not defined(danger):
switch("define", "nimOldCaseObjects")
# Prevent outdir override
-switch("out", currentSourcePath.parentDir() / "toast".addFileExt(ExeExt)) \ No newline at end of file
+switch("out", currentSourcePath.parentDir() / "toast".addFileExt(ExeExt))
+
+# Define TOAST for globals.nim
+switch("define", "TOAST") \ No newline at end of file
diff --git a/tests/getheader.nims b/tests/getheader.nims
index 2e6530f..1e8027a 100644
--- a/tests/getheader.nims
+++ b/tests/getheader.nims
@@ -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 = "
diff --git a/tests/tsoloud.nim b/tests/tsoloud.nim
index afff0f1..8dd197c 100644
--- a/tests/tsoloud.nim
+++ b/tests/tsoloud.nim
@@ -7,7 +7,6 @@ const
static:
gitPull("https://github.com/jarikomppa/soloud", baseDir, "include/*\nsrc/*\n", checkout = "RELEASE_20200207")
- cDebug()
cDisableCaching()
cOverride: