Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package emulator.code;
- import java.util.LinkedHashMap;
- import emulator.memory.Identifier;
- public class BuiltinType {
- //int (long)
- //unsigned int
- //float (single/double)
- //fixed byte size type (signed/unsigned)
- //boolean
- //char/string
- //Structure (list, vector, hashmap)
- public static class BuiltinType1 {
- Identifier.Type type;
- Identifier.Type default1;
- boolean instantiable;
- Identifier.Type[] extends1;
- }
- public static LinkedHashMap<Identifier.Type, BuiltinType1> typeList = new LinkedHashMap<Identifier.Type, BuiltinType.BuiltinType1>();
- public static void initBuiltinType() {
- Identifier.Type objectT, numberT, intT, floatT, structureT, listT, identifierT, eventT, exceptionT;
- // abstract
- add(objectT = new Identifier.Type(null, new String[] { "builtin", "Object" }), null, false);// abstract, root type
- add(numberT = new Identifier.Type(null, new String[] { "builtin", "primitive", "Number" }), null, false);// abstract
- 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
- 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
- add(structureT = new Identifier.Type(null, new String[] { "builtin", "Structure"}), null, false); // abstract
- add(listT = new Identifier.Type(null, new String[] { "builtin", "Structure", "List" }), null, false, structureT); // abstract
- add(identifierT = new Identifier.Type(null, new String[] { "builtin", "Identifier" }));
- add(eventT = new Identifier.Type(null, new String[] { "builtin", "Event" }), null, false); // abstract
- add(exceptionT = new Identifier.Type(null, new String[] { "builtin", "Event", "Exception" }), null, false, eventT); // abstract
- // text / buffer
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "text", "Char" })); // uint8 or uint16
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "text", "String" })); // list of chars and wchars (unicode)
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Buffer" })); // list of bytes
- // boolean
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Boolean" }));
- // extends int
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int8" }), intT);
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Uint8" }), intT); // byte, char
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int16" }), intT);
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Uint16" }), intT); // wchar
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int32" }), intT);
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Uint32" }), intT);
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Int64" }), intT);
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Int", "Uint64" }), intT);
- // extends float
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Float", "Single" }), floatT);
- add(new Identifier.Type(null, new String[] { "builtin", "primitive", "Number", "Float", "Souble" }), floatT);
- // structure
- add(new Identifier.Type(null, new String[] { "builtin", "Structure", "List", "Linked" }), listT);
- add(new Identifier.Type(null, new String[] { "builtin", "Structure", "List", "Vector" }), listT);
- add(new Identifier.Type(null, new String[] { "builtin", "Structure", "Hashmap" }), structureT); // also used for enum (identifier as key)
- // identifier
- add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "HardwareSystem" }), identifierT);
- add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Program" }), identifierT);
- add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Process" }), identifierT);
- add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Thread" }), identifierT);
- add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Stack" }), identifierT);
- add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Property" }), identifierT);
- add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Code" }), identifierT);
- add(new Identifier.Type(null, new String[] { "builtin", "Identifier", "Type" }), identifierT);
- // ...
- //java.lang.ClassLoader.getSystemClassLoader().
- //new java.lang.Math().
- //new java.lang.Process().
- //java.lang.Runtime.getRuntime().
- //java.lang.
- //Number n;
- //Iterable i;
- //java.util.Collection c;
- //java.util.List l;
- // Throwable t;
- // Error
- // Exception
- // IoException
- // RuntimeException
- // ...
- // exception
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "General" }), exceptionT); // unknown
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "Fatal" }), exceptionT); // hypervisor error (memory error, threading error, hardware error)
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "UnresolvedIdentifier" }), exceptionT); // also for missing permissions
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "NullPointer" }), exceptionT);
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "DivideByZero" }), exceptionT);
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "OutOfBounds" }), exceptionT);
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "OutOfMemory" }), exceptionT);
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "RecursionLimit" }), exceptionT);
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "Io" }), exceptionT); // system failure
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "Net" }), exceptionT); // distributed failure
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "Timeout" }), exceptionT); // for io or distributed
- // event
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "Asynchronous" }), eventT); // message passed
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "Suspend" }), eventT); // thread manual or hypervisor suspend
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "ContinueNextThread" }), eventT); // return to hypervisor
- add(new Identifier.Type(null, new String[] { "builtin", "Event", "Access" }), eventT); // stack access for: stack variables, fields and specific types
- }
- public static void add(Identifier.Type type, Identifier.Type... extends1) {
- BuiltinType1 type1 = new BuiltinType1();
- type1.type = type;
- type1.default1 = null;
- type1.instantiable = true;
- type1.extends1 = extends1;
- typeList.put(type, type1);
- }
- public static void add(Identifier.Type type, Identifier.Type default1, boolean instantiable, Identifier.Type... extends1) {
- assert instantiable == false;
- BuiltinType1 type1 = new BuiltinType1();
- type1.type = type;
- type1.default1 = default1;
- type1.instantiable = instantiable;
- type1.extends1 = extends1;
- typeList.put(type, type1);
- }
- public static Identifier.Type getInstantiableTypeId(Identifier.Type type) {
- assert typeList.containsKey(type);
- BuiltinType1 type1 = typeList.get(type);
- if(type1.instantiable) {
- return type1.type;
- }
- else if(type1.default1 != null) {
- return getInstantiableTypeId(type1.default1);
- }
- return null;
- }
- public static String getName(Identifier.Type type) {
- assert type.package1.length > 0;
- String name = type.package1[type.package1.length - 1];
- return name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment