Permalink
Browse files

Added runtime functions and separated core runtime classes into separ…

…ate modules.
  • Loading branch information...
wilkie committed May 9, 2010
1 parent 8963c59 commit 08e9e7e1b411cbbf4a724b28d48613ec7e9feb1b
View
@@ -39,10 +39,10 @@ DFILES_PLATFORM_XOMB = platform/xomb/main.d platform/xomb/common.d platform/xomb
DFILES_ANALYZING = analyzing/debugger.d
DFILES_LOCALES = locales/en_us.d locales/fr_fr.d locales/all.d
-DFILES_CORE = core/date.d core/locale.d core/variant.d core/exception.d core/event.d core/library.d core/system.d core/regex.d core/arguments.d core/definitions.d core/application.d core/time.d core/timezone.d core/unicode.d core/endian.d core/stream.d core/string.d core/main.d core/color.d
+DFILES_CORE = core/date.d core/locale.d core/variant.d core/exception.d core/event.d core/library.d core/system.d core/regex.d core/arguments.d core/definitions.d core/application.d core/time.d core/timezone.d core/unicode.d core/endian.d core/stream.d core/string.d core/main.d core/color.d core/error.d
DFILES_GUI = gui/container.d gui/trackbar.d gui/radiogroup.d gui/progressbar.d gui/togglefield.d gui/listfield.d gui/listbox.d gui/vscrollbar.d gui/hscrollbar.d gui/button.d gui/textfield.d gui/window.d gui/widget.d gui/application.d
DFILES_DATA = data/stack.d data/queue.d data/queue2.d data/fibonacci.d data/heap.d data/list.d data/iterable.d
-DFILES_RUNTIME = #runtime/array.d #runtime/apply.d runtime/lifetime.d
+DFILES_RUNTIME = #runtime/array.d runtime/apply.d #runtime/lifetime.d runtime/gc.d runtime/exception.d
DFILES_PARSING = parsing/d/trees.d parsing/d/addexprunit.d parsing/d/andexprunit.d parsing/d/assignexprunit.d parsing/d/blockstmtunit.d parsing/d/switchstmtunit.d parsing/d/casestmtunit.d parsing/d/defaultstmtunit.d parsing/d/breakstmtunit.d parsing/d/continuestmtunit.d parsing/d/gotostmtunit.d parsing/d/returnstmtunit.d parsing/d/volatilestmtunit.d parsing/d/throwstmtunit.d parsing/d/postfixexprlistunit.d parsing/d/cmpexprunit.d parsing/d/conditionalexprunit.d parsing/d/declarationunit.d parsing/d/expressionunit.d parsing/d/importdeclunit.d parsing/d/isexprunit.d parsing/d/lexer.d parsing/d/logicalandexprunit.d parsing/d/logicalorexprunit.d parsing/d/moduledeclunit.d parsing/d/moduleunit.d parsing/d/mulexprunit.d parsing/d/nodes.d parsing/d/orexprunit.d parsing/d/parser.d parsing/d/postfixexprunit.d parsing/d/primaryexprunit.d parsing/d/shiftexprunit.d parsing/d/staticunit.d parsing/d/declaratorunit.d parsing/d/declaratorsuffixunit.d parsing/d/declaratortypeunit.d parsing/d/tokens.d parsing/d/enumdeclunit.d parsing/d/typeunit.d parsing/d/enumbodyunit.d parsing/d/aggregatedeclunit.d parsing/d/aggregatebodyunit.d parsing/d/classbodyunit.d parsing/d/templatebodyunit.d parsing/d/interfacebodyunit.d parsing/d/classdeclunit.d parsing/d/interfacedeclunit.d parsing/d/constructorunit.d parsing/d/destructorunit.d parsing/d/parameterlistunit.d parsing/d/functionbodyunit.d parsing/d/staticifunit.d parsing/d/versionunit.d parsing/d/debugunit.d parsing/d/unittestunit.d parsing/d/parameterunit.d parsing/d/basictypeunit.d parsing/d/statementunit.d parsing/d/pragmastmtunit.d parsing/d/staticassertunit.d parsing/d/foreachstmtunit.d parsing/d/scopedstmtunit.d parsing/d/forstmtunit.d parsing/d/typedeclarationunit.d parsing/d/unaryexprunit.d parsing/d/xorexprunit.d parsing/ast.d parsing/lexer.d parsing/token.d parsing/parser.d parsing/options.d parsing/cfg.d parsing/parseunit.d
DFILES = djehuty.d
DFILES_BINARY_CODECS = decoders/binary/decoder.d decoders/binary/base64.d decoders/binary/yEnc.d decoders/binary/deflate.d decoders/binary/zlib.d
View
@@ -0,0 +1,49 @@
+/*
+ * error.d
+ *
+ * This module implements the Error objects useable by the system.
+ * This objects are for irrecoverable failures.
+ *
+ * Originated: May 8th, 2010
+ *
+ */
+
+module core.error;
+
+import core.definitions;
+
+// Description: This is for non irrecoverable failure.
+class Error : Exception {
+ this(string msg, string file = "", ulong line = 0) {
+ super(msg, file, line);
+ }
+
+private:
+// Error _next;
+}
+
+abstract class RuntimeError : Error {
+ this(string msg, string file, ulong line){
+ super(msg,file,line);
+ }
+
+static:
+
+ // Description: This Error is thrown when assertions fail.
+ class Assert : RuntimeError {
+ this(string msg, string file, ulong line) {
+ super("Assertion `" ~ msg ~ "` failed", file, line);
+ }
+
+ this(string file, ulong line) {
+ super("Assertion failed",file,line);
+ }
+ }
+
+ // Description: This Error is thrown when a switch statement does not have a default and there is no case available.
+ class NoDefaultCase : RuntimeError {
+ this(string file, ulong line) {
+ super("Switch has no default",file,line);
+ }
+ }
+}
View
@@ -12,32 +12,104 @@ module core.exception;
import core.string;
import core.definitions;
+/*
+class Exception {
+ this(string msg, string file = "", ulong line = 0) {
+ _msg = msg.dup;
+ _file = file.dup;
+ _line = line;
+ }
-template CustomException(char[] name, char[] error, char[] error_more) {
- const char[] CustomException = `
- class `~name~` : Exception {
- this() {
- super("`~error~`");
- }
+ string name() {
+ return this.classinfo.name.dup;
+ }
- this(string msg) {
- super("`~error~error_more~`" ~ msg);
- }
- }
- `;
+ string message() {
+ return _msg.dup;
+ }
+
+ string file() {
+ return _file;
+ }
+
+ ulong line() {
+ return _line;
+ }
+
+ string toString() {
+ return this.name() ~ " caught at " ~ _file ~ "@" ~ toStr(_line) ~ ": " ~ _msg;
+ }
+
+private:
+ char[] _msg;
+ char[] _file;
+ ulong _line;
}
+*/
+
+// Exceptions for IO
+abstract class IOException : Exception {
+ this(string msg) {
+ super(msg);
+ }
-// Exceptions for file IO
+static:
-mixin(CustomException!("FileNotFound", "File Not Found", ": "));
+ class CreationFailure : IOException {
+ this(string filename) {
+ super(filename ~ " could not be created.");
+ }
+ }
+
+ class ExistenceFailure : IOException {
+ this(string filename) {
+ super(filename ~ " not found.");
+ }
+ }
-mixin(CustomException!("DirectoryNotFound", "Directory Not Found", ": "));
+ class PermissionFailure : IOException {
+ this(string filename) {
+ super(filename ~ " has the wrong permissions for the operation.");
+ }
+ }
+}
// Exceptions for data structures
+abstract class DataException : Exception {
+ this(string msg) {
+ super(msg);
+ }
+
+static:
+
+ class OutOfElements : DataException {
+ this(string objectName) {
+ super("Out of items in " ~ objectName);
+ }
+ }
-mixin(CustomException!("OutOfElements", "Out of Elements", " in "));
+ class OutOfBounds : DataException {
+ this(string objectName) {
+ super("Index out of bounds in " ~ objectName);
+ }
+ }
-mixin(CustomException!("OutOfBounds", "Out of Bounds", " in "));
+ class ElementNotFound : DataException {
+ this(string objectName) {
+ super("Element does not exist in " ~ objectName);
+ }
+ }
+}
-mixin(CustomException!("ElementNotFound", "Element Not Found", " in "));
+abstract class MemoryException : Exception {
+ this(string msg) {
+ super(msg);
+ }
+static:
+ class OutOfMemory : MemoryException {
+ this() {
+ super("Out of memory");
+ }
+ }
+}
View
@@ -85,7 +85,7 @@ class List(T) : Iterable!(T) {
}
if (idx >= _count) {
- throw new OutOfBounds(this.classinfo.name);
+ throw new DataException.OutOfBounds(this.classinfo.name);
}
if (_count == 0) {
@@ -134,11 +134,11 @@ class List(T) : Iterable!(T) {
T removeAt(size_t index) {
synchronized(this) {
if (index >= _count) {
- throw new OutOfBounds(this.classinfo.name);
+ throw new DataException.OutOfBounds(this.classinfo.name);
}
if (this.empty()) {
- throw new OutOfElements(this.classinfo.name);
+ throw new DataException.OutOfElements(this.classinfo.name);
}
_count--;
@@ -150,7 +150,7 @@ class List(T) : Iterable!(T) {
T peek() {
synchronized(this) {
if (this.empty()) {
- throw new OutOfElements(this.classinfo.name);
+ throw new DataException.OutOfElements(this.classinfo.name);
}
return _data[_count-1];
@@ -160,11 +160,11 @@ class List(T) : Iterable!(T) {
T peekAt(size_t index) {
synchronized(this) {
if (index >= _count) {
- throw new OutOfBounds(this.classinfo.name);
+ throw new DataException.OutOfBounds(this.classinfo.name);
}
if (this.empty()) {
- throw new OutOfElements(this.classinfo.name);
+ throw new DataException.OutOfElements(this.classinfo.name);
}
return _data[index];
@@ -175,7 +175,7 @@ class List(T) : Iterable!(T) {
void set(R value) {
synchronized(this) {
if (this.empty()) {
- throw new OutOfElements(this.classinfo.name);
+ throw new DataException.OutOfElements(this.classinfo.name);
}
if (_count > 0) {
@@ -189,11 +189,11 @@ class List(T) : Iterable!(T) {
void setAt(size_t index, R value) {
synchronized(this) {
if (index >= _count) {
- throw new OutOfBounds(this.classinfo.name);
+ throw new DataException.OutOfBounds(this.classinfo.name);
}
if (this.empty()) {
- throw new OutOfElements(this.classinfo.name);
+ throw new DataException.OutOfElements(this.classinfo.name);
}
_data[index] = cast(T)value;
View
@@ -87,7 +87,7 @@ class Queue(T) : Iterable!(T) {
T peek() {
if (_count == 0) {
- throw new OutOfElements(this.classinfo.name);
+ throw new DataException.OutOfElements(this.classinfo.name);
}
return _head.data;
@@ -96,7 +96,7 @@ class Queue(T) : Iterable!(T) {
T peekAt(size_t index) {
synchronized(this) {
if (index >= _count) {
- throw new OutOfBounds(this.classinfo.name);
+ throw new DataException.OutOfBounds(this.classinfo.name);
}
if (index == 0) {
@@ -154,7 +154,7 @@ class Queue(T) : Iterable!(T) {
T remove() {
synchronized(this) {
if (_tail == null) {
- throw new OutOfElements(this.classinfo.name);
+ throw new DataException.OutOfElements(this.classinfo.name);
}
T data = _tail.data;
@@ -182,7 +182,7 @@ class Queue(T) : Iterable!(T) {
T remove(T item) {
synchronized(this) {
if (_head is null) {
- throw new OutOfElements(this.classinfo.name);
+ throw new DataException.OutOfElements(this.classinfo.name);
}
LinkedListNode* curnode = null;
@@ -218,14 +218,14 @@ class Queue(T) : Iterable!(T) {
curnode = curnode.next;
} while (curnode !is _head);
- throw new ElementNotFound(this.classinfo.name);
+ throw new DataException.ElementNotFound(this.classinfo.name);
}
}
T removeAt(size_t index) {
synchronized(this) {
if (index >= _count) {
- throw new OutOfBounds(this.classinfo.name);
+ throw new DataException.OutOfBounds(this.classinfo.name);
}
LinkedListNode* curnode = null;
View
@@ -9,9 +9,7 @@
module io.file;
-import core.stream;
-import core.string;
-import core.definitions;
+import djehuty;
import platform.vars.file;
@@ -33,7 +31,7 @@ class File : Stream {
bool r = FileCreate(_pfvars, _name);
if (!r) {
- throw new Exception("File Cannot be Created");
+ throw new IOException.CreationFailure(filename);
}
_length = 0;
View
@@ -3,6 +3,8 @@ module runtime.classinfo;
import core.string;
import core.definitions;
+// Description: The information stored for a class. Retrieved via the .classinfo property.
+// It is stored as the first entry in the class' vtbl[].
class ClassInfo {
byte[] init;
View
@@ -161,38 +161,3 @@ int _d_obj_cmp(Object o1, Object o2) {
return o1.opCmp(o2);
}
-void _d_assert( char[] file, uint line ) {
- onAssertError( file, line );
-}
-
-void _d_assert_msg( char[] msg, char[] file, uint line ) {
- onAssertErrorMsg( file, line, msg );
-}
-
-void _d_array_bounds( char[] file, uint line ) {
- onArrayBoundsError( file, line );
-}
-
-void _d_switch_error( char[] file, uint line ) {
- onSwitchError( file, line );
-}
-
-private void onAssertError(char[] file, size_t line) {
- //kprintfln!("Error in {}, line {}: assertion failed.")(file, line);
- asm { l: hlt; jmp l; }
-}
-
-private void onAssertErrorMsg(char[] file, size_t line, char[] msg) {
- //kprintfln!("Error in {}, line {}: assertion failed: \"{}\"")(file, line, msg);
- asm { l: hlt; jmp l; }
-}
-
-private void onArrayBoundsError(char[] file, size_t line) {
- //kprintfln!("Error in {}, line {}: array index out of bounds.")(file, line);
- asm { l: hlt; jmp l; }
-}
-
-private void onSwitchError(char[] file, size_t line) {
- //kprintfln!("Error in {}, line {}: switch has no case or default to handle the switched-upon value.")(file, line);
- asm { l: hlt; jmp l; }
-}
Oops, something went wrong.

0 comments on commit 08e9e7e

Please sign in to comment.