Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Cargo.lock

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

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ cast_possible_truncation = "allow"
case_sensitive_file_extension_comparisons = "allow"

[workspace.dependencies]
rue-lexer = { path = "crates/rue-lexer", version = "0.7.1" }
rue-parser = { path = "crates/rue-parser", version = "0.7.1" }
rue-diagnostic = { path = "crates/rue-diagnostic", version = "0.7.1" }
rue-ast = { path = "crates/rue-ast", version = "0.7.1" }
rue-compiler = { path = "crates/rue-compiler", version = "0.7.1" }
rue-options = { path = "crates/rue-options", version = "0.7.1" }
rue-lir = { path = "crates/rue-lir", version = "0.7.1" }
rue-hir = { path = "crates/rue-hir", version = "0.7.1" }
rue-types = { path = "crates/rue-types", version = "0.7.1" }
rue-lexer = { path = "crates/rue-lexer", version = "0.8.0" }
rue-parser = { path = "crates/rue-parser", version = "0.8.0" }
rue-diagnostic = { path = "crates/rue-diagnostic", version = "0.8.0" }
rue-ast = { path = "crates/rue-ast", version = "0.8.0" }
rue-compiler = { path = "crates/rue-compiler", version = "0.8.0" }
rue-options = { path = "crates/rue-options", version = "0.8.0" }
rue-lir = { path = "crates/rue-lir", version = "0.8.0" }
rue-hir = { path = "crates/rue-hir", version = "0.8.0" }
rue-types = { path = "crates/rue-types", version = "0.8.0" }
anyhow = "1.0.98"
clvm-traits = "0.28.1"
clvm-utils = "0.28.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-ast"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "An implementation of the Abstract Syntax Tree for the Rue compiler."
Expand Down
7 changes: 7 additions & 0 deletions crates/rue-ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,13 @@ impl AstStructBinding {
}

