Commits

Anonymous committed a151b6d

#90: mainlining directly

  • Participants
  • Parent commits 8a9186a

Comments (0)

Files changed (9)

File src/lib/ipm.py

 #
 # Runs the target device-side interactive session.
 #
-import plat
+import sys
 def ipm():
     while 1:
         # Wait for a code image, make a code object from it
         rv = eval(Co(_getImg()))
 
         # Send a byte to indicate completion of evaluation
-        plat.puts('\x04')
+        sys.putb(0x04)
 
 # Start the interactive session when this module is imported
 ipm()

File src/lib/sys.py

     pass
 
 
+#
+# Returns the number of milliseconds since the PyMite VM was initialized
+#
+def time():
+    """__NATIVE__
+    uint32_t t;
+    pPmObj_t pt;
+    PmReturn_t retval;
+
+    /* If wrong number of args, raise TypeError */
+    if (NATIVE_GET_NUM_ARGS() != 0)
+    {
+        PM_RAISE(retval, PM_RET_EX_TYPE);
+        return retval;
+    }
+
+    /* Get the system time (milliseconds since init) */
+    retval = plat_getMsTicks(&t);
+    PM_RETURN_IF_ERROR(retval);
+
+    /*
+     * Raise ValueError if there is an overflow
+     * (plat_getMsTicks is unsigned; int is signed)
+     */
+    if ((int32_t)t < 0)
+    {
+        PM_RAISE(retval, PM_RET_EX_VAL);
+        return retval;
+    }
+
+    /* Return an int object with the time value */
+    retval = int_new((int32_t)t, &pt);
+    NATIVE_SET_TOS(pt);
+    return retval;
+    """
+    pass
+
+
 # :mode=c:

File src/lib/time.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.
-#
-
-#
-# Provides PyMite's time module, time
-#
-# USAGE
-# -----
-#
-# import time
-# t1 = time.clock()
-# doStuff()
-# t2 = time.clock()
-# print t2 - t1
-#
-# LOG
-# ---
-#
-# 2006/08/21    #28: Adapt native libs to use the changed func calls
-# 2002/05/25    Created.
-#
-
-
-#### CONSTS
-
-
-#### FUNCS
-
-#
-# Returns the current time in (?milli?)seconds
-#
-def clock():
-    """__NATIVE__
-    PmReturn_t retval;
-    pPmObj_t ptime;
-
-    /* Create int obj with current time */
-#ifdef TARGET_DESKTOP
-    retval = int_new((int)time(C_NULL), &ptime);
-#else
-# error time.clock is unimplemented for non-DESKTOP builds
-    retval = int_new(0, &ptime);
-#endif
-
-    /* return time via stack */
-    NATIVE_SET_TOS(ptime);
-    return retval;
-    """
-    pass
-
-# :mode=c:

File src/tests/system/t071.py

 
 # The variable "n" does not exist
 # "n" will be initialized by the code contained in the image below
-# The image below is an image of the following code snippet:
-#ipm> import plat; plat.puts("A"); n=42; plat.puts("B")
-img = '\na\x00\x00\x03\x00\x04\x04\x03\x04plat\x03\x04puts\x03\x01n\x03\x05<ipm>\x04\x05\x01\xff\xff\xff\xff\x00\x03\x01A\x01*\x00\x00\x00\x03\x01Bd\x00\x00d\x01\x00k\x00\x00Z\x00\x00e\x00\x00i\x01\x00d\x02\x00\x83\x01\x00\x01d\x03\x00Z\x02\x00e\x00\x00i\x01\x00d\x04\x00\x83\x01\x00\x01d\x01\x00S'
+# The image below is an image of the following code snippet::
+#
+#   ipm> import sys; sys.putb(0x34); n=42; sys.putb(0x32)
+#
+img = '\nd\x00\x00\x03\x00\x04\x04\x03\x03sys\x03\x04putb\x03\x01n\x03\x05<ipm>\x04\x05\x01\xff\xff\xff\xff\x00\x014\x00\x00\x00\x01*\x00\x00\x00\x012\x00\x00\x00d\x00\x00d\x01\x00k\x00\x00Z\x00\x00e\x00\x00i\x01\x00d\x02\x00\x83\x01\x00Fd\x03\x00Z\x02\x00e\x00\x00i\x01\x00d\x04\x00\x83\x01\x00Fd\x01\x00S'
 
 # Convert the image to a code object and evaluate it
 co = Co(img)

File src/tools/ipm.py

     def __init__(self, target=PMVM_EXE):
         self.open(target)
 
-        
+
     def open(self, target):
         self.child = subprocess.Popen(target,
                                       bufsize=-1,
         codeobj = compile(line, COMPILE_FN, COMPILE_MODE)
 
         # DEBUG: Uncomment the next line to print the statement's bytecodes
-        #dis.disco(codeobj) 
+        #dis.disco(codeobj)
 
         # Convert to a code image
         pic = pmImgCreator.PmImgCreator()
 
         # Otherwise send the image and print the reply
         else:
+
+            # DEBUG: Uncomment the next line to print the code image
+            # print "codeimg = ", repr(codeimg)
+
             try:
                 self.conn.write(codeimg)
             except Exception, e:

File src/vm/Makefile

 # Configure the contents of pmstdlib by editing this list
 PMSTDLIB_SOURCES = ../lib/__bi.py \
                    ../lib/sys.py \
-                   ../lib/plat.py \
                    ../lib/ipm.py
 
 TARGET ?= DESKTOP

File src/vm/plat/avr.c

     return PM_RET_OK;
 }
 
-/* remember that 32bit-accesses are non-atomic on AVR */
-uint32_t
-plat_getMsTicks(void)
+
+/*
+ * This operation is made atomic by temporarily disabling
+ * the interrupts. The old state is restored afterwards.
+ */
+PmReturn_t
+plat_getMsTicks(uint32_t *r_ticks)
 {
-    uint32_t result;
     /* Critical section start */
     unsigned char _sreg = SREG;
     cli();
-    result = pm_timerMsTicks;
+    *r_ticks = pm_timerMsTicks;
     SREG = _sreg;
     /* Critical section end */
-    return result;
+    return PM_RET_OK;
 }

File src/vm/plat/desktop.c

     return retval;
 }
 
-/* remember that 32bit-accesses are non-atomic on AVR */
-uint32_t
-plat_getMsTicks(void)
+
+PmReturn_t
+plat_getMsTicks(uint32_t *r_ticks)
 {
-    return pm_timerMsTicks;
+    *r_ticks = pm_timerMsTicks;
+    
+    return PM_RET_OK;
 }

File src/vm/plat/plat.h

 PmReturn_t plat_putByte(uint8_t b);
 
 /**
- * Get the number of timer ticks that have passed since system start.
- * On embedded targets, this operatoin is made atomic by temporarily disabling
- * the interrupts. The old state is restored afterwards.
+ * Gets the number of timer ticks that have passed since system start.
  */
-uint32_t plat_getMsTicks(void);
+PmReturn_t plat_getMsTicks(uint32_t *r_ticks);
 
 #endif /* PLAT_H_ */