parent
0f2aa053d9
commit
1785c6877b
25 changed files with 127 additions and 126 deletions
|
|
@ -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`)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -115,7 +115,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 +246,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 +265,7 @@ when not defined(ECMAScript):
|
|||
## doWork()
|
||||
## echo "CPU time [s] ", cpuTime() - t0
|
||||
|
||||
when not defined(ECMAScript):
|
||||
when not defined(JS):
|
||||
|
||||
# C wrapper:
|
||||
type
|
||||
|
|
@ -694,4 +694,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"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue