bootstraps with new template symbol binding rules
This commit is contained in:
parent
83a0a31276
commit
4d01408a46
4 changed files with 20 additions and 21 deletions
|
|
@ -359,6 +359,8 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
return symChoice(c.c, n, s, scClosed)
|
return symChoice(c.c, n, s, scClosed)
|
||||||
elif Contains(c.toMixin, s.name.id):
|
elif Contains(c.toMixin, s.name.id):
|
||||||
return symChoice(c.c, n, s, scForceOpen)
|
return symChoice(c.c, n, s, scForceOpen)
|
||||||
|
else:
|
||||||
|
return symChoice(c.c, n, s, scOpen)
|
||||||
result = n
|
result = n
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
result.sons[i] = semTemplBody(c, n.sons[i])
|
result.sons[i] = semTemplBody(c, n.sons[i])
|
||||||
|
|
@ -399,7 +401,7 @@ proc transformToExpr(n: PNode): PNode =
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
case n.sons[i].kind
|
case n.sons[i].kind
|
||||||
of nkCommentStmt, nkEmpty, nkNilLit:
|
of nkCommentStmt, nkEmpty, nkNilLit:
|
||||||
nil
|
discard
|
||||||
else:
|
else:
|
||||||
if realStmt == - 1: realStmt = i
|
if realStmt == - 1: realStmt = i
|
||||||
else: realStmt = - 2
|
else: realStmt = - 2
|
||||||
|
|
@ -409,7 +411,7 @@ proc transformToExpr(n: PNode): PNode =
|
||||||
n.kind = nkBlockExpr
|
n.kind = nkBlockExpr
|
||||||
#nkIfStmt: n.kind = nkIfExpr // this is not correct!
|
#nkIfStmt: n.kind = nkIfExpr // this is not correct!
|
||||||
else:
|
else:
|
||||||
nil
|
discard
|
||||||
|
|
||||||
proc semTemplateDef(c: PContext, n: PNode): PNode =
|
proc semTemplateDef(c: PContext, n: PNode): PNode =
|
||||||
var s: PSym
|
var s: PSym
|
||||||
|
|
@ -476,8 +478,6 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
||||||
SymTabReplace(c.currentScope.symbols, proto, s)
|
SymTabReplace(c.currentScope.symbols, proto, s)
|
||||||
if n.sons[patternPos].kind != nkEmpty:
|
if n.sons[patternPos].kind != nkEmpty:
|
||||||
c.patterns.add(s)
|
c.patterns.add(s)
|
||||||
#if s.name.s == "move":
|
|
||||||
# echo renderTree(result)
|
|
||||||
|
|
||||||
proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
|
proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
template templToExpand(s: expr): expr =
|
template templToExpand(s: expr): expr =
|
||||||
|
|
@ -522,7 +522,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
result = handleSym(c, n, s)
|
result = handleSym(c, n, s)
|
||||||
of nkBindStmt:
|
of nkBindStmt:
|
||||||
result = semBindStmt(c.c, n, c.toBind)
|
result = semBindStmt(c.c, n, c.toBind)
|
||||||
of nkEmpty, nkSym..nkNilLit: nil
|
of nkEmpty, nkSym..nkNilLit: discard
|
||||||
of nkCurlyExpr:
|
of nkCurlyExpr:
|
||||||
# we support '(pattern){x}' to bind a subpattern to a parameter 'x';
|
# we support '(pattern){x}' to bind a subpattern to a parameter 'x';
|
||||||
# '(pattern){|x}' does the same but the matches will be gathered in 'x'
|
# '(pattern){|x}' does the same but the matches will be gathered in 'x'
|
||||||
|
|
@ -543,8 +543,8 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
of nkCallKinds:
|
of nkCallKinds:
|
||||||
let s = QualifiedLookUp(c.c, n.sons[0], {})
|
let s = QualifiedLookUp(c.c, n.sons[0], {})
|
||||||
if s != nil:
|
if s != nil:
|
||||||
if s.owner == c.owner and s.kind == skParam: nil
|
if s.owner == c.owner and s.kind == skParam: discard
|
||||||
elif Contains(c.toBind, s.id): nil
|
elif Contains(c.toBind, s.id): discard
|
||||||
elif templToExpand(s):
|
elif templToExpand(s):
|
||||||
return semPatternBody(c, semTemplateExpr(c.c, n, s, false))
|
return semPatternBody(c, semTemplateExpr(c.c, n, s, false))
|
||||||
|
|
||||||
|
|
@ -588,7 +588,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
return newIdentNode(s.name, n.info)
|
return newIdentNode(s.name, n.info)
|
||||||
of nkPar:
|
of nkPar:
|
||||||
if n.len == 1: return semPatternBody(c, n.sons[0])
|
if n.len == 1: return semPatternBody(c, n.sons[0])
|
||||||
else: nil
|
else: discard
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
result.sons[i] = semPatternBody(c, n.sons[i])
|
result.sons[i] = semPatternBody(c, n.sons[i])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@
|
||||||
|
|
||||||
{.push hints:off}
|
{.push hints:off}
|
||||||
|
|
||||||
proc c_strcmp(a, b: CString): cint {.header: "<string.h>",
|
proc c_strcmp(a, b: cstring): cint {.header: "<string.h>",
|
||||||
noSideEffect, importc: "strcmp".}
|
noSideEffect, importc: "strcmp".}
|
||||||
proc c_memcmp(a, b: CString, size: int): cint {.header: "<string.h>",
|
proc c_memcmp(a, b: cstring, size: int): cint {.header: "<string.h>",
|
||||||
noSideEffect, importc: "memcmp".}
|
noSideEffect, importc: "memcmp".}
|
||||||
proc c_memcpy(a, b: CString, size: int) {.header: "<string.h>", importc: "memcpy".}
|
proc c_memcpy(a, b: cstring, size: int) {.header: "<string.h>", importc: "memcpy".}
|
||||||
proc c_strlen(a: CString): int {.header: "<string.h>",
|
proc c_strlen(a: cstring): int {.header: "<string.h>",
|
||||||
noSideEffect, importc: "strlen".}
|
noSideEffect, importc: "strlen".}
|
||||||
proc c_memset(p: pointer, value: cint, size: int) {.
|
proc c_memset(p: pointer, value: cint, size: int) {.
|
||||||
header: "<string.h>", importc: "memset".}
|
header: "<string.h>", importc: "memset".}
|
||||||
|
|
@ -49,7 +49,7 @@ when not defined(SIGINT):
|
||||||
SIGINT = cint(2)
|
SIGINT = cint(2)
|
||||||
SIGSEGV = cint(11)
|
SIGSEGV = cint(11)
|
||||||
SIGTERM = cint(15)
|
SIGTERM = cint(15)
|
||||||
elif defined(macosx):
|
elif defined(macosx) or defined(linux):
|
||||||
const
|
const
|
||||||
SIGABRT = cint(6)
|
SIGABRT = cint(6)
|
||||||
SIGFPE = cint(8)
|
SIGFPE = cint(8)
|
||||||
|
|
@ -92,27 +92,27 @@ proc c_fgetc(stream: C_TextFileStar): int {.importc: "fgetc",
|
||||||
header: "<stdio.h>".}
|
header: "<stdio.h>".}
|
||||||
proc c_ungetc(c: int, f: C_TextFileStar) {.importc: "ungetc",
|
proc c_ungetc(c: int, f: C_TextFileStar) {.importc: "ungetc",
|
||||||
header: "<stdio.h>".}
|
header: "<stdio.h>".}
|
||||||
proc c_putc(c: Char, stream: C_TextFileStar) {.importc: "putc",
|
proc c_putc(c: char, stream: C_TextFileStar) {.importc: "putc",
|
||||||
header: "<stdio.h>".}
|
header: "<stdio.h>".}
|
||||||
proc c_fprintf(f: C_TextFileStar, frmt: CString) {.
|
proc c_fprintf(f: C_TextFileStar, frmt: cstring) {.
|
||||||
importc: "fprintf", header: "<stdio.h>", varargs.}
|
importc: "fprintf", header: "<stdio.h>", varargs.}
|
||||||
proc c_printf(frmt: CString) {.
|
proc c_printf(frmt: cstring) {.
|
||||||
importc: "printf", header: "<stdio.h>", varargs.}
|
importc: "printf", header: "<stdio.h>", varargs.}
|
||||||
|
|
||||||
proc c_fopen(filename, mode: cstring): C_TextFileStar {.
|
proc c_fopen(filename, mode: cstring): C_TextFileStar {.
|
||||||
importc: "fopen", header: "<stdio.h>".}
|
importc: "fopen", header: "<stdio.h>".}
|
||||||
proc c_fclose(f: C_TextFileStar) {.importc: "fclose", header: "<stdio.h>".}
|
proc c_fclose(f: C_TextFileStar) {.importc: "fclose", header: "<stdio.h>".}
|
||||||
|
|
||||||
proc c_sprintf(buf, frmt: CString) {.header: "<stdio.h>",
|
proc c_sprintf(buf, frmt: cstring) {.header: "<stdio.h>",
|
||||||
importc: "sprintf", varargs, noSideEffect.}
|
importc: "sprintf", varargs, noSideEffect.}
|
||||||
# we use it only in a way that cannot lead to security issues
|
# we use it only in a way that cannot lead to security issues
|
||||||
|
|
||||||
proc c_fread(buf: Pointer, size, n: int, f: C_BinaryFileStar): int {.
|
proc c_fread(buf: pointer, size, n: int, f: C_BinaryFileStar): int {.
|
||||||
importc: "fread", header: "<stdio.h>".}
|
importc: "fread", header: "<stdio.h>".}
|
||||||
proc c_fseek(f: C_BinaryFileStar, offset: clong, whence: int): int {.
|
proc c_fseek(f: C_BinaryFileStar, offset: clong, whence: int): int {.
|
||||||
importc: "fseek", header: "<stdio.h>".}
|
importc: "fseek", header: "<stdio.h>".}
|
||||||
|
|
||||||
proc c_fwrite(buf: Pointer, size, n: int, f: C_BinaryFileStar): int {.
|
proc c_fwrite(buf: pointer, size, n: int, f: C_BinaryFileStar): int {.
|
||||||
importc: "fwrite", header: "<stdio.h>".}
|
importc: "fwrite", header: "<stdio.h>".}
|
||||||
|
|
||||||
proc c_exit(errorcode: cint) {.importc: "exit", header: "<stdlib.h>".}
|
proc c_exit(errorcode: cint) {.importc: "exit", header: "<stdlib.h>".}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ when NoFakeVars:
|
||||||
const
|
const
|
||||||
IOFBF = cint(0)
|
IOFBF = cint(0)
|
||||||
IONBF = cint(4)
|
IONBF = cint(4)
|
||||||
elif defined(macosx):
|
elif defined(macosx) or defined(linux):
|
||||||
const
|
const
|
||||||
IOFBF = cint(0)
|
IOFBF = cint(0)
|
||||||
IONBF = cint(2)
|
IONBF = cint(2)
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -1,7 +1,6 @@
|
||||||
version 0.9.4
|
version 0.9.4
|
||||||
=============
|
=============
|
||||||
|
|
||||||
- make new templating symbol binding rules work
|
|
||||||
- document new templating symbol binding rules
|
- document new templating symbol binding rules
|
||||||
- convert all with "nimrod pretty"
|
- convert all with "nimrod pretty"
|
||||||
- make '--implicitStatic:on' the default
|
- make '--implicitStatic:on' the default
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue