Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 100 lines (76 sloc) 2.038 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#ifndef RBX_PRIMITIVES_HPP
#define RBX_PRIMITIVES_HPP

#include "executor.hpp"
#include "prelude.hpp"

#include <stdexcept>

namespace rubinius {

  /* Forwards */
  class Object;
  class Primitives;
  class Symbol;


  enum PrimitiveRuntimeCode {
    // A weird value, but works well. It looks like a reference to the highest
    // address in memory.
    kPrimitiveFailed = ((unsigned int)-1) & ~TAG_REF_MASK
  };

#ifdef ENABLE_LLVM
  class JITStubResults {
    int arg_count_;
    const char* name_;
    bool pass_callframe_;
    bool can_fail_;

  public:
    JITStubResults()
      : arg_count_(0)
      , name_(0)
      , pass_callframe_(true)
      , can_fail_(false)
    {}

    void set_arg_count(int count) {
      arg_count_ = count;
    }

    int arg_count() const {
      return arg_count_;
    }

    void set_name(const char* name) {
      name_ = name;
    }

    const char* name() const {
      return name_;
    }

    void set_pass_callframe(bool val) {
      pass_callframe_ = val;
    }

    bool pass_callframe() const {
      return pass_callframe_;
    }

    void set_can_fail(bool val) {
      can_fail_ = val;
    }

    bool can_fail() const {
      return can_fail_;
    }

  };
#endif


  class Primitives {
  public:
    static Object* failure() {
      return reinterpret_cast<Object*>(kPrimitiveFailed);
    }

    /*
* The primitive generator emits one 'executor' function per
* primitive. This simply checks the argument types and then
* calls the C++ code that implements the primitive.
* See MachineCode::execute for the version that handles 'regular'
* Ruby code.
*/
    static executor resolve_primitive(STATE, Symbol* name, int* index = 0);
    static Object* unknown_primitive(STATE, CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args);
#ifdef ENABLE_LLVM
    static bool get_jit_stub(int index, JITStubResults& res);
#endif
    static InvokePrimitive get_invoke_stub(STATE, Symbol* name);

#include "gen/primitives_declare.hpp"

  };
}

#endif
Something went wrong with that request. Please try again.