Quick Reference
A quick lookup guide for Twinkies syntax and features.
Keywords
Control Flow & Declarations:
func,let,if,else,while,break,continue,return,print,extern,from
Types:
int,int8,int16,int32,int64,bool,float,double,string,void
Literals:
true,false,null
Other:
asm,volatile
Types
int // Integer
int8 // 8-bit integer
int16 // 16-bit integer
int32 // 32-bit integer
int64 // 64-bit integer
bool // Boolean
float // Single-precision float
double // Double-precision float
string // String
void // No return value
Variable Declaration
let name: type = value;
let x: int = 10;
let name: string = "Hello";
Functions
func name(params) -> return_type {
return value;
}
func add(x: int, y: int) -> int {
return x + y;
}
Control Flow
If Statement
if (condition) {
// code
}
if (condition) {
// code
} else {
// code
}
While Loop
while (condition) {
// code
}
Break/Continue
break; // Exit loop
continue; // Skip to next iteration
Return
return value; // Return from function
return; // Return from void function
Operators
Arithmetic
+ // Addition
- // Subtraction
* // Multiplication
/ // Division
% // Modulo
Comparison
== // Equal
!= // Not equal
< // Less than
> // Greater than
<= // Less than or equal
>= // Greater than or equal
Logical
&& // Logical AND
|| // Logical OR
! // Logical NOT
Unary
- // Negation
! // Logical NOT
Arrays
let arr: int[5]; // Declare array
arr[0] = 10; // Assign element
let value: int = arr[0]; // Access element
Strings
let str: string = "Hello";
let len: int = strlen(str);
let sub: string = substr(str, 0, 5);
let combined: string = str1 + str2;
let cmp: int = strcmp(str1, str2);
String Functions
strlen(str) // Get length
strcmp(str1, str2) // Compare strings
substr(str, start, len) // Extract substring
concat(str1, str2) // Concatenate strings
Modules
#include "module.tlh" // Include header
// Header file (module.tlh)
func function_name(params) -> return_type;
// Implementation (module.tl)
func function_name(params) -> return_type {
// implementation
}
FFI
extern "calling_convention" from "library" {
func function_name(params) -> return_type;
}
extern "cdecl" from "kernel32.dll" {
func GetTickCount() -> int;
}
Calling Conventions
cdecl- Default C calling conventionstdcall- Windows API calling conventionfastcall- Optimized calling conventionthiscall- C++ member function calling convention
Inline Assembly
asm {
"assembly code"
: outputs
: inputs
: clobbers
};
asm {
"mov $42, %0"
: "=r" (result)
:
:
};
Volatile Assembly
asm volatile {
"assembly code"
: outputs
: inputs
: clobbers
};
Register Constraints
r- Any general-purpose registera- RAX/EAXb- RBX/EBXc- RCX/ECXd- RDX/EDXi- Immediate integerm- Memory operand
Comments
// Single-line comment
/* Multi-line
comment */
Literals
42 // Integer
3.14 // Float
true // Boolean
false // Boolean
"Hello" // String
null // Null
Escape Sequences
\n // Newline
\t // Tab
\\ // Backslash
\" // Double quote
Precedence
- Unary:
!,- - Multiplicative:
*,/,% - Additive:
+,- - Comparison:
<,>,<=,>= - Equality:
==,!= - Logical AND:
&& - Logical OR:
||
Compiler Options
-o <file> # Output file
--asm # Generate assembly
--modules # Enable modules
--debug # Debug output
--verbose # Verbose output
--tokens # Print tokens
--ast # Print AST
--ir # Print IR
-I <path> # Include path
Common Patterns
Array Iteration
let arr: int[10];
let i: int = 0;
while (i < 10) {
arr[i] = i;
i = i + 1;
}
Input Validation
let choice: int = input();
while (choice < 1 || choice > 5) {
choice = input();
}
Function Overloading
func add(x: int) -> int {
return x + 1;
}
func add(x: int, y: int) -> int {
return x + y;
}
Recursion
func factorial(n: int) -> int {
if (n <= 1) {
return 1;
}
return n * factorial(n - 1);
}
File Extensions
.tl- Twinkies source file.tlh- Twinkies header file
Program Structure
// Optional includes
#include "module.tlh"
// Optional FFI declarations
extern "cdecl" from "library.dll" {
func function() -> int;
}
// Functions
func helper() -> int {
return 42;
}
// Main function (required)
func main() -> int {
// Program code
return 0;
}
Type Conversions
// Automatic numeric conversions
let i: int = 10;
let f: float = 3.14;
let result: double = i + f; // Automatic
// Null compatibility
let x: int = null;
let s: string = null;
Error Messages
The compiler provides:
- Line and column numbers
- Error context
- Helpful suggestions
- Color-coded output
Best Practices
- Always specify types explicitly
- Use meaningful variable names
- Check array bounds
- Handle null values
- Use comments for complex logic
- Organize code into modules
- Test FFI functions carefully
- Document inline assembly
Common Errors
Missing Semicolon
let x: int = 10 // ✗ Missing semicolon
let x: int = 10; // ✓ Correct
Type Mismatch
let x: bool = 42; // ✗ Type mismatch
let x: int = 42; // ✓ Correct
Undefined Variable
print(undefined); // ✗ Undefined variable
let x: int = 10;
print(x); // ✓ Correct
Array Out of Bounds
let arr: int[5];
arr[10] = 0; // ✗ Out of bounds
arr[4] = 0; // ✓ Valid
