summary refs log tree commit diff stats
path: root/compiler/jsgen.nim
Commit message (Collapse)AuthorAgeFilesLines
* enable closures tests for JS & implement `finished` for JS (#23521)ringabout2024-09-091-10/+12
|
* fixes push warnings for sempass2 (#23603)ringabout2024-09-031-4/+4
| | | ref https://forum.nim-lang.org/t/11590
* fixes #24031; js codegen bug for case statement with just else branch (#24047)ringabout2024-09-021-2/+7
| | | fixes #24031
* remove fauxMatch for tyFromExpr, remove tyProxy and tyUnknown aliases (#24018)metagn2024-08-281-1/+1
| | | | | | | | | | | | | | | | | | | | | updated version of #22193 After #22029 and the followups #23983 and #24005 which fixed issues with it, `tyFromExpr` no longer match any proc params in generic type bodies but delay all non-matching calls until the type is instantiated. Previously the mechanism `fauxMatch` was used to pretend that any failing match against `tyFromExpr` actually matched, but prevented the instantiation of the type until later. Since this mechanism is not needed anymore for `tyFromExpr`, it is now only used for `tyError` to prevent cascading errors and changed to a bool field for simplicity. A change in `semtypes` was also needed to prevent calling `fitNode` on default param values resolving to type `tyFromExpr` in generic procs for params with non-generic types, as this would try to coerce the expression into a concrete type when it can't be instantiated yet. The aliases `tyProxy` and `tyUnknown` for `tyError` and `tyFromExpr` are also removed for uniformity.
* fixes jsbigint64 regression; keeps convs to `Number` in danger mode (#23926)ringabout2024-08-111-1/+7
| | | fixes jsbigint64 regression
* refactor: The popular 'r' field is now named 'snippet' (#23829)Andreas Rumpf2024-07-121-51/+51
|
* implement `legacy:jsNoLambdaLifting` for compatibility (#23727)ringabout2024-06-171-18/+61
|
* improve view types for jsgen; eliminate unnecessary copies of view types ↵ringabout2024-06-021-2/+2
| | | | (#23654)
* fixes openarray views default values in JS (#23607)ringabout2024-05-141-2/+2
|
* rework `wasMoved`, `move` on the JS backend (#23577)ringabout2024-05-081-7/+8
| | | | | `reset`, `wasMoved` and `move` doesn't support primitive types, which generate `null` for these types. It is now produce `x = default(...)` in the backend. Ideally it should be done by ast2ir in the future
* adds another fix for concept in JS (#23535)ringabout2024-04-241-1/+1
| | | ref https://github.com/nim-lang/Nim/issues/9550
* remove php code from jsgen (#23502)ringabout2024-04-181-14/+0
| | | | follow up https://github.com/nim-lang/Nim/pull/7606 https://github.com/nim-lang/Nim/pull/13466
* remove `|| []` from jsgen because string cannot be nil anymore (#23508)ringabout2024-04-181-3/+3
| | | introduced in https://github.com/nim-lang/Nim/pull/9411
* fixes #23492; fixes JS float range causes compiler crash (#23517)ringabout2024-04-181-1/+1
| | | | | | | | | | | | | | | fixes #23492 ```nim proc foo = var x: range[1.0 .. 5.0] = 2.0 case x of 1.0..2.0: echo 1 else: echo 3 foo() ```
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-181-5/+13
| | | | | | | | | | | | | | | | | | | | | | | fixes #4695 ref https://github.com/nim-lang/Nim/pull/15818 Since `nkState` is only for the main loop state labels and `nkGotoState` is used only for dispatching the `:state` (since https://github.com/nim-lang/Nim/pull/7770), it's feasible to rewrite the loop body into a single case-based dispatcher, which enables support for JS, VM backend. `nkState` Node is replaced by a label and Node pair and `nkGotoState` is only used for intermediary processing. Backends only need to implement `nkBreakState` and `closureIterSetupExc` to support closure iterators. pending https://github.com/nim-lang/Nim/pull/23484 <del> I also observed some performance boost for C backend in the release mode (not in the danger mode though, I suppose the old implementation is optimized into computed goto in the danger mode) </del> allPathsAsgnResult???
* [JS backend] improve `discard` statement; ridding of the awkward special ↵ringabout2024-04-131-1/+1
| | | | | | | | | | variable `_` (#23498) According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/Expression_statement, some expression statements need parentheses to make it unambiguous. `_` introduced in the https://github.com/nim-lang/Nim/pull/15789 is unnecessary. We can get rid of it by adding parentheses so that object literals are not ambiguous with block statements.
* fixes #4299 #12492 #10849; lambda lifting for JS backend (#23484)ringabout2024-04-111-49/+51
| | | | | | | | fixes #4299 fixes #12492 fixes #10849 It binds `function` with `env`: `function.bind(:env)` to ease codegen for now
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-101-1/+1
|
* remove unused magics: mIntToStr, mInt64ToStr, mFloatToStr (#23486)ringabout2024-04-091-6/+1
| | | mIntToStr, mInt64ToStr, mFloatToStr,
* apply the new mangle algorithm to JS backend for parameters and procs (#23476)ringabout2024-04-051-2/+7
| | | | | | | | | | | | | | the function name extension encoded by paths could be useful for debugging where the function is from Before: ```js function newSeq_33556909(len_33556911) ``` After: ```js function newSeq__system_u2477(len_p0) ```
* fixes #16771; lower `swap` for JS backend (#23473)ringabout2024-04-031-13/+4
| | | | | | | | | | | | fixes #16771 follow up https://github.com/nim-lang/Nim/pull/16536 Ideally it should be handled in the IR part in the future I have also checked the double evaluation of `swap` in the JS runtime https://github.com/nim-lang/Nim/issues/16779, that might be solved by a copy flag or something. Well, it should be best solved in the IR so that it doesn't bother backends anymore.
* fixes #9550; Concept related crash only when compiling to JS (#23470)ringabout2024-04-021-1/+1
| | | fixes #9550
* fixes #23382; gives compiler errors for closure iterators in JS (#23398)ringabout2024-03-141-1/+3
| | | | fixes #23382 follow up https://github.com/nim-lang/Nim/pull/15823
* fixes #23378; fixes js abs negative int64 (#23379)ringabout2024-03-091-1/+7
| | | fixes #23378
* Deprecate asm stmt for js target (#23149)ASVIEST2024-01-021-3/+9
| | | | | | | | | | | | | | | | | | | | | | | 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>
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-121-11/+11
|
* rework the vtable implementation embedding the vtable array directly with ↵ringabout2023-11-281-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | new strictions on methods (#22991) **TODO** - [x] fixes changelog With the new option `nimPreviewVtables`, `methods` are confined in the same module where the type of the first parameter is defined - [x] make it opt in after CI checks its feasibility ## In the following-up PRs - [ ] in the following PRs, refactor code into a more efficient one - [ ] cpp needs special treatments since it cannot embed array in light of the preceding limits: ref https://github.com/nim-lang/Nim/pull/20977#discussion_r1035528927; we can support cpp backends with vtable implementations later on the comprise that uses indirect vtable access --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-291-2/+2
| | | follow up https://github.com/nim-lang/Nim/pull/22851
* NIR: progress (#22817)Andreas Rumpf2023-10-121-1/+1
| | | | | | Done: - [x] Implement conversions to openArray/varargs. - [x] Implement index/range checking.
* make float32 literals stringifying behave in JS the same as in C (#22500)ringabout2023-08-171-2/+7
|
* replaces `doAssert false` with `raiseAssert` for unreachable branches, which ↵ringabout2023-08-101-2/+1
| | | | | works better with strictdefs (#22436) replaces `doAssert false` with `raiseAssert`, which works better with strictdefs
* simplify isAtom condition (#22430)ringabout2023-08-091-4/+1
|
* modernize jsgen; clean up some leftovers (#22423)ringabout2023-08-091-16/+13
|
* use strictdefs for compiler (#22365)ringabout2023-08-061-55/+64
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* Fix some jsgen bugs (#22330)konsumlamm2023-08-061-8/+45
| | | | | Fix `succ`, `pred` Fix `genRangeChck` for unsigned ints Fix typo in `dec`
* fixes #22362; Compiler crashes with staticBoundsCheck on (#22363)ringabout2023-08-021-0/+4
|
* implement `ensureMove` (#22339)ringabout2023-07-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * implement `ensureMove` * use an additional flag * improve some logics * progress: fixes discard ensureMove * forbids nested expressions * improve error messages * checkpoint * fixes cursor * ADD MORE TESTS * fixes cursorinference again * tiny cleanup * improve error messages * fixes docs * implement comments add more tests * fixes js
* [JS] Fix bitwise ops & shifts (#22340)konsumlamm2023-07-271-30/+53
| | | | | * [JS] Fix bitwise ops & shifts * Test `int64` & `uint64` only with `jsbigint64`
* [JS] Fix casting to ints (#22327)konsumlamm2023-07-251-19/+7
| | | | | * [JS] Fix casting to ints * Simplify `genCast` by using `asUintN`/`asIntN`
* fix VM uint conversion size bug, stricter int gen on JS (#22150)metagn2023-06-251-6/+16
| | | | | | | | | | | * fix VM uint conversion bug, stricter int gen on JS fixes #19929 * fix float -> uint64 conversion too * no need to mask to source type * simpler diff with explanation, add test for described issue
* Fix jsgen (#21880)Juan Carlos2023-05-231-0/+5
| | | | | | | | | | | * . * Fix jsgen FrameInfo * Fix jsgen FrameInfo * . * Move to PProc
* implement `=dup` hook eliminating `wasMoved` and `=copy` pairs (#21586)ringabout2023-05-061-0/+9
| | | | | | | | | | | | | | | | | | | * import `=dup` hook eliminating `wasMoved` and `=copy` pairs * add dup * add a test for dup * fixes documentation * fixes signature * resolve comments * fixes tests * fixes tests * clean up
* int64/uint64 as bigint in JS (#21613)metagn2023-04-111-26/+183
| | | | | | | | | | | * int64/uint64 as bigint in JS * fix CI * convert to compile option * fix lie * smaller diff, changelog entry
* fixes #21592; create type bound operations for calls in the method ↵ringabout2023-04-011-1/+1
| | | | | | | dispatcher for ORC (#21594) * fixes #21592; create type operations for the method dispatcher * add a test case
* `--embedsrc` for JavaScript (#21467)quantimnot2023-03-041-0/+2
| | | Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* replaces implicit passes array registed at runtime with explicit function ↵ringabout2023-03-031-10/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | calls; simplify compilation pipeline (#21444) * abolish using passes in the compiler; simplify compilation pipeline * duplicate code * Really cool to have the same signature... * haul * unify other backends * refactor process * introduce PipelinePhase * refactor compiler * fixes passes * fixes nimsuggest * add a sentinel * enable docs checkj * activate doc testing * clean up * complete cleanups
* fixes #20139; hash types based on its path relative to its package path ↵ringabout2023-03-021-2/+2
| | | | | | | | | | | | | | | (#21274) [backport:1.6] * fixes #20139; hash types based on its path relative its project * add a test case * fixes procs * better implementation and test case --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #19795; fixes #11852; fixes #19974; remove parsing pipeline, Nim now ↵ringabout2023-02-221-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | parses the whole module at one time (#21379) * fixes #19795; remove parse pipeline * isScript * fixes nimscriptapi * don't touch reorder * check script * fixes tests * it seems implicit imports of system cause troubles * access the first child of `nkStmtList` * ignore comments * minor messages * perhaps increases hloLoopDetector * the module is a stmtList, which changes the errors * fixes nimdoc * fixes tlinter * fixes nim secret tests * fixes arc_misc * fixes nim secret tests again * safe; fixes one more test * GlobalError is the root cause too * fixes parsing errors * put emit types to the cfsForwardTypes section * fixes #11852; `{.push checks:off}` now works in procs * disable navigator * fixes nimdoc * add tests for JS * fixes nimsuggest
* fixes #21317; 1.6.4 regression; etyBaseIndex should return fat pointers ↵ringabout2023-02-011-3/+4
| | | | | [backport 1.6] (#21320) fixes #21317; regression; etyBaseIndex should return fat pointers
* JS backend properly extends string with `setLen` (#21087)Jake Leahy2022-12-131-1/+3
| | | | | * Add test case * Extend string with '0' when setting length to be longer