Skip to content

Commit

Permalink
Replace rug::Integer with num_bigint::BigInt
Browse files Browse the repository at this point in the history
rug::Integer is dependent on gmp-mpfr-sys v1.1.10, which doesn't work
for wasm-unknown-unknown.
  • Loading branch information
KronicDeth committed Apr 17, 2019
1 parent af5453b commit 93e1a6b
Show file tree
Hide file tree
Showing 17 changed files with 452 additions and 286 deletions.
15 changes: 14 additions & 1 deletion Cargo.lock

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

14 changes: 11 additions & 3 deletions liblumen_beam/src/beam/reader/beam_file.rs
Expand Up @@ -42,7 +42,9 @@ impl<C: Chunk> BeamFile<C> {
/// Returns all chunks in the order they were encountered in the origin BEAM file
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.Beam#chunkCollection` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/Beam.kt#L70) in Kotlin.
/// - [`org.elixir_lang.beam.Beam#chunkCollection` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/Beam.kt#L70) in Kotlin.
pub fn chunks(&self) -> Vec<&C> {
let mut result: Vec<&C> = Vec::new();
for id in &self.order {
Expand All @@ -68,15 +70,21 @@ impl<C: Chunk> BeamFile<C> {
/// }
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.Beam#chunk` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/Beam.kt#L68-L69) in Kotlin.
/// - [`org.elixir_lang.beam.Beam#chunk` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/Beam.kt#L68-L69) in
/// Kotlin.
pub fn get_chunk(&self, id: &Id) -> Option<&C> {
self.chunks.get(id)
}

/// Returns whichever chunk is the atom chunk, if it exists
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.Beam#atoms` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/Beam.kt#L63-L65) in Kotlin.
/// - [`org.elixir_lang.beam.Beam#atoms` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/Beam.kt#L63-L65) in
/// Kotlin.
pub fn atoms(&self) -> Option<&C> {
match self.get_chunk(b"Atom") {
Some(c) => Some(c),
Expand Down
74 changes: 58 additions & 16 deletions liblumen_beam/src/beam/reader/chunk.rs
Expand Up @@ -115,7 +115,10 @@ impl Chunk for RawChunk {

/// ## Alternative Implementations
///
/// - [`org.elixir_lang.beam.chunk.Chunk.from` in IntelliJ ELixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Chunk.java#L34-L52) in Kotlin
/// - [`org.elixir_lang.beam.chunk.Chunk.from` in IntelliJ
/// ELixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Chunk.java#
/// L34-L52) in Kotlin
fn decode_data<R: Read>(id: &Id, mut reader: R) -> Result<Self>
where
Self: Sized,
Expand Down Expand Up @@ -210,8 +213,14 @@ impl Chunk for AtomChunk {
/// - [StrTChunk](StrTChunk) for strings from the string pool used in `bs_*` operations.
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.Code` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Code.kt) in Kotlin
/// - [`org.elixir_lang.beam.chunk.code.Operation#assembly` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/code/Operation.kt#L23-L164) in Kotlin for an example of how to disassemble the individual byte code operations back to BEAM Assembly.
/// - [`org.elixir_lang.beam.chunk.Code` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Code.kt) in Kotlin
/// - [`org.elixir_lang.beam.chunk.code.Operation#assembly` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/code/Operation.kt#
/// L23-L164) in Kotlin for an example of how to disassemble the individual byte code operations
/// back to BEAM Assembly.
#[derive(Debug, PartialEq, Eq)]
pub struct CodeChunk {
/// Length of the information fields before code.
Expand All @@ -238,7 +247,10 @@ impl Chunk for CodeChunk {
}

/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.Code.Companion.from` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Code.kt#L171-L216) in Kotlin
/// - [`org.elixir_lang.beam.chunk.Code.Companion.from` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Code.kt#L171-L216)
/// in Kotlin
/// NOTE: This implementation decodes the operations as it loads the data instead of storing it
/// as raw bytes.
fn decode_data<R: Read>(id: &Id, mut reader: R) -> Result<Self>
Expand Down Expand Up @@ -275,7 +287,9 @@ impl Chunk for CodeChunk {
/// `'static str`.
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.Strings` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Strings.kt) in Kotlin
/// - [`org.elixir_lang.beam.chunk.Strings` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Strings.kt) in Kotlin
#[derive(Debug, PartialEq, Eq)]
pub struct StrTChunk {
/// Concatenated strings.
Expand All @@ -287,7 +301,9 @@ impl Chunk for StrTChunk {
}

/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.Strings.Companion.from`](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Strings.kt#L9) in Kotlin
/// - [`org.elixir_lang.beam.chunk.Strings.Companion.from`](https://github.com/KronicDeth/
/// intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/
/// chunk/Strings.kt#L9) in Kotlin
fn decode_data<R: Read>(id: &Id, mut reader: R) -> Result<Self>
where
Self: Sized,
Expand All @@ -314,7 +330,9 @@ impl Chunk for StrTChunk {
/// operands for the MFA.
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.Imports` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Imports.kt) in Kotlin
/// - [`org.elixir_lang.beam.chunk.Imports` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Imports.kt) in Kotlin
#[derive(Debug, PartialEq, Eq)]
pub struct ImpTChunk {
/// The list of imported functions.
Expand All @@ -326,7 +344,9 @@ impl Chunk for ImpTChunk {
}

/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.Imports.Companion.from`](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Imports.kt#L14-L32)
/// - [`org.elixir_lang.beam.chunk.Imports.Companion.from`](https://github.com/KronicDeth/
/// intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/
/// chunk/Imports.kt#L14-L32)
fn decode_data<R: Read>(id: &Id, mut reader: R) -> Result<Self>
where
Self: Sized,
Expand Down Expand Up @@ -365,7 +385,10 @@ impl Chunk for ImpTChunk {
/// The format is the same as [LocTChunk](LocTChunk).
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.CallDefinitions` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/CallDefinitions.java) in Java
/// - [`org.elixir_lang.beam.chunk.CallDefinitions` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/CallDefinitions.java)
/// in Java
#[derive(Debug, PartialEq, Eq)]
pub struct ExpTChunk {
/// The list of exported functions.
Expand All @@ -377,7 +400,10 @@ impl Chunk for ExpTChunk {
}

/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.CallDefinitions.from(Chunk, Chunk.TypeID.EXPT, Atoms)`](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/CallDefinitions.java#L52-L76) in Java
/// - [`org.elixir_lang.beam.chunk.CallDefinitions.from(Chunk, Chunk.TypeID.EXPT,
/// Atoms)`](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/CallDefinitions.
/// java#L52-L76) in Java
fn decode_data<R: Read>(id: &Id, mut reader: R) -> Result<Self>
where
Self: Sized,
Expand Down Expand Up @@ -411,7 +437,9 @@ impl Chunk for ExpTChunk {
/// `term_to_binary`.
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.Literals` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Literals.kt) in Kotlin
/// - [`org.elixir_lang.beam.chunk.Literals` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Literals.kt) in Kotlin
#[derive(Debug, PartialEq, Eq)]
pub struct LitTChunk {
/// The list of literal terms.
Expand All @@ -426,7 +454,9 @@ impl Chunk for LitTChunk {
}

/// ## Alternative Implementations
/// - [`org.elixir_lang.bream.chunk.Literals.Companion.from`](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Literals.kt#L20-L46) in Kotlin
/// - [`org.elixir_lang.bream.chunk.Literals.Companion.from`](https://github.com/KronicDeth/
/// intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/
/// chunk/Literals.kt#L20-L46) in Kotlin
/// NOTE: This implementation converts the raw bytes to JInterface objects
fn decode_data<R: Read>(id: &Id, mut reader: R) -> Result<Self>
where
Expand Down Expand Up @@ -476,7 +506,10 @@ impl Chunk for LitTChunk {
/// The format is the same as [ExpTChunk](ExpTChunk).
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.CallDefinitions` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/CallDefinitions.java) in Java
/// - [`org.elixir_lang.beam.chunk.CallDefinitions` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/CallDefinitions.java)
/// in Java
#[derive(Debug, PartialEq, Eq)]
pub struct LocTChunk {
/// The list of local functions.
Expand All @@ -488,7 +521,10 @@ impl Chunk for LocTChunk {
}

/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.CallDefinitions.from(Chunk, Chunk.TypeID.LOCT, Atoms)`](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/CallDefinitions.java#L52-L76) in Java
/// - [`org.elixir_lang.beam.chunk.CallDefinitions.from(Chunk, Chunk.TypeID.LOCT,
/// Atoms)`](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/CallDefinitions.
/// java#L52-L76) in Java
fn decode_data<R: Read>(id: &Id, mut reader: R) -> Result<Self>
where
Self: Sized,
Expand Down Expand Up @@ -529,7 +565,10 @@ impl Chunk for LocTChunk {
/// 6. Old Unique - a number that _was_ used to uniquely identify the anonymous function
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.Functions` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Functions.kt) in Kotlin
/// - [`org.elixir_lang.beam.chunk.Functions` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Functions.kt) in
/// Kotlin
#[derive(Debug, PartialEq, Eq)]
pub struct FunTChunk {
/// The list of anonymous functions.
Expand Down Expand Up @@ -698,7 +737,10 @@ impl Chunk for DbgiChunk {
}

/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.debug_info` namespace in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/tree/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/debug_info) handles all current variants, both Erlang and Elixir and invalid forms thereof.
/// - [`org.elixir_lang.beam.chunk.debug_info` namespace in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/tree/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/debug_info)
/// handles all current variants, both Erlang and Elixir and invalid forms thereof.
fn decode_data<R: Read>(id: &Id, mut reader: R) -> Result<Self>
where
Self: Sized,
Expand Down
10 changes: 8 additions & 2 deletions liblumen_beam/src/beam/reader/chunk/aux.rs
Expand Up @@ -16,7 +16,10 @@ impl Header {
}
}
/// Alternative Implementations
/// - [In `org.elixir_lang.bean.chunk.Chunk.from` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Chunk.java#L36-L40) in Java.
/// - [In `org.elixir_lang.bean.chunk.Chunk.from` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Chunk.java#
/// L36-L40) in Java.
pub fn decode<R: std::io::Read>(mut reader: R) -> std::io::Result<Self> {
let mut id = [0; 4];
reader.read_exact(&mut id)?;
Expand All @@ -31,7 +34,10 @@ impl Header {
}

/// ## Alternative Implementations
/// - [In `org.elixir_lang.bean.chunk.Chunk.from` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Chunk.java#L45) in Java.
/// - [In `org.elixir_lang.bean.chunk.Chunk.from` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/Chunk.java#L45) in
/// Java.
pub fn padding_size(data_size: u32) -> u32 {
(4 - data_size % 4) % 4
}
Expand Down
5 changes: 4 additions & 1 deletion liblumen_beam/src/beam/reader/parts.rs
Expand Up @@ -23,7 +23,10 @@ pub struct Atom {
/// An imported function.
///
/// ## Alternative Implementations
/// - [`org.elixir_lang.beam.chunk.imports.Import` in IntelliJ Elixir](https://github.com/KronicDeth/intellij-elixir/blob/2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/imports/Import.kt) in Kotlin
/// - [`org.elixir_lang.beam.chunk.imports.Import` in IntelliJ
/// Elixir](https://github.com/KronicDeth/intellij-elixir/blob/
/// 2f5c826040681e258e98c3e2f02b25985cd0766b/src/org/elixir_lang/beam/chunk/imports/Import.kt) in
/// Kotlin
#[derive(Debug, PartialEq, Eq)]
pub struct Import {
pub module: AtomId,
Expand Down
4 changes: 3 additions & 1 deletion liblumen_syntax/src/lexer/token.rs
Expand Up @@ -80,7 +80,9 @@ impl TryFrom<LexicalToken> for AtomToken {
use super::symbol::symbols;

match t {
LexicalToken(start, tok @ Token::Atom(_), end) => return Ok(AtomToken(start, tok, end)),
LexicalToken(start, tok @ Token::Atom(_), end) => {
return Ok(AtomToken(start, tok, end))
}
LexicalToken(start, Token::If, end) => {
return Ok(AtomToken(start, Token::Atom(symbols::If), end));
}
Expand Down
4 changes: 3 additions & 1 deletion liblumen_syntax/src/preprocessor/evaluator.rs
Expand Up @@ -724,7 +724,9 @@ fn eval_op_float(span: ByteSpan, x: f64, op: BinaryOp, y: f64) -> Result<Expr, P
BinaryOp::Add => Ok(Expr::Literal(Literal::Float(span, x + y))),
BinaryOp::Sub => Ok(Expr::Literal(Literal::Float(span, x - y))),
BinaryOp::Multiply => Ok(Expr::Literal(Literal::Float(span, x * y))),
BinaryOp::Divide if y == 0.0 => return Err(PreprocessorError::InvalidConstExpression(span)),
BinaryOp::Divide if y == 0.0 => {
return Err(PreprocessorError::InvalidConstExpression(span))
}
BinaryOp::Divide => Ok(Expr::Literal(Literal::Float(span, x / y))),
BinaryOp::Div => return Err(PreprocessorError::InvalidConstExpression(span)),
BinaryOp::Rem => return Err(PreprocessorError::InvalidConstExpression(span)),
Expand Down
3 changes: 2 additions & 1 deletion lumen_runtime/Cargo.toml
Expand Up @@ -19,7 +19,8 @@ lazy_static = "1.2"
libc = "0.2"
liblumen_arena = { path = "../liblumen_arena" }
log = "0.4"
rug = "1.3"
num-bigint = "0.2.2"
num-traits = "0.2.6"
signal-hook = "0.1"
xdg = "2.1"

Expand Down

0 comments on commit 93e1a6b

Please sign in to comment.