[분석할 소스] MicroPython.js MicroPython transmuted into Javascript by Emscripten.

MicroPython.js

MicroPython transmuted into Javascript by Emscripten.

 

소스 다운 : microPython port WebAssembly.zip

 

Dependencies

Building micropython.js bears the same requirements as the standard MicroPython ports with the addition of Emscripten (and uglify-js for the minified file).

A standard installation of Emscripten should provide functional code, however if memory errors are encountered it may be worthwhile to modify the tool. emscripten-fastcomp/lib/Target/JSBackend.cpp may require the minor fix found in JSBackend.patch. This patch attempts to address situations where C code running through Emscripten is denied access to Javascript variables leading to false-positives in the MicroPython garbage collector as variables with pointers exclusively in Javascript will be erased prematurely. Refer to Emscripten documentation for instructions on building Emscripten from source.

Build instructions

In order to build micropython.js, run:

$ make

To generate the minified file micropython.min.js, run:

$ make min

Running with Node.js

Access the repl with:

$ node build/micropython.js

Stack size may be modified using:

$ node build/micropython.js -X stack=64K

Where stack size may be represented in Bytes, KiB or MiB.

MicroPython scripts may be executed using:

$ node build/micropython.js hello.py

Alternatively micropython.js may by accessed by other javascript programs in node using the require command and the general API outlined below. For example:

var mp_js = require('./build/micropython.js');

mp_js_init(64 * 1024);
mp_js_do_str("print('hello world')\n");

Running with HTML

The prerequisite for browser operation of micropython.js is an element with the id mp_js_stdout which receives print events. The following code demonstrates basic functionality:

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

<!doctype html>
<html>
  <head>
    <script src="build/micropython.js"></script>
  </head>
  <body>
    <div id='mp_js_stdout'></div>
    <script>
      mp_js_stdout.addEventListener('print', function(e) {
        document.write(e.data);
      }, false);

      mp_js_init(64 * 1024);
      mp_js_do_str('print(\'hello world\')');
    </script>
  </body>
</html>

MicroPython code execution will suspend the browser so be sure to atomize usage within this environment. Unfortunately interrupts have not been implemented for the browser.

Testing

Run the test suite using:

$ make test

API

The following functions have been exposed to javascript.

mp_js_init(stack_size)

Initialize MicroPython with the given stack size in bytes. This must be called before attempting to interact with MicroPython.

mp_js_do_str(code)

Execute the input code. code must be a string.

mp_js_init_repl()

Initialize MicroPython repl. Must be called before entering characters into the repl.

mp_js_process_char(char)

Input character into MicroPython repl. char must be of type number. This will execute MicroPython code when necessary.

 

[출처] https://github.com/micropython/micropython/tree/master/ports/javascript

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
23 [C/C++ 인공지능] Artificial Neural Network C++ Class : 인공신경망 C++ 클래스 file 졸리운_곰 2023.11.25 308
22 [C/C++ 인공지능] Visual Studio 2019에서 LibTorch 사용하기 file 졸리운_곰 2023.11.20 392
21 [C/C++ 인공지능] A Simple and Complete Explanation of Neural Networks : 신경망에 대한 간단하고 완전한 설명 file 졸리운_곰 2023.10.22 279
20 [C/C++ 인공지능] Deep Learning from Scratch in C++: Tensor Programming file 졸리운_곰 2023.09.06 340
19 [C/C++ 인공지능] Getting Started with mlpack 졸리운_곰 2023.01.28 310
18 [C/C++][인공지능] Most Useful C/C++ ML Libraries Every Data Scientist Should Know file 졸리운_곰 2022.10.01 423
17 [인공지능] 추론 기법 file 졸리운_곰 2022.05.05 509
16 [C++ 인공지능] C ++을 이용한 단순 MLP 역 전파 인공 신경망 (단계 별) file 졸리운_곰 2022.04.11 370
15 [C/C++인공지능] An Introduction to Machine Learning Libraries for C++ file 졸리운_곰 2021.12.06 360
14 [C/C++][tensorflow 1.x] windows C lib : [Tensorflow] How to Install Tensorflow for C API file 졸리운_곰 2021.11.19 396
13 [C/C++][tensorflow] tensorflovw 1.x version 텐서플로우 C 예제 file 졸리운_곰 2021.11.19 544
12 [C/C++ 인공지능][linux][cuda] flashlight file 졸리운_곰 2021.11.09 506
11 [C/C++] (고전 기호 처리 인공지능) 전문가 시스템 file 졸리운_곰 2020.06.13 330
10 [유전알고리즘] 자동 그림생성 프로그램 - Evolving Image file 졸리운_곰 2018.03.04 910
9 대화 프로그램 - ELIZA 졸리운_곰 2018.03.04 359
8 Caffe 설치하기 ๑•‿•๑ (2) file 졸리운_곰 2018.02.21 337
7 Caffe 설치하기 ๑•‿•๑ (1) file 졸리운_곰 2018.02.21 427
6 Windows 에 Caffe 설치하기 (๑•‿•๑) 졸리운_곰 2018.02.21 306
5 Windows에서 Caffe 예제 돌리기 : MNIST(1) (๑•‿•๑) file 졸리운_곰 2018.02.21 356
4 Caffe 구성 요소들 알아보기: blobs, nets, layer, solver, prototxt ๑•‿•๑ file 졸리운_곰 2018.02.21 569
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED