
B64: examples explained
Maturity and boundaries: experimental
Implemented scope: Functions, prototypes, pointers, structures, fixed arrays, loops and numeric expressions are represented by the guided examples.
Boundary: Integer spellings still use signed 64-bit values; self-referential structure pointers are unsupported, so this is not a general B64 compatibility claim.
B64 supported commands and scope
Browse the language-specific supported-command and scope reference, with searchable categories and explicit boundaries.
Open scope referenceB64 uses typed variables and functions with brace-delimited blocks. These examples cover loops, parameters and an explicit loop exit.
Twelve short examples and one larger program. Choose a topic or work through the examples in order.
1. 1 + 2 + 3 + 4 + 5 = 15
The numbers 1 through 5 are added to 15. Return value 15 is checked as the process exit code.
fn main(): i64 {
let sum: i64 = 0;
let i: i64 = 1;
while i <= 5 {
sum = sum + i;
i = i + 1;
}
return sum; // 15
}Expected exit code: 15
PBXB64.exe sum15-b64.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Executed natively with the V22 candidate from 2026-09-30; final-compiler verification pending.
2. Typed function: 20 + 22
add takes two i64 parameters and returns their sum as i64. main calls add(20, 22), returning 42. Here the result is the process exit code, not console output.
fn add(a: i64, b: i64): i64 {
return a + b;
}
fn main(): i64 {
return add(20, 22);
}
Expected exit code: 42
PBXB64.exe params.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Canonical test case with an expected result; no new native V22 check here. Final execution pending.
3. Exit a loop with break
i starts at 0 and increases before the check. At i = 25, break exits immediately. The nominal bound 100 is never reached; main returns 25.
fn main(): i64 {
let i: i64 = 0;
while i < 100 {
i = i + 1;
if i == 25 {
break;
}
}
return i;
}
Expected exit code: 25
PBXB64.exe loop_control.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Canonical test case with an expected result; no new native V22 check here. Final execution pending.
4. Precedence and a bit shift
Step-by-step flow
- Addition is evaluated before the shift.
- 1 + 2 is 3; 3 << 3 shifts left by three bit positions.
- main returns 24 as the exit code rather than printing text.
fn main(): i64 {
return 1 + 2 << 3;
}
Expected exit code: 24
PBXB64.exe b64-precedence.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
5. A global constant
Step-by-step flow
- const defines ANSWER as an i64 with value 42.
- main reads that name from the global scope.
- There is no mutable global variable or console output.
const ANSWER: i64 = 42;
fn main(): i64 {
return ANSWER;
}
Expected exit code: 42
PBXB64.exe b64-global_data.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
6. Address and dereference
Step-by-step flow
- g is a global i64 variable initialized to 5.
- &g obtains its address; p has the matching *i64 pointer type.
- *p reads the value at that address and returns 5.
var g: i64 = 5;
fn main(): i64 {
let p: *i64 = &g;
return *p;
}
Expected exit code: 5
PBXB64.exe b64-address_of_global.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
7. Two return paths with if/else
Step-by-step flow
- x is 10, so x > 5 is true.
- The first branch returns 42 and ends main immediately.
- The alternative return value 0 is reached only when the condition is false.
fn main(): i64 {
let x: i64 = 10;
if x > 5 {
return 42;
} else {
return 0;
}
}
Expected exit code: 42
PBXB64.exe b64-if_else.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
8. Five function arguments
Step-by-step flow
- sum5 names five separate i64 parameters.
- The call supplies 1, 2, 3, 4 and 5 in that order.
- The sum 15 is returned to main and then to the process.
fn sum5(a: i64, b: i64, c: i64, d: i64, e: i64): i64 {
return a + b + c + d + e;
}
fn main(): i64 {
return sum5(1, 2, 3, 4, 5);
}Expected exit code: 15
PBXB64.exe b64-five_args.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
9. Check division and remainders together
Step-by-step flow
- 81 / 3 returns 27; the remainder operators produce 0, 2 and 2.
- && requires all four individual checks to be true.
- Only then does main return 27; otherwise it returns 0.
fn main(): i64 {
let q: i64 = 81 / 3;
let r1: i64 = 100 % 5;
let r2: i64 = 100 % 7;
let r3: i64 = 17 % 5;
if (q == 27 && r1 == 0 && r2 == 2 && r3 == 2) {
return 27;
}
return 0;
}
Expected exit code: 27
PBXB64.exe b64-div_rem.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
10. A named array type
Step-by-step flow
- Triple is an array of three i64 values; Again aliases the same type.
- Initialization stores 10, 11 and 21 at indices 0, 1 and 2.
- sizeof(Again) is checked against 24 bytes; the elements sum to 42.
typedef [3]i64 Triple;
typedef Triple Again;
fn main(): i64 {
let x: Again = [10, 11, 21];
if (sizeof(Again) == 24) {
return x[0] + x[1] + x[2];
}
return 0;
}
Expected exit code: 42
PBXB64.exe b64-array_typedef_shape.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
11. A floating value inside a struct
Step-by-step flow
- FloatBox contains an f64 field named value.
- Both x and box.value are initialized with numeric value 21.
- Both comparisons with 21.0 must hold for main to return 42.
struct FloatBox { value: f64 }
fn main(): i64 {
let x: f64 = 21;
let box: FloatBox = FloatBox { value: 21 };
if (x == 21.0 && box.value == 21.0) {
return 42;
}
return 0;
}
Expected exit code: 42
PBXB64.exe b64-scalar_struct_float_init.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
12. One name in two scopes
Step-by-step flow
- The outer variable value contains 40.
- The inner block declares a separate variable with the same name, initialized to 2, and checks it.
- After the block, value refers to the outer variable again: 40 + 2 is 42.
fn main(): i64 {
let value: i64 = 40;
{
let value: i64 = 2;
if value != 2 {
return 100;
}
}
return value + 2;
}
Expected exit code: 42
PBXB64.exe b64-b64_types_shadowing.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
Larger example: Operators, literals and a function call
Step-by-step flow
- Compound assignments change 0 through 10, 8, 24, 12 and 5; the two shifts leave 5 again.
- 'A' supplies 65, 0xFF supplies 255 and signed ~15 is -16.
- helper returns no value. The true branch returns 5 + 65 + 255 - 16 = 309.
// B64 lexer-coverage fixture: exercises keywords, operators, literals and comments.
typedef i64 MyInt;
fn helper(v: i64): void {
return;
}
fn main(): i64 {
let mut_a: i64 = 0;
mut_a += 10;
mut_a -= 2;
mut_a *= 3;
mut_a /= 2;
mut_a %= 7;
mut_a <<= 1;
mut_a >>= 1;
let b: bool = true;
let c: i64 = 'A';
let hex: i64 = 0xFF;
let neg: i64 = ~15;
let not_b: bool = !b;
helper(c);
/* block comment */
if (b || not_b) {
return mut_a + c + hex + neg;
}
return 0;
}
Expected exit code: 309
PBXB64.exe b64-lexer_coverage.b64 -O2 -o example.exe .\example.exe $LASTEXITCODE
Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.
All sources for this tutorial
Each example has its own folder; the README lists compiler commands. Included support files retain matching paths.
Download all 13 examples as ZIPBridging
B64 can call an external C function through a matching extern contract. The example pairs i64 with int64_t; both source files belong in the same compiler invocation.
Explore complete source pairsPBXB64 is part of the PBX-Compiler package. Free for private use, cleanly licensed for business.