use num_derive::{FromPrimitive, ToPrimitive}; #[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)] pub enum Op { Noop, Nothing, Nil, True, False, Constant, Jump, JumpIfFalse, JumpIfTrue, Pop, PopN, PushBinding, PushGlobal, Store, StoreN, Stash, Load, LoadN, ResetMatch, Match, MatchNil, MatchTrue, MatchFalse, PanicIfNoMatch, MatchConstant, MatchString, PushStringMatches, MatchType, MatchTuple, MatchSplattedTuple, PushTuple, LoadTuple, LoadSplattedTuple, MatchList, MatchSplattedList, LoadList, LoadSplattedList, PushList, AppendList, ConcatList, PushDict, AppendDict, ConcatDict, LoadDictValue, MatchDict, MatchSplattedDict, DropDictEntry, PushBox, GetKey, PanicNoWhen, JumpIfNoMatch, JumpIfMatch, PanicNoMatch, TypeOf, JumpBack, JumpIfZero, Duplicate, Decrement, Truncate, MatchDepth, Panic, EmptyString, ConcatStrings, Stringify, Call, TailCall, Return, Partial, Eq, Add, Sub, Mult, Div, Unbox, BoxStore, Assert, Get, At, Not, Print, SetUpvalue, GetUpvalue, Msg, // Inc, // Dec, // Gt, // Gte, // Lt, // Lte, // Mod, // Round, // Ceil, // Floor, // Random, // Sqrt, // Assoc, // Concat, // Conj, // Count, // Disj, // Dissoc, // Range, // Rest, // Slice, // "atan_2" math/atan2 // "chars" chars // "cos" math/cos // "doc" doc // "downcase" string/ascii-lower // "pi" math/pi // "show" show // "sin" math/sin // "split" string/split // "str_slice" string/slice // "tan" math/tan // "trim" string/trim // "triml" string/triml // "trimr" string/trimr // "upcase" string/ascii-upper } impl std::fmt::Display for Op { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { use Op::*; let rep = match self { Msg => "msg", Noop => "noop", Nothing => "nothing", Nil => "nil", True => "true", False => "false", Constant => "constant", Jump => "jump", JumpIfFalse => "jump_if_false", JumpIfTrue => "jump_if_true", Pop => "pop", PopN => "pop_n", PushBinding => "push_binding", PushGlobal => "push_global", Store => "store", StoreN => "store_n", Stash => "stash", Load => "load", LoadN => "load_n", Match => "match", MatchNil => "match_nil", MatchTrue => "match_true", MatchFalse => "match_false", ResetMatch => "reset_match", PanicIfNoMatch => "panic_if_no_match", MatchConstant => "match_constant", MatchString => "match_string", PushStringMatches => "push_string_matches", MatchType => "match_type", MatchTuple => "match_tuple", MatchSplattedTuple => "match_splatted_tuple", PushTuple => "push_tuple", LoadTuple => "load_tuple", LoadSplattedTuple => "load_splatted_tuple", MatchList => "match_list", MatchSplattedList => "match_splatted_list", LoadList => "load_list", LoadSplattedList => "load_splatted_list", PushList => "push_list", AppendList => "append_list", ConcatList => "concat_list", PushDict => "push_dict", AppendDict => "append_dict", ConcatDict => "concat_dict", LoadDictValue => "load_dict_value", MatchDict => "match_dict", MatchSplattedDict => "match_splatted_dict", DropDictEntry => "drop_dict_entry", PushBox => "push_box", GetKey => "get_key", PanicNoWhen => "panic_no_when", JumpIfNoMatch => "jump_if_no_match", JumpIfMatch => "jump_if_match", PanicNoMatch => "panic_no_match", TypeOf => "type_of", JumpBack => "jump_back", JumpIfZero => "jump_if_zero", Decrement => "decrement", Truncate => "truncate", Duplicate => "duplicate", MatchDepth => "match_depth", Panic => "panic", EmptyString => "empty_string", ConcatStrings => "concat_strings", Stringify => "stringify", Print => "print", Eq => "eq", Add => "add", Sub => "sub", Mult => "mult", Div => "div", Unbox => "unbox", BoxStore => "box_store", Assert => "assert", Get => "get", At => "at", Not => "not", Call => "call", Return => "return", Partial => "partial", TailCall => "tail_call", SetUpvalue => "set_upvalue", GetUpvalue => "get_upvalue", }; write!(f, "{rep}") } }