Commits

Anonymous committed eb5dbc8

#113: Mainlining directly

  • Participants
  • Parent commits e2bbf90

Comments (0)

Files changed (3)

File src/lib/__bi.py

 
 
 def map(f, s):
-    """__NATIVE__
-    PmReturn_t retval;
-    pPmObj_t pf = C_NULL;
-    pPmObj_t ps = C_NULL;
-    pPmObj_t pr = C_NULL;
-    int8_t length = 0;
-    int8_t i = 0;
-
-    /* If wrong number of args, raise TypeError */
-    if (NATIVE_GET_NUM_ARGS() != 2)
-    {
-        PM_RAISE(retval, PM_RET_EX_TYPE);
-        return retval;
-    }
-
-    /* Get args */
-    pf = NATIVE_GET_LOCAL(0);
-    ps = NATIVE_GET_LOCAL(1);
-
-    /* If args are wrong type, raise TypeError */
-    if (OBJ_GET_TYPE(*pf) != OBJ_TYPE_FXN)
-    {
-        PM_RAISE(retval, PM_RET_EX_TYPE);
-        return retval;
-    }
-
-    /* Get the sequence length based on type */
-    switch (OBJ_GET_TYPE(*ps))
-    {
-        case OBJ_TYPE_TUP:
-            length = ((pPmTuple_t)ps)->length;
-            break;
-
-        case OBJ_TYPE_LST:
-            length = ((pPmList_t)ps)->length;
-            break;
-
-        case OBJ_TYPE_STR:
-            length = ((pPmString_t)ps)->length;
-            break;
-
-        default:
-            PM_RAISE(retval, PM_RET_EX_TYPE);
-            return retval;
-    }
-
-    /* TODO #113: Fix the implementation of __bi.map */
-    /* Do a dummy map, fill func with Nones */
-    retval = list_new(&pr);
-    PM_RETURN_IF_ERROR(retval);
-
-    for (i = 0; i < length; i++)
-    {
-        retval = list_append(pr, PM_NONE);
-        PM_RETURN_IF_ERROR(retval);
-    }
-
-    return retval;
-    """
-    pass
+    # Do this as a workaround since list.append() doesn't work
+    r = [None,] * len(s)
+    
+    # Call function f once with each argument in sequence s
+    i = 0
+    for a in s:
+        r[i] = f(a)
+        i += 1
+        
+    # Return list of results
+    return r
 
 
 def ord(s):

File src/tests/system/t113.c

+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * System Test 113
+ *
+ * Regression test for issue #113:
+ * Fix the implementation of builtin map()
+ *
+ * Log
+ * ---
+ *
+ * 2007/04/26   #113: First
+ */
+
+#include "pm.h"
+#include "stdio.h"
+
+
+extern unsigned char usrlib_img[];
+
+
+int main(void)
+{
+    PmReturn_t retval;
+
+    retval = pm_init(MEMSPACE_PROG, usrlib_img);
+    PM_RETURN_IF_ERROR(retval);
+
+    retval = pm_run((uint8_t *)"t113");
+    return (int)retval;
+}

File src/tests/system/t113.py

+# PyMite - A flyweight Python interpreter for 8-bit microcontrollers and more.
+# Copyright 2002 Dean Hall
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# System Test 113
+#
+# Regression test for issue #113:
+# Fix the implementation of builtin map()
+#
+
+# Test setting each value to None
+def noneify(a):
+    return None
+    
+r = map(noneify, "test")
+
+assert r == [None, None, None, None]
+
+
+# Test adding a tuple pair
+def addPair(a):
+    return a[0] + a[1]
+    
+r = map(addPair, ((3,4),(5,6),(7,8)))
+
+assert r == [7, 11, 15]