From 9e1d0d15137c6439d886406293a25eaa16b600c5 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 19 Apr 2024 00:52:30 +0800 Subject: fixes #4695; closure iterators support for JS backend (#23493) 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 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) allPathsAsgnResult??? --- lib/system/jssys.nim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/system') diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index ffd23b12d..9f9a410d5 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -72,6 +72,10 @@ proc getCurrentExceptionMsg*(): string = proc setCurrentException*(exc: ref Exception) = lastJSError = cast[PJSError](exc) +proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} = + ## Used to set up exception handling for closure iterators + setCurrentException(e) + proc auxWriteStackTrace(f: PCallFrame): string = type TempFrame = tuple[procname: cstring, line: int, filename: cstring] -- cgit 1.4.1-2-gfad0