Permalink
Browse files

pristine djehuty runtime

  • Loading branch information...
1 parent 59effdf commit 725bad6d779a5d4ce78fa7ee0e1ae7b6994b2f48 @wolfwood wolfwood committed Oct 7, 2011
Showing with 6,673 additions and 0 deletions.
  1. +265 −0 runtimes/djehuty/apply.d
  2. +360 −0 runtimes/djehuty/array.d
  3. +345 −0 runtimes/djehuty/assocarray.d
  4. +32 −0 runtimes/djehuty/classinvariant.d
  5. +39 −0 runtimes/djehuty/common.d
  6. +162 −0 runtimes/djehuty/dstatic.d
  7. +35 −0 runtimes/djehuty/entry.d
  8. +43 −0 runtimes/djehuty/error.d
  9. +424 −0 runtimes/djehuty/exception.d
  10. +210 −0 runtimes/djehuty/gc.d
  11. +628 −0 runtimes/djehuty/lifetime.d
  12. +222 −0 runtimes/djehuty/main.d
  13. +73 −0 runtimes/djehuty/moduleinfo.d
  14. +67 −0 runtimes/djehuty/monitor.d
  15. +148 −0 runtimes/djehuty/object.d
  16. +579 −0 runtimes/djehuty/precision.d
  17. +85 −0 runtimes/djehuty/switchstmt.d
  18. +89 −0 runtimes/djehuty/typeinfo.d
  19. +202 −0 runtimes/djehuty/typeinfos/ti_array.d
  20. +20 −0 runtimes/djehuty/typeinfos/ti_array_bool.d
  21. +12 −0 runtimes/djehuty/typeinfos/ti_array_byte.d
  22. +90 −0 runtimes/djehuty/typeinfos/ti_array_cdouble.d
  23. +92 −0 runtimes/djehuty/typeinfos/ti_array_cfloat.d
  24. +12 −0 runtimes/djehuty/typeinfos/ti_array_char.d
  25. +95 −0 runtimes/djehuty/typeinfos/ti_array_creal.d
  26. +12 −0 runtimes/djehuty/typeinfos/ti_array_dchar.d
  27. +91 −0 runtimes/djehuty/typeinfos/ti_array_double.d
  28. +91 −0 runtimes/djehuty/typeinfos/ti_array_float.d
  29. +20 −0 runtimes/djehuty/typeinfos/ti_array_idouble.d
  30. +20 −0 runtimes/djehuty/typeinfos/ti_array_ifloat.d
  31. +12 −0 runtimes/djehuty/typeinfos/ti_array_int.d
  32. +20 −0 runtimes/djehuty/typeinfos/ti_array_ireal.d
  33. +12 −0 runtimes/djehuty/typeinfos/ti_array_long.d
  34. +96 −0 runtimes/djehuty/typeinfos/ti_array_object.d
  35. +93 −0 runtimes/djehuty/typeinfos/ti_array_real.d
  36. +12 −0 runtimes/djehuty/typeinfos/ti_array_short.d
  37. +12 −0 runtimes/djehuty/typeinfos/ti_array_ubyte.d
  38. +12 −0 runtimes/djehuty/typeinfos/ti_array_uint.d
  39. +12 −0 runtimes/djehuty/typeinfos/ti_array_ulong.d
  40. +12 −0 runtimes/djehuty/typeinfos/ti_array_ushort.d
  41. +20 −0 runtimes/djehuty/typeinfos/ti_array_void.d
  42. +12 −0 runtimes/djehuty/typeinfos/ti_array_wchar.d
  43. +42 −0 runtimes/djehuty/typeinfos/ti_assocarray.d
  44. +40 −0 runtimes/djehuty/typeinfos/ti_byte.d
  45. +65 −0 runtimes/djehuty/typeinfos/ti_cdouble.d
  46. +70 −0 runtimes/djehuty/typeinfos/ti_cfloat.d
  47. +45 −0 runtimes/djehuty/typeinfos/ti_char.d
  48. +72 −0 runtimes/djehuty/typeinfos/ti_creal.d
  49. +47 −0 runtimes/djehuty/typeinfos/ti_dchar.d
  50. +40 −0 runtimes/djehuty/typeinfos/ti_delegate.d
  51. +74 −0 runtimes/djehuty/typeinfos/ti_double.d
  52. +14 −0 runtimes/djehuty/typeinfos/ti_enum.d
  53. +70 −0 runtimes/djehuty/typeinfos/ti_float.d
  54. +32 −0 runtimes/djehuty/typeinfos/ti_function.d
  55. +16 −0 runtimes/djehuty/typeinfos/ti_idouble.d
  56. +16 −0 runtimes/djehuty/typeinfos/ti_ifloat.d
  57. +44 −0 runtimes/djehuty/typeinfos/ti_int.d
  58. +71 −0 runtimes/djehuty/typeinfos/ti_interface.d
  59. +17 −0 runtimes/djehuty/typeinfos/ti_ireal.d
  60. +44 −0 runtimes/djehuty/typeinfos/ti_long.d
  61. +57 −0 runtimes/djehuty/typeinfos/ti_object.d
  62. +51 −0 runtimes/djehuty/typeinfos/ti_ptr.d
  63. +61 −0 runtimes/djehuty/typeinfos/ti_real.d
  64. +38 −0 runtimes/djehuty/typeinfos/ti_short.d
  65. +98 −0 runtimes/djehuty/typeinfos/ti_staticarray.d
  66. +106 −0 runtimes/djehuty/typeinfos/ti_struct.d
  67. +60 −0 runtimes/djehuty/typeinfos/ti_tuple.d
  68. +63 −0 runtimes/djehuty/typeinfos/ti_typedef.d
  69. +44 −0 runtimes/djehuty/typeinfos/ti_ubyte.d
  70. +45 −0 runtimes/djehuty/typeinfos/ti_uint.d
  71. +45 −0 runtimes/djehuty/typeinfos/ti_ulong.d
  72. +38 −0 runtimes/djehuty/typeinfos/ti_ushort.d
  73. +42 −0 runtimes/djehuty/typeinfos/ti_void.d
  74. +44 −0 runtimes/djehuty/typeinfos/ti_wchar.d
  75. +25 −0 runtimes/djehuty/types.d
  76. +17 −0 runtimes/djehuty/unwind.d
  77. +122 −0 runtimes/djehuty/util.d
  78. +10 −0 runtimes/djehuty/vararg.d
