Commits

Anonymous committed b04c75e

Mainlining #24. Ported from branch issue_0019_padelt_atmega103_too_specific. Fixes #19. Fixes #18. Fixes #23.

  • Participants
  • Parent commits 459a501

Comments (0)

Files changed (3)

-#
-# Available arguments:
-#     TARGET = [DESKTOP, ATMEGA103]
-#
-# Default values:
-#     TARGET = DESKTOP
-#
-
-# Tools configuration
-SHELL = /bin/sh
-CP := cp
-MKDIR := mkdir -p
-TAGS := ctags
-CSCOPE := cscope
-
-VPATH := . src/vm src/lib docs/src
-
-# Build configuration
-TARGET := DESKTOP
-SIZE := size
-DEFS = -DTARGET_$(TARGET) -DHEAP_SIZE=$(HEAP_SIZE)
-CFLAGS = -ansi -g -Os -Wall -gstabs -Wstrict-prototypes $(DEFS)
-HEAP_SIZE = 0x10000
-ARFLAGS := rcs
-
-# Product configuration
-PRODUCT_VM := libpmvm.a
-
-# Changes for an embedded target
-ifeq ($(TARGET), ATMEGA103)
-	AR = /usr/local/bin/avr-ar
-	CC = /usr/local/bin/avr-gcc
-	CFLAGS += -mmcu=atmega103
-	SIZE = /usr/local/bin/avr-size
-	HEAP_SIZE = 0x0D00
-endif
-
-# Export config to child makefiles
-export  AR ARFLAGS CC CFLAGS HEAP_SIZE PRODUCT_VM SIZE TARGET
-
-.PHONY: all vm pmstdlib docs TAGS dist check clean
-
-# TODO: Hopefully can uncomment when issue #2 is resolved
-#all : vm pmstdlib
-all : vm
-
-vm :
-	$(MAKE) -C src/vm
-
-# TODO: Hopefully can uncomment when issue #2 is resolved
-#pmstdlib :
-#	$(MAKE) -C src/lib
-
-html : docs/src/*.txt
-	$(MKDIR) docs/html
-	$(MAKE) -C docs/src
-
-TAGS :
-	$(TAGS) -R *
-	$(CSCOPE) -b -c -R
-	cd src/tools && pycscope.py -R *.py
-
-dist : check docs
-ifndef PYMITE_RELEASE
-	$(error Must define PYMITE_RELEASE=RR)
-else
-	# TODO: issue #5
-	# Make a script in tools/ that will:
-	# 	- make fresh checkout,
-	#   - build docs
-	#   - make pymite-RR.tar.gz
-	#	- create release tag in svn repos
-endif
-
-check : vm
-	$(MAKE) -C src/tests
-
-# Removes all files created during default make
-clean :
-	$(MAKE) -C src/vm clean
-# TODO: Hopefully can uncomment when issue #2 is resolved
-#	$(MAKE) -C src/lib clean
-
+#
+# Available arguments:
+#     TARGET = [DESKTOP, AVR]
+#
+# Default values:
+#     TARGET = DESKTOP
+#
+# For target AVR, check options in section "Changes for an embedded target".
+#
+
+# Tools configuration
+SHELL = /bin/sh
+CP := cp
+MKDIR := mkdir -p
+TAGS := ctags
+CSCOPE := cscope
+
+VPATH := . src/vm src/lib docs/src
+
+# Build configuration
+TARGET := DESKTOP
+SIZE := size
+DEFS = -DTARGET_$(TARGET) -DHEAP_SIZE=$(HEAP_SIZE)
+CFLAGS = -g -Os -Wall -gstabs -Wstrict-prototypes $(DEFS)
+HEAP_SIZE = 0x10000
+ARFLAGS := rcs
+
+# Product configuration
+PRODUCT_VM := libpmvm.a
+
+# Changes for an embedded target
+ifeq ($(TARGET), AVR)
+	# TARGET_MCU should equal avr-gcc option "-mmcu" possible values.
+	TARGET_MCU := atmega103
+	
+	CFLAGS += -mmcu=$(TARGET_MCU)
+	HEAP_SIZE = 0x0D00
+
+	AR = avr-ar
+	CC = avr-gcc
+	SIZE = avr-size
+	CFLAGS += -DTARGET_MCU=$(TARGET_MCU)
+else
+	CFLAGS += -ansi
+endif
+
+# Export config to child makefiles
+export  AR ARFLAGS CC CFLAGS HEAP_SIZE PRODUCT_VM SIZE TARGET
+
+.PHONY: all vm pmstdlib docs TAGS dist check clean
+
+# TODO: Hopefully can uncomment when issue #2 is resolved
+#all : vm pmstdlib
+all : vm
+
+vm :
+	$(MAKE) -C src/vm
+
+# TODO: Hopefully can uncomment when issue #2 is resolved
+#pmstdlib :
+#	$(MAKE) -C src/lib
+
+html : docs/src/*.txt
+	$(MKDIR) docs/html
+	$(MAKE) -C docs/src
+
+TAGS :
+	$(TAGS) -R *
+	$(CSCOPE) -b -c -R
+	cd src/tools && pycscope.py -R *.py
+
+dist : check docs
+ifndef PYMITE_RELEASE
+	$(error Must define PYMITE_RELEASE=RR)
+else
+	# TODO: issue #5
+	# Make a script in tools/ that will:
+	# 	- make fresh checkout,
+	#   - build docs
+	#   - make pymite-RR.tar.gz
+	#	- create release tag in svn repos
+endif
+
+check : vm
+	$(MAKE) -C src/tests
+
+# Removes all files created during default make
+clean :
+	$(MAKE) -C src/vm clean
+# TODO: Hopefully can uncomment when issue #2 is resolved
+#	$(MAKE) -C src/lib clean
+
-======
-PyMite
-======
-
-:Author:    Dean Hall
-:Copyright: Copyright 2002 Dean Hall.
-            See `License`_ for details.
-:Release:   02
-:Site:      http://sourceforge.net/projects/thmonkeeproject/
-:Id:        $Id: README 116 2006-08-24 13:42:09Z dwhall $
-
-Purpose
--------
-
-PyMite is a flyweight Python interpreter written from scratch
-to execute on 8-bit microcontrollers.  PyMite supports a subset
-of the Python 2.0 syntax and can execute a subset of the
-Python 2.0 bytecodes.  PyMite can be compiled, tested and
-executed on a desktop computer and also targeted for 8-bit
-embedded systems with resources as limited as 64 KiB of
-program memory (flash) and 4 KiB of RAM.
-
-License
--------
-
-Copyright 2002 Dean Hall.
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of version 2 of the GNU General
-Public License as published by the Free Software Foundation.
-
-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
-
-Build
------
-
-Perform the following steps to build PyMite and the included
-sample application for the desktop:
-
-    1. In the project root, run ``make`` to create ``libpmvm.a``
-    2. In the project root, run ``make check`` to make an executable for
-       ``src/tests/t003.*``
-
-To build for the ATmega103:
-
-    1. In the project root, run ``make clean; make check TARGET=ATMEGA103``
-       to make an executable for ``src/tests/t003.*``
-
-The development system should have installed the GNU Compiler
-Collection version 3.4 or later and Python 2.0 or later.
-The author also uses avr-gcc to target Atmel AVR
-microcontrollers.
-
-PyMite is developed on Mac OS X 10.4 and should also compile on
-GNU/Linux and Cygwin operating systems.  Since PyMite is so
-deeply embedded, it does not rely on many libraries.
-When compiling for the AVR, it will need avr-libc.
-
-PyMite builds as an archive.  The user should then build his
-own main() function following given examples and link in
-``libpymvm.a`` and the appropriate PyMite native libraries.
-
-Contact
--------
-
-Please use the `sourceforge project
-<http://sourceforge.net/projects/thmonkeeproject/>`_
-space for all communications concerning PyMite.
-This will ensure that any email is forwarded to an up-to-date
-address and all comments and issues are recorded.
-
-Release Notes
--------------
-
-This is PyMite release 02
-
-* Release 02, 2006/08/11
-
-    - N/A:  Create Release v 02 package.
-    - N/A:  VM funcs modified so that return objects are by
-      reference and funcs return a PyReturn_t for internal
-      error checking.  Library modules are broken until they
-      are modified similarly.
-    - N/A:  The pmImgCreator.py script was modified to work via
-      the command line. pmImgCreator GUI is deprecated.
-    - N/A:  Converted many files' EOLs to Unix.
-
-* Release 01, 2003/03/18
-
-    - N/A:  Initial release made for PyCon 2003.
-    - N/A:  Compiles for desktop and Atmel ATmega103.
-
-Thanks
-------
-
-My personal thanks go out to these people for their contribution to PyMite:
-
-    - Philipp Adelt: Enhancements to pmImgCreator.py and reports on general use.
-
-
-.. :mode=rest:
+======
+PyMite
+======
+
+:Author:    Dean Hall
+:Copyright: Copyright 2002 Dean Hall.
+            See `License`_ for details.
+:Release:   02
+:Site:      http://sourceforge.net/projects/thmonkeeproject/
+:Id:        $Id: README 116 2006-08-24 13:42:09Z dwhall $
+
+Purpose
+-------
+
+PyMite is a flyweight Python interpreter written from scratch
+to execute on 8-bit microcontrollers.  PyMite supports a subset
+of the Python 2.0 syntax and can execute a subset of the
+Python 2.0 bytecodes.  PyMite can be compiled, tested and
+executed on a desktop computer and also targeted for 8-bit
+embedded systems with resources as limited as 64 KiB of
+program memory (flash) and 4 KiB of RAM.
+
+License
+-------
+
+Copyright 2002 Dean Hall.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of version 2 of the GNU General
+Public License as published by the Free Software Foundation.
+
+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
+
+Build
+-----
+
+Perform the following steps to build PyMite and the included
+sample application for the desktop:
+
+    1. In the project root, run ``make`` to create ``libpmvm.a``
+    2. In the project root, run ``make check`` to make an executable for
+       ``src/tests/t003.*``
+
+To build for AVR targets like the ATmega103 (refer to the Makefile for others):
+
+    1. In the project root, run ``make clean; make check TARGET=AVR``
+       to make an executable for ``src/tests/t003.*``
+
+The development system should have installed the GNU Compiler
+Collection version 3.4 or later and Python 2.0 or later.
+The author also uses avr-gcc to target Atmel AVR
+microcontrollers.
+
+PyMite is developed on Mac OS X 10.4 and should also compile on
+GNU/Linux and Cygwin operating systems.  Since PyMite is so
+deeply embedded, it does not rely on many libraries.
+When compiling for the AVR, it will need avr-libc.
+
+PyMite builds as an archive.  The user should then build his
+own main() function following given examples and link in
+``libpymvm.a`` and the appropriate PyMite native libraries.
+
+Contact
+-------
+
+Please use the `sourceforge project
+<http://sourceforge.net/projects/thmonkeeproject/>`_
+space for all communications concerning PyMite.
+This will ensure that any email is forwarded to an up-to-date
+address and all comments and issues are recorded.
+
+Release Notes
+-------------
+
+This is PyMite release 02
+
+* Release 02, 2006/08/11
+
+    - N/A:  Create Release v 02 package.
+    - N/A:  VM funcs modified so that return objects are by
+      reference and funcs return a PyReturn_t for internal
+      error checking.  Library modules are broken until they
+      are modified similarly.
+    - N/A:  The pmImgCreator.py script was modified to work via
+      the command line. pmImgCreator GUI is deprecated.
+    - N/A:  Converted many files' EOLs to Unix.
+
+* Release 01, 2003/03/18
+
+    - N/A:  Initial release made for PyCon 2003.
+    - N/A:  Compiles for desktop and Atmel ATmega103.
+
+Thanks
+------
+
+My personal thanks go out to these people for their contribution to PyMite:
+
+    - Philipp Adelt: Enhancements to pmImgCreator.py and reports on general use.
+
+
+.. :mode=rest:

File src/vm/mem.c

-#undef __FILE_ID__
-#define __FILE_ID__ 0x0D
-/**
- * VM Memory
- *
- * VM memory operations.
- * Implementations and stubs for getByte and memCopy functions.
- * Functions to load object images from static memory.
- *
- * @author      Dean Hall
- * @copyright   Copyright 2002 Dean Hall.  All rights reserved.
- *
- * Log
- * ---
- *
- * 2006/08/31   #9: Fix BINARY_SUBSCR for case stringobj[intobj]
- * 2006/08/29   #12: Make mem_*() funcs use RAM when target is DESKTOP
- * 2006/08/29   #15 - All mem_*() funcs and pointers in the vm should use
- *              unsigned not signed or void
- * 2002/05/27   Added access to Flash and EEPROM.
- * 2002/04/21   First.
- */
-
-/***************************************************************
- * Includes
- **************************************************************/
-
-#include "py.h"
-
-#ifdef TARGET_ATMEGA103
-#include <avr/pgmspace.h>
-#include <avr/eeprom.h>
-#endif /* atmega103 */
-
-
-/***************************************************************
- * Constants
- **************************************************************/
-
-/***************************************************************
- * Macros
- **************************************************************/
-
-/***************************************************************
- * Types
- **************************************************************/
-
-/***************************************************************
- * Globals
- **************************************************************/
-
-/***************************************************************
- * Prototypes
- **************************************************************/
-
-/***************************************************************
- * Functions
- **************************************************************/
-
-U8
-mem_getByte(PyMemSpace_t memspace, P_U8 *paddr)
-{
-    U8 b = 0;
-
-    switch (memspace)
-    {
-        case MEMSPACE_RAM:
-            b = **paddr;
-            *paddr += 1;
-            return b;
-
-        case MEMSPACE_FLASH:
-#ifdef TARGET_ATMEGA103
-            b = pgm_read_byte(*paddr);
-#elif defined(TARGET_DESKTOP)
-            b = **paddr;
-#else
-#error Undefined TARGET
-#endif /* TARGET_ATMEGA103 */
-            *paddr += 1;
-            return b;
-
-        case MEMSPACE_EEPROM:
-#ifdef TARGET_ATMEGA103
-            b = eeprom_read_byte((U16)*paddr);
-            *paddr += 1;
-#endif /* TARGET_ATMEGA103 */
-            return b;
-
-        case MEMSPACE_SEEPROM:
-        case MEMSPACE_OTHER0:
-        case MEMSPACE_OTHER1:
-        case MEMSPACE_OTHER2:
-        case MEMSPACE_OTHER3:
-        default:
-            return 0;
-    }
-}
-
-
-INLINE
-U16
-mem_getWord(PyMemSpace_t memspace, P_U8 *paddr)
-{
-    /* PyMite is little endien; get lo byte first */
-    U8 blo = mem_getByte(memspace, paddr);
-    U8 bhi = mem_getByte(memspace, paddr);
-    return (U16)(blo | (bhi << 8));
-}
-
-
-INLINE
-U32
-mem_getInt(PyMemSpace_t memspace, P_U8 *paddr)
-{
-    /* PyMite is little endien; get low word first */
-    U16 wlo = mem_getWord(memspace, paddr);
-    U16 whi = mem_getWord(memspace, paddr);
-    return (U32)(wlo | (whi << 8));
-}
-
-
-void
-mem_copy(PyMemSpace_t memspace,
-         P_U8 *pdest,
-         P_U8 *psrc,
-         U16 count)
-{
-
-    /* copy memory from RAM */
-    if (memspace == MEMSPACE_RAM)
-    {
-        sli_memcpy(*pdest, *psrc, count);
-        *psrc += count;
-        *pdest += count;
-        return;
-    }
-
-    /* copy memory from non-RAM to RAM */
-    else
-    {
-        U8 b;
-
-        for ( ; count > 0; count--)
-        {
-            b = mem_getByte(memspace, psrc);
-            **pdest = b;
-            (*pdest)++;
-        }
-        return;
-    }
-}
-
-
-U16
-mem_getNumUtf8Bytes(PyMemSpace_t memspace, P_U8 *psrc)
-{
-    P_U8 pbase = *psrc;
-    while(mem_getByte(memspace, psrc) != 0);
-    return *psrc - pbase - 1;
-}
-
-
-/***************************************************************
- * Test
- **************************************************************/
-
-/***************************************************************
- * Main
- **************************************************************/
+#undef __FILE_ID__
+#define __FILE_ID__ 0x0D
+/**
+ * VM Memory
+ *
+ * VM memory operations.
+ * Implementations and stubs for getByte and memCopy functions.
+ * Functions to load object images from static memory.
+ *
+ * @author      Dean Hall
+ * @copyright   Copyright 2002 Dean Hall.  All rights reserved.
+ *
+ * Log
+ * ---
+ *
+ * 2006/08/31   #9: Fix BINARY_SUBSCR for case stringobj[intobj]
+ * 2006/08/29   #12: Make mem_*() funcs use RAM when target is DESKTOP
+ * 2006/08/29   #15 - All mem_*() funcs and pointers in the vm should use
+ *              unsigned not signed or void
+ * 2002/05/27   Added access to Flash and EEPROM.
+ * 2002/04/21   First.
+ */
+
+/***************************************************************
+ * Includes
+ **************************************************************/
+
+#include "py.h"
+
+#ifdef TARGET_AVR
+#include <avr/pgmspace.h>
+#include <avr/eeprom.h>
+#endif /* AVR */
+
+
+/***************************************************************
+ * Constants
+ **************************************************************/
+
+/***************************************************************
+ * Macros
+ **************************************************************/
+
+/***************************************************************
+ * Types
+ **************************************************************/
+
+/***************************************************************
+ * Globals
+ **************************************************************/
+
+/***************************************************************
+ * Prototypes
+ **************************************************************/
+
+/***************************************************************
+ * Functions
+ **************************************************************/
+
+U8
+mem_getByte(PyMemSpace_t memspace, P_U8 *paddr)
+{
+    U8 b = 0;
+
+    switch (memspace)
+    {
+        case MEMSPACE_RAM:
+            b = **paddr;
+            *paddr += 1;
+            return b;
+
+        case MEMSPACE_FLASH:
+#ifdef TARGET_AVR
+            b = pgm_read_byte(*paddr);
+#elif defined(TARGET_DESKTOP)
+            b = **paddr;
+#else
+#error Undefined TARGET
+#endif /* TARGET_AVR */
+            *paddr += 1;
+            return b;
+
+        case MEMSPACE_EEPROM:
+#ifdef TARGET_AVR
+            b = eeprom_read_byte((U16)*paddr);
+            *paddr += 1;
+#endif /* TARGET_AVR */
+            return b;
+
+        case MEMSPACE_SEEPROM:
+        case MEMSPACE_OTHER0:
+        case MEMSPACE_OTHER1:
+        case MEMSPACE_OTHER2:
+        case MEMSPACE_OTHER3:
+        default:
+            return 0;
+    }
+}
+
+
+INLINE
+U16
+mem_getWord(PyMemSpace_t memspace, P_U8 *paddr)
+{
+    /* PyMite is little endien; get lo byte first */
+    U8 blo = mem_getByte(memspace, paddr);
+    U8 bhi = mem_getByte(memspace, paddr);
+    return (U16)(blo | (bhi << 8));
+}
+
+
+INLINE
+U32
+mem_getInt(PyMemSpace_t memspace, P_U8 *paddr)
+{
+    /* PyMite is little endien; get low word first */
+    U16 wlo = mem_getWord(memspace, paddr);
+    U16 whi = mem_getWord(memspace, paddr);
+    return (U32)(wlo | (whi << 8));
+}
+
+
+void
+mem_copy(PyMemSpace_t memspace,
+         P_U8 *pdest,
+         P_U8 *psrc,
+         U16 count)
+{
+
+    /* copy memory from RAM */
+    if (memspace == MEMSPACE_RAM)
+    {
+        sli_memcpy(*pdest, *psrc, count);
+        *psrc += count;
+        *pdest += count;
+        return;
+    }
+
+    /* copy memory from non-RAM to RAM */
+    else
+    {
+        U8 b;
+
+        for ( ; count > 0; count--)
+        {
+            b = mem_getByte(memspace, psrc);
+            **pdest = b;
+            (*pdest)++;
+        }
+        return;
+    }
+}
+
+
+U16
+mem_getNumUtf8Bytes(PyMemSpace_t memspace, P_U8 *psrc)
+{
+    P_U8 pbase = *psrc;
+    while(mem_getByte(memspace, psrc) != 0);
+    return *psrc - pbase - 1;
+}
+
+
+/***************************************************************
+ * Test
+ **************************************************************/
+
+/***************************************************************
+ * Main
+ **************************************************************/