فهرست منبع

Add some string operations to the JIT intrinsics

jonathanvdc 8 سال پیش
والد
کامیت
d01b72eb90
1فایلهای تغییر یافته به همراه25 افزوده شده و 0 حذف شده
  1. 25 0
      kernel/modelverse_jit/intrinsics.py

+ 25 - 0
kernel/modelverse_jit/intrinsics.py

@@ -44,6 +44,31 @@ MISC_INTRINSICS = {
         tree_ir.CreateNodeWithValueInstruction(
             tree_ir.BinaryInstruction(lhs, '!=', rhs)),
 
+    # Strings
+    'string_get' :
+        lambda str_node, index_node:
+        tree_ir.CreateNodeWithValueInstruction(
+            tree_ir.LoadIndexInstruction(
+                tree_ir.ReadValueInstruction(str_node),
+                tree_ir.ReadValueInstruction(index_node))),
+    'string_len' :
+        lambda str_node:
+        tree_ir.CreateNodeWithValueInstruction(
+            tree_ir.CallInstruction(
+                tree_ir.LoadGlobalInstruction('len'),
+                [tree_ir.ReadValueInstruction(str_node)])),
+    'string_join' :
+        lambda lhs, rhs:
+        tree_ir.CreateNodeWithValueInstruction(
+            tree_ir.BinaryInstruction(
+                tree_ir.CallInstruction(
+                    tree_ir.LoadGlobalInstruction('str'),
+                    [tree_ir.ReadValueInstruction(lhs)]),
+                '+',
+                tree_ir.CallInstruction(
+                    tree_ir.LoadGlobalInstruction('str'),
+                    [tree_ir.ReadValueInstruction(rhs)]))),
+
     # State creation
     'create_node' : tree_ir.CreateNodeInstruction,
     'create_edge' : tree_ir.CreateEdgeInstruction,