I could understand the problem with the C-backend compiler.
It is a problem as a single pass compiler.
The compiler interprets the structure entry as a substructure. However, it is later defined as an interface.
I don't see a solution as a single pass compiler, except for the rule that interfaces must always be defined first before they are used in structures.
Code: Select all
; Compile as C-backend
Structure structA
*Method.iMethods ; Interprets the structure entry as a substructure -> (s_imethods)
EndStructure
Interface iMethods ; Move it before structure -> (i_imethods)
Get()
Put(Value)
EndInterface
Structure MyObject
*vTable
Value.i
EndStructure
; ----
Procedure Get(*this.MyObject)
ProcedureReturn *this\Value
EndProcedure
Procedure Put(*this.MyObject, Value)
*this\Value = Value
EndProcedure
Procedure InitMethods()
*obj.MyObject
*obj = AllocateStructure(MyObject)
If *obj
*obj\vTable = ?MyMethods
EndIf
ProcedureReturn *obj
EndProcedure
DataSection
MyMethods:
Data.i @Get()
Data.i @Put()
EndDataSection
;-Test
*mem.structA = AllocateStructure(structA)
*mem\Method = InitMethods()
*mem\Method\Put(100)
Debug *mem\Method\Get()
Result
---------------------------
PureBasic - Assembler error
---------------------------
error: invalid use of undefined type 'struct s_imethods'
552 | integer rr3=(*p_mem->f_method)->m_put(p0,100LL);
| ~^~~~~~~~~~~~~~~~~
purebasic.c:557:14: error: invalid use of undefined type 'struct s_imethods'
557 | integer rr4=(*p_me
---------------------------
OK
---------------------------