Handle load/store with null.

This commit is contained in:
cfreksen 2017-10-29 22:03:31 +01:00
parent 7deddce45d
commit ce61eb151e
No known key found for this signature in database
GPG Key ID: EAC13EE101008978

View File

@ -77,6 +77,10 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
' Current size is {}') ' Current size is {}')
.format(size)) .format(size))
if location_v == 0:
err('You are not allowed to read from location 0')
res = 0
else:
res = heap[location_v] res = heap[location_v]
elif isinstance(next_insn, ll.Store): elif isinstance(next_insn, ll.Store):
ty = next_insn.ty ty = next_insn.ty
@ -91,8 +95,9 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
# TODO # TODO
print('heap[{}] <- {}' print('heap[{}] <- {}'
.format(location_v, value_v)) .format(location_v, value_v))
if location_v == 0:
if size == 1: err('You are not allowed to store at location 0 (Null)')
elif size == 1:
heap[location_v] = value_v heap[location_v] = value_v
else: else:
err(('This emulator cannot store objects larger than 1 cell.' err(('This emulator cannot store objects larger than 1 cell.'
@ -407,7 +412,6 @@ define i64 @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) {
terminator = first_block.terminator terminator = first_block.terminator
stack_frames = [] stack_frames = []
ssa_env = {} ssa_env = {}
# TODO: memory structure has not been decided yet
heap = [None] heap = [None]
call_res = [] call_res = []