// Simplified bootstrap test for Ruchy self-hosting
// Core data structures
struct Token {
kind: String,
value: String
}
struct CompilerState {
tokens: Vec<Token>,
position: i32
}
// Simple tokenizer
fn tokenize(input: String) -> Vec<Token> {
vec![
Token { kind: "IDENT".to_string(), value: "test".to_string() },
Token { kind: "EQUAL".to_string(), value: "=".to_string() },
Token { kind: "NUMBER".to_string(), value: "42".to_string() }
]
}
// Simple parser
fn parse(tokens: Vec<Token>) -> String {
if tokens.len() > 0 {
let first_token = tokens[0]
format!("parsed_{}", first_token.value)
} else {
"empty".to_string()
}
}
// Simple code generator
fn generate(ast: String) -> String {
format!("fn main() {{ let result = \"{}\"; println!(\"{{}}\", result); }}", ast)
}
// Compiler pipeline using function composition and lambdas
let compile_step1 = input => tokenize(input)
let compile_step2 = tokens => parse(tokens)
let compile_step3 = ast => generate(ast)
// Higher-order function for pipeline
fn run_pipeline(input: String, step1, step2, step3) -> String {
let tokens = step1(input)
let ast = step2(tokens)
let code = step3(ast)
code
}
fn main() {
let source_code = "let test = 42".to_string()
println("=== Ruchy Self-Hosting Bootstrap Test ===")
println("Input:", source_code)
// Test the compilation pipeline
let compiled = run_pipeline(source_code, compile_step1, compile_step2, compile_step3)
println("Generated Rust code:")
println(compiled)
// Test lambda expressions and type inference
let double = x => x * 2
let result = double(21)
println("Lambda test result:", result)
println("=== Bootstrap Test SUCCESS ===")
}