Skip to content

Commit

Permalink
Finalize Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danii committed Aug 11, 2021
1 parent 052a563 commit d7f7737
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Hematita Da Lua
===============
![](https://img.shields.io/crates/d/hematitia?style=for-the-badge) ![](https://img.shields.io/tokei/lines/github/danii/hematita?style=for-the-badge) ![](https://img.shields.io/crates/v/hematita?style=for-the-badge) ![](https://img.shields.io/badge/compiler%20version-unknown-007EC6?style=for-the-badge)
![](https://img.shields.io/crates/d/hematitia?style=for-the-badge) ![](https://img.shields.io/tokei/lines/github/danii/hematita?style=for-the-badge) ![](https://img.shields.io/crates/v/hematita?style=for-the-badge) ![](https://img.shields.io/badge/compiler%20version-1.53.0-007EC6?style=for-the-badge)
<br>
[![](https://img.shields.io/badge/crates.io-E6B14C?style=for-the-badge&logo=rust&logoColor=000000)](https://crates.io/crates/hematita) [![](https://img.shields.io/badge/lib.rs-282A36?style=for-the-badge&logo=rust)](https://lib.rs/crates/hematita) [![](https://img.shields.io/badge/github.com-24292E?style=for-the-badge&logo=github)](https://github.com/danii/hematita) [![](https://img.shields.io/badge/sponsor_me-FF69B4?style=for-the-badge&logo=github%20sponsors&logoColor=FFFFFF)](https://github.com/sponsors/danii) [![](https://img.shields.io/badge/telegram_group-26A5E4?style=for-the-badge&logo=telegram)](https://t.me/danii_hangout)

Expand Down Expand Up @@ -87,13 +87,15 @@ Hematita is composed of four main segments. Those being, `ast::lexer`, `ast::par
Each segment can be used on it's own, but they're best used all together. If you'd like to just lex and parse lua code, the `ast` module can totally handle that. If you'd like to just run hand crafted bytecode, the `vm` module is well suited for it. But the real effect comes from stringing everything together, to form a complete interpreter.

### The Lexer
The lexer just turns a stream of characters into a stream of `Token`s. It's effectively just an operation over an iterator. You can read it's docs [here]().
The lexer just turns a stream of characters into a stream of `Token`s. It's effectively just an operation over an iterator. You can read it's docs [here](https://docs.rs/hematita/0.1.0/hematita/ast/lexer/index.html), note that they are incomplete.

### The Parser
The parser takes a stream of tokens, and turns it into a `Block`. A `Block` is just a `Vec` of `Statement`s. `Statement`s are an internal representation of a Lua statement. You can read it's docs [here](), note that they are incomplete.
The parser takes a stream of tokens, and turns it into a `Block`. A `Block` is just a `Vec` of `Statement`s. `Statement`s are an internal representation of a Lua statement. You can read it's docs [here](https://docs.rs/hematita/0.1.0/hematita/ast/parser/index.html), note that they are incomplete.

### The Compiler
The compiler takes a `Block`, and produces a `Chunk`. A `Chunk` is just a `Vec` of `OpCode`s, with some metadata. It is effectively a one to one transformation, so no error handling is needed. You can read it's docs [here](), note that they are incomplete.
The compiler takes a `Block`, and produces a `Chunk`. A `Chunk` is just a `Vec` of `OpCode`s, with some metadata. It is effectively a one to one transformation, so no error handling is needed. You can read it's docs [here](https://docs.rs/hematita/0.1.0/hematita/compiler/index.html), note that they are incomplete.

### The Virtual Machine
The virtual machine takes a `Function`, and executes it. A `Function` is just an instantiated form of a `Chunk`, with associated up-values. It can be made just by calling `into` on a `Chunk`. The virtual machine is effectively a match statement over every `OpCode`, and the code that implements it. You can read it's docs [here](), note that they are incomplete.
The virtual machine takes a `Function`, and executes it. A `Function` is just an instantiated form of a `Chunk`, with associated up-values. It can be made just by calling `into` on a `Chunk`. The virtual machine is effectively a match statement over every `OpCode`, and the code that implements it. You can read it's docs [here](https://docs.rs/hematita/0.1.0/hematita/vm/index.html), note that they are incomplete.

[internals]: #the-internals
2 changes: 1 addition & 1 deletion hematita/src/ast/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<I> TokenIterator<I>
}
}

/// Parses a block of lua tokens.
/// Parses a block of Lua tokens.
pub fn parse_block<I>(iter: &mut TokenIterator<I>) -> Result<Block>
where I: Iterator<Item = LexerResult<Token>> {
let mut statements = Vec::new();
Expand Down
5 changes: 5 additions & 0 deletions hematita/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ macro_rules! insert_byte_code {
}}
}

/// Compiles Lua statements into bytecode.
pub fn compile_block(block: &Block) -> Chunk {
let mut compiler = Generator::new();
compiler.compile(block);
compiler.finish()
}

/// Compiles Lua statements into bytecode, as a Lua function.
///
/// The only difference between this function and [compile_block], is that this
/// function accepts arguments, and assigns received arguments to them.
pub fn compile_function(block: &Block, arguments: &[String],
up_values: HashMap<String, (usize, bool)>, method: bool) -> Chunk {
let mut compiler = Generator {up_values, ..Generator::new()};
Expand Down

0 comments on commit d7f7737

Please sign in to comment.