git.iko.soy/rowtype-yoga/purescm
on bytevector help sign in
Convert GetIndex (#104)
commiteee842c83e1997fd9cf96e02f686167c7f66773f authorJordanMartinez <jordanalex.martinez@protonmail.com> dateThu 30 Mar 2023, 14:40 (4 years ago) parent7815f84
3 files changed+23−2
src/PureScript/Backend/Chez/Convert.purs+4−2 test-snapshots/src/snapshots-input/Snapshot.ArrayIndex.purs+6 test-snapshots/src/snapshots-output/Snapshot.ArrayIndex.ss+13
src/PureScript/Backend/Chez/Convert.purs+4−2
@@ -159,8 +159,10 @@ codegenExpr codegenEnv@{ currentModule } (NeutralExpr s) = case s of
159159
160160 Accessor _ (GetProp _) ->
161161 S.Identifier $ "accessor-get-prop"
162− Accessor _ (GetIndex _) ->
163− S.Identifier $ "accessor-get-index"
162+ Accessor e (GetIndex i) ->
163+ S.chezUncurriedApplication
164+ (S.Identifier $ scmPrefixed "vector-ref")
165+ [ codegenExpr codegenEnv e, S.Integer $ wrap $ show i ]
164166 Accessor e (GetCtorField qi _ _ _ field _) ->
165167 S.recordAccessor (codegenExpr codegenEnv e) (S.resolve currentModule qi) field
166168 Update _ _ ->
test-snapshots/src/snapshots-input/Snapshot.ArrayIndex.pursnew file+6
@@ -0,0 +1,6 @@
1+module Snapshot.ArrayIndex where
2+
3+testAccessorGetIndex :: Array Int -> Int
4+testAccessorGetIndex = case _ of
5+ [ x ] -> x
6+ _ -> 0
test-snapshots/src/snapshots-output/Snapshot.ArrayIndex.ssnew file+13
@@ -0,0 +1,13 @@
1+#!r6rs
2+#!chezscheme
3+(library
4+ (Snapshot.ArrayIndex lib)
5+ (export
6+ testAccessorGetIndex)
7+ (import
8+ (prefix (chezscheme) scm:)
9+ (prefix (_Chez_Runtime lib) rt:))
10+
11+ (scm:define testAccessorGetIndex
12+ (scm:lambda (v0)
13+ (scm:cond ((scm:fx=? (scm:vector-length v0) 1) (scm:vector-ref v0 0)) (scm:else 0)))))