summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xcompiler/ast.nim2
-rwxr-xr-xcompiler/condsyms.nim25
-rwxr-xr-xcompiler/main.nim6
-rwxr-xr-xcompiler/semexprs.nim16
-rwxr-xr-xdoc/nimrodc.txt6
-rwxr-xr-xlib/pure/collections/lists.nim18
-rwxr-xr-xlib/system.nim6
-rw-r--r--tests/accept/compile/tslurp.nim6
-rwxr-xr-xtodo.txt1
-rwxr-xr-xweb/news.txt1
10 files changed, 63 insertions, 24 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 909c7c3bf..eb214e87f 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -313,7 +313,7 @@ type
 
   TMagic* = enum # symbols that require compiler magic:
     mNone, mDefined, mDefinedInScope, mLow, mHigh, mSizeOf, mIs, mOf,
-    mEcho, mShallowCopy,
+    mEcho, mShallowCopy, mSlurp,
     mUnaryLt, mSucc, 
     mPred, mInc, mDec, mOrd, mNew, mNewFinalize, mNewSeq, mLengthOpenArray, 
     mLengthStr, mLengthArray, mLengthSeq, mIncl, mExcl, mCard, mChr, mGCref, 
diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim
index 9c95e8fcc..b37b754f0 100755
--- a/compiler/condsyms.nim
+++ b/compiler/condsyms.nim
@@ -14,16 +14,7 @@ import
 
 var gSymbols*: TStrTable
 
-proc InitDefines*()
-proc DeinitDefines*()
-proc DefineSymbol*(symbol: string)
-proc UndefSymbol*(symbol: string)
-proc isDefined*(symbol: PIdent): bool
-proc ListSymbols*()
-proc countDefinedSymbols*(): int
-# implementation
-
-proc DefineSymbol(symbol: string) = 
+proc DefineSymbol*(symbol: string) = 
   var i = getIdent(symbol)
   var sym = StrTableGet(gSymbols, i)
   if sym == nil: 
@@ -33,15 +24,15 @@ proc DefineSymbol(symbol: string) =
     StrTableAdd(gSymbols, sym)
   sym.position = 1
 
-proc UndefSymbol(symbol: string) = 
+proc UndefSymbol*(symbol: string) = 
   var sym = StrTableGet(gSymbols, getIdent(symbol))
   if sym != nil: sym.position = 0
   
-proc isDefined(symbol: PIdent): bool = 
+proc isDefined*(symbol: PIdent): bool = 
   var sym = StrTableGet(gSymbols, symbol)
-  result = (sym != nil) and (sym.position == 1)
+  result = sym != nil and sym.position == 1
 
-proc ListSymbols() = 
+proc ListSymbols*() = 
   var it: TTabIter
   var s = InitTabIter(it, gSymbols)
   OutWriteln("-- List of currently defined symbols --")
@@ -50,7 +41,7 @@ proc ListSymbols() =
     s = nextIter(it, gSymbols)
   OutWriteln("-- End of list --")
 
-proc countDefinedSymbols(): int = 
+proc countDefinedSymbols*(): int = 
   var it: TTabIter
   var s = InitTabIter(it, gSymbols)
   result = 0
@@ -58,7 +49,7 @@ proc countDefinedSymbols(): int =
     if s.position == 1: inc(result)
     s = nextIter(it, gSymbols)
 
-proc InitDefines() = 
+proc InitDefines*() = 
   initStrTable(gSymbols)
   DefineSymbol("nimrod") # 'nimrod' is always defined
   
@@ -98,5 +89,3 @@ proc InitDefines() =
   DefineSymbol(cpu[targetCPU].name)
   DefineSymbol(platform.os[targetOS].name)
 
-proc DeinitDefines() = 
-  nil
diff --git a/compiler/main.nim b/compiler/main.nim
index d08e94397..017d188b5 100755
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -182,12 +182,12 @@ proc CommandSuggest(filename: string) =
   compileProject(filename)
 
 proc WantFile(filename: string) = 
-  if filename == "": 
+  if filename.len == 0: 
     Fatal(newLineInfo("command line", 1, 1), errCommandExpectsFilename)
   
 proc MainCommand(cmd, filename: string) = 
   appendStr(searchPaths, options.libpath)
-  if filename != "": 
+  if filename.len != 0:
     # current path is always looked first for modules
     prependStr(searchPaths, splitFile(filename).dir)
   setID(100)
@@ -203,11 +203,13 @@ proc MainCommand(cmd, filename: string) =
     extccomp.cExt = ".cpp"
     gCmd = cmdCompileToCpp
     wantFile(filename)
+    DefineSymbol("cpp")
     CommandCompileToC(filename)
   of "objc", "compiletooc":
     extccomp.cExt = ".m"
     gCmd = cmdCompileToOC
     wantFile(filename)
+    DefineSymbol("objc")
     CommandCompileToC(filename)
   of "run":
     gCmd = cmdRun
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 58fbf3a25..aa069c971 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -883,6 +883,21 @@ proc setMs(n: PNode, s: PSym): PNode =
   n.sons[0] = newSymNode(s)
   n.sons[0].info = n.info
 
+proc semSlurp(c: PContext, n: PNode, flags: TExprFlags): PNode = 
+  if sonsLen(n) == 2:
+    var a = c.semConstExpr(c, n.sons[1])
+    if a.kind notin {nkStrLit, nkRStrLit, nkTripleStrLit}: 
+      GlobalError(a.info, errStringLiteralExpected)
+    try:
+      var content = readFile(a.strVal)
+      result = newStrNode(nkStrLit, content)
+      result.typ = getSysType(tyString)
+      result.info = n.info
+    except EIO:
+      GlobalError(a.info, errCannotOpenFile, a.strVal)
+  else:
+    result = semDirectOp(c, n, flags)
+
 proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode = 
   # this is a hotspot in the compiler!
   result = n
@@ -905,6 +920,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
       result = semAsgn(c, result)
     else:
       result = semDirectOp(c, n, flags)
+  of mSlurp: result = semSlurp(c, n, flags)
   else: result = semDirectOp(c, n, flags)
 
 proc semIfExpr(c: PContext, n: PNode): PNode = 
diff --git a/doc/nimrodc.txt b/doc/nimrodc.txt
index 2fd9267b2..5808ca684 100755
--- a/doc/nimrodc.txt
+++ b/doc/nimrodc.txt
@@ -226,7 +226,8 @@ interfacing with libraries written in C++:
     header: irr, importcpp: "run".}

   

 The compiler needs to be told to generate C++ (command ``cpp``) for 

-this to work.

+this to work. The conditional symbol ``cpp`` is defined when the compiler

+emits C++ code.

 

 

 ImportObjC pragma

@@ -274,7 +275,8 @@ interfacing with libraries written in Objective C:
   g.free()

 

 The compiler needs to be told to generate Objective C (command ``objc``) for 

-this to work.

+this to work. The conditional symbol ``objc`` is defined when the compiler

+emits Objective C code.

 

 

 LineDir option

diff --git a/lib/pure/collections/lists.nim b/lib/pure/collections/lists.nim
index 55c3d6ad9..3e54dc02b 100755
--- a/lib/pure/collections/lists.nim
+++ b/lib/pure/collections/lists.nim
@@ -35,7 +35,23 @@ type
   
   TDoublyLinkedRing* {.pure, final.}[T] = object ## a doubly linked ring
     head*: PDoublyLinkedNode[T]
-    
+
+proc initSinglyLinkedList*[T](): TSinglyLinkedList[T] =
+  ## creates a new singly linked list that is empty.
+  nil
+
+proc initDoublyLinkedList*[T](): TDoublyLinkedList[T] =
+  ## creates a new doubly linked list that is empty.
+  nil
+
+proc initSinglyLinkedRing*[T](): TSinglyLinkedRing[T] =
+  ## creates a new singly linked ring that is empty.
+  nil
+
+proc initDoublyLinkedRing*[T](): TDoublyLinkedRing[T] =
+  ## creates a new doubly linked ring that is empty.
+  nil
+
 proc newDoublyLinkedNode*[T](value: T): PDoublyLinkedNode[T] =
   ## creates a new doubly linked node with the given `value`.
   new(result)
diff --git a/lib/system.nim b/lib/system.nim
index 024b84077..ace36bcc9 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1974,4 +1974,10 @@ proc getTypeInfo*[T](x: T): pointer {.magic: "GetTypeInfo".}
   ## get type information for `x`. Ordinary code should not use this, but
   ## the `typeinfo` module instead.
   
+proc slurp*(filename: string): string {.magic: "Slurp".}
+  ## compiletime ``readFile`` proc for easy `resource`:idx: embedding:
+  ## .. code-block:: nimrod
+  ##
+  ##   const myResource = slurp"mydatafile.bin"
+  ##
 
diff --git a/tests/accept/compile/tslurp.nim b/tests/accept/compile/tslurp.nim
new file mode 100644
index 000000000..c99fefe23
--- /dev/null
+++ b/tests/accept/compile/tslurp.nim
@@ -0,0 +1,6 @@
+
+const
+  myRes = slurp"readme.txt"
+  
+echo myRes
+
diff --git a/todo.txt b/todo.txt
index 1dd6853fc..eb8b783a1 100755
--- a/todo.txt
+++ b/todo.txt
@@ -19,6 +19,7 @@ version 0.9.0
 - change overloading resolution
 - implement closures; implement proper coroutines
 - make exceptions compatible with C++ exceptions
+- ``=`` should be overloadable; requires specialization for ``=``
 
 Bugs
 ----
diff --git a/web/news.txt b/web/news.txt
index 9e4a2d67c..61cf024c6 100755
--- a/web/news.txt
+++ b/web/news.txt
@@ -64,6 +64,7 @@ Library Additions
 - Added explicit channels for thread communication.
 - Added ``matchers`` module for email address etc. matching.
 - Added ``strutils.unindent``.
+- Added ``system.slurp`` for easy resource embedding.
 
 
 2011-07-10 Version 0.8.12 released