summaryrefslogtreecommitdiff
path: root/tiger-compiler/tcsh/src/tiger_misc.i
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tcsh/src/tiger_misc.i
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/tcsh/src/tiger_misc.i')
-rw-r--r--tiger-compiler/tcsh/src/tiger_misc.i73
1 files changed, 73 insertions, 0 deletions
diff --git a/tiger-compiler/tcsh/src/tiger_misc.i b/tiger-compiler/tcsh/src/tiger_misc.i
new file mode 100644
index 0000000..7e1470f
--- /dev/null
+++ b/tiger-compiler/tcsh/src/tiger_misc.i
@@ -0,0 +1,73 @@
+// -*- C++ -*-
+
+%module tiger_misc
+
+%include "std_string.i"
+
+%{
+ #include <sstream>
+
+ #include <misc/file-library.hh>
+ #include <misc/symbol.hh>
+ #include <misc/error.hh>
+ // The need for this using directive seems to be a SWIG bug. It is
+ // needed by the _wrap_error___lshift____SWIG_5 in the C++ wrapper
+ // generated by swig (tiger_bind-wrap.cc).
+ using misc::error;
+
+ #include <misc/timer.hh>
+%}
+
+%exception {
+ try {
+ $function
+ } catch (const misc::error& e)
+ {
+ std::ostringstream o;
+ o << e;
+ PyObject *err = Py_BuildValue("is", e.status_get_value(), o.str().c_str());
+ PyErr_SetObject(PyExc_RuntimeError, err);
+ SWIG_fail;
+ }
+}
+
+%include "misc/file-library.hh"
+
+// Save some warnings from SWIG.
+%ignore misc::error::operator=;
+%ignore misc::error::operator bool;
+
+// SWIG has trouble wrapping some of misc::error's operator<<'s; ignore them.
+%ignore misc::error::operator<<;
+
+%include "misc/error.hh"
+
+// Wrap misc::error::operator<<.
+%extend misc::error
+{
+ std::string __str__() const
+ {
+ std::ostringstream o;
+ o << *$self;
+ return o.str();
+ }
+
+ %pythoncode %{
+ @staticmethod
+ def error_type_message() -> dict[int, str]:
+ return { getattr(_tiger_misc, t): t[len("error_error_type_"):].upper() for t in dir(_tiger_misc) if t.startswith("error_error_type_") }
+ %}
+}
+
+%ignore misc::symbol::operator=;
+%ignore misc::symbol::operator<<;
+%include "misc/symbol.hh"
+%extend misc::symbol
+{
+ std::string __str__() const
+ {
+ return ($self)->get();
+ }
+}
+
+%include "misc/timer.hh"