Advertisement
Dimension

Operation.java

Dec 10th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.81 KB | None | 0 0
  1. package emulator.code;
  2.  
  3. import java.util.LinkedHashMap;
  4.  
  5.  
  6. public class Operation {
  7.     public interface OperationType {
  8.         public interface IExecute{};
  9.         public interface IExecuteExpression{};
  10.        
  11.         public enum Control implements OperationType, IExecute {
  12.             OP_SEQUENCE, // sequence, all items are environment "function calls"
  13.             OP_ENVIRONMENT, // equivalent to "function call", equal to OP_SEQUENCE, params are decls
  14.             // method calls provide "this" environment (single stack with structure object ?)
  15.             // multiple "this" environments (nested non static)
  16.             // fully qualified code identifier (type path)
  17.             // NO LATE BINDING ! provide type path as stack var ! (=> template)
  18.             // provide (static) environments for primitive types (string, int, float)
  19.            
  20.             // accessible environment:
  21.             // OP_ENVIRONMENT param decls (rewire)
  22.             // environment state (local (traditional stack), static-thread-local, static-thread-global, other processes, distributed, ...)
  23.             // type properties (this-pointer, static/see-above)
  24.             // always with typeId, except fixed final stacks (init)
  25.            
  26.            
  27.             //OP_MANAGE, // new, calls object initializer # use SystemCall
  28.             // delete calls object destructor
  29.             // manual memory management, gc control
  30.            
  31.             // USE OP_ACCESS / System API Call :
  32.             // class: reflection
  33.             // code modification / generation, control execute
  34.             // hypervisor control
  35.             // cache control
  36.             // container/string size
  37.             // reference pointer management
  38.             // process/tread fields
  39.             // available stacks
  40.             // analyze/require environment
  41.            
  42.            
  43.             OP_IF, // contains if, elseif, else blocks
  44.             OP_SWITCH, // contains (multiple) case and fallthrough
  45.             OP_FOR_STEP,// init(decl), cond, step
  46.             OP_FOR_LIST,// item, optional i counter, optional reverse, optional concurrent modify
  47.             OP_FOR_LOOP,// i counter; simple decrement
  48.             // list/loop forward/reverse
  49.             OP_WHILE, // while or do-while
  50.             OP_INTERRUPT, // scope, optional "return" expression; break, continue, goto, skip(goto after), return, exit, throw, assert, raise, extern message
  51.             //OP_GOTO, // equal to OP_BREAK
  52.             OP_ASSERT, // breaks on cond to event scope
  53.            
  54.             // further/custom if, switch, loop, macro/generating and function-call constructs will follow
  55.         }  
  56.        
  57.         public enum Expression implements OperationType, IExecute, IExecuteExpression {
  58.             //OP_CONDITIONAL, // EXECUTE IF / SWITCH AS EXPRESSION
  59.             //OP_LITERAL,// USE CONSTANT TABLE !
  60.             OP_ACCESS, // access to stack var, class/type structures, constant tables/ressources, array index, code properties, management/system info/config
  61.             // configure reference, copy, copy deepness
  62.             // does NOT push a new stack item (only decl does)
  63.            
  64.             // TODO copy binary data to stack on access (late deserialization)
  65.            
  66.             OP_ASSIGN, // TODO decl vars, on first use (primitive keyword or type identifier)
  67.             OP_ASSIGN_OP, // '=' follows op
  68.             //OP_PACKED_OP, // OP_ASSIGN_OP -> OP_PACKED_OP -> OP possible
  69.             // packed, cast, ...: is property
  70.            
  71.             // TODO add "new" statement to create instances in expression
  72.             // stack vars although have to be allocated with decl
  73.            
  74.             OP_TRIGGER, // prepares environment and calls function after logic (if present) has arrived to this trigger
  75.             // provide direct access to environment references (return values)
  76.             // configure single/multiple execution (same environment)
  77.             // access multiple return values (assign to var stack or use in expression)
  78.            
  79.  
  80.            
  81.             // A:
  82.             // function(arg1, arg2, result1, result2);
  83.             //
  84.             // B:
  85.             // function(name1: arg1, name2: arg2, name3: result1, name4: result2);
  86.             //
  87.             // C:
  88.             // result1 = function(arg1, arg2).name3;
  89.             //
  90.             // D: // for expression
  91.             // FUNC = function(arg1, arg2); // triggered on first FUNC access
  92.             // result1 = FUNC.name3;
  93.             // result2 = FUNC.name4;
  94.             //
  95.            
  96.            
  97.         }
  98.        
  99.         /*
  100.        
  101.         Type instance = new Type();
  102.         => decl without init, OP_MANAGE (new), OP_ENVIRONMENT (init)
  103.        
  104.         instance = cond ? new Type() : null;
  105.         => OP_ASSIGN, OP_CONDITIONAL, OP_TRIGGER (OP_MAGAGE, OP_ENVIRONMENT)
  106.         trigger pushes instance to expression stack
  107.        
  108.         instance = 1 + new Type().value;
  109.         => OP_ASSIGN, OP_ADD, OP_TRIGGER (OP_MAGAGE, OP_ENVIRONMENT), OP_ACCESS
  110.         trigger pushes instance to expression stack
  111.        
  112.         */
  113.        
  114.         public enum Arithmetic implements OperationType, IExecuteExpression { // detect int / float
  115.             OP_ADD,
  116.             OP_SUB,
  117.             OP_MUL,
  118.             OP_DIV,
  119.             OP_MOD,
  120.             OP_INC, // access
  121.             OP_DEC, // access
  122.             OP_NEGATE, // unary -
  123.         }
  124.        
  125.         public enum Bitwise implements OperationType, IExecuteExpression {
  126.             OP_AND,
  127.             OP_OR,
  128.             OP_XOR, // ^
  129.             OP_COMPLEMENT,
  130.             OP_SHR, // >>
  131.             OP_SHL, // <<
  132.             OP_ROR, // >>|
  133.             OP_ROL, // <<|
  134.         }
  135.        
  136.         public enum Logic implements OperationType, IExecuteExpression {
  137.             OP_AND,
  138.             OP_OR,
  139.             OP_XOR, // ^^
  140.             OP_NOT,
  141.            
  142.             OP_EQ,
  143.             OP_NEQ,
  144.             OP_GT,
  145.             OP_GTE,
  146.             OP_LT,
  147.             OP_LTE,
  148.         }
  149.        
  150.         // structurize with properties
  151.         // events are structure
  152.         /*public enum Structure implements OperationType {
  153.             OP_SCOPE,
  154.             OP_PERMISSION,
  155.         }
  156.        
  157.         public enum Event implements OperationType {
  158.             // arithmetic/bitwise overflow/saturate event
  159.             // null-pointer/divZero exception
  160.             OP_RAISE,
  161.             OP_PUSH,
  162.         }*/
  163.        
  164.         public enum Editor implements OperationType {
  165.             OP_FORMAT, // newlines, breaking rulers, indent / columnize
  166.             // use also for comments between elements
  167.             // normal comments are properties
  168.            
  169.            
  170.             OP_EDITOR, // unparsed code, provide typing editor (EditorItem)
  171.             // keyword(control), identifier(operator: control/expr) or type(decl)
  172.            
  173.             //###OP_CONFIGURE, // unparsed code with keyword, provide placeholders (CodeItem)
  174.             // configure: decl, placeholder code/expr properties
  175.             // distinguish: for for_list for_loop
  176.             // append: if-else else case
  177.         }
  178.        
  179.     }
  180.    
  181.     // assign and unary are R to L !
  182.     // display parens on every bitwise and logic operation
  183.    
  184.     // parens ONLY DISPLAY, not parse. use drag and drop to change expression priority
  185.     LinkedHashMap<OperationType, Integer> priorityTable = new LinkedHashMap<Operation.OperationType, Integer>();
  186.     OperationType[][] priority  = new OperationType[][] {
  187.             new OperationType [] {
  188.                     OperationType.Expression.OP_ACCESS,
  189.                     //OperationType.Expression.OP_TRIGGER,
  190.             },
  191.             new OperationType [] {
  192.                     OperationType.Arithmetic.OP_INC,
  193.                     OperationType.Arithmetic.OP_DEC,
  194.             },
  195.             new OperationType [] {
  196.                     OperationType.Arithmetic.OP_NEGATE,
  197.                     OperationType.Bitwise.OP_COMPLEMENT,
  198.                     OperationType.Logic.OP_NOT,
  199.             },
  200.             new OperationType [] {
  201.                     OperationType.Arithmetic.OP_MUL,
  202.                     OperationType.Arithmetic.OP_DIV,
  203.                     OperationType.Arithmetic.OP_MOD,
  204.             },
  205.             new OperationType [] {
  206.                     OperationType.Arithmetic.OP_ADD,
  207.                     OperationType.Arithmetic.OP_SUB,
  208.             },
  209.             new OperationType [] {
  210.                     OperationType.Bitwise.OP_AND, // surround with parens
  211.                     OperationType.Bitwise.OP_OR, // surround with parens
  212.                     OperationType.Bitwise.OP_XOR, // surround with parens
  213.                     OperationType.Bitwise.OP_SHR,
  214.                     OperationType.Bitwise.OP_SHL,
  215.                     OperationType.Bitwise.OP_ROR,
  216.                     OperationType.Bitwise.OP_ROL,
  217.             },
  218.             new OperationType [] { // surround all with parens
  219.                     OperationType.Logic.OP_EQ,
  220.                     OperationType.Logic.OP_NEQ,
  221.                     OperationType.Logic.OP_GT,
  222.                     OperationType.Logic.OP_GTE,
  223.                     OperationType.Logic.OP_LT,
  224.                     OperationType.Logic.OP_LTE,
  225.             },
  226.             new OperationType [] {
  227.                     OperationType.Logic.OP_AND, // surround with parens
  228.                     OperationType.Logic.OP_OR, // surround with parens
  229.                     OperationType.Logic.OP_XOR, // surround with parens
  230.             },
  231.             new OperationType [] {
  232.                     OperationType.Expression.OP_ASSIGN,
  233.                     OperationType.Expression.OP_ASSIGN_OP,
  234.             },
  235.             new OperationType [] {
  236.                     //OperationType.Expression.OP_CONDITIONAL,
  237.             },
  238.     };
  239.    
  240.     public void explicitPriority() {
  241.        
  242.     }
  243. }
  244.  
  245.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement