Dimension

BuiltinType.java

Dec 10th, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.99 KB | None | 0 0
  1. package emulator.code;
  2.  
  3. import java.util.LinkedHashMap;
  4.  
  5. import emulator.memory.Identifier;
  6.  
  7. public class BuiltinType {
  8.     //int (long)
  9.     //unsigned int
  10.     //float (single/double)
  11.     //fixed byte size type (signed/unsigned)
  12.     //boolean
  13.     //char/string
  14.  
  15.     //Structure (list, vector, hashmap)
  16.  
  17.     public static class BuiltinType1 {
  18.         Identifier.Type type;
  19.         Identifier.Type default1;
  20.         boolean instantiable;
  21.         Identifier.Type[] extends1;
  22.     }
  23.     public static LinkedHashMap<Identifier.Type, BuiltinType1> typeList = new LinkedHashMap<Identifier.Type, BuiltinType.BuiltinType1>();
  24.  
  25.     public static void initBuiltinType() {
  26.         Identifier.Type objectT, numberT, intT, floatT, structureT, listT, identifierT, eventT, exceptionT;
  27.        
  28.         // abstract
  29.         add(objectT =       new Identifier.Type(null, new String[] { "builtin", "Object" }), null, false);// abstract, root type
  30.         add(numberT =       new Identifier.Type(null, new String[] { "builtin", "primitive", "Number" }), null, false);// abstract
  31.         add(intT =          new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int" }), new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int32" }), false, numberT);// defaults to int32
  32.         add(floatT =        new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Float" }), new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Float", "Double" }), false, numberT);// defaults to double
  33.         add(structureT =    new Identifier.Type(null, new String[] { "builtin", "Structure"}), null, false); // abstract
  34.         add(listT =         new Identifier.Type(null, new String[] { "builtin", "Structure", "List" }), null, false, structureT); // abstract
  35.         add(identifierT =   new Identifier.Type(null, new String[] { "builtin", "Identifier" }));
  36.         add(eventT =        new Identifier.Type(null, new String[] { "builtin", "Event" }), null, false); // abstract
  37.         add(exceptionT =    new Identifier.Type(null, new String[] { "builtin", "Event", "Exception" }), null, false, eventT); // abstract
  38.        
  39.         // text / buffer
  40.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "text", "Char" })); // uint8 or uint16
  41.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "text", "String" })); // list of chars and wchars (unicode)
  42.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Buffer" })); // list of bytes
  43.        
  44.         // boolean
  45.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Boolean" }));
  46.  
  47.         // extends int
  48.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int8" }), intT);
  49.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Uint8" }), intT); // byte, char
  50.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int16" }), intT);
  51.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Uint16" }), intT); // wchar
  52.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int32" }), intT);
  53.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Uint32" }), intT);
  54.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int64" }), intT);
  55.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Uint64" }), intT);
  56.        
  57.         // extends float
  58.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Float", "Single" }), floatT);
  59.         add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Float", "Souble" }), floatT);
  60.        
  61.         // structure
  62.         add(new Identifier.Type(null, new String[] { "builtin", "Structure", "List", "Linked" }), listT);
  63.         add(new Identifier.Type(null, new String[] { "builtin", "Structure", "List", "Vector" }), listT);
  64.         add(new Identifier.Type(null, new String[] { "builtin", "Structure", "Hashmap" }), structureT); // also used for enum (identifier as key)
  65.        
  66.         // identifier
  67.         add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "HardwareSystem" }), identifierT);
  68.         add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Program" }), identifierT);
  69.         add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Process" }), identifierT);
  70.         add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Thread" }), identifierT);
  71.         add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Stack" }), identifierT);
  72.         add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Property" }), identifierT);
  73.         add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Code" }), identifierT);
  74.         add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Type" }), identifierT);
  75.         // ...
  76.        
  77.         //java.lang.ClassLoader.getSystemClassLoader().
  78.         //new java.lang.Math().
  79.         //new java.lang.Process().
  80.         //java.lang.Runtime.getRuntime().
  81.         //java.lang.
  82.         //Number n;
  83.         //Iterable i;
  84.         //java.util.Collection c;
  85.         //java.util.List l;
  86.        
  87.        
  88.         // Throwable t;
  89.         // Error
  90.         // Exception
  91.         // IoException
  92.         // RuntimeException
  93.         // ...
  94.        
  95.         // exception
  96.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "General" }), exceptionT); // unknown
  97.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "Fatal" }), exceptionT); // hypervisor error (memory error, threading error, hardware error)
  98.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "UnresolvedIdentifier" }), exceptionT); // also for missing permissions
  99.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "NullPointer" }), exceptionT);
  100.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "DivideByZero" }), exceptionT);
  101.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "OutOfBounds" }), exceptionT);
  102.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "OutOfMemory" }), exceptionT);
  103.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "RecursionLimit" }), exceptionT);
  104.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "Io" }), exceptionT); // system failure
  105.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "Net" }), exceptionT); // distributed failure
  106.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "Timeout" }), exceptionT); // for io or distributed
  107.  
  108.         // event
  109.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "Asynchronous" }), eventT); // message passed
  110.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "Suspend" }), eventT); // thread manual or hypervisor suspend
  111.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "ContinueNextThread" }), eventT); // return to hypervisor
  112.         add(new Identifier.Type(null, new String[] { "builtin", "Event", "Access" }), eventT); // stack access for: stack variables, fields and specific types
  113.     }
  114.    
  115.     public static void add(Identifier.Type type, Identifier.Type... extends1) {
  116.         BuiltinType1 type1 = new BuiltinType1();
  117.         type1.type = type;
  118.         type1.default1 = null;
  119.         type1.instantiable = true;
  120.         type1.extends1 = extends1;
  121.         typeList.put(type, type1);
  122.     }
  123.    
  124.     public static void add(Identifier.Type type, Identifier.Type default1, boolean instantiable, Identifier.Type... extends1) {
  125.         assert instantiable == false;
  126.        
  127.         BuiltinType1 type1 = new BuiltinType1();
  128.         type1.type = type;
  129.         type1.default1 = default1;
  130.         type1.instantiable = instantiable;
  131.         type1.extends1 = extends1;
  132.         typeList.put(type, type1);
  133.     }
  134.    
  135.     public static Identifier.Type getInstantiableTypeId(Identifier.Type type) {
  136.         assert typeList.containsKey(type);
  137.         BuiltinType1 type1 = typeList.get(type);
  138.  
  139.         if(type1.instantiable) {
  140.             return type1.type;
  141.         }
  142.         else if(type1.default1 != null) {
  143.             return getInstantiableTypeId(type1.default1);
  144.         }
  145.         return null;
  146.     }
  147.    
  148.     public static String getName(Identifier.Type type) {
  149.         assert type.package1.length > 0;
  150.         String name = type.package1[type.package1.length - 1];
  151.        
  152.         return name;
  153.     }
  154. }
  155.  
  156.  
Advertisement
Add Comment
Please, Sign In to add comment