View
@@ -0,0 +1,265 @@
+/*
+ * apply.d
+ *
+ * This module implements the D runtime functions that involve UTF strings
+ * and foreach or foreach_reverse loops.
+ *
+ */
+
+module runtime.apply;
+
+import runtime.common;
+
+import core.unicode;
+
+import io.console;
+
+extern(D) typedef int delegate(void*) apply_dg_t;
+extern(D) typedef int delegate(size_t*, void*) apply_dg2_t;
+
+extern(C):
+
+private {
+ const char[] applyCode = `
+ // Capture the result
+ int result;
+
+ foreach(size_t idx, ref chr; array) {
+ // Call the loop body of the foreach, passing the pointer to the character
+ result = loopBody(&array[idx]);
+
+ // It will return nonzero when it breaks out of the loop early
+ if (result) {
+ return result;
+ }
+ }
+
+ // Return result
+ return result;
+ `;
+
+ const char[] indexedApplyCode = `
+ // Capture the result
+ int result;
+
+ foreach(size_t idx, ref chr; array) {
+ // Call the loop body of the foreach, passing the pointer to the character and index
+ result = loopBody(&idx, &array[idx]);
+
+ // It will return nonzero when it breaks out of the loop early
+ if (result) {
+ return result;
+ }
+ }
+
+ // Return result
+ return result;
+ `;
+
+ const char[] applyReverseCode = `
+ int result;
+
+ foreach_reverse(size_t idx, ref chr; array) {
+ // Call the loop body of the foreach, passing the pointer to the character and index
+ result = loopBody(&array[idx]);
+
+ // It will return nonzero when it breaks out of the loop early
+ if (result) {
+ return result;
+ }
+ }
+
+ return result;
+ `;
+
+ const char[] indexedApplyReverseCode = `
+ int result;
+
+ foreach_reverse(size_t idx, ref chr; array) {
+ // Call the loop body of the foreach, passing the pointer to the character and index
+ result = loopBody(&idx, &array[idx]);
+
+ // It will return nonzero when it breaks out of the loop early
+ if (result) {
+ return result;
+ }
+ }
+
+ return result;
+ `;
+
+ template _apply(T, char[] code) {
+ static if (is(T : dchar) && T.sizeof == dchar.sizeof) {
+ const char[] _apply = `
+ dchar[] array = Unicode.toUtf32(input);` ~ code;
+ }
+ else static if (is(T : wchar) && T.sizeof == wchar.sizeof) {
+ const char[] _apply = `
+ wchar[] array = Unicode.toUtf16(input);` ~ code;
+ }
+ else static if (is(T : char) && T.sizeof == char.sizeof) {
+ const char[] _apply = `
+ char[] array = Unicode.toUtf8(input);` ~ code;
+ }
+ else {
+ static assert(false, "Runtime mixin for string apply functions has been misused.");
+ }
+ }
+}
+
+// Description: This runtime function will decode a UTF8 string into wchar
+// elements. Used with a foreach loop of the form: foreach(wchar ; char[]).
+int _aApplycw1(char[] input, apply_dg_t loopBody) {
+ mixin(_apply!(wchar, applyCode));
+}
+
+// Description: This runtime function will decode a UTF8 string into dchar
+// elements. Used with a foreach loop of the form: foreach(dchar ; char[]).
+int _aApplycd1(char[] input, apply_dg_t loopBody) {
+ mixin(_apply!(dchar, applyCode));
+}
+
+// Description: This runtime function will decode a UTF16 string into char
+// elements. Used with a foreach loop of the form: foreach(char;: wchar[]).
+int _aApplywc1(wchar[] input, apply_dg_t loopBody) {
+ mixin(_apply!(char, applyCode));
+}
+
+// Description: This runtime function will decode a UTF16 string into dchar
+// elements. Used with a foreach loop of the form: foreach(dchar ; wchar[]).
+int _aApplywd1(wchar[] input, apply_dg_t loopBody) {
+ mixin(_apply!(dchar, applyCode));
+}
+
+// Description: This runtime function will decode a UTF32 string into char
+// elements. Used with a foreach loop of the form: foreach(char ; dchar[]).
+int _aApplydc1(dchar[] input, apply_dg_t loopBody) {
+ mixin(_apply!(char, applyCode));
+}
+
+// Description: This runtime function will decode a UTF32 string into wchar
+// elements. Used with a foreach loop of the form: foreach(wchar ; dchar[]).
+int _aApplydw1(dchar[] input, apply_dg_t loopBody) {
+ mixin(_apply!(wchar, applyCode));
+}
+
+// Description: This runtime function will decode a UTF8 string into wchar
+// elements. Used with a foreach loop of the form: foreach(i, wchar ; char[]).
+int _aApplycw2(char[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(wchar, indexedApplyCode));
+}
+
+// Description: This runtime function will decode a UTF8 string into dchar
+// elements. Used with a foreach loop of the form: foreach(i, dchar ; char[]).
+int _aApplycd2(char[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(dchar, indexedApplyCode));
+}
+
+// Description: This runtime function will decode a UTF16 string into char
+// elements. Used with a foreach loop of the form: foreach(i, char ; wchar[]).
+int _aApplywc2(wchar[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(char, indexedApplyCode));
+}
+
+// Description: This runtime function will decode a UTF16 string into dchar
+// elements. Used with a foreach loop of the form: foreach(i, dchar ; wchar[]).
+int _aApplywd2(wchar[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(dchar, indexedApplyCode));
+}
+
+// Description: This runtime function will decode a UTF32 string into char
+// elements. Used with a foreach loop of the form: foreach(i, char ; dchar[]).
+int _aApplydc2(dchar[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(char, indexedApplyCode));
+}
+
+// Description: This runtime function will decode a UTF32 string into wchar
+// elements. Used with a foreach loop of the form: foreach(i, wchar ; dchar[]).
+int _aApplydw2(dchar[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(wchar, indexedApplyCode));
+}
+
+// Description: This runtime function will decode a UTF8 string into wchar
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(wchar ; char[]).
+int _aApplyRcw1(char[] input, apply_dg_t loopBody) {
+ mixin(_apply!(wchar, applyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF8 string into dchar
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(dchar ; char[]).
+int _aApplyRcd1(char[] input, apply_dg_t loopBody) {
+ mixin(_apply!(dchar, applyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF16 string into char
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(char;: wchar[]).
+int _aApplyRwc1(wchar[] input, apply_dg_t loopBody) {
+ mixin(_apply!(char, applyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF16 string into dchar
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(dchar ; wchar[]).
+int _aApplyRwd1(wchar[] input, apply_dg_t loopBody) {
+ mixin(_apply!(dchar, applyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF32 string into char
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(char ; dchar[]).
+int _aApplyRdc1(dchar[] input, apply_dg_t loopBody) {
+ mixin(_apply!(char, applyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF32 string into wchar
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(wchar ; dchar[]).
+int _aApplyRdw1(dchar[] input, apply_dg_t loopBody) {
+ mixin(_apply!(wchar, applyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF8 string into wchar
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(i, wchar ; char[]).
+int _aApplyRcw2(char[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(wchar, indexedApplyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF8 string into dchar
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(i, dchar ; char[]).
+int _aApplyRcd2(char[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(dchar, indexedApplyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF16 string into char
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(i, char ; wchar[]).
+int _aApplyRwc2(wchar[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(char, indexedApplyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF16 string into dchar
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(i, dchar ; wchar[]).
+int _aApplyRwd2(wchar[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(dchar, indexedApplyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF32 string into char
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(i, char ; dchar[]).
+int _aApplyRdc2(dchar[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(char, indexedApplyReverseCode));
+}
+
+// Description: This runtime function will decode a UTF32 string into wchar
+// elements. Used with a foreach_reverse loop of the form:
+// foreach_reverse(i, wchar ; dchar[]).
+int _aApplyRdw2(dchar[] input, apply_dg2_t loopBody) {
+ mixin(_apply!(wchar, indexedApplyReverseCode));
+}
+
Oops, something went wrong.

0 comments on commit 725bad6

Please sign in to comment.