Jacek Caban : jscript: Always store numeric literals as double.
Alexandre Julliard
julliard at winehq.org
Wed Jun 20 13:49:43 CDT 2012
Module: wine
Branch: master
Commit: 4cfab07748f4187ea71941ddebd40f890b798dea
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4cfab07748f4187ea71941ddebd40f890b798dea
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Jun 20 11:18:22 2012 +0200
jscript: Always store numeric literals as double.
---
dlls/jscript/compile.c | 5 ---
dlls/jscript/engine.c | 5 +--
dlls/jscript/engine.h | 2 -
dlls/jscript/lex.c | 73 +++++++++++------------------------------------
4 files changed, 18 insertions(+), 67 deletions(-)
diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index d3deccd..f3c1df1 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -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:
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 1ed1c97..0b97fdd 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -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 */
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index fabf840..d0dec0d 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -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;
diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c
index 06d0b89..d2b87ac 100644
--- a/dlls/jscript/lex.c
+++ b/dlls/jscript/lex.c
@@ -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,18 +415,20 @@ 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';
- if(d>LONGLONG_MAX/10 || hlp<0)
- break;
+ 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--;
+ d = hlp;
+ exp--;
+ }
+ while(ctx->ptr < ctx->end && isdigitW(*ctx->ptr))
+ ctx->ptr++;
}
- 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);
- }
-
- 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);
+ if(isdigitW(*ctx->ptr)) {
+ FIXME("octal literals not implemented\n");
+ return lex_error(ctx, E_NOTIMPL);
}
}
- *literal = new_int_literal(ctx, l);
- return tNumericLiteral;
+ return parse_double_literal(ctx, l, literal);
}
static int next_token(parser_ctx_t *ctx, void *lval)
More information about the wine-cvs
mailing list