Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package emulator.code;
- import java.util.LinkedHashMap;
- public class Operation {
- public interface OperationType {
- public interface IExecute{};
- public interface IExecuteExpression{};
- public enum Control implements OperationType, IExecute {
- OP_SEQUENCE, // sequence, all items are environment "function calls"
- OP_ENVIRONMENT, // equivalent to "function call", equal to OP_SEQUENCE, params are decls
- // method calls provide "this" environment (single stack with structure object ?)
- // multiple "this" environments (nested non static)
- // fully qualified code identifier (type path)
- // NO LATE BINDING ! provide type path as stack var ! (=> template)
- // provide (static) environments for primitive types (string, int, float)
- // accessible environment:
- // OP_ENVIRONMENT param decls (rewire)
- // environment state (local (traditional stack), static-thread-local, static-thread-global, other processes, distributed, ...)
- // type properties (this-pointer, static/see-above)
- // always with typeId, except fixed final stacks (init)
- //OP_MANAGE, // new, calls object initializer # use SystemCall
- // delete calls object destructor
- // manual memory management, gc control
- // USE OP_ACCESS / System API Call :
- // class: reflection
- // code modification / generation, control execute
- // hypervisor control
- // cache control
- // container/string size
- // reference pointer management
- // process/tread fields
- // available stacks
- // analyze/require environment
- OP_IF, // contains if, elseif, else blocks
- OP_SWITCH, // contains (multiple) case and fallthrough
- OP_FOR_STEP,// init(decl), cond, step
- OP_FOR_LIST,// item, optional i counter, optional reverse, optional concurrent modify
- OP_FOR_LOOP,// i counter; simple decrement
- // list/loop forward/reverse
- OP_WHILE, // while or do-while
- OP_INTERRUPT, // scope, optional "return" expression; break, continue, goto, skip(goto after), return, exit, throw, assert, raise, extern message
- //OP_GOTO, // equal to OP_BREAK
- OP_ASSERT, // breaks on cond to event scope
- // further/custom if, switch, loop, macro/generating and function-call constructs will follow
- }
- public enum Expression implements OperationType, IExecute, IExecuteExpression {
- //OP_CONDITIONAL, // EXECUTE IF / SWITCH AS EXPRESSION
- //OP_LITERAL,// USE CONSTANT TABLE !
- OP_ACCESS, // access to stack var, class/type structures, constant tables/ressources, array index, code properties, management/system info/config
- // configure reference, copy, copy deepness
- // does NOT push a new stack item (only decl does)
- // TODO copy binary data to stack on access (late deserialization)
- OP_ASSIGN, // TODO decl vars, on first use (primitive keyword or type identifier)
- OP_ASSIGN_OP, // '=' follows op
- //OP_PACKED_OP, // OP_ASSIGN_OP -> OP_PACKED_OP -> OP possible
- // packed, cast, ...: is property
- // TODO add "new" statement to create instances in expression
- // stack vars although have to be allocated with decl
- OP_TRIGGER, // prepares environment and calls function after logic (if present) has arrived to this trigger
- // provide direct access to environment references (return values)
- // configure single/multiple execution (same environment)
- // access multiple return values (assign to var stack or use in expression)
- // A:
- // function(arg1, arg2, result1, result2);
- //
- // B:
- // function(name1: arg1, name2: arg2, name3: result1, name4: result2);
- //
- // C:
- // result1 = function(arg1, arg2).name3;
- //
- // D: // for expression
- // FUNC = function(arg1, arg2); // triggered on first FUNC access
- // result1 = FUNC.name3;
- // result2 = FUNC.name4;
- //
- }
- /*
- Type instance = new Type();
- => decl without init, OP_MANAGE (new), OP_ENVIRONMENT (init)
- instance = cond ? new Type() : null;
- => OP_ASSIGN, OP_CONDITIONAL, OP_TRIGGER (OP_MAGAGE, OP_ENVIRONMENT)
- trigger pushes instance to expression stack
- instance = 1 + new Type().value;
- => OP_ASSIGN, OP_ADD, OP_TRIGGER (OP_MAGAGE, OP_ENVIRONMENT), OP_ACCESS
- trigger pushes instance to expression stack
- */
- public enum Arithmetic implements OperationType, IExecuteExpression { // detect int / float
- OP_ADD,
- OP_SUB,
- OP_MUL,
- OP_DIV,
- OP_MOD,
- OP_INC, // access
- OP_DEC, // access
- OP_NEGATE, // unary -
- }
- public enum Bitwise implements OperationType, IExecuteExpression {
- OP_AND,
- OP_OR,
- OP_XOR, // ^
- OP_COMPLEMENT,
- OP_SHR, // >>
- OP_SHL, // <<
- OP_ROR, // >>|
- OP_ROL, // <<|
- }
- public enum Logic implements OperationType, IExecuteExpression {
- OP_AND,
- OP_OR,
- OP_XOR, // ^^
- OP_NOT,
- OP_EQ,
- OP_NEQ,
- OP_GT,
- OP_GTE,
- OP_LT,
- OP_LTE,
- }
- // structurize with properties
- // events are structure
- /*public enum Structure implements OperationType {
- OP_SCOPE,
- OP_PERMISSION,
- }
- public enum Event implements OperationType {
- // arithmetic/bitwise overflow/saturate event
- // null-pointer/divZero exception
- OP_RAISE,
- OP_PUSH,
- }*/
- public enum Editor implements OperationType {
- OP_FORMAT, // newlines, breaking rulers, indent / columnize
- // use also for comments between elements
- // normal comments are properties
- OP_EDITOR, // unparsed code, provide typing editor (EditorItem)
- // keyword(control), identifier(operator: control/expr) or type(decl)
- //###OP_CONFIGURE, // unparsed code with keyword, provide placeholders (CodeItem)
- // configure: decl, placeholder code/expr properties
- // distinguish: for for_list for_loop
- // append: if-else else case
- }
- }
- // assign and unary are R to L !
- // display parens on every bitwise and logic operation
- // parens ONLY DISPLAY, not parse. use drag and drop to change expression priority
- LinkedHashMap<OperationType, Integer> priorityTable = new LinkedHashMap<Operation.OperationType, Integer>();
- OperationType[][] priority = new OperationType[][] {
- new OperationType [] {
- OperationType.Expression.OP_ACCESS,
- //OperationType.Expression.OP_TRIGGER,
- },
- new OperationType [] {
- OperationType.Arithmetic.OP_INC,
- OperationType.Arithmetic.OP_DEC,
- },
- new OperationType [] {
- OperationType.Arithmetic.OP_NEGATE,
- OperationType.Bitwise.OP_COMPLEMENT,
- OperationType.Logic.OP_NOT,
- },
- new OperationType [] {
- OperationType.Arithmetic.OP_MUL,
- OperationType.Arithmetic.OP_DIV,
- OperationType.Arithmetic.OP_MOD,
- },
- new OperationType [] {
- OperationType.Arithmetic.OP_ADD,
- OperationType.Arithmetic.OP_SUB,
- },
- new OperationType [] {
- OperationType.Bitwise.OP_AND, // surround with parens
- OperationType.Bitwise.OP_OR, // surround with parens
- OperationType.Bitwise.OP_XOR, // surround with parens
- OperationType.Bitwise.OP_SHR,
- OperationType.Bitwise.OP_SHL,
- OperationType.Bitwise.OP_ROR,
- OperationType.Bitwise.OP_ROL,
- },
- new OperationType [] { // surround all with parens
- OperationType.Logic.OP_EQ,
- OperationType.Logic.OP_NEQ,
- OperationType.Logic.OP_GT,
- OperationType.Logic.OP_GTE,
- OperationType.Logic.OP_LT,
- OperationType.Logic.OP_LTE,
- },
- new OperationType [] {
- OperationType.Logic.OP_AND, // surround with parens
- OperationType.Logic.OP_OR, // surround with parens
- OperationType.Logic.OP_XOR, // surround with parens
- },
- new OperationType [] {
- OperationType.Expression.OP_ASSIGN,
- OperationType.Expression.OP_ASSIGN_OP,
- },
- new OperationType [] {
- //OperationType.Expression.OP_CONDITIONAL,
- },
- };
- public void explicitPriority() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement