git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Change map and array indexing rendering
commit9819f6cd924e3df3efb17c40c099739102178e88 authorAndy Arvanitis <andyarvanitis@gmail.com> dateTue 9 Jul 2019, 21:25 (7 years ago) parentbdaf3eb
3 files changed+29−23
runtime/purescript.go+2−10 src/CodeGen/IL/Common.hs+2−2 src/CodeGen/IL/Printer.hs+25−11
runtime/purescript.go+2−10
@@ -8,6 +8,8 @@ type Any interface{}
88
99type Fn = func(Any) Any
1010type EffFn = func() Any
11+type Map = map[string]Any
12+type Array = []Any
1113
1214type Once = sync.Once
1315
@@ -29,11 +31,6 @@ func Run(f Any, args ...Any) Any {
2931 return fn()
3032}
3133
32−func Get(dict Any, key string) Any {
33− d, _ := dict.(map[string]Any)
34− return d[key]
35−}
36−
3734func SafeGet(dict map[string]Any, key string) Any {
3835 value, ok := dict[key]
3936 if !ok {
@@ -42,11 +39,6 @@ func SafeGet(dict map[string]Any, key string) Any {
4239 return value
4340}
4441
45−func At(arr Any, index int) Any {
46− a, _ := arr.([]Any)
47− return a[index]
48−}
49−
5042func Contains(dict Any, key string) bool {
5143 d, _ := dict.(map[string]Any)
5244 _, found := d[key]
src/CodeGen/IL/Common.hs+2−2
@@ -154,10 +154,10 @@ anyType :: Text
154154anyType = "Any"
155155
156156dictType :: Text
157−dictType = "map[string]Any"
157+dictType = "Map"
158158
159159arrayType :: Text
160−arrayType = "[]Any"
160+arrayType = "Array"
161161
162162int :: Text
163163int = "int"
src/CodeGen/IL/Printer.hs+25−11
@@ -175,19 +175,33 @@ literals = mkPattern' match'
175175 , prettyPrintIL' (Var Nothing $ withPrefix name)
176176 , return $ emit "()"
177177 ]
178− match (Indexer _ index@NumericLiteral{} val) = mconcat <$> sequence
179− [ return $ emit "At("
180− , prettyPrintIL' val
181− , return $ emit ", "
182− , prettyPrintIL' index
183− , return $ emit ")"
178+ match (Indexer _ prop@StringLiteral{} val@ObjectLiteral{}) = mconcat <$> sequence
179+ [ prettyPrintIL' val
180+ , return $ emit "["
181+ , prettyPrintIL' prop
182+ , return $ emit "]"
184183 ]
185− match (Indexer _ prop val) = mconcat <$> sequence
186− [ return $ emit "Get("
187− , prettyPrintIL' val
188− , return $ emit ", "
184+ match (Indexer _ prop@StringLiteral{} val) = mconcat <$> sequence
185+ [ prettyPrintIL' val
186+ , return $ emit ".("
187+ , return $ emit dictType
188+ , return $ emit ")["
189189 , prettyPrintIL' prop
190− , return $ emit ")"
190+ , return $ emit "]"
191+ ]
192+ match (Indexer _ index val@ArrayLiteral{}) = mconcat <$> sequence
193+ [ prettyPrintIL' val
194+ , return $ emit "["
195+ , prettyPrintIL' index
196+ , return $ emit "]"
197+ ]
198+ match (Indexer _ index val) = mconcat <$> sequence
199+ [ prettyPrintIL' val
200+ , return $ emit ".("
201+ , return $ emit arrayType
202+ , return $ emit ")["
203+ , prettyPrintIL' index
204+ , return $ emit "]"
191205 ]
192206 match (InstanceOf _ val ty) = mconcat <$> sequence
193207 [ return $ emit "Contains("