Add support for new map syntax.
This commit is contained in:
parent
b1eceb9789
commit
0981ace7ed
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python3.6
|
#!/usr/bin/env python3
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
|
@ -3,7 +3,7 @@ from vdb.source_map import produce_source_map
|
||||||
|
|
||||||
def test_source_map_output():
|
def test_source_map_output():
|
||||||
code = """
|
code = """
|
||||||
a_map: bytes32[bytes32]
|
a_map: map(bytes32, bytes32)
|
||||||
|
|
||||||
@public
|
@public
|
||||||
def func1(a: int128) -> int128:
|
def func1(a: int128) -> int128:
|
||||||
|
@ -21,7 +21,7 @@ def func2(a: int128):
|
||||||
|
|
||||||
# globals
|
# globals
|
||||||
assert sm['globals']['a_map'] == {
|
assert sm['globals']['a_map'] == {
|
||||||
'type': 'mapping(bytes32[bytes32])',
|
'type': 'map(bytes32, bytes32)',
|
||||||
'size': 0,
|
'size': 0,
|
||||||
'position': 0
|
'position': 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import io
|
||||||
|
|
||||||
def test_single_key(get_contract, get_last_out):
|
def test_single_key(get_contract, get_last_out):
|
||||||
code = """
|
code = """
|
||||||
amap: bytes32[bytes32]
|
amap: map(bytes32, bytes32)
|
||||||
|
|
||||||
|
|
||||||
@public
|
@public
|
||||||
|
@ -31,8 +31,7 @@ def get(key: bytes32) -> bytes32:
|
||||||
|
|
||||||
def test_double_key(get_contract, get_last_out):
|
def test_double_key(get_contract, get_last_out):
|
||||||
code = """
|
code = """
|
||||||
amap: (bytes32)[bytes32][bytes32]
|
amap: map(bytes32, map(bytes32, bytes32))
|
||||||
|
|
||||||
|
|
||||||
@public
|
@public
|
||||||
def set(key1: bytes32, key2: bytes32, value: bytes32):
|
def set(key1: bytes32, key2: bytes32, value: bytes32):
|
||||||
|
|
|
@ -23,7 +23,7 @@ def serialise_var_rec(var_rec):
|
||||||
type_str = 'tuple'
|
type_str = 'tuple'
|
||||||
_size = get_size_of_type(var_rec.typ) * 32
|
_size = get_size_of_type(var_rec.typ) * 32
|
||||||
elif isinstance(var_rec.typ, MappingType):
|
elif isinstance(var_rec.typ, MappingType):
|
||||||
type_str = 'map(%s)' % var_rec.typ
|
type_str = str(var_rec.typ)
|
||||||
_size = 0
|
_size = 0
|
||||||
else:
|
else:
|
||||||
type_str = var_rec.typ.typ
|
type_str = var_rec.typ.typ
|
||||||
|
|
|
@ -78,7 +78,7 @@ def get_hash(var_pos, keys, _type):
|
||||||
def valid_subscript(name, global_type):
|
def valid_subscript(name, global_type):
|
||||||
if name.count('[') != name.count(']'):
|
if name.count('[') != name.count(']'):
|
||||||
return False
|
return False
|
||||||
elif global_type.count('[') != name.count('['):
|
elif global_type.count('(') != name.count(']'):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -95,8 +95,6 @@ def parse_global(stdout, global_vars, computation, line):
|
||||||
global_type = global_vars[var_name]['type']
|
global_type = global_vars[var_name]['type']
|
||||||
slot = None
|
slot = None
|
||||||
|
|
||||||
import ipdb; ipdb.set_trace()
|
|
||||||
|
|
||||||
if global_type in base_types:
|
if global_type in base_types:
|
||||||
slot = global_vars[var_name]['position']
|
slot = global_vars[var_name]['position']
|
||||||
elif global_type.startswith('map') and valid_subscript(name, global_type):
|
elif global_type.startswith('map') and valid_subscript(name, global_type):
|
||||||
|
@ -110,7 +108,7 @@ def parse_global(stdout, global_vars, computation, line):
|
||||||
slot=slot,
|
slot=slot,
|
||||||
)
|
)
|
||||||
if global_type.startswith('map'):
|
if global_type.startswith('map'):
|
||||||
global_type = global_type[global_type.find('(') + 1: global_type.find('[')]
|
global_type = global_type[global_type.rfind(',') + 1: global_type.rfind(')')].strip()
|
||||||
print_var(stdout, value, global_type)
|
print_var(stdout, value, global_type)
|
||||||
else:
|
else:
|
||||||
stdout.write('Can not read global of type "{}".\n'.format(global_type))
|
stdout.write('Can not read global of type "{}".\n'.format(global_type))
|
||||||
|
|
Loading…
Reference in New Issue