OMEGA Language Specification
Complete reference for OMEGA blockchain programming language syntax and semantics (.mega files)
File Structure
OMEGA source files use the .mega extension and follow a structured format:
// Import statements
import "std/io";
import "std/blockchain";
// Blockchain contract declaration
blockchain MyContract {
// Contract body
}
Basic Syntax
Blockchain Declaration
Every OMEGA smart contract is declared as a blockchain:
blockchain MyContract {
// Contract body
}
State Variables
State variables are declared in a state block:
blockchain MyContract {
state {
uint256 public total_supply;
mapping(address => uint256) balances;
string name;
bool is_paused;
}
}
Data Types
Primitive Types
bool- Boolean values (true/false)uint8,uint16,uint32,uint64,uint128,uint256- Unsigned integersint8,int16,int32,int64,int128,int256- Signed integersaddress- Blockchain addressstring- UTF-8 stringbytes- Dynamic byte array
Complex Types
// Arrays
uint256[] dynamic_array;
uint256[10] fixed_array;
// Mappings
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowances;
// Structs
struct User {
string name;
uint256 balance;
bool is_active;
}
// Enums
enum Status {
Pending,
Active,
Inactive
}
Import System
OMEGA uses a module-based import system:
// Standard library imports
import "std/io";
import "std/process";
import "std/env";
// Local module imports
import "lexer/lexer";
import "parser/parser";
import "semantic/analyzer";
// Blockchain-specific imports
import "std/blockchain";
import "std/crypto";
Functions
Function Declaration
function transfer(address to, uint256 amount) public returns (bool) {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
balances[to] += amount;
emit Transfer(msg.sender, to, amount);
return true;
}
Visibility Modifiers
public- Accessible from anywhereprivate- Only accessible within the contractinternal- Accessible within contract and derived contractsexternal- Only accessible from outside the contract
State Mutability
view- Function doesn't modify statepure- Function doesn't read or modify statepayable- Function can receive native tokens
Constructor
blockchain Token {
state {
string name;
string symbol;
uint256 total_supply;
}
constructor(string _name, string _symbol, uint256 _supply) {
name = _name;
symbol = _symbol;
total_supply = _supply;
}
}
Events
// Event declaration
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
// Emitting events
emit Transfer(msg.sender, recipient, amount);
emit Approval(owner, spender, amount);
Control Flow
Conditionals
if (balance > 0) {
// Execute if condition is true
} else if (balance == 0) {
// Execute if first condition is false and this is true
} else {
// Execute if all conditions are false
}
Loops
// For loop
for (uint256 i = 0; i < array.length; i++) {
// Loop body
}
// While loop
while (condition) {
// Loop body
}
Error Handling
// Require statements
require(condition, "Error message");
// Assert statements
assert(invariant_condition);
// Revert statements
if (error_condition) {
revert("Custom error message");
}
Cross-Chain Features
Cross-Chain Function Calls
@cross_chain(target = "solana")
function bridge_to_solana(bytes32 recipient, uint256 amount) public {
require(amount > 0, "Invalid amount");
locked_balances[msg.sender] += amount;
emit TokensBridged(msg.sender, recipient, amount, "solana");
}
Target-Specific Code
function get_block_info() public view returns (uint256) {
#[target(evm)]
return block.number;
#[target(solana)]
return Clock::get().slot;
#[target(cosmos)]
return ctx.block_height();
}
Multi-Target Compilation
// Conditional compilation for different targets
#[cfg(target = "evm")]
function evm_specific_function() public {
// EVM-specific implementation
}
#[cfg(target = "solana")]
function solana_specific_function() public {
// Solana-specific implementation
}
Built-in Variables
msg.sender- Address of the callermsg.value- Amount of native tokens sentblock.timestamp- Current block timestampblock.number- Current block numbertx.origin- Original transaction sender
Comments
// Single line comment
/*
* Multi-line comment
* Can span multiple lines
*/
/// Documentation comment
/// Used for generating documentation