This commit is contained in:
Ganesh Viswanathan 2018-11-27 16:58:11 -06:00
commit fb053dd81e
3 changed files with 16 additions and 13 deletions

View file

@ -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)

View file

@ -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
echo result.repr

View file

@ -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()