aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-11-27 16:58:11 -0600
committerGanesh Viswanathan <dev@genotrance.com>2018-11-27 16:58:11 -0600
commitfb053dd81eca9a45a813a7d7b0de868c28203976 (patch)
tree8e04de8313ef128ee35f8d473b98671b698ae276
parent9ee67da1c254db70b84712a96c33389f5f3feb9b (diff)
downloadnimterop-fb053dd81eca9a45a813a7d7b0de868c28203976.tar.gz
nimterop-fb053dd81eca9a45a813a7d7b0de868c28203976.zip
Cleanup
-rw-r--r--nimterop/ast.nim3
-rw-r--r--nimterop/cimport.nim20
-rw-r--r--nimterop/lisp.nim6
3 files changed, 16 insertions, 13 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim
index a84f503..cc1cd61 100644
--- a/nimterop/ast.nim
+++ b/nimterop/ast.nim
@@ -228,6 +228,9 @@ proc pDeclaration*(node: ref Ast) =
pFunctionDeclarator(node.children[1], styp)
proc genNimAst*(node: ref Ast) =
+ if node.isNil:
+ return
+
case node.sym:
of ERROR:
let (line, col) = getLineCol(node)
diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim
index 8a85145..9c63665 100644
--- a/nimterop/cimport.nim
+++ b/nimterop/cimport.nim
@@ -33,11 +33,11 @@ macro cDebug*(): untyped =
macro cDefine*(name: static string, val: static string = ""): untyped =
result = newNimNode(nnkStmtList)
-
+
var str = name
if val.nBl:
str &= &"=\"{val}\""
-
+
if str notin gDefines:
gDefines.add(str)
str = "-D" & str
@@ -69,7 +69,7 @@ macro cIncludeDir*(dir: static string): untyped =
result.add(quote do:
{.passC: `str`.}
)
-
+
if gDebug:
echo result.repr
@@ -85,7 +85,7 @@ macro cAddStdDir*(mode = "c"): untyped =
continue
elif "End of search list" in line:
break
-
+
if inc:
let sline = line.strip()
result.add quote do:
@@ -131,7 +131,7 @@ macro cCompile*(path: static string): untyped =
dcompile(fpath / "*.c")
result.add stmt.parseStmt()
-
+
if gDebug:
echo result.repr
@@ -144,14 +144,14 @@ macro cImport*(filename: static string): untyped =
root = parseLisp(fullpath)
echo "Importing " & fullpath
-
+
gCode = staticRead(fullpath)
gConstStr = ""
gTypeStr = ""
-
+
addHeader(fullpath)
genNimAst(root)
-
+
if gConstStr.nBl:
if gDebug:
echo "const\n" & gConstStr
@@ -170,6 +170,6 @@ macro cImport*(filename: static string): untyped =
if gDebug:
echo gProcStr
result.add gProcStr.parseStmt()
-
+
if gDebug:
- echo result.repr \ No newline at end of file
+ echo result.repr
diff --git a/nimterop/lisp.nim b/nimterop/lisp.nim
index c4a3b54..36c810a 100644
--- a/nimterop/lisp.nim
+++ b/nimterop/lisp.nim
@@ -8,7 +8,7 @@ var
proc tokenize(fullpath: string) =
var collect = ""
-
+
gTokens = @[]
idx = 0
for i in staticExec("toast -m " & fullpath):
@@ -53,7 +53,7 @@ proc readFromTokens(): ref Ast =
elif gTokens[idx] == ")":
echo "Poor AST"
quit(1)
-
+
idx += 1
proc printAst*(node: ref Ast, offset=""): string =
@@ -68,5 +68,5 @@ proc printAst*(node: ref Ast, offset=""): string =
proc parseLisp*(fullpath: string): ref Ast =
tokenize(fullpath)
-
+
return readFromTokens()