javascript: Fix Emscripten async load, and to compile with modern clang.

pull/1/head
Wolf Vollprecht 2019-02-10 16:29:25 +01:00 committed by Damien George
parent 7d675f3a17
commit ea2fcdd338
4 changed files with 55 additions and 44 deletions

View File

@ -14,7 +14,12 @@ INC += -I$(TOP)
INC += -I$(BUILD)
CPP = clang -E
CFLAGS = -m32 $(INC) -Wall -Werror -std=c99 $(COPT)
ifdef EMSCRIPTEN
CPP += -isystem $(EMSCRIPTEN)/system/include/libc -cxx-isystem $(EMSCRIPTEN)/system/include/libcxx
endif
CFLAGS = -m32 -Wall -Werror $(INC) -std=c99 $(COPT)
LDFLAGS = -m32 -Wl,-Map=$@.map,--cref -Wl,--gc-sections
CFLAGS += -O0 -DNDEBUG
@ -46,8 +51,7 @@ all: $(BUILD)/micropython.js
$(BUILD)/micropython.js: $(OBJ) library.js wrapper.js
$(ECHO) "LINK $(BUILD)/firmware.js"
$(Q)emcc $(LDFLAGS) -o $(BUILD)/firmware.js $(OBJ) $(JSFLAGS)
cat $(BUILD)/firmware.js > $@
cat wrapper.js >> $@
cat wrapper.js $(BUILD)/firmware.js > $@
min: $(BUILD)/micropython.js
uglifyjs $< -c -o $(BUILD)/micropython.min.js

View File

@ -27,7 +27,7 @@
#include "library.h"
#include "mphalport.h"
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
mp_js_write(str, len);
}

View File

@ -28,7 +28,7 @@
#include "lib/utils/interrupt_char.h"
#define mp_hal_stdin_rx_chr() (0)
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
void mp_hal_stdout_tx_strn(const char *str, size_t len);
void mp_hal_delay_ms(mp_uint_t ms);
void mp_hal_delay_us(mp_uint_t us);

View File

@ -24,47 +24,54 @@
* THE SOFTWARE.
*/
mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']);
mp_js_do_str = Module.cwrap('mp_js_do_str', 'null', ['string']);
mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']);
mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number']);
var Module = {};
var MP_JS_EPOCH = (new Date()).getTime();
var mainProgram = function()
{
mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']);
mp_js_do_str = Module.cwrap('mp_js_do_str', 'null', ['string']);
mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']);
mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number']);
if (typeof window === 'undefined' && require.main === module) {
var fs = require('fs');
var stack_size = 64 * 1024;
var contents = '';
var repl = true;
MP_JS_EPOCH = (new Date()).getTime();
for (var i = 0; i < process.argv.length; i++) {
if (process.argv[i] === '-X' && i < process.argv.length - 1) {
if (process.argv[i + 1].includes('stack=')) {
stack_size = parseInt(process.argv[i + 1].split('stack=')[1]);
if (process.argv[i + 1].substr(-1).toLowerCase() === 'k') {
stack_size *= 1024;
} else if (process.argv[i + 1].substr(-1).toLowerCase() === 'm') {
stack_size *= 1024 * 1024;
}
}
} else if (process.argv[i].includes('.py')) {
contents += fs.readFileSync(process.argv[i], 'utf8');
repl = false;;
}
}
mp_js_init(stack_size);
if (typeof window === 'undefined' && require.main === module) {
var fs = require('fs');
var stack_size = 64 * 1024;
var contents = '';
var repl = true;
if (repl) {
mp_js_init_repl();
process.stdin.setRawMode(true);
process.stdin.on('data', function (data) {
for (var i = 0; i < data.length; i++) {
if (mp_js_process_char(data[i])) {
process.exit()
}
}
});
} else {
mp_js_do_str(contents);
}
for (var i = 0; i < process.argv.length; i++) {
if (process.argv[i] === '-X' && i < process.argv.length - 1) {
if (process.argv[i + 1].includes('stack=')) {
stack_size = parseInt(process.argv[i + 1].split('stack=')[1]);
if (process.argv[i + 1].substr(-1).toLowerCase() === 'k') {
stack_size *= 1024;
} else if (process.argv[i + 1].substr(-1).toLowerCase() === 'm') {
stack_size *= 1024 * 1024;
}
}
} else if (process.argv[i].includes('.py')) {
contents += fs.readFileSync(process.argv[i], 'utf8');
repl = false;;
}
}
mp_js_init(stack_size);
if (repl) {
mp_js_init_repl();
process.stdin.setRawMode(true);
process.stdin.on('data', function (data) {
for (var i = 0; i < data.length; i++) {
if (mp_js_process_char(data[i])) {
process.exit()
}
}
});
} else {
mp_js_do_str(contents);
}
}
}
Module["onRuntimeInitialized"] = mainProgram;