Page 1 of 1

[Done] PB 6.30 b1 - HeaderSection / EndHeaderSection

Posted: Thu Sep 04, 2025 8:58 pm
by User_Russian

Code: Select all

Procedure Test()
  ProcedureReturn 0
EndProcedure

HeaderSection
int Func(int a, int b)
{
   return a+b;
}
EndHeaderSection

Procedure Test2()
  ProcedureReturn 0
EndProcedure

x=0
!v_x = Func(2, 8);
Debug x
Test()
Test2()
C code.

Code: Select all

// 
// PureBasic 6.30 beta 1 - C Backend (Windows - x64) generated code
// 
// (c) 2025 Fantaisie Software
// 
// The header must remain intact for Re-Assembly
// 
// :System
// 
#pragma warning(disable: 4024)
// 
typedef long long quad;
typedef quad integer;
#define PB_INFINITY (1.0 / 0.0)
#define PB_NEG_INFINITY (-1.0 / 0.0)
typedef struct pb_array { void *a; } pb_array;
typedef struct pb_array2 { void *a; integer b[2]; } pb_array2;
typedef struct pb_array3 { void *a; integer b[3]; } pb_array3;
typedef struct pb_array4 { void *a; integer b[4]; } pb_array4;
typedef struct pb_array5 { void *a; integer b[5]; } pb_array5;
typedef struct pb_array6 { void *a; integer b[6]; } pb_array6;
typedef struct pb_array7 { void *a; integer b[7]; } pb_array7;
typedef struct pb_array8 { void *a; integer b[8]; } pb_array8;
typedef struct pb_array9 { void *a; integer b[9]; } pb_array9;
typedef struct pb_listitem { void *a; void *b; void *c;} pb_listitem;
typedef struct pb_list { void *a; pb_listitem *b; } pb_list;
typedef struct pb_mapitem { void *a; void *b; void *c;} pb_mapitem;
typedef struct pb_pbmap { pb_mapitem *a; } pb_pbmap;
typedef struct pb_map { pb_pbmap *a; } pb_map;
static integer s_s[]={0, -1};
#define M_SYSFUNCTION(a) a
#define M_PBFUNCTION(a) a
#define M_CDECL
typedef void TCHAR;
static inline long long pb_llrint(double x) { long long out; __asm__ __volatile__("fldl %1\n" "fistpll %0" : "=m" (out) : "m" (x)); return out; }
#define SYS_BankerRound(x) pb_llrint(x)
#define SYS_BankerRoundQuad(x) pb_llrint(x)
integer f_exitprocess_(integer) asm("ExitProcess");
integer f_heapcreate_(integer,integer,integer) asm("HeapCreate");
integer f_heapdestroy_(integer) asm("HeapDestroy");
integer f_getmodulehandle_(integer) asm("GetModuleHandleW");
// 
static char *tls;
int PB_ExitCode=0;
integer PB_MemoryBase=0;
integer PB_Instance=0;
static unsigned char *pb_datapointer;
// 
// 
// 
integer f_internal_setcurrentdirectory_(integer) asm("SetCurrentDirectoryA");
// 
void SYS_Quit();
M_SYSFUNCTION(void) SYS_InitPureBasic();
volatile int PB_DEBUGGER_LineNumber=-1;
volatile int PB_DEBUGGER_IncludedFiles=0;
char *PB_DEBUGGER_FileName=0;
// 
static integer f_test();
static integer f_test2();

static integer ms_s[]={0,-1};
static integer v_x=0;
// 
// 
// Procedure Test()
static integer f_test() {
integer r=0;
// ProcedureReturn 0
r=0LL;
goto end;
// EndProcedure
r=0;
end:
return r;
}
// Procedure Test2()
static integer f_test2() {
integer r=0;
// ProcedureReturn 0
r=0LL;
goto end;
// EndProcedure
r=0;
end:
return r;
}
// 
char PB_OpenGLSubsystem=1;
int PB_Compiler_Unicode=1;
int PB_Compiler_Thread=0;
int PB_Compiler_Purifier=0;
int PB_Compiler_Debugger=0;
int PB_Compiler_DPIAware=0;
int PB_Compiler_XPSkins=1;
int PB_ExecutableType=0;
// 
void PB_EndFunctions() {
}
// 
int Func(int a, int b)
{
   Return a+b
}

int WinMain(void *instance, void *prevInstance, void *cmdLine, int cmdShow) {
PB_Instance = f_getmodulehandle_(0);
PB_MemoryBase = f_heapcreate_(0,4096,0);
SYS_InitPureBasic();
// 
// HeaderSection
// 
// 
// x=0
v_x=0;
// !v_x = Func(2, 8);
v_x = Func(2, 8);
// Debug x
// Test()
integer r0=f_test();
// Test2()
integer r1=f_test2();
SYS_Quit();
}

void SYS_Quit() {
PB_EndFunctions();
f_heapdestroy_(PB_MemoryBase);
f_exitprocess_(PB_ExitCode);
}
There are several bugs here.

1 bug - in line

Code: Select all

return a+b
there is no semicolon, but it is present in the source code.

2 bug - In the source code, function Func() is located between procedures Test() and Test2(), but after translation to C, the order of placement is incorrect.

Re: PB 6.30 b1 - HeaderSection / EndHeaderSection

Posted: Fri Sep 05, 2025 2:27 am
by idle
I hadn't noticed it was eating the semicolon, good catch.

The header section should appear after
char *PB_DEBUGGER_FileName=0;
or
static unsigned char *pb_datapointer;

you can currently include a c file but you can't use symbols from it in procedures as they appear above the header section.

Re: [Done] PB 6.30 b1 - HeaderSection / EndHeaderSection

Posted: Sat Sep 06, 2025 1:13 pm
by Fred
Fixed.