### Iridium REPL: Interactive Shell Setup and Usage Source: https://context7.com/fhaynes/iridium/llms.txt Shows how to initialize and run the Iridium REPL for interactive assembly execution. Includes common REPL commands and direct assembly input. ```rust use iridium::repl::REPL; use iridium::vm::VM; // Create and run the REPL let vm = VM::new().with_alias("dev-node".to_string()); let mut repl = REPL::new(vm); repl.run(); // Starts interactive loop ``` -------------------------------- ### Start Interactive REPL Source: https://context7.com/fhaynes/iridium/llms.txt Launch the Iridium interactive Read-Eval-Print Loop (REPL) for command-line interaction. ```bash # Start interactive REPL iridium ``` -------------------------------- ### Configure and Bind VM for Cluster Source: https://context7.com/fhaynes/iridium/llms.txt Create a VM instance, assign an alias, and configure it to bind to a specific network address and port for cluster communication. Use `bind_cluster_server` to start listening for incoming connections. ```rust use iridium::vm::VM; use iridium::repl::REPL; // Create a VM configured for clustering let vm = VM::new() .with_alias("node-alpha".to_string()) .with_cluster_bind("127.0.0.1".to_string(), "2254".to_string()); // Start cluster server (listens for incoming connections) vm.bind_cluster_server(); // Join an existing cluster via REPL // >>> !start_cluster // >>> !join_cluster 192.168.1.100 2254 // >>> !cluster_members // Cluster configuration defaults: // DEFAULT_NODE_LISTEN_PORT = "2254" // DEFAULT_REMOTE_ACCESS_PORT = "2244" ``` -------------------------------- ### LOAD Instruction Example Source: https://context7.com/fhaynes/iridium/llms.txt Shows the usage of the LOAD opcode to load immediate values into integer registers. Explains how the assembler handles values exceeding 16 bits by splitting instructions. ```assembly // Assembly syntax: load $ # // Loads value into specified register (0-31) // Example: Load values and perform calculation let program = r"\ .data .code load $0 #100 ; Load 100 into register 0 load $1 #50 ; Load 50 into register 1 load $2 #25 ; Load 25 into register 2 hlt "; // Bytecode format: [opcode(1 byte), register(1 byte), value_high(1 byte), value_low(1 byte)] // LOAD opcode = 0, so: [0, 0, 0, 100] loads 100 into register 0 // For values > 65535, use LUI (Load Upper Immediate) for the upper bits let large_value_program = r"\ .data .code load $0 #70000 ; Assembler auto-splits: LOAD low bits, then LUI for upper bits hlt "; ``` -------------------------------- ### Create and Execute VM Source: https://context7.com/fhaynes/iridium/llms.txt Demonstrates creating a new VM instance, configuring it with an alias and cluster binding, loading assembly code, and executing it. Handles potential assembly errors. ```rust use iridium::vm::VM; use iridium::assembler::Assembler; // Create a new VM instance let mut vm = VM::new(); // Configure VM with an alias and cluster binding let mut vm = VM::new() .with_alias("node-1".to_string()) .with_cluster_bind("127.0.0.1".to_string(), "2254".to_string()); // Load and run a program from assembly let mut asm = Assembler::new(); let program_source = r"\ .data .code load $0 #100 load $1 #50 add $0 $1 $2 hlt "; match asm.assemble(program_source) { Ok(bytecode) => { vm.add_bytes(bytecode); let events = vm.run(); // Run until HLT instruction println!("Register 2 value: {}", vm.registers[2]); // Output: 150 } Err(errors) => { for error in errors { eprintln!("Assembly error: {:?}", error); } } } ``` -------------------------------- ### Configure Node Settings via CLI Source: https://context7.com/fhaynes/iridium/llms.txt Set node-specific configurations such as alias, server listen host, and port using command-line arguments. ```bash # Configure node settings iridium --node-alias my-node --server-listen-host 0.0.0.0 --server-listen-port 2254 ``` -------------------------------- ### Run Iridium Assembly File Source: https://context7.com/fhaynes/iridium/llms.txt Execute an Iridium assembly program directly from a file using the `iridium` binary. ```bash # Run an assembly file directly iridium program.iasm ``` -------------------------------- ### Iridium Assembly: Load Upper Immediate (LUI) Source: https://context7.com/fhaynes/iridium/llms.txt Demonstrates the LUI instruction for building 32-bit values by shifting and ORing immediate values. ```rust let lui_program = r" .data .code load $0 #0 ; Start with 0 lui $0 1 0 ; Shift and OR: $0 = ($0 << 8) | 1, then ($0 << 8) | 0 hlt "; ``` -------------------------------- ### Iridium Assembly: Loop Instructions CLOOP and LOOP Source: https://context7.com/fhaynes/iridium/llms.txt Shows how to implement loops using CLOOP to set the counter and LOOP to decrement and conditionally jump. The loop counter is managed internally. ```rust let loop_program = r" .data .code load $0 #0 ; Accumulator load $1 #1 ; Increment value cloop #10 ; Set loop counter to 10 iteration: add $0 $1 $0 ; $0 += 1 loop @iteration ; Decrement counter, jump if > 0 hlt ; $0 = 10 after loop completes "; ``` -------------------------------- ### Iridium Assembly: Manual Stack Manipulation with PUSH and POP Source: https://context7.com/fhaynes/iridium/llms.txt Illustrates direct stack manipulation using PUSH and POP instructions. Data is pushed and popped in LIFO order. ```rust let stack_program = r" .data .code load $0 #10 load $1 #20 load $2 #30 push $0 ; Push 10 onto stack push $1 ; Push 20 onto stack push $2 ; Push 30 onto stack pop $3 ; $3 = 30 (LIFO order) pop $4 ; $4 = 20 pop $5 ; $5 = 10 hlt "; ``` -------------------------------- ### Enable Remote Access via CLI Source: https://context7.com/fhaynes/iridium/llms.txt Configure the Iridium VM to enable remote access by specifying the listen host and port. ```bash # Enable remote access iridium --enable-remote-access --listen-host 0.0.0.0 --listen-port 2244 ``` -------------------------------- ### Construct and Verify Bytecode Header Source: https://context7.com/fhaynes/iridium/llms.txt Manually construct bytecode with the Iridium header, including the magic number and reserved space. Verify the header prefix and calculate the expected total bytecode length. ```rust use iridium::assembler::{PIE_HEADER_PREFIX, PIE_HEADER_LENGTH}; use iridium::vm::VM; // Header structure: // Bytes 0-3: Magic number [0x45, 0x50, 0x49, 0x45] = "EPIE" // Bytes 4-63: Reserved (zeros) // Bytes 64-67: Read-only section length (u32 little-endian) // Bytes 68+: Read-only data section // After RO: Executable bytecode // Each instruction is 32 bits (4 bytes): // Byte 0: Opcode // Bytes 1-3: Operands (register numbers, immediate values) // Manually construct bytecode with header let program = vec![ 0, 0, 1, 244, // LOAD $0 #500 5, 0, 0, 0, // HLT ]; let bytecode = VM::prepend_header(program); // Verify header assert_eq!(&bytecode[0..4], &PIE_HEADER_PREFIX); assert_eq!(bytecode.len(), PIE_HEADER_LENGTH + 4 + 8); // header + offset + instructions ``` -------------------------------- ### Run in Daemon Mode via CLI Source: https://context7.com/fhaynes/iridium/llms.txt Execute the Iridium VM in daemon mode for background operation. ```bash # Run in daemon mode (background) iridium --daemon true ``` -------------------------------- ### Iridium Assembly: Function Call with CALL and RET Source: https://context7.com/fhaynes/iridium/llms.txt Demonstrates function calls using CALL and RET instructions. CALL pushes the return address onto the stack, and RET restores it. ```rust let function_program = r" .data .code load $0 #100 ; Initial value call @multiply ; Call function, return address pushed to stack hlt ; Program ends here after function returns multiply: load $1 #2 ; Multiplier mul $0 $1 $0 ; $0 = $0 * 2 ret ; Return to caller, pops return address from stack "; ``` -------------------------------- ### Set Data Directory via CLI Source: https://context7.com/fhaynes/iridium/llms.txt Configure the root directory for Iridium data files. ```bash # Set data directory iridium --data-root-dir /var/lib/iridium/ ``` -------------------------------- ### Perform Arithmetic Operations in Iridium Source: https://context7.com/fhaynes/iridium/llms.txt Demonstrates integer and floating-point arithmetic instructions. DIV also updates the VM's remainder field. ```rust let arithmetic_program = r" .data .code load $0 #20 ; $0 = 20 load $1 #5 ; $1 = 5 add $0 $1 $2 ; $2 = $0 + $1 = 25 sub $0 $1 $3 ; $3 = $0 - $1 = 15 mul $0 $1 $4 ; $4 = $0 * $1 = 100 div $0 $1 $5 ; $5 = $0 / $1 = 4, remainder stored in vm.remainder hlt "; ``` ```rust let float_program = r" .data .code loadf64 $0 #100 ; float_registers[0] = 100.0 loadf64 $1 #30 ; float_registers[1] = 30.0 addf64 $0 $1 $2 ; float_registers[2] = 130.0 hlt "; ``` -------------------------------- ### Execute Comparison Instructions Source: https://context7.com/fhaynes/iridium/llms.txt Compares registers to update the VM's equal_flag for conditional logic. ```rust let comparison_program = r" .data .code load $0 #100 load $1 #50 load $2 #100 eq $0 $1 ; equal_flag = false (100 != 50) eq $0 $2 ; equal_flag = true (100 == 100) neq $0 $1 ; equal_flag = true (100 != 50) gt $0 $1 ; equal_flag = true (100 > 50) gte $0 $2 ; equal_flag = true (100 >= 100) lt $1 $0 ; equal_flag = true (50 < 100) lte $0 $2 ; equal_flag = true (100 <= 100) hlt "; ``` ```rust let float_compare = r" .data .code loadf64 $0 #100 loadf64 $1 #100 eqf64 $0 $1 ; Uses epsilon comparison for floating-point equality hlt "; ``` -------------------------------- ### Set Execution Threads via CLI Source: https://context7.com/fhaynes/iridium/llms.txt Specify the number of threads to be used for bytecode execution. ```bash # Specify number of execution threads iridium --threads 4 ``` -------------------------------- ### Iridium Assembly: String Output with PRTS Source: https://context7.com/fhaynes/iridium/llms.txt Demonstrates printing null-terminated strings using the PRTS instruction. Strings are defined in the .data section using .asciiz. ```rust let string_program = r" .data greeting: .asciiz 'Hello, Iridium!' newline: .asciiz '\n' .code prts @greeting ; Print 'Hello, Iridium!' prts @newline ; Print newline hlt "; ``` -------------------------------- ### Two-Pass Assembly Process Source: https://context7.com/fhaynes/iridium/llms.txt Illustrates the two-pass assembly process for converting Iridium Assembly Language (IASM) into bytecode. Includes handling data sections, labels, and executing the assembled program. ```rust use iridium::assembler::Assembler; use iridium::vm::VM; let mut asm = Assembler::new(); // Assembly program with data section and labels let source = r"\ .data hello: .asciiz 'Hello, World!' count: .integer #42 .code load $0 #10 load $1 #1 load $2 #0 loop_start: inc $2 neq $0 $2 djmpe @loop_start prts @hello hlt "; match asm.assemble(source) { Ok(bytecode) => { println!("Bytecode length: {} bytes", bytecode.len()); println!("Symbol table: {:?}", asm.symbols); // Execute the assembled program let mut vm = VM::new(); vm.add_bytes(bytecode); vm.run(); } Err(errors) => { for error in errors { eprintln!("Error: {:?}", error); } } } ``` -------------------------------- ### Control Program Flow with Jump Instructions Source: https://context7.com/fhaynes/iridium/llms.txt Uses absolute, relative, and conditional jumps to manage execution flow based on the equal_flag. ```rust let jump_program = r" .data .code load $0 #10 ; Counter = 10 load $1 #1 ; Decrement value load $2 #0 ; Zero for comparison loop: dec $0 ; Decrement counter neq $0 $2 ; Set equal_flag = ($0 != $2) djmpe @loop ; Jump to loop if not equal hlt ; Exit when counter reaches 0 "; ``` ```rust let jmpe_program = r" .data .code load $0 #5 ; Counter load $1 #0 ; Zero load $3 #68 ; Address to jump to (calculated based on header + code offset) test: dec $0 eq $0 $1 ; equal_flag = ($0 == $1) jmpe $3 ; Jump to address in $3 if equal djmpe @test ; Otherwise loop back hlt "; ``` -------------------------------- ### Iridium Assembly: Bitwise Operations Source: https://context7.com/fhaynes/iridium/llms.txt Shows various bitwise operations including AND, OR, XOR, NOT, SHL (shift left), and SHR (shift right). Shift operations default to 16 bits if 0 is specified. ```rust let bitwise_program = r" .data .code load $0 #0b1010 ; 10 in binary load $1 #0b1100 ; 12 in binary and $0 $1 $2 ; $2 = 0b1000 = 8 or $0 $1 $3 ; $3 = 0b1110 = 14 xor $0 $1 $4 ; $4 = 0b0110 = 6 not $0 $5 ; $5 = bitwise NOT of $0 ; Shift operations load $6 #4 ; Value to shift shl $6 2 ; Shift left by 2: $6 = 16 shr $6 1 ; Shift right by 1: $6 = 8 hlt "; ``` -------------------------------- ### Manage Heap Memory Operations Source: https://context7.com/fhaynes/iridium/llms.txt Allocates heap space and performs read/write operations between registers and memory. ```rust let memory_program = r" .data .code load $0 #1024 ; Bytes to allocate aloc $0 ; Expand heap by 1024 bytes load $0 #0 ; Heap offset = 0 load $1 #42 ; Value to store setm $0 $1 ; Store 42 at heap[0..4] loadm $0 $2 ; Load heap[0..4] into register 2 hlt "; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.