Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 24, 2015 21:54:56 GMT 1
|
|
|
Post by vovchik on Nov 24, 2015 22:04:07 GMT 1
Dear John, Thanks for finding this. I wonder whether we could get it to work with BaCon. Intriguing prospect. With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 25, 2015 7:01:56 GMT 1
I'm building the LLVM compiler for Linux 64 bit. What a monster!
Calling JavaScript from C/C++
Emscripten provides two main approaches for calling JavaScript from C/C++: running the script using emscripten_run_script() or writing “inline JavaScript”.
The most direct, but slightly slower, way is to use emscripten_run_script(). This effectively runs the specified JavaScript code from C/C++ using eval(). For example, to call the browser’s alert() function with the text ‘hi’, you would call the following JavaScript:
emscripten_run_script("alert('hi')");
I'm going to try and use this as a Script BASIC extension module JavaScript interpreter. (like the TinyScheme, Perl and MyBASIC extension modules interfaces I did)
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 25, 2015 8:18:16 GMT 1
Here is my Hello World with the ems compiler.
#include <stdio.h>
int main() { printf("hello, world!\n"); return 0; }
jrs@laptop:~/ems/test$ emcc hello_world.c jrs@laptop:~/ems/test$ node a.out.js hello, world! jrs@laptop:~/ems/test$ ls -l total 472 -rw-rw-r-- 1 jrs jrs 477197 Nov 24 23:15 a.out.js -rw-rw-r-- 1 jrs jrs 75 Nov 24 23:13 hello_world.c jrs@laptop:~/ems/test$
|
|
|
Post by Pjot on Nov 25, 2015 20:04:49 GMT 1
Hi John,
This is interesting indeed. I will check it out!
Thanks Peter
|
|
|
Post by Pjot on Nov 25, 2015 22:38:49 GMT 1
Well, it works, sort of. Consider the following BaCon fractal program: OPTION VARTYPE double '------------------------------------------------------------------------------ k=1:FOR y=-16 TO 15:FOR x=0 TO 78:PRINT CHR$(((int)k&15)+32);:m=r=0:FOR k=0 TO 111 j=r*r-m*m-2+x/25:m=2*r*m+y/10:r=j:IF j*j+m*m>11 THEN BREAK:NEXT:NEXT:PRINT:NEXT '------------------------------------------------------------------------------
The emcc compiler needs its version of libbacon.a so bacon must generate it first, also using the emcc compiler: We can ignore the warning about 'ldl' for now. The file 'libbacon.a' is generated and that is what we need. Also the C source files for the fractal program are there. Now we compile using emcc directly: The result is redirected to an HTML file which shows the result. So console based programs seems to work. For OpenGL, more work is needed as the API calls must be ported to WebGL or GL ES... BR Peter
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 26, 2015 3:56:17 GMT 1
Great news Peter!
Building and running the test suite was a 1/2 day adventure. I slept through the test suite part but everything passed.
Ran 3408 tests in 26329.577s
OK
7 + hours for the test run alone. Building this monster took at least a couple hours.
It is so cool to hear it works with BaCon.
|
|
mattw
New Member
Posts: 3
|
Post by mattw on Jun 10, 2018 23:40:52 GMT 1
Hey all, I came upon this thread after Googling to confirm my own suspicions of using BaCon to generate C as an intermediary for web development using Emscripten/wasm. I put together a GitHub repository with all the files you need to get started using BaCon/BASIC to write programs for the web. You can find it at this link: github.com/matthewwiese/basic-to-c-wasm-exampleThe BASIC code simply brute forces all primes up to 1000; upon finding a prime it "prints" to stdout. Then, the HTML shiv retrieves that output and appends each new number to the page. Quite simple once put together but it took a bit of head scratching last night to find all the missing pieces. Many thanks to Pjot for his post in this thread with the specific command line arguments needed. That was my saving grace! Below is the BASIC code: FOR i = 0 TO 1000
factors = 0
FOR q = 1 TO i
IF MOD(i, q) = 0 THEN
INCR factors
ENDIF
NEXT
IF factors = 2 THEN
PRINT i
ENDIF
NEXT And here's the HTML: <html>
<body>
<h1>BASIC -> C -> -> WebAssembly/JavaScript</h1>
<h2>Using <i>BaCon</i> and <i>Emscripten</i></h2>
<h3>Find prime numbers up to 1000:</h3>
<p id="output" />
<script>
var Module = {
print: (function() {
var element = document.getElementById('output');
return function(text) {
element.innerHTML += text + "<br>";
};
})(),
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
if (0) {
dump(text + '\n');
}
},
canvas: (function() {
var canvas = document.getElementById('canvas');
return canvas;
})()
};
</script>
<script src="primefac.js"></script>
</body>
</html>
|
|