mirror of
git://source.winehq.org/git/wine.git
synced 2024-11-05 18:01:34 +00:00
jscript: Always store numeric literals as double.
This commit is contained in:
parent
0e55fb682f
commit
4cfab07748
4 changed files with 20 additions and 69 deletions
|
@ -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);
|
return push_instr_int(ctx, OP_bool, literal->u.bval);
|
||||||
case LT_DOUBLE:
|
case LT_DOUBLE:
|
||||||
return push_instr_double(ctx, OP_double, literal->u.dval);
|
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:
|
case LT_NULL:
|
||||||
return push_instr(ctx, OP_null) ? S_OK : E_OUTOFMEMORY;
|
return push_instr(ctx, OP_null) ? S_OK : E_OUTOFMEMORY;
|
||||||
case LT_STRING:
|
case LT_STRING:
|
||||||
|
@ -748,9 +746,6 @@ static HRESULT literal_as_bstr(compiler_ctx_t *ctx, literal_t *literal, BSTR *st
|
||||||
case LT_STRING:
|
case LT_STRING:
|
||||||
*str = compiler_alloc_bstr(ctx, literal->u.wstr);
|
*str = compiler_alloc_bstr(ctx, literal->u.wstr);
|
||||||
break;
|
break;
|
||||||
case LT_INT:
|
|
||||||
*str = int_to_bstr(literal->u.lval);
|
|
||||||
break;
|
|
||||||
case LT_DOUBLE:
|
case LT_DOUBLE:
|
||||||
return double_to_bstr(literal->u.dval, str);
|
return double_to_bstr(literal->u.dval, str);
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1185,13 +1185,10 @@ static HRESULT interp_int(exec_ctx_t *ctx)
|
||||||
static HRESULT interp_double(exec_ctx_t *ctx)
|
static HRESULT interp_double(exec_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
const double arg = get_op_double(ctx);
|
const double arg = get_op_double(ctx);
|
||||||
VARIANT v;
|
|
||||||
|
|
||||||
TRACE("%lf\n", arg);
|
TRACE("%lf\n", arg);
|
||||||
|
|
||||||
V_VT(&v) = VT_R8;
|
return stack_push_number(ctx, arg);
|
||||||
V_R8(&v) = arg;
|
|
||||||
return stack_push(ctx, &v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ECMA-262 3rd Edition 7.8.4 */
|
/* ECMA-262 3rd Edition 7.8.4 */
|
||||||
|
|
|
@ -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;
|
HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LT_INT,
|
|
||||||
LT_DOUBLE,
|
LT_DOUBLE,
|
||||||
LT_STRING,
|
LT_STRING,
|
||||||
LT_BOOL,
|
LT_BOOL,
|
||||||
|
@ -259,7 +258,6 @@ typedef enum {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
literal_type_t type;
|
literal_type_t type;
|
||||||
union {
|
union {
|
||||||
LONG lval;
|
|
||||||
double dval;
|
double dval;
|
||||||
const WCHAR *wstr;
|
const WCHAR *wstr;
|
||||||
VARIANT_BOOL bval;
|
VARIANT_BOOL bval;
|
||||||
|
|
|
@ -376,16 +376,6 @@ static int parse_string_literal(parser_ctx_t *ctx, const WCHAR **ret, WCHAR endc
|
||||||
return tStringLiteral;
|
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)
|
static literal_t *new_double_literal(parser_ctx_t *ctx, DOUBLE d)
|
||||||
{
|
{
|
||||||
literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
|
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;
|
LONGLONG d, hlp;
|
||||||
int exp = 0;
|
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;
|
d = int_part;
|
||||||
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr)) {
|
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr)) {
|
||||||
hlp = d*10 + *(ctx->ptr++) - '0';
|
hlp = d*10 + *(ctx->ptr++) - '0';
|
||||||
|
@ -431,19 +415,21 @@ static int parse_double_literal(parser_ctx_t *ctx, LONG int_part, literal_t **li
|
||||||
ctx->ptr++;
|
ctx->ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(*ctx->ptr == '.') ctx->ptr++;
|
if(*ctx->ptr == '.') {
|
||||||
|
|
||||||
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr)) {
|
|
||||||
hlp = d*10 + *(ctx->ptr++) - '0';
|
|
||||||
if(d>LONGLONG_MAX/10 || hlp<0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
d = hlp;
|
|
||||||
exp--;
|
|
||||||
}
|
|
||||||
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr))
|
|
||||||
ctx->ptr++;
|
ctx->ptr++;
|
||||||
|
|
||||||
|
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr)) {
|
||||||
|
hlp = d*10 + *(ctx->ptr++) - '0';
|
||||||
|
if(d>LONGLONG_MAX/10 || hlp<0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
d = hlp;
|
||||||
|
exp--;
|
||||||
|
}
|
||||||
|
while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr))
|
||||||
|
ctx->ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
if(ctx->ptr < ctx->end && (*ctx->ptr == 'e' || *ctx->ptr == 'E')) {
|
if(ctx->ptr < ctx->end && (*ctx->ptr == 'e' || *ctx->ptr == 'E')) {
|
||||||
int sign = 1, e = 0;
|
int sign = 1, e = 0;
|
||||||
|
|
||||||
|
@ -485,11 +471,6 @@ static int parse_numeric_literal(parser_ctx_t *ctx, literal_t **literal)
|
||||||
LONG l, d;
|
LONG l, d;
|
||||||
|
|
||||||
l = *ctx->ptr++ - '0';
|
l = *ctx->ptr++ - '0';
|
||||||
if(ctx->ptr == ctx->end) {
|
|
||||||
*literal = new_int_literal(ctx, l);
|
|
||||||
return tNumericLiteral;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!l) {
|
if(!l) {
|
||||||
if(*ctx->ptr == 'x' || *ctx->ptr == 'X') {
|
if(*ctx->ptr == 'x' || *ctx->ptr == 'X') {
|
||||||
if(++ctx->ptr == ctx->end) {
|
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);
|
return lex_error(ctx, E_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
*literal = new_int_literal(ctx, l);
|
*literal = new_double_literal(ctx, l);
|
||||||
return tNumericLiteral;
|
return tNumericLiteral;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isdigitW(*ctx->ptr) || is_identifier_char(*ctx->ptr)) {
|
if(is_identifier_char(*ctx->ptr)) {
|
||||||
WARN("wrong char after zero\n");
|
WARN("wrong char after zero\n");
|
||||||
return lex_error(ctx, E_FAIL);
|
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 parse_double_literal(ctx, l, literal);
|
||||||
return tNumericLiteral;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int next_token(parser_ctx_t *ctx, void *lval)
|
static int next_token(parser_ctx_t *ctx, void *lval)
|
||||||
|
|
Loading…
Reference in a new issue