What happened to the Emscripten branch?
Re: What happened to the Emscripten branch?
I have read that workers in JavaScript can be used only with an HTTPS connection, with SSL certificates. Since threads require the use of workers, under Emscripten, that could be the reason why it doesn't work
Re: What happened to the Emscripten branch?
Hi all!
I decided to change one program. I assembled it without errors, but got an exception in the browser. In the console the following:
I build it like this: fbc -target js-asmjs mancala.bas -Wl "-s ASYNCIFY=1" -Wl --preload-file,res
Previously, I compiled on compiler 1.07 or 1.08 (the compiler compiled itself from source codes, as recommended by Victor in the 2015 year) and there were no such problems.
What could be wrong?
I decided to change one program. I assembled it without errors, but got an exception in the browser. In the console the following:
This program: https://users.freebasic-portal.de/freeb ... ncala.htmlGET
http://localhost:8000/favicon.ico
[HTTP/1 404 File not found 0ms]
wasm streaming compile failed: TypeError: WebAssembly: Response has unsupported MIME type 'application/octet-stream' expected 'application/wasm' mancala.html:138:19
printErr http://localhost:8000/mancala.html:138
instantiateAsync http://localhost:8000/mancala.js:1775
(Asynchronous: promise callback)
instantiateAsync http://localhost:8000/mancala.js:1772
(Asynchronous: promise callback)
instantiateAsync http://localhost:8000/mancala.js:1770
createWasm http://localhost:8000/mancala.js:1798
<anonymous> http://localhost:8000/mancala.js:7508
falling back to ArrayBuffer instantiation mancala.html:138:19
printErr http://localhost:8000/mancala.html:138
instantiateAsync http://localhost:8000/mancala.js:1776
(Asynchronous: promise callback)
instantiateAsync http://localhost:8000/mancala.js:1772
(Asynchronous: promise callback)
instantiateAsync http://localhost:8000/mancala.js:1770
createWasm http://localhost:8000/mancala.js:1798
<anonymous> http://localhost:8000/mancala.js:7508
..........
Uncaught RuntimeError: index out of bounds
x http://localhost:8000/mancala.js:7241
handleSleep http://localhost:8000/mancala.js:7326
safeSetTimeout http://localhost:8000/mancala.js:4719
setTimeout handler*safeSetTimeout http://localhost:8000/mancala.js:4716
_emscripten_sleep http://localhost:8000/mancala.js:7040
handleSleep http://localhost:8000/mancala.js:7305
_emscripten_sleep http://localhost:8000/mancala.js:7039
x http://localhost:8000/mancala.js:7217
x http://localhost:8000/mancala.js:7241
handleSleep http://localhost:8000/mancala.js:7326
safeSetTimeout http://localhost:8000/mancala.js:4719
setTimeout handler*safeSetTimeout http://localhost:8000/mancala.js:4716
_emscripten_sleep http://localhost:8000/mancala.js:7040
handleSleep http://localhost:8000/mancala.js:7305
_emscripten_sleep http://localhost:8000/mancala.js:7039
x http://localhost:8000/mancala.js:7217
x http://localhost:8000/mancala.js:7241
handleSleep http://localhost:8000/mancala.js:7326
safeSetTimeout http://localhost:8000/mancala.js:4719
setTimeout handler*safeSetTimeout http://localhost:8000/mancala.js:4716
_emscripten_sleep http://localhost:8000/mancala.js:7040
handleSleep http://localhost:8000/mancala.js:7305
_emscripten_sleep http://localhost:8000/mancala.js:7039
x http://localhost:8000/mancala.js:7217
x http://localhost:8000/mancala.js:7241
handleSleep http://localhost:8000/mancala.js:7326
safeSetTimeout http://localhost:8000/mancala.js:4719
setTimeout handler*safeSetTimeout http://localhost:8000/mancala.js:4716
_emscripten_sleep http://localhost:8000/mancala.js:7040
handleSleep http://localhost:8000/mancala.js:7305
_emscripten_sleep http://localhost:8000/mancala.js:7039
x http://localhost:8000/mancala.js:7217
x http://localhost:8000/mancala.js:7241
handleSleep http://localhost:8000/mancala.js:7326
safeSetTimeout http://localhost:8000/mancala.js:4719
setTimeout handler*safeSetTimeout http://localhost:8000/mancala.js:4716
_emscripten_sleep http://localhost:8000/mancala.js:7040
I build it like this: fbc -target js-asmjs mancala.bas -Wl "-s ASYNCIFY=1" -Wl --preload-file,res
Previously, I compiled on compiler 1.07 or 1.08 (the compiler compiled itself from source codes, as recommended by Victor in the 2015 year) and there were no such problems.
What could be wrong?
Re: What happened to the Emscripten branch?
The problem is with the array index, which for some reason seems to be out of bounds. But I looked at the code bas and it seems to me that everything is fine there. Could there be an error in the conversion to Emscripten code?
Re: What happened to the Emscripten branch?
I don't know what's the matter. But it doesn't work like this:
And this is how it works:
There is some problem in the compiler.
Code: Select all
For i As Long = 0 To 5
s = Str(bDimMancala(i+1).bValue)
Var s2 = Str(bDimMancala(13-i).bValue)
....
Next
Code: Select all
For i As Long = 0 To 5
dim as long iOffset1 , iOffset2
iOffset1 = i+1
iOffset2 = 13 - i
s = Str(bDimMancala(iOffset1).bValue)
Var s2 = Str(bDimMancala(iOffset2).bValue)
....
Next
Re: What happened to the Emscripten branch?
Where is the file mancala.bas? In the archive I found only the files mancala(32-bit).bas and mancala(64-bit).bas , and they both are unusable, since they contain some ASM code.
Also, can you still compile it if you use an older version of FreeBasic? Because I wonder if the change happened in FreeBasic or in Emscripten
Also, can you still compile it if you use an older version of FreeBasic? Because I wonder if the change happened in FreeBasic or in Emscripten
Re: What happened to the Emscripten branch?
Everything worked well with the version that was not yet built into the official compiler. That is, the Victor version, but corrected by you.angros47 wrote: ↑Sep 18, 2023 17:39 Where is the file mancala.bas? In the archive I found only the files mancala(32-bit).bas and mancala(64-bit).bas , and they both are unusable, since they contain some ASM code.
Also, can you still compile it if you use an older version of FreeBasic? Because I wonder if the change happened in FreeBasic or in Emscripten
https://dropmefiles.com/2FaWOWhere is the file mancala.bas? In the archive I found only the files mancala(32-bit).bas and mancala(64-bit).bas , and they both are unusable, since they contain some ASM code.
Procedure DrawNumbers() , lines starting with 261 (loop). It's already fixed there, but you can return the error, as I indicated in my last post.
It looks like the compiler is incorrectly calculating the offset in parentheses for the Emscripten backend.
This is incorrect:
Code: Select all
bDimMancala(13-i).bValue
Code: Select all
dim as long iOffset2
iOffset2 = 13 - i
bDimMancala(iOffset2).bValue
Re: What happened to the Emscripten branch?
That's strange: I changed the code from:
to:
Indeed it crashes on the start, but I compared the C files, and this is the diff file:
Basically, the code is equivalent, and some minor variables have changed number, nothing more. Original C file uses:
the not working one uses:
They should be perfectly equivalent
Code: Select all
iOffset1 = i+1
iOffset2 = 13 - i
s = Str(bDimMancala(iOffset1).bValue)
Var s2 = Str(bDimMancala(iOffset2).bValue)
Code: Select all
iOffset1 = i+1
iOffset2 = 13 - i
s = Str(bDimMancala(i+1).bValue)
Var s2 = Str(bDimMancala(13-i).bValue)
Code: Select all
298c298
< FBSTRING* vr$26 = fb_IntToStr( (int32)*(int8*)(((int64)(struct $8TMANCALA*)BDIMMANCALA$ + ((int64)I$2 * 49ll)) + 49ll) );
---
> FBSTRING* vr$26 = fb_IntToStr( (int32)*(int8*)((int64)(struct $8TMANCALA*)BDIMMANCALA$ + ((int64)IOFFSET1$3 * 49ll)) );
301,304c301,304
< FBSTRING* vr$32 = fb_IntToStr( (int32)*(int8*)(((int64)(struct $8TMANCALA*)BDIMMANCALA$ + (-(int64)I$2 * 49ll)) + 637ll) );
< fb_StrInit( (void*)&S2$3, -1ll, (void*)vr$32, -1ll, 0 );
< int64 vr$35 = fb_StrLen( (void*)&S$1, -1ll );
< if( vr$35 != 2ll ) goto label$51;
---
> FBSTRING* vr$31 = fb_IntToStr( (int32)*(int8*)((int64)(struct $8TMANCALA*)BDIMMANCALA$ + ((int64)IOFFSET2$3 * 49ll)) );
> fb_StrInit( (void*)&S2$3, -1ll, (void*)vr$31, -1ll, 0 );
> int64 vr$34 = fb_StrLen( (void*)&S$1, -1ll );
> if( vr$34 != 2ll ) goto label$51;
314,315c314,315
< int64 vr$47 = fb_StrLen( (void*)&S2$3, -1ll );
< if( vr$47 != 2ll ) goto label$53;
---
> int64 vr$46 = fb_StrLen( (void*)&S2$3, -1ll );
> if( vr$46 != 2ll ) goto label$53;
Code: Select all
IOFFSET1$3 = (int32)((int64)I$2 + 1ll);
IOFFSET2$3 = (int32)(-(int64)I$2 + 13ll);
FBSTRING* vr$26 = fb_IntToStr( (int32)*(int8*)((int64)(struct $8TMANCALA*)BDIMMANCALA$ + ((int64)IOFFSET1$3 * 49ll)) );
fb_StrAssign( (void*)&S$1, -1ll, (void*)vr$26, -1ll, 0 );
FBSTRING S2$3;
FBSTRING* vr$31 = fb_IntToStr( (int32)*(int8*)((int64)(struct $8TMANCALA*)BDIMMANCALA$ + ((int64)IOFFSET2$3 * 49ll)) );
Code: Select all
IOFFSET1$3 = (int32)((int64)I$2 + 1ll);
IOFFSET2$3 = (int32)(-(int64)I$2 + 13ll);
FBSTRING* vr$26 = fb_IntToStr( (int32)*(int8*)(((int64)(struct $8TMANCALA*)BDIMMANCALA$ + ((int64)I$2 * 49ll)) + 49ll) );
fb_StrAssign( (void*)&S$1, -1ll, (void*)vr$26, -1ll, 0 );
FBSTRING S2$3;
FBSTRING* vr$32 = fb_IntToStr( (int32)*(int8*)(((int64)(struct $8TMANCALA*)BDIMMANCALA$ + (-(int64)I$2 * 49ll)) + 637ll) );
Re: What happened to the Emscripten branch?
If you compile under a regular gcc backend, the compiler first forcibly creates a temporary variable in which it performs the calculation in parentheses. And then this variable is placed in brackets. But for the Emscripten backend, the compiler does not do this and substitutes numbers. Perhaps this is the problem.
Also, I noticed that it is impossible to compile Emscripten backend with the -exx option, errors appear. Is this how it should be?
Also, I noticed that it is impossible to compile Emscripten backend with the -exx option, errors appear. Is this how it should be?
-
- Posts: 719
- Joined: Jul 26, 2018 18:28
Re: What happened to the Emscripten branch?
I also found a bug regarding WString size in WASM. In WASM, the size of WString must be twice as large as in Windows. Otherwise the text in the variable will be damaged. So I decided to do this in my library:
Code: Select all
#ifdef __USE_WASM__
#define GrowLength 2
#else
#define GrowLength 1
#endif
m_BytesCount = (m_Length + 1) * SizeOf(WString) * GrowLength
clang does not support getting the address of line numbers. That is, commands like Resume Next will not work.
Re: What happened to the Emscripten branch?
I don't know why, since it seems legit C syntaxVANYA wrote: ↑Sep 20, 2023 3:42 If you compile under a regular gcc backend, the compiler first forcibly creates a temporary variable in which it performs the calculation in parentheses. And then this variable is placed in brackets. But for the Emscripten backend, the compiler does not do this and substitutes numbers. Perhaps this is the problem.
Also, I have a question: does the INPUT work in graphic mode, compiled with ASYNCIFY? In the old version, I saw it asked something before starting, and now it doesn't...
Re: What happened to the Emscripten branch?
Thank you for the clarification!Xusinboy Bekchanov wrote: ↑Sep 20, 2023 7:15 clang does not support getting the address of line numbers. That is, commands like Resume Next will not work.
work.Also, I have a question: does the INPUT work in graphic mode, compiled with ASYNCIFY?
Here is a minimal example that leads to an exception:I don't know why, since it seems legit C syntax
Code: Select all
ScreenRes 792,400,32,2
Dim Shared As long bDimMancala(13)
Sub DrawNumbers()
For i As Long = 0 To 5
bDimMancala(13 - i) = i
next
End Sub
DrawNumbers()
Re: What happened to the Emscripten branch?
I can see that:
produces exception, while:
works fine. So, it affects only shared arrays...
Code: Select all
Dim shared As long bDimMancala(13)
Sub DrawNumbers()
For i As Long = 0 To 5
bDimMancala(13 - i) = i
next
End Sub
DrawNumbers()
Code: Select all
Sub DrawNumbers()
Dim As long bDimMancala(13)
For i As Long = 0 To 5
bDimMancala(13 - i) = i
next
End Sub
DrawNumbers()
Re: What happened to the Emscripten branch?
Ok, now I have found a minimal code written in C to trigger the issue:
This code:
compiled with "emcc bug.c -o bug.html" works flawlessly
that should be equivalent (the only difference is that the array is shared) crashes. Can you confirm it?
This code:
Code: Select all
int main(){
int arr[13];
for (int i=0;i<=5;i++){
*(int*)(((int)(int*)arr + (-i << (2 & 31))) + 52) = i;
}
}
Code: Select all
int arr[13];
int main(){
for (int i=0;i<=5;i++){
*(int*)(((int)(int*)arr + (-i << (2 & 31))) + 52) = i;
}
}
Re: What happened to the Emscripten branch?
Those write out of bounds on the first loop (arr + 52 writes to arr[13]). If it still happens with +48 instead of +52 then that's a worry.
Re: What happened to the Emscripten branch?
yes.that should be equivalent (the only difference is that the array is shared) crashes. Can you confirm it?