Introducing try_get_string_by_idx interface for retrieving literal string value by it's identifier.

This commit is contained in:
Ruben Ayrapetyan
2014-07-17 21:07:25 +04:00
parent 0a87643eb6
commit 819b947445
2 changed files with 34 additions and 1 deletions
+30
View File
@@ -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 */
+4 -1
View File
@@ -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 */