diff src/jit-ir.h @ 15056:bc32288f4a42

Support the end keyword for one dimentional indexing in JIT. * src/jit-ir.cc (jit_magic_end): New class. * src/jit-ir.h (jit_magic_end): New class. (jit_instruction::jit_instruction): New overload. * src/jit-typeinfo.cc (jit_function::call): Throw jit_fail_exception if invalid. (jit_typeinfo::jit_typeinfo): Initialize end_fn. * src/jit-typeinfo.h (jit_typeinfo::end): New function. * src/pt-jit.cc (jit_convert::visit_identifier): Handle magic_end. (jit_convert::resolve): Keep track of end context. (jit_convert::convert_llvm::visit): New overload. * src/pt-jit.h (jit_convert): Add end_context.
author Max Brister <max@2bass.com>
date Mon, 30 Jul 2012 13:05:29 -0500
parents 005cb78e1dd1
children df4538e3b50b
line wrap: on
line diff
--- a/src/jit-ir.h	Mon Jul 30 16:23:52 2012 +0100
+++ b/src/jit-ir.h	Mon Jul 30 13:05:29 2012 -0500
@@ -46,7 +46,8 @@
   JIT_METH(variable);                           \
   JIT_METH(error_check);                        \
   JIT_METH(assign)                              \
-  JIT_METH(argument)
+  JIT_METH(argument)                            \
+  JIT_METH(magic_end)
 
 #define JIT_VISIT_IR_CONST                      \
   JIT_METH(const_bool);                         \
@@ -256,6 +257,14 @@
 #undef STASH_ARG
 #undef JIT_INSTRUCTION_CTOR
 
+  jit_instruction (const std::vector<jit_value *>& aarguments)
+  : already_infered (aarguments.size ()), marguments (aarguments.size ()),
+    mid (next_id ()), mparent (0)
+  {
+    for (size_t i = 0; i < aarguments.size (); ++i)
+      stash_argument (i, aarguments[i]);
+  }
+
   static void reset_ids (void)
   {
     next_id (true);
@@ -1137,6 +1146,34 @@
   }
 };
 
+// for now only handles the 1D case
+class
+jit_magic_end : public jit_instruction
+{
+public:
+  jit_magic_end (const std::vector<jit_value *>& context)
+    : jit_instruction (context)
+  {}
+
+  const jit_function& overload () const;
+
+  jit_value *resolve_context (void) const;
+
+  virtual bool infer (void);
+
+  virtual std::ostream& short_print (std::ostream& os) const
+  {
+    return os << "magic_end";
+  }
+
+  virtual std::ostream& print (std::ostream& os, size_t indent = 0) const
+  {
+    return short_print (print_indent (os, indent));
+  }
+
+  JIT_VALUE_ACCEPT;
+};
+
 class
 jit_extract_argument : public jit_assign_base
 {