diff --git a/src/libcoreint/opcodes-native-call.c b/src/libcoreint/opcodes-native-call.c index 49262a76d..ffe80b415 100644 --- a/src/libcoreint/opcodes-native-call.c +++ b/src/libcoreint/opcodes-native-call.c @@ -24,6 +24,7 @@ #include "actuators.h" #include "common-io.h" #include "sensors.h" +#include "jerry-libc.h" /** * 'Native call' opcode handler. @@ -110,6 +111,46 @@ opfunc_native_call (opcode_t opdata, /**< operation data */ break; } + case OPCODE_NATIVE_CALL_PRINT: + { + JERRY_ASSERT (args_number == 1); + + ECMA_TRY_CATCH (str_value, + ecma_op_to_string (arg_values[0]), + ret_value); + + ecma_string_t *str_p = ECMA_GET_POINTER (str_value.u.value.value); + + int32_t chars = ecma_string_get_length (str_p); + JERRY_ASSERT (chars >= 0); + + ssize_t zt_str_size = (ssize_t) sizeof (ecma_char_t) * (chars + 1); + ecma_char_t *zt_str_p = mem_heap_alloc_block ((size_t) zt_str_size, + MEM_HEAP_ALLOC_SHORT_TERM); + if (zt_str_p == NULL) + { + jerry_exit (ERR_MEMORY); + } + + ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size); + +#if defined (CONFIG_ECMA_CHAR_ASCII) + __printf ("%s\n", (char*) str_p); +#elif defined (CONFIG_ECMA_CHAR_UTF16) + JERRY_UNIMPLEMENTED (); +#else /* !CONFIG_ECMA_CHAR_ASCII && !CONFIG_ECMA_CHAR_UTF16 */ +# error "!CONFIG_ECMA_CHAR_ASCII && !CONFIG_ECMA_CHAR_UTF16" +#endif /* !CONFIG_ECMA_CHAR_ASCII && !CONFIG_ECMA_CHAR_UTF16 */ + + mem_heap_free_block (zt_str_p); + + ret_value = ecma_make_empty_completion_value (); + + ECMA_FINALIZE (str_value); + + break; + } + case OPCODE_NATIVE_CALL__COUNT: { JERRY_UNREACHABLE (); diff --git a/src/libcoreint/opcodes-native-call.h b/src/libcoreint/opcodes-native-call.h index 44712e0f6..5e49199f0 100644 --- a/src/libcoreint/opcodes-native-call.h +++ b/src/libcoreint/opcodes-native-call.h @@ -26,6 +26,7 @@ typedef enum OPCODE_NATIVE_CALL_LED_OFF, OPCODE_NATIVE_CALL_LED_ONCE, OPCODE_NATIVE_CALL_WAIT, + OPCODE_NATIVE_CALL_PRINT, OPCODE_NATIVE_CALL__COUNT } opcode_native_call_t;