Skip to content

Commit

Permalink
Substitute constant values for DSKIP when initializing symbol table
Browse files Browse the repository at this point in the history
Previously the interpreter could not handle constructions of the form

   CONSTANT(N, 100)
   DSKIP(N)

No error would be printed but the symbol table would be initialized
incorrectly.
  • Loading branch information
iafisher committed Dec 18, 2018
1 parent 24e43dd commit d46c211
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 18 additions & 12 deletions hera/symtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@ def get_symtab(program):
dc = HERA_DATA_START
for op in program:
odc = dc
if op.name == "LABEL" and len(op.args) == 1:
labels[op.args[0]] = pc
elif op.name == "DLABEL" and len(op.args) == 1:
labels[op.args[0]] = dc
elif op.name == "CONSTANT" and len(op.args) == 2:
labels[op.args[0]] = op.args[1]
if op.name == "LABEL":
if len(op.args) == 1:
labels[op.args[0]] = pc
elif op.name == "DLABEL":
if len(op.args) == 1:
labels[op.args[0]] = dc
elif op.name == "CONSTANT":
if len(op.args) == 2:
labels[op.args[0]] = op.args[1]
elif op.name == "INTEGER":
dc += 1
elif op.name == "DSKIP" and len(op.args) == 1 and isinstance(op.args[0], int):
dc += op.args[0]
elif (
op.name == "LP_STRING" and len(op.args) == 1 and isinstance(op.args[0], str)
):
dc += len(op.args[0]) + 1
elif op.name == "DSKIP":
if len(op.args) == 1:
if isinstance(op.args[0], int):
dc += op.args[0]
elif op.args[0] in labels:
dc += labels[op.args[0]]
elif op.name == "LP_STRING":
if len(op.args) == 1 and isinstance(op.args[0], str):
dc += len(op.args[0]) + 1
else:
pc += len(convert(op))

Expand Down
6 changes: 3 additions & 3 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ def test_cs240_array_dot_hera():

assert not vm.flag_sign
assert vm.flag_zero
assert not vm.flagoverflow
assert not vm.flag_overflow
assert vm.flag_carry
assert not vm.flag_carry_block

for i in range(100):
assert vm.memory[HERA_DATA_START+i] == i+1
assert vm.memory[HERA_DATA_START+100] == 5050
assert vm.memory[HERA_DATA_START + i] == i + 1
assert vm.memory[HERA_DATA_START + 100] == 5050


def test_error_message_for_missing_comma(capsys):
Expand Down

0 comments on commit d46c211

Please sign in to comment.