From 53f9ee13de8021b102d51cc731d3320e2bfaf202 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Sat, 23 Aug 2008 23:10:41 -0700 Subject: [PATCH] Moved C++ exceptions classes to their own file. --- vm/{object.cpp => exception.cpp} | 2 +- vm/exception.hpp | 82 ++++++++++++++++++++++++++++++++ vm/object.hpp | 73 +--------------------------- 3 files changed, 84 insertions(+), 73 deletions(-) rename vm/{object.cpp => exception.cpp} (98%) create mode 100644 vm/exception.hpp diff --git a/vm/object.cpp b/vm/exception.cpp similarity index 98% rename from vm/object.cpp rename to vm/exception.cpp index dfdf935eaa..b4fac2de89 100644 --- a/vm/object.cpp +++ b/vm/exception.cpp @@ -1,5 +1,5 @@ #include "prelude.hpp" -#include "object.hpp" +#include "exception.hpp" #include #include #include diff --git a/vm/exception.hpp b/vm/exception.hpp new file mode 100644 index 0000000000..428af7a270 --- /dev/null +++ b/vm/exception.hpp @@ -0,0 +1,82 @@ +#ifndef RBX_EXCEPTION_HPP +#define RBX_EXCEPTION_HPP + +#include "prelude.hpp" +#include "builtin/object.hpp" + +namespace rubinius { + + void abort(); + void print_backtrace(); + + class VMException { + public: + typedef std::vector Backtrace; + + Backtrace* backtrace; + VMException(); + void print_backtrace(); + }; + + class Assertion : public VMException { + public: + char *reason; + + // Used instead of throwing an Assertion directly so that + // you can set a breakpoint on raise. + static void raise(const char* mesg); + + Assertion(const char* reason) { + this->reason = strdup(reason); + } + + ~Assertion() { + free(reason); + } + }; + + class TypeError : public VMException { + public: + object_type type; + OBJECT object; + const char* reason; + + // Used instead of throw'ning a TypeError directly, + // so that breakpoints can be set on this function and easily be + // debugged. + static void raise(object_type type, OBJECT obj, const char* reason = NULL); + + TypeError(object_type type, OBJECT obj, const char* reason = NULL) + : type(type), object(obj), reason(reason) { }; + }; + + class ObjectBoundsExceeded : public VMException { + public: + OBJECT obj; + size_t index; + + static void raise(OBJECT o, size_t i); + + ObjectBoundsExceeded(OBJECT o, size_t i) : obj(o), index(i) { } + }; + + class ZeroDivisionError : public VMException { + public: + INTEGER i; + const char* reason; + + ZeroDivisionError(INTEGER i, const char* reason = NULL) + : i(i), reason(reason) { }; + }; + + class FloatDomainError : public VMException { + public: + double d; + const char* reason; + + FloatDomainError(double d, const char* reason = NULL) + : d(d), reason(reason) { }; + }; +}; + +#endif diff --git a/vm/object.hpp b/vm/object.hpp index 50cbc4695b..3c3a69c27a 100644 --- a/vm/object.hpp +++ b/vm/object.hpp @@ -10,84 +10,13 @@ #include "prelude.hpp" #include "builtin/object.hpp" +#include "exception.hpp" /* Defines all the most common operations on for dealing with * objects, such as type checking and casting. */ namespace rubinius { - void abort(); - void print_backtrace(); - - class VMException { - public: - typedef std::vector Backtrace; - - Backtrace* backtrace; - VMException(); - void print_backtrace(); - }; - - class Assertion : public VMException { - public: - char *reason; - - // Used instead of throwing an Assertion directly so that - // you can set a breakpoint on raise. - static void raise(const char* mesg); - - Assertion(const char* reason) { - this->reason = strdup(reason); - } - - ~Assertion() { - free(reason); - } - }; - - class TypeError : public VMException { - public: - object_type type; - OBJECT object; - const char* reason; - - // Used instead of throw'ning a TypeError directly, - // so that breakpoints can be set on this function and easily be - // debugged. - static void raise(object_type type, OBJECT obj, const char* reason = NULL); - - TypeError(object_type type, OBJECT obj, const char* reason = NULL) - : type(type), object(obj), reason(reason) { }; - }; - - class ObjectBoundsExceeded : public VMException { - public: - OBJECT obj; - size_t index; - - static void raise(OBJECT o, size_t i); - - ObjectBoundsExceeded(OBJECT o, size_t i) : obj(o), index(i) { } - }; - - class ZeroDivisionError : public VMException { - public: - INTEGER i; - const char* reason; - - ZeroDivisionError(INTEGER i, const char* reason = NULL) - : i(i), reason(reason) { }; - }; - - class FloatDomainError : public VMException { - public: - double d; - const char* reason; - - FloatDomainError(double d, const char* reason = NULL) - : d(d), reason(reason) { }; - }; - void inspect(STATE, OBJECT); void inspect(STATE, SYMBOL);