Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fbc-1.08' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrm committed Jun 19, 2021
2 parents 622443c + 28d7adb commit 146862f
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 21 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ Version 1.09.0

[changed]
- github #314: fbc: pass '-T scriptfile' option to linker LD and add 'INSERT AFTER .data;' to fbextra.x linker script to quiet warning on LD version 2.36 and higher
- gas64: .a64 replaced by .asm to be coherent with documentation

[added]

[fixed]
- github #315: set parameters when calling SCREENCONTROL (was broken in fbc 1.08.0 due to new LONG/LONGINT SCREENCONTROL API's)
- github #318: duplicate definition for deleting destructor; the deleting destructor was being emitted even though the class was declarations only on the fbc side
- github #320: oGLfbGFX: scaling set by SCREENCONTROL not used when initializing opengl unix driver
- github #321: __FB_ARG_EXTRACT__ incorrectly recognizes commas nested in other forms with variadic macros - internally use new hlp-str.bas:hStr2Args() procedure


Version 1.08.0
Expand Down
197 changes: 179 additions & 18 deletions src/compiler/hlp-str.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1304,18 +1304,18 @@ end sub
'':::::
function hStr2Tok(byval txt as const zstring ptr, res() as string) as integer

var t = 0
var lc = 32UL
var s = cast(const ubyte ptr, txt)
do while( *s <> 0 )
var c = cast(uinteger, *s)
dim as integer t = 0
dim as uinteger lc = CHAR_SPACE
dim as const ubyte ptr s = cast(const ubyte ptr, txt)
do while( *s <> CHAR_NULL )
dim as uinteger c = cast(uinteger, *s)

if( c = 7 ) then
c = 32
if( c = CHAR_BELL ) then
c = CHAR_SPACE
end if

if( c = 32 ) then
if( lc <> 32 ) then
if( c = CHAR_SPACE ) then
if( lc <> CHAR_SPACE ) then
t += 1
end if
end if
Expand All @@ -1324,7 +1324,7 @@ function hStr2Tok(byval txt as const zstring ptr, res() as string) as integer
s += 1
loop

if( lc <> 32 ) then
if( lc <> CHAR_SPACE ) then
t += 1
end if

Expand All @@ -1335,17 +1335,17 @@ function hStr2Tok(byval txt as const zstring ptr, res() as string) as integer
redim res(0 to t-1)

t = 0
lc = 32
lc = CHAR_SPACE
s = cast(const ubyte ptr, txt)
do while( *s <> 0 )
do while( *s <> CHAR_NULL )
var c = cast(uinteger, *s)

if( c = 7 ) then
c = 32
if( c = CHAR_BELL ) then
c = CHAR_SPACE
end if

if( c = 32 ) then
if( lc <> 32 ) then
if( c = CHAR_SPACE ) then
if( lc <> CHAR_SPACE ) then
t += 1
end if
else
Expand All @@ -1356,6 +1356,167 @@ function hStr2Tok(byval txt as const zstring ptr, res() as string) as integer
s += 1
loop

function = iif(lc <> 32, t + 1, t)
function = iif(lc <> CHAR_SPACE, t + 1, t)

end function
end function

'':::::
function hStr2args( byval txt as const zstring ptr, res() as string ) as integer

'' !!! TODO !! add the wstring version

dim as integer t = 0
dim as const ubyte ptr s = cast(const ubyte ptr, txt)
dim as integer prntcnt = 0
dim as uinteger c = CHAR_NULL
dim as integer max_t = 10

#define PeekChar() cast( uinteger, s[0] )
#define SkipChar() s += 1
#define ReadChar(c) res(t-1) += chr(c) : s += 1

redim res( 0 to max_t-1 ) as string

do
c = PeekChar()
if (c = CHAR_TAB) or (c = CHAR_SPACE) then
SkipChar()
else
exit do
end if
loop

'' no arguments?
if( c = CHAR_NULL ) then
return 0
end if

'' ok, there's at least one argument
t += 1

'' scan for arguments
do
c = PeekChar()
select case c
case CHAR_NULL
exit do

case CHAR_LPRNT
prntcnt += 1

case CHAR_RPRNT
if( prntcnt > 0 ) then
prntcnt -= 1
end if

case CHAR_COMMA
if( prntcnt = 0 ) then
t += 1
if( t > max_t ) then
max_t += 10
redim preserve res( 0 to max_t - 1 )
end if
SkipChar()
continue do
end if

case CHAR_QUOTE, CHAR_EXCL, CHAR_DOLAR
dim as integer escaped = env.opt.escapestr
if( c <> CHAR_QUOTE ) then
escaped = ( c = CHAR_EXCL )

'' '!' | '$'
ReadChar(c)
c = PeekChar()
if( c <> CHAR_QUOTE ) then
continue do
end if

end if

'' '"'
ReadChar(c)

do
c = PeekChar()
if( c = CHAR_NULL ) then
exit do
end if

'' '"' | '\\' | any other string char
ReadChar(c)
if( c = CHAR_QUOTE ) then

c = PeekChar()
if( c <> CHAR_QUOTE ) then
exit do
end if

'' '"'
ReadChar(c)

elseif( c = CHAR_RSLASH ) then

c = PeekChar()
select case c
case CHAR_QUOTE, CHAR_RSLASH
'' '"' | '\\'
ReadChar(c)
end select

end if
loop
continue do

case CHAR_SLASH

'' '/'
ReadChar(c)

c = PeekChar()
if( c <> CHAR_APOST ) then
continue do
end if

'' '''
ReadChar(c)

do
c = PeekChar()
if( c = CHAR_NULL ) then
exit do
end if

'' ''' | any other comment char
ReadChar(c)

if( c = CHAR_APOST ) then
c = PeekChar()
if( c = CHAR_SLASH ) then
'' '/'
ReadChar(c)
exit do
end if
end if

loop
continue do

case CHAR_APOST
while( c <> CHAR_NULL )
'' ''' or any comment char to end of line
ReadChar(c)
c = PeekChar()
wend
exit do

end select

'' any other char not handled above
ReadChar(c)

loop

function = t

end function
2 changes: 2 additions & 0 deletions src/compiler/hlp-str.bi
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ declare sub hSplitStr(byref txt as string, byref del as string, res() as string)

declare function hStr2Tok(byval txt as const zstring ptr, res() as string) as integer

declare function hStr2Args(byval txt as const zstring ptr, res() as string) as integer

'':::::
#define ZstrAllocate(chars) xallocate( chars + 1 )

Expand Down
6 changes: 4 additions & 2 deletions src/compiler/symb-define.bas
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,10 @@ private function hDefArgExtract_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum
var argString = hMacro_getArgZ( argtb, 1 )
dim varArgs() as string

hSplitStr(*argString, ",", varArgs())
res = varArgs(index)
if( hStr2Args( argString, varArgs() ) > 0 ) then
res = varArgs(index)
end if

ZStrFree(argString)
end if

Expand Down
2 changes: 1 addition & 1 deletion src/gfxlib2/unix/gfx_driver_opengl_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ static int driver_init(char *title, int w, int h, int depth, int refresh_rate, i
__fb_gl_params.mode_2d = __fb_gl_params.init_mode_2d;

if (__fb_gl_params.init_scale>1){
__fb_gl_params.init_scale = __fb_gl_params.init_scale;
__fb_gl_params.scale = __fb_gl_params.init_scale;
free(__fb_gfx->dirty);
__fb_gfx->dirty = (char *)calloc(1, __fb_gfx->h * __fb_gfx->scanline_size* __fb_gl_params.scale);
}
Expand Down
96 changes: 96 additions & 0 deletions tests/pp/macro-arg-extract.bas
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,101 @@ SUITE( fbc_tests.pp.macro_arg_extract )
CU_ASSERT_EQUAL( FLOAT_VAL, __FB_ARG_EXTRACT__(2, WHOLE_LIST) )
END_TEST

#macro nested1( n, arg0, arg1, arg3 )
__FB_UNQUOTE__( "#define n1 " ) __FB_QUOTE__( arg1 )
#endmacro

#macro nestedX( n, args... )
__FB_UNQUOTE__( "#define nx " ) __FB_QUOTE__( __FB_ARG_EXTRACT__( n, args ) )
#endmacro

#macro nestedreset
__FB_UNQUOTE__( "#undef n1" )
__FB_UNQUOTE__( "#undef nx" )
#endmacro

TEST( nested_comma_direct )

scope
dim a(0,0) as integer
nested1( 1, 1, a(0,0), 3 )
nestedX( 1, 1, a(0,0), 3 )
CU_ASSERT_EQUAL( n1, nx )
nestedreset
end scope

nested1( 1, 1, /'2,3'/, 3 )
nestedX( 1, 1, /'2,3'/, 3 )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( ) )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( ) )
nestedreset

nested1( 1, 1, "2,3", 3 )
nestedX( 1, 1, "2,3", 3 )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( "2,3" ) )
CU_ASSERT_EQUAL( nx, __FB_QUOTE__( "2,3" ) )
nestedreset

nested1( 1, 1, "2,(3", 3 )
nestedX( 1, 1, "2,(3", 3 )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( "2,(3" ) )
CU_ASSERT_EQUAL( nx, __FB_QUOTE__( "2,(3" ) )
nestedreset

nested1( 1, 1, "2,""3", 3 )
nestedX( 1, 1, "2,""3", 3 )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( "2,""3" ) )
CU_ASSERT_EQUAL( nx, __FB_QUOTE__( "2,""3" ) )
nestedreset

nested1( 1, 1, $"2,3", 3 )
nestedX( 1, 1, $"2,3", 3 )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( $"2,3" ) )
CU_ASSERT_EQUAL( nx, __FB_QUOTE__( $"2,3" ) )
nestedreset

nested1( 1, 1, !"2,3", 3 )
nestedX( 1, 1, !"2,3", 3 )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( !"2,3" ) )
CU_ASSERT_EQUAL( nx, __FB_QUOTE__( !"2,3" ) )
nestedreset

nested1( 1, 1, !"\\\"""2,3", 3 )
nestedX( 1, 1, !"\\\"""2,3", 3 )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( !"\\\"""2,3" ) )
CU_ASSERT_EQUAL( nx, __FB_QUOTE__( !"\\\"""2,3" ) )
nestedreset

END_TEST

#macro nested_test( arg )
nested1( 1, 1, arg, 3 )
nestedX( 1, 1, arg, 3 )
CU_ASSERT_EQUAL( n1, __FB_QUOTE__( arg ) )
CU_ASSERT_EQUAL( nx, __FB_QUOTE__( arg ) )
nestedreset

#endmacro

TEST( nested_comma_indirect )

nested_test( /' comment '/ )
nested_test( () )
nested_test( a(1,2) )
nested_test( "2,3" )
nested_test( "2,(3" )
nested_test( "2,""3" )
nested_test( "/' string '/" )
nested_test( $"2,3" )
nested_test( !"2,3" )
nested_test( $"\\""""2,3" )
nested_test( !"\\\"""2,3" )

END_TEST

TEST( string_args )

END_TEST

END_SUITE

0 comments on commit 146862f

Please sign in to comment.