patch quickjs to compile on the wii
This commit is contained in:
parent
136f5a2c66
commit
7b20dcd58f
4 changed files with 56 additions and 28 deletions
|
@ -27,7 +27,7 @@ macro(xcheck_add_c_compiler_flag FLAG)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
xcheck_add_c_compiler_flag(-Wall)
|
xcheck_add_c_compiler_flag(-Wall)
|
||||||
if(NOT MSVC AND NOT IOS)
|
if(NOT MSVC AND NOT IOS AND NOT NINTENDO_WII)
|
||||||
xcheck_add_c_compiler_flag(-Werror)
|
xcheck_add_c_compiler_flag(-Werror)
|
||||||
xcheck_add_c_compiler_flag(-Wextra)
|
xcheck_add_c_compiler_flag(-Wextra)
|
||||||
endif()
|
endif()
|
||||||
|
@ -155,7 +155,12 @@ list(APPEND qjs_defines _GNU_SOURCE)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
list(APPEND qjs_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0602)
|
list(APPEND qjs_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0602)
|
||||||
endif()
|
endif()
|
||||||
list(APPEND qjs_libs qjs ${CMAKE_DL_LIBS})
|
if (NINTENDO_WII)
|
||||||
|
set (BUILD_QJS_LIBC ON)
|
||||||
|
list(APPEND qjs_libs qjs ogc)
|
||||||
|
elseif()
|
||||||
|
list(APPEND qjs_libs qjs ${CMAKE_DL_LIBS})
|
||||||
|
endif()
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI")
|
if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI")
|
||||||
list(APPEND qjs_libs ${CMAKE_THREAD_LIBS_INIT})
|
list(APPEND qjs_libs ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
@ -234,7 +239,7 @@ endif()
|
||||||
#
|
#
|
||||||
|
|
||||||
# run-test262 uses pthreads.
|
# run-test262 uses pthreads.
|
||||||
if(NOT WIN32 AND NOT EMSCRIPTEN)
|
if(NOT WIN32 AND NOT EMSCRIPTEN AND NOT NINTENDO_WII)
|
||||||
add_executable(run-test262
|
add_executable(run-test262
|
||||||
quickjs-libc.c
|
quickjs-libc.c
|
||||||
run-test262.c
|
run-test262.c
|
||||||
|
@ -330,7 +335,7 @@ add_executable(test_conv
|
||||||
# Install target
|
# Install target
|
||||||
#
|
#
|
||||||
|
|
||||||
if(NOT IOS)
|
if(NOT IOS OR NOT NINTENDO_WII)
|
||||||
file(STRINGS quickjs.h quickjs_h REGEX QJS_VERSION)
|
file(STRINGS quickjs.h quickjs_h REGEX QJS_VERSION)
|
||||||
string(REGEX MATCHALL "([0-9])" QJS_VERSION "${quickjs_h}")
|
string(REGEX MATCHALL "([0-9])" QJS_VERSION "${quickjs_h}")
|
||||||
list(GET QJS_VERSION 0 QJS_VERSION_MAJOR)
|
list(GET QJS_VERSION 0 QJS_VERSION_MAJOR)
|
||||||
|
|
20
cutils.c
20
cutils.c
|
@ -28,6 +28,22 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#if defined(__wii__)
|
||||||
|
|
||||||
|
#if defined(HW_RVL)
|
||||||
|
#define TB_BUS_CLOCK 243000000u
|
||||||
|
#define TB_CORE_CLOCK 729000000u
|
||||||
|
#elif defined(HW_DOL)
|
||||||
|
#define TB_BUS_CLOCK 162000000u
|
||||||
|
#define TB_CORE_CLOCK 486000000u
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TB_TIMER_CLOCK (TB_BUS_CLOCK/4000) //4th of the bus frequency
|
||||||
|
#define ticks_to_nanosecs(ticks) ((((unsigned long)(ticks)*8000)/(unsigned long)(TB_TIMER_CLOCK/125)))
|
||||||
|
|
||||||
|
extern unsigned long gettime(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
#if !defined(_MSC_VER)
|
#if !defined(_MSC_VER)
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -1169,6 +1185,10 @@ uint64_t js__hrtime_ns(void) {
|
||||||
result = (double) counter.QuadPart / scaled_freq;
|
result = (double) counter.QuadPart / scaled_freq;
|
||||||
return (uint64_t) result;
|
return (uint64_t) result;
|
||||||
}
|
}
|
||||||
|
#elif defined(__wii__)
|
||||||
|
uint64_t js__hrtime_ns(void) {
|
||||||
|
return ticks_to_nanosecs(gettime()) * NANOSEC;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
uint64_t js__hrtime_ns(void) {
|
uint64_t js__hrtime_ns(void) {
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
|
|
|
@ -59,8 +59,8 @@
|
||||||
#define getcwd _getcwd
|
#define getcwd _getcwd
|
||||||
#define chdir _chdir
|
#define chdir _chdir
|
||||||
#else
|
#else
|
||||||
#include <sys/ioctl.h>
|
// #include <sys/ioctl.h>
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
@ -80,7 +80,7 @@ extern char **environ;
|
||||||
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(__wasi__)
|
#if !defined(_WIN32) && !defined(__wasi__) && !defined(__wii__)
|
||||||
/* enable the os.Worker API. IT relies on POSIX threads */
|
/* enable the os.Worker API. IT relies on POSIX threads */
|
||||||
#define USE_WORKER
|
#define USE_WORKER
|
||||||
#endif
|
#endif
|
||||||
|
@ -480,7 +480,7 @@ typedef JSModuleDef *(JSInitModuleFunc)(JSContext *ctx,
|
||||||
const char *module_name);
|
const char *module_name);
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__wasi__)
|
#if defined(_WIN32) || defined(__wasi__) || defined(__wii__)
|
||||||
static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
||||||
const char *module_name)
|
const char *module_name)
|
||||||
{
|
{
|
||||||
|
@ -557,7 +557,7 @@ int js_module_set_import_meta(JSContext *ctx, JSValue func_val,
|
||||||
return -1;
|
return -1;
|
||||||
if (!strchr(module_name, ':')) {
|
if (!strchr(module_name, ':')) {
|
||||||
strcpy(buf, "file://");
|
strcpy(buf, "file://");
|
||||||
#if !defined(_WIN32) && !defined(__wasi__)
|
#if !defined(_WIN32) && !defined(__wasi__) && !defined(__wii__)
|
||||||
/* realpath() cannot be used with modules compiled with qjsc
|
/* realpath() cannot be used with modules compiled with qjsc
|
||||||
because the corresponding module source code is not
|
because the corresponding module source code is not
|
||||||
necessarily present */
|
necessarily present */
|
||||||
|
@ -830,7 +830,7 @@ static void js_std_file_finalizer(JSRuntime *rt, JSValue val)
|
||||||
JSSTDFile *s = JS_GetOpaque(val, js_std_file_class_id);
|
JSSTDFile *s = JS_GetOpaque(val, js_std_file_class_id);
|
||||||
if (s) {
|
if (s) {
|
||||||
if (s->f && s->close_in_finalizer) {
|
if (s->f && s->close_in_finalizer) {
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
if (s->is_popen)
|
if (s->is_popen)
|
||||||
pclose(s->f);
|
pclose(s->f);
|
||||||
else
|
else
|
||||||
|
@ -921,7 +921,7 @@ static JSValue js_std_open(JSContext *ctx, JSValue this_val,
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
static JSValue js_std_popen(JSContext *ctx, JSValue this_val,
|
static JSValue js_std_popen(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
|
@ -957,7 +957,7 @@ static JSValue js_std_popen(JSContext *ctx, JSValue this_val,
|
||||||
JS_FreeCString(ctx, mode);
|
JS_FreeCString(ctx, mode);
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
}
|
}
|
||||||
#endif // !defined(__wasi__)
|
#endif // !defined(__wasi__) && !defined(__wii__)
|
||||||
|
|
||||||
static JSValue js_std_fdopen(JSContext *ctx, JSValue this_val,
|
static JSValue js_std_fdopen(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
|
@ -992,7 +992,7 @@ static JSValue js_std_fdopen(JSContext *ctx, JSValue this_val,
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
static JSValue js_std_tmpfile(JSContext *ctx, JSValue this_val,
|
static JSValue js_std_tmpfile(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
|
@ -1065,7 +1065,7 @@ static JSValue js_std_file_close(JSContext *ctx, JSValue this_val,
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
if (!s->f)
|
if (!s->f)
|
||||||
return JS_ThrowTypeError(ctx, "invalid file handle");
|
return JS_ThrowTypeError(ctx, "invalid file handle");
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
if (s->is_popen)
|
if (s->is_popen)
|
||||||
err = js_get_errno(pclose(s->f));
|
err = js_get_errno(pclose(s->f));
|
||||||
else
|
else
|
||||||
|
@ -1299,7 +1299,7 @@ static JSValue js_std_file_putByte(JSContext *ctx, JSValue this_val,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* urlGet */
|
/* urlGet */
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
|
|
||||||
#define URL_GET_PROGRAM "curl -s -i --"
|
#define URL_GET_PROGRAM "curl -s -i --"
|
||||||
#define URL_GET_BUF_SIZE 4096
|
#define URL_GET_BUF_SIZE 4096
|
||||||
|
@ -1493,7 +1493,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValue this_val,
|
||||||
JS_FreeValue(ctx, response);
|
JS_FreeValue(ctx, response);
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
}
|
}
|
||||||
#endif // !defined(__wasi__)
|
#endif // !defined(__wasi__) && !defined(__wii__)
|
||||||
|
|
||||||
static JSClassDef js_std_file_class = {
|
static JSClassDef js_std_file_class = {
|
||||||
"FILE",
|
"FILE",
|
||||||
|
@ -1526,7 +1526,7 @@ static const JSCFunctionListEntry js_std_funcs[] = {
|
||||||
JS_CFUNC_DEF("setenv", 1, js_std_setenv ),
|
JS_CFUNC_DEF("setenv", 1, js_std_setenv ),
|
||||||
JS_CFUNC_DEF("unsetenv", 1, js_std_unsetenv ),
|
JS_CFUNC_DEF("unsetenv", 1, js_std_unsetenv ),
|
||||||
JS_CFUNC_DEF("getenviron", 1, js_std_getenviron ),
|
JS_CFUNC_DEF("getenviron", 1, js_std_getenviron ),
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
JS_CFUNC_DEF("urlGet", 1, js_std_urlGet ),
|
JS_CFUNC_DEF("urlGet", 1, js_std_urlGet ),
|
||||||
#endif
|
#endif
|
||||||
JS_CFUNC_DEF("loadFile", 1, js_std_loadFile ),
|
JS_CFUNC_DEF("loadFile", 1, js_std_loadFile ),
|
||||||
|
@ -1534,7 +1534,7 @@ static const JSCFunctionListEntry js_std_funcs[] = {
|
||||||
|
|
||||||
/* FILE I/O */
|
/* FILE I/O */
|
||||||
JS_CFUNC_DEF("open", 2, js_std_open ),
|
JS_CFUNC_DEF("open", 2, js_std_open ),
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
JS_CFUNC_DEF("popen", 2, js_std_popen ),
|
JS_CFUNC_DEF("popen", 2, js_std_popen ),
|
||||||
JS_CFUNC_DEF("tmpfile", 0, js_std_tmpfile ),
|
JS_CFUNC_DEF("tmpfile", 0, js_std_tmpfile ),
|
||||||
#endif
|
#endif
|
||||||
|
@ -1751,7 +1751,7 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValue this_val,
|
||||||
}
|
}
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
#elif !defined(__wasi__)
|
#elif !defined(__wasi__) && !defined(__wii__)
|
||||||
static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValue this_val,
|
static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
|
@ -2004,7 +2004,7 @@ static JSValue js_os_signal(JSContext *ctx, JSValue this_val,
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(__wasi__)
|
#if !defined(_WIN32) && !defined(__wasi__) && !defined(__wii__)
|
||||||
static JSValue js_os_cputime(JSContext *ctx, JSValue this_val,
|
static JSValue js_os_cputime(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
|
@ -2395,7 +2395,10 @@ static int js_os_poll(JSContext *ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = select(fd_max + 1, &rfds, &wfds, NULL, tvp);
|
// ret = select(fd_max + 1, &rfds, &wfds, NULL, tvp);
|
||||||
|
|
||||||
|
// jank stub
|
||||||
|
ret = 0;
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
list_for_each(el, &ts->os_rw_handlers) {
|
list_for_each(el, &ts->os_rw_handlers) {
|
||||||
rh = list_entry(el, JSOSRWHandler, link);
|
rh = list_entry(el, JSOSRWHandler, link);
|
||||||
|
@ -2734,7 +2737,7 @@ static char *realpath(const char *path, char *buf)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
/* return [path, errorcode] */
|
/* return [path, errorcode] */
|
||||||
static JSValue js_os_realpath(JSContext *ctx, JSValue this_val,
|
static JSValue js_os_realpath(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
|
@ -2758,7 +2761,7 @@ static JSValue js_os_realpath(JSContext *ctx, JSValue this_val,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(__wasi__)
|
#if !defined(_WIN32) && !defined(__wasi__) && !defined(__wii__)
|
||||||
static JSValue js_os_symlink(JSContext *ctx, JSValue this_val,
|
static JSValue js_os_symlink(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
|
@ -3709,7 +3712,7 @@ static const JSCFunctionListEntry js_os_funcs[] = {
|
||||||
JS_CFUNC_MAGIC_DEF("read", 4, js_os_read_write, 0 ),
|
JS_CFUNC_MAGIC_DEF("read", 4, js_os_read_write, 0 ),
|
||||||
JS_CFUNC_MAGIC_DEF("write", 4, js_os_read_write, 1 ),
|
JS_CFUNC_MAGIC_DEF("write", 4, js_os_read_write, 1 ),
|
||||||
JS_CFUNC_DEF("isatty", 1, js_os_isatty ),
|
JS_CFUNC_DEF("isatty", 1, js_os_isatty ),
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
JS_CFUNC_DEF("ttyGetWinSize", 1, js_os_ttyGetWinSize ),
|
JS_CFUNC_DEF("ttyGetWinSize", 1, js_os_ttyGetWinSize ),
|
||||||
JS_CFUNC_DEF("ttySetRaw", 1, js_os_ttySetRaw ),
|
JS_CFUNC_DEF("ttySetRaw", 1, js_os_ttySetRaw ),
|
||||||
#endif
|
#endif
|
||||||
|
@ -3724,7 +3727,7 @@ static const JSCFunctionListEntry js_os_funcs[] = {
|
||||||
OS_FLAG(SIGILL),
|
OS_FLAG(SIGILL),
|
||||||
OS_FLAG(SIGSEGV),
|
OS_FLAG(SIGSEGV),
|
||||||
OS_FLAG(SIGTERM),
|
OS_FLAG(SIGTERM),
|
||||||
#if !defined(_WIN32) && !defined(__wasi__)
|
#if !defined(_WIN32) && !defined(__wasi__) && !defined(__wii__)
|
||||||
OS_FLAG(SIGQUIT),
|
OS_FLAG(SIGQUIT),
|
||||||
OS_FLAG(SIGPIPE),
|
OS_FLAG(SIGPIPE),
|
||||||
OS_FLAG(SIGALRM),
|
OS_FLAG(SIGALRM),
|
||||||
|
@ -3766,10 +3769,10 @@ static const JSCFunctionListEntry js_os_funcs[] = {
|
||||||
JS_CFUNC_MAGIC_DEF("stat", 1, js_os_stat, 0 ),
|
JS_CFUNC_MAGIC_DEF("stat", 1, js_os_stat, 0 ),
|
||||||
JS_CFUNC_DEF("utimes", 3, js_os_utimes ),
|
JS_CFUNC_DEF("utimes", 3, js_os_utimes ),
|
||||||
JS_CFUNC_DEF("sleep", 1, js_os_sleep ),
|
JS_CFUNC_DEF("sleep", 1, js_os_sleep ),
|
||||||
#if !defined(__wasi__)
|
#if !defined(__wasi__) && !defined(__wii__)
|
||||||
JS_CFUNC_DEF("realpath", 1, js_os_realpath ),
|
JS_CFUNC_DEF("realpath", 1, js_os_realpath ),
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_WIN32) && !defined(__wasi__)
|
#if !defined(_WIN32) && !defined(__wasi__) && !defined(__wii__)
|
||||||
JS_CFUNC_MAGIC_DEF("lstat", 1, js_os_stat, 1 ),
|
JS_CFUNC_MAGIC_DEF("lstat", 1, js_os_stat, 1 ),
|
||||||
JS_CFUNC_DEF("symlink", 2, js_os_symlink ),
|
JS_CFUNC_DEF("symlink", 2, js_os_symlink ),
|
||||||
JS_CFUNC_DEF("readlink", 1, js_os_readlink ),
|
JS_CFUNC_DEF("readlink", 1, js_os_readlink ),
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
#define NO_TM_GMTOFF
|
#define NO_TM_GMTOFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(EMSCRIPTEN) && !defined(__wasi__)
|
#if !defined(EMSCRIPTEN) && !defined(__wasi__) && !defined(__wii__)
|
||||||
#include "quickjs-c-atomics.h"
|
#include "quickjs-c-atomics.h"
|
||||||
#define CONFIG_ATOMICS
|
#define CONFIG_ATOMICS
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue