Skip to content

Commit

Permalink
Fix output issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkskeller committed May 24, 2022
1 parent de12e08 commit 1460c9b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Compiler/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5189,10 +5189,10 @@ def delete(self):
self.value_type.free(self.address)
self.address = None

def get_address(self, index):
def get_address(self, index, size=None):
if isinstance(index, (_secret, _single)):
raise CompilerError('need cleartext index')
key = str(index)
key = str(index), size or 1
if self.length is not None:
from .GC.types import cbits
if isinstance(index, int):
Expand All @@ -5211,6 +5211,8 @@ def get_address(self, index):
# length can be None for single-element arrays
length = 0
base = self.address + index * self.value_type.mem_size()
if size is not None and isinstance(base, _register):
base = regint._expand_address(base, size)
self.address_cache[program.curr_block, key] = \
util.untuplify([base + i * length \
for i in range(n)])
Expand Down Expand Up @@ -5332,7 +5334,8 @@ def assign(self, other, base=0):
except:
pass
try:
self.value_type.conv(other).store_in_mem(self.get_address(base))
other = self.value_type.conv(other)
other.store_in_mem(self.get_address(base, other.size))
if len(self) != None and util.is_constant(base):
assert len(self) >= other.size + base
except (AttributeError, CompilerError):
Expand Down Expand Up @@ -5370,7 +5373,7 @@ def get_vector(self, base=0, size=None):
:param base: starting point (regint/cint/int)
:param size: length (compile-time int) """
size = size or self.length - base
return self.value_type.load_mem(self.get_address(base), size=size)
return self.value_type.load_mem(self.get_address(base, size), size=size)

get_part_vector = get_vector

Expand Down Expand Up @@ -5581,6 +5584,9 @@ def Array(self, size):
# compatibility with registers
return Array(size, self.value_type)

def output_if(self, cond):
library.print_str_if(cond, '%s', self.get_vector())

def __str__(self):
return '%s array of length %s at %s' % (self.value_type, len(self),
self.address)
Expand Down

0 comments on commit 1460c9b

Please sign in to comment.