from-scratch/lang/tests/ast.rs
2025-10-29 20:39:32 +01:00

56 lines
1.2 KiB
Rust

#[path = "shared/shared.rs"]
mod util;
#[repr(C)]
struct Ast {
nodes: util::vec::Vec<AstNode>,
}
#[repr(C)]
struct Argument {
name: *const u8,
name_len: usize,
arg_type: u8,
}
#[repr(C)]
#[derive(Debug)]
struct AstNode {
node_type: u8,
data: usize,
}
use util::FFISlice;
unsafe extern "C" {
unsafe fn bump_init();
unsafe fn parse_func(ast: *mut Ast) -> u64;
unsafe fn parse_args(ast: *mut Ast) -> FFISlice;
unsafe fn parse_expr(ast: *mut Ast) -> u64;
unsafe fn parse_binary_expr(ast: *mut Ast) -> u64;
unsafe fn parse_primary_expr(ast: *mut Ast) -> u64;
unsafe fn parse_statement(ast: *mut Ast) -> u64;
unsafe fn parse_block(ast: *mut Ast) -> u64;
unsafe fn tokeniser_init_buf(bytes: *const u8, len: usize) -> ();
}
fn main() {
unsafe {
bump_init();
}
println!("Bump allocator initialized.");
let src = b"3 + 4";
unsafe {
tokeniser_init_buf(src.as_ptr(), src.len());
let mut ast = Ast {
nodes: util::vec::Vec::new(),
};
let expr_id = parse_expr(&mut ast);
println!("Parsed expression with ID: {}", expr_id);
println!("{:#?}", ast.nodes.as_slice());
}
}