[Done] PB6.xx cryptic Assembler Errors

All bugs related to new C backend
User avatar
HeX0R
Addict
Addict
Posts: 912
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

[Done] PB6.xx cryptic Assembler Errors

Post by HeX0R »

I'm trying to find the problem in srods minscript, but since it is not my source and the error message from PB is not really helpful, I'm stuck now.
It compiles fine with the ASM compilers.
Error message is e.g.:
---------------------------
PureBasic - Assembler error
---------------------------
error: invalid use of undefined type 'struct s_minscriptcodeexecution'

21285 | integer rr1125=(*p_code->f_execution)->m_execute(p1846,p1847);

| ~^~~~~~~~~~~~~~~~~~~~~

purebasic.c:21375:17: error: invalid use of undefined type 'struct s
I've uploaded minScript to -> download

Just compile the Demos/qdMin/qdMin.pb and you'll see it (only tried under Windows x64)
User avatar
mk-soft
Addict
Addict
Posts: 4863
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB6.xx cryptic Assembler Errors

Post by mk-soft »

Same error here with PB v6.02 C-backend ...
---------------------------
PureBasic - Assembler error
---------------------------
error: invalid use of undefined type 'struct s_minscriptcodeexecution'
21285 | integer rr1125=(*p_code->f_execution)->m_execute(p1846,p1847);
| ~^~~~~~~~~~~~~~~~~~~~~
purebasic.c:21375:17: error: invalid use of undefined type 'struct s

---------------------------
OK
---------------------------
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Addict
Addict
Posts: 4863
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB6.xx cryptic Assembler Errors

Post by mk-soft »

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
---------------------------
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
HeX0R
Addict
Addict
Posts: 912
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: PB6.xx cryptic Assembler Errors

Post by HeX0R »

nice catch!
Even if it can't be avoided, I'd prefer to receive a usable error message at least.
Fred
Administrator
Administrator
Posts: 15950
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB6.xx cryptic Assembler Errors

Post by Fred »

C allows forward declaration, so it should work. I will take a closer look.
User avatar
mk-soft
Addict
Addict
Posts: 4863
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB6.xx cryptic Assembler Errors

Post by mk-soft »

From my example the c-code
With single pass through, it is first assumed that it is a pointer to a substructure.

Code: Select all

#pragma pack(1)
typedef struct s_structa {
struct s_imethods *f_method;
} s_structa;
#pragma pack()
But since the interface is defined later in the pb code, the structure would have to be corrected afterwards.

Code: Select all

#pragma pack(1)
typedef struct s_structa {
struct i_imethods **f_method;
} s_structa;
#pragma pack()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 15950
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Done] PB6.xx cryptic Assembler Errors

Post by Fred »

Fixed.
User avatar
mk-soft
Addict
Addict
Posts: 4863
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Done] PB6.xx cryptic Assembler Errors

Post by mk-soft »

Works ;)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply