summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/js/dom.nim (renamed from lib/ecmas/dom.nim)6
-rwxr-xr-xlib/pure/hashes.nim6
-rwxr-xr-xlib/pure/math.nim16
-rwxr-xr-xlib/pure/times.nim17
-rw-r--r--lib/pure/unittest.nim39
-rwxr-xr-xlib/system.nim24
-rwxr-xr-xlib/system/jssys.nim (renamed from lib/system/ecmasys.nim)10
7 files changed, 67 insertions, 51 deletions
diff --git a/lib/ecmas/dom.nim b/lib/js/dom.nim
index 2fb2085b4..d90067176 100755
--- a/lib/ecmas/dom.nim
+++ b/lib/js/dom.nim
@@ -7,10 +7,10 @@
 #    distribution, for details about the copyright.
 #
 
-## Declaration of the Document Object Model for the ECMAScript backend.
+## Declaration of the Document Object Model for the JavaScript backend.
 
-when not defined(ecmascript) and not defined(Nimdoc):
-  {.error: "This module only works on the ECMAScript platform".}
+when not defined(js) and not defined(Nimdoc):
+  {.error: "This module only works on the JavaScript platform".}
 
 type
   TEventHandlers* {.importc.} = object of TObject
diff --git a/lib/pure/hashes.nim b/lib/pure/hashes.nim
index ac6d3c3ce..cf0777ff7 100755
--- a/lib/pure/hashes.nim
+++ b/lib/pure/hashes.nim
@@ -35,7 +35,7 @@ proc `!$`*(h: THash): THash {.inline.} =
 proc hashData*(Data: Pointer, Size: int): THash = 
   ## hashes an array of bytes of size `size`
   var h: THash = 0
-  when defined(ecmascript):
+  when defined(js):
     var p: cstring
     asm """`p` = `Data`;"""
   else:
@@ -48,12 +48,12 @@ proc hashData*(Data: Pointer, Size: int): THash =
     Dec(s)
   result = !$h
 
-when defined(ecmascript):
+when defined(js):
   var objectID = 0
 
 proc hash*(x: Pointer): THash {.inline.} = 
   ## efficient hashing of pointers
-  when defined(ecmascript):
+  when defined(js):
     asm """
       if (typeof `x` == "object") {
         if ("_NimID" in `x`)
diff --git a/lib/pure/math.nim b/lib/pure/math.nim
index f9ab6d0f8..d65330c4a 100755
--- a/lib/pure/math.nim
+++ b/lib/pure/math.nim
@@ -10,7 +10,7 @@
 ##   Constructive mathematics is naturally typed. -- Simon Thompson
 ## 
 ## Basic math routines for Nimrod.
-## This module is available for the ECMAScript target.
+## This module is available for the JavaScript target.
 
 {.push debugger:off .} # the user does not want to trace a part
                        # of the standard library!
@@ -50,7 +50,7 @@ proc classify*(x: float): TFloatClass =
   ## classifies a floating point value. Returns `x`'s class as specified by
   ## `TFloatClass`.
     
-  # ECMAScript and most C compilers have no classify:
+  # JavaScript and most C compilers have no classify:
   if x == 0.0:
     if 1.0/x == Inf:
       return fcZero
@@ -138,15 +138,15 @@ when not defined(windows):
 
 proc randomize*()
   ## initializes the random number generator with a "random"
-  ## number, i.e. a tickcount. Note: Does nothing for the ECMAScript target,
-  ## as ECMAScript does not support this.
+  ## number, i.e. a tickcount. Note: Does nothing for the JavaScript target,
+  ## as JavaScript does not support this.
   
 proc randomize*(seed: int)
   ## initializes the random number generator with a specific seed.
-  ## Note: Does nothing for the ECMAScript target,
-  ## as ECMAScript does not support this.
+  ## Note: Does nothing for the JavaScript target,
+  ## as JavaScript does not support this.
 
-when not defined(ECMAScript):
+when not defined(JS):
   proc sqrt*(x: float): float {.importc: "sqrt", header: "<math.h>".}
     ## computes the square root of `x`.
   
@@ -310,7 +310,7 @@ proc standardDeviation*(s: TRunningStat): float =
 {.pop.}
 {.pop.}
 
-when isMainModule and not defined(ECMAScript):
+when isMainModule and not defined(JS):
   # Verifies random seed initialization.
   let seed = gettime(nil)
   randomize(seed)
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index d84fbbb67..6a73303d9 100755
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -9,7 +9,7 @@
 
 
 ## This module contains routines and types for dealing with time.
-## This module is available for the ECMAScript target.
+## This module is available for the JavaScript target.
 
 {.push debugger:off.} # the user does not want to trace a part
                       # of the standard library!
@@ -58,7 +58,7 @@ elif defined(windows):
   type
     TTime* = distinct TTimeImpl
 
-elif defined(ECMAScript):
+elif defined(JS):
   type
     TTime* {.final, importc.} = object
       getDay: proc (): int
@@ -78,6 +78,7 @@ elif defined(ECMAScript):
       getUTCMinutes: proc (): int
       getUTCMonth: proc (): int
       getUTCSeconds: proc (): int
+      getUTCDay: proc (): int
       getYear: proc (): int
       parse: proc (s: cstring): TTime
       setDate: proc (x: int)
@@ -115,7 +116,7 @@ type
     weekday*: TWeekDay        ## The current day of the week.
     yearday*: range[0..365]   ## The number of days since January 1,
                               ## in the range 0 to 365.
-                              ## Always 0 if the target is ECMAScript.
+                              ## Always 0 if the target is JS.
     isDST*: bool              ## Determines whether DST is in effect. Always
                               ## ``False`` if time is UTC.
     tzname*: string           ## The timezone this time is in. E.g. GMT
@@ -246,7 +247,7 @@ proc `-`*(a: TTimeInfo, interval: TTimeInterval): TTimeInfo =
   else:
     result = getLocalTime(TTime(float(t) - secs))
 
-when not defined(ECMAScript):  
+when not defined(JS):  
   proc epochTime*(): float {.rtl, extern: "nt$1", tags: [FTime].}
     ## gets time after the UNIX epoch (1970) in seconds. It is a float
     ## because sub-second resolution is likely to be supported (depending 
@@ -265,7 +266,7 @@ when not defined(ECMAScript):
     ##   doWork()
     ##   echo "CPU time [s] ", cpuTime() - t0
 
-when not defined(ECMAScript):
+when not defined(JS):
   
   # C wrapper:
   type
@@ -427,7 +428,7 @@ when not defined(ECMAScript):
     proc cpuTime(): float = 
       result = toFloat(int(clock())) / toFloat(clocksPerSec)
     
-else:
+elif defined(JS):
   proc newDate(): TTime {.importc: "new Date", nodecl.}
   proc getTime(): TTime = return newDate()
 
@@ -452,7 +453,7 @@ else:
     result.monthday = t.getUTCDate()
     result.month = TMonth(t.getUTCMonth())
     result.year = t.getUTCFullYear()
-    result.weekday = weekDays[t.getDay()]
+    result.weekday = weekDays[t.getUTCDay()]
     result.yearday = 0
   
   proc TimeInfoToTime*(timeInfo: TTimeInfo): TTime =
@@ -694,4 +695,4 @@ when isMainModule:
   var t4 = getGMTime(TTime(876124714)) # Mon  6 Oct 08:58:34 BST 1997
   assert t4.format("M MM MMM MMMM") == "10 10 Oct October"
   
-  
\ No newline at end of file
+  
diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim
index fce84bea4..71f4d498b 100644
--- a/lib/pure/unittest.nim
+++ b/lib/pure/unittest.nim
@@ -17,7 +17,13 @@
 ## It is loosely based on C++'s boost.test and Haskell's QuickTest
 
 import
-  macros, terminal, os
+  macros
+
+when defined(stdout):
+  import os
+
+when not defined(ECMAScript):
+  import terminal
 
 type
   TTestStatus* = enum OK, FAILED
@@ -52,12 +58,15 @@ proc testDone(name: string, s: TTestStatus) =
     program_result += 1
 
   if OutputLevel != PRINT_NONE and (OutputLevel == PRINT_ALL or s == FAILED):
-    var color = (if s == OK: fgGreen else: fgRed)
-    
-    if ColorOutput:
-      styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"
+    template rawPrint() = echo("[", $s, "] ", name, "\n")
+    when not defined(ECMAScript):
+      if ColorOutput and not defined(ECMAScript):
+        var color = (if s == OK: fgGreen else: fgRed)
+        styledEcho styleBright, color, "[", $s, "] ", fgWhite, name, "\n"
+      else:
+        rawPrint()
     else:
-      echo "[", $s, "] ", name, "\n"
+      rawPrint()
   
 template test*(name: expr, body: stmt): stmt {.immediate, dirty.} =
   bind shouldRun, checkpoints, testDone
@@ -87,7 +96,8 @@ template fail* =
   for msg in items(checkpoints):
     echo msg
 
-  if AbortOnError: quit(1)
+  when not defined(ECMAScript):
+    if AbortOnError: quit(1)
   
   TestStatusIMPL = FAILED
   checkpoints = @[]
@@ -171,14 +181,19 @@ macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} =
   result = getAst(expectBody(errorTypes, exp.lineinfo, body))
 
 
-## Reading settings
-var envOutLvl = os.getEnv("NIMTEST_OUTPUT_LVL").string
+when defined(stdout):
+  ## Reading settings
+  var envOutLvl = os.getEnv("NIMTEST_OUTPUT_LVL").string
+
+  AbortOnError = existsEnv("NIMTEST_ABORT_ON_ERROR")
+  ColorOutput  = not existsEnv("NIMTEST_NO_COLOR")
+
+else:
+  var envOutLvl = "" # TODO
+  ColorOutput  = false
 
 if envOutLvl.len > 0:
   for opt in countup(low(TOutputLevel), high(TOutputLevel)):
     if $opt == envOutLvl:
       OutputLevel = opt
       break
-
-AbortOnError = existsEnv("NIMTEST_ABORT_ON_ERROR")
-ColorOutput  = not existsEnv("NIMTEST_NO_COLOR")
diff --git a/lib/system.nim b/lib/system.nim
index b4c265f62..ea765644c 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -184,7 +184,7 @@ proc `..`*[T](b: T): TSlice[T] {.noSideEffect, inline.} =
 when not defined(niminheritable):
   {.pragma: inheritable.}
 
-when not defined(EcmaScript) and not defined(NimrodVM):
+when not defined(JS) and not defined(NimrodVM):
   type
     TGenericSeq* {.compilerproc, pure, inheritable.} = object
       len, reserved: int
@@ -900,7 +900,7 @@ template sysAssert(cond: bool, msg: string) =
 
 include "system/inclrtl"
 
-when not defined(ecmascript) and not defined(nimrodVm) and hostOS != "standalone":
+when not defined(JS) and not defined(nimrodVm) and hostOS != "standalone":
   include "system/cgprocs"
 
 proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}
@@ -1170,7 +1170,7 @@ proc `$` *(x: int64): string {.magic: "Int64ToStr", noSideEffect.}
   ## converted to a decimal string.
 
 when not defined(NimrodVM):
-  when not defined(ECMAScript):
+  when not defined(JS):
     proc `$` *(x: uint64): string {.noSideEffect.}
       ## The stingify operator for an unsigned integer argument. Returns `x`
       ## converted to a decimal string.
@@ -1422,7 +1422,7 @@ proc `&` *[T](x: T, y: seq[T]): seq[T] {.noSideEffect.} =
   result[y.len] = x
 
 when not defined(NimrodVM):
-  when not defined(ECMAScript):
+  when not defined(JS):
     proc seqToPtr[T](x: seq[T]): pointer {.inline, nosideeffect.} =
       result = cast[pointer](x)
   else:
@@ -1698,7 +1698,7 @@ type
     filename: CString
     len: int  # length of slots (when not debugging always zero)
 
-when not defined(ECMAScript):
+when not defined(JS):
   {.push stack_trace:off, profiler:off.}
   proc add*(x: var string, y: cstring) {.noStackFrame.} =
     var i = 0
@@ -1724,7 +1724,7 @@ proc echo*[T](x: varargs[T, `$`]) {.magic: "Echo", tags: [FWriteIO].}
   ## is converted to a string via ``$``, so it works for user-defined
   ## types that have an overloaded ``$`` operator.
   ## It is roughly equivalent to ``writeln(stdout, x); flush(stdout)``, but
-  ## available for the ECMAScript target too.
+  ## available for the JavaScript target too.
   ## Unlike other IO operations this is guaranteed to be thread-safe as
   ## ``echo`` is very often used for debugging convenience.
 
@@ -1747,7 +1747,7 @@ proc getTypeInfo*[T](x: T): pointer {.magic: "GetTypeInfo".}
   ## get type information for `x`. Ordinary code should not use this, but
   ## the `typeinfo` module instead.
 
-when not defined(EcmaScript): #and not defined(NimrodVM):
+when not defined(JS): #and not defined(NimrodVM):
   {.push stack_trace: off, profiler:off.}
 
   when not defined(NimrodVM):
@@ -2166,7 +2166,7 @@ when not defined(EcmaScript): #and not defined(NimrodVM):
       `result` = *((NI*) `x`.ClEnv) < 0;
       """.}
 
