Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL on the sneklang website #38

Open
vanillajonathan opened this issue Oct 19, 2021 · 10 comments
Open

REPL on the sneklang website #38

vanillajonathan opened this issue Oct 19, 2021 · 10 comments

Comments

@vanillajonathan
Copy link
Contributor

A Snek REPL on the sneklang website.

@keith-packard
Copy link
Owner

This would be cool, but I fear it would be very difficult to prevent abuse and make it secure.

@drawkula
Copy link

drawkula commented Dec 13, 2021

Maybe the Unix binary can be adopted by TryItOnline (their source @ github)? They have some experience in jailing interpreters and compilers.

@vanillajonathan
Copy link
Contributor Author

This would be cool, but I fear it would be very difficult to prevent abuse and make it secure.

Maybe this could be done with Emscripten to compile it down to WASM that executes the code client-side in the web browser?

@vanillajonathan
Copy link
Contributor Author

MicroPython has a REPL built with Unicorn.js.

https://micropython.org/unicorn/

@mobluse
Copy link

mobluse commented Jan 14, 2022

MicroPython has a REPL built with Unicorn.js.

https://micropython.org/unicorn/

Unicorn is an emulator. If there is another emulator in JavaScript for Linux (or OS that supports what is needed for Posix Snek) that supports a CPU for which gcc and the dependencies for Snek exist, that might be an easy way to get Snek running in a browser.

I found this example of an Arduino UNO emulator:
https://wokwi.com/arduino/projects/308893120796295745

Then I changed the loop() function to something that is more like a REPL:

void loop() {
  int incomingByte = 0; // for incoming serial data
  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print("I received: ");
    Serial.print(incomingByte, DEC);
    Serial.print(" ");
    Serial.println((char)incomingByte);
  }
}

This is also open source: https://github.com/wokwi/avr8js

If one could make Snek into a library that could be called from an Arduino sketch then that Wokwi system could be used to get the Snek REPL running in a browser.

@keith-packard
Copy link
Owner

Katie Bell just gave a presentation at LCA 2022 where she compiled CPython with enscripten to wasm and ran the result in a browser. I suspect doing that for snek would be less work.

@mobluse
Copy link

mobluse commented Jan 16, 2022

I could not find that presentation on YouTube.

I tried to compile Snek for ia32 (x86) and upload it to a x86 emulator running Buildroot Linux https://copy.sh/v86/?profile=buildroot and https://github.com/copy/v86. It would not work because of dynamic libraries. Then I tried to compile it statically, but I could not get it to compile. I compiled it on Ubuntu 18.04.6 LTS (GNU/Linux 4.15.0-166-generic i686).

These were my changes to Makefile in ports/posix:

CFLAGS+=-DSNEK_MEM_INCLUDE_NAME -static $(OPT) -g -I. $(SNEK_CFLAGS) -Werror $(CPPFLAGS) $(CFLAGS_POSIX)

LIBS=-static-libgcc -Wl,-Bstatic -lreadline -Wl,-Bstatic -lm

@keith-packard
Copy link
Owner

As you can see, I hacked up the posix port to allow it to be built without readline so that it can be linked -static. If you're up for trying this again, please let us know!

@markh2016
Copy link

Hi

I'm new to this and just started

Ive read through the manual but have a questions

How do I write to serial port as I would with arduino C++

How also do I address pins for lets say writing to a LCD in nibble mode , byte mode using the snek programming language Could you perhaps provide some examples I could follow

Thanking you

Mark Harrington

@vanillajonathan
Copy link
Contributor Author

@markh2016 This issue is about another topic, here is the answer to your question: #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants