Skip to content

Commit

Permalink
Restore MSVC6 build
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Feb 27, 2015
1 parent 3814fc6 commit ad5c993
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 105 deletions.
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,9 @@ amalgamated_v7: v7.h v7.c
m32_v7: $(TOP_HEADERS) $(TOP_SOURCES) v7.h
$(CC) $(TOP_SOURCES) -o v7 -DV7_EXE -DV7_EXPOSE_PRIVATE $(CFLAGS) -m32 -lm

js: v7
@./v7 tests/v7_basic_test.js
@rhino -version 130 tests/v7_basic_test.js

t: v7
./v7 tests/run_ecma262_tests.js

w: v7.c
wine cl v7.c /Zi -DV7_EXE -DV7_EXPOSE_PRIVATE
wine cl tests/unit_test.c $(TOP_SOURCES) $(V7_FLAGS) /Zi -DV7_EXPOSE_PRIVATE
wine unit_test.exe

clean:
@$(MAKE) -C tests clean
Expand Down
8 changes: 4 additions & 4 deletions src/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ typedef unsigned long ast_off_t;

struct ast_node_def {
const char *name; /* tag name, for debugging and serialization */
uint8_t has_varint; /* has a varint body */
uint8_t has_inlined; /* inlined data whose size is in the varint field */
uint8_t num_skips; /* number of skips */
uint8_t num_subtrees; /* number of fixed subtrees */
unsigned char has_varint; /* has a varint body */
unsigned char has_inlined; /* inlined data whose size is in the varint field */
unsigned char num_skips; /* number of skips */
unsigned char num_subtrees; /* number of fixed subtrees */
};
extern const struct ast_node_def ast_node_defs[];

Expand Down
14 changes: 2 additions & 12 deletions src/date.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
*/

#include "internal.h"
#include <sys/time.h>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <stddef.h>

#ifdef __APPLE__
int64_t strtoll(const char *, char **, int);
Expand Down Expand Up @@ -228,10 +220,8 @@ struct timeparts {

/*+++ this functions is used to get current date/time & timezone */

static void d_gettime(etime_t *time) {
struct timeval tv;
gettimeofday(&tv, NULL);
*time = (etime_t) tv.tv_sec * 1000 + (etime_t) tv.tv_usec / 1000;
static void d_gettime(etime_t *t) {
*t = time(NULL);
}

static const char *d_gettzname() {
Expand Down
4 changes: 2 additions & 2 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ V7_PRIVATE void gc_mark(struct v7 *v7, val_t v) {

static void gc_dump_arena_stats(const char *msg, struct gc_arena *a) {
if (a->verbose) {
fprintf(stderr, "%s: total allocations %lu, max %lu, alive %u\n", msg,
(unsigned long) a->allocations, a->size, a->alive);
fprintf(stderr, "%s: total allocations %lu, max %lu, alive %lu\n", msg,
a->allocations, a->size, a->alive);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "internal.h"
#include "vm.h"


/* Disable GC on 32-bit platform for now */
#if ULONG_MAX == 4294967295
#define V7_DISABLE_GC
Expand All @@ -28,8 +27,12 @@ struct gc_cell {
uintptr_t word;
};

#ifdef _WIN32
#define GC_TMP_FRAME(v) struct gc_tmp_frame v = new_tmp_frame(v7);
#else
#define GC_TMP_FRAME(v) __attribute__((cleanup(tmp_frame_cleanup), unused)) \
struct gc_tmp_frame v = new_tmp_frame(v7);
#endif

#if defined(__cplusplus)
extern "C" {
Expand Down
9 changes: 8 additions & 1 deletion src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <time.h>

#ifdef _WIN32
#define vsnprintf _vsnprintf
#define snprintf _snprintf
#define isnan(x) _isnan(x)
#define isinf(x) (!_finite(x))
#define __unused
typedef unsigned __int64 uint64_t;
typedef __int64 int64_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef unsigned long uintptr_t;
#define __func__ ""
#else
#include <sys/time.h>
#include <stdint.h>
#endif

Expand Down
6 changes: 6 additions & 0 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ static double i_int_bin_op(struct v7 *v7, enum ast_tag tag, double a,
}
}

#ifdef _WIN32
static int signbit(double x) {
return x > 0;
}
#endif

static double i_num_bin_op(struct v7 *v7, enum ast_tag tag, double a,
double b) {
switch (tag) {
Expand Down
6 changes: 6 additions & 0 deletions src/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ V7_PRIVATE val_t Math_##name(struct v7 *v7, val_t this_obj, val_t args) { \
return func(v7, args, name); \
}

#ifdef _WIN32
static double round(double n) {
return n;
}
#endif

DEFINE_WRAPPER(fabs, m_one_arg)
DEFINE_WRAPPER(acos, m_one_arg)
DEFINE_WRAPPER(asin, m_one_arg)
Expand Down
4 changes: 2 additions & 2 deletions src/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ struct gc_arena {
char *free; /* head of free list */
size_t cell_size;

uint64_t allocations; /* cumulative counter of allocations */
uint32_t alive; /* number of living cells */
unsigned long allocations; /* cumulative counter of allocations */
unsigned long alive; /* number of living cells */

int verbose;
const char *name; /* for debugging purposes */
Expand Down
14 changes: 9 additions & 5 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int v7_is_error(struct v7 *v7, val_t v) {
}

V7_PRIVATE val_t v7_pointer_to_value(void *p) {
return ((uint64_t) p & ((1L << 48) -1));
return (uint64_t) p & ~V7_TAG_MASK;
}

V7_PRIVATE void *v7_to_pointer(val_t v) {
Expand Down Expand Up @@ -223,7 +223,7 @@ v7_val_t v7_create_regexp(struct v7 *v7, const char *re, size_t re_len,
v7_val_t v7_create_function(struct v7 *v7) {
struct v7_function *f = new_function(v7);
val_t proto = v7_create_undefined(), fval = v7_function_to_value(f);
GC_TMP_FRAME(tf);
struct gc_tmp_frame tf = new_tmp_frame(v7);
if (f == NULL) {
return V7_NULL;
}
Expand All @@ -238,6 +238,7 @@ v7_val_t v7_create_function(struct v7 *v7) {
v7_set_property(v7, proto, "constructor", 11, V7_PROPERTY_DONT_ENUM, fval);
v7_set_property(v7, fval, "prototype", 9, V7_PROPERTY_DONT_ENUM |
V7_PROPERTY_DONT_DELETE, proto);
tmp_frame_cleanup(&tf);
return fval;
}

Expand Down Expand Up @@ -648,12 +649,13 @@ int v7_del_property(struct v7 *v7, val_t obj, const char *name, size_t len) {
V7_PRIVATE v7_val_t v7_create_cfunction_object(struct v7 *v7,
v7_cfunction_t f, int num_args) {
val_t obj = create_object(v7, v7->cfunction_prototype);
GC_TMP_FRAME(tf);
struct gc_tmp_frame tf = new_tmp_frame(v7);
tmp_stack_push(&tf, &obj);
v7_set_property(v7, obj, "", 0, V7_PROPERTY_HIDDEN, v7_create_cfunction(f));
v7_set_property(v7, obj, "length", 6, V7_PROPERTY_READ_ONLY |
V7_PROPERTY_DONT_ENUM | V7_PROPERTY_DONT_DELETE,
v7_create_number(num_args));
tmp_frame_cleanup(&tf);
return obj;
}

Expand Down Expand Up @@ -792,7 +794,8 @@ v7_val_t v7_create_string(struct v7 *v7, const char *p, size_t len, int own) {
embed_string(m, m->len, (char *) &p, sizeof(p));
}

return v7_pointer_to_value((void *) offset) | tag;
/* NOTE(lsm): don't use v7_pointer_to_value, 32-bit ptrs will truncate */
return (offset & ~V7_TAG_MASK) | tag;
}

/*
Expand Down Expand Up @@ -874,7 +877,8 @@ V7_PRIVATE val_t s_concat(struct v7 *v7, val_t a, val_t b) {
memcpy(s, a_ptr, a_len);
memcpy(s + a_len, b_ptr, b_len);

return v7_pointer_to_value((void *) offset) | tag;
/* NOTE(lsm): don't use v7_pointer_to_value, 32-bit ptrs will truncate */
return (offset & ~V7_TAG_MASK) | tag;
}

V7_PRIVATE val_t s_substr(struct v7 *v7, val_t s, long start, long len) {
Expand Down
4 changes: 2 additions & 2 deletions tests/ecma_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@
2065 PASS ch11/11.6/11.6.1/S11.6.1_A2.1_T2.js (tail -c +1598918 tests/ecmac.db|head -c 439)
2066 PASS ch11/11.6/11.6.1/S11.6.1_A2.1_T3.js (tail -c +1599358 tests/ecmac.db|head -c 439)
2067 FAIL ch11/11.6/11.6.1/S11.6.1_A2.2_T1.js (tail -c +1599798 tests/ecmac.db|head -c 2951): [{"message":"#5: 1 + {toString: function() {return 1}} === 2. Actual: 1{"toString":[function()]}"}]
2068 FAIL ch11/11.6/11.6.1/S11.6.1_A2.2_T2.js (tail -c +1602750 tests/ecmac.db|head -c 1064): [{"message":"#1: var date = new Date(); date + date === date.toString() + date.toString(). Actual: 2.8501e+12"}]
2068 FAIL ch11/11.6/11.6.1/S11.6.1_A2.2_T2.js (tail -c +1602750 tests/ecmac.db|head -c 1064): [{"message":"#1: var date = new Date(); date + date === date.toString() + date.toString(). Actual: 2.8501e+09"}]
2069 FAIL ch11/11.6/11.6.1/S11.6.1_A2.2_T3.js (tail -c +1603815 tests/ecmac.db|head -c 1141): [{"message":"#1: function f1() {return 0;}; f1 + 1 === f1.toString() + 1"}]
2070 PASS ch11/11.6/11.6.1/S11.6.1_A2.3_T1.js (tail -c +1604957 tests/ecmac.db|head -c 858)
2071 PASS ch11/11.6/11.6.1/S11.6.1_A2.4_T1.js (tail -c +1605816 tests/ecmac.db|head -c 464)
Expand Down Expand Up @@ -9692,7 +9692,7 @@ d-G]/.exec("a") throw SyntaxError. Actual: {"message":"[RegExp] is not defined"}
9638 PASS ch15/15.4/15.4.5/15.4.5.2/S15.4.5.2_A2_T1.js (tail -c +8768885 tests/ecmac.db|head -c 778)
9639 PASS ch15/15.4/15.4.5/15.4.5.2/S15.4.5.2_A3_T1.js (tail -c +8769664 tests/ecmac.db|head -c 810)
9640 PASS ch15/15.4/15.4.5/15.4.5.2/S15.4.5.2_A3_T2.js (tail -c +8770475 tests/ecmac.db|head -c 1508)
9641 FAIL ch15/15.4/15.4.5/15.4.5.2/S15.4.5.2_A3_T3.js (tail -c +8771984 tests/ecmac.db|head -c 795): [{"message":"#2.2: x = []; x.length = 4294967296 throw RangeError. Actual: {"message":"#2.1: x = []; x.length = 4294967296 throw RangeError. Actual: x.length === 4.29497e+09"}"}]
9641 FAIL ch15/15.4/15.4.5/15.4.5.2/S15.4.5.2_A3_T3.js (tail -c +8771984 tests/ecmac.db|head -c 795): [{"message":"#1: x = []; x.length = 4294967295; x.length === 4294967295"}]
9642 PASS ch15/15.4/15.4.5/15.4.5.2/S15.4.5.2_A3_T4.js (tail -c +8772780 tests/ecmac.db|head -c 1074)
9643 FAIL ch15/15.5/15.5.1/S15.5.1.1_A1_T1.js (tail -c +8773855 tests/ecmac.db|head -c 922): [{"message":"#2: __str = String(function(){}()); __str === "undefined". Actual: __str ==="}]
9644 PASS ch15/15.5/15.5.1/S15.5.1.1_A1_T10.js (tail -c +8774778 tests/ecmac.db|head -c 1477)
Expand Down

0 comments on commit ad5c993

Please sign in to comment.