Browse Source

Added a rudimentary form of None...

Yentl Van Tendeloo 4 years ago
parent
commit
990561a052

+ 1 - 0
bootstrap/bootstrap.py

@@ -71,6 +71,7 @@ def bootstrap():
                     "is_physical_string": ["Boolean", "Element"],
                     "is_physical_action": ["Boolean", "Element"],
                     "is_physical_float": ["Boolean", "Element"],
+                    "is_physical_none": ["Boolean", "Element"],
                     "create_node": ["Element"],
                     "create_edge": ["Element", "Element", "Element"],
                     "create_value": ["Element", "Element"],

+ 6 - 1
bootstrap/json.alc

@@ -14,7 +14,10 @@ Void function json_send_data(port : String, data : Element):
 	// Send the current value to the service
 	// First determine what it is!
 
-	if (has_value(data)):
+	if (is_physical_none(data)):
+		comm_set(port, "N")
+		
+	elif (has_value(data)):
 		// Primitive value, so send as-is
 		comm_set(port, "P")
 		comm_set(port, data)
@@ -59,6 +62,8 @@ Element function process_JSON_data(port : String):
 	if (type == "P"):
 		// Primitive data type, so just return as-is
 		result = comm_get(port)
+	elif (type == "N"):
+		result = !none
 	elif (type == "L"):
 		// List, so fetch elements in turn
 		Integer length

+ 2 - 1
bootstrap/primitives.alc

@@ -64,7 +64,8 @@ Boolean function is_physical_float(a: Element) = ?primitives/is_physical_float
 Boolean function is_physical_string(a: Element) = ?primitives/is_physical_string
 Boolean function is_physical_boolean(a: Element) = ?primitives/is_physical_boolean
 Boolean function is_physical_action(a: Element) = ?primitives/is_physical_action
+Boolean function is_physical_none(a: Element) = ?primitives/is_physical_none
 Float function time() = ?primitives/time
 String function hash(a : String) = ?primitives/hash
 Float function __sleep(a : Float, b : Boolean) = ?primitives/__sleep
-Boolean function is_error() = ?primitives/is_error
+Boolean function is_error(a : Element) = ?primitives/is_error

+ 1 - 1
bootstrap/semi_primitives.alc

@@ -129,7 +129,7 @@ Boolean function string_startswith(a: String, b: String):
 	return True!
 
 Boolean function has_value(a: Element):
-	return bool_or(bool_or(bool_or(is_physical_action, is_physical_int(a)), is_physical_float(a)), bool_or(is_physical_string(a), is_physical_boolean(a)))!
+	return bool_or(bool_or(bool_or(is_physical_action, is_physical_int(a)), bool_or(is_physical_none(a), is_physical_float(a))), bool_or(is_physical_string(a), is_physical_boolean(a)))!
 
 Boolean function float_gte(a: Float, b: Float):
 	return bool_or(float_gt(a, b), value_eq(a, b))!

+ 2 - 1
interface/HUTN/grammars/actionlanguage.g

@@ -86,7 +86,7 @@ grammar{
 
     type_specifier: INT | FLOAT | BOOL | STRING | TYPE | ACTION | ELEMENT;
 
-    actionname: IF_NODE | WHILE_NODE | ASSIGN_NODE | CALL_NODE | BREAK_NODE | CONTINUE_NODE | RETURN_NODE | RESOLVE_NODE | ACCESS_NODE | CONSTANT_NODE | GLOBAL_NODE | DECLARE_NODE | INPUT_NODE | OUTPUT_NODE;
+    actionname: IF_NODE | WHILE_NODE | ASSIGN_NODE | CALL_NODE | BREAK_NODE | CONTINUE_NODE | RETURN_NODE | RESOLVE_NODE | ACCESS_NODE | CONSTANT_NODE | GLOBAL_NODE | DECLARE_NODE | INPUT_NODE | OUTPUT_NODE | NONE_NODE;
 
     string: (STRVALUE|LONG_STRVALUE);
 
@@ -147,6 +147,7 @@ grammar{
         OUTPUT_NODE: '!output';
         GLOBAL_NODE: '!global';
         DECLARE_NODE: '!declare';
+        NONE_NODE: '!none';
 
         FUNCTION: 'function';
         RETURN: 'return';

+ 1 - 0
interface/HUTN/includes/primitives.alh

@@ -93,6 +93,7 @@ Boolean function is_physical_float(a : Element)
 Boolean function is_physical_string(a : Element)
 Boolean function is_physical_action(a : Element)
 Boolean function is_physical_boolean(a : Element)
+Boolean function is_physical_none(a : Element)
 Boolean function has_value(a : Element)
 Float function time()
 String function hash(a : String)

+ 5 - 0
kernel/modelverse_kernel/primitives.py

@@ -327,6 +327,11 @@ def is_physical_action(a, **remainder):
     result, = yield [("CNV", [isinstance(t, dict) and t["value"] in ["if", "while", "assign", "call", "break", "continue", "return", "resolve", "access", "constant", "global", "declare"]])]
     raise PrimitiveFinished(result)
 
+def is_physical_none(a, **remainder):
+    t, = yield [("RV", [a])]
+    result, = yield [("CNV", [isinstance(t, dict) and t["value"] == "none"])]
+    raise PrimitiveFinished(result)
+
 def create_node(**remainder):
     result, = yield [("CN", [])]
     raise PrimitiveFinished(result)

+ 6 - 0
scripts/JSON_service.py

@@ -24,6 +24,8 @@ def json_service(port):
             service_set(port, len(data))
             for value in data:
                 print_out_json(value)
+        elif data is None:
+            service_set(port, "N")
         else:
             # Is a primitive value (normally), so send as-is
             service_set(port, "P")
@@ -44,6 +46,8 @@ def json_service(port):
                 rval.append(fetch_data())
         elif data == "P":
             rval = service_get(port)
+        elif data == "N":
+            rval = None
         else:
             raise Exception("Unknown data type: " + data)
         return rval
@@ -57,12 +61,14 @@ def json_service(port):
             json_str = service_get(port)
             json_data = json.loads(json_str)
             print_out_json(json_data)
+            print("Decoded %s" % json_str)
 
         elif mode == "encode":
             service_set(port, "OK")
             json_data = fetch_data()
             json_str = json.dumps(json_data)
             service_set(port, json_str)
+            print("Encoded %s" % json_str)
             
         else:
             raise Exception("No such mode: " + mode)

+ 1 - 1
state/modelverse_state/main.py

@@ -13,7 +13,7 @@ if sys.version > '3': # pragma: no cover
 else: # pragma: no cover
     integer_types = (int, long)
     primitive_types = (int, long, float, str, bool, unicode)
-complex_primitives = frozenset(["if", "while", "assign", "call", "break", "continue", "return","resolve","access", "constant", "input", "output", "declare", "global"])
+complex_primitives = frozenset(["if", "while", "assign", "call", "break", "continue", "return","resolve","access", "constant", "input", "output", "declare", "global", "none"])
 
 def instance_to_string(value):
     return value["value"]

+ 1 - 1
wrappers/modelverse.py

@@ -118,7 +118,7 @@ def _get_metamodel(model):
         raise UnknownMetamodellingHierarchy(model)
 
 def _check_type(value):
-    if not isinstance(value, (int, long, float, str, unicode, bool)):
+    if not isinstance(value, (int, long, float, str, unicode, bool, type(None))):
         raise UnsupportedValue("%s : %s" % (value, str(type(value))))
 
 def _check_type_list(value):