21 breaking releases

new 0.35.0 Dec 14, 2025
0.22.0 Dec 13, 2025
0.16.0 Nov 26, 2025

#134 in Programming languages

Download history 809/week @ 2025-11-23 3043/week @ 2025-11-30 1923/week @ 2025-12-07

5,775 downloads per month
Used in 3 crates (2 directly)

MIT license

415KB
9K SLoC

Fusabi Frontend - Parser, Typechecker, and Bytecode Compiler

This crate implements the frontend of the Fusabi (F# Script Runtime System), responsible for parsing F# source code into an AST, performing type checking, and compiling to bytecode for the Fusabi VM.

Modules

  • ast: Core AST (Abstract Syntax Tree) definitions
  • lexer: Lexer/Tokenizer for Mini-F# source code
  • parser: Recursive-descent parser for Mini-F# expressions
  • compiler: Bytecode compiler (AST → Bytecode)
  • types: Type system infrastructure for Hindley-Milner type inference
  • inference: Type inference engine (Hindley-Milner algorithm)
  • typed_ast: Optional typed AST with type annotations
  • span: Source location tracking for error reporting
  • error: Error types with beautiful formatting and suggestions
  • modules: Module system for code organization

Example

use fusabi_frontend::ast::{Expr, Literal, BinOp};
use fusabi_frontend::lexer::Lexer;
use fusabi_frontend::parser::Parser;
use fusabi_frontend::compiler::{Compiler, CompileOptions};
use fusabi_frontend::inference::TypeInference;
use fusabi_frontend::types::TypeEnv;

// Full pipeline: source -> tokens -> AST -> type check -> bytecode
let source = "let x = 42 in x + 1";
let mut lexer = Lexer::new(source);
let tokens = lexer.tokenize().unwrap();
let mut parser = Parser::new(tokens);
let ast = parser.parse().unwrap();

// Type check
let mut infer = TypeInference::new();
let env = TypeEnv::new();
let ty = infer.infer_and_solve(&ast, &env).unwrap();

// Compile without type checking (backward compatible)
let chunk = Compiler::compile(&ast).unwrap();

// Or compile with type checking enabled
let options = CompileOptions {
    enable_type_checking: true,
    ..Default::default()
};
let chunk_checked = Compiler::compile_with_options(&ast, options).unwrap();

// Chunk is ready for VM execution
assert!(chunk.instructions.len() > 0);

Fusabi Frontend

The compiler frontend for the Fusabi scripting engine. Handles lexing, parsing, and bytecode generation.

Features

  • F# Dialect: Supports a subset of F# including let-bindings, pattern matching, records, and DUs.
  • Type Inference: Hindley-Milner type inference engine.
  • Compiler: Emits optimized bytecode for fusabi-vm.

Usage

use fusabi_frontend::{Lexer, Parser, Compiler};

let source = "let x = 42";
let mut lexer = Lexer::new(source);
let tokens = lexer.tokenize()?;
let mut parser = Parser::new(tokens);
let ast = parser.parse()?;
let chunk = Compiler::compile(&ast)?;

License

MIT

Dependencies

~1MB
~19K SLoC