mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
up
up Update build_wasm.sh
This commit is contained in:
parent
ec8ca3bb8d
commit
addd9d6feb
@ -1,3 +1,3 @@
|
|||||||
rm -rf web/lib/
|
rm -rf web/lib/
|
||||||
mkdir -p web/lib/
|
mkdir -p web/lib/
|
||||||
em++ src/main.cpp -fno-rtti -fexceptions -sEXIT_RUNTIME -O3 -sMODULARIZE -sEXPORTED_FUNCTIONS=_repl_input,_repl_start,_pkpy_delete,_pkpy_new_repl,_pkpy_repl_input,_pkpy_new_tvm,_pkpy_tvm_exec_async,_pkpy_tvm_get_state,_pkpy_tvm_read_jsonrpc_request,_pkpy_tvm_reset_state,_pkpy_tvm_terminate,_pkpy_tvm_write_jsonrpc_response,_pkpy_new_vm,_pkpy_vm_add_module,_pkpy_vm_eval,_pkpy_vm_exec,_pkpy_vm_get_global,_pkpy_vm_read_output -sEXPORTED_RUNTIME_METHODS=ccall,cwrap -o web/lib/pocketpy.js
|
em++ src/main.cpp -fno-rtti -fexceptions -O3 -sEXPORTED_FUNCTIONS=_pkpy_delete,_pkpy_new_repl,_pkpy_repl_input,_pkpy_new_tvm,_pkpy_tvm_exec_async,_pkpy_tvm_get_state,_pkpy_tvm_read_jsonrpc_request,_pkpy_tvm_reset_state,_pkpy_tvm_terminate,_pkpy_tvm_write_jsonrpc_response,_pkpy_new_vm,_pkpy_vm_add_module,_pkpy_vm_eval,_pkpy_vm_exec,_pkpy_vm_get_global,_pkpy_vm_read_output -sEXPORTED_RUNTIME_METHODS=ccall -o web/lib/pocketpy.js
|
@ -67,6 +67,13 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
js:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: js
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.5"
|
||||||
matcher:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
5
plugins/flutter/lib/web.dart
Normal file
5
plugins/flutter/lib/web.dart
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import 'package:js/js.dart';
|
||||||
|
|
||||||
|
@JS("Module.ccall")
|
||||||
|
external int ccall(String name, String returnType, List<String> argTypes,
|
||||||
|
List<dynamic> args);
|
@ -12,6 +12,7 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
ffi: ^2.0.1
|
ffi: ^2.0.1
|
||||||
|
js: ^0.6.5
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
@ -6784,6 +6784,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__wasm32__) || defined(__wasm64__)
|
#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__wasm32__) || defined(__wasm64__)
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#define __EXPORT EMSCRIPTEN_KEEPALIVE
|
#define __EXPORT EMSCRIPTEN_KEEPALIVE
|
||||||
|
#define __NO_MAIN
|
||||||
#else
|
#else
|
||||||
#define __EXPORT
|
#define __EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 0024722da6796a9f5c954bba2d0b617c602106c7
|
Subproject commit d3e448cdbca422c2c9af45b46d8371f66139e12e
|
14
src/main.cpp
14
src/main.cpp
@ -22,19 +22,6 @@ struct Timer{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__wasm32__) || defined(__wasm64__)
|
|
||||||
|
|
||||||
// these code is for demo use, feel free to modify it
|
|
||||||
REPL* _repl;
|
|
||||||
extern "C" {
|
|
||||||
__EXPORT
|
|
||||||
void repl_start(){ _repl = pkpy_new_repl(pkpy_new_vm(true));}
|
|
||||||
__EXPORT
|
|
||||||
bool repl_input(const char* line){ return pkpy_repl_input(_repl, line) == NEED_MORE_LINES;}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
|
|
||||||
|
|
||||||
void _tvm_dispatch(ThreadedVM* vm){
|
void _tvm_dispatch(ThreadedVM* vm){
|
||||||
while(pkpy_tvm_get_state(vm) != THREAD_FINISHED){
|
while(pkpy_tvm_get_state(vm) != THREAD_FINISHED){
|
||||||
if(pkpy_tvm_get_state(vm) == THREAD_SUSPENDED){
|
if(pkpy_tvm_get_state(vm) == THREAD_SUSPENDED){
|
||||||
@ -59,6 +46,7 @@ void _tvm_dispatch(ThreadedVM* vm){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __NO_MAIN
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
if(argc == 1){
|
if(argc == 1){
|
||||||
|
@ -592,6 +592,7 @@ void __initializeBuiltinFunctions(VM* _vm) {
|
|||||||
#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__wasm32__) || defined(__wasm64__)
|
#elif defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(__wasm32__) || defined(__wasm64__)
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#define __EXPORT EMSCRIPTEN_KEEPALIVE
|
#define __EXPORT EMSCRIPTEN_KEEPALIVE
|
||||||
|
#define __NO_MAIN
|
||||||
#else
|
#else
|
||||||
#define __EXPORT
|
#define __EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,6 +3,7 @@ const term = new Terminal();
|
|||||||
var command = "";
|
var command = "";
|
||||||
var need_more_lines = false;
|
var need_more_lines = false;
|
||||||
var stopped = false;
|
var stopped = false;
|
||||||
|
var repl = 0;
|
||||||
|
|
||||||
var Module = {
|
var Module = {
|
||||||
'print': function(text) {
|
'print': function(text) {
|
||||||
@ -12,7 +13,8 @@ var Module = {
|
|||||||
term.write(text + "\r\n");
|
term.write(text + "\r\n");
|
||||||
},
|
},
|
||||||
'onRuntimeInitialized': function(text) {
|
'onRuntimeInitialized': function(text) {
|
||||||
Module.ccall('repl_start', null, [], []);
|
var vm = Module.ccall('pkpy_new_vm', 'number', ['boolean'], [true]);
|
||||||
|
repl = Module.ccall('pkpy_new_repl', 'number', ['number'], [vm]);
|
||||||
term.write(need_more_lines ? "... " : ">>> ");
|
term.write(need_more_lines ? "... " : ">>> ");
|
||||||
},
|
},
|
||||||
'onAbort': function(text) {
|
'onAbort': function(text) {
|
||||||
@ -32,7 +34,7 @@ function term_init() {
|
|||||||
term.write("Bye!\r\n");
|
term.write("Bye!\r\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
need_more_lines = Module.ccall('repl_input', Boolean, ['string'], [command]);
|
need_more_lines = Module.ccall('pkpy_repl_input', 'number', ['number', 'string'], [repl, command]) == 0;
|
||||||
command = '';
|
command = '';
|
||||||
term.write(need_more_lines ? "... " : ">>> ");
|
term.write(need_more_lines ? "... " : ">>> ");
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user