[Quipu-dev] quipu/quipu: Implement relational operators

Zurück zum Archiv-Index

scmno****@osdn***** scmno****@osdn*****
Mon Jun 4 04:21:15 JST 2018


changeset 86d6195e06d0 in quipu/quipu
details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=86d6195e06d0
user: Agustina Arzille <avarz****@riseu*****>
date: Sun Jun 03 19:20:52 2018 +0000
description: Implement relational operators

diffstat:

 builtins.cpp |  57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 symbol.cpp   |   8 ++++----
 2 files changed, 61 insertions(+), 4 deletions(-)

diffs (109 lines):

diff -r dd1ad9f5c411 -r 86d6195e06d0 builtins.cpp
--- a/builtins.cpp	Sat Jun 02 18:55:55 2018 +0000
+++ b/builtins.cpp	Sun Jun 03 19:20:52 2018 +0000
@@ -653,6 +653,58 @@
   qp_return (*argv);
 }
 
+// (< arg1 [...args])
+DEFBUILTIN (lt_fct)
+{
+  if (argc == 0)
+    interp->raise_nargs ("#<builtin function <>", 1, -1, 0);
+
+  for (int i = 0; i < argc - 1; ++i)
+    if (!(xcmp (interp, argv[i], argv[i + 1]) < 0))
+      qp_return (NIL);
+
+  qp_return (QP_S(t));
+}
+
+// (> arg1 [...args])
+DEFBUILTIN (gt_fct)
+{
+  if (argc == 0)
+    interp->raise_nargs ("#<builtin function >>", 1, -1, 0);
+
+  for (int i = 0; i < argc - 1; ++i)
+    if (!(xcmp (interp, argv[i], argv[i + 1]) > 0))
+      qp_return (NIL);
+
+  qp_return (QP_S(t));
+}
+
+// (<= arg1 [...args])
+DEFBUILTIN (lte_fct)
+{
+  if (argc == 0)
+    interp->raise_nargs ("#<builtin function <=>", 1, -1, 0);
+
+  for (int i = 0; i < argc - 1; ++i)
+    if (!(xcmp (interp, argv[i], argv[i + 1]) <= 0))
+      qp_return (NIL);
+
+  qp_return (QP_S(t));
+}
+
+// (>= arg1 [...args])
+DEFBUILTIN (gte_fct)
+{
+  if (argc == 0)
+    interp->raise_nargs ("#<builtin function >=>", 1, -1, 0);
+
+  for (int i = 0; i < argc - 1; ++i)
+    if (!(xcmp (interp, argv[i], argv[i + 1]) >= 0))
+      qp_return (NIL);
+
+  qp_return (QP_S(t));
+}
+
 // (nputcar lst val)
 DEFBUILTIN (nputcar_fct)
 {
@@ -1240,6 +1292,7 @@
   "list\0"
   "list*\0"
   "+\0-\0*\0/\0"
+  "<\0>\0<=\0>=\0"
   "nputcar\0"
   "nputcdr\0"
   "apply\0"
@@ -1303,6 +1356,10 @@
   sub_fct,
   mul_fct,
   div_fct,
+  lt_fct,
+  gt_fct,
+  lte_fct,
+  gte_fct,
   nputcar_fct,
   nputcdr_fct,
   apply_fct,
diff -r dd1ad9f5c411 -r 86d6195e06d0 symbol.cpp
--- a/symbol.cpp	Sat Jun 02 18:55:55 2018 +0000
+++ b/symbol.cpp	Sun Jun 03 19:20:52 2018 +0000
@@ -216,11 +216,11 @@
   return (interp->retval);
 }
 
-static int
+static bool
 pkg_remove (interpreter *interp, package *pkg, object name)
 {
   object *ptr;
-  int ret = 0;
+  bool ret = false;
 
   /* Deletions are much more infrequent than insertions, so we 
    * grab the lock inconditionally here. */
@@ -232,8 +232,8 @@
       array *symp = as_array (pkg->syms);
       int nsyms = as_int (symp->data[0]) - 1;
 
-      *ptr = PKG_DELETED, ret = 1;
-      symp->data[0] = intobj (nsyms);
+      as_symbol(*ptr)->idx = -1, *ptr = PKG_DELETED;
+      ret = true;
 
       // Resize the table if it gets too sparse.
       if (symp->len * 25 >= nsyms * 100 && symp->len > PKG_BASE_SIZE + 1)




More information about the Quipu-dev mailing list
Zurück zum Archiv-Index