What happened to the Emscripten branch?

For other topics related to the FreeBASIC project or its community.
VANYA
Posts: 1411
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Postby VANYA » Nov 21, 2020 10:27

This is the result I get:

fbcE -target js-asmjs FBFILE.bas -c -v
FreeBASIC Compiler - Version 1.08.0 (2020-11-21), built for linux-x86_64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
target: js-asmjs, asmjs, 32bit (js-asmjs)
backend: gcc
compiling: FBFILE.bas -o FBFILE.c
compiling C: emcc -c -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-warn-absolute-paths -s ASYNCIFY=1 -s RETAIN_COMPILER_SETTINGS=1 -Wno-main -Werror-implicit-function-declaration -fno-strict-aliasing -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-format "FBFILE.c" -o "FBFILE.o"


And then nothing happens (hanging , CPU core load 100%)
angros47
Posts: 1755
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Postby angros47 » Nov 21, 2020 10:47

All I can suggest is: try "splitting" your program in several parts, deleting different blocks of lines every time, to see if there is a specific line that causes the fail

For example, if you compile just few lines using Cyrillic alphabets, does that cause issue or not?
VANYA
Posts: 1411
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Postby VANYA » Nov 21, 2020 11:52

I apologize. It turns out nothing hangs, but it's just a workflow! The compilation speed of this code (500 lines) takes EMCC only 5 minutes :) And this is on a relatively fast processor with a full load of one core :) I am afraid to imagine if I would compile the code under a pentium I processor. The FB compiler does its job in a split second, and EMCC spends the rest of the time. I'm just shocked. Ultimately, however, the work gets done.
angros47
Posts: 1755
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Postby angros47 » Nov 21, 2020 12:57

Nice!

But now, please, can you tell me what that program was supposed to do? I didn't even try to understand that messy source, and the texts are in Russian.
VANYA
Posts: 1411
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Postby VANYA » Nov 21, 2020 13:23

angros47 wrote:Nice!

But now, please, can you tell me what that program was supposed to do? I didn't even try to understand that messy source, and the texts are in Russian.


This is a textual economic strategy, the goal of which is for an ordinary person who has arrived in the country to earn money, status, and, as the final result, become a president.

--------------

Unfortunately, the program is compiled only in synchronous mode. But it is not possible to play with this mode. When using "-s ASYNCIFY = 1", I get incomprehensible compilation errors:

