Use foliage’s built-in variable declaration stack

This commit is contained in:
2020-04-17 01:44:16 +02:00
parent becd8d4c19
commit 84bec338ae
4 changed files with 5 additions and 76 deletions

View File

@@ -371,7 +371,8 @@ fn read_rule(rule: &clingo::ast::Rule, context: &Context) -> Result<(), crate::E
let definitions = definitions.get_mut(&head_atom.predicate_declaration).unwrap();
let head_atom_parameters = std::rc::Rc::clone(&definitions.head_atom_parameters);
context.variable_declaration_stack.borrow_mut().push(head_atom_parameters);
let variable_declaration_stack_guard = foliage::VariableDeclarationStack::push(
&context.variable_declaration_stack, head_atom_parameters);
let mut definition_arguments = translate_body(rule.body(), context)?;
@@ -401,7 +402,7 @@ fn read_rule(rule: &clingo::ast::Rule, context: &Context) -> Result<(), crate::E
definition_arguments.push(translated_head_term);
}
context.variable_declaration_stack.borrow_mut().pop()?;
drop(variable_declaration_stack_guard);
let free_variable_declarations = std::mem::replace(
&mut context.variable_declaration_stack.borrow_mut().free_variable_declarations,

View File

@@ -22,7 +22,7 @@ pub(crate) struct Context
pub function_declarations: std::cell::RefCell<foliage::FunctionDeclarations>,
pub predicate_declarations: std::cell::RefCell<foliage::PredicateDeclarations>,
pub variable_declaration_stack: std::cell::RefCell<crate::VariableDeclarationStack>,
pub variable_declaration_stack: std::cell::RefCell<foliage::VariableDeclarationStack>,
pub variable_declaration_domains: std::cell::RefCell<VariableDeclarationDomains>,
pub program_variable_declaration_ids: std::cell::RefCell<VariableDeclarationIDs>,
pub integer_variable_declaration_ids: std::cell::RefCell<VariableDeclarationIDs>,
@@ -45,7 +45,7 @@ impl Context
function_declarations: std::cell::RefCell::new(foliage::FunctionDeclarations::new()),
predicate_declarations: std::cell::RefCell::new(foliage::PredicateDeclarations::new()),
variable_declaration_stack:
std::cell::RefCell::new(crate::VariableDeclarationStack::new()),
std::cell::RefCell::new(foliage::VariableDeclarationStack::new()),
variable_declaration_domains:
std::cell::RefCell::new(VariableDeclarationDomains::new()),
program_variable_declaration_ids: