[Quipu-dev] quipu/quipu: 2 new changesets

Back to archive index
scmno****@osdn***** scmno****@osdn*****
Fri Dec 27 05:25:01 JST 2019


changeset 05f2a51e31c5 in quipu/quipu
details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=05f2a51e31c5
user: Agustina Arzille <avarz****@riseu*****>
date: Thu Dec 26 16:52:49 2019 -0300
description: Fix test in thread module
changeset 112f5a980ec1 in quipu/quipu
details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=112f5a980ec1
user: Agustina Arzille <avarz****@riseu*****>
date: Thu Dec 26 17:24:49 2019 -0300
description: Add the 'as' interface

diffstat:

 array.h    |   1 +
 bvector.h  |   2 +
 cons.h     |   2 +
 coro.h     |   1 +
 function.h |   2 +
 quipu.h    |  81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 str.h      |   2 +
 stream.h   |   2 +
 symbol.h   |   4 ++-
 table.h    |   2 +
 thread.cpp |  33 +++++++++++-------------
 thread.h   |   9 ++++++
 tuple.h    |   2 +
 types.h    |   8 +++--
 14 files changed, 129 insertions(+), 22 deletions(-)

diffs (truncated from 356 to 300 lines):

diff -r d935e6bde298 -r 112f5a980ec1 array.h
--- a/array.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/array.h	Thu Dec 26 17:24:49 2019 -0300
@@ -10,6 +10,7 @@
 {
   static const uint32_t nonref_flag = 1u << 15;
   static const uint32_t signature_flag = 1u << 16;
+  static const int code = typecode::ARRAY;
 
   uint32_t len;
   object *data;
diff -r d935e6bde298 -r 112f5a980ec1 bvector.h
--- a/bvector.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/bvector.h	Thu Dec 26 17:24:49 2019 -0300
@@ -8,6 +8,8 @@
 
 struct bvector : public varobj
 {
+  static const int code = typecode::BVECTOR;
+
   unsigned char *data;
   uint32_t nbytes;
 
diff -r d935e6bde298 -r 112f5a980ec1 cons.h
--- a/cons.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/cons.h	Thu Dec 26 17:24:49 2019 -0300
@@ -11,6 +11,8 @@
  * that they work a bit differently than other objects. */
 struct alignas (8) cons
 {
+  static const int code = typecode::CONS;
+
   object car;
   object cdr;
 
diff -r d935e6bde298 -r 112f5a980ec1 coro.h
--- a/coro.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/coro.h	Thu Dec 26 17:24:49 2019 -0300
@@ -7,6 +7,7 @@
 
 struct coroutine : public varobj
 {
+  static const int code = typecode::CORO;
   static coroutine* alloc_raw ();
   static object make (interpreter *__interp, uint32_t __bp);
 
diff -r d935e6bde298 -r 112f5a980ec1 function.h
--- a/function.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/function.h	Thu Dec 26 17:24:49 2019 -0300
@@ -16,6 +16,8 @@
   static const int genericfn_flag = 1 << 19;
   static const int method_flag = 1 << 20;
 
+  static const int code = typecode::FCT;
+
   int min_argc;
   int max_argc;
   object name;
diff -r d935e6bde298 -r 112f5a980ec1 quipu.h
--- a/quipu.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/quipu.h	Thu Dec 26 17:24:49 2019 -0300
@@ -25,6 +25,87 @@
 
 extern bool quipu_init (void);
 
+template <class T>
+struct objtype
+{
+  typedef T* type;
+  static const int code = T::code;
+
+  static inline type get (object __obj)
+    {
+      return ((type)unmask (__obj));
+    }
+};
+
+template <>
+struct objtype<int>
+{
+  typedef int type;
+  static const int code = typecode::INT;
+
+  static inline type get (object __obj)
+    {
+      return (as_int (__obj));
+    }
+};
+
+template <>
+struct objtype<char>
+{
+  typedef uint32_t type;
+  static const int code = typecode::CHAR;
+
+  static inline type get (object __obj)
+    {
+      return (as_char (__obj));
+    }
+};
+
+template <>
+struct objtype<float>
+{
+  typedef double type;
+  static const int code = typecode::FLOAT;
+
+  static inline type get (object __obj)
+    {
+      return (as_float (__obj));
+    }
+};
+
+template <class T>
+typename objtype<T>::type as (object __obj, bool& __got)
+{
+  typedef typename objtype<T>::type __rtype;
+  int __tx = objtype<T>::code;
+  int __itp = itype (__obj);
+
+  __got = true;
+  if (__tx == __itp || (__tx == typecode::BVECTOR && __itp == typecode::STR))
+    return (objtype<T>::get (__obj));
+  else if (__itp == typecode::INSTANCE)
+    {
+      object __tmp = builtin_member (__obj);
+      __itp = itype (__tmp);
+
+      if (__tx == __itp ||
+          (__tx == typecode::BVECTOR && __itp == typecode::STR))
+        return (objtype<T>::get (__tmp));
+    }
+
+  __got = false;
+  return (__rtype (0));
+
+#undef RETURN
+}
+
+template <class T>
+typename objtype<T>::type as (object __obj)
+{
+  bool __dummy;
+  return (as<T> (__obj, __dummy));
+}
+
 QP_DECLS_END
 
 #endif
diff -r d935e6bde298 -r 112f5a980ec1 str.h
--- a/str.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/str.h	Thu Dec 26 17:24:49 2019 -0300
@@ -10,6 +10,8 @@
  * structure (lazily initialized, of course). */
 struct string : public bvector
 {
+  static const int code = typecode::STR;
+
   uint32_t len;
   uint32_t hval;
 
diff -r d935e6bde298 -r 112f5a980ec1 stream.h
--- a/stream.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/stream.h	Thu Dec 26 17:24:49 2019 -0300
@@ -48,6 +48,8 @@
 
 struct stream : public finobj
 {
+  static const int code = typecode::STREAM;
+
   struct buffer
     {
       char *start;
diff -r d935e6bde298 -r 112f5a980ec1 symbol.h
--- a/symbol.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/symbol.h	Thu Dec 26 17:24:49 2019 -0300
@@ -35,6 +35,8 @@
   static const int ctv_flag = 1 << 19;
   static const int alias_flag = 1 << 18;
 
+  static const int code = typecode::SYMBOL;
+
   object name;
   object value;
   object pkg;
@@ -62,7 +64,7 @@
 
 struct package : public finobj
 {
-  static const int specific_flag = 1 << 18;
+  static const int code = typecode::PKG;
 
   object syms;
   object name;
diff -r d935e6bde298 -r 112f5a980ec1 table.h
--- a/table.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/table.h	Thu Dec 26 17:24:49 2019 -0300
@@ -8,6 +8,8 @@
 
 struct table : public varobj
 {
+  static const int code = typecode::TABLE;
+
   object vector;
   object cmpfct;
   object hashfct;
diff -r d935e6bde298 -r 112f5a980ec1 thread.cpp
--- a/thread.cpp	Mon Dec 23 15:28:07 2019 -0300
+++ b/thread.cpp	Thu Dec 26 17:24:49 2019 -0300
@@ -1,9 +1,5 @@
 #include <new>
-#include "thread.h"
-#include "memory.h"
-#include "integer.h"
-#include "floatp.h"
-#include "xtime.h"
+#include "quipu.h"
 
 #ifdef QP_PLATFORM_WINDOWS
 #  define WIN32_LEAN_AND_MEAN
@@ -171,10 +167,10 @@
 
 bool lock::init (bool recursive_p)
 {
-  if (recursive_p)
+  if (!init_mtx_cv (this->mtx, this->cv))
+    return (false);
+  else if (recursive_p)
     this->vo_full |= lock::recursive_flag;
-  else if (!init_mtx_cv (this->mtx, this->cv))
-    return (false);
 
   this->lock_cnt = 0u;
   this->owner = UNBOUND;
@@ -273,14 +269,16 @@
 validate_time (interpreter *interp, object timeout, bool absolute)
 {
   double tm;
+  bool got;
 
-  if (fixint_p (timeout))
-    tm = as_int (timeout);
-  else if (float_p (timeout))
+  tm = as<int> (timeout, got);
+  if (!got)
     {
-      tm = as_float (timeout);
-      if (finf_p (tm) || fnan_p (tm))
-        interp->raise ("arg-error", "timeout must not be NaN or infinite");
+      tm = as<float> (timeout, got);
+      if (!got)
+        interp->raise ("type-error", "timeout must be an integer or float");
+      else if (finf_p (tm) || fnan_p (tm))
+        interp->raise ("arg-error", "timeout must not ne NaN or infinite");
     }
 
   return (absolute ? tm : tm + real_time ());
@@ -370,11 +368,10 @@
 static lock*
 validate_lock (interpreter *interp, object lk)
 {
-  if (!lock_p (lk))
+  lock *lp = as<lock> (lk);
+  if (!lp)
     interp->raise ("type-error", "first argument must be a lock");
-
-  lock *lp = as_lock (lk);
-  if (lp->owner != interp->thread)
+  else if (lp->owner != interp->thread)
     interp->raise ("arg-error", "lock must be owned by the calling thread");
 
   return (lp);
diff -r d935e6bde298 -r 112f5a980ec1 thread.h
--- a/thread.h	Mon Dec 23 15:28:07 2019 -0300
+++ b/thread.h	Thu Dec 26 17:24:49 2019 -0300
@@ -70,6 +70,8 @@
 {
   static const uint32_t recursive_flag = 1u << 16;
 
+  static const int code = typecode::LOCK;
+
   bool init (bool)
     {
       return (true);
@@ -140,6 +142,9 @@
 struct lock : public finobj
 {
   static const uint32_t recursive_flag = 1 << 16;
+
+  static const int code = typecode::LOCK;
+
   raw_lock mtx;
   raw_condvar cv;
   lazy<valref> ref;
@@ -158,6 +163,8 @@
 {
   raw_condvar cv;
 
+  static const int code = typecode::CONDVAR;
+



More information about the Quipu-dev mailing list
Back to archive index