Cleanup
This commit is contained in:
parent
9ee67da1c2
commit
fb053dd81e
3 changed files with 16 additions and 13 deletions
|
|
@ -228,6 +228,9 @@ proc pDeclaration*(node: ref Ast) =
|
||||||
pFunctionDeclarator(node.children[1], styp)
|
pFunctionDeclarator(node.children[1], styp)
|
||||||
|
|
||||||
proc genNimAst*(node: ref Ast) =
|
proc genNimAst*(node: ref Ast) =
|
||||||
|
if node.isNil:
|
||||||
|
return
|
||||||
|
|
||||||
case node.sym:
|
case node.sym:
|
||||||
of ERROR:
|
of ERROR:
|
||||||
let (line, col) = getLineCol(node)
|
let (line, col) = getLineCol(node)
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ macro cDebug*(): untyped =
|
||||||
|
|
||||||
macro cDefine*(name: static string, val: static string = ""): untyped =
|
macro cDefine*(name: static string, val: static string = ""): untyped =
|
||||||
result = newNimNode(nnkStmtList)
|
result = newNimNode(nnkStmtList)
|
||||||
|
|
||||||
var str = name
|
var str = name
|
||||||
if val.nBl:
|
if val.nBl:
|
||||||
str &= &"=\"{val}\""
|
str &= &"=\"{val}\""
|
||||||
|
|
||||||
if str notin gDefines:
|
if str notin gDefines:
|
||||||
gDefines.add(str)
|
gDefines.add(str)
|
||||||
str = "-D" & str
|
str = "-D" & str
|
||||||
|
|
@ -69,7 +69,7 @@ macro cIncludeDir*(dir: static string): untyped =
|
||||||
result.add(quote do:
|
result.add(quote do:
|
||||||
{.passC: `str`.}
|
{.passC: `str`.}
|
||||||
)
|
)
|
||||||
|
|
||||||
if gDebug:
|
if gDebug:
|
||||||
echo result.repr
|
echo result.repr
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ macro cAddStdDir*(mode = "c"): untyped =
|
||||||
continue
|
continue
|
||||||
elif "End of search list" in line:
|
elif "End of search list" in line:
|
||||||
break
|
break
|
||||||
|
|
||||||
if inc:
|
if inc:
|
||||||
let sline = line.strip()
|
let sline = line.strip()
|
||||||
result.add quote do:
|
result.add quote do:
|
||||||
|
|
@ -131,7 +131,7 @@ macro cCompile*(path: static string): untyped =
|
||||||
dcompile(fpath / "*.c")
|
dcompile(fpath / "*.c")
|
||||||
|
|
||||||
result.add stmt.parseStmt()
|
result.add stmt.parseStmt()
|
||||||
|
|
||||||
if gDebug:
|
if gDebug:
|
||||||
echo result.repr
|
echo result.repr
|
||||||
|
|
||||||
|
|
@ -144,14 +144,14 @@ macro cImport*(filename: static string): untyped =
|
||||||
root = parseLisp(fullpath)
|
root = parseLisp(fullpath)
|
||||||
|
|
||||||
echo "Importing " & fullpath
|
echo "Importing " & fullpath
|
||||||
|
|
||||||
gCode = staticRead(fullpath)
|
gCode = staticRead(fullpath)
|
||||||
gConstStr = ""
|
gConstStr = ""
|
||||||
gTypeStr = ""
|
gTypeStr = ""
|
||||||
|
|
||||||
addHeader(fullpath)
|
addHeader(fullpath)
|
||||||
genNimAst(root)
|
genNimAst(root)
|
||||||
|
|
||||||
if gConstStr.nBl:
|
if gConstStr.nBl:
|
||||||
if gDebug:
|
if gDebug:
|
||||||
echo "const\n" & gConstStr
|
echo "const\n" & gConstStr
|
||||||
|
|
@ -170,6 +170,6 @@ macro cImport*(filename: static string): untyped =
|
||||||
if gDebug:
|
if gDebug:
|
||||||
echo gProcStr
|
echo gProcStr
|
||||||
result.add gProcStr.parseStmt()
|
result.add gProcStr.parseStmt()
|
||||||
|
|
||||||
if gDebug:
|
if gDebug:
|
||||||
echo result.repr
|
echo result.repr
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ var
|
||||||
|
|
||||||
proc tokenize(fullpath: string) =
|
proc tokenize(fullpath: string) =
|
||||||
var collect = ""
|
var collect = ""
|
||||||
|
|
||||||
gTokens = @[]
|
gTokens = @[]
|
||||||
idx = 0
|
idx = 0
|
||||||
for i in staticExec("toast -m " & fullpath):
|
for i in staticExec("toast -m " & fullpath):
|
||||||
|
|
@ -53,7 +53,7 @@ proc readFromTokens(): ref Ast =
|
||||||
elif gTokens[idx] == ")":
|
elif gTokens[idx] == ")":
|
||||||
echo "Poor AST"
|
echo "Poor AST"
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
proc printAst*(node: ref Ast, offset=""): string =
|
proc printAst*(node: ref Ast, offset=""): string =
|
||||||
|
|
@ -68,5 +68,5 @@ proc printAst*(node: ref Ast, offset=""): string =
|
||||||
|
|
||||||
proc parseLisp*(fullpath: string): ref Ast =
|
proc parseLisp*(fullpath: string): ref Ast =
|
||||||
tokenize(fullpath)
|
tokenize(fullpath)
|
||||||
|
|
||||||
return readFromTokens()
|
return readFromTokens()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue