throw exception when call-ing a system instruction.

This commit is contained in:
Mark Thom
2018-05-10 23:08:56 -06:00
parent 910bafef61
commit ba7e7ac895
10 changed files with 122 additions and 122 deletions

View File

@@ -1,5 +1,4 @@
use prolog::ast::*;
use prolog::builtins::*;
use prolog::machine::machine_state::*;
use prolog::num::bigint::BigInt;
@@ -8,6 +7,94 @@ use std::rc::Rc;
pub(super) type MachineError = Vec<HeapCellValue>;
pub(super) type MachineStub = Vec<HeapCellValue>;
// from 7.12.2 b) of 13211-1:1995
#[derive(Clone, Copy)]
pub enum ValidType {
Atom,
Atomic,
Byte,
Callable,
Character,
Compound,
Evaluable,
InByte,
InCharacter,
Integer,
List,
Number,
Pair,
PredicateIndicator,
Variable
}
impl ValidType {
pub fn as_str(self) -> &'static str {
match self {
ValidType::Atom => "atom",
ValidType::Atomic => "atomic",
ValidType::Byte => "byte",
ValidType::Callable => "callable",
ValidType::Character => "character",
ValidType::Compound => "compound",
ValidType::Evaluable => "evaluable",
ValidType::InByte => "in_byte",
ValidType::InCharacter => "in_character",
ValidType::Integer => "integer",
ValidType::List => "list",
ValidType::Number => "number",
ValidType::Pair => "pair",
ValidType::PredicateIndicator => "predicate_indicator",
ValidType::Variable => "variable"
}
}
}
// from 7.12.2 f) of 13211-1:1995
#[derive(Clone, Copy)]
pub enum RepFlag {
Character,
CharacterCode,
InCharacterCode,
MaxArity,
MaxInteger,
MinInteger
}
impl RepFlag {
pub fn as_str(self) -> &'static str {
match self {
RepFlag::Character => "character",
RepFlag::CharacterCode => "character_code",
RepFlag::InCharacterCode => "in_character_code",
RepFlag::MaxArity => "max_arity",
RepFlag::MaxInteger => "max_integer",
RepFlag::MinInteger => "min_integer"
}
}
}
// from 7.12.2 g) of 13211-1:1995
#[derive(Clone, Copy)]
pub enum EvalError {
FloatOverflow,
IntOverflow,
Undefined,
Underflow,
ZeroDivisor
}
impl EvalError {
pub fn as_str(self) -> &'static str {
match self {
EvalError::FloatOverflow => "float_overflow",
EvalError::IntOverflow => "int_overflow",
EvalError::Undefined => "undefined",
EvalError::Underflow => "underflow",
EvalError::ZeroDivisor => "zero_divisor"
}
}
}
// used by '$skip_max_list'.
pub(super) enum CycleSearchResult {
EmptyList,
@@ -125,7 +212,7 @@ impl MachineState {
let mut error_form = vec![HeapCellValue::NamedStr(2, clause_name!("error"), None),
HeapCellValue::Addr(Addr::HeapCell(h + 3)),
HeapCellValue::Addr(Addr::HeapCell(h + 3 + err.len()))];
error_form.extend(err.into_iter());
error_form.extend(src.into_iter());
@@ -143,6 +230,6 @@ impl MachineState {
self.registers[1] = Addr::HeapCell(h);
self.set_ball();
self.unwind_stack();
self.unwind_stack();
}
}