Better tiger_print.
This commit is contained in:
parent
2086af34d9
commit
de369fd440
|
@ -3,12 +3,14 @@ from enum import Enum
|
||||||
from llvm_emulator import ll
|
from llvm_emulator import ll
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import random
|
||||||
|
|
||||||
############
|
############
|
||||||
# Messages #
|
# Messages #
|
||||||
|
|
||||||
|
PRINT_LEVEL_SILENT = -1
|
||||||
PRINT_LEVEL_NONE = 0
|
PRINT_LEVEL_NONE = 0
|
||||||
PRINT_LEVEL_ERR = 1
|
PRINT_LEVEL_ERROR = 1
|
||||||
PRINT_LEVEL_WARN = 2
|
PRINT_LEVEL_WARN = 2
|
||||||
PRINT_LEVEL_INFO = 3
|
PRINT_LEVEL_INFO = 3
|
||||||
|
|
||||||
|
@ -20,7 +22,7 @@ def eprint(*args, **kwargs):
|
||||||
print(*args, file=sys.stderr, **kwargs)
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
def err(msg):
|
def err(msg):
|
||||||
if PRINT_LEVEL >= PRINT_LEVEL_ERR:
|
if PRINT_LEVEL >= PRINT_LEVEL_ERROR:
|
||||||
eprint('ERROR: {}'
|
eprint('ERROR: {}'
|
||||||
.format(msg))
|
.format(msg))
|
||||||
|
|
||||||
|
@ -37,6 +39,13 @@ def info(*args, **kwargs):
|
||||||
if PRINT_LEVEL >= PRINT_LEVEL_INFO:
|
if PRINT_LEVEL >= PRINT_LEVEL_INFO:
|
||||||
print(*args, **kwargs)
|
print(*args, **kwargs)
|
||||||
|
|
||||||
|
def tiger_print(msg):
|
||||||
|
if PRINT_LEVEL == PRINT_LEVEL_SILENT:
|
||||||
|
return
|
||||||
|
if not isinstance(msg, str):
|
||||||
|
msg = ''.join([chr(random.randint(0, 255)) for i in range(random.randint(1, 5))])
|
||||||
|
sys.stdout.write(msg)
|
||||||
|
|
||||||
##########
|
##########
|
||||||
# Stuff? #
|
# Stuff? #
|
||||||
|
|
||||||
|
@ -624,7 +633,7 @@ def emulate_builtin(name, arguments_v, ssa_env, heap):
|
||||||
info('Printing string, heap[{}]:'
|
info('Printing string, heap[{}]:'
|
||||||
.format(struct_begin))
|
.format(struct_begin))
|
||||||
printee = heap[struct_begin + 1]
|
printee = heap[struct_begin + 1]
|
||||||
info(printee)
|
tiger_print(printee)
|
||||||
if not isinstance(printee, str):
|
if not isinstance(printee, str):
|
||||||
warn('What was printed, was not stored as a string in the heap')
|
warn('What was printed, was not stored as a string in the heap')
|
||||||
elif name in builtins:
|
elif name in builtins:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user