impl AstStructFieldBinding {
pub fn spread(&self) -> Option<SyntaxToken> {
self.syntax()
.children_with_tokens()
.filter_map(SyntaxElement::into_token)
.find(|token| token.kind() == T![...])
}

pub fn name(&self) -> Option<SyntaxToken> {
self.syntax()
.children_with_tokens()
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-cli"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "A CLI tool for invoking the Rue compiler."
Expand Down
11 changes: 5 additions & 6 deletions crates/rue-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,13 @@ fn build(args: BuildArgs) -> Result<()> {
};

if args.hex && args.hash {
eprintln!("{}", "Cannot use both `--hex` and `--hash`".red().bold());
process::exit(1);
}

if args.hex {
println!("{}", hex::encode(node_to_bytes(&allocator, program)?));
println!();
println!("{}", tree_hash(&allocator, program));
} else if args.hex {
println!("{}", hex::encode(node_to_bytes(&allocator, program)?));
} else if args.hash {
println!("0x{}", tree_hash(&allocator, program));
println!("{}", tree_hash(&allocator, program));
} else {
println!("{}", disassemble(&allocator, program, None));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-compiler"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "A compiler for the Rue programming language."
Expand Down
26 changes: 25 additions & 1 deletion crates/rue-compiler/src/compile/binding/struct_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,35 @@ pub fn create_struct_binding(

let mut specified_fields = HashSet::new();

for field in struct_binding.fields() {
let len = struct_binding.fields().count();

for (i, field) in struct_binding.fields().enumerate() {
let Some(name) = field.name() else {
continue;
};

if let Some(spread) = field.spread() {
if i != len - 1 {
ctx.diagnostic(&spread, DiagnosticKind::NonFinalSpread);
}

let binding_symbol = ctx.alloc_symbol(Symbol::Binding(BindingSymbol {
name: None,
value: reference.clone(),
inline: true,
}));

ctx.push_declaration(Declaration::Symbol(binding_symbol));

ctx.reference(Declaration::Symbol(symbol), None);

create_binding_for_identifier(ctx, binding_symbol, &name);

ctx.pop_declaration();

continue;
}

specified_fields.insert(name.text().to_string());

let value = match compile_field(ctx, reference.clone(), &Field::Named(name.text())) {
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-diagnostic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-diagnostic"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "All of the potential diagnostics that can be emitted by the Rue compiler."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-hir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-hir"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "Provides a high-level intermediate representation of the Rue programming language."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-lexer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-lexer"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "A lexer for the Rue programming language."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-lir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-lir"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "Provides a low-level intermediate representation that compiles to CLVM."
Expand Down
12 changes: 11 additions & 1 deletion crates/rue-lir/src/optimize/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sha3::Keccak256;
use crate::{
ClvmOp, Lir, LirId, atom_bigint, bigint_atom, first_path,
optimize::{ArgList, opt_truthy},
rest_path,
parent_path, rest_path,
};

// There's no way to optimize an atom
Expand Down Expand Up @@ -98,6 +98,16 @@ pub fn opt_cons(arena: &mut Arena<Lir>, first: LirId, rest: LirId) -> LirId {
return rest;
}

if let Lir::Path(f_path) = arena[first].clone()
&& let Lir::Path(r_path) = arena[rest].clone()
&& let parent = parent_path(f_path)
&& parent == parent_path(r_path)
&& first_path(parent) == f_path
&& rest_path(parent) == r_path
{
return arena.alloc(Lir::Path(parent));
}

arena.alloc(Lir::Cons(first, rest))
}

Expand Down
31 changes: 31 additions & 0 deletions crates/rue-lir/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ fn add_path(a: u32, mut b: u32) -> u32 {
b | (a & mask)
}

pub fn parent_path(path: u32) -> u32 {
let result_depth = 31 - path.leading_zeros();
let original_depth = result_depth - 1;
let mask = (1 << original_depth) - 1;
let lower_bits = path & mask;
(1 << original_depth) | lower_bits
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -52,4 +60,27 @@ mod tests {
assert_eq!(rest_path(2), 6);
assert_eq!(rest_path(5), 13);
}

#[test]
fn test_parent_path() {
assert_eq!(parent_path(2), 1);
assert_eq!(parent_path(3), 1);
assert_eq!(parent_path(4), 2);
assert_eq!(parent_path(6), 2);
assert_eq!(parent_path(5), 3);
assert_eq!(parent_path(7), 3);
assert_eq!(parent_path(8), 4);
assert_eq!(parent_path(12), 4);
assert_eq!(parent_path(10), 6);
assert_eq!(parent_path(14), 6);
assert_eq!(parent_path(9), 5);
assert_eq!(parent_path(13), 5);
assert_eq!(parent_path(11), 7);
assert_eq!(parent_path(15), 7);

for path in 1..u32::from(u16::MAX) {
assert_eq!(parent_path(first_path(path)), path);
assert_eq!(parent_path(rest_path(path)), path);
}
}
}
2 changes: 1 addition & 1 deletion crates/rue-lsp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-lsp"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "A language server protocol (LSP) implementation for the Rue programming language."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-options/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-options"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "Provides a way to configure the Rue compiler."
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-parser"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "A parser for the Rue programming language."
Expand Down
3 changes: 2 additions & 1 deletion crates/rue-parser/src/grammar/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ pub fn binding(p: &mut Parser) {
p.expect(T!['{']);
while !p.at(T!['}']) {
p.start(SyntaxKind::StructFieldBinding);
let spread = p.try_eat(T![...]);
p.expect(SyntaxKind::Ident);
if p.try_eat(T![:]) {
if p.try_eat(T![:]) && !spread {
binding(p);
}
p.finish();
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-tests"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
publish = false
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rue-types"
version = "0.7.1"
version = "0.8.0"
edition = "2024"
license = "Apache-2.0"
description = "A type system for the Rue programming language."
Expand Down
Loading
Loading