Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
43e7762
refactor(opy-rs): simplify repeated lowering paths
Teakowa Sep 27, 2026
ab20300
refactor(opy-rs): centralize HIR traversal
Teakowa Sep 27, 2026
da7b21a
refactor(opy-rs): remove redundant lowering state
Teakowa Sep 27, 2026
95489f2
refactor(opy-rs): collapse redundant match arms
Teakowa Sep 27, 2026
6335a7b
refactor(opy-rs): split lowering responsibilities
Teakowa Sep 27, 2026
6662011
refactor(opy-provider): share LSP position conversion
Teakowa Sep 27, 2026
1f680a8
refactor(opy-rs): unify settings scalar parsing
Teakowa Sep 27, 2026
7dd5756
refactor(opy-rs): remove HIR validation wrappers
Teakowa Sep 27, 2026
b84eab0
refactor(opy-rs): reuse compile-time value display
Teakowa Sep 27, 2026
d125a1b
refactor(opy-rs): share loop condition lowering
Teakowa Sep 27, 2026
c2caa80
refactor(opy-rs): centralize condition folding
Teakowa Sep 27, 2026
9286f4d
refactor(opy-rs): share settings source cursor
Teakowa Sep 27, 2026
aa04f4e
refactor(opy-rs): remove dead debug count branch
Teakowa Sep 27, 2026
3eba1fd
refactor(opy-rs): move reserved index set
Teakowa Sep 27, 2026
812fae6
refactor(opy-rs): centralize lowerer initialization
Teakowa Sep 27, 2026
d3e3067
refactor(opy-rs): centralize parser initialization
Teakowa Sep 27, 2026
7e17575
refactor(opy-rs): centralize settings cursor creation
Teakowa Sep 27, 2026
7740e80
refactor(opy-rs): centralize check failure state
Teakowa Sep 27, 2026
89424e8
refactor(opy-rs): centralize preprocessing error state
Teakowa Sep 27, 2026
2558563
refactor(opy-rs): consolidate parser and lowering paths
Teakowa Sep 27, 2026
d15aaca
refactor(opy-rs): reuse numeric operator folds
Teakowa Sep 27, 2026
8cc9a4d
refactor(opy-rs): share value tree traversal
Teakowa Sep 27, 2026
55f47d6
refactor(opy-rs): share compression decode lowering
Teakowa Sep 27, 2026
056664f
refactor(opy-rs): share rule template values
Teakowa Sep 27, 2026
da5a3e9
refactor(opy-rs): reuse shared directive lookup
Teakowa Sep 27, 2026
3c72667
refactor(opy-rs): remove string token forwarder
Teakowa Sep 27, 2026
13ada4f
refactor(opy-rs): read space widths from source table
Teakowa Sep 27, 2026
7d3f991
refactor(opy-rs): reuse lexer identifier rules
Teakowa Sep 27, 2026
bfff7d2
refactor(opy-rs): localize cased progress lowering
Teakowa Sep 27, 2026
b398ee8
refactor(opy-rs): isolate declaration lowering
Teakowa Sep 27, 2026
a038c2a
refactor(opy-rs): combine declaration allocation scans
Teakowa Sep 27, 2026
ff5e84c
refactor(opy-rs): streamline declaration planning
Teakowa Sep 27, 2026
a78de25
refactor(opy-rs): mutate expanded hir in place
Teakowa Sep 27, 2026
f0fd06b
refactor(opy-rs): share rule name formatting filter
Teakowa Sep 27, 2026
56809ce
refactor(opy-rs): reuse generated rule construction
Teakowa Sep 27, 2026
ebfc736
refactor(opy-rs): centralize rule provenance writes
Teakowa Sep 27, 2026
d6c4de6
refactor(opy-rs): unify logical operator folding
Teakowa Sep 27, 2026
b8b882e
refactor(opy-rs): reuse literal value predicates
Teakowa Sep 27, 2026
9e9039d
refactor(opy-rs): share size optimizer boolean rewrite
Teakowa Sep 27, 2026
863cc56
refactor(opy-rs): group parser directive state
Teakowa Sep 27, 2026
36a211c
refactor(opy-rs): share reconstruction call resolution
Teakowa Sep 27, 2026
b5ad67b
refactor(opy-rs): borrow settings constant expressions
Teakowa Sep 28, 2026
bbf9a71
perf(opy-rs): avoid duplicate HIR condition validation
Teakowa Sep 28, 2026
5fc9aae
refactor(opy-rs): share cased glyph record construction
Teakowa Sep 28, 2026
08cc6f6
refactor(opy-rs): consolidate expression parser helpers
Teakowa Sep 28, 2026
ea7a6fb
refactor(opy-rs): share settings string escape decoding
Teakowa Sep 28, 2026
1b4f4e8
refactor(opy-rs): reuse lexer identifier boundaries
Teakowa Sep 28, 2026
643e0be
refactor(opy-rs): share initializer reconstruction scan
Teakowa Sep 28, 2026
ec381e7
refactor(opy-rs): share block indentation parsing
Teakowa Sep 28, 2026
33334ba
refactor(opy-rs): share colon body parsing
Teakowa Sep 28, 2026
b8e7688
refactor(opy-rs): share compression eligibility checks
Teakowa Sep 28, 2026
4e009fc
refactor(opy-rs): share compressed component classification
Teakowa Sep 28, 2026
23159bf
refactor(opy-rs): share declaration visibility check
Teakowa Sep 28, 2026
11e889a
refactor(opy-rs): borrow macro templates during expansion
Teakowa Sep 28, 2026
be6f8aa
refactor(opy-rs): share disabled-rule diagnostics
Teakowa Sep 28, 2026
367bcba
refactor(opy-rs): share variable declaration emission
Teakowa Sep 28, 2026
ec60908
refactor(opy-rs): centralize HIR program traversal
Teakowa Sep 28, 2026
129c209
refactor(opy-rs): centralize HIR span accessors
Teakowa Sep 28, 2026
0ffdfea
refactor(opy-rs): share delimited expression parsing
Teakowa Sep 28, 2026
60fd207
refactor(opy-rs): keep HIR span accessors explicit
Teakowa Sep 28, 2026
e80ada8
refactor(opy-rs): share indexed expression decomposition
Teakowa Sep 28, 2026
481be7e
refactor(opy-rs): simplify synthetic texture rule
Teakowa Sep 28, 2026
c9217c0
refactor(opy-rs): remove unused JavaScript engine trait
Teakowa Sep 28, 2026
135a633
refactor(opy-rs): borrow self-modification operands
Teakowa Sep 28, 2026
8d5b8e8
refactor(opy-rs): reuse reconstruction subroutine set
Teakowa Sep 28, 2026
2773225
refactor(opy-rs): avoid cloning compile report output
Teakowa Sep 28, 2026
dc7d635
fix(opy-rs): preserve HIR validation error precedence
Teakowa Sep 28, 2026
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
54 changes: 20 additions & 34 deletions crates/opy-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ use std::process::ExitCode;

