Support code hot reloading for JavaScript projects (#7362)

* Support code hot reloading for JavaScript projects

* Add some missing JavaScript symbols and APIs

* fix the Travis build

* (review changes) remove the js type from the standard library as it doesn't follow NEP-1

* more additions to the DOM module

* Follow NEP-1 in jsffi; spell 'hot code reloading' correctly

* introduce a jscore module

* Document jscore module.

* readded js type

* Remove the '$' operator that doesn't behave
This commit is contained in:
zah 2018-04-13 20:08:43 +03:00 • committed by Andreas Rumpf
commit e3037a2f33
14 changed files with 285 additions and 68 deletions

View file

@ -9,7 +9,7 @@
## Computes hash values for routine (proc, method etc) signatures.
import ast, md5
import ast, md5, tables, ropes
from hashes import Hash
from astalgo import debug
from types import typeToString, preferDesc
@ -326,3 +326,32 @@ proc hashOwner*(s: PSym): SigHash =
c &= m.name.s
md5Final c, result.Md5Digest
proc idOrSig*(s: PSym, currentModule: string,
sigCollisions: var CountTable[SigHash]): Rope =
if s.kind in routineKinds and s.typ != nil:
# signatures for exported routines are reliable enough to
# produce a unique name and this means produced C++ is more stable wrt
# Nim changes:
let sig = hashProc(s)
result = rope($sig)
#let m = if s.typ.callConv != ccInline: findPendingModule(m, s) else: m
let counter = sigCollisions.getOrDefault(sig)
#if sigs == "_jckmNePK3i2MFnWwZlp6Lg" and s.name.s == "contains":
# echo "counter ", counter, " ", s.id
if counter != 0:
result.add "_" & rope(counter+1)
# this minor hack is necessary to make tests/collections/thashes compile.
# The inlined hash function's original module is ambiguous so we end up
# generating duplicate names otherwise:
if s.typ.callConv == ccInline:
result.add rope(currentModule)
sigCollisions.inc(sig)
else:
let sig = hashNonProc(s)
result = rope($sig)
let counter = sigCollisions.getOrDefault(sig)
if counter != 0:
result.add "_" & rope(counter+1)
sigCollisions.inc(sig)