Skip to content

Commit 248da04

Browse files
authored
Merge pull request #89 from jayrm/byref-init-byref
Add Byref Initializers of Byref Variables
2 parents e3fcb8d + 1769ad7 commit 248da04

File tree

7 files changed

+498
-10
lines changed

7 files changed

+498
-10
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Version 1.06.0
1414
- Under X11, ScreenControl GET_WINDOW_HANDLE places the Display ptr in param2
1515
- Updated bindings: SDL2 2.0.6, SDL2_image 2.0.1, SDL2_mixer 2.0.1, SDL2_net 2.0.1, SDL2_ttf 2.0.14
1616
- allow overload operator SQR()
17+
- allow [static] shared byref variables to be initialized with byref variable
1718

1819
[fixed]
1920
- win/d3dx9.bi no longer has a hard-coded #inclib "d3dx9d". d3dx9d.dll is apparently not a generally valid choice. In practice programs have to be linked against d3dx9_33.dll or d3dx9_39.dll, etc.
@@ -62,6 +63,7 @@ Version 1.06.0
6263
- #878: Fix fbc-64bit hangs on 'Case True' + 'Case False' inside 'Select Case As const'
6364
- Fix SELECT CASE AS CONST to allow both signed & unsigned case range values
6465
- #822, #814, #842: Compiler crash when initializing static/shared reference (DIM SHARED/STATIC BYREF) with non-constant initializer (e.g. another reference, or dynamic array element)
66+
- ASM backend: Fix bad code generated for comparisons such as IF @globalvar = 0 THEN
6567

6668

6769
Version 1.05.0

src/compiler/ir-tac.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,8 @@ private sub hFlushCOMP _
20192019
doload = TRUE
20202020
elseif( v1_typ = IR_VREGTYPE_IMM) then '' /
20212021
doload = TRUE
2022+
elseif( v1_typ = IR_VREGTYPE_OFS and v2_typ = IR_VREGTYPE_IMM ) then
2023+
doload = TRUE
20222024
elseif( v2_typ <> IR_VREGTYPE_REG ) then '' /
20232025
if( v2_typ <> IR_VREGTYPE_IMM ) then
20242026
doload = TRUE

src/compiler/parser-decl-var.bas

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,49 @@ private function hBuildFakeByrefInitExpr( byval dtype as integer, byval subtype
854854
function = astNewDEREF( expr )
855855
end function
856856

857+
'' resolve reference to a reference
858+
private function hResolveRefToRefInitializer( byval dtype as integer, byval expr as ASTNODE ptr ) as ASTNODE ptr
859+
860+
dim tree as ASTNODE ptr = any
861+
dim n as ASTNODE ptr = any
862+
863+
'' if initializer expr is a REF VAR, then crawl the INITREE of the var
864+
'' it references for a VAR initializer. If none found just return the
865+
'' original expr.
866+
867+
if( expr andalso astIsDEREF( expr ) ) then
868+
if( expr->l andalso astIsVAR( expr->l ) ) then
869+
if( expr->l->sym andalso symbIsRef( expr->l->sym ) andalso symbIsVar( expr->l->sym ) ) then
870+
tree = expr->l->sym->var_.initree
871+
if( tree andalso astIsTYPEINI( tree ) ) then
872+
if( tree->l andalso tree->l->class = AST_NODECLASS_TYPEINI_ASSIGN ) then
873+
n = tree->l->l
874+
if( n ) then
875+
876+
select case astGetClass( n )
877+
case AST_NODECLASS_OFFSET
878+
n = n->l
879+
if( n andalso astIsVAR( n ) ) then
880+
'' compatible types?
881+
if( astGetFullType( n ) = dtype ) then
882+
astDelTree( expr )
883+
expr = astCloneTree( n )
884+
end if
885+
end if
886+
end select
887+
888+
end if
889+
end if
890+
end if
891+
892+
end if
893+
end if
894+
end if
895+
896+
function = expr
897+
898+
end function
899+
857900
private function hCheckAndBuildByrefInitializer( byval sym as FBSYMBOL ptr, byref expr as ASTNODE ptr ) as ASTNODE ptr
858901
'' Check data types, CONSTness, etc.
859902
var ok = astCheckByrefAssign( sym->typ, sym->subtype, expr )
@@ -866,6 +909,8 @@ private function hCheckAndBuildByrefInitializer( byval sym as FBSYMBOL ptr, byre
866909
errReport( FB_ERRMSG_INVALIDDATATYPES )
867910
astDelTree( expr )
868911
expr = hBuildFakeByrefInitExpr( sym->typ, sym->subtype )
912+
else
913+
expr = hResolveRefToRefInitializer( sym->typ, expr )
869914
end if
870915

871916
'' Build the TYPEINI for initializing the reference/pointer

0 commit comments

Comments
 (0)