Skip to content

Commit

Permalink
fbc/emscripten: allow wchar conversion on win32 for development
Browse files Browse the repository at this point in the history
- add 'enum FB_WCHARCONV'
- replace 'env.wchar_doconv' with 'env.wcharconv as FB_WCHARCONV'
- when compiler is built with __FB_DEBUG__<>0 then allow wstring conversions
  even though the host wchar size and target wchar size are different
- purpose of this is to allow some building and testing with the test-suite
  on a win32 host while also not having deal with all unicode/wchar issues
  • Loading branch information
jayrm committed Jul 29, 2023
1 parent c9fcb5d commit 16b8e94
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.txt
@@ -1,6 +1,7 @@
Version 1.10.1

[changed]
- emscripten/fbc: in debug version of fbc (__FB_DEBUG__<>0) allow wchar conversion on win32 host to allow building and testing of the test-suite

[added]
- fbc: '-fbgfx' command line option to link against correct libfbgfx variant, for platforms (emscripten) where it's not automatic due to missing objinfo support
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ast-node-bop.bas
Expand Up @@ -869,7 +869,7 @@ function astNewBOP _
if( litsym <> NULL ) then
'' ok to convert at compile-time?
if( (typeGetDtAndPtrOnly( ldtype ) = typeGetDtAndPtrOnly( rdtype )) or _
env.wchar_doconv ) then
(env.wcharconv <> FB_WCHARCONV_NEVER) ) then
return hWstrLiteralConcat( l, r )
end if
end if
Expand Down
17 changes: 16 additions & 1 deletion src/compiler/fb.bas
Expand Up @@ -474,7 +474,22 @@ sub fbInit _
irInit( )

'' After symbInit(), we can use typeGetSize()
env.wchar_doconv = (sizeof( wstring ) = typeGetSize( env.target.wchar ))
if( sizeof( wstring ) = typeGetSize( env.target.wchar ) ) then
env.wcharconv = FB_WCHARCONV_ALWAYS
else
env.wcharconv = FB_WCHARCONV_NEVER
end if

#if ( __FB_DEBUG__ <> 0 ) andalso defined( __FB_WIN32__ )
select case( env.clopt.target )
case FB_COMPTARGET_JS
'' !!!TODO!!! - FB_WCHARCONV_WARNING needs to show warnings on conversions
'' !!!TODO!!! - FB_WCHARCONV_WARNING probably not correct to force a value
'' but setting it helps with development and testing
'' where sizeof(host-wstring) <> sizeof(target-wstring)
env.wcharconv = FB_WCHARCONV_WARNING
end select
#endif

hashInit( @env.filenamehash, FB_INITINCFILES )
hashInit( @env.incfilehash, FB_INITINCFILES, FALSE )
Expand Down
8 changes: 7 additions & 1 deletion src/compiler/fbint.bi
Expand Up @@ -571,6 +571,12 @@ enum FB_TARGETOPT
FB_TARGETOPT_MACHO = &h00000200
end enum

enum FB_WCHARCONV
FB_WCHARCONV_NEVER = 0
FB_WCHARCONV_WARNING = 1
FB_WCHARCONV_ALWAYS = 2
end enum

type FBTARGET
id as zstring ptr
wchar as FB_DATATYPE '' Real wstring data type
Expand Down Expand Up @@ -614,7 +620,7 @@ type FBENV

clopt as FBCMMLINEOPT '' cmm-line options
target as FBTARGET '' target specific
wchar_doconv as integer '' ok to convert literals at compile-time?
wcharconv as FB_WCHARCONV '' ok to convert literals at compile-time?
underscoreprefix as integer '' Whether ASM symbols need a leading underscore on the current target
pointersize as integer

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parser-quirk-string.bas
Expand Up @@ -288,7 +288,7 @@ private function cStrASC() as ASTNODE ptr
if( litsym <> NULL ) then
'' if wstring, check if compile-time conversion can be done
if( (astGetDataType( expr1 ) = FB_DATATYPE_WCHAR) and _
(env.wchar_doconv = FALSE) ) then
(env.wcharconv = FB_WCHARCONV_NEVER) ) then
p = -1
else
'' pos is an constant too?
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/rtl-string.bas
Expand Up @@ -2873,9 +2873,9 @@ function rtlToStr _
if( dtype = FB_DATATYPE_WCHAR ) then
litsym = astGetStrLitSymbol( expr )
if( litsym <> NULL ) then
if( env.wchar_doconv ) then
if( env.wcharconv <> FB_WCHARCONV_NEVER ) then
litsym = symbAllocStrConst( str( *symbGetVarLitTextW( litsym ) ), _
symbGetWstrLen( litsym ) - 1 )
symbGetWstrLen( litsym ) - 1 )

return astNewVAR( litsym )
end if
Expand Down Expand Up @@ -2978,9 +2978,9 @@ function rtlToWstr _
if( dtype = FB_DATATYPE_CHAR ) then
litsym = astGetStrLitSymbol( expr )
if( litsym <> NULL ) then
if( env.wchar_doconv ) then
if( env.wcharconv <> FB_WCHARCONV_NEVER ) then
litsym = symbAllocWstrConst( wstr( *symbGetVarLitText( litsym ) ), _
symbGetStrLen( litsym ) - 1 )
symbGetStrLen( litsym ) - 1 )
return astNewVAR( litsym )
end if
end if
Expand Down

0 comments on commit 16b8e94

Please sign in to comment.