I would like to implement c-style blocks, in fact i already did. But this (ugly) code that "emulates" c-style blocks runs only in 32 bit mode:
#COMPILE EXE
#COMPILER OXYGEN
#OPTIONS X32 CONSOLE
#DIM ALL
int function PBMAIN() {
for (int i = 0; i < 10; i++) {
stdout i
}
}
Please give it a try... maybe this will give a clue why my operators sometimes causes an error that compiles but doesnt run...
Please ignore unnecessary declarations and code, i will make it cleaner later. This 32bit example compiles and runs fine:
'Generated with PluriBASIC 6.0.237326.0
$ filename "C:\Users\Diamante\Documents\PluriBASIC\EJEMPLOS\c_style.exe"
uses rtl32
uses console
DIM STRING ¤SYSTEM_UDT_OFFSETS(0)
STRING ¤TMPS = "" ' a temporary string.
DECLARE FUNCTION ¤GetLastError Lib "Kernel32.dll" Alias "GetLastError" () AS LONG
DECLARE FUNCTION ¤GetAsyncKeyState Lib "User32.dll" Alias "GetAsyncKeyState" (ByVal vKey AS LONG) AS short
DECLARE SUB ¤Sleep lib "Kernel32.dll" alias "Sleep" (dword mSec)
function ¤INI_QUAD(dword v1, v2) as quad
quad v = 0
copy @v+0, @v2, 4
copy @v+4, @v1, 4
return v
end function
DECLARE FUNCTION ¤OpenProcess Lib "KERNEL32.DLL" Alias "OpenProcess" (ByVal dwDesiredAccess AS DWORD, ByVal bInheritHandle AS LONG, ByVal dwProcessId AS SYS) AS SYS
DECLARE FUNCTION ¤TerminateProcess Lib "KERNEL32.DLL" Alias "TerminateProcess" ( ByVal hProcess AS SYS, ByVal uExitCode AS DWORD) AS LONG
DECLARE FUNCTION ¤CloseHandle Lib "KERNEL32.DLL" Alias "CloseHandle" (ByVal hObject AS SYS) AS LONG
DECLARE FUNCTION ¤GetCurrentProcessId Lib "KERNEL32.DLL" Alias "GetCurrentProcessId" () AS SYS
DECLARE FUNCTION ¤WriteConsole LIB "KERNEL32.DLL" ALIAS "WriteFile" (BYVAL hFile AS SYS, lpBuffer AS ANY, BYVAL nNumberOfBytesToWrite AS dword, lpNumberOfBytesWritten AS dword, lpReserved AS long) AS LONG
DECLARE FUNCTION ¤AllocConsole LIB "KERNEL32.DLL" ALIAS "AllocConsole" () AS LONG
DECLARE FUNCTION ¤FlushFileBuffers LIB "KERNEL32.DLL" ALIAS "FlushFileBuffers" (BYVAL hFile AS SYS) AS LONG
DECLARE FUNCTION ¤GetStdHandle LIB "KERNEL32.DLL" Alias "GetStdHandle" (ByVal nStdHandle AS DWORD) AS SYS
' STARTS PLURIBASIC_PREPARE.BIN
' This code is executed before anything else, if you want to do something after defining other things, see PLURIBASIC_INIT
int ¤i = 0
' STARTS SYSTEM_OPERATORS.BIN
FUNCTION ¤BytOvf(byte b) AS byte
return b
END FUNCTION
FUNCTION ¤STRDIF(STRING a, STRING b) AS INT
IF (a = b) THEN
return 0
else
return -1
end if
END FUNCTION
FUNCTION ¤STREQL(STRING a, STRING b) AS INT
IF (a = b) THEN
return -1
else
return 0
end if
END FUNCTION
FUNCTION ¤ISTRUE(byval quad v1) AS QUAD
IF v1 = 0 then
return 0
ELSE
return -1
END IF
END FUNCTION
FUNCTION ¤ISFALSE(byval quad v1) AS QUAD
IF v1 = 0 then
return -1
ELSE
return 0
END IF
END FUNCTION
FUNCTION ¤NOT(byval quad v1) AS QUAD
dword w1
dword w2
quad r
copy @w1, @v1, 4
copy @w2, @v1+4, 4
w1 = not(w1)
w2 = not(w2)
copy @r, @w1, 4
copy @r+4, @w2, 4
return r
END FUNCTION
FUNCTION ¤AND(byval quad v1, v2) as quad
dword w1
dword w2
quad r
copy @w1, @v1, 4
copy @w2, @v2, 4
w1 = (w1 and w2)
copy @r, @w1, 4
copy @w1, @v1+4, 4
copy @w2, @v2+4, 4
w1 = (w1 and w2)
copy @r+4, @w1, 4
return r
end function
FUNCTION ¤OR(byval int v1, v2) as int
return v1 or v2
end function
'FUNCTION ¤OR(byval quad v1, v2) as quad
' dword w1
' dword w2
' quad r
' copy @w1, @v1, 4
' copy @w2, @v2, 4
' w1 = (w1 or w2)
' copy @r, @w1, 4
' copy @w1, @v1+4, 4
' copy @w2, @v2+4, 4
' w1 = (w1 or w2)
' copy @r+4, @w1, 4
' return r
'end function
FUNCTION ¤IMP(byval quad v1, v2) as quad
if v1 then return -1
if v2 then return -1
end function
FUNCTION ¤EQV(byval quad v1, v2) as quad
if v1=0 then return 0
if v2=0 then return 0
return -1
end function
FUNCTION ¤MOD(quad v1, v2) as quad
return MOD(v1, v2)
end function
' END OF SYSTEM_OPERATORS.BIN
' CONTINUES (12) PLURIBASIC_PREPARE.BIN
#DEF HANDLE SYS
TYPE ¤SYSNMHDR
hwndFrom AS SYS
idFrom AS SYS
Code AS DWORD
END TYPE
class ¤SYSF
FUNCTION CONSTRUCTOR()
END FUNCTION
END CLASS
new ¤SYSF EXE()
MACRO ¤STRCODE(dc)
numberformat(dc,1,0,1,0,0)
string ss = str(v)
numberformat
if v < 0 then
return ltrim(ss)
else
return " " + ltrim(ss)
end if
END MACRO
FUNCTION ¤STR(double v, byref long d = 0) as string
long d2 = 6
if @d then d2 = d
¤STRCODE(d2)
END FUNCTION
FUNCTION ¤STR(single v, byref long d = 0) as string
long d2 = 6
if @d then d2 = d
¤STRCODE(d2)
END FUNCTION
FUNCTION ¤STR(quad v, byref long d = 0) as string
¤STRCODE(0)
END FUNCTION
' END OF STR$.BIN
' STARTS PRINTR.BIN
SUB ¤INITCONSOLE()
STATIC Allc AS LONG
IF Allc=0 THEN
¤AllocConsole()
Allc = 1
END IF
END SUB
MACRO ¤STDOUT()
INT lWritten = 0
SYS hFile = 0
INT Btc = 0
¤INITCONSOLE()
if cr=1 then s += chr(13, 10)
if cr=2 then s += "</br>"
¤Sleep(0)
hFile = ¤GetStdHandle(-11)
FOR Btc = 1 TO 50
IF ((Btc*32000)-31999) > len(s) THEN EXIT FOR
TTsnd = MID(s, ((Btc*32000)-31999), 32000)
¤WriteConsole(hFile, ByVal StrPtr(TTsnd), byval Len(TTsnd), lWritten, ByVal 0)
NEXT Btc
'¤FlushFileBuffers(hFile)
END MACRO
SUB ¤PRINTASZ(ASCIIZ c[0], byval int cr)
STRING TTsnd = ""
string s = c
¤STDOUT()
END SUB
SUB ¤PRINTSTR(STRING c, byval int cr)
STRING TTsnd = ""
STRING s = c
¤STDOUT()
END SUB
SUB ¤PRINTJSN(STRING c, byval int cr)
STRING TTsnd = ""
STRING s = c
¤STDOUT()
END SUB
SUB ¤PRINTSTZ(ZSTRING c[0], byval int cr)
STRING TTsnd = ""
STRING s = c
¤STDOUT()
END SUB
SUB ¤PRINTWST(WSTRING c, byval int cr)
STRING TTsnd = ""
STRING s = c
¤STDOUT()
END SUB
SUB ¤PRINTWSZ(ZSTRING2 c[0], byval int cr)
WSTRING TTsnd = ""
WSTRING s = c
¤STDOUT()
END SUB
DECLARE FUNCTION PBMAIN() AS INT
' Initializes various things in the script.
FUNCTION PluriBASIC_Initialize() AS LONG
END FUNCTION
FUNCTION PBMAIN() AS INT
INT ¤RETVAL = 0
INT i
i = 0
int ¤ite0003
for ¤ite0003 = 0 to 2 step 1
if (¤ite0003 = 2) then ¤ite0003 = 1
if (¤ite0003 > 0) then
i = ((i) + 1)
end if
if ((i < 10) = 0) then exit for
¤PRINTSTR(¤STR(i), 1)
NEXT
RETURN ¤RETVAL
END FUNCTION
PBMAIN() ' invoke entry point
This 64 bit example compiles fine but doesnt run, it complains about not being a valid win32 application? Isnt it a 64 bit application?:
'Generated with PluriBASIC 6.0.237326.0
$ filename "C:\Users\Diamante\Documents\PluriBASIC\EJEMPLOS\c_style.exe"
uses rtl64
DIM STRING ¤SYSTEM_UDT_OFFSETS(0)
STRING ¤TMPS = "" ' a temporary string.
DECLARE FUNCTION ¤GetLastError Lib "Kernel32.dll" Alias "GetLastError" () AS LONG
DECLARE FUNCTION ¤GetAsyncKeyState Lib "User32.dll" Alias "GetAsyncKeyState" (ByVal vKey AS LONG) AS short
DECLARE SUB ¤Sleep lib "Kernel32.dll" alias "Sleep" (dword mSec)
function ¤INI_QUAD(dword v1, v2) as quad
quad v = 0
copy @v+0, @v2, 4
copy @v+4, @v1, 4
return v
end function
DECLARE FUNCTION ¤OpenProcess Lib "KERNEL32.DLL" Alias "OpenProcess" (ByVal dwDesiredAccess AS DWORD, ByVal bInheritHandle AS LONG, ByVal dwProcessId AS SYS) AS SYS
DECLARE FUNCTION ¤TerminateProcess Lib "KERNEL32.DLL" Alias "TerminateProcess" ( ByVal hProcess AS SYS, ByVal uExitCode AS DWORD) AS LONG
DECLARE FUNCTION ¤CloseHandle Lib "KERNEL32.DLL" Alias "CloseHandle" (ByVal hObject AS SYS) AS LONG
DECLARE FUNCTION ¤GetCurrentProcessId Lib "KERNEL32.DLL" Alias "GetCurrentProcessId" () AS SYS
DECLARE FUNCTION ¤WriteConsole LIB "KERNEL32.DLL" ALIAS "WriteFile" (BYVAL hFile AS SYS, lpBuffer AS ANY, BYVAL nNumberOfBytesToWrite AS dword, lpNumberOfBytesWritten AS dword, lpReserved AS long) AS LONG
DECLARE FUNCTION ¤AllocConsole LIB "KERNEL32.DLL" ALIAS "AllocConsole" () AS LONG
DECLARE FUNCTION ¤FlushFileBuffers LIB "KERNEL32.DLL" ALIAS "FlushFileBuffers" (BYVAL hFile AS SYS) AS LONG
DECLARE FUNCTION ¤GetStdHandle LIB "KERNEL32.DLL" Alias "GetStdHandle" (ByVal nStdHandle AS DWORD) AS SYS
' STARTS PLURIBASIC_PREPARE.BIN
' This code is executed before anything else, if you want to do something after defining other things, see PLURIBASIC_INIT
int ¤i = 0
' STARTS SYSTEM_OPERATORS.BIN
FUNCTION ¤BytOvf(byte b) AS byte
return b
END FUNCTION
FUNCTION ¤STRDIF(STRING a, STRING b) AS INT
IF (a = b) THEN
return 0
else
return -1
end if
END FUNCTION
FUNCTION ¤STREQL(STRING a, STRING b) AS INT
IF (a = b) THEN
return -1
else
return 0
end if
END FUNCTION
FUNCTION ¤ISTRUE(byval quad v1) AS QUAD
IF v1 = 0 then
return 0
ELSE
return -1
END IF
END FUNCTION
FUNCTION ¤ISFALSE(byval quad v1) AS QUAD
IF v1 = 0 then
return -1
ELSE
return 0
END IF
END FUNCTION
FUNCTION ¤NOT(byval quad v1) AS QUAD
dword w1
dword w2
quad r
copy @w1, @v1, 4
copy @w2, @v1+4, 4
w1 = not(w1)
w2 = not(w2)
copy @r, @w1, 4
copy @r+4, @w2, 4
return r
END FUNCTION
FUNCTION ¤AND(byval quad v1, v2) as quad
dword w1
dword w2
quad r
copy @w1, @v1, 4
copy @w2, @v2, 4
w1 = (w1 and w2)
copy @r, @w1, 4
copy @w1, @v1+4, 4
copy @w2, @v2+4, 4
w1 = (w1 and w2)
copy @r+4, @w1, 4
return r
end function
FUNCTION ¤OR(byval int v1, v2) as int
return v1 or v2
end function
'FUNCTION ¤OR(byval quad v1, v2) as quad
' dword w1
' dword w2
' quad r
' copy @w1, @v1, 4
' copy @w2, @v2, 4
' w1 = (w1 or w2)
' copy @r, @w1, 4
' copy @w1, @v1+4, 4
' copy @w2, @v2+4, 4
' w1 = (w1 or w2)
' copy @r+4, @w1, 4
' return r
'end function
FUNCTION ¤IMP(byval quad v1, v2) as quad
if v1 then return -1
if v2 then return -1
end function
FUNCTION ¤EQV(byval quad v1, v2) as quad
if v1=0 then return 0
if v2=0 then return 0
return -1
end function
FUNCTION ¤MOD(quad v1, v2) as quad
return MOD(v1, v2)
end function
' END OF SYSTEM_OPERATORS.BIN
' CONTINUES (12) PLURIBASIC_PREPARE.BIN
#DEF HANDLE SYS
TYPE ¤SYSNMHDR
hwndFrom AS SYS
idFrom AS SYS
Code AS DWORD
END TYPE
class ¤SYSF
FUNCTION CONSTRUCTOR()
END FUNCTION
END CLASS
new ¤SYSF EXE()
' END OF PLURIBASIC_PREPARE.BIN
' STARTS STR$.BIN
'int dp ' DECIMAL PLACES
'int trz ' STRIP TRAILING ZEROS
'int sn ' SCIENTIFIC NOTATION BY DEFAULT
'int sdp ' INHIBIT ZERO BEFORE DECIMAL POINT
'int sns ' LEADING SPACE FOR NON NEGATIVE NUMBERS
'int lps ' LEAD PADDING SPACES
'numberformat(8,0,0,0,1,0) 'default settings
'numberformat 'return to default
MACRO ¤STRCODE(dc)
numberformat(dc,1,0,1,0,0)
string ss = str(v)
numberformat
if v < 0 then
return ltrim(ss)
else
return " " + ltrim(ss)
end if
END MACRO
FUNCTION ¤STR(double v, byref long d = 0) as string
long d2 = 6
if @d then d2 = d
¤STRCODE(d2)
END FUNCTION
FUNCTION ¤STR(single v, byref long d = 0) as string
long d2 = 6
if @d then d2 = d
¤STRCODE(d2)
END FUNCTION
FUNCTION ¤STR(quad v, byref long d = 0) as string
¤STRCODE(0)
END FUNCTION
' END OF STR$.BIN
' STARTS PRINTR.BIN
SUB ¤INITCONSOLE()
STATIC Allc AS LONG
IF Allc=0 THEN
¤AllocConsole()
Allc = 1
END IF
END SUB
MACRO ¤STDOUT()
INT lWritten = 0
SYS hFile = 0
INT Btc = 0
¤INITCONSOLE()
if cr=1 then s += chr(13, 10)
if cr=2 then s += "</br>"
¤Sleep(0)
hFile = ¤GetStdHandle(-11)
FOR Btc = 1 TO 50
IF ((Btc*32000)-31999) > len(s) THEN EXIT FOR
TTsnd = MID(s, ((Btc*32000)-31999), 32000)
¤WriteConsole(hFile, ByVal StrPtr(TTsnd), byval Len(TTsnd), lWritten, ByVal 0)
NEXT Btc
'¤FlushFileBuffers(hFile)
END MACRO
SUB ¤PRINTASZ(ASCIIZ c[0], byval int cr)
STRING TTsnd = ""
string s = c
¤STDOUT()
END SUB
SUB ¤PRINTSTR(STRING c, byval int cr)
STRING TTsnd = ""
STRING s = c
¤STDOUT()
END SUB
SUB ¤PRINTJSN(STRING c, byval int cr)
STRING TTsnd = ""
STRING s = c
¤STDOUT()
END SUB
SUB ¤PRINTSTZ(ZSTRING c[0], byval int cr)
STRING TTsnd = ""
STRING s = c
¤STDOUT()
END SUB
SUB ¤PRINTWST(WSTRING c, byval int cr)
STRING TTsnd = ""
STRING s = c
¤STDOUT()
END SUB
SUB ¤PRINTWSZ(ZSTRING2 c[0], byval int cr)
WSTRING TTsnd = ""
WSTRING s = c
¤STDOUT()
END SUB
' END OF PRINTR.BIN
' STARTS PLURIBASIC_INIT.BIN
' This code is executed before anything else, if you want to do something before nything else, see PLURIBASIC_PREPARE
' END OF PLURIBASIC_INIT.BIN
' STARTS CALLBACKDATA.BIN
' END OF CALLBACKDATA.BIN
DECLARE FUNCTION PBMAIN() AS INT
' Initializes various things in the script.
FUNCTION PluriBASIC_Initialize() AS LONG
END FUNCTION
FUNCTION PBMAIN() AS INT
INT ¤RETVAL = 0
INT i
i = 0
int ¤ite0003
for ¤ite0003 = 0 to 2 step 1
if (¤ite0003 = 2) then ¤ite0003 = 1
if (¤ite0003 > 0) then
i = ((i) + 1)
end if
if ((i < 10) = 0) then exit for
¤PRINTSTR(¤STR(i), 1)
NEXT
RETURN ¤RETVAL
END FUNCTION
PBMAIN() ' invoke entry point
I hope its not the 32bit declarations, those are not used, i am hoping they dont break something for 64bit applications.+