Add support for print from runtime.c.

This commit is contained in:
cfreksen 2017-11-09 15:32:29 +01:00
parent 8afdf563b3
commit cea1cece13
No known key found for this signature in database
GPG Key ID: EAC13EE101008978

View File

@ -25,7 +25,10 @@ class Garbage(Enum):
return '<<Garbage>>' return '<<Garbage>>'
builtins = ['allocRecord', 'initArray'] builtins = ['allocRecord', 'initArray', 'stringEqual', 'stringNotEq', 'stringLess',
'stringLessEq', 'stringGreater', 'stringGreaterEq', 'exponent', 'print',
'flush', 'getChar', 'ord', 'chr', 'size', 'substring', 'concat', 'not',
'exit_tig']
def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap, def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
@ -580,6 +583,18 @@ def emulate_builtin(name, arguments_v, ssa_env, heap):
struct_begin + 1, array_begin, struct_begin + 1, array_begin,
array_init_s)) array_init_s))
res = struct_begin res = struct_begin
elif name == 'print':
if len(arguments_v) != 2:
err('Number of arguments to {} should be 3'
.format(name))
else:
struct_begin = arguments_v[1]
print('Printing string, heap[{}]:'
.format(struct_begin))
printee = heap[struct_begin + 1]
print(printee)
if not isinstance(printee, str):
warn('What was printed, was not stored as a string in the heap')
elif name in builtins: elif name in builtins:
TODO('Have not implemented builtin function {}, yet.' TODO('Have not implemented builtin function {}, yet.'
.format(name)) .format(name))