From 0981ace7ed9054facb948e90bde7c71703212800 Mon Sep 17 00:00:00 2001 From: Jacques Wagener Date: Mon, 11 Feb 2019 12:07:17 +0200 Subject: [PATCH] Add support for new map syntax. --- bin/vyper-run | 2 +- tests/core/test_source_map.py | 4 ++-- tests/variables/test_globals.py | 5 ++--- vdb/source_map.py | 2 +- vdb/variables.py | 6 ++---- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/bin/vyper-run b/bin/vyper-run index 3caa331..3e30f38 100755 --- a/bin/vyper-run +++ b/bin/vyper-run @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3 import argparse import sys import os diff --git a/tests/core/test_source_map.py b/tests/core/test_source_map.py index 1456fd2..56189b9 100644 --- a/tests/core/test_source_map.py +++ b/tests/core/test_source_map.py @@ -3,7 +3,7 @@ from vdb.source_map import produce_source_map def test_source_map_output(): code = """ -a_map: bytes32[bytes32] +a_map: map(bytes32, bytes32) @public def func1(a: int128) -> int128: @@ -21,7 +21,7 @@ def func2(a: int128): # globals assert sm['globals']['a_map'] == { - 'type': 'mapping(bytes32[bytes32])', + 'type': 'map(bytes32, bytes32)', 'size': 0, 'position': 0 } diff --git a/tests/variables/test_globals.py b/tests/variables/test_globals.py index 0a2816b..8bbb863 100644 --- a/tests/variables/test_globals.py +++ b/tests/variables/test_globals.py @@ -3,7 +3,7 @@ import io def test_single_key(get_contract, get_last_out): code = """ -amap: bytes32[bytes32] +amap: map(bytes32, bytes32) @public @@ -31,8 +31,7 @@ def get(key: bytes32) -> bytes32: def test_double_key(get_contract, get_last_out): code = """ -amap: (bytes32)[bytes32][bytes32] - +amap: map(bytes32, map(bytes32, bytes32)) @public def set(key1: bytes32, key2: bytes32, value: bytes32): diff --git a/vdb/source_map.py b/vdb/source_map.py index 377341d..4a261ab 100644 --- a/vdb/source_map.py +++ b/vdb/source_map.py @@ -23,7 +23,7 @@ def serialise_var_rec(var_rec): type_str = 'tuple' _size = get_size_of_type(var_rec.typ) * 32 elif isinstance(var_rec.typ, MappingType): - type_str = 'map(%s)' % var_rec.typ + type_str = str(var_rec.typ) _size = 0 else: type_str = var_rec.typ.typ diff --git a/vdb/variables.py b/vdb/variables.py index dfea379..4e0f3b8 100644 --- a/vdb/variables.py +++ b/vdb/variables.py @@ -78,7 +78,7 @@ def get_hash(var_pos, keys, _type): def valid_subscript(name, global_type): if name.count('[') != name.count(']'): return False - elif global_type.count('[') != name.count('['): + elif global_type.count('(') != name.count(']'): return False return True @@ -95,8 +95,6 @@ def parse_global(stdout, global_vars, computation, line): global_type = global_vars[var_name]['type'] slot = None - import ipdb; ipdb.set_trace() - if global_type in base_types: slot = global_vars[var_name]['position'] 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, ) 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) else: stdout.write('Can not read global of type "{}".\n'.format(global_type))