Add ClassCastException thrower, small refactoring. (#67)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "Assert.h"
|
||||
#include "Exceptions.h"
|
||||
@@ -10,7 +12,7 @@ void ThrowNullPointerException() {
|
||||
void* pc = __builtin_return_address(0);
|
||||
char message[100];
|
||||
snprintf(message, sizeof(message), "NullPointerException at %p", pc);
|
||||
fprintf(stderr, "%s\n", message);
|
||||
write(STDOUT_FILENO, message, strlen(message));
|
||||
// TODO: throw it for real.
|
||||
RuntimeAssert(false, "Throwing is unsupported");
|
||||
}
|
||||
@@ -19,11 +21,21 @@ void ThrowArrayIndexOutOfBoundsException() {
|
||||
void* pc = __builtin_return_address(0);
|
||||
char message[100];
|
||||
snprintf(message, sizeof(message), "ArrayIndexOutOfBoundsException at %p", pc);
|
||||
fprintf(stderr, "%s\n", message);
|
||||
write(STDOUT_FILENO, message, strlen(message));
|
||||
// TODO: throw it for real.
|
||||
RuntimeAssert(false, "Throwing is unsupported");
|
||||
}
|
||||
|
||||
void ThrowClassCastException() {
|
||||
void* pc = __builtin_return_address(0);
|
||||
char message[100];
|
||||
snprintf(message, sizeof(message), "ClassCastException at %p", pc);
|
||||
write(STDOUT_FILENO, message, strlen(message));
|
||||
// TODO: throw it for real.
|
||||
RuntimeAssert(false, "Throwing is unsupported");
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef RUNTIME_EXCEPTIONS_H
|
||||
#define RUNTIME_EXCEPTIONS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "Types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -11,6 +11,8 @@ void ThrowNullPointerException();
|
||||
// Throws array index out of bounds exception.
|
||||
// Context is evaluated from caller's address.
|
||||
void ThrowArrayIndexOutOfBoundsException();
|
||||
// Throws class cast exception.
|
||||
void ThrowClassCastException();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
@@ -85,6 +85,12 @@ inline void* AddressOfElementAt(ArrayHeader* obj, int32_t index) {
|
||||
obj->type_info()->instanceSize_ * index;
|
||||
}
|
||||
|
||||
inline const void* AddressOfElementAt(const ArrayHeader* obj, int32_t index) {
|
||||
// Instance size is negative.
|
||||
return reinterpret_cast<const uint8_t*>(obj + 1) -
|
||||
obj->type_info()->instanceSize_ * index;
|
||||
}
|
||||
|
||||
inline uint32_t ArrayDataSizeBytes(const ArrayHeader* obj) {
|
||||
// Instance size is negative.
|
||||
return -obj->type_info()->instanceSize_ * obj->count_;
|
||||
|
||||
@@ -1,23 +1,8 @@
|
||||
#ifndef RUNTIME_NATIVES_H
|
||||
#define RUNTIME_NATIVES_H
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Types.h"
|
||||
|
||||
typedef uint8_t KBoolean;
|
||||
typedef int8_t KByte;
|
||||
typedef uint16_t KChar;
|
||||
// Note that it is signed.
|
||||
typedef int16_t KShort;
|
||||
typedef int32_t KInt;
|
||||
typedef int64_t KLong;
|
||||
typedef float KFloat;
|
||||
typedef double KDouble;
|
||||
|
||||
typedef ObjHeader* KRef;
|
||||
typedef const ObjHeader* KConstRef;
|
||||
typedef const ArrayHeader* KString;
|
||||
|
||||
// Optimized versions not accessing type info.
|
||||
inline KByte* ByteArrayAddressOfElementAt(ArrayHeader* obj, KInt index) {
|
||||
return reinterpret_cast<KByte*>(obj + 1) + index;
|
||||
|
||||
@@ -1,8 +1,23 @@
|
||||
#ifndef RUNTIME_TYPES_H
|
||||
#define RUNTIME_TYPES_H
|
||||
|
||||
#include "Memory.h"
|
||||
#include "TypeInfo.h"
|
||||
|
||||
// Note that almost all types are signed.
|
||||
typedef uint8_t KBoolean;
|
||||
typedef int8_t KByte;
|
||||
typedef uint16_t KChar;
|
||||
typedef int16_t KShort;
|
||||
typedef int32_t KInt;
|
||||
typedef int64_t KLong;
|
||||
typedef float KFloat;
|
||||
typedef double KDouble;
|
||||
|
||||
typedef ObjHeader* KRef;
|
||||
typedef const ObjHeader* KConstRef;
|
||||
typedef const ArrayHeader* KString;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user