Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/lang/py/py.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ LangPy.prototype.initRunTimeState = function (reboot) {
};

function runtime_print(msg, rte) {
rte.vm.replAddTranscript(msg + '\n', 'cb-repl-output');
rte.vm.replAddTranscript(msg, 'cb-repl-output');
rte.vm.lang.refreshUI();
};

Expand Down
22 changes: 18 additions & 4 deletions pyinterp/pyinterp/pyinterp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7268,6 +7268,20 @@ def om_print_code(rte, _):
args_seq = OM_get_list_seq(args)
args_len = len(args_seq)

sep = rte_lookup_locals(rte, 'sep')
end = rte_lookup_locals(rte, 'end')

if not (om_isinstance(sep, class_str) or om_isinstance(sep, class_NoneType)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's faster to do om_is(sep, om_None) since None is a singleton.

ctx = make_out_of_ast_context(rte, om_None)
return sem_raise_with_message(ctx, class_TypeError, "sep must be None or a string")

if not (om_isinstance(end, class_str) or om_isinstance(end, class_NoneType)):
ctx = make_out_of_ast_context(rte, om_None)
return sem_raise_with_message(ctx, class_TypeError, "end must be None or a string")

sep = OM_get_boxed_value(sep)
end = OM_get_boxed_value(end)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful, at this point, sep and end could be om_None in your code.


result = []
for _ in args_seq:
result.append(None)
Expand All @@ -7280,8 +7294,7 @@ def print_value(rte, str_result):
if new_index < args_len:
return stmt_end(make_out_of_ast_context(rte, lambda rte: loop(rte, new_index)), 0)
else:
# sep=' '
runtime_print(' '.join(result), rte)
runtime_print(sep.join(result) + end, rte)
return unwind_return(rte, om_None)

next_ctx = make_out_of_ast_context(rte, print_value)
Expand All @@ -7290,7 +7303,7 @@ def print_value(rte, str_result):
if args_len > 0:
return loop(rte, 0)
else:
runtime_print('', rte)
runtime_print('' + end, rte)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime_print(end, rte) should do the trick

return unwind_return(rte, om_None)

def om_alert_code(rte, _):
Expand Down Expand Up @@ -8622,7 +8635,8 @@ def fresh_rte(options):
rte = make_new_rte(globals_env, locals_env, builtins_env, builtins_module, options)

# Vanilla Python builtins
om_builtin_print = om_make_builtin_function_with_signature('print', om_print_code, make_vararg_only_signature('args'))
om_builtin_print = om_make_builtin_function_with_signature('print', om_print_code,
make_signature((), (), 'args', ('sep', 'end'), (om_str(" "), om_str("\n")), None, ()))
om_builtin_breakpoint = om_make_builtin_function_with_signature('breakpoint', om_breakpoint_code, empty_signature)
om_builtin_input = om_make_builtin_function_with_signature('input', om_input_code, make_posonly_defaults_signature(('obj',), (om_str(''),)))
om_builtin_hex = om_make_builtin_function_with_signature('hex', om_hex_code, make_posonly_only_signature(('obj',)))
Expand Down