From 40dae8c73196fb4e8e151e65f678f38882605d48 Mon Sep 17 00:00:00 2001 From: Amjad Ben Hedhili Date: Mon, 26 Sep 2022 11:26:28 +0100 Subject: [PATCH] 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 --- compiler/jsgen.nim | 10 ++++++++-- 1 file 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 =