use clap::{CommandFactory, Parser, error::ErrorKind};
use clap_complete::{generate, shells};
use opy_rs::tooling::{CheckOutcome, Diagnostic as OpyDiagnostic, check};
use opy_rs::tooling::{CheckOutcome, Diagnostic as OpyDiagnostic, SourceLocation, check};
use opy_rs::{CompileDiagnostic, CompileStatus, Compiler};
use opy_rs::{FilesystemProject, LANGUAGE_NAME, LANGUAGE_VERSION};
use serde::Serialize;

use crate::cli::{CheckArgs, Cli, Command, CompileArgs, FileArgs, OutputFormatArg};
use crate::present::{
CheckView, DiagnosticSeverity, DiagnosticView, PositionView, Presentation, SpanView,
};
use crate::present::{CheckView, DiagnosticView, PositionView, Presentation, SpanView};

fn main() -> ExitCode {
let cli = match Cli::try_parse() {
Expand Down Expand Up @@ -234,45 +232,33 @@ fn check_view(outcome: &CheckOutcome) -> CheckView {

fn diagnostic_view(diagnostic: &OpyDiagnostic) -> DiagnosticView {
DiagnosticView {
severity: match diagnostic.severity {
opy_rs::tooling::DiagnosticSeverity::Error => DiagnosticSeverity::Error,
opy_rs::tooling::DiagnosticSeverity::Warning => DiagnosticSeverity::Warning,
},
severity: diagnostic.severity.into(),
code: diagnostic.code.clone(),
message: diagnostic.message.clone(),
span: diagnostic.span.as_ref().map(|span| SpanView {
path: span.path.clone(),
start: PositionView {
line: span.start.line,
col: span.start.col,
},
end: PositionView {
line: span.end.line,
col: span.end.col,
},
}),
span: diagnostic.span.as_ref().map(diagnostic_span_view),
}
}

fn compile_diagnostic_view(diagnostic: &CompileDiagnostic) -> DiagnosticView {
DiagnosticView {
severity: match diagnostic.severity {
opy_rs::tooling::DiagnosticSeverity::Error => DiagnosticSeverity::Error,
opy_rs::tooling::DiagnosticSeverity::Warning => DiagnosticSeverity::Warning,
},
severity: diagnostic.severity.into(),
code: diagnostic.code.clone(),
message: diagnostic.message.clone(),
span: diagnostic.span.as_ref().map(|span| SpanView {
path: span.path.clone(),
start: PositionView {
line: span.start.line,
col: span.start.col,
},
end: PositionView {
line: span.end.line,
col: span.end.col,
},
}),
span: diagnostic.span.as_ref().map(diagnostic_span_view),
}
}

fn diagnostic_span_view(span: &SourceLocation) -> SpanView {
SpanView {
path: span.path.clone(),
start: PositionView {
line: span.start.line,
col: span.start.col,
},
end: PositionView {
line: span.end.line,
col: span.end.col,
},
}
}

Expand Down
11 changes: 11 additions & 0 deletions crates/opy-cli/src/present.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::io::{IsTerminal, Write};

use opy_rs::tooling::DiagnosticSeverity as OpyDiagnosticSeverity;

use crate::cli::{ColorArg, RendererArg};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand All @@ -8,6 +10,15 @@ pub(crate) enum DiagnosticSeverity {
Warning,
}

impl From<OpyDiagnosticSeverity> for DiagnosticSeverity {
fn from(value: OpyDiagnosticSeverity) -> Self {
match value {
OpyDiagnosticSeverity::Error => Self::Error,
OpyDiagnosticSeverity::Warning => Self::Warning,
}
}
}

impl DiagnosticSeverity {
fn as_str(self) -> &'static str {
match self {
Expand Down
22 changes: 8 additions & 14 deletions crates/opy-provider/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,17 +1070,7 @@ fn document_lsp_position(
.map(|document| document.text.clone())
.or_else(|| std::fs::read_to_string(&resolved).ok())
.unwrap_or_default();
let character = source
.lines()
.nth(line.saturating_sub(1) as usize)
.map(|text| {
text.chars()
.take(col.saturating_sub(1) as usize)
.map(char::len_utf16)
.sum::<usize>() as u32
})
.unwrap_or_else(|| col.saturating_sub(1));
json!({ "line": line.saturating_sub(1), "character": character })
lsp_position(&source, line, col)
}

fn check_result(project: &LoadedProject, outcome: &CheckOutcome) -> Value {
Expand Down Expand Up @@ -1209,17 +1199,21 @@ fn diagnostic_range(project: &LoadedProject, location: Option<&SourceLocation>)
});
};
json!({
"start": lsp_position(project, &location.path, location.start.line, location.start.col),
"end": lsp_position(project, &location.path, location.end.line, location.end.col),
"start": project_lsp_position(project, &location.path, location.start.line, location.start.col),
"end": project_lsp_position(project, &location.path, location.end.line, location.end.col),
})
}

fn lsp_position(project: &LoadedProject, path: &str, line: u32, col: u32) -> Value {
fn project_lsp_position(project: &LoadedProject, path: &str, line: u32, col: u32) -> Value {
let source = if path == path_string(project.filesystem.main_path()) {
project.filesystem.source().to_owned()
} else {
std::fs::read_to_string(resolved_project_path(project, path)).unwrap_or_default()
};
lsp_position(&source, line, col)
}

fn lsp_position(source: &str, line: u32, col: u32) -> Value {
let character = source
.lines()
.nth(line.saturating_sub(1) as usize)
Expand Down
10 changes: 5 additions & 5 deletions crates/opy-rs/src/compile_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) fn evaluate(
.map(|arg| evaluate(arg, constants, bindings, stack))
.collect::<Option<Vec<_>>>()?;
let mut result = text.clone();
for (index, value) in values.iter().enumerate() {
for (index, value) in values.into_iter().enumerate() {
result = result.replace(&format!("{{{index}}}"), &display(value)?);
}
Some(Value::String(result))
Expand Down Expand Up @@ -197,10 +197,10 @@ fn evaluate_index(collection: Value, index: Value) -> Option<Value> {
}
}

fn display(value: &Value) -> Option<String> {
pub(crate) fn display(value: Value) -> Option<String> {
match value {
Value::Number(value) if value.is_finite() => Some(workshop_number_text(*value)),
Value::String(value) => Some(value.clone()),
Value::Number(value) if value.is_finite() => Some(workshop_number_text(value)),
Value::String(value) => Some(value),
Value::Bool(value) => Some(value.to_string()),
_ => None,
}
Expand All @@ -219,7 +219,7 @@ pub(crate) fn round_half_up(value: f64) -> f64 {
}
}

pub(crate) fn workshop_number_text(value: f64) -> String {
fn workshop_number_text(value: f64) -> String {
let rounded = (value * 100.0).round() / 100.0;
if rounded.fract() == 0.0 {
format!("{}", rounded as i64)
Expand Down
6 changes: 2 additions & 4 deletions crates/opy-rs/src/compiler/action_optimization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use workshop_rs::{Action, Value};
use super::Compiler;
use super::operator_optimization::falsy;
use super::size_optimization::{action_values, is_empty_string};
use super::value_walk::for_each_child;

pub(super) struct ActionOptimizer<'a> {
compiler: &'a Compiler,
Expand Down Expand Up @@ -88,10 +89,7 @@ impl<'a> ActionOptimizer<'a> {
fn nested(&self, value: &mut Value) {
match value {
Value::Call { name, args } => self.booleans(Kind::Value, name, args),
Value::Array(elements) => elements.iter_mut().for_each(|element| self.nested(element)),
Value::Vector { x, y, z } => [x, y, z].into_iter().for_each(|part| self.nested(part)),
Value::PlayerVariable { player, .. } => self.nested(player),
_ => {}
_ => for_each_child(value, |child| self.nested(child)),
}
}
}
Expand Down
Loading
Loading