diff --git a/stepper.py b/stepper.py index c1b2feb..5dd008c 100644 --- a/stepper.py +++ b/stepper.py @@ -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 = []