Map constructs a map constant. Parts can only be accessed in transforms.
(kvMap map[*Constant]*Constant)
| 382 | |
| 383 | // Map constructs a map constant. Parts can only be accessed in transforms. |
| 384 | func Map(kvMap map[*Constant]*Constant) *Constant { |
| 385 | m := &MapNil |
| 386 | if len(kvMap) == 0 { |
| 387 | return m |
| 388 | } |
| 389 | keys := make([]*Constant, len(kvMap)) |
| 390 | vals := make([]*Constant, len(kvMap)) |
| 391 | i := 0 |
| 392 | for k, v := range kvMap { |
| 393 | keys[i] = k |
| 394 | vals[i] = v |
| 395 | i++ |
| 396 | } |
| 397 | index := make([]int, len(kvMap)) |
| 398 | SortIndexInto(keys, index) |
| 399 | for _, i := range index { |
| 400 | next := MapCons(keys[i], vals[i], m) |
| 401 | m = &next |
| 402 | } |
| 403 | return m |
| 404 | } |
| 405 | |
| 406 | // Struct constructs a struct constant. Parts can only be accessed in transforms. |
| 407 | // labels must be sorted . |