diff options
author | ASVIEST <71895914+ASVIEST@users.noreply.github.com> | 2024-01-02 09:49:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 07:49:54 +0100 |
commit | 20d79c9fb0cd2e72473f5fb08134cf72d0fdd9e7 (patch) | |
tree | 28fbfbcb69b8fc913101b2b7cf0c12a9b4b1dcce /lib/std | |
parent | c7d742e484e06cdc8d87443a76ec03f1f1724bee (diff) | |
download | Nim-20d79c9fb0cd2e72473f5fb08134cf72d0fdd9e7.tar.gz |
Deprecate asm stmt for js target (#23149)
why ? - We already have an emit that does the same thing - The name asm itself is a bit confusing, you might think it's an alias for asm.js or something else. - The asm keyword is used differently on different compiler targets (it makes it inexpressive). - Does anyone (other than some compiler libraries) use asm instead of emit ? If yes, it's a bit strange to use asm somewhere and emit somewhere. By making the asm keyword for js target deprecated, there would be even less use of the asm keyword for js target, reducing the amount of confusion. - New users might accidentally use a non-universal approach via the asm keyword instead of emit, and then when they learn about asm, try to figure out what the differences are. see https://forum.nim-lang.org/t/10821 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'lib/std')
-rw-r--r-- | lib/std/exitprocs.nim | 16 | ||||
-rw-r--r-- | lib/std/formatfloat.nim | 4 |
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/std/exitprocs.nim b/lib/std/exitprocs.nim index 52e9653df..f26368f42 100644 --- a/lib/std/exitprocs.nim +++ b/lib/std/exitprocs.nim @@ -29,13 +29,13 @@ initLock(gFunsLock) when defined(js): proc addAtExit(quitProc: proc() {.noconv.}) = when defined(nodejs): - asm """ + {.emit: """ process.on('exit', `quitProc`); - """ + """.} elif defined(js): - asm """ + {.emit: """ window.onbeforeunload = `quitProc`; - """ + """.} else: proc addAtExit(quitProc: proc() {.noconv.}) {. importc: "atexit", header: "<stdlib.h>".} @@ -72,16 +72,16 @@ proc addExitProc*(cl: proc() {.noconv.}) = when not defined(nimscript) and (not defined(js) or defined(nodejs)): proc getProgramResult*(): int = when defined(js) and defined(nodejs): - asm """ + {.emit: """ `result` = process.exitCode; -""" +""".} else: result = programResult proc setProgramResult*(a: int) = when defined(js) and defined(nodejs): - asm """ + {.emit: """ process.exitCode = `a`; -""" +""".} else: programResult = a diff --git a/lib/std/formatfloat.nim b/lib/std/formatfloat.nim index 872549c3b..7103b5863 100644 --- a/lib/std/formatfloat.nim +++ b/lib/std/formatfloat.nim @@ -104,7 +104,7 @@ when defined(js): proc nimFloatToString(a: float): cstring = ## ensures the result doesn't print like an integer, i.e. return 2.0, not 2 # print `-0.0` properly - asm """ + {.emit: """ function nimOnlyDigitsOrMinus(n) { return n.toString().match(/^-?\d+$/); } @@ -116,7 +116,7 @@ when defined(js): `result` = `a`+".0" } } - """ + """.} proc addFloat*(result: var string; x: float | float32) {.inline.} = ## Converts float to its string representation and appends it to `result`. |