tables work in 'const' sections; echo supports 'nil' strings; minor cleanups
This commit is contained in:
parent
9431b734b4
commit
ecd0dea091
11 changed files with 69 additions and 52 deletions
|
|
@ -83,7 +83,9 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): PRope =
|
||||||
else:
|
else:
|
||||||
result = toRope("NIM_NIL")
|
result = toRope("NIM_NIL")
|
||||||
of nkStrLit..nkTripleStrLit:
|
of nkStrLit..nkTripleStrLit:
|
||||||
if skipTypes(ty, abstractVarRange).kind == tyString:
|
if n.strVal.isNil:
|
||||||
|
result = ropecg(p.module, "((#NimStringDesc*) NIM_NIL)", [])
|
||||||
|
elif skipTypes(ty, abstractVarRange).kind == tyString:
|
||||||
var id = nodeTableTestOrSet(p.module.dataCache, n, gBackendId)
|
var id = nodeTableTestOrSet(p.module.dataCache, n, gBackendId)
|
||||||
if id == gBackendId:
|
if id == gBackendId:
|
||||||
# string literal not found in the cache:
|
# string literal not found in the cache:
|
||||||
|
|
@ -950,7 +952,7 @@ proc genEcho(p: BProc, n: PNode) =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
for i in countup(0, n.len-1):
|
for i in countup(0, n.len-1):
|
||||||
initLocExpr(p, n.sons[i], a)
|
initLocExpr(p, n.sons[i], a)
|
||||||
appf(args, ", ($1)->data", [rdLoc(a)])
|
appf(args, ", $1? ($1)->data:\"nil\"", [rdLoc(a)])
|
||||||
linefmt(p, cpsStmts, "printf($1$2);$n",
|
linefmt(p, cpsStmts, "printf($1$2);$n",
|
||||||
makeCString(repeatStr(n.len, "%s") & tnl), args)
|
makeCString(repeatStr(n.len, "%s") & tnl), args)
|
||||||
|
|
||||||
|
|
@ -2173,7 +2175,7 @@ proc genConstExpr(p: BProc, n: PNode): PRope =
|
||||||
var cs: TBitSet
|
var cs: TBitSet
|
||||||
toBitSet(n, cs)
|
toBitSet(n, cs)
|
||||||
result = genRawSetData(cs, int(getSize(n.typ)))
|
result = genRawSetData(cs, int(getSize(n.typ)))
|
||||||
of nkBracket, nkPar, nkClosure:
|
of nkBracket, nkPar, nkClosure, nkObjConstr:
|
||||||
var t = skipTypes(n.typ, abstractInst)
|
var t = skipTypes(n.typ, abstractInst)
|
||||||
if t.kind == tySequence:
|
if t.kind == tySequence:
|
||||||
result = genConstSeq(p, n, t)
|
result = genConstSeq(p, n, t)
|
||||||
|
|
|
||||||
|
|
@ -253,15 +253,6 @@ proc genConstStmt(p: BProc, t: PNode) =
|
||||||
elif c.typ.kind in ConstantDataTypes and lfNoDecl notin c.loc.flags and
|
elif c.typ.kind in ConstantDataTypes and lfNoDecl notin c.loc.flags and
|
||||||
c.ast.len != 0:
|
c.ast.len != 0:
|
||||||
if not emitLazily(c): requestConstImpl(p, c)
|
if not emitLazily(c): requestConstImpl(p, c)
|
||||||
when false:
|
|
||||||
# generate the data:
|
|
||||||
fillLoc(c.loc, locData, c.typ, mangleName(c), OnUnknown)
|
|
||||||
if sfImportc in c.flags:
|
|
||||||
appf(p.module.s[cfsData], "extern NIM_CONST $1 $2;$n",
|
|
||||||
[getTypeDesc(p.module, c.typ), c.loc.r])
|
|
||||||
else:
|
|
||||||
appf(p.module.s[cfsData], "NIM_CONST $1 $2 = $3;$n",
|
|
||||||
[getTypeDesc(p.module, c.typ), c.loc.r, genConstExpr(p, c.ast)])
|
|
||||||
|
|
||||||
proc genIf(p: BProc, n: PNode, d: var TLoc) =
|
proc genIf(p: BProc, n: PNode, d: var TLoc) =
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -30,47 +30,32 @@ type
|
||||||
|
|
||||||
PLLStream* = ref TLLStream
|
PLLStream* = ref TLLStream
|
||||||
|
|
||||||
proc llStreamOpen*(data: string): PLLStream
|
proc llStreamOpen*(data: string): PLLStream =
|
||||||
proc llStreamOpen*(f: var File): PLLStream
|
|
||||||
proc llStreamOpen*(filename: string, mode: FileMode): PLLStream
|
|
||||||
proc llStreamOpen*(): PLLStream
|
|
||||||
proc llStreamOpenStdIn*(): PLLStream
|
|
||||||
proc llStreamClose*(s: PLLStream)
|
|
||||||
proc llStreamRead*(s: PLLStream, buf: pointer, bufLen: int): int
|
|
||||||
proc llStreamReadLine*(s: PLLStream, line: var string): bool
|
|
||||||
proc llStreamReadAll*(s: PLLStream): string
|
|
||||||
proc llStreamWrite*(s: PLLStream, data: string)
|
|
||||||
proc llStreamWrite*(s: PLLStream, data: char)
|
|
||||||
proc llStreamWrite*(s: PLLStream, buf: pointer, buflen: int)
|
|
||||||
proc llStreamWriteln*(s: PLLStream, data: string)
|
|
||||||
# implementation
|
|
||||||
|
|
||||||
proc llStreamOpen(data: string): PLLStream =
|
|
||||||
new(result)
|
new(result)
|
||||||
result.s = data
|
result.s = data
|
||||||
result.kind = llsString
|
result.kind = llsString
|
||||||
|
|
||||||
proc llStreamOpen(f: var File): PLLStream =
|
proc llStreamOpen*(f: var File): PLLStream =
|
||||||
new(result)
|
new(result)
|
||||||
result.f = f
|
result.f = f
|
||||||
result.kind = llsFile
|
result.kind = llsFile
|
||||||
|
|
||||||
proc llStreamOpen(filename: string, mode: FileMode): PLLStream =
|
proc llStreamOpen*(filename: string, mode: FileMode): PLLStream =
|
||||||
new(result)
|
new(result)
|
||||||
result.kind = llsFile
|
result.kind = llsFile
|
||||||
if not open(result.f, filename, mode): result = nil
|
if not open(result.f, filename, mode): result = nil
|
||||||
|
|
||||||
proc llStreamOpen(): PLLStream =
|
proc llStreamOpen*(): PLLStream =
|
||||||
new(result)
|
new(result)
|
||||||
result.kind = llsNone
|
result.kind = llsNone
|
||||||
|
|
||||||
proc llStreamOpenStdIn(): PLLStream =
|
proc llStreamOpenStdIn*(): PLLStream =
|
||||||
new(result)
|
new(result)
|
||||||
result.kind = llsStdIn
|
result.kind = llsStdIn
|
||||||
result.s = ""
|
result.s = ""
|
||||||
result.lineOffset = -1
|
result.lineOffset = -1
|
||||||
|
|
||||||
proc llStreamClose(s: PLLStream) =
|
proc llStreamClose*(s: PLLStream) =
|
||||||
case s.kind
|
case s.kind
|
||||||
of llsNone, llsString, llsStdIn:
|
of llsNone, llsString, llsStdIn:
|
||||||
discard
|
discard
|
||||||
|
|
@ -130,7 +115,7 @@ proc llReadFromStdin(s: PLLStream, buf: pointer, bufLen: int): int =
|
||||||
copyMem(buf, addr(s.s[s.rd]), result)
|
copyMem(buf, addr(s.s[s.rd]), result)
|
||||||
inc(s.rd, result)
|
inc(s.rd, result)
|
||||||
|
|
||||||
proc llStreamRead(s: PLLStream, buf: pointer, bufLen: int): int =
|
proc llStreamRead*(s: PLLStream, buf: pointer, bufLen: int): int =
|
||||||
case s.kind
|
case s.kind
|
||||||
of llsNone:
|
of llsNone:
|
||||||
result = 0
|
result = 0
|
||||||
|
|
@ -144,7 +129,7 @@ proc llStreamRead(s: PLLStream, buf: pointer, bufLen: int): int =
|
||||||
of llsStdIn:
|
of llsStdIn:
|
||||||
result = llReadFromStdin(s, buf, bufLen)
|
result = llReadFromStdin(s, buf, bufLen)
|
||||||
|
|
||||||
proc llStreamReadLine(s: PLLStream, line: var string): bool =
|
proc llStreamReadLine*(s: PLLStream, line: var string): bool =
|
||||||
setLen(line, 0)
|
setLen(line, 0)
|
||||||
case s.kind
|
case s.kind
|
||||||
of llsNone:
|
of llsNone:
|
||||||
|
|
@ -168,7 +153,7 @@ proc llStreamReadLine(s: PLLStream, line: var string): bool =
|
||||||
of llsStdIn:
|
of llsStdIn:
|
||||||
result = readLine(stdin, line)
|
result = readLine(stdin, line)
|
||||||
|
|
||||||
proc llStreamWrite(s: PLLStream, data: string) =
|
proc llStreamWrite*(s: PLLStream, data: string) =
|
||||||
case s.kind
|
case s.kind
|
||||||
of llsNone, llsStdIn:
|
of llsNone, llsStdIn:
|
||||||
discard
|
discard
|
||||||
|
|
@ -178,11 +163,11 @@ proc llStreamWrite(s: PLLStream, data: string) =
|
||||||
of llsFile:
|
of llsFile:
|
||||||
write(s.f, data)
|
write(s.f, data)
|
||||||
|
|
||||||
proc llStreamWriteln(s: PLLStream, data: string) =
|
proc llStreamWriteln*(s: PLLStream, data: string) =
|
||||||
llStreamWrite(s, data)
|
llStreamWrite(s, data)
|
||||||
llStreamWrite(s, "\n")
|
llStreamWrite(s, "\n")
|
||||||
|
|
||||||
proc llStreamWrite(s: PLLStream, data: char) =
|
proc llStreamWrite*(s: PLLStream, data: char) =
|
||||||
var c: char
|
var c: char
|
||||||
case s.kind
|
case s.kind
|
||||||
of llsNone, llsStdIn:
|
of llsNone, llsStdIn:
|
||||||
|
|
@ -194,7 +179,7 @@ proc llStreamWrite(s: PLLStream, data: char) =
|
||||||
c = data
|
c = data
|
||||||
discard writeBuffer(s.f, addr(c), sizeof(c))
|
discard writeBuffer(s.f, addr(c), sizeof(c))
|
||||||
|
|
||||||
proc llStreamWrite(s: PLLStream, buf: pointer, buflen: int) =
|
proc llStreamWrite*(s: PLLStream, buf: pointer, buflen: int) =
|
||||||
case s.kind
|
case s.kind
|
||||||
of llsNone, llsStdIn:
|
of llsNone, llsStdIn:
|
||||||
discard
|
discard
|
||||||
|
|
@ -206,7 +191,7 @@ proc llStreamWrite(s: PLLStream, buf: pointer, buflen: int) =
|
||||||
of llsFile:
|
of llsFile:
|
||||||
discard writeBuffer(s.f, buf, buflen)
|
discard writeBuffer(s.f, buf, buflen)
|
||||||
|
|
||||||
proc llStreamReadAll(s: PLLStream): string =
|
proc llStreamReadAll*(s: PLLStream): string =
|
||||||
const
|
const
|
||||||
bufSize = 2048
|
bufSize = 2048
|
||||||
case s.kind
|
case s.kind
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ proc hashTree(n: PNode): THash =
|
||||||
if (n.floatVal >= - 1000000.0) and (n.floatVal <= 1000000.0):
|
if (n.floatVal >= - 1000000.0) and (n.floatVal <= 1000000.0):
|
||||||
result = result !& toInt(n.floatVal)
|
result = result !& toInt(n.floatVal)
|
||||||
of nkStrLit..nkTripleStrLit:
|
of nkStrLit..nkTripleStrLit:
|
||||||
|
if not n.strVal.isNil:
|
||||||
result = result !& hash(n.strVal)
|
result = result !& hash(n.strVal)
|
||||||
else:
|
else:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
|
|
||||||
|
|
@ -1038,7 +1038,9 @@ proc typeAllowedNode(marker: var IntSet, n: PNode, kind: TSymKind,
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
result = typeAllowedNode(marker, n.sons[i], kind, flags)
|
let it = n.sons[i]
|
||||||
|
if it.kind == nkRecCase and kind == skConst: return n.typ
|
||||||
|
result = typeAllowedNode(marker, it, kind, flags)
|
||||||
if result != nil: break
|
if result != nil: break
|
||||||
|
|
||||||
proc matchType*(a: PType, pattern: openArray[tuple[k:TTypeKind, i:int]],
|
proc matchType*(a: PType, pattern: openArray[tuple[k:TTypeKind, i:int]],
|
||||||
|
|
@ -1118,7 +1120,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||||
result = typeAllowedAux(marker, t.sons[i], kind, flags)
|
result = typeAllowedAux(marker, t.sons[i], kind, flags)
|
||||||
if result != nil: break
|
if result != nil: break
|
||||||
of tyObject, tyTuple:
|
of tyObject, tyTuple:
|
||||||
if kind == skConst and t.kind == tyObject: return t
|
if kind == skConst and t.kind == tyObject and t.sons[0] != nil: return t
|
||||||
let flags = flags+{taField}
|
let flags = flags+{taField}
|
||||||
for i in countup(0, sonsLen(t) - 1):
|
for i in countup(0, sonsLen(t) - 1):
|
||||||
result = typeAllowedAux(marker, t.sons[i], kind, flags)
|
result = typeAllowedAux(marker, t.sons[i], kind, flags)
|
||||||
|
|
|
||||||
|
|
@ -604,7 +604,8 @@ proc genNarrowU(c: PCtx; n: PNode; dest: TDest) =
|
||||||
let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})
|
let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})
|
||||||
# uint is uint64 in the VM, we we only need to mask the result for
|
# uint is uint64 in the VM, we we only need to mask the result for
|
||||||
# other unsigned types:
|
# other unsigned types:
|
||||||
if t.kind in {tyUInt8..tyUInt32, tyInt8..tyInt32}:
|
if t.kind in {tyUInt8..tyUInt32, tyInt8..tyInt32} or
|
||||||
|
(t.kind == tyInt and t.size == 4):
|
||||||
c.gABC(n, opcNarrowU, dest, TRegister(t.size*8))
|
c.gABC(n, opcNarrowU, dest, TRegister(t.size*8))
|
||||||
|
|
||||||
proc genBinaryABCnarrow(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) =
|
proc genBinaryABCnarrow(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) =
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ Advanced options:
|
||||||
--threadanalysis:on|off turn thread analysis on|off
|
--threadanalysis:on|off turn thread analysis on|off
|
||||||
--tlsEmulation:on|off turn thread local storage emulation on|off
|
--tlsEmulation:on|off turn thread local storage emulation on|off
|
||||||
--taintMode:on|off turn taint mode on|off
|
--taintMode:on|off turn taint mode on|off
|
||||||
--symbolFiles:on|off turn symbol files on|off (experimental)
|
|
||||||
--implicitStatic:on|off turn implicit compile time evaluation on|off
|
--implicitStatic:on|off turn implicit compile time evaluation on|off
|
||||||
--patterns:on|off turn pattern matching on|off
|
--patterns:on|off turn pattern matching on|off
|
||||||
--skipCfg do not read the general configuration file
|
--skipCfg do not read the general configuration file
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ Options:
|
||||||
-p, --path:PATH add path to search paths
|
-p, --path:PATH add path to search paths
|
||||||
-d, --define:SYMBOL define a conditional symbol
|
-d, --define:SYMBOL define a conditional symbol
|
||||||
-u, --undef:SYMBOL undefine a conditional symbol
|
-u, --undef:SYMBOL undefine a conditional symbol
|
||||||
--symbol:SYMBOL declare a conditional symbol
|
|
||||||
-f, --forceBuild force rebuilding of all modules
|
-f, --forceBuild force rebuilding of all modules
|
||||||
--stackTrace:on|off turn stack tracing on|off
|
--stackTrace:on|off turn stack tracing on|off
|
||||||
--lineTrace:on|off turn line tracing on|off
|
--lineTrace:on|off turn line tracing on|off
|
||||||
|
|
|
||||||
19
tests/vm/tconsttable.nim
Normal file
19
tests/vm/tconsttable.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
discard """
|
||||||
|
output: '''is
|
||||||
|
finally
|
||||||
|
nice!'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import tables
|
||||||
|
|
||||||
|
const
|
||||||
|
foo = {"ah": "finally", "this": "is", "possible.": "nice!"}.toTable()
|
||||||
|
|
||||||
|
# protect against overly smart compiler:
|
||||||
|
var x = "this"
|
||||||
|
|
||||||
|
echo foo[x]
|
||||||
|
x = "ah"
|
||||||
|
echo foo[x]
|
||||||
|
x = "possible."
|
||||||
|
echo foo[x]
|
||||||
15
todo.txt
15
todo.txt
|
|
@ -1,11 +1,20 @@
|
||||||
version 0.10
|
version 0.10.4
|
||||||
============
|
==============
|
||||||
|
|
||||||
|
- make 'nil' work for 'add' and 'len'
|
||||||
|
- improve GC-unsafety warnings
|
||||||
|
- get rid of 'mget'; aka priority of 'var' needs to be 'var{lvalue}'
|
||||||
|
- improve documentation (theindex!)
|
||||||
|
- fix the getUniqueType() bug
|
||||||
|
|
||||||
|
|
||||||
|
version 1.0
|
||||||
|
===========
|
||||||
|
|
||||||
- nimsuggest: auto-completion needs to work in 'class' macros
|
- nimsuggest: auto-completion needs to work in 'class' macros
|
||||||
- improve the docs for inheritance
|
- improve the docs for inheritance
|
||||||
- The bitwise 'not' operator will be renamed to 'bnot' to
|
- The bitwise 'not' operator will be renamed to 'bnot' to
|
||||||
prevent 'not 4 == 5' from compiling. -> requires 'mixin' annotation for procs!
|
prevent 'not 4 == 5' from compiling. -> requires 'mixin' annotation for procs!
|
||||||
- parameter lists without type end up in 'experimental'
|
|
||||||
- iterators always require a return type
|
- iterators always require a return type
|
||||||
- overloading of '='
|
- overloading of '='
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,15 @@ News
|
||||||
- Automatic dereferencing is now done for the first argument of a routine
|
- Automatic dereferencing is now done for the first argument of a routine
|
||||||
call if overloading resolution produces no match otherwise. This feature
|
call if overloading resolution produces no match otherwise. This feature
|
||||||
has to be enabled with the `experimental`_ pragma.
|
has to be enabled with the `experimental`_ pragma.
|
||||||
|
- Objects that do not use inheritance nor ``case`` can be put into ``const``
|
||||||
|
sections. This means that finally this is possible and produces rather
|
||||||
|
nice code:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
import tables
|
||||||
|
|
||||||
|
const
|
||||||
|
foo = {"ah": "finally", "this": "is", "possible.": "nice!"}.toTable()
|
||||||
|
|
||||||
|
|
||||||
2014-12-29 Version 0.10.2 released
|
2014-12-29 Version 0.10.2 released
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue