Browse Source

Make 'list_len' an intrinsic

jonathanvdc 8 years ago
parent
commit
d88e84c800
2 changed files with 37 additions and 1 deletions
  1. 9 1
      kernel/modelverse_jit/intrinsics.py
  2. 28 0
      kernel/modelverse_jit/tree_ir.py

+ 9 - 1
kernel/modelverse_jit/intrinsics.py

@@ -153,7 +153,15 @@ MISC_INTRINSICS = {
     'dict_add' : __dict_add,
 
     # Set operations
-    'set_add' : __set_add
+    'set_add' : __set_add,
+
+    # List operations
+    'list_len' :
+        lambda a:
+        tree_ir.CreateNodeWithValueInstruction(
+            tree_ir.CallInstruction(
+                tree_ir.LoadGlobalInstruction('len'),
+                [tree_ir.ReadOutgoingEdgesInstruction(a)]))
 }
 
 def register_intrinsics(target_jit):

+ 28 - 0
kernel/modelverse_jit/tree_ir.py

@@ -1048,6 +1048,34 @@ class ReadEdgeInstruction(StateInstruction):
         """Gets this state instruction's argument list."""
         return [self.node_id]
 
+class ReadOutgoingEdgesInstruction(StateInstruction):
+    """An instruction that reads all outgoing edges for a node."""
+    def __init__(self, node_id):
+        StateInstruction.__init__(self)
+        self.node_id = node_id
+
+    def get_opcode(self):
+        """Gets the opcode for this state instruction."""
+        return "RO"
+
+    def get_arguments(self):
+        """Gets this state instruction's argument list."""
+        return [self.node_id]
+
+class ReadIncomingEdgesInstruction(StateInstruction):
+    """An instruction that reads all incoming edges for a node."""
+    def __init__(self, node_id):
+        StateInstruction.__init__(self)
+        self.node_id = node_id
+
+    def get_opcode(self):
+        """Gets the opcode for this state instruction."""
+        return "RI"
+
+    def get_arguments(self):
+        """Gets this state instruction's argument list."""
+        return [self.node_id]
+
 class CreateNodeInstruction(StateInstruction):
     """An instruction that creates an empty node."""