ByteStrings are used when a string contains only ASCII/LATIN-1 characters (code points 0-255):
// Regular String (UTF-16, 2 bytes/char)let emoji = "hello 👋"; // Contains emoji, must use Stringlet chinese = "你好"; // Contains Chinese, must use String// ByteString (1 byte/char)let ascii = "hello"; // ASCII only, can use ByteStringlet url = "https://example.com"; // ASCII, can use ByteString
Regular strings in Porffor are UTF-16 encoded (2 bytes per character). ByteStrings use 1 byte per character for ASCII/LATIN-1, halving memory usage. Many builtins must be written twice—once for String and once for ByteString.
The i32 type represents a 32-bit integer, primarily used for pointers.
From CONTRIBUTING.md:40-42: Only use i32 for pointers. It represents the WebAssembly i32 valtype, which is neither signed nor unsigned—signedness is instruction-dependent.
// Type definition from compiler/builtins/porffor.d.ts:1export type i32 = number;function example() { // Get pointer to a string let ptr: i32 = Porffor.wasm`local.get ${myString}`; // Use pointer for memory operations let charCode: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 4);}
The f64 type represents a 64-bit floating-point number (IEEE 754 double):
// Type definition from compiler/builtins/porffor.d.ts:3export type f64 = number;// This is the default valtype in Porfforlet x: f64 = 3.14159;let y: f64 = 42; // Integers are also f64 by default
By default, Porffor uses f64 as its valtype. You can change this with --valtype=i32 to use 32-bit integers instead, but this is experimental.
// Type definition from compiler/builtins/porffor.d.ts:2export type i64 = number;// Used for bigint operations and large integerslet big: i64 = 9007199254740991;
// Compiler knows these are numbers, generates optimized codefunction add(a: number, b: number): number { return a + b;}function processString(s: bytestring): i32 { return s.length;}
Porffor does not type-check your code. Type annotations are purely used as compiler hints for optimization. Invalid types won’t cause errors at compile time.