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,7 +77,11 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
' Current size is {}')
.format(size))
res = heap[location_v]
if location_v == 0:
err('You are not allowed to read from location 0')
res = 0
else:
res = heap[location_v]
elif isinstance(next_insn, ll.Store):
ty = next_insn.ty
base_ty = ty2base_ty(ty, tdecs)
@ -91,8 +95,9 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
# TODO
print('heap[{}] <- {}'
.format(location_v, value_v))
if size == 1:
if location_v == 0:
err('You are not allowed to store at location 0 (Null)')
elif size == 1:
heap[location_v] = value_v
else:
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
stack_frames = []
ssa_env = {}
# TODO: memory structure has not been decided yet
heap = [None]
call_res = []