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>
This commit is contained in:
ASVIEST
2024-01-02 09:49:54 +03:00
committed by GitHub
parent c7d742e484
commit 20d79c9fb0
11 changed files with 121 additions and 114 deletions

View File

@@ -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`.