prepare to add project_attributes/2 and attribute_goals/2
This commit is contained in:
@@ -18,7 +18,7 @@ gather_modules([Attr|Attrs], [Module|Modules]) :-
|
||||
|
||||
verify_attrs([Module|Modules], Var, Value, [Goals|ListOfGoalLists]) :-
|
||||
catch(Module:verify_attributes(Var, Value, Goals),
|
||||
error(evaluation_error((M:verify_attributes)/3), verify_attrs/3),
|
||||
error(evaluation_error((Module:verify_attributes)/3), verify_attributes/3),
|
||||
Goals = []),
|
||||
verify_attrs(Modules, Var, Value, ListOfGoalLists).
|
||||
verify_attrs([], _, _, []).
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
use prolog::machine::*;
|
||||
|
||||
pub static VERIFY_ATTRS: &str = include_str!("attributed_variables.pl");
|
||||
pub static VERIFY_ATTRS: &str = include_str!("attributed_variables.pl");
|
||||
pub static PROJECT_ATTRS: &str = include_str!("project_attributes.pl");
|
||||
|
||||
pub(super) type Bindings = Vec<(usize, Addr)>;
|
||||
|
||||
pub(super) struct AttrVarInitializer {
|
||||
pub(super) bindings: Bindings,
|
||||
pub(super) cp: LocalCodePtr,
|
||||
pub(super) verify_attrs_loc: usize
|
||||
pub(super) verify_attrs_loc: usize,
|
||||
pub(super) project_attrs_loc: usize
|
||||
}
|
||||
|
||||
impl AttrVarInitializer {
|
||||
pub(super) fn new(p: usize) -> Self {
|
||||
pub(super) fn new(verify_attrs_loc: usize, project_attrs_loc: usize) -> Self {
|
||||
AttrVarInitializer {
|
||||
bindings: vec![],
|
||||
cp: LocalCodePtr::default(),
|
||||
verify_attrs_loc: p,
|
||||
verify_attrs_loc,
|
||||
project_attrs_loc
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ impl MachineState {
|
||||
e: 0,
|
||||
num_of_args: 0,
|
||||
cp: LocalCodePtr::default(),
|
||||
attr_var_init: AttrVarInitializer::new(0),
|
||||
attr_var_init: AttrVarInitializer::new(0, 0),
|
||||
fail: false,
|
||||
heap: Heap::with_capacity(256),
|
||||
mode: MachineMode::Write,
|
||||
|
||||
@@ -319,6 +319,7 @@ static ERROR: &str = include_str!("../lib/error.pl");
|
||||
static TERMS: &str = include_str!("../lib/terms.pl");
|
||||
static DCGS: &str = include_str!("../lib/dcgs.pl");
|
||||
static ATTS: &str = include_str!("../lib/atts.pl");
|
||||
static DIF: &str = include_str!("../lib/dif.pl");
|
||||
|
||||
impl Machine {
|
||||
fn compile_special_forms(&mut self) {
|
||||
@@ -327,8 +328,27 @@ impl Machine {
|
||||
self.machine_st.attr_var_init.verify_attrs_loc = self.code_repo.code.len();
|
||||
self.code_repo.code.extend(code.into_iter());
|
||||
},
|
||||
Err(_) => panic!("Machine::compile_special_forms() failed")
|
||||
Err(_) => panic!("Machine::compile_special_forms() failed at VERIFY_ATTRS")
|
||||
}
|
||||
|
||||
match compile_special_form(self, PROJECT_ATTRS.as_bytes()) {
|
||||
Ok(code) => {
|
||||
self.machine_st.attr_var_init.project_attrs_loc = self.code_repo.code.len();
|
||||
self.code_repo.code.extend(code.into_iter());
|
||||
},
|
||||
Err(_) => panic!("Machine::compile_special_forms() failed at PROJECT_ATTRS")
|
||||
}
|
||||
}
|
||||
|
||||
fn compile_libraries(&mut self) {
|
||||
compile_user_module(self, LISTS.as_bytes());
|
||||
compile_user_module(self, CONTROL.as_bytes());
|
||||
compile_user_module(self, QUEUES.as_bytes());
|
||||
compile_user_module(self, ERROR.as_bytes());
|
||||
compile_user_module(self, TERMS.as_bytes());
|
||||
compile_user_module(self, DCGS.as_bytes());
|
||||
compile_user_module(self, ATTS.as_bytes());
|
||||
compile_user_module(self, DIF.as_bytes());
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
@@ -344,15 +364,9 @@ impl Machine {
|
||||
compile_listing(&mut wam, BUILTINS.as_bytes(),
|
||||
default_index_store!(atom_tbl.clone()));
|
||||
|
||||
compile_user_module(&mut wam, LISTS.as_bytes());
|
||||
compile_user_module(&mut wam, CONTROL.as_bytes());
|
||||
compile_user_module(&mut wam, QUEUES.as_bytes());
|
||||
compile_user_module(&mut wam, ERROR.as_bytes());
|
||||
compile_user_module(&mut wam, TERMS.as_bytes());
|
||||
compile_user_module(&mut wam, DCGS.as_bytes());
|
||||
compile_user_module(&mut wam, ATTS.as_bytes());
|
||||
|
||||
wam.compile_libraries();
|
||||
wam.compile_special_forms();
|
||||
|
||||
wam
|
||||
}
|
||||
|
||||
@@ -608,7 +622,7 @@ impl MachineState {
|
||||
for i in 1 .. rs + 1 {
|
||||
self.and_stack[e][i] = self[RegType::Temp(i)].clone();
|
||||
}
|
||||
|
||||
|
||||
self.and_stack[e][rs + 1] = Addr::Con(Constant::Usize(self.b0));
|
||||
self.and_stack[e][rs + 2] = Addr::Con(Constant::Usize(self.num_of_args));
|
||||
|
||||
|
||||
46
src/prolog/machine/project_attributes.pl
Normal file
46
src/prolog/machine/project_attributes.pl
Normal file
@@ -0,0 +1,46 @@
|
||||
:- use_module(library(dcgs)).
|
||||
|
||||
driver(QueryVars, AttrVars) :-
|
||||
phrase(gather_modules(AttrVars), Modules0),
|
||||
sort(Modules0, Modules),
|
||||
call_project_attributes(Modules, QueryVars, AttrVars),
|
||||
call_attribute_goals(QueryVars),
|
||||
call_attribute_goals(AttrVars).
|
||||
|
||||
call_project_attributes([], _, _).
|
||||
call_project_attributes([Module|Modules], QueryVars, AttrVars) :-
|
||||
( catch(Module:project_attributes(QueryVars, AttrVars),
|
||||
error(evaluation_error((Module:project_attributes/2), project_attributes/2)),
|
||||
true) -> true
|
||||
; true
|
||||
),
|
||||
call_project_attributes(Modules, QueryVars, AttrVars).
|
||||
|
||||
call_attribute_goals([]).
|
||||
call_attribute_goals([AttrVar | AttrVars]) :-
|
||||
( '$get_attr_list'(AttrVar, Ls) -> call_goals(Ls, AttrVar)
|
||||
; true
|
||||
),
|
||||
call_attribute_goals(AttrVars).
|
||||
|
||||
call_goals(Ls, _) :- var(Ls), !.
|
||||
call_goals([Attr|Attrs], X) :-
|
||||
'$module_of'(Module, Attr),
|
||||
( catch(Module:attribute_goals(X, Goal),
|
||||
error(evaluation_error((Module:attribute_goals/2), attribute_goals/2)),
|
||||
writeq(Goal)) -> true
|
||||
; true
|
||||
),
|
||||
call_goals(Attrs, X).
|
||||
|
||||
gather_modules([]) --> [].
|
||||
gather_modules([AttrVar|AttrVars]) -->
|
||||
{ '$get_attr_list'(AttrVar, Attrs) },
|
||||
gather_modules_for_attrs(Attrs),
|
||||
gather_modules(AttrVars).
|
||||
|
||||
gather_modules_for_attrs(Attrs) --> { var(Attrs), ! }.
|
||||
gather_modules_for_attrs([Attr|Attrs]) -->
|
||||
{ '$module_of'(Module, Attr) },
|
||||
[Module],
|
||||
gather_modules_for_attrs(Attrs).
|
||||
Reference in New Issue
Block a user