summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xcompiler/evals.nim38
-rwxr-xr-xcompiler/semexprs.nim2
-rwxr-xr-xdoc/manual.txt11
-rwxr-xr-xlib/pure/strtabs.nim2
-rwxr-xr-xlib/pure/strutils.nim6
-rwxr-xr-xlib/pure/unidecode/unidecode.nim46
-rw-r--r--tests/accept/run/tunidecode.nim9
-rwxr-xr-xtodo.txt7
-rwxr-xr-xweb/news.txt3
9 files changed, 76 insertions, 48 deletions
diff --git a/compiler/evals.nim b/compiler/evals.nim
index d2559176e..b1d3688c3 100755
--- a/compiler/evals.nim
+++ b/compiler/evals.nim
@@ -65,7 +65,7 @@ proc popStackFrame*(c: PEvalContext) {.inline.} =
   if (c.tos == nil): InternalError("popStackFrame")
   c.tos = c.tos.next
 
-proc eval*(c: PEvalContext, n: PNode): PNode
+proc evalMacroCall*(c: PEvalContext, n: PNode, sym: PSym): PNode
 proc evalAux(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode
 
 proc stackTraceAux(x: PStackFrame) =
@@ -834,24 +834,6 @@ proc evalTemplate(n: PNode, sym: PSym): PNode =
   result = evalTemplateAux(sym.ast.sons[codePos], args, sym)
 
   dec(evalTemplateCounter)
-
-proc evalMacroCall*(c: PEvalContext, n: PNode, sym: PSym): PNode =
-  inc(evalTemplateCounter)
-  if evalTemplateCounter > 100: 
-    GlobalError(n.info, errTemplateInstantiationTooNested)
-
-  var s = newStackFrame()
-  s.call = n
-  setlen(s.params, 2)
-  s.params[0] = newNodeIT(nkNilLit, n.info, sym.typ.sons[0])
-  s.params[1] = n
-  pushStackFrame(c, s)
-  discard eval(c, sym.ast.sons[codePos])
-  result = s.params[0]
-  popStackFrame(c)
-  if cyclicTree(result): GlobalError(n.info, errCyclicTree)
-
-  dec(evalTemplateCounter)
   
 proc evalExpandToAst(c: PEvalContext, original: PNode): PNode =
   var
@@ -1258,6 +1240,24 @@ proc evalConstExpr*(module: PSym, e: PNode): PNode =
   if result != nil and result.kind == nkExceptBranch: result = nil
   popStackFrame(p)
 
+proc evalMacroCall*(c: PEvalContext, n: PNode, sym: PSym): PNode =
+  # XXX GlobalError() is ugly here, but I don't know a better solution for now
+  inc(evalTemplateCounter)
+  if evalTemplateCounter > 100: 
+    GlobalError(n.info, errTemplateInstantiationTooNested)
+
+  var s = newStackFrame()
+  s.call = n
+  setlen(s.params, 2)
+  s.params[0] = newNodeIT(nkNilLit, n.info, sym.typ.sons[0])
+  s.params[1] = n
+  pushStackFrame(c, s)
+  discard eval(c, sym.ast.sons[codePos])
+  result = s.params[0]
+  popStackFrame(c)
+  if cyclicTree(result): GlobalError(n.info, errCyclicTree)
+  dec(evalTemplateCounter)
+
 proc myOpen(module: PSym, filename: string): PPassContext = 
   var c = newEvalContext(module, filename, false)
   pushStackFrame(c, newStackFrame())
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 54f0af9df..b30ffc64a 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -942,7 +942,7 @@ proc semSlurp(c: PContext, n: PNode, flags: TExprFlags): PNode =
   if sonsLen(n) == 2:
     var a = expectStringArg(c, n, 0)
     try:
-      var content = readFile(a.strVal)
+      var content = readFile(a.strVal.FindFile)
       result = newStrNode(nkStrLit, content)
       result.typ = getSysType(tyString)
       result.info = n.info
diff --git a/doc/manual.txt b/doc/manual.txt
index e07c7aff8..2cff05641 100755
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -1547,9 +1547,8 @@ The rules for compile-time computability are:
    computable arguments.

 

 

-Constants cannot be of type ``var`` or ``object``, nor can 

-they contain such a type. For the types ``ptr`` and ``ref`` only the

-constant literal ``nil`` is possible.

+Constants cannot be of type ``ptr``, ``ref``, ``var`` or ``object``, nor can 

+they contain such a type.

 

 

 If statement

@@ -3322,7 +3321,11 @@ improve compile times.
 A thread proc is passed to ``createThread`` and invoked indirectly; so the

 ``thread`` pragma implies ``procvar``.

 

-If a global variable can also be marked with the ``thread`` pragma; it is 

+

+Threadvar pragma

+----------------

+

+A global variable can be marked with the `threadvar`:idx: pragma; it is 

 a `thead-local`:idx: variable then:

 

 .. code-block:: nimrod

diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim
index 15ff5a079..25220703f 100755
--- a/lib/pure/strtabs.nim
+++ b/lib/pure/strtabs.nim
@@ -218,7 +218,7 @@ proc `$`*(t: PStringTable): string {.rtl, extern: "nstDollar".} =
     result.add("}")
 
 when isMainModule:
-  const x = {"k": "v", "11": "22", "565": "67"}.newStringTable
+  var x = {"k": "v", "11": "22", "565": "67"}.newStringTable
   assert x["k"] == "v"
   assert x["11"] == "22"
   assert x["565"] == "67"
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 5f91b65b5..33bb5b5f0 100755
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -972,9 +972,9 @@ proc c_sprintf(buf, frmt: CString) {.nodecl, importc: "sprintf", varargs,
 

 type

   TFloatFormat* = enum ## the different modes of floating point formating

-    ffDefault,    ## use the shorter floating point notation

-    ffDecimal,    ## use decimal floating point notation

-    ffScientific  ## use scientific notation (using ``e`` character)

+    ffDefault,         ## use the shorter floating point notation

+    ffDecimal,         ## use decimal floating point notation

+    ffScientific       ## use scientific notation (using ``e`` character)

 

 proc formatBiggestFloat*(f: BiggestFloat, format: TFloatFormat = ffDefault,

                          precision = 16): string {.noSideEffect,

diff --git a/lib/pure/unidecode/unidecode.nim b/lib/pure/unidecode/unidecode.nim
index 52f9b6b1a..453e1b289 100755
--- a/lib/pure/unidecode/unidecode.nim
+++ b/lib/pure/unidecode/unidecode.nim
@@ -1,7 +1,7 @@
 #
 #
 #            Nimrod's Runtime Library
-#        (c) Copyright 2010 Andreas Rumpf
+#        (c) Copyright 2011 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -22,23 +22,32 @@
 ## strictly one-way transformation. However a human reader will probably 
 ## still be able to guess what original string was meant from the context.
 ##
-## This module needs the data file "unidecode.dat" to work, so it has to be
-## shipped with the application! 
+## This module needs the data file "unidecode.dat" to work: You can either
+## ship this file with your application and initialize this module with the
+## `loadUnidecodeTable` proc or you can define the ``embedUnidecodeTable``
+## symbol to embed the file as a resource into your application.
 
 import unicode
 
-proc loadTranslationTable(filename: string): seq[string] =  
-  newSeq(result, 0xffff)
-  var i = 0
-  for line in lines(filename):
-    result[i] = line
-    inc(i)
-
-var 
-  translationTable: seq[string]
+when defined(embedUnidecodeTable):
+  import strutils
   
-var
-  datafile* = "unidecode.dat"   ## location can be overwritten for deployment
+  const translationTable = splitLines(slurp"unidecode/unidecode.dat")
+else:
+  # shared is fine for threading:
+  var translationTable: seq[string]
+
+proc loadUnidecodeTable*(datafile = "unidecode.dat") =
+  ## loads the datafile that `unidecode` to work. Unless this module is
+  ## compiled with the ``embedUnidecodeTable`` symbol defined, this needs
+  ## to be called by the main thread before any thread can make a call
+  ## to `unidecode`.
+  when not defined(embedUnidecodeTable):
+    newSeq(translationTable, 0xffff)
+    var i = 0
+    for line in lines(datafile):
+      translationTable[i] = line
+      inc(i)
 
 proc unidecode*(s: string): string = 
   ## Finds the sequence of ASCII characters that is the closest approximation
@@ -51,15 +60,14 @@ proc unidecode*(s: string): string =
   ##
   ## Results in: "Bei Jing"
   ##
+  assert(not isNil(translationTable))
   result = ""
   for r in runes(s): 
     var c = int(r)
     if c <=% 127: add(result, chr(c))
-    elif c <=% 0xffff: 
-      if isNil(translationTable):
-        translationTable = loadTranslationTable(datafile)
-      add(result, translationTable[c-128])
+    elif c <% translationTable.len: add(result, translationTable[c-128])
 
-when isMainModule: 
+when isMainModule:
+  loadUnidecodeTable("lib/pure/unidecode/unidecode.dat")
   echo unidecode("Äußerst")
 
diff --git a/tests/accept/run/tunidecode.nim b/tests/accept/run/tunidecode.nim
new file mode 100644
index 000000000..7fee69a34
--- /dev/null
+++ b/tests/accept/run/tunidecode.nim
@@ -0,0 +1,9 @@
+discard """
+  cmd: "nimrod cc --hints:on -d:embedUnidecodeTable $# $#"
+  output: "Ausserst"
+"""
+
+import unidecode
+
+unidecode("Äußerst")
+
diff --git a/todo.txt b/todo.txt
index 343ab6991..2ef926c5f 100755
--- a/todo.txt
+++ b/todo.txt
@@ -1,12 +1,15 @@
 Version 0.8.14
 ==============
 
-- fix the 'const' issues
+- optimize unused constants away
 - 'let x = y'; const ptr/ref
 - fix actors.nim
 - make threadvar efficient again on linux after testing
 - test the sort implementation again
 - optional indentation for 'case' statement
+- ``bind`` as a declaration
+- document splicing
+- fix unidecode.nim
 
 
 version 0.9.0
@@ -20,6 +23,7 @@ version 0.9.0
 - implement closures; implement proper coroutines
 - make exceptions compatible with C++ exceptions
 - ``=`` should be overloadable; requires specialization for ``=``
+- 'const' objects including case objects
 
 Bugs
 ----
@@ -93,6 +97,7 @@ Low priority
 ------------
 
 - ``with proc `+`(x, y: T): T`` for generic code
+- new feature: ``distinct T with operations``
 - find a way for easy constructors and destructors; (destructors are much more
   important than constructors)
 - code generated for type information is wasteful
diff --git a/web/news.txt b/web/news.txt
index 2ee7c6822..bd11cf184 100755
--- a/web/news.txt
+++ b/web/news.txt
@@ -37,6 +37,7 @@ Changes affecting backwards compatibility
 - The ``is`` operator is now used to check type equivalence in generic code.
 - The ``pure`` pragma for procs has been renamed to ``noStackFrame``. 
 - The threading API has been completely redesigned.
+- The interface of the ``unidecode`` module changed and it's now thread-safe.
 
 
 Language Additions
@@ -50,6 +51,7 @@ Language Additions
   a compile-time error.
 - There is a new ``discardable`` pragma that can be used to mark a routine 
   so that its result can be discarded implicitely.
+- Constants can now have the type ``seq``.
 
 
 Compiler Additions
@@ -74,6 +76,7 @@ Library Additions
 - Added ``system.mainThreadId``.
 - Added ``system.allocShared``, ``system.allocShared0``, 
   ``system.deallocShared``, ``system.reallocShared``.
+- Slicing as implemented by the system module now supports *splicing*.
 - Added explicit channels for thread communication.
 - Added ``matchers`` module for email address etc. matching.
 - Added ``strutils.unindent``, ``strutils.countLines``.