-elif defined(ecmaScript):
+elif defined(JS):
   # Stubs:
   proc nimGCvisit(d: pointer, op: int) {.compilerRtl.} = nil
 
@@ -2192,8 +2192,8 @@ elif defined(ecmaScript):
   proc deallocShared(p: pointer) = nil
   proc reallocShared(p: pointer, newsize: int): pointer = nil
 
-  when defined(ecmaScript):
-    include "system/ecmasys"
+  when defined(JS):
+    include "system/jssys"
     include "system/reprjs"
   elif defined(NimrodVM):
     proc cmp(x, y: string): int =
@@ -2437,7 +2437,7 @@ proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
   ## marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
   ## perform deep copies of `s`. This is only useful for optimization 
   ## purposes.
-  when not defined(EcmaScript) and not defined(NimrodVM):
+  when not defined(JS) and not defined(NimrodVM):
     var s = cast[PGenericSeq](s)
     s.reserved = s.reserved or seqShallowFlag
 
@@ -2445,7 +2445,7 @@ proc shallow*(s: var string) {.noSideEffect, inline.} =
   ## marks a string `s` as `shallow`:idx:. Subsequent assignments will not
   ## perform deep copies of `s`. This is only useful for optimization 
   ## purposes.
-  when not defined(EcmaScript) and not defined(NimrodVM):
+  when not defined(JS) and not defined(NimrodVM):
     var s = cast[PGenericSeq](s)
     s.reserved = s.reserved or seqShallowFlag
 
diff --git a/lib/system/ecmasys.nim b/lib/system/jssys.nim
index f78b7f68c..789e39d6d 100755
--- a/lib/system/ecmasys.nim
+++ b/lib/system/jssys.nim
@@ -42,7 +42,7 @@ proc nimCharToStr(x: char): string {.compilerproc.} =
   result = newString(1)
   result[0] = x
 
-proc getCurrentExceptionMsg(): string =
+proc getCurrentExceptionMsg*(): string =
   if excHandler != nil: return $excHandler.exc.msg
   return ""
 
@@ -151,7 +151,7 @@ proc cstrToNimstr(c: cstring): string {.noStackFrame, compilerproc.} =
     return result;
   """
 
-proc toEcmaStr(s: string): cstring {.noStackFrame, compilerproc.} =
+proc toJSStr(s: string): cstring {.noStackFrame, compilerproc.} =
   asm """
     var len = `s`.length-1;
     var result = new Array(len);
@@ -304,7 +304,7 @@ when defined(kwin):
     asm """
       var buf = "";
       for (var i = 0; i < arguments.length; ++i) {
-        buf += `toEcmaStr`(arguments[i]);
+        buf += `toJSStr`(arguments[i]);
       }
       print(buf);
     """
@@ -316,7 +316,7 @@ elif defined(nodejs):
     asm """
       var buf = "";
       for (var i = 0; i < arguments.length; ++i) {
-        buf += `toEcmaStr`(arguments[i]);
+        buf += `toJSStr`(arguments[i]);
       }
       console.log(buf);
     """
@@ -338,7 +338,7 @@ else:
     if node == nil: raise newException(EIO, "<body> element does not exist yet!")
     asm """
       for (var i = 0; i < arguments.length; ++i) {
-        var x = `toEcmaStr`(arguments[i]);
+        var x = `toJSStr`(arguments[i]);
         `node`.appendChild(document.createTextNode(x))
       }
     """
'oid'>9a7f0cd85 ^
8c6290342 ^
5d63ecb3a ^




ed0d9e271 ^






08c0ba379 ^
2962ca789 ^

08c0ba379 ^

ab26298a0 ^
08c0ba379 ^


8ef66b973 ^


2962ca789 ^
efb53233c ^
af792da0b ^


78f4aacde ^
4fbba0a65 ^
0257f389f ^
8c6290342 ^
9a7f0cd85 ^
105a0616a ^


ed0d9e271 ^

2b80d75aa ^



5d63ecb3a ^
29a916696 ^

5d63ecb3a ^
29a916696 ^

5d63ecb3a ^
29a916696 ^


5d63ecb3a ^
29a916696 ^

5d63ecb3a ^



29a916696 ^
5d63ecb3a ^



29a916696 ^
5d63ecb3a ^




4be0d1652 ^






2962ca789 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220