From 819b9474456fee015020545fc2c3a8c6c3b4f449 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Thu, 17 Jul 2014 21:07:25 +0400 Subject: [PATCH] Introducing try_get_string_by_idx interface for retrieving literal string value by it's identifier. --- src/libcoreint/interpreter.c | 30 ++++++++++++++++++++++++++++++ src/libcoreint/interpreter.h | 5 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index 5652ebd30..aa94b445b 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -44,3 +44,33 @@ run_int_from_pos (struct __int_data *int_data) OPCODE *curr = &__program[int_data->pos]; __opfuncs[curr->op_idx](*curr, int_data); } + +/** + * Copy zero-terminated string literal value to specified buffer. + * + * @return upon success - number of bytes actually copied, + * otherwise (buffer size is not enough) - negated minimum required buffer size. + */ +ssize_t +try_get_string_by_idx(T_IDX idx, /**< literal id */ + ecma_Char_t *buffer_p, /**< buffer */ + ssize_t buffer_size) /**< buffer size */ +{ + TODO( Actual string literal retrievement ); + + ssize_t req_length = 2; // TODO + + JERRY_ASSERT( idx < 'z' - 'a' + 1 ); + + if ( buffer_size < req_length ) + { + return -req_length; + } + + // TODO + + buffer_p[0] = (ecma_Char_t) ('a' + idx); + buffer_p[1] = 0; + + return req_length; +} /* try_get_string_by_idx */ diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index 7611f05ab..3368045e5 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -16,8 +16,9 @@ #ifndef INTERPRETER_H #define INTERPRETER_H -#include "opcodes.h" #include "ecma-globals.h" +#include "globals.h" +#include "opcodes.h" OPCODE __program[128]; @@ -35,5 +36,7 @@ void init_int (void); void run_int (void); void run_int_from_pos (struct __int_data *); +ssize_t try_get_string_by_idx( T_IDX idx, ecma_Char_t *buffer_p, ssize_t buffer_size); + #endif /* INTERPRETER_H */