1 | """Methods on YSH Dict"""
|
2 |
|
3 | from __future__ import print_function
|
4 |
|
5 | from _devbuild.gen.value_asdl import (value, value_t)
|
6 |
|
7 | from core import vm
|
8 | from frontend import typed_args
|
9 | from mycpp.mylib import log
|
10 |
|
11 | from typing import List
|
12 |
|
13 | _ = log
|
14 |
|
15 |
|
16 | class Keys(vm._Callable):
|
17 |
|
18 | def __init__(self):
|
19 | # type: () -> None
|
20 | pass
|
21 |
|
22 | def Call(self, rd):
|
23 | # type: (typed_args.Reader) -> value_t
|
24 |
|
25 | dictionary = rd.PosDict()
|
26 | rd.Done()
|
27 |
|
28 | keys = [value.Str(k) for k in dictionary.keys()] # type: List[value_t]
|
29 | return value.List(keys)
|
30 |
|
31 |
|
32 | class Values(vm._Callable):
|
33 |
|
34 | def __init__(self):
|
35 | # type: () -> None
|
36 | pass
|
37 |
|
38 | def Call(self, rd):
|
39 | # type: (typed_args.Reader) -> value_t
|
40 |
|
41 | dictionary = rd.PosDict()
|
42 | rd.Done()
|
43 |
|
44 | values = dictionary.values() # type: List[value_t]
|
45 | return value.List(values)
|