From fb053dd81eca9a45a813a7d7b0de868c28203976 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Tue, 27 Nov 2018 16:58:11 -0600 Subject: Cleanup --- nimterop/ast.nim | 3 +++ nimterop/cimport.nim | 20 ++++++++++---------- nimterop/lisp.nim | 6 +++--- 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() -- cgit v1.2.3