2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-09-26 06:42:07 +02:00
|
|
|
|
|
|
|
#pragma once
|
2017-10-25 18:47:03 +02:00
|
|
|
#define HAVE_IRCD_M_VM_H
|
2017-09-26 06:42:07 +02:00
|
|
|
|
2017-11-16 02:48:25 +01:00
|
|
|
/// Matrix Virtual Machine
|
|
|
|
///
|
2017-10-25 18:47:03 +02:00
|
|
|
namespace ircd::m::vm
|
2017-09-26 06:42:07 +02:00
|
|
|
{
|
2017-11-16 02:48:25 +01:00
|
|
|
IRCD_M_EXCEPTION(m::error, VM_ERROR, http::INTERNAL_SERVER_ERROR);
|
|
|
|
IRCD_M_EXCEPTION(VM_ERROR, VM_FAULT, http::BAD_REQUEST);
|
2018-02-09 08:21:15 +01:00
|
|
|
IRCD_M_EXCEPTION(VM_ERROR, VM_INVALID, http::BAD_REQUEST);
|
2017-11-16 02:48:25 +01:00
|
|
|
|
2017-11-30 20:01:14 +01:00
|
|
|
enum fault :uint;
|
2017-11-16 02:48:25 +01:00
|
|
|
struct eval;
|
|
|
|
|
2017-09-28 03:31:21 +02:00
|
|
|
using closure = std::function<void (const event &)>;
|
|
|
|
using closure_bool = std::function<bool (const event &)>;
|
2017-09-26 06:42:07 +02:00
|
|
|
|
2017-11-16 02:48:25 +01:00
|
|
|
extern struct log::log log;
|
|
|
|
extern uint64_t current_sequence;
|
|
|
|
extern ctx::view<const event> inserted;
|
2017-09-26 06:42:07 +02:00
|
|
|
|
2018-01-26 21:26:09 +01:00
|
|
|
event::id::buf commit(json::iov &event);
|
|
|
|
event::id::buf commit(json::iov &event, const json::iov &content);
|
2017-11-16 02:48:25 +01:00
|
|
|
}
|
|
|
|
|
2018-02-08 22:23:01 +01:00
|
|
|
/// Event Evaluation Device
|
|
|
|
///
|
|
|
|
/// This object conducts the evaluation of an event or a tape of multiple
|
|
|
|
/// events. An event is evaluated in an attempt to execute it. Events which
|
|
|
|
/// fail during evaluation won't be executed; such is the case for events which
|
|
|
|
/// have already been executed, or events which are invalid or lead to invalid
|
|
|
|
/// transitions or actions of the machine etc.
|
|
|
|
///
|
|
|
|
struct ircd::m::vm::eval
|
|
|
|
{
|
|
|
|
struct opts;
|
|
|
|
|
|
|
|
struct opts static const default_opts;
|
|
|
|
|
|
|
|
const struct opts *opts {&default_opts};
|
|
|
|
db::txn txn{*dbs::events};
|
|
|
|
|
|
|
|
fault operator()(const event &);
|
|
|
|
|
|
|
|
eval(const event &, const struct opts & = default_opts);
|
|
|
|
eval(const struct opts &);
|
|
|
|
eval() = default;
|
|
|
|
|
|
|
|
friend string_view reflect(const fault &);
|
|
|
|
};
|
|
|
|
|
2017-11-30 20:01:14 +01:00
|
|
|
/// Evaluation Options
|
2018-02-08 22:23:01 +01:00
|
|
|
struct ircd::m::vm::eval::opts
|
2017-11-30 20:01:14 +01:00
|
|
|
{
|
2018-02-08 22:23:01 +01:00
|
|
|
|
2017-11-30 20:01:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Individual evaluation state
|
|
|
|
///
|
|
|
|
/// Evaluation faults. These are reasons which evaluation has halted but may
|
|
|
|
/// continue after the user defaults the fault. They are basically types of
|
|
|
|
/// interrupts and traps, which are recoverable. Only the GENERAL protection
|
|
|
|
/// fault (#gp) is an abort and is not recoverable. An exception_ptr will be
|
|
|
|
/// set; aborts are otherwise just thrown as exceptions from eval. If any
|
|
|
|
/// fault isn't handled properly that is an abort.
|
|
|
|
///
|
|
|
|
enum ircd::m::vm::fault
|
|
|
|
:uint
|
|
|
|
{
|
|
|
|
ACCEPT, ///< No fault.
|
|
|
|
DEBUGSTEP, ///< Debug step. (#db)
|
|
|
|
BREAKPOINT, ///< Debug breakpoint. (#bp)
|
|
|
|
GENERAL, ///< General protection fault. (#gp)
|
|
|
|
EVENT, ///< Eval requires addl events in the ef register (#ef)
|
|
|
|
STATE, ///< Required state is missing (#st)
|
|
|
|
};
|