1. tuck
  2. pymite

Commits

Dean Hall  committed 3c68e65

#103: Mainlining directly

  • Participants
  • Parent commits 08b1838
  • Branches default

Comments (0)

Files changed (6)

File src/tests/system/t103.c

View file
  • Ignore whitespace
+/*
+ * 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 103
+ *
+ * Regression test for issue #103:
+ * Implement obj_print() for other object types
+ *
+ * Log
+ * ---
+ *
+ * 2007/03/19   #103: First
+ */
+
+#include "pm.h"
+#include "stdio.h"
+
+
+extern unsigned char usrlib_img[];
+
+
+int main(void)
+{
+    PmReturn_t retval;
+
+    retval = pm_init(MEMSPACE_FLASH, usrlib_img);
+    PM_RETURN_IF_ERROR(retval);
+
+    retval = pm_run((uint8_t *)"t103");
+    return (int)retval;
+}

File src/tests/system/t103.py

View file
  • Ignore whitespace
+# 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 103
+#
+# Regression test for issue #103:
+# Implement obj_print() for other object types
+#
+
+import sys
+
+def f(a,b):
+    return a+b
+    
+#
+# If the following throws an exception, it's a regression
+#
+print f, sys

File src/tools/ipm.py

View file
  • Ignore whitespace
         while c != REPLY_TERMINATOR:
             c = self.child.stdout.read(1)
             if c == '':
-                print "DEBUG: child returncode = %s\n" % hex(self.child.poll())
+                # DEBUG: uncomment the next line to print the child's return val
+                #print "DEBUG: child returncode = %s\n" % hex(self.child.poll())
                 break
             chars.append(c)
         msg = "".join(chars)

File src/vm/int.c

View file
  • Ignore whitespace
      */
     bytesWritten = sprintf((void*)&tBuffer, "%li", (long int)((pPmInt_t)pint)->val);
     #endif /* !TARGET_AVR */
-    
+
 
     /* Sanity check */
     C_ASSERT(bytesWritten != 0);
     }
     return PM_RET_OK;
 }
+
+
+PmReturn_t
+int_printHexByte(uint8_t b)
+{
+    uint8_t nibble;
+    PmReturn_t retval;
+
+    nibble = (b >> 4) + '0';
+    if (nibble > '9') nibble += ('a' - '0' - 10);
+    retval = plat_putByte(nibble);
+    PM_RETURN_IF_ERROR(retval);
+
+    nibble = (b & 0x0F) + '0';
+    if (nibble > '9') nibble += ('a' - '0' - 10);
+    retval = plat_putByte(nibble);
+    return retval;
+}
+
+
+PmReturn_t
+_int_printHex(int32_t n)
+{
+    PmReturn_t retval;
+
+    /* Print the hex value, most significant byte first */
+    retval = int_printHexByte((n >> 24) & (uint8_t)0xFF);
+    PM_RETURN_IF_ERROR(retval);
+    retval = int_printHexByte((n >> 16) & (uint8_t)0xFF);
+    PM_RETURN_IF_ERROR(retval);
+    retval = int_printHexByte((n >> 8) & (uint8_t)0xFF);
+    PM_RETURN_IF_ERROR(retval);
+    retval = int_printHexByte(n & (uint8_t)0xFF);
+
+    return retval;
+}
+
+
+PmReturn_t
+int_printHex(pPmObj_t pint)
+{
+    C_ASSERT(OBJ_GET_TYPE(*pint) == OBJ_TYPE_INT);
+
+    /* Print the integer object */
+    return _int_printHex(((pPmInt_t)pint)->val);
+}
 #endif /* HAVE_PRINT */
 
+
 /***************************************************************
  * Test
  **************************************************************/

File src/vm/int.h

View file
  • Ignore whitespace
 /**
  * Sends out an integer object in decimal notation with MSB first.
  * The number is preceded with a "-" when necessary.
- * 
+ *
  * @param pObj Ptr to int object
  * @return Return status
  */
 PmReturn_t int_print(pPmObj_t pint);
+
+/**
+ * Prints the byte in ascii-coded hexadecimal out the platform output
+ *
+ * @param b Byte to print
+ */
+PmReturn_t int_printHexByte(uint8_t b);
+
+/**
+ * Prints the integer in ascii-coded hexadecimal out the platform output
+ *
+ * @param n Integer to print
+ */
+PmReturn_t _int_printHex(int32_t n);
+
+/**
+ * Prints the Int object in ascii-coded hexadecimal out the platform output
+ *
+ * @param pint Pointer to Int object
+ */
+PmReturn_t int_printHex(pPmObj_t pint);
 #endif /* HAVE_PRINT */
 
 #endif /* __INT_H__ */

File src/vm/obj.c

View file
  • Ignore whitespace
         case OBJ_TYPE_TUP:
             retval = tuple_print(pobj);
             break;
+
+        case OBJ_TYPE_COB:
+        case OBJ_TYPE_MOD:
+        case OBJ_TYPE_CLO:
+        case OBJ_TYPE_FXN:
+        case OBJ_TYPE_CLI:
+        case OBJ_TYPE_CIM:
+        case OBJ_TYPE_NIM:
+        case OBJ_TYPE_NOB:
+        case OBJ_TYPE_EXN:
+        case OBJ_TYPE_SQI:
+        case OBJ_TYPE_THR:
+            if (marshallString)
+            {
+                retval = plat_putByte('\''); PM_RETURN_IF_ERROR(retval);
+            }
+            plat_putByte('<'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('o'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('b'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('j'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte(' '); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('t'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('y'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('p'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('e'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte(' '); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('0'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('x'); PM_RETURN_IF_ERROR(retval);
+            int_printHexByte(OBJ_GET_TYPE(*pobj)); PM_RETURN_IF_ERROR(retval);
+            plat_putByte(' '); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('@'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte(' '); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('0'); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('x'); PM_RETURN_IF_ERROR(retval);
+            _int_printHex((int32_t)pobj); PM_RETURN_IF_ERROR(retval);
+            plat_putByte('>'); PM_RETURN_IF_ERROR(retval);
+            if (marshallString)
+            {
+                plat_putByte('\''); PM_RETURN_IF_ERROR(retval);
+            }
+            break;
+
         default:
             /* Otherwise raise a TypeError */
             PM_RAISE(retval, PM_RET_EX_TYPE);