[분석할 소스] 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

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
174 [Unix/Linux][유닉스/리눅스] chmod [권한변경] /bin/chmod 졸리운_곰 2021.02.14 247
173 How to Install Dev-C++ and the GLUT Libraries for Compiling OpenGL Programs with ANSI C file 졸리운_곰 2021.02.02 321
172 [무료 리눅스 linux 백신, 안티바이러스] 무료 리눅스 백신 ClamAV 이용 및 문제 해결법 졸리운_곰 2021.02.01 342
171 [C/C++] 미니멀 가상화폐 코드 , 미니멀 블룩체인, noincoin (Block Chain in C Major) file 졸리운_곰 2021.01.30 279
170 리눅스 tee, 화면과 파일에 동시 출력하기 졸리운_곰 2021.01.21 395
169 [C/C++ 네트워크 프로그래밍] POCO 라이브러리의 특징 졸리운_곰 2021.01.06 642
168 Visual Studio Community로 V8 엔진 다운로드 및 빌드하고 간단히 살펴보기 file 졸리운_곰 2020.11.30 271
167 [Linux] [C/C++] CMake를 이용한 패키지 빌드 file 졸리운_곰 2020.11.08 297
166 [Linux][C/C++] cmake 사용법과 활용 file 졸리운_곰 2020.11.08 552
165 [CMake] Linux C/C++ cmake 시작하기 졸리운_곰 2020.11.08 398
164 [C++] CMake Build System file 졸리운_곰 2020.11.08 328
163 [리눅스, Linux] YUM 명령어 정리 file 졸리운_곰 2020.11.07 322
162 자바(Java) instanceof 사용방법 졸리운_곰 2020.10.29 328
161 Building libtorrent with Visual Studio file 졸리운_곰 2020.10.25 309
160 [분석할 소스] microPython 마이크로 파이썬 소스 file 졸리운_곰 2020.10.18 348
» [분석할 소스] MicroPython.js MicroPython transmuted into Javascript by Emscripten. file 졸리운_곰 2020.10.18 250
158 [리눅스, linux] 프로세스를 이름으로 단번에 종료하기 졸리운_곰 2020.08.17 497
157 Fun with YouTube Data API v3 (Public Data) and Kigs Framework file 졸리운_곰 2020.07.19 314
156 Kigs Framework Introduction (8/8) - Data Driven Application file 졸리운_곰 2020.07.18 302
155 ubuntu 18.04 - Ubuntu 한글 입력기 설치(fcitx) file 졸리운_곰 2020.06.29 334
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED