summary refs log tree commit diff stats
path: root/lib/system.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2011-11-10 04:10:03 +0200
committerZahary Karadjov <zahary@gmail.com>2011-11-10 04:10:03 +0200
commit489340658ea855d01de853d3c95c928d6e1b9f86 (patch)
treee1e85d36257851daed8d907aeba89cc9453d5c08 /lib/system.nim
parent2bd14f4ba8863f08eadc99e6664935ab1e3fec20 (diff)
downloadNim-489340658ea855d01de853d3c95c928d6e1b9f86.tar.gz
Added system.program_results for controlling the exit code of the program under normal circumstances
Implemented operators like +=, -=, etc for ordinals, floats and string

Programs using the UnitTest module will now report the number of failed tests as the exit code of test runs (0 for successful run)
Diffstat (limited to 'lib/system.nim')
-rwxr-xr-xlib/system.nim33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 8657efe2a..00555fa45 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -402,6 +402,9 @@ proc `+` *(x, y: int32): int32 {.magic: "AddI", noSideEffect.}
 proc `+` *(x, y: int64): int64 {.magic: "AddI64", noSideEffect.}
   ## Binary `+` operator for an integer.
 
+proc `+=`*[T](x, y: ordinal[T]) {.magic: "Inc", noSideEffect.}
+  ## Increments an ordinal
+
 proc `-` *(x, y: int): int {.magic: "SubI", noSideEffect.}
 proc `-` *(x, y: int8): int8 {.magic: "SubI", noSideEffect.}
 proc `-` *(x, y: int16): int16 {.magic: "SubI", noSideEffect.}
@@ -409,6 +412,9 @@ proc `-` *(x, y: int32): int32 {.magic: "SubI", noSideEffect.}
 proc `-` *(x, y: int64): int64 {.magic: "SubI64", noSideEffect.}
   ## Binary `-` operator for an integer.
 
+proc `-=`*[T](x, y: ordinal[T]) {.magic: "Dec", noSideEffect.}
+  ## Decrements an ordinal
+  
 proc `*` *(x, y: int): int {.magic: "MulI", noSideEffect.}
 proc `*` *(x, y: int8): int8 {.magic: "MulI", noSideEffect.}
 proc `*` *(x, y: int16): int16 {.magic: "MulI", noSideEffect.}
@@ -416,6 +422,10 @@ proc `*` *(x, y: int32): int32 {.magic: "MulI", noSideEffect.}
 proc `*` *(x, y: int64): int64 {.magic: "MulI64", noSideEffect.}
   ## Binary `*` operator for an integer.
 
+proc `*=`*[T](x: var ordinal[T], y: ordinal[T]) {.inline noSideEffect.} =
+  ## Binary `*=` operator for oridinals
+  x = x * y
+
 proc `div` *(x, y: int): int {.magic: "DivI", noSideEffect.}
 proc `div` *(x, y: int8): int8 {.magic: "DivI", noSideEffect.}
 proc `div` *(x, y: int16): int16 {.magic: "DivI", noSideEffect.}
@@ -569,6 +579,22 @@ proc `*` *(x, y: float): float {.magic: "MulF64", noSideEffect.}
 proc `/` *(x, y: float): float {.magic: "DivF64", noSideEffect.}
   ## computes the floating point division
 
+proc `+=` *(x: var float, y:float) {.inline noSideEffect.} =
+  ## Increments in placee a floating point number
+  x = x + y
+
+proc `-=` *(x: var float, y:float) {.inline noSideEffect.} =
+  ## Decrements in place a floating point number
+  x = x - y
+
+proc `*=` *(x: var float, y:float) {.inline noSideEffect.} =
+  ## Multiplies in place a floating point number
+  x = x * y
+
+proc `/=` *(x: var float, y:float) {.inline noSideEffect.} =
+  ## Divides in place a floating point number
+  x = x / y
+
 proc `==` *(x, y: float): bool {.magic: "EqF64", noSideEffect.}
 proc `<=` *(x, y: float): bool {.magic: "LeF64", noSideEffect.}
 proc `<`  *(x, y: float): bool {.magic: "LtF64", noSideEffect.}
@@ -717,6 +743,8 @@ proc `&` * (x: char, y: string): string {.
 proc add*(x: var string, y: char) {.magic: "AppendStrCh", noSideEffect.}
 proc add*(x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
 
+proc `&=`* (x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
+
 type
   TEndian* = enum ## is a type describing the endianness of a processor.
     littleEndian, bigEndian
@@ -1541,6 +1569,11 @@ const
     ## is the value that should be passed to ``quit`` to indicate
     ## failure.
 
+var program_result* {.exportc: "nim_$1".} = QuitSuccess
+  ## modify this varialbe to specify the exit code of the program
+  ## under normal circumstances. when the program is terminated
+  ## prematurelly using ``quit``, this value is ignored.
+
 proc quit*(errorcode: int = QuitSuccess) {.
   magic: "Exit", importc: "exit", noDecl, noReturn.}
   ## stops the program immediately; before stopping the program the