jscript: Always store numeric literals as double.

This commit is contained in:
Jacek Caban 2012-06-20 11:18:22 +02:00 committed by Alexandre Julliard
parent 0e55fb682f
commit 4cfab07748
4 changed files with 20 additions and 69 deletions

View File

@ -712,8 +712,6 @@ static HRESULT compile_literal(compiler_ctx_t *ctx, literal_t *literal)
return push_instr_int(ctx, OP_bool, literal->u.bval);
case LT_DOUBLE:
return push_instr_double(ctx, OP_double, literal->u.dval);
case LT_INT:
return push_instr_int(ctx, OP_int, literal->u.lval);
case LT_NULL:
return push_instr(ctx, OP_null) ? S_OK : E_OUTOFMEMORY;
case LT_STRING:
@ -748,9 +746,6 @@ static HRESULT literal_as_bstr(compiler_ctx_t *ctx, literal_t *literal, BSTR *st
case LT_STRING:
*str = compiler_alloc_bstr(ctx, literal->u.wstr);
break;
case LT_INT:
*str = int_to_bstr(literal->u.lval);
break;
case LT_DOUBLE:
return double_to_bstr(literal->u.dval, str);
default:

View File

@ -1185,13 +1185,10 @@ static HRESULT interp_int(exec_ctx_t *ctx)
static HRESULT interp_double(exec_ctx_t *ctx)
{
const double arg = get_op_double(ctx);
VARIANT v;
TRACE("%lf\n", arg);
V_VT(&v) = VT_R8;
V_R8(&v) = arg;
return stack_push(ctx, &v);
return stack_push_number(ctx, arg);
}
/* ECMA-262 3rd Edition 7.8.4 */

View File

@ -248,7 +248,6 @@ HRESULT exec_source(exec_ctx_t*,bytecode_t*,function_code_t*,BOOL,jsexcept_t*,VA
HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN;
typedef enum {
LT_INT,
LT_DOUBLE,
LT_STRING,
LT_BOOL,
@ -259,7 +258,6 @@ typedef enum {
typedef struct {
literal_type_t type;
union {
LONG lval;
double dval;
const WCHAR *wstr;
VARIANT_BOOL bval;

View File

@ -376,16 +376,6 @@ static int parse_string_literal(parser_ctx_t *ctx, const WCHAR **ret, WCHAR endc
return tStringLiteral;
}
static literal_t *new_int_literal(parser_ctx_t *ctx, LONG l)
{
literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
ret->type = LT_INT;
ret->u.lval = l;
return ret;
}
static literal_t *new_double_literal(parser_ctx_t *ctx, DOUBLE d)
{
literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
@ -410,12 +400,6 @@ static int parse_double_literal(parser_ctx_t *ctx, LONG int_part, literal_t **li
LONGLONG d, hlp;
int exp = 0;
if(ctx->ptr == ctx->end || (!isdigitW(*ctx->ptr) &&
*ctx->ptr!='.' && *ctx->ptr!='e' && *ctx->ptr!='E')) {
ERR("Illegal character\n");
return 0;
}
d = int_part;
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr)) {
hlp = d*10 + *(ctx->ptr++) - '0';
@ -431,7 +415,8 @@ static int parse_double_literal(parser_ctx_t *ctx, LONG int_part, literal_t **li
ctx->ptr++;
}
if(*ctx->ptr == '.') ctx->ptr++;
if(*ctx->ptr == '.') {
ctx->ptr++;
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr)) {
hlp = d*10 + *(ctx->ptr++) - '0';
@ -443,6 +428,7 @@ static int parse_double_literal(parser_ctx_t *ctx, LONG int_part, literal_t **li
}
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr))
ctx->ptr++;
}
if(ctx->ptr < ctx->end && (*ctx->ptr == 'e' || *ctx->ptr == 'E')) {
int sign = 1, e = 0;
@ -485,11 +471,6 @@ static int parse_numeric_literal(parser_ctx_t *ctx, literal_t **literal)
LONG l, d;
l = *ctx->ptr++ - '0';
if(ctx->ptr == ctx->end) {
*literal = new_int_literal(ctx, l);
return tNumericLiteral;
}
if(!l) {
if(*ctx->ptr == 'x' || *ctx->ptr == 'X') {
if(++ctx->ptr == ctx->end) {
@ -507,42 +488,22 @@ static int parse_numeric_literal(parser_ctx_t *ctx, literal_t **literal)
return lex_error(ctx, E_FAIL);
}
*literal = new_int_literal(ctx, l);
*literal = new_double_literal(ctx, l);
return tNumericLiteral;
}
if(isdigitW(*ctx->ptr) || is_identifier_char(*ctx->ptr)) {
if(is_identifier_char(*ctx->ptr)) {
WARN("wrong char after zero\n");
return lex_error(ctx, E_FAIL);
}
*literal = new_int_literal(ctx, 0);
if(isdigitW(*ctx->ptr)) {
FIXME("octal literals not implemented\n");
return lex_error(ctx, E_NOTIMPL);
}
}
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr))
{
d = l*10 + *(ctx->ptr)-'0';
/* Check for integer overflow */
if (l > INT_MAX/10 || d < 0)
return parse_double_literal(ctx, l, literal);
l = d;
ctx->ptr++;
}
if(ctx->ptr < ctx->end) {
if(*ctx->ptr == '.' || *ctx->ptr == 'e' || *ctx->ptr == 'E')
return parse_double_literal(ctx, l, literal);
if(is_identifier_char(*ctx->ptr)) {
WARN("unexpected identifier char\n");
return lex_error(ctx, E_FAIL);
}
}
*literal = new_int_literal(ctx, l);
return tNumericLiteral;
}
static int next_token(parser_ctx_t *ctx, void *lval)