warning: too many locals (862970) to run liveness analysis in 2
wasm-opt: /b/s/w/ir/cache/builder/emscripten-releases/binaryen/src/cfg/liveness-traversal.h:193: void wasm::LivenessWalker<RelevantLiveLocalsWalker, wasm::Visitor<RelevantLiveLocalsWalker, void>>::doWalkFunction(wasm::Function *) [SubType = RelevantLiveLocalsWalker, VisitorType = wasm::Visitor<RelevantLiveLocalsWalker, void>]: Assertion `canRun(func)' failed.
emcc: error: '/home/haav/emc/emsdk/upstream/bin/wasm-opt --strip-dwarf --asyncify --pass-arg=asyncify-asserts --pass-arg=asyncify-imports@env.invoke_*,env.emscripten_sleep,env.emscripten_wget,env.emscripten_wget_data,env.emscripten_idb_load,env.emscripten_idb_store,env.emscripten_idb_delete,env.emscripten_idb_exists,env.emscripten_idb_load_blob,env.emscripten_idb_store_blob,env.SDL_Delay,env.emscripten_scan_registers,env.emscripten_lazy_load_code,env.emscripten_fiber_swap,wasi_snapshot_preview1.fd_sync,env.__wasi_fd_sync,env._emval_await --strip-debug --strip-producers FBFILE.wasm -o FBFILE.wasm --mvp-features' failed (-6)


Okay ... negative result is also a result. The experience is still interesting.
angros47
Posts: 1755
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Postby angros47 » Nov 21, 2020 16:12

Those errors come from emscripten, not from FreeBasic (the -ASYNCIFY parameter affects the linker, not the compiler), so I am unable to tell you what is going on.

Anyway, your program could not work without changes, with the current form of the compiler: if contains some INPUT commands, so it would need the ASYNC mode to work (and would work only in graphic mode, not in text more, and as you can clearly see it doesn't contain any SCREEN instruction)

Also, in graphic mode as far as I know there is no Cyrillic font.

Last but not least: I have always been pro retro-compatibility, but... come on: do you seriously expect to compile a software for ZX Spectrum without changes? Or you experimented with it because you just wanted to push the compiler to its limits?
VANYA
Posts: 1411
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Postby VANYA » Nov 21, 2020 17:10

angros47 wrote:Anyway, your program could not work without changes, with the current form of the compiler: if contains some INPUT commands, so it would need the ASYNC mode to work (and would work only in graphic mode, not in text more, and as you can clearly see it doesn't contain any SCREEN instruction)


Of course, I compiled, having previously written the command in the code Screen

Also, in graphic mode as far as I know there is no Cyrillic font.


This is not a problem, there is a library that replaces symbols (ALBOM_FONT). As a last resort, you can use draw string with your own font.

Last but not least: I have always been pro retro-compatibility, but... come on: do you seriously expect to compile a software for ZX Spectrum without changes? Or you experimented with it because you just wanted to push the compiler to its limits?


Exactly!!! I always try to find the limits of possibilities when testing. After all, in work situations, it never happens that everything goes smoothly. So far I have made at least three conclusions when working with fbc-emscripten:

1) You can forget about outdated modes. Use only "FB" mode
2) You can forget about ASM inserts
3) The code should be written as simple as possible in a procedural style (without any classes, inheritance, polymorphism, etc.)

For the future, I want to check how the sound works (it seems like emscripten supports OpenAL). I haven't figured it out yet, but it's in the plans.
angros47
Posts: 1755
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Postby angros47 » Nov 21, 2020 18:15

I'd say this: C is a structured language. FreeBasic compiler can take a structured basic code, and emit a perfectly working C code. It can also take a spaghetti-code basic source, and with some efforts, manages to emit a C code that still works. It is not optimal, but more or less it still works (and that's why by default it is not enabled, you have to explicitly set lang qb)

Javascript is an event driven language: Emscripten can take an event driven code written in C (even from a FreeBasic source) and emit a perfectly working Javascript code. It can also take a procedural program, and with some efforts, manages to emit a Javascript code that still works. Again, it is not optimal, but still works (and that's why by default it's not enabled, and you have to explicitly set with ASYNCIFY)

I guess that trying to convert a basic code to C in sub-optimal way (with lang QB), then convert the resulting code to Javascript in another sub-optimal way, and expecting everything to work seamlessly is asking too much
VANYA
Posts: 1411
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Postby VANYA » Nov 21, 2020 19:11

I guess that trying to convert a basic code to C in sub-optimal way (with lang QB), then convert the resulting code to Javascript in another sub-optimal way, and expecting everything to work seamlessly is asking too much


angros47!
Well, of course you are right, but I wanted to try :)
I am not belittling fbc-emscripten in any way. In fact, the developers of emscripten, as well as v1ctor and you have done a very good job. Even in this state, it is a great tool. And now, if I think to write something, I will keep in mind that it is necessary to compose the code with an eye on the WEB.
angros47
Posts: 1755
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Postby angros47 » Nov 21, 2020 21:52

Actually, your tests have been pretty useful, you helped me finding some issues much faster!

If you manage to get other games to work on it, try publishing them, they might even attract new people to FreeBasic.
VANYA
Posts: 1411
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Postby VANYA » Nov 22, 2020 8:00

Ported another games:

GameWord WEB
GameWord PC (description, rules)

Don't be intimidated by the Russian words on the bottom line, these are just templates to collect. Knowledge of the Russian language is not required!

**********************************************

Mancala WEB
Mancala PC
VANYA
Posts: 1411
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Postby VANYA » Nov 23, 2020 3:24

I tried opengl examples, but unfortunately an error occurs:

wasm-ld: error: unable to find library -lGLU


I don't know where to get it. The system already has OpenGL, and the examples run if compiled without -target js-asmjs. I also tried OpenAL sound, compiling C source codes. Everything compiles, but there is no sound in the browser. How complicated everything is.
angros47
Posts: 1755
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Postby angros47 » Nov 23, 2020 9:27

Emscripten does support OpenGL through SDL, so it is surely possible to use it (I know because I managed to compile and use OpenB3D with it), but the context creation is different.

Also, although Emscripten could compile classic OpenGL 1 programs, that is explicitly not recommended, because the browser does not support OpenGL, it supports WebGL (that is more similar to OpenGL ES). Classic OpenGL is emulated on top of it, and not optimal. (I warn you, OpenGL ES is pretty different to use)
VANYA
Posts: 1411
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: What happened to the Emscripten branch?

Postby VANYA » Nov 23, 2020 15:53

angros47 wrote:Emscripten does support OpenGL through SDL, so it is surely possible to use it (I know because I managed to compile and use OpenB3D with it), but the context creation is different.

Also, although Emscripten could compile classic OpenGL 1 programs, that is explicitly not recommended, because the browser does not support OpenGL, it supports WebGL (that is more similar to OpenGL ES). Classic OpenGL is emulated on top of it, and not optimal. (I warn you, OpenGL ES is pretty different to use)


Then I'd better stay on fbgfx :)
angros47
Posts: 1755
Joined: Jun 21, 2005 19:04

Re: What happened to the Emscripten branch?

Postby angros47 » Nov 23, 2020 19:43

I hope to add OpenGL support to fbGfx

Anyway, a better input in terminal mode:

in the directory src/rtlib/js, the file io_isredir.c should be:

Code: Select all

#include "../fb.h"

int fb_ConsoleIsRedirected( int is_input )
{
   return FB_FALSE;
}

(just changed to FALSE)

The file io_readstr.c should become:

Code: Select all

/* console line input function */

#include "../fb.h"
#include "fb_private_console.h"


char *fb_ConsoleReadStr( char *buffer, ssize_t len )
{
   EM_ASM_ARGS({
      var jsString = __fb_rtlib.console.input();
      jsString+='\n';
      stringToUTF8(jsString, $0, $1);
   }, buffer, len );


   return buffer;

   //return fgets( buffer, len, stdin );
}


The file fb_rtlib.js (there are two copies, one in /lib and one in lib/freebasic/js-asmjs/ , and they both need to be updated) needs to add, after the WriteSub part, a new section:


Code: Select all

      writeSubs: function(text, len)
      {
         this.write(text.substr(0, len));
      },

      input: function()
      {
         var t=prompt();
         this.write(t+"\n");
         return t;
      },



The INPUT command will work a bit better in terminal mode (unfortunately, it still needs that annoying popup windows: it is the only way to have it to work even when ASYNCIFY is not enabled)

I wonder if CoderJeff will want to add some more of my patches to github

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 11 guests