diff options
author | Amjad Ben Hedhili <amjadhedhili@outlook.com> | 2022-09-26 11:26:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 12:26:28 +0200 |
commit | 40dae8c73196fb4e8e151e65f678f38882605d48 (patch) | |
tree | 937baf20a3bbc6e692166546c5a18857235560cf | |
parent | e13cd40e21dbfa7d9981e2eeb2aa09625d3deda5 (diff) | |
download | Nim-40dae8c73196fb4e8e151e65f678f38882605d48.tar.gz |
Represent more types as JS `TypedArray`s (#20411)
* Represent `array[N, char]` as JS `UInt8Array(N)` * Add support distinct and range types * Add support for bools and enums
-rw-r--r-- | compiler/jsgen.nim | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 116d31de4..f3477cd48 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1742,16 +1742,22 @@ proc createObjInitList(p: PProc, typ: PType, excludedFieldIDs: IntSet, output: v t = t[0] proc arrayTypeForElemType(typ: PType): string = - # XXX This should also support tyEnum and tyBool + let typ = typ.skipTypes(abstractRange) case typ.kind of tyInt, tyInt32: "Int32Array" of tyInt16: "Int16Array" of tyInt8: "Int8Array" of tyUInt, tyUInt32: "Uint32Array" of tyUInt16: "Uint16Array" - of tyUInt8: "Uint8Array" + of tyUInt8, tyChar, tyBool: "Uint8Array" of tyFloat32: "Float32Array" of tyFloat64, tyFloat: "Float64Array" + of tyEnum: + case typ.size + of 1: "Uint8Array" + of 2: "Uint16Array" + of 4: "Uint32Array" + else: "" else: "" proc createVar(p: PProc, typ: PType, indirect: bool): Rope = |