summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authordom96 <dominikpicheta@googlemail.com>2011-09-23 21:43:24 +0100
committerdom96 <dominikpicheta@googlemail.com>2011-09-23 21:43:24 +0100
commit6deda5a973312e86fe58e319e97afd93bc07c82d (patch)
tree0769b2871024febab389c8bc72d01cd770b52cfb /lib
parent2359b8b1073cfd027ac14a147aba06cc18d61010 (diff)
downloadNim-6deda5a973312e86fe58e319e97afd93bc07c82d.tar.gz
Fixed string concatenation and other bugs in the JS backend. Fixed a small bug in the IRC module.
Diffstat (limited to 'lib')
-rwxr-xr-xlib/ecmas/dom.nim1
-rw-r--r--lib/pure/irc.nim8
-rwxr-xr-xlib/pure/times.nim8
-rwxr-xr-xlib/system.nim3
-rwxr-xr-xlib/system/ecmasys.nim2
-rw-r--r--lib/system/reprjs.nim23
6 files changed, 40 insertions, 5 deletions
diff --git a/lib/ecmas/dom.nim b/lib/ecmas/dom.nim
index e9c587928..3a1caecbe 100755
--- a/lib/ecmas/dom.nim
+++ b/lib/ecmas/dom.nim
@@ -227,6 +227,7 @@ type
     getAttributeNode*: proc (attr: cstring): ref TNode
     getElementsByTagName*: proc (): seq[ref TNode]
     hasChildNodes*: proc (): bool
+    innerHTML*: cstring
     insertBefore*: proc (newNode, before: ref TNode)
     insertData*: proc (position: int, data: cstring)
     removeAttribute*: proc (attr: cstring)
diff --git a/lib/pure/irc.nim b/lib/pure/irc.nim
index 5a4c815f6..0397502cd 100644
--- a/lib/pure/irc.nim
+++ b/lib/pure/irc.nim
@@ -70,7 +70,12 @@ type
   
 proc send*(irc: var TIRC, message: string) =
   ## Sends ``message`` as a raw command. It adds ``\c\L`` for you.
-  irc.sock.send(message & "\c\L")
+  try:
+    irc.sock.send(message & "\c\L")
+  except EOS:
+    # Assuming disconnection of every EOS could be bad,
+    # but I can't exactly check for EBrokenPipe.
+    irc.connected = false
 
 proc privmsg*(irc: var TIRC, target, message: string) =
   ## Sends ``message`` to ``target``. ``Target`` can be a channel, or a user.
@@ -199,6 +204,7 @@ proc poll*(irc: var TIRC, ev: var TIRCEvent,
   ##
   ## This function should be called often as it also handles pinging
   ## the server.
+  if not irc.connected: ev.typ = EvDisconnected
   var line = ""
   var socks = @[irc.sock]
   var ret = socks.select(timeout)
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index da23d4615..378d6ae80 100755
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -52,7 +52,7 @@ elif defined(windows):
 
 elif defined(ECMAScript):
   type
-    TTime* {.final.} = object
+    TTime* {.final, importc.} = object
       getDay: proc (): int
       getFullYear: proc (): int
       getHours: proc (): int
@@ -62,6 +62,7 @@ elif defined(ECMAScript):
       getSeconds: proc (): int
       getTime: proc (): int
       getTimezoneOffset: proc (): int
+      getDate: proc (): int
       getUTCDate: proc (): int
       getUTCFullYear: proc (): int
       getUTCHours: proc (): int
@@ -310,7 +311,8 @@ when not defined(ECMAScript):
       result = toFloat(int(clock())) / toFloat(clocksPerSec)
     
 else:
-  proc getTime(): TTime {.importc: "new Date", nodecl.}
+  proc newDate(): TTime {.importc: "new Date", nodecl.}
+  proc getTime(): TTime = return newDate()
 
   const
     weekDays: array [0..6, TWeekDay] = [
@@ -346,7 +348,7 @@ else:
     result.setDate(timeInfo.monthday)
   
   proc `$`(timeInfo: TTimeInfo): string = return $(TimeInfoToTIme(timeInfo))
-  proc `$`(time: TTime): string = $time.toLocaleString()
+  proc `$`(time: TTime): string = return $time.toLocaleString()
     
   proc `-` (a, b: TTime): int64 = 
     return a.getTime() - b.getTime()
diff --git a/lib/system.nim b/lib/system.nim
index ea004b925..644202d8c 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1495,6 +1495,8 @@ else:
       `x`[0][len] = 0
     """
 
+  proc add*(x: var cstring, y: cstring) {.magic: "AppendStrStr".}
+
 proc echo*[Ty](x: openarray[Ty]) {.magic: "Echo", noSideEffect.}
   ## special built-in that takes a variable number of arguments. Each argument
   ## is converted to a string via ``$``, so it works for user-defined
@@ -1886,6 +1888,7 @@ elif defined(ecmaScript) or defined(NimrodVM):
 
   when defined(ecmaScript):
     include "system/ecmasys"
+    include "system/reprjs"
   elif defined(NimrodVM):
     proc cmp(x, y: string): int =
       if x == y: return 0
diff --git a/lib/system/ecmasys.nim b/lib/system/ecmasys.nim
index ece33d9dc..5dc01f46e 100755
--- a/lib/system/ecmasys.nim
+++ b/lib/system/ecmasys.nim
@@ -228,7 +228,7 @@ proc cmp(x, y: string): int = return cmpStrings(x, y)
 
 proc eqStrings(a, b: string): bool {.noStackFrame, compilerProc.} =
   asm """
-    if (`a == `b`) return true;
+    if (`a` == `b`) return true;
     if ((!`a`) || (!`b`)) return false;
     var alen = `a`.length;
     if (alen != `b`.length) return false;
diff --git a/lib/system/reprjs.nim b/lib/system/reprjs.nim
new file mode 100644
index 000000000..b6b6ffe9c
--- /dev/null
+++ b/lib/system/reprjs.nim
@@ -0,0 +1,23 @@
+#
+#
+#            Nimrod's Runtime Library
+#        (c) Copyright 2011 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+proc reprInt(x: int64): string {.compilerproc.} = return $x
+
+proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
+  if ntfEnumHole notin typ.flags:
+    if e <% typ.node.len:
+      return $typ.node.sons[e].name
+  else:
+    # ugh we need a slow linear search:
+    var n = typ.node
+    var s = n.sons
+    for i in 0 .. n.len-1:
+      if s[i].offset == e: return $s[i].name
+  result = $e & " (invalid data!)"
+