PBXB64 supports a growing PowerBASIC-compatible dialect. V12+ adds type suffixes, literal prefixes, #DEFINE/#COMPILE, dynamic arrays (DIM/REDIM/ERASE), OPTIONAL parameters, SELECT CASE with IS/TO, ON GOTO/GOSUB, DATA/READ/RESTORE, CODEPTR/FUNCPTR, and 60+ builtin functions.
Program Entry Point
FUNCTION PBMAIN() AS LONG
FUNCTION = 0 ' Return code
END FUNCTION
Variable Declarations
LOCAL x AS LONG ' Stack variable (explicit type) LOCAL s AS STRING ' Heap-managed string LOCAL f AS SINGLE ' 32-bit float DIM arr(10) AS LONG ' Static array (0-10) GLOBAL g AS LONG ' Module-level global ' Type suffixes (PBWin style) LOCAL intvar% ' INTEGER via % suffix LOCAL longvar& ' LONG via & suffix LOCAL sngvar! ' SINGLE via ! suffix LOCAL dblvar# ' DOUBLE via # suffix LOCAL strvar$ ' STRING via $ suffix LOCAL curvar## ' CURRENCY via ## suffix LOCAL cuxvar?# ' CURRENCYX via ?# suffix LOCAL extvar?? ' EXTENDED via ?? suffix
Literal Prefixes
x = &HFF ' Hex: 255 x = &O77 ' Octal: 63 x = &B1010 ' Binary: 10
Equates
%WIN_WIDTH = 800 ' Integer equate %MAX_ITEMS = 100 $APP_NAME = "MyApp" ' String equate ' Usage in expressions: w = %WIN_WIDTH n = %MAX_ITEMS
Assignment & Operators
x = 42 s = "Hello World" x = x + 1 y = a * b - c / d z = (x > 0) AND (y < 10)
PRINT Statement
PRINT "Hello" PRINT "A"; "B" ' Semicolon: no separator PRINT "A", "B" ' Comma: tab stop (~8 chars) PRINT TAB(4); "D" ' TAB(n): pad with spaces
Control Flow
' IF/THEN/ELSE
IF x > 0 THEN
PRINT "positive"
ELSE
PRINT "negative"
END IF
' FOR/NEXT
FOR i = 1 TO 10 STEP 2
PRINT i
NEXT i
' WHILE/WEND
WHILE x < 100
x = x * 2
WEND
WinAPI Integration
#INCLUDE "windows_core.pbi"
FUNCTION PBMAIN() AS LONG
CALL MessageBoxA(0, "Hello", "PBXB64", 0)
CALL Sleep(1000)
FUNCTION = 0
END FUNCTION
String Operations (V7/V8)
LOCAL s AS STRING, t AS STRING s = "Hello" t = s + " World" ' Concatenation s = "" ' Reassignment frees old heap string automatically s = LEFT$(t, 5) ' Built-in string functions
Macros (V9+)
PBXB64 supports multi-line MACRO definitions with parameter substitution, local labels, and MACROTEMP variables.
Multi-line MACRO
MACRO AddEm(a, b, result)
result = a + b
END MACRO
' Usage:
AddEm x, y, z ' Expands to: z = x + y
MACROTEMP (local variables)
MACROTEMP declares variables that get unique names per expansion, preventing collisions.
MACRO DoSwap(p, q)
MACROTEMP t
LOCAL t AS LONG
t = p : p = q : q = t
END MACRO
DoSwap x, y ' t_1 = x; x = y; y = t_1
DoSwap a, b ' t_2 = a; a = b; b = t_2
Local Labels
Labels inside macros are automatically mangled to avoid conflicts between expansions.
MACRO CheckVal(n)
IF n > 0 THEN GOTO Done
n = 0
Done:
END MACRO
CheckVal 42 ' goto Done_1 ... Done_1:
CheckVal -1 ' goto Done_2 ... Done_2:
%PARAMCOUNT
Returns the number of arguments passed to the macro.
MACRO LogArgs(a, b, c)
x = %PARAMCOUNT ' x = 3
END MACRO
Preprocessor Directives (V12+)
#COMPILE EXE ' Output type (EXE/DLL/CONSOLE)
#DEFINE MAX_SIZE 100 ' Text replacement (resolved in expressions)
#UNDEF MAX_SIZE ' Remove a #DEFINE
#INCLUDE ONCE "file.pbi" ' Include with guard against re-inclusion
' Conditional compilation with comparison operators
%VERSION = 5
#IF %VERSION >= 3
PRINT "Version 3+"
#ELSEIF %VERSION = 2
PRINT "Version 2"
#ELSE
PRINT "Version 1"
#ENDIF
Dynamic Arrays (V12+)
DIM arr(5) AS LONG ' Allocate 5-element heap array arr(2) = 100 ' Write to element x = arr(2) ' Read from element REDIM arr(10) AS LONG ' Resize (discards old data) REDIM PRESERVE arr(20) ' Resize (preserves old data) ERASE arr() ' Free heap buffer ' Bounds n = LBOUND(arr()) ' Lower bound (usually 0) n = UBOUND(arr()) ' Upper bound = element count - 1
OPTIONAL Parameters (V12+)
FUNCTION add(a AS LONG, OPTIONAL b AS LONG) AS LONG
FUNCTION = a + b ' b defaults to 0 if not passed
END FUNCTION
result = add(10) ' b = 0
result = add(10, 20) ' b = 20
ON GOTO / ON GOSUB (V12+)
ON choice GOTO lab1, lab2, lab3 ' Computed goto ON choice GOSUB sub1, sub2, sub3 ' Computed gosub DATA 1, 2, 3, 4, 5 ' Data block READ a, b, c ' Read from data RESTORE ' Reset to start of data
Nesting & Limits
- Max nesting depth: 16 levels
- Macros are pre-scanned before the main pass (forward references OK)
- Parameter substitution is case-insensitive word-boundary
MACRO name(x) = expression emits a C #define and is also supported.Wide-Integer Types (V8+)
PBXB64 supports native 128-bit, 256-bit, and 512-bit signed and unsigned integers with inline x64 arithmetic - no runtime library calls.
LOCAL a AS INT128 ' 128-bit signed LOCAL b AS I128 ' Alias for INT128 LOCAL c AS UINT128 ' 128-bit unsigned LOCAL d AS U128 ' Alias for UINT128 LOCAL e AS INT256 ' 256-bit signed LOCAL f AS I256 ' Alias for INT256 LOCAL g AS UINT256 ' 256-bit unsigned LOCAL h AS U256 ' Alias for UINT256 LOCAL i AS INT512 ' 512-bit signed LOCAL j AS I512 ' Alias for INT512 LOCAL k AS UINT512 ' 512-bit unsigned LOCAL l AS U512 ' Alias for UINT512 ' All standard arithmetic operators are supported: a = 1000000000000000000000 ' 10^21 b = a + a ' 2*10^21 c = a * b ' 2*10^42 (fits in 128 bits)
MODULE System (V8+)
Encapsulate code into named scopes with visibility control.
MODULE MyModule
' Private by default — only visible inside this module
FUNCTION PrivateHelper() AS LONG
FUNCTION = 42
END FUNCTION
' Public — callable from outside via module prefix
PUBLIC FUNCTION PublicFunc() AS LONG
FUNCTION = PrivateHelper()
END FUNCTION
' Module-scoped equates and globals
%MY_CONST = 100
GLOBAL gCounter AS LONG
END MODULE
' Call from another module or the main program:
FUNCTION PBMAIN() AS LONG
result = MyModule.PublicFunc() ' OK: PUBLIC
' result = MyModule.PrivateHelper() ' ERROR: PRIVATE
FUNCTION = result
END FUNCTION
H-Lib Native Containers (V8+)
23 container families with auto-initialization, method-dispatch syntax, and UDT payload support.
LOCAL q AS LNQUE ' FIFO queue of LONGs q = q.New q.Push 10 q.Push 20 PRINT q.Pop ' 10 q.Final LOCAL h AS LNHSH ' Hash table (LONG key, LONG value) h = h.New h.Set(1, 100) PRINT h.Get(1) ' 100 h.Final ' Subscript access: LOCAL a AS LNARR a = a.New a[0] = 42 PRINT a[0] ' 42 a.Final
LIKE / ALIKE Operator (V8+)
Pattern matching with wildcards and character classes.
IF "Hello" LIKE "H*" THEN ' true: * matches any sequence IF "abc" LIKE "a[bc]c" THEN ' true: bracket list IF "abc" LIKE "a[!b]c" THEN ' false: complemented class IF "abc" LIKE "a[a-z]c" THEN ' true: character range IF "test.txt" LIKE "*.txt" THEN ' true: wildcard extension ' ALIKE is always case-insensitive: IF "Hello" ALIKE "h*" THEN ' true
V15 Qualified Additions
- Native DLL/export output and import-library generation are covered by focused linker lanes.
#COMPILE SLLremains a separate native archive compatibility surface. - StringX functions
COMPARE,COMPARE$,LIKE$,MATCH$,REGEX$,REGEXREPLACE$,FIND$,FINDREV$,REPLACES$, andREMOVES$have positive and negative tests. REGEXPRandREGREPLuse the vendored REGEXPR v1.25.0 engine through the PB dialect layer.TIMEBASEsupports query and assignment forms.ROTATEsupports tested expression and statement forms with strict malformed-call diagnostics.- Focused native coverage includes TAB controls, bounded DIALOG/GUI operations, XPRINT/LPRINT printer functions, preview callbacks, and SAPI-backed
SAY. - COM/OOP coverage includes inheritance/override, selected real automation-server probes, BYREF outputs,
OBJRESULT$, and per-threadIDISPINFO/EXCEPINFOdetails. - Qualified metastatements generate code or configuration where documented. Unsupported type-library emission fails explicitly rather than being ignored.
Known Limitations (V15)
- Full WinAPI .pbi include library available in
includes/(1,272 headers) #COMPILE DLLand exports are available for the tested native PE/export surface; complete historical linker parity is not claimed- Full PowerBASIC compatibility is ongoing work
