Skip to content

Commit

Permalink
Minimal documentation for phoron_asm
Browse files Browse the repository at this point in the history
  • Loading branch information
timmyjose committed Mar 20, 2023
1 parent f5a18f2 commit d560178
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "phoron_asm"
description = "A Jasmin-compatible Assembler for the JVM"
version = "1.0.1"
version = "1.0.2"
authors = ["Timmy Jose"]
homepage = "https://github.com/oyi-lang/phoron_asm"
documentation = "https://docs.rs/phoron_asm/1.0.0/phoron_asm/"
documentation = "https://docs.rs/phoron_asm/1.0.2/phoron_asm/"
repository = "https://github.com/oyi-lang/phoron_asm"
readme = "README.md"
license-file = "LICENSE"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Running it:
$ cargo run --release
Class file generated
:$ javap -v samples/HelloWorld.class
$ javap -v samples/HelloWorld.class
Classfile /Users/z0ltan/dev/playground/phoron_asm_demo/samples/HelloWorld.class
Last modified 19-Mar-2023; size 389 bytes
SHA-256 checksum 533a66c051831cba84a32b20d38c4bb20d68b78aabc137d7c7fb3cc864ff8bf9
Expand Down Expand Up @@ -263,7 +263,7 @@ Constant pool:
}
SourceFile: "./samples/HelloWorld.pho"
~/dev/playground/phoron_asm_demo:$ java -cp "./samples" HelloWorld
$ java -cp "./samples" HelloWorld
Hello, world
```
Expand Down
5 changes: 5 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! The Phoron AST.
//!
//! The model is kept as simple as possible in order to allow provide good type-checking as well as
//! east and direct translation into the `ClassFile` format required by the `Codegen` module.
use std::default::Default;

pub mod attributes;
Expand Down
2 changes: 2 additions & 0 deletions src/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The interface to `phoron_core`. This module constructs the `ClassFile` object needed by
//! `phoron_core` in order to generate the actual `class` file.
use crate::{
ast::{attributes::*, *},
cp_analyzer::constant_pool::*,
Expand Down
6 changes: 6 additions & 0 deletions src/cp_analyzer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! A Phoron abstraction of the JVM's Constant Pool (arguably the most important aspect of the JVM
//! bytecode format).
//!
//! The indxeing of the Constant Pool elements is deterministic (the ordering is left unspecified
//! in the JVM specification) and follows a top-down recursive approach.
//!
use crate::ast::{attributes::*, *};

pub mod constant_pool;
Expand Down
4 changes: 4 additions & 0 deletions src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! A simple diagnostic module for Phoron.
//!
//! Provides formatted error reporting via the `emitter` submodule as well as a fail-fast version
//! that exits immediately.
use crate::sourcefile::{Location, SourceFile, Span};
use std::error::Error;

Expand Down
3 changes: 3 additions & 0 deletions src/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Takes a `SourceFile` representing the assembly source code, and produces a stream of tokens
//! for consumption by the parser.
use std::{
error::Error,
fmt,
Expand Down
3 changes: 3 additions & 0 deletions src/lexer/token.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Represents a valid token in the Phoron (Jasmin) assembly language.
//! Unlike Jasmin, each JVM opcode becomes its own type enabling better type-checking and error
//! reporting.
use crate::sourcefile::Span;

#[derive(Debug)]
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! `Phoron` is a [Jasmin](https://jasmin.sourceforge.net/) compatible assembler for the JVM.
//!
//! `phoron_asm` provides the actual assembler for the assembly language whereas `phoron_core`
//! handles the low-level `class` file serialisation and deserialisation.
//!
pub mod ast;
pub mod codegen;
pub mod cp_analyzer;
Expand Down
7 changes: 7 additions & 0 deletions src/parser/levenshtein.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//! A utility module to provide suggestions for possibly misspelt JVM opcodes. Since the assembly
//! language allows a lot of overlap in terms of labels, opcodes, and other syntactic elements,
//! type-checking is necessarily more difficult especially when coupled with error recovery via
//! skipping tokens (panic mode).
//! This module calculates the Levenshtein distance between a (possible) label and a JVM opcode,
//! and given a sufficient probability, provides recommendations of the closest matching JVM
//! opcode.
use std::cmp::{max, min};

const LEVENSHTEIN_THRESHOLD: f64 = 0.50;
Expand Down
4 changes: 4 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! The Phoron Parser takes in a lexer and produces a token on demand (syntax-driven).
//! It also uses the `Span` information collected during tokenisation to provide goood
//! error recovery and error reporting.
use crate::{
ast::*,
diagnostics::DiagnosticManager,
Expand Down
2 changes: 1 addition & 1 deletion src/parser/type_descriptor_parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A parser for type descriptors as per the JVM specification
//! A parser for type descriptors as per the JVM specification.
use crate::ast::{PhoronBaseType, PhoronFieldDescriptor, PhoronReturnDescriptor};
use std::{error::Error, fmt, iter::Peekable, str::Chars};
Expand Down
4 changes: 4 additions & 0 deletions src/sourcefile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Abstract representation of a physical source file in the file system. The `SourceFile` is
//! used by the lexer for tokenisation, as well as to provide `Span`s over the actual source code
//! for error reporting during parsing and type-checking.
use std::{convert::From, fmt::Debug, fs, io, ops::Sub, path::Path};

/// Absolute offset from the beginning of the byte stream
Expand Down

0 comments on commit d560178

Please sign in to comment.