Skip to content

Commit

Permalink
Fixed select compilation issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Jan 20, 2025
1 parent 7759235 commit a7aff03
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 28 deletions.
8 changes: 4 additions & 4 deletions crates/icy_board_engine/src/compiler/ast_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ impl AstVisitorMut for AstTransformationVisitor {
match spec {
crate::ast::CaseSpecifier::Expression(spec_expr) => {
statements.push(IfStatement::create_empty_statement(
BinaryExpression::create_empty_expression(crate::ast::BinOp::Eq, expr.clone(), *spec_expr.clone()),
BinaryExpression::create_empty_expression(crate::ast::BinOp::NotEq, expr.clone(), *spec_expr.clone()),
GotoStatement::create_empty_statement(next_case_label.clone()),
));
}
crate::ast::CaseSpecifier::FromTo(from_expr, to_expr) => {
statements.push(IfStatement::create_empty_statement(
BinaryExpression::create_empty_expression(
crate::ast::BinOp::And,
BinaryExpression::create_empty_expression(crate::ast::BinOp::LowerEq, *from_expr.clone(), expr.clone()),
BinaryExpression::create_empty_expression(crate::ast::BinOp::LowerEq, expr.clone(), *to_expr.clone()),
crate::ast::BinOp::Or,
BinaryExpression::create_empty_expression(crate::ast::BinOp::Greater, *from_expr.clone(), expr.clone()),
BinaryExpression::create_empty_expression(crate::ast::BinOp::Greater, expr.clone(), *to_expr.clone()),
),
GotoStatement::create_empty_statement(next_case_label.clone()),
));
Expand Down
1 change: 1 addition & 0 deletions crates/icy_board_engine/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl<'a> PPECompiler<'a> {
/// Panics if .
pub fn compile(&mut self, prg: &Ast) {
let prg = prg.visit_mut(&mut AstTransformationVisitor::new(true));
// println!("{}", prg);
prg.visit(&mut self.semantic_visitor);
self.lookup_table = self.semantic_visitor.generate_variable_table();
for d in &prg.nodes {
Expand Down
4 changes: 2 additions & 2 deletions crates/icy_board_engine/src/decompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ impl Decompiler {
let mut decl = Vec::new();

let (start, end) = if entry.header.variable_type == VariableType::Function {
let start = entry.value.data.function_value.first_var_id as usize + entry.value.data.function_value.parameters as usize + 1;
let start = entry.value.data.function_value.first_var_id as usize + entry.value.data.function_value.parameters as usize + 1;
(start, start + entry.value.data.function_value.local_variables as usize - 1)
} else {
let start = entry.value.data.function_value.first_var_id as usize + entry.value.data.function_value.parameters as usize + 1;
let start = entry.value.data.function_value.first_var_id as usize + entry.value.data.function_value.parameters as usize + 1;
(start, start + entry.value.data.function_value.local_variables as usize)
};

Expand Down
1 change: 0 additions & 1 deletion crates/icy_board_engine/src/executable/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub enum ExecutableError {
BufferTooShort(usize),
}


#[derive(Clone)]
pub struct Executable {
pub version: u16,
Expand Down
9 changes: 4 additions & 5 deletions crates/icy_board_engine/src/executable/variable_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,18 +806,18 @@ impl VariableTable {
pub fn get_entries(&self) -> &[TableEntry] {
&self.entries
}

pub(crate) fn analyze_locals(&mut self) {
for t in self.entries.clone().iter() {
if t.header.variable_type == VariableType::Function {
unsafe {
let start = t.value.data.function_value.first_var_id as usize + t.value.data.function_value.parameters as usize + 1;
unsafe {
let start = t.value.data.function_value.first_var_id as usize + t.value.data.function_value.parameters as usize + 1;
for i in 0..t.value.data.function_value.local_variables {
let idx = start + i as usize;
if idx == t.value.data.function_value.return_var as usize {
continue;
}

let var = self.get_var_entry_mut(idx);
if var.header.flags != 0 {
continue;
Expand All @@ -838,7 +838,6 @@ impl VariableTable {
}
}
}

}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/icy_board_engine/src/executable/variable_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,6 @@ impl VariableValue {
}

pub fn set_array_value(&mut self, dim1: usize, dim2: usize, dim3: usize, val: VariableValue) {

match &mut self.generic_data {
GenericVariableData::None => {
log::error!("generic data not set - array expected.");
Expand All @@ -1155,7 +1154,7 @@ impl VariableValue {
if dim1 < data.len() && dim2 < data[dim1].len() {
data[dim1][dim2] = val.convert_to(self.vtype);
} else {
if dim1 < data.len() {
if dim1 < data.len() {
log::error!("dim2 out of bounds: {} > {}", dim2, data[dim1].len());
} else {
log::error!("dim1 out of bounds: {} > {}", dim1, data.len());
Expand Down
3 changes: 0 additions & 3 deletions crates/icy_board_engine/src/semantic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,6 @@ impl<'a> SemanticVisitor<'a> {
variable_table.push(new_entry);
}



for idx in f.local_variables.clone() {
let (rt, r) = &self.references[idx];
if !matches!(rt, ReferenceType::Variable(_)) {
Expand Down Expand Up @@ -1181,7 +1179,6 @@ impl<'a> AstVisitor<VariableType> for SemanticVisitor<'a> {
VariableType::None
}


fn visit_variable_declaration_statement(&mut self, var_decl: &VariableDeclarationStatement) -> VariableType {
for v in var_decl.get_variables() {
if self.has_variable_defined(v.get_identifier()) {
Expand Down
2 changes: 2 additions & 0 deletions crates/icy_board_engine/tests/test_data/select_case.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OK
OK
16 changes: 16 additions & 0 deletions crates/icy_board_engine/tests/test_data/select_case.pps
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
INTEGER A
A = -1

SELECT CASE A
CASE -1
PRINTLN "OK"
DEFAULT
PRINTLN "NOT OK"
END SELECT

SELECT CASE A
CASE 4..10
PRINTLN "NOT OK"
DEFAULT
PRINTLN "OK"
END SELECT
12 changes: 2 additions & 10 deletions crates/icy_board_engine/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
use std::{
env,
path::PathBuf,
sync::Arc,
thread,
};
use std::{env, path::PathBuf, sync::Arc, thread};

use icy_board_engine::{
compiler::PPECompiler,
executable::{Executable, LAST_PPLC},
icy_board::{
bbs::BBS,
state::IcyBoardState,
},
icy_board::{bbs::BBS, state::IcyBoardState},
parser::{Encoding, UserTypeRegistry},
};
use icy_net::{channel::ChannelConnection, Connection, ConnectionType};
Expand Down
2 changes: 1 addition & 1 deletion crates/ppl-lsp/src/semantic_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl AstVisitor<()> for SemanticTokenVisitor {
self.highlight_token(else_if_block.get_elseif_token(), SemanticTokenType::KEYWORD);
if let Some(token) = else_if_block.get_then_token() {
self.highlight_token(token, SemanticTokenType::KEYWORD);
}
}
}
if let Some(else_block) = if_then.get_else_block() {
self.highlight_token(else_block.get_else_token(), SemanticTokenType::KEYWORD);
Expand Down

0 comments on commit a7aff03

Please sign in to comment.