Skip to content

Instantly share code, notes, and snippets.

@actondev
Created August 5, 2020 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save actondev/41067d7028051b7795b7f05c2d0f033b to your computer and use it in GitHub Desktop.
Save actondev/41067d7028051b7795b7f05c2d0f033b to your computer and use it in GitHub Desktop.
s7 wasm example
#include "s7.h"
#include <stdio.h>
void _s7_print_stderr(s7_scheme *sc, uint8_t c, s7_pointer port) {
printf("%c", c);
}
int main() {
printf("hello, world!\n");
s7_scheme* sc = s7_init();
s7_set_current_output_port(sc, s7_open_output_function(sc, _s7_print_stderr));
s7_eval_c_string(sc, "(format #t \"result is ~A\n\" (+ 1 2 3))");
return 0;
}
@actondev
Copy link
Author

actondev commented Aug 5, 2020

emcc -c s7.c
emcc -c s7_wasm.c
# disabling error on undefined symbols cause of popen
emcc s7_wasm.o s7.o -o s7_wasm.js -s ERROR_ON_UNDEFINED_SYMBOLS=0
node wasm.js

Output:

hello, world!
result is 6

@actondev
Copy link
Author

actondev commented Aug 5, 2020

emcc -v

emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.40.1
clang version 12.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project 9f21947a331203ee2579db87f1d1ec22a949e20a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/actondev/dev/github/emsdk/upstream/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
shared:INFO: (Emscripten: Running sanity checks)

@actondev
Copy link
Author

actondev commented Aug 5, 2020

Or, the "fix" for popen (or throw some error actually)

 static s7_pointer g_system(s7_scheme *sc, s7_pointer args)
 {
   #define H_system "(system command) executes the command.  If the optional second argument is #t, \
 system captures the output as a string and returns it."
   #define Q_system s7_make_signature(sc, 3, s7_make_signature(sc, 2, sc->is_integer_symbol, sc->is_string_symbol), sc->is_string_symbol, sc->is_boolean_symbol)
 
+#ifdef __EMSCRIPTEN__
+     return s7_nil(sc);
+#else

@iainctduncan
Copy link

Fantastic! Can't wait to try. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment