Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of for-in statement #241

Merged
merged 4 commits into from
Jun 26, 2015
Merged
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
5 changes: 5 additions & 0 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,11 @@ typedef uint32_t ecma_magic_string_ex_id_t;
*/
typedef uint8_t ecma_string_hash_t;

/**
* Length of string hash, in bits
*/
#define ECMA_STRING_HASH_BITS (sizeof (ecma_string_hash_t) * JERRY_BITSINBYTE)

/**
* Number of string's last characters to use for hash calculation
*/
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/ecma/base/ecma-lcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ JERRY_STATIC_ASSERT (sizeof (ecma_lcache_hash_entry_t) == sizeof (uint64_t));
/**
* LCache hash value length, in bits
*/
#define ECMA_LCACHE_HASH_BITS (sizeof (ecma_string_hash_t) * JERRY_BITSINBYTE)
#define ECMA_LCACHE_HASH_BITS (ECMA_STRING_HASH_BITS)

/**
* Number of rows in LCache's hash table
Expand Down
110 changes: 101 additions & 9 deletions jerry-core/parser/js/opcodes-dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "syntax-errors.h"
#include "opcodes-native-call.h"

#define MIN_TEMP_NAME 128
static idx_t temp_name, max_temp_name;

#define OPCODE(name) (__op__idx_##name)
Expand Down Expand Up @@ -115,22 +114,42 @@ enum
};
STATIC_STACK (reg_var_decls, opcode_counter_t)

/**
* Reset counter of register variables allocator
* to identifier of first general register
*/
static void
reset_temp_name (void)
{
temp_name = MIN_TEMP_NAME;
}
temp_name = OPCODE_REG_GENERAL_FIRST;
} /* reset_temp_name */

/**
* Allocate next register variable
*
* @return identifier of the allocated variable
*/
static idx_t
next_temp_name (void)
{
temp_name++;
if (max_temp_name < temp_name)
idx_t next_reg = temp_name++;

if (next_reg > OPCODE_REG_GENERAL_LAST)
{
max_temp_name = temp_name;
/*
* FIXME:
* Implement mechanism, allowing reusage of register variables
*/
PARSE_ERROR ("Not enough register variables", 0);
}
return temp_name;
}

if (max_temp_name < next_reg)
{
max_temp_name = next_reg;
}

return next_reg;
} /* next_temp_name */

static op_meta
create_op_meta (opcode_t op, lit_cpointer_t lit_id1, lit_cpointer_t lit_id2, lit_cpointer_t lit_id3)
Expand Down Expand Up @@ -689,6 +708,23 @@ eval_ret_operand (void)
return ret;
} /* eval_ret_operand */

/**
* Creates operand for taking iterator value (next property name)
* from for-in opcode handler.
*
* @return constructed operand
*/
operand
jsp_create_operand_for_in_special_reg (void)
{
operand ret;

ret.type = OPERAND_TMP;
ret.data.uid = OPCODE_REG_SPECIAL_FOR_IN_PROPERTY_NAME;

return ret;
} /* jsp_create_operand_for_in_special_reg */

bool
operand_is_empty (operand op)
{
Expand Down Expand Up @@ -2343,6 +2379,62 @@ dump_with_end (void)
serializer_dump_op_meta (create_op_meta_000 (opcode));
} /* dump_with_end */

/**
* Dump template of 'for_in' instruction.
*
* Note:
* the instruction's flags field is written later (see also: rewrite_for_in).
*
* @return position of dumped instruction
*/
opcode_counter_t
dump_for_in_for_rewrite (operand op) /**< operand - result of evaluating Expression
* in for-in statement */
{
opcode_counter_t oc = serializer_get_current_opcode_counter ();

if (op.type == OPERAND_LITERAL)
{
const opcode_t opcode = getop_for_in (LITERAL_TO_REWRITE, INVALID_VALUE, INVALID_VALUE);
serializer_dump_op_meta (create_op_meta_100 (opcode, op.data.lit_id));
}
else
{
JERRY_ASSERT (op.type == OPERAND_TMP);

const opcode_t opcode = getop_for_in (op.data.uid, INVALID_VALUE, INVALID_VALUE);
serializer_dump_op_meta (create_op_meta_000 (opcode));
}

return oc;
} /* dump_for_in_for_rewrite */

/**
* Write position of 'for_in' block's end to specified 'for_in' instruction template,
* dumped earlier (see also: dump_for_in_for_rewrite).
*/
void
rewrite_for_in (opcode_counter_t oc) /**< opcode counter of the instruction template */
{
op_meta for_in_op_meta = serializer_get_op_meta (oc);

idx_t id1, id2;
split_opcode_counter (get_diff_from (oc), &id1, &id2);
for_in_op_meta.op.data.for_in.oc_idx_1 = id1;
for_in_op_meta.op.data.for_in.oc_idx_2 = id2;
serializer_rewrite_op_meta (oc, for_in_op_meta);
} /* rewrite_for_in */

/**
* Dump 'meta' instruction of 'end for_in' type
*/
void
dump_for_in_end (void)
{
const opcode_t opcode = getop_meta (OPCODE_META_TYPE_END_FOR_IN, INVALID_VALUE, INVALID_VALUE);
serializer_dump_op_meta (create_op_meta_000 (opcode));
} /* dump_for_in_end */

void
dump_try_for_rewrite (void)
{
Expand Down Expand Up @@ -2500,7 +2592,7 @@ void
dump_reg_var_decl_for_rewrite (void)
{
STACK_PUSH (reg_var_decls, serializer_get_current_opcode_counter ());
serializer_dump_op_meta (create_op_meta_000 (getop_reg_var_decl (MIN_TEMP_NAME, INVALID_VALUE)));
serializer_dump_op_meta (create_op_meta_000 (getop_reg_var_decl (OPCODE_REG_FIRST, INVALID_VALUE)));
}

void
Expand Down
5 changes: 5 additions & 0 deletions jerry-core/parser/js/opcodes-dumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef enum __attr_packed___
operand empty_operand (void);
operand literal_operand (lit_cpointer_t);
operand eval_ret_operand (void);
operand jsp_create_operand_for_in_special_reg (void);
bool operand_is_empty (operand);

void dumper_init (void);
Expand Down Expand Up @@ -211,6 +212,10 @@ opcode_counter_t dump_with_for_rewrite (operand);
void rewrite_with (opcode_counter_t);
void dump_with_end (void);

opcode_counter_t dump_for_in_for_rewrite (operand);
void rewrite_for_in (opcode_counter_t);
void dump_for_in_end (void);

void dump_try_for_rewrite (void);
void rewrite_try (void);
void dump_catch_for_rewrite (operand);
Expand Down
Loading