Added the sleep predicate
This commit is contained in:
@@ -251,6 +251,7 @@ pub enum SystemClauseType {
|
|||||||
SetDoubleQuotes,
|
SetDoubleQuotes,
|
||||||
SetSeed,
|
SetSeed,
|
||||||
SkipMaxList,
|
SkipMaxList,
|
||||||
|
Sleep,
|
||||||
Succeed,
|
Succeed,
|
||||||
TermVariables,
|
TermVariables,
|
||||||
TruncateLiftedHeapTo,
|
TruncateLiftedHeapTo,
|
||||||
@@ -402,6 +403,7 @@ impl SystemClauseType {
|
|||||||
&SystemClauseType::SetCutPointByDefault(_) => clause_name!("$set_cp_by_default"),
|
&SystemClauseType::SetCutPointByDefault(_) => clause_name!("$set_cp_by_default"),
|
||||||
&SystemClauseType::SetDoubleQuotes => clause_name!("$set_double_quotes"),
|
&SystemClauseType::SetDoubleQuotes => clause_name!("$set_double_quotes"),
|
||||||
&SystemClauseType::SkipMaxList => clause_name!("$skip_max_list"),
|
&SystemClauseType::SkipMaxList => clause_name!("$skip_max_list"),
|
||||||
|
&SystemClauseType::Sleep => clause_name!("$sleep"),
|
||||||
&SystemClauseType::Succeed => clause_name!("$succeed"),
|
&SystemClauseType::Succeed => clause_name!("$succeed"),
|
||||||
&SystemClauseType::TermVariables => clause_name!("$term_variables"),
|
&SystemClauseType::TermVariables => clause_name!("$term_variables"),
|
||||||
&SystemClauseType::TruncateLiftedHeapTo => clause_name!("$truncate_lh_to"),
|
&SystemClauseType::TruncateLiftedHeapTo => clause_name!("$truncate_lh_to"),
|
||||||
@@ -525,6 +527,7 @@ impl SystemClauseType {
|
|||||||
("$set_double_quotes", 1) => Some(SystemClauseType::SetDoubleQuotes),
|
("$set_double_quotes", 1) => Some(SystemClauseType::SetDoubleQuotes),
|
||||||
("$set_seed", 1) => Some(SystemClauseType::SetSeed),
|
("$set_seed", 1) => Some(SystemClauseType::SetSeed),
|
||||||
("$skip_max_list", 4) => Some(SystemClauseType::SkipMaxList),
|
("$skip_max_list", 4) => Some(SystemClauseType::SkipMaxList),
|
||||||
|
("$sleep", 1) => Some(SystemClauseType::Sleep),
|
||||||
("$store_global_var", 2) => Some(SystemClauseType::StoreGlobalVar),
|
("$store_global_var", 2) => Some(SystemClauseType::StoreGlobalVar),
|
||||||
("$store_global_var_with_offset", 2) => Some(SystemClauseType::StoreGlobalVarWithOffset),
|
("$store_global_var_with_offset", 2) => Some(SystemClauseType::StoreGlobalVarWithOffset),
|
||||||
("$term_variables", 2) => Some(SystemClauseType::TermVariables),
|
("$term_variables", 2) => Some(SystemClauseType::TermVariables),
|
||||||
|
|||||||
@@ -9,11 +9,15 @@
|
|||||||
'$cpu_new' can be replaced by statistics/2 once that is implemented.
|
'$cpu_new' can be replaced by statistics/2 once that is implemented.
|
||||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
:- module(time, [time/1]).
|
:- module(time, [sleep/1, time/1]).
|
||||||
|
|
||||||
:- use_module(library(format)).
|
:- use_module(library(format)).
|
||||||
:- use_module(library(iso_ext)).
|
:- use_module(library(iso_ext)).
|
||||||
|
|
||||||
|
sleep(T) :-
|
||||||
|
builtins:must_be_number(T, sleep),
|
||||||
|
'$sleep'(T).
|
||||||
|
|
||||||
time(Goal) :-
|
time(Goal) :-
|
||||||
'$cpu_now'(T0),
|
'$cpu_now'(T0),
|
||||||
Goal,
|
Goal,
|
||||||
|
|||||||
@@ -3092,6 +3092,22 @@ impl MachineState {
|
|||||||
if let Err(err) = self.skip_max_list() {
|
if let Err(err) = self.skip_max_list() {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
},
|
},
|
||||||
|
&SystemClauseType::Sleep => {
|
||||||
|
let time = self.store(self.deref(self[temp_v!(1)]));
|
||||||
|
|
||||||
|
let time = match Number::try_from((time, &self.heap)) {
|
||||||
|
Ok(Number::Float(OrderedFloat(n))) => n,
|
||||||
|
Ok(Number::Fixnum(n)) => n as f64,
|
||||||
|
Ok(Number::Integer(n)) => n.to_f64(),
|
||||||
|
_ => {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let duration = Duration::new(1, 0);
|
||||||
|
let duration = duration.mul_f64(time);
|
||||||
|
::std::thread::sleep(duration);
|
||||||
|
}
|
||||||
&SystemClauseType::StoreGlobalVar => {
|
&SystemClauseType::StoreGlobalVar => {
|
||||||
let key = self[temp_v!(1)];
|
let key = self[temp_v!(1)];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user