Code Monkey home page Code Monkey logo

micropython-wasm's People

Contributors

alanjds avatar boisgera avatar rafi16jan avatar tessereth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

micropython-wasm's Issues

Webpack: Can't resolve 'fs'

I tried pulling in this npm package and compiling it with webpack but I get the following errors:

ERROR in ./node_modules/micropython/index.js
Module not found: Error: Can't resolve 'fs' in './micropython_example/node_modules/micropython'
 @ ./node_modules/micropython/index.js 21:9-22
 @ ./assets/js/app.js
 @ ./assets/js/index.js

ERROR in ./node_modules/micropython/lib/micropython.js
Module not found: Error: Can't resolve 'fs' in './micropython_example/node_modules/micropython/lib'
 @ ./node_modules/micropython/lib/micropython.js 39:15-28 80:13-26 179:28-41 3005:23-36
 @ ./node_modules/micropython/index.js
 @ ./assets/js/app.js
 @ ./assets/js/index.js

This appears to be because webpack is not detecting that it can never go down the "node-only" path and still trying to require fs. If I add typeof __webpack_require__ !== 'function' on every branch that requires fs, everything works. But I don't know enough about webpack to be confident such changes are a good idea and/or they wouldn't break it for someone else.

You can see my webpack version and config and a working example at https://github.com/tessereth/micropython_wasm_example.

Could not compile from `master` @ 21bf511f93dd94a5ac05626b5a94c70d7492d427

I am trying to compile on master @ 21bf511f93dd94a5ac05626b5a94c70d7492d427 (Save my work at micropython-wasm), but is not compiling:

$ time make
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p build/genhdr
GEN build/genhdr/mpversion.h
GEN build/genhdr/moduledefs.h
GEN build/genhdr/qstr.i.last
GEN build/genhdr/qstr.split
GEN build/genhdr/qstrdefs.collected.h
QSTR updated
GEN build/genhdr/qstrdefs.generated.h
mkdir -p build/extmod
mkdir -p build/lib/embed
mkdir -p build/lib/mp-readline
mkdir -p build/lib/utils
mkdir -p build/py
CC ../../py/mpstate.c
(...)
CC ../../lib/mp-readline/readline.c
CC main.c
CC mphalport.c
CC modutime.c
LINK build/firmware.js
emcc:WARNING: ignoring unsupported linker flag: `-Map=build/micropython.js.map`
emcc:WARNING: ignoring unsupported linker flag: `--cref`
emcc:WARNING: ignoring unsupported linker flag: `--gc-sections`
error: undefined symbol: mp_module_js
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
Error: Aborting compilation due to previous errors
shared:ERROR: '/Users/alanjds/src/git/emsdk/node/8.9.1_64bit/bin/node /Users/alanjds/src/git/emsdk/fastcomp/emscripten/src/compiler.js /tmp/tmpvPCwWN.txt /Users/alanjds/src/git/micropython/ports/javascript/library.js /Users/alanjds/src/git/emsdk/fastcomp/emscripten/src/library_pthread_stub.js' failed (1)
make: *** [build/micropython.js] Error 1

real	0m50.846s
user	0m31.518s
sys	0m18.148s

Am I doing something wrong?

Parcel (or any other bundler) support

Trying to use micropython.js following the npmjs readmem somehow an internal node_modules/micropython/index.js:113:49 could not be imported.

// index.js
import mp_js from 'micropython';

/*
(async () => {
    await mp_js;
    mp_js.init(64 * 1024);
    mp_js.do_str("print('hello world')\n");
})();
*/
๐Ÿšจ  /Users/alanjds/src/git/parcel-plugin-micropython/node_modules/micropython/index.js:113:49: Unexpected token, expected ";" (113:49)
  111 |     return await methods.do_str(pyjs);
  112 |   }
> 113 |   methods.register_module = async (module, code) {
      |                                                 ^
  114 |     if (!pyjs_initiated) return pyjs += '\n' + await methods.do_str(code, module, false);
  115 |     return await methods.do_str(code, module, true);
  116 |   }

May be possible to this package to have some specification issue on packages.json?
Looks like some babel translation is not being applied? But I could not find it by myself. Am I looking at the wrong place/path?

Context:

$ node --version
v9.11.2
$ cat package.json
{
  "name": "helloworld",
  "version": "1.0.0",
  "description": "An absolute bare-bones web app.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "parcel serve web/index.html"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "eslint": "^6.0.1",
    "parcel-plugin-micropython": "file:../.."
  },
  "devDependencies": {
    "@babel/core": "^7.2.2"
  }
}

process_char does result in repl response

Ran the following code but didn't see any repl response...
Am I doing something wrong?
Running mp_js.do_str does execute print statements though....

const mp_js = require('micropython') \\ I waited till promises fulfilled for each
mp_js.init(64*1024)
mp_js.init_repl()
let b = new TextEncoder().encode('print(\'hello world\')')
for(let i = 0; i < b.length; i++){
   mp_js.process_char(b[ i ])
}
mp_js.process_char("\r".charCodeAt(0))
mp_js.process_char("\n".charCodeAt(0))

Silent failure on python exceptions

I don't know how much this is to do with your code or Emscripten, but if your python code raises an exception, the do_str promise never resolves. Eg:

import mp_js from 'micropython'

async () => {
  await mp_js.init(64 * 1024)
  const stdout = await mp_js.do_str(`invalid syntax`)
  console.log(stdout) // <-- this never logs and no exception is raised
}();

This makes it very difficult to debug what could be going wrong. It would be great if python exceptions were accessible in some way, even if just logged to console, and the promise rejected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.