Skip to content

Commit ea2fcdd

Browse files
wolfvdpgeorge
authored andcommitted
javascript: Fix Emscripten async load, and to compile with modern clang.
1 parent 7d675f3 commit ea2fcdd

File tree

4 files changed

+55
-44
lines changed

4 files changed

+55
-44
lines changed

ports/javascript/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ INC += -I$(TOP)
1414
INC += -I$(BUILD)
1515

1616
CPP = clang -E
17-
CFLAGS = -m32 $(INC) -Wall -Werror -std=c99 $(COPT)
17+
18+
ifdef EMSCRIPTEN
19+
CPP += -isystem $(EMSCRIPTEN)/system/include/libc -cxx-isystem $(EMSCRIPTEN)/system/include/libcxx
20+
endif
21+
22+
CFLAGS = -m32 -Wall -Werror $(INC) -std=c99 $(COPT)
1823
LDFLAGS = -m32 -Wl,-Map=$@.map,--cref -Wl,--gc-sections
1924

2025
CFLAGS += -O0 -DNDEBUG
@@ -46,8 +51,7 @@ all: $(BUILD)/micropython.js
4651
$(BUILD)/micropython.js: $(OBJ) library.js wrapper.js
4752
$(ECHO) "LINK $(BUILD)/firmware.js"
4853
$(Q)emcc $(LDFLAGS) -o $(BUILD)/firmware.js $(OBJ) $(JSFLAGS)
49-
cat $(BUILD)/firmware.js > $@
50-
cat wrapper.js >> $@
54+
cat wrapper.js $(BUILD)/firmware.js > $@
5155

5256
min: $(BUILD)/micropython.js
5357
uglifyjs $< -c -o $(BUILD)/micropython.min.js

ports/javascript/mphalport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "library.h"
2828
#include "mphalport.h"
2929

30-
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
30+
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
3131
mp_js_write(str, len);
3232
}
3333

ports/javascript/mphalport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "lib/utils/interrupt_char.h"
2929

3030
#define mp_hal_stdin_rx_chr() (0)
31-
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len);
31+
void mp_hal_stdout_tx_strn(const char *str, size_t len);
3232

3333
void mp_hal_delay_ms(mp_uint_t ms);
3434
void mp_hal_delay_us(mp_uint_t us);

ports/javascript/wrapper.js

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,54 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']);
28-
mp_js_do_str = Module.cwrap('mp_js_do_str', 'null', ['string']);
29-
mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']);
30-
mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number']);
27+
var Module = {};
3128

32-
var MP_JS_EPOCH = (new Date()).getTime();
29+
var mainProgram = function()
30+
{
31+
mp_js_init = Module.cwrap('mp_js_init', 'null', ['number']);
32+
mp_js_do_str = Module.cwrap('mp_js_do_str', 'null', ['string']);
33+
mp_js_init_repl = Module.cwrap('mp_js_init_repl', 'null', ['null']);
34+
mp_js_process_char = Module.cwrap('mp_js_process_char', 'number', ['number']);
3335

34-
if (typeof window === 'undefined' && require.main === module) {
35-
var fs = require('fs');
36-
var stack_size = 64 * 1024;
37-
var contents = '';
38-
var repl = true;
36+
MP_JS_EPOCH = (new Date()).getTime();
3937

40-
for (var i = 0; i < process.argv.length; i++) {
41-
if (process.argv[i] === '-X' && i < process.argv.length - 1) {
42-
if (process.argv[i + 1].includes('stack=')) {
43-
stack_size = parseInt(process.argv[i + 1].split('stack=')[1]);
44-
if (process.argv[i + 1].substr(-1).toLowerCase() === 'k') {
45-
stack_size *= 1024;
46-
} else if (process.argv[i + 1].substr(-1).toLowerCase() === 'm') {
47-
stack_size *= 1024 * 1024;
48-
}
49-
}
50-
} else if (process.argv[i].includes('.py')) {
51-
contents += fs.readFileSync(process.argv[i], 'utf8');
52-
repl = false;;
53-
}
54-
}
55-
mp_js_init(stack_size);
38+
if (typeof window === 'undefined' && require.main === module) {
39+
var fs = require('fs');
40+
var stack_size = 64 * 1024;
41+
var contents = '';
42+
var repl = true;
5643

57-
if (repl) {
58-
mp_js_init_repl();
59-
process.stdin.setRawMode(true);
60-
process.stdin.on('data', function (data) {
61-
for (var i = 0; i < data.length; i++) {
62-
if (mp_js_process_char(data[i])) {
63-
process.exit()
64-
}
65-
}
66-
});
67-
} else {
68-
mp_js_do_str(contents);
69-
}
44+
for (var i = 0; i < process.argv.length; i++) {
45+
if (process.argv[i] === '-X' && i < process.argv.length - 1) {
46+
if (process.argv[i + 1].includes('stack=')) {
47+
stack_size = parseInt(process.argv[i + 1].split('stack=')[1]);
48+
if (process.argv[i + 1].substr(-1).toLowerCase() === 'k') {
49+
stack_size *= 1024;
50+
} else if (process.argv[i + 1].substr(-1).toLowerCase() === 'm') {
51+
stack_size *= 1024 * 1024;
52+
}
53+
}
54+
} else if (process.argv[i].includes('.py')) {
55+
contents += fs.readFileSync(process.argv[i], 'utf8');
56+
repl = false;;
57+
}
58+
}
59+
mp_js_init(stack_size);
60+
61+
if (repl) {
62+
mp_js_init_repl();
63+
process.stdin.setRawMode(true);
64+
process.stdin.on('data', function (data) {
65+
for (var i = 0; i < data.length; i++) {
66+
if (mp_js_process_char(data[i])) {
67+
process.exit()
68+
}
69+
}
70+
});
71+
} else {
72+
mp_js_do_str(contents);
73+
}
74+
}
7075
}
76+
77+
Module["onRuntimeInitialized"] = mainProgram;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy