style fix: change 'JS' to 'js' to make it consistent (#13168)

This commit is contained in:
Miran
2020-01-16 14:14:03 +01:00
committed by Andreas Rumpf
parent 54bfd69a27
commit 352232e62d
14 changed files with 60 additions and 60 deletions

View File

@@ -26,7 +26,7 @@ when defined(hotcodereloading):
proc hasAnyModuleChanged*(): bool = hcrReloadNeeded()
when not defined(JS):
when not defined(js):
template performCodeReload* =
when isMainModule:
{.warning: "Code residing in the main module will not be changed from calling a code-reload".}

View File

@@ -196,7 +196,7 @@
# block. Perhaps something can be done about this - some way of re-allocating
# the state and transferring the old...
when not defined(JS) and (defined(hotcodereloading) or
when not defined(js) and (defined(hotcodereloading) or
defined(createNimHcr) or
defined(testNimHcr)):
const
@@ -612,7 +612,7 @@ when defined(createNimHcr):
global.markerProc()
elif defined(hotcodereloading) or defined(testNimHcr):
when not defined(JS):
when not defined(js):
const
nimhcrLibname = when defined(windows): "nimhcr." & dllExt
elif defined(macosx): "libnimhcr." & dllExt

View File

@@ -151,7 +151,7 @@ proc hash*[A](x: openArray[A]): Hash
proc hash*[A](x: set[A]): Hash
when defined(JS):
when defined(js):
proc imul(a, b: uint32): uint32 =
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
let mask = 0xffff'u32
@@ -267,7 +267,7 @@ proc hash*(x: cstring): Hash =
inc i
result = !$result
else:
when not defined(JS) and defined(nimToOpenArrayCString):
when not defined(js) and defined(nimToOpenArrayCString):
murmurHash(toOpenArrayByte(x, 0, x.high))
else:
let xx = $x

View File

@@ -263,7 +263,7 @@ proc cumsum*[T](x: var openArray[T]) =
for i in 1 ..< x.len: x[i] = x[i-1] + x[i]
{.push noSideEffect.}
when not defined(JS): # C
when not defined(js): # C
proc sqrt*(x: float32): float32 {.importc: "sqrtf", header: "<math.h>".}
proc sqrt*(x: float64): float64 {.importc: "sqrt", header: "<math.h>".}
## Computes the square root of ``x``.
@@ -329,7 +329,7 @@ proc log*[T: SomeFloat](x, base: T): T =
## echo log(8.0, -2.0) ## nan
ln(x) / ln(base)
when not defined(JS): # C
when not defined(js): # C
proc log10*(x: float32): float32 {.importc: "log10f", header: "<math.h>".}
proc log10*(x: float64): float64 {.importc: "log10", header: "<math.h>".}
## Computes the common logarithm (base 10) of ``x``.
@@ -562,7 +562,7 @@ proc arccsch*[T: float32|float64](x: T): T = arcsinh(1.0 / x)
const windowsCC89 = defined(windows) and defined(bcc)
when not defined(JS): # C
when not defined(js): # C
proc hypot*(x, y: float32): float32 {.importc: "hypotf", header: "<math.h>".}
proc hypot*(x, y: float64): float64 {.importc: "hypot", header: "<math.h>".}
## Computes the hypotenuse of a right-angle triangle with ``x`` and
@@ -851,7 +851,7 @@ proc floorMod*[T: SomeNumber](x, y: T): T =
result = x mod y
if (result > 0 and y < 0) or (result < 0 and y > 0): result += y
when not defined(JS):
when not defined(js):
proc c_frexp*(x: float32, exponent: var int32): float32 {.
importc: "frexp", header: "<math.h>".}
proc c_frexp*(x: float64, exponent: var int32): float64 {.
@@ -1104,7 +1104,7 @@ proc lcm*[T](x: openArray[T]): T {.since: (1, 1).} =
result = lcm(result, x[i])
inc(i)
when isMainModule and not defined(JS) and not windowsCC89:
when isMainModule and not defined(js) and not windowsCC89:
# Check for no side effect annotation
proc mySqrt(num: float): float {.noSideEffect.} =
return sqrt(num)

View File

@@ -83,7 +83,7 @@ import algorithm #For upperBound
include "system/inclrtl"
{.push debugger: off.}
when defined(JS):
when defined(js):
type Ui = uint32
const randMax = 4_294_967_295u32
@@ -108,7 +108,7 @@ type
## generator are **not** thread-safe!
a0, a1: Ui
when defined(JS):
when defined(js):
var state = Rand(
a0: 0x69B4C98Cu32,
a1: 0xFED1DD30u32) # global for backwards compatibility
@@ -190,7 +190,7 @@ proc skipRandomNumbers*(s: var Rand) =
##
## See also:
## * `next proc<#next,Rand>`_
when defined(JS):
when defined(js):
const helper = [0xbeac0467u32, 0xd86b048bu32]
else:
const helper = [0xbeac0467eba5facbu64, 0xd86b048b86aa9922u64]
@@ -216,7 +216,7 @@ proc random*(max: int): int {.benign, deprecated:
proc random*(max: float): float {.benign, deprecated:
"Deprecated since v0.18.0; use 'rand' instead".} =
let x = next(state)
when defined(JS):
when defined(js):
result = (float(x) / float(high(uint32))) * max
else:
let u = (0x3FFu64 shl 52u64) or (x shr 12u64)
@@ -287,7 +287,7 @@ proc rand*(r: var Rand; max: range[0.0 .. high(float)]): float {.benign.} =
let f = r.rand(1.0)
## f = 8.717181376738381e-07
let x = next(r)
when defined(JS):
when defined(js):
result = (float(x) / float(high(uint32))) * max
else:
let u = (0x3FFu64 shl 52u64) or (x shr 12u64)
@@ -641,7 +641,7 @@ when not defined(nimscript) and not defined(standalone):
## See also:
## * `randomize proc<#randomize,int64>`_ that accepts a seed
## * `initRand proc<#initRand,int64>`_
when defined(JS):
when defined(js):
let time = int64(times.epochTime() * 1000) and 0x7fff_ffff
randomize(time)
else:

View File

@@ -196,7 +196,7 @@ import strutils, math, options
include "system/inclrtl"
when defined(JS):
when defined(js):
import jscore
# This is really bad, but overflow checks are broken badly for
@@ -1070,7 +1070,7 @@ proc toAdjTime(dt: DateTime): Time =
seconds.inc dt.second
result = initTime(seconds, dt.nanosecond)
when defined(JS):
when defined(js):
proc localZonedTimeFromTime(time: Time): ZonedTime =
let jsDate = newDate(time.seconds * 1000)
let offset = jsDate.getTimezoneOffset() * secondsInMin
@@ -1200,7 +1200,7 @@ proc local*(t: Time): DateTime =
proc getTime*(): Time {.tags: [TimeEffect], benign.} =
## Gets the current time as a ``Time`` with up to nanosecond resolution.
when defined(JS):
when defined(js):
let millis = newDate().getTime()
let seconds = convert(Milliseconds, Seconds, millis)
let nanos = convert(Milliseconds, Nanoseconds,
@@ -2498,7 +2498,7 @@ proc toTimeInterval*(time: Time): TimeInterval
initTimeInterval(dt.nanosecond, 0, 0, dt.second, dt.minute, dt.hour,
dt.monthday, 0, dt.month.ord - 1, dt.year)
when not defined(JS):
when not defined(js):
type
Clock {.importc: "clock_t".} = distinct int
@@ -2559,7 +2559,7 @@ when not defined(JS):
else:
{.error: "unknown OS".}
when defined(JS):
when defined(js):
proc epochTime*(): float {.tags: [TimeEffect].} =
newDate().getTime() / 1000
@@ -2664,7 +2664,7 @@ proc fractional*(dur: Duration): Duration {.inline, deprecated.} =
nanoseconds = 9)
initDuration(nanoseconds = dur.nanosecond)
when not defined(JS):
when not defined(js):
proc unixTimeToWinTime*(time: CTime): int64
{.deprecated: "Use toWinTime instead".} =
## Converts a UNIX `Time` (``time_t``) to a Windows file time
@@ -2731,7 +2731,7 @@ proc getTimezone*(): int
##
## **Deprecated since v0.18.0:** use ``now().utcOffset`` to get the current
## utc offset (including DST).
when defined(JS):
when defined(js):
return newDate().getTimezoneOffset() * 60
elif defined(freebsd) or defined(netbsd) or defined(openbsd):
# This is wrong since it will include DST offsets, but the behavior has

View File

@@ -100,7 +100,7 @@ proc getMonoTime*(): MonoTime {.tags: [TimeEffect].} =
## this proc calls `window.performance.now()`, which is not supported by
## older browsers. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now)
## for more information.
when defined(JS):
when defined(js):
let ticks = getJsTicks()
result = MonoTime(ticks: (ticks * 1_000_000_000).int64)
elif defined(macosx):
@@ -171,4 +171,4 @@ when isMainModule:
doAssert t1 <= t1
doAssert not(t2 < t1)
doAssert t1 < high(MonoTime)
doAssert low(MonoTime) < t1
doAssert low(MonoTime) < t1

View File

@@ -477,9 +477,9 @@ include "system/inclrtl"
const NoFakeVars* = defined(nimscript) ## `true` if the backend doesn't support \
## "fake variables" like `var EBADF {.importc.}: cint`.
const notJSnotNims = not defined(JS) and not defined(nimscript)
const notJSnotNims = not defined(js) and not defined(nimscript)
when not defined(JS) and not defined(nimSeqsV2):
when not defined(js) and not defined(nimSeqsV2):
type
TGenericSeq {.compilerproc, pure, inheritable.} = object
len, reserved: int
@@ -520,7 +520,7 @@ type
include "system/exceptions"
when defined(JS) or defined(nimdoc):
when defined(js) or defined(nimdoc):
type
JsRoot* = ref object of RootObj
## Root type of the JavaScript object hierarchy
@@ -625,7 +625,7 @@ proc newSeqOfCap*[T](cap: Natural): seq[T] {.
## assert len(x) == 1
discard
when not defined(JS):
when not defined(js):
proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] =
## Creates a new sequence of type ``seq[T]`` with length ``len``.
##
@@ -1103,7 +1103,7 @@ const
## is the value that should be passed to `quit <#quit,int>`_ to indicate
## failure.
when defined(JS) and defined(nodejs) and not defined(nimscript):
when defined(js) and defined(nodejs) and not defined(nimscript):
var programResult* {.importc: "process.exitCode".}: int
programResult = 0
elif hostOS != "standalone":
@@ -1145,7 +1145,7 @@ elif defined(genode):
proc quit*(errorcode: int = QuitSuccess) =
systemEnv.quit(errorcode)
elif defined(JS) and defined(nodejs) and not defined(nimscript):
elif defined(js) and defined(nodejs) and not defined(nimscript):
proc quit*(errorcode: int = QuitSuccess) {.magic: "Exit",
importc: "process.exit", noreturn.}
@@ -1237,7 +1237,7 @@ proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
when nimvm:
defaultImpl()
else:
when defined(JS):
when defined(js):
{.emit: "`x`.splice(`i`, 1);".}
else:
defaultImpl()
@@ -1258,7 +1258,7 @@ proc insert*[T](x: var seq[T], item: T, i = 0.Natural) {.noSideEffect.} =
when nimvm:
defaultImpl()
else:
when defined(JS):
when defined(js):
var it : T
{.emit: "`x` = `x` || []; `x`.splice(`i`, 0, `it`);".}
else:
@@ -1288,7 +1288,7 @@ type
## compiler supports. Currently this is ``float64``, but it is
## platform-dependent in general.
when defined(JS):
when defined(js):
type BiggestUInt* = uint32
## is an alias for the biggest unsigned integer type the Nim compiler
## supports. Currently this is ``uint32`` for JS and ``uint64`` for other
@@ -1424,7 +1424,7 @@ proc swap*[T](a, b: var T) {.magic: "Swap", noSideEffect.}
## assert a == 9
## assert b == 5
when not defined(JS) and not defined(booting) and defined(nimTrMacros):
when not defined(js) and not defined(booting) and defined(nimTrMacros):
template swapRefsInArray*{swap(arr[a], arr[b])}(arr: openArray[ref], a, b: int) =
# Optimize swapping of array elements if they are refs. Default swap
# implementation will cause unsureAsgnRef to be emitted which causes
@@ -1613,12 +1613,12 @@ when notJSnotNims:
{.push stackTrace: off.}
when not defined(JS) and hasThreadSupport and hostOS != "standalone":
when not defined(js) and hasThreadSupport and hostOS != "standalone":
const insideRLocksModule = false
include "system/syslocks"
include "system/threadlocalstorage"
when not defined(JS) and defined(nimV2):
when not defined(js) and defined(nimV2):
type
TNimNode {.compilerproc.} = object # to keep the code generator simple
DestructorProc = proc (p: pointer) {.nimcall, benign, raises: [].}
@@ -1827,7 +1827,7 @@ type
len*: int16 ## Length of the inspectable slots.
calldepth*: int16 ## Used for max call depth checking.
when defined(JS):
when defined(js):
proc add*(x: var string, y: cstring) {.asmNoStackFrame.} =
asm """
if (`x` === null) { `x` = []; }
@@ -1920,7 +1920,7 @@ proc abs*(x: int64): int64 {.magic: "AbsI", noSideEffect.} =
{.pop.}
when not defined(JS):
when not defined(js):
proc likelyProc(val: bool): bool {.importc: "NIM_LIKELY", nodecl, noSideEffect.}
proc unlikelyProc(val: bool): bool {.importc: "NIM_UNLIKELY", nodecl, noSideEffect.}
@@ -1943,7 +1943,7 @@ template likely*(val: bool): bool =
when nimvm:
val
else:
when defined(JS):
when defined(js):
val
else:
likelyProc(val)
@@ -1967,7 +1967,7 @@ template unlikely*(val: bool): bool =
when nimvm:
val
else:
when defined(JS):
when defined(js):
val
else:
unlikelyProc(val)
@@ -2003,7 +2003,7 @@ type
fspEnd ## Seek relative to end
when not defined(JS):
when not defined(js):
{.push stackTrace: off, profiler: off.}
when hasAlloc:
@@ -2034,7 +2034,7 @@ when not defined(JS):
{.pop.}
when not defined(JS):
when not defined(js):
# ugly hack, see the accompanying .pop for
# the mysterious error message
{.push stackTrace: off, profiler: off.}
@@ -2055,7 +2055,7 @@ when notJSnotNims:
proc equalMem(a, b: pointer, size: Natural): bool =
nimCmpMem(a, b, size) == 0
when not defined(JS):
when not defined(js):
proc cmp(x, y: string): int =
when defined(nimscript):
if x < y: result = -1
@@ -2087,7 +2087,7 @@ when not defined(JS):
result = cstringArrayToSeq(a, L)
when not defined(JS) and declared(alloc0) and declared(dealloc):
when not defined(js) and declared(alloc0) and declared(dealloc):
proc allocCStringArray*(a: openArray[string]): cstringArray =
## Creates a NULL terminated cstringArray from `a`. The result has to
## be freed with `deallocCStringArray` after it's not needed anymore.
@@ -2115,7 +2115,7 @@ when notJSnotNims:
context: C_JmpBuf
SafePoint = TSafePoint
when not defined(JS):
when not defined(js):
when declared(initAllocator):
initAllocator()
when hasThreadSupport:
@@ -2157,7 +2157,7 @@ when notJSnotNims:
{.pop.}
when not defined(JS):
when not defined(js):
# this is a hack: without this when statement, you would get:
# Error: system module needs: nimGCvisit
{.pop.} # stackTrace: off, profiler: off
@@ -2264,7 +2264,7 @@ when notJSnotNims:
`result` = ((NI*) `x`.ClE_0)[1] < 0;
""".}
when defined(JS):
when defined(js):
when not defined(nimscript):
include "system/jssys"
include "system/reprjs"
@@ -2274,7 +2274,7 @@ when defined(JS):
if x < y: return -1
return 1
when defined(JS) or defined(nimscript):
when defined(js) or defined(nimscript):
proc addInt*(result: var string; x: int64) =
result.add $x
@@ -2283,7 +2283,7 @@ when defined(JS) or defined(nimscript):
proc quit*(errormsg: string, errorcode = QuitFailure) {.noreturn.} =
## A shorthand for ``echo(errormsg); quit(errorcode)``.
when defined(nimscript) or defined(JS) or (hostOS == "standalone"):
when defined(nimscript) or defined(js) or (hostOS == "standalone"):
echo errormsg
else:
when nimvm:
@@ -2584,7 +2584,7 @@ proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
##
## This is only useful for optimization purposes.
if s.len == 0: return
when not defined(JS) and not defined(nimscript) and not defined(nimSeqsV2):
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
var s = cast[PGenericSeq](s)
s.reserved = s.reserved or seqShallowFlag
@@ -2593,7 +2593,7 @@ proc shallow*(s: var string) {.noSideEffect, inline.} =
## perform deep copies of `s`.
##
## This is only useful for optimization purposes.
when not defined(JS) and not defined(nimscript) and not defined(nimSeqsV2):
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
var s = cast[PGenericSeq](s)
if s == nil:
s = cast[PGenericSeq](newString(0))
@@ -2880,7 +2880,7 @@ proc substr*(s: string, first = 0): string =
when defined(nimconfig):
include "system/nimscript"
when not defined(JS):
when not defined(js):
proc toOpenArray*[T](x: ptr UncheckedArray[T]; first, last: int): openArray[T] {.
magic: "Slice".}
when defined(nimToOpenArrayCString):

View File

@@ -105,7 +105,7 @@ when defined(nimNoZeroExtendMagic):
## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int32](x)
elif not defined(JS):
elif not defined(js):
proc ze*(x: int8): int {.magic: "Ze8ToI", noSideEffect, deprecated.}
## zero extends a smaller integer type to ``int``. This treats `x` as
## unsigned.

View File

@@ -283,7 +283,7 @@ proc `==`*[T](x, y: seq[T]): bool {.noSideEffect.} =
if x.len == 0 and y.len == 0:
return true
else:
when not defined(JS):
when not defined(js):
proc seqToPtr[T](x: seq[T]): pointer {.inline, noSideEffect.} =
when defined(nimSeqsV2):
result = cast[NimSeqV2[T]](x).p

View File

@@ -13,7 +13,7 @@ when hasAlloc:
gcOptimizeTime, ## optimize for speed
gcOptimizeSpace ## optimize for memory footprint
when hasAlloc and not defined(JS) and not usesDestructors:
when hasAlloc and not defined(js) and not usesDestructors:
proc GC_disable*() {.rtl, inl, benign.}
## Disables the GC. If called `n` times, `n` calls to `GC_enable`
## are needed to reactivate the GC.
@@ -58,7 +58,7 @@ when hasAlloc and not defined(JS) and not usesDestructors:
## Expands operating GC stack range to `theStackBottom`. Does nothing
## if current stack bottom is already lower than `theStackBottom`.
when hasAlloc and defined(JS):
when hasAlloc and defined(js):
template GC_disable* =
{.warning: "GC_disable is a no-op in JavaScript".}

View File

@@ -229,7 +229,7 @@ when hasAlloc:
## Returns the number of bytes that are owned by the process.
when defined(JS):
when defined(js):
# Stubs:
proc getOccupiedMem(): int = return -1
proc getFreeMem(): int = return -1

View File

@@ -4,7 +4,7 @@ discard """
action: compile
"""
when defined(JS):
when defined(js):
var foo = proc(): void{.codegenDecl: "/*HELLO*/function $2($3)".} =
echo "baa"
else:

View File

@@ -21,7 +21,7 @@ proc foo() =
foo()
# #376
when not defined(JS):
when not defined(js):
proc foo(val: float): string = "no js " & $val
else:
proc foo(val: float): string = "js " & $val