ArrayRuntime adapters #84
RealColdFry
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The
runtime-adapters-kernelbranch adds a typed interface for swapping tslua's emit per category, propagating into lualib (which tslua compiles from TS source in the same pass). Kernel wires one primitive:ArrayRuntime.length. Seeexamples/array-length-adapter/for a working demo.Before extending the interface, I want to pressure-test it against two cases @pilaoda explored upstream:
Proxy arrays. Host-tracked length where
#arrreturns the wrong value; the rewrite needs to reach into lualib so__TS__ArrayPushetc. use the right length too.Metatable-tagged arrays for
Array.isArray. Tagging literals at construction makesisArrayexact and enables the class-basedArraysketched there. Needs__TS__ArrayMapetc. to emit tagged arrays for their internalresult = [].Current interface:
Open questions
TS-authored primitives. A class-based runtime could be written entirely in TS and transpile down, if the class encapsulates its raw representation. Missing: linking
.d.tsdeclarations to.tsimplementations;.luais the only resolved path today.Push fast path routing through
length. tslua's push single-arg fast path emitsarr[#arr + 1] = val. On a proxy host,#is wrong, so the fast path is broken. Should the fast path route its#throughArrayRuntime.length(so a user who overrides onlylengthgets a working push for free), or shouldpushbe its own primitive (overridden explicitly when the user wants different append semantics)? The first feels cleaner; push becomes a primitive only when the append contract itself differs, not when length happens to.If you've hit a case that doesn't fit, that's the most useful signal.
Other links
Beta Was this translation helpful? Give feedback.
All reactions