diff --git a/include/lang/py/py.js b/include/lang/py/py.js index 0edbf64e..fd33f22a 100644 --- a/include/lang/py/py.js +++ b/include/lang/py/py.js @@ -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(); }; diff --git a/pyinterp/pyinterp/pyinterp/__init__.py b/pyinterp/pyinterp/pyinterp/__init__.py index 7ec89507..87b566f4 100644 --- a/pyinterp/pyinterp/pyinterp/__init__.py +++ b/pyinterp/pyinterp/pyinterp/__init__.py @@ -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)): + 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) + result = [] for _ in args_seq: result.append(None) @@ -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) @@ -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) return unwind_return(rte, om_None) def om_alert_code(rte, _): @@ -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',)))