Explorar o código

Use interruptable_sleep as an option

Yentl Van Tendeloo %!s(int64=8) %!d(string=hai) anos
pai
achega
cf33fbed38

+ 1 - 1
bootstrap/bootstrap.py

@@ -105,7 +105,7 @@ def bootstrap():
                     "log": ["String", "String"],
                     "time": ["Float"],
                     "hash": ["String", "String"],
-                    "__sleep": ["Float", "Float"],
+                    "__sleep": ["Float", "Float", "Boolean"],
                 }
 
     jit_primitives = {

+ 6 - 2
bootstrap/primitives.alc

@@ -82,10 +82,14 @@ Boolean function is_physical_boolean(a: Element) = ?primitives/is_physical_boole
 Boolean function is_physical_action(a: Element) = ?primitives/is_physical_action
 Float function time() = ?primitives/time
 String function hash(a : String) = ?primitives/hash
-Float function __sleep(a : Float) = ?primitives/__sleep
+Float function __sleep(a : Float, b : Boolean) = ?primitives/__sleep
 
 Void function sleep(a : Float):
-	__sleep(a)
+	__sleep(a, False)
+	return!
+
+Void function interruptable_sleep(a : Float):
+	__sleep(a, True)
 	return!
 
 Element function exec(first_instr : Element):

+ 0 - 18
bootstrap/utils.alc

@@ -54,24 +54,6 @@ String function JSON_print(model : Element):
 	result = result + "]"
 	return result!
 
-Element function input_timeout(timeout : Float):
-	Float start
-	start = time()
-
-	// Do this first, such that we will always get at least the chance to push input in
-	if (has_input()):
-		return input()!
-
-	// Now just try this again from time to time
-	while (time() - start < timeout):
-		if (has_input()):
-			return input()!
-		else:
-			// Nothing to do, we should yield...
-			sleep(0.02)
-
-	return read_root()!
-
 Element function list_reverse(lst : Element):
 	Element result
 	result = create_node()

+ 1 - 1
hybrid_server/classes/task.xml

@@ -39,7 +39,7 @@
                     reply = [mvs_operations[command[0]](*(command[1])) for command in commands]
                 return (0.0, False)
             except SleepKernel as e:
-                return (e.timeout, False)
+                return (e.timeout, e.interruptable)
             except:
                 import traceback
                 print(traceback.format_exc())

+ 2 - 1
interface/HUTN/includes/io.alh

@@ -1,2 +1,3 @@
 Element function input()
-Element function output(value : Element)
+Void function output(value : Element)
+Element function input_timeout(timeout : Float)

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

@@ -92,7 +92,8 @@ Boolean function is_physical_boolean(a : Element)
 Boolean function has_value(a : Element)
 Float function time()
 String function hash(a : String)
-Float function sleep(a : Float)
+Void function sleep(a : Float)
+Void function interruptable_sleep(a : Float)
 
 Element function exec(a : Element)
 Element function resolve(var_name : String)

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

@@ -1,5 +1,4 @@
 String function JSON_print(model : Element)
-Element function input_timeout(timeout : Float)
 Element function list_reverse(lst : Element)
 Element function list_splice(lst : Element, start : Integer, end : Integer)
 Void function list_extend(lst : Element, ext : Element)

+ 5 - 4
kernel/modelverse_kernel/primitives.py

@@ -15,9 +15,10 @@ class InterpretedFunctionFinished(Exception):
 
 class SleepKernel(Exception):
     """Exception to indicate the kernel to sleep for some time."""
-    def __init__(self, timeout):
+    def __init__(self, timeout, interruptable):
         Exception.__init__(self)
         self.timeout = timeout
+        self.interruptable = interruptable
 
 # Functions annotated with __exception_return use the JIT's calling convention instead of
 # the kernel's: returns are handled by throwing a PrimitiveFinished exception; the caller's
@@ -534,7 +535,7 @@ def hash(a, **remainder):
     b, = yield [("CNV", [b_value])]
     raise PrimitiveFinished(b)
 
-def __sleep(a, **remainder):
-    timeout, = yield [("RV", [a])]
-    yield [("SLEEP", [timeout, False])]
+def __sleep(a, b, **remainder):
+    timeout, interruptable = yield [("RV", [a]), ("RV", [b])]
+    yield [("SLEEP", [timeout, interruptable])]
     raise PrimitiveFinished(a)

+ 1 - 1
kernel/modelverse_kernel/request_handler.py

@@ -377,4 +377,4 @@ class RequestHandler(object):
     def execute_sleep(self, request_args):
         """Executes a SLEEP-request with the given argument list."""
         self.append_reply(None)
-        raise primitive_functions.SleepKernel(request_args[0])
+        raise primitive_functions.SleepKernel(request_args[0], request_args[1])

+ 1 - 0
models/SCCD_execute.alc

@@ -4,6 +4,7 @@ include "object_operations.alh"
 include "utils.alh"
 include "random.alh"
 include "library.alh"
+include "io.alh"
 
 Element function resolve_function(location : String, data : Element):
 	if (bool_not(dict_in(data["cache_operations"], location))):