Commits

Anonymous committed f2347e9

#72 mainlining branch issue_0072_dwhall_port_to_mbed

Comments (0)

Files changed (21)

     }
 
     /* Create char string from  integer value */
-    retval = string_newFromChar((uint8_t const)n, &ps);
+    retval = string_newFromChar((uint8_t)n, &ps);
     NATIVE_SET_TOS(ps);
     return retval;
     """

src/platform/desktop/main.py

 
 
 import ipm
-ipm.ipm(globals())
+ipm.ipm()

src/platform/mbed/Makefile

+# Hey Emacs, this is a -*- makefile -*-
+#
+# WinARM template makefile 
+# by Martin Thomas, Kaiserslautern, Germany 
+# <eversmith@heizung-thomas.de>
+#
+# based on the WinAVR makefile written by Eric B. Weddington, J�rg Wunsch, et al.
+# Released to the Public Domain
+# Please read the make user manual!
+#
+#
+# On command line:
+#
+# make all = Make software.
+#
+# make clean = Clean out built project files.
+#
+# make program = Download the hex file to the device
+#
+# (TODO: make filename.s = Just compile filename.c into the assembler code only)
+#
+# To rebuild project do "make clean" then "make all".
+#
+# Changelog:
+# - 17. Feb. 2005  - added thumb-interwork support (mth)
+# - 28. Apr. 2005  - added C++ support (mth)
+# - 29. Arp. 2005  - changed handling for lst-Filename (mth)
+# -  1. Nov. 2005  - exception-vector placement options (mth)
+# - 15. Nov. 2005  - added library-search-path (EXTRA_LIB...) (mth)
+# -  2. Dec. 2005  - fixed ihex and binary file extensions (mth)
+# - 22. Feb. 2006  - added AT91LIBNOWARN setting (mth)
+# - 19. Apr. 2006  - option FLASH_TOOL (default lpc21isp); variable IMGEXT (mth)
+# - 23. Jun. 2006  - option USE_THUMB_MODE -> THUMB/THUMB_IW
+# -  3. Aug. 2006  - added -ffunction-sections -fdata-sections to CFLAGS
+#                    and --gc-sections to LDFLAGS. Only available for gcc 4 (mth)
+# -  4. Aug. 2006  - pass SUBMDL-define to frontend (mth)
+# - 11. Nov. 2006  - FLASH_TOOL-config, TCHAIN-config (mth)
+# - 28. Mar. 2007  - remove .dep-Directory with rm -r -f and force "no error"
+# - 24. Aprl 2007  - added "both" option for format (.bin and .hex)
+
+# PyMite Configuration
+PLATFORM := $(notdir $(CURDIR))
+PM_LIB_ROOT = pmvm_$(PLATFORM)
+PM_LIB_FN = lib$(PM_LIB_ROOT).a
+PM_LIB_PATH = ../../vm/$(PM_LIB_FN)
+PM_USR_SOURCES = main.py plat.py
+PM_HEAP_SIZE = 0x7000
+PMIMGCREATOR := ../../tools/pmImgCreator.py
+PM_UART_BAUD = 19200
+IPM := true
+
+# Toolchain prefix (i.e arm-elf -> arm-elf-gcc.exe)
+TCHAIN = arm-elf
+#TCHAIN = arm-none-eabi
+
+#FLASH_TOOL = UVISION
+#FLASH_TOOL = OPENOCD
+
+USE_THUMB_MODE = YES
+#USE_THUMB_MODE = NO
+
+# MCU name and submodel
+MCU      = arm7tdmi-s
+SUBMDL   = LPC2368
+
+## not supported in this example:
+## Create ROM-Image (final)
+RUN_MODE=ROM_RUN
+## Create RAM-Image (debugging) - not used in this example
+#RUN_MODE=RAM_RUN
+
+## not supported in this example:
+## Exception-Vector placement only supported for "ROM_RUN"
+## (placement settings ignored when using "RAM_RUN")
+## - Exception vectors in ROM:
+#VECTOR_LOCATION=VECTORS_IN_ROM
+## - Exception vectors in RAM:
+#VECTOR_LOCATION=VECTORS_IN_RAM
+
+
+# Target file name (without extension).
+TARGET = main
+
+# List C source files here. (C dependencies are automatically generated.)
+# use file-extension c for "c-only"-files
+SRC = $(TARGET)_nat.c $(TARGET)_img.c
+
+# List C source files here which must be compiled in ARM-Mode.
+# use file-extension c for "c-only"-files
+SRCARM = 
+
+# List C++ source files here.
+# use file-extension cpp for C++-files (use extension .cpp)
+CPPSRC = $(TARGET).cpp plat.cpp
+
+# List C++ source files here which must be compiled in ARM-Mode.
+# use file-extension cpp for C++-files (use extension .cpp)
+#CPPSRCARM = $(TARGET).cpp
+CPPSRCARM = 
+
+# List Assembler source files here.
+# Make them always end in a capital .S.  Files ending in a lowercase .s
+# will not be considered source files but generated files (assembler
+# output from the compiler), and will be deleted upon "make clean"!
+# Even though the DOS/Win* filesystem matches both .s and .S the same,
+# it will preserve the spelling of the filenames, and gcc itself does
+# care about how the name is spelled on its command-line.
+ASRC = 
+
+# List Assembler source files here which must be assembled in ARM-Mode..
+ASRCARM = 
+
+# Path to Linker-Scripts
+LINKERSCRIPTPATH = 
+
+## Output format. (can be ihex or binary or both)
+## (binary i.e. for openocd and SAM-BA, hex i.e. for lpc21isp and uVision)
+#FORMAT = ihex
+FORMAT = binary
+
+# Optimization level, can be [0, 1, 2, 3, s]. 
+# 0 = turn off optimization. s = optimize for size.
+# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
+OPT = s
+#OPT = 0
+
+## Using the Atmel AT91_lib produces warning with
+## the default warning-levels. 
+## yes - disable these warnings; no - keep default settings
+#AT91LIBNOWARN = yes
+AT91LIBNOWARN = no
+
+# Debugging format.
+# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
+# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
+#DEBUG = stabs
+DEBUG_FMT = dwarf-2
+
+# List any extra directories to look for include files here.
+#     Each directory must be seperated by a space.
+EXTRAINCDIRS = ../../vm
+
+# List any extra directories to look for library files here.
+#     Each directory must be seperated by a space.
+#EXTRA_LIBDIRS = ../arm7_efsl_0_2_4
+EXTRA_LIBDIRS = . ../../vm
+
+
+# Compiler flag to set the C Standard level.
+# c89   - "ANSI" C
+# gnu89 - c89 plus GCC extensions
+# c99   - ISO C99 standard (not yet fully implemented)
+# gnu99 - c99 plus GCC extensions
+CSTANDARD = -std=gnu99
+
+# Place -D or -U options for C here
+CDEFS =  -D$(RUN_MODE)
+# PyMite CDEFS
+CDEFS += -DHEAP_SIZE=$(PM_HEAP_SIZE) -DUART_BAUD=$(PM_UART_BAUD)
+ifeq ($(DEBUG),true)
+	CDEFS += -g -g$(DEBUG_FMT) -D__DEBUG__=1
+endif
+
+# Place -I options here
+CINCS =
+
+# Place -D or -U options for ASM here
+ADEFS =  -D$(RUN_MODE)
+
+ifdef VECTOR_LOCATION
+CDEFS += -D$(VECTOR_LOCATION)
+ADEFS += -D$(VECTOR_LOCATION)
+endif
+
+CDEFS += -D__WinARM__ -D__WINARMSUBMDL_$(SUBMDL)__
+ADEFS += -D__WinARM__ -D__WINARMSUBMDL_$(SUBMDL)__
+
+# Compiler flags.
+
+ifeq ($(USE_THUMB_MODE),YES)
+THUMB    = -mthumb
+#THUMB_IW = -mthumb-interwork
+THUMB_IW = 
+else 
+THUMB    = 
+THUMB_IW = 
+endif
+
+#  -g*:          generate debugging information
+#  -O*:          optimization level
+#  -f...:        tuning, see GCC manual and avr-libc documentation
+#  -Wall...:     warning level
+#  -Wa,...:      tell GCC to pass this to the assembler.
+#    -adhlns...: create assembler listing
+#
+# Flags for C and C++ (arm-elf-gcc/arm-elf-g++)
+CFLAGS = $(CDEFS) $(CINCS)
+CFLAGS += -O$(OPT)
+#CFLAGS += -Wcast-align 
+CFLAGS += -Wall -Wimplicit 
+CFLAGS += -Wpointer-arith -Wswitch
+CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wunused
+CFLAGS += -Wa,-adhlns=$(subst $(suffix $<),.lst,$<) 
+CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
+
+# flags only for C
+CONLYFLAGS += -Wnested-externs 
+CONLYFLAGS += $(CSTANDARD)
+
+ifneq ($(AT91LIBNOWARN),yes)
+#AT91-lib warnings with:
+CFLAGS += -Wcast-qual
+CONLYFLAGS += -Wmissing-prototypes 
+CONLYFLAGS += -Wstrict-prototypes
+CONLYFLAGS += -Wmissing-declarations
+endif
+
+# flags only for C++ (arm-elf-g++)
+# CPPFLAGS = -fno-rtti -fno-exceptions
+CPPFLAGS = 
+
+# Assembler flags.
+#  -Wa,...:    tell GCC to pass this to the assembler.
+#  -ahlns:     create listing
+#  -g$(DEBUG): have the assembler create line number information
+ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:.S=.lst),--g$(DEBUG_FMT)
+
+
+#Additional libraries.
+
+# Extra libraries
+#    Each library-name must be seperated by a space.
+#    To add libxyz.a, libabc.a and libefsl.a: 
+#    EXTRA_LIBS = xyz abc efsl
+#EXTRA_LIBS = efsl
+EXTRA_LIBS = $(PM_LIB_ROOT) mbed
+
+#Support for newlibc-lpc (file: libnewlibc-lpc.a)
+#NEWLIBLPC = -lnewlib-lpc
+
+MATH_LIB = -lm
+
+# CPLUSPLUS_LIB = -lstdc++
+
+
+# Linker flags.
+#  -Wl,...:     tell GCC to pass this to linker.
+#    -Map:      create map file
+#    --cref:    add cross reference to  map file
+LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref,--gc-sections
+LDFLAGS += -lc
+LDFLAGS += $(NEWLIBLPC) $(MATH_LIB)
+LDFLAGS += -lc -lgcc 
+LDFLAGS += $(CPLUSPLUS_LIB)
+LDFLAGS += $(patsubst %,-L%,$(EXTRA_LIBDIRS))
+LDFLAGS += $(patsubst %,-l%,$(EXTRA_LIBS))
+
+# Set Linker-Script Depending On Selected Memory and Controller
+ifeq ($(RUN_MODE),RAM_RUN)
+LDFLAGS +=-T$(LINKERSCRIPTPATH)/$(SUBMDL)-RAM.ld
+else 
+LDFLAGS +=-T$(LINKERSCRIPTPATH)/$(SUBMDL)-ROM.ld
+endif
+
+# ---------------------------------------------------------------------------
+# Flash-Programming support using lpc21isp by Martin Maurer 
+# only for Philips LPC and Analog ADuC ARMs
+#
+# Settings and variables:
+#LPC21ISP = lpc21isp
+LPC21ISP = lpc21isp
+LPC21ISP_PORT = com1
+LPC21ISP_BAUD = 38400
+LPC21ISP_XTAL = 12000
+# other options:
+# * verbose output: -debug
+# * enter bootloader via RS232 DTR/RTS (only if hardware supports this
+#   feature - see Philips AppNote): -control
+LPC21ISP_OPTIONS = -control
+#LPC21ISP_OPTIONS += -debug
+# ---------------------------------------------------------------------------
+
+
+# Define directories, if needed.
+## DIRARM = c:/WinARM/
+## DIRARMBIN = $(DIRAVR)/bin/
+## DIRAVRUTILS = $(DIRAVR)/utils/bin/
+
+# Define programs and commands.
+SHELL = sh
+CC = $(TCHAIN)-gcc
+CPP = $(TCHAIN)-g++
+AR = $(TCHAIN)-ar
+OBJCOPY = $(TCHAIN)-objcopy
+OBJDUMP = $(TCHAIN)-objdump
+SIZE = $(TCHAIN)-size
+NM = $(TCHAIN)-nm
+AR = $(TCHAIN)-ar
+REMOVE = rm -f
+REMOVEDIR = rm -f -r
+COPY = cp
+
+# Define Messages
+# English
+MSG_ERRORS_NONE = Errors: none
+MSG_BEGIN = "-------- begin (mode: $(RUN_MODE)) --------"
+MSG_END = --------  end  --------
+MSG_SIZE_BEFORE = Size before: 
+MSG_SIZE_AFTER = Size after:
+MSG_FLASH = Creating load file for Flash:
+MSG_EXTENDED_LISTING = Creating Extended Listing:
+MSG_SYMBOL_TABLE = Creating Symbol Table:
+MSG_LINKING = Linking:
+MSG_COMPILING = Compiling C:
+MSG_COMPILING_ARM = "Compiling C (ARM-only):"
+MSG_COMPILINGCPP = Compiling C++:
+MSG_COMPILINGCPP_ARM = "Compiling C++ (ARM-only):"
+MSG_ASSEMBLING = Assembling:
+MSG_ASSEMBLING_ARM = "Assembling (ARM-only):"
+MSG_CLEANING = Cleaning project:
+MSG_FORMATERROR = Can not handle output-format
+MSG_LPC21_RESETREMINDER = You may have to bring the target in bootloader-mode now.
+
+# Define all object files.
+COBJ      = $(SRC:.c=.o) 
+AOBJ      = $(ASRC:.S=.o)
+COBJARM   = $(SRCARM:.c=.o)
+AOBJARM   = $(ASRCARM:.S=.o)
+CPPOBJ    = $(CPPSRC:.cpp=.o) 
+CPPOBJARM = $(CPPSRCARM:.cpp=.o)
+
+# Define all listing files.
+LST = $(ASRC:.S=.lst) $(ASRCARM:.S=.lst) $(SRC:.c=.lst) $(SRCARM:.c=.lst)
+LST += $(CPPSRC:.cpp=.lst) $(CPPSRCARM:.cpp=.lst)
+
+# Compiler flags to generate dependency files.
+### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
+#GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
+
+# Combine all necessary flags and optional flags.
+# Add target processor to flags.
+ALL_CFLAGS  = -mcpu=$(MCU) $(THUMB) $(THUMB_IW) -I. $(CFLAGS) $(GENDEPFLAGS)
+ALL_ASFLAGS = -mcpu=$(MCU) $(THUMB) $(THUMB_IW) -I. -x assembler-with-cpp $(ASFLAGS)
+
+
+# Default target.
+all: begin gccversion pmvm sizebefore build sizeafter finished end
+
+ifeq ($(FORMAT),ihex)
+build: elf hex bin lss sym
+hex: $(TARGET).hex
+IMGEXT=hex
+else 
+ifeq ($(FORMAT),binary)
+build: elf bin lss sym
+bin: $(TARGET).bin
+IMGEXT=bin
+else 
+ifeq ($(FORMAT),both)
+build: elf hex bin lss sym
+hex: $(TARGET).hex
+bin: $(TARGET).bin
+else 
+$(error "$(MSG_FORMATERROR) $(FORMAT)")
+endif
+endif
+endif
+
+elf: $(TARGET).elf
+lss: $(TARGET).lss 
+sym: $(TARGET).sym
+
+# PyMite: Build the VM archive if it doesn't exist
+pmvm : $(PM_LIB_PATH)
+
+$(PM_LIB_PATH) :
+	make -C ../../vm
+
+# Eye candy.
+begin:
+	@echo
+	@echo $(MSG_BEGIN)
+
+finished:
+	@echo $(MSG_ERRORS_NONE)
+
+end:
+	@echo $(MSG_END)
+	@echo
+
+
+# Display size of file.
+HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
+ELFSIZE = $(SIZE) -A $(TARGET).elf
+sizebefore:
+	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
+
+sizeafter:
+	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
+
+
+# Display compiler version information.
+gccversion : 
+	@$(CC) --version
+
+# Program the device.
+ifeq ($(FLASH_TOOL),UVISION)
+# Program the device with Keil's uVision (needs configured uVision-Workspace). 
+program: $(TARGET).hex
+	@echo
+	@echo "Programming with uVision"
+#	C:\Keil\uv3\Uv3.exe -f uvisionflash.Uv2 -ouvisionflash.txt
+	$(REMOVE) ../Common_WinARM/$(TARGET).hex
+	$(COPY) $(TARGET).hex ../Common_WinARM/
+	C:\Keil\uv3\Uv3.exe -f ..\Common_WinARM\uvisionflash.Uv2
+else
+ifeq ($(FLASH_TOOL),OPENOCD)
+# Program the device with Dominic Rath's OPENOCD in "batch-mode", needs cfg and "reset-script".
+program: $(TARGET).bin
+	@echo
+	@echo "Programming with OPENOCD"
+	openocd_start_flash.cmd
+#OOCD_load_image=$(TARGET).bin
+#include oocd_flashing.mk
+#program : $(TARGET).bin oocd_programprepare oocd_programdoit
+#program : $(TARGET).bin oocd_programdoit
+else
+# Program the device.  - lpc21isp will not work for SAM7
+program: $(TARGET).hex
+	@echo
+	@echo $(MSG_LPC21_RESETREMINDER)
+	$(LPC21ISP) $(LPC21ISP_OPTIONS) $(LPC21ISP_FLASHFILE) $(LPC21ISP_PORT) $(LPC21ISP_BAUD) $(LPC21ISP_XTAL)
+endif
+endif
+
+
+# Create final output file (.hex) from ELF output file.
+%.hex: %.elf
+	@echo
+	@echo $(MSG_FLASH) $@
+	$(OBJCOPY) -O ihex $< $@
+	
+# Create final output file (.bin) from ELF output file.
+%.bin: %.elf
+	@echo
+	@echo $(MSG_FLASH) $@
+	$(OBJCOPY) -O binary $< $@
+
+
+# Create extended listing file from ELF output file.
+# testing: option -C
+%.lss: %.elf
+	@echo
+	@echo $(MSG_EXTENDED_LISTING) $@
+	$(OBJDUMP) -h -S -C $< > $@
+
+
+# Create a symbol table from ELF output file.
+%.sym: %.elf
+	@echo
+	@echo $(MSG_SYMBOL_TABLE) $@
+	$(NM) -n $< > $@
+
+
+# Link: create ELF output file from object files.
+.SECONDARY : $(TARGET).elf
+.PRECIOUS : $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) $(CPPOBJ) $(CPPOBJARM)
+%.elf:  $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) $(CPPOBJ) $(CPPOBJARM)
+	@echo
+	@echo $(MSG_LINKING) $@
+	$(CC) $(THUMB) $(ALL_CFLAGS) $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) $(CPPOBJ) $(CPPOBJARM) --output $@ $(LDFLAGS)
+#	$(CPP) $(THUMB) $(ALL_CFLAGS) $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) $(CPPOBJ) $(CPPOBJARM) --output $@ $(LDFLAGS)
+
+# Compile: create object files from C source files. ARM/Thumb
+$(COBJ) : %.o : %.c
+	@echo
+	@echo $(MSG_COMPILING) $<
+	$(CC) -c $(THUMB) $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@ 
+
+# Compile: create object files from C source files. ARM-only
+$(COBJARM) : %.o : %.c
+	@echo
+	@echo $(MSG_COMPILING_ARM) $<
+	$(CC) -c $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@ 
+
+# Compile: create object files from C++ source files. ARM/Thumb
+$(CPPOBJ) : %.o : %.cpp
+	@echo
+	@echo $(MSG_COMPILINGCPP) $<
+	$(CPP) -c $(THUMB) $(ALL_CFLAGS) $(CPPFLAGS) $< -o $@ 
+
+# Compile: create object files from C++ source files. ARM-only
+$(CPPOBJARM) : %.o : %.cpp
+	@echo
+	@echo $(MSG_COMPILINGCPP_ARM) $<
+	$(CPP) -c $(ALL_CFLAGS) $(CPPFLAGS) $< -o $@ 
+
+
+# Compile: create assembler files from C source files. ARM/Thumb
+## does not work - TODO - hints welcome
+##$(COBJ) : %.s : %.c
+##	$(CC) $(THUMB) -S $(ALL_CFLAGS) $< -o $@
+
+
+# Assemble: create object files from assembler source files. ARM/Thumb
+$(AOBJ) : %.o : %.S
+	@echo
+	@echo $(MSG_ASSEMBLING) $<
+	$(CC) -c $(THUMB) $(ALL_ASFLAGS) $< -o $@
+
+
+# Assemble: create object files from assembler source files. ARM-only
+$(AOBJARM) : %.o : %.S
+	@echo
+	@echo $(MSG_ASSEMBLING_ARM) $<
+	$(CC) -c $(ALL_ASFLAGS) $< -o $@
+
+
+# PyMite: Generate native code and module images from the python source
+$(TARGET)_nat.c $(TARGET)_img.c : $(PM_USR_SOURCES)
+	$(PMIMGCREATOR) -c -u -o $(TARGET)_img.c --native-file=$(TARGET)_nat.c $(PM_USR_SOURCES)
+
+../../vm/pmstdlib_img.c ../../vm/pmstdlib_nat.c : 
+	$(MAKE) -C ../../vm pmstdlib_img.c pmstdlib_nat.c
+
+zip: pymite_mbed.zip
+
+pymite_mbed.zip: pmvm $(TARGET)_nat.c $(TARGET)_img.c ../../vm/pmstdlib_img.c ../../vm/pmstdlib_nat.c
+	$(RM) $@
+	cd ../../.. && zip src/platform/mbed/$@ src/vm/*.c src/vm/*.h src/platform/mbed/* -x src/platform/mbed/Makefile -x src/platform/mbed/README -x src/platform/mbed/*.py
+
+
+# Target: clean project.
+clean: begin clean_list finished end
+
+
+clean_list :
+	$(MAKE) -C ../../vm clean
+	@echo
+	@echo $(MSG_CLEANING)
+	$(REMOVE) $(TARGET).hex
+	$(REMOVE) $(TARGET).bin
+	$(REMOVE) $(TARGET).obj
+	$(REMOVE) $(TARGET).elf
+	$(REMOVE) $(TARGET).map
+	$(REMOVE) $(TARGET).obj
+	$(REMOVE) $(TARGET).a90
+	$(REMOVE) $(TARGET).sym
+	$(REMOVE) $(TARGET).lnk
+	$(REMOVE) $(TARGET).lss
+	$(REMOVE) $(COBJ)
+	$(REMOVE) $(CPPOBJ)
+	$(REMOVE) $(AOBJ)
+	$(REMOVE) $(COBJARM)
+	$(REMOVE) $(CPPOBJARM)
+	$(REMOVE) $(AOBJARM)
+	$(REMOVE) $(LST)
+	$(REMOVE) $(SRC:.c=.s)
+	$(REMOVE) $(SRC:.c=.d)
+	$(REMOVE) $(SRCARM:.c=.s)
+	$(REMOVE) $(SRCARM:.c=.d)
+	$(REMOVE) $(CPPSRC:.cpp=.s) 
+	$(REMOVE) $(CPPSRC:.cpp=.d)
+	$(REMOVE) $(CPPSRCARM:.cpp=.s) 
+	$(REMOVE) $(CPPSRCARM:.cpp=.d)
+	$(REMOVE) $(TARGET)_img.c
+	$(REMOVE) $(TARGET)_nat.c
+	$(REMOVEDIR) .dep | exit 0
+
+
+# Include the dependency files.
+-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
+
+
+# Listing of phony targets.
+.PHONY : all begin finish end sizebefore sizeafter gccversion \
+build elf hex bin lss sym clean clean_list program pmvm zip
+
+
+export CC OBJCOPY NM CFLAGS ALL_CFLAGS AR IPM PM_HEAP_SIZE PM_LIB_FN

src/platform/mbed/README

+=========================
+The Mbed Platform Project
+=========================
+
+
+:Author:    Dean Hall
+:Id:        $Id$
+
+
+Purpose
+-------
+
+This is a sample project that demonstrates running interactive PyMite (ipm)
+on the Mbed-002_ board, which is an NXP LPC2368_ in a stamp configuration.
+
+.. _`Mbed-002`: http://mbed.co.uk
+.. _`LPC2368`: http://www.standardics.nxp.com/products/lpc2000/lpc23xx/
+
+
+Building the Project
+--------------------
+
+Building this project is not currently supported.
+You must be a beta-tester of the Mbed system to build this project.
+All this will change soon when the Mbed is released to the public.
+
+
+.. :mode=rest:

src/platform/mbed/TextLCD.lib

+http://mbed.co.uk/projects/cookbook/svn/TextLCD/trunk@267

src/platform/mbed/main.cpp

+/*
+ * PyMite - A flyweight Python interpreter for 8-bit and larger microcontrollers.
+ * Copyright 2002 Dean Hall.  All rights reserved.
+ * PyMite is offered through one of two licenses: commercial or open-source.
+ * See the LICENSE file at the root of this package for licensing details.
+ */
+
+
+#include "pm.h"
+
+
+#ifdef __cplusplus
+extern
+#endif
+unsigned char const usrlib_img[];
+
+
+int
+main(void)
+{
+    PmReturn_t retval;
+
+    /* Init PyMite */
+    retval = pm_init(MEMSPACE_PROG, (uint8_t *)usrlib_img);
+    PM_RETURN_IF_ERROR(retval);
+
+    /* Run the sample program */
+    retval = pm_run((uint8_t *)"main");
+
+    return (int)retval;
+}

src/platform/mbed/main.py

+#
+# PyMite - A flyweight Python interpreter for 8-bit and larger microcontrollers.
+# Copyright 2002 Dean Hall.  All rights reserved.
+# PyMite is offered through one of two licenses: commercial or open-source.
+# See the LICENSE file at the root of this package for licensing details.
+#
+
+import ipm
+ipm.ipm(globals())

src/platform/mbed/mbed.lib

+http://mbed.co.uk/projects/libraries/svn/mbed/trunk@9

src/platform/mbed/plat.cpp

+/*
+ * PyMite - A flyweight Python interpreter for 8-bit and larger microcontrollers.
+ * Copyright 2002 Dean Hall.  All rights reserved.
+ * PyMite is offered through one of two licenses: commercial or open-source.
+ * See the LICENSE file at the root of this package for licensing details.
+ */
+
+
+#undef __FILE_ID__
+#define __FILE_ID__ 0x52
+
+
+/** PyMite platform-specific routines for ARM7 target */
+
+
+#include "pm.h"
+#include "mbed.h"
+
+
+#define CALLBACK_MS 100
+
+
+Serial serial(USBTX, USBRX, "serial");
+Ticker ticker;
+
+
+static void
+ticker_callback(void)
+{
+    PmReturn_t retval;
+
+    retval = pm_vmPeriodic(CALLBACK_MS);
+    PM_REPORT_IF_ERROR(retval);
+}
+
+
+PmReturn_t
+plat_init(void)
+{
+    serial.baud(19200);
+    serial.format(8, serial.None, 1);
+
+    ticker.attach_us(ticker_callback, CALLBACK_MS * 1000);
+
+    return PM_RET_OK;
+}
+
+
+uint8_t
+plat_memGetByte(PmMemSpace_t memspace, uint8_t const **paddr)
+{
+    uint8_t b = 0;
+
+    switch (memspace)
+    {
+        case MEMSPACE_RAM:
+        case MEMSPACE_PROG:
+            b = **paddr;
+            *paddr += 1;
+            return b;
+
+        case MEMSPACE_EEPROM:
+        case MEMSPACE_SEEPROM:
+        case MEMSPACE_OTHER0:
+        case MEMSPACE_OTHER1:
+        case MEMSPACE_OTHER2:
+        case MEMSPACE_OTHER3:
+        default:
+            return 0;
+    }
+}
+
+
+PmReturn_t
+plat_getByte(uint8_t *b)
+{
+    int c;
+    PmReturn_t retval = PM_RET_OK;
+
+    c = serial.getc();
+    *b = c & 0xFF;
+
+    if (c > 0xFF)
+    {
+        PM_RAISE(retval, PM_RET_EX_IO);
+    }
+
+    return retval;
+}
+
+
+PmReturn_t
+plat_putByte(uint8_t b)
+{
+    while (!serial.writeable());
+    serial.putc(b);
+
+    return PM_RET_OK;
+}
+
+
+PmReturn_t
+plat_getMsTicks(uint32_t *r_ticks)
+{
+    *r_ticks = pm_timerMsTicks;
+
+    return PM_RET_OK;
+}
+
+
+void
+plat_reportError(PmReturn_t result)
+{
+     /* Print error */
+    serial.printf("Error:     0x%02X\n", result);
+    serial.printf("  Release: 0x%02X\n", gVmGlobal.errVmRelease);
+    serial.printf("  FileId:  0x%02X\n", gVmGlobal.errFileId);
+    serial.printf("  LineNum: %d\n", gVmGlobal.errLineNum);
+
+    /* Print traceback */
+    {
+        pPmObj_t pframe;
+        pPmObj_t pstr;
+        PmReturn_t retval;
+
+        serial.printf("Traceback (top first):\n");
+
+        /* Get the top frame */
+        pframe = (pPmObj_t)gVmGlobal.pthread->pframe;
+
+        /* If it's the native frame, print the native function name */
+        if (pframe == (pPmObj_t)&(gVmGlobal.nativeframe))
+        {
+
+            /* The last name in the names tuple of the code obj is the name */
+            retval = tuple_getItem((pPmObj_t)gVmGlobal.nativeframe.nf_func->
+                                   f_co->co_names, -1, &pstr);
+            if ((retval) != PM_RET_OK)
+            {
+                serial.printf("  Unable to get native func name.\n");
+                return;
+            }
+            else
+            {
+                serial.printf("  %s() __NATIVE__\n", ((pPmString_t)pstr)->val);
+            }
+
+            /* Get the frame that called the native frame */
+            pframe = (pPmObj_t)gVmGlobal.nativeframe.nf_back;
+        }
+
+        /* Print the remaining frame stack */
+        for (;
+             pframe != C_NULL;
+             pframe = (pPmObj_t)((pPmFrame_t)pframe)->fo_back)
+        {
+            /* The last name in the names tuple of the code obj is the name */
+            retval = tuple_getItem((pPmObj_t)((pPmFrame_t)pframe)->
+                                   fo_func->f_co->co_names, -1, &pstr);
+            if ((retval) != PM_RET_OK) break;
+
+            serial.printf("  %s()\n", ((pPmString_t)pstr)->val);
+        }
+        serial.printf("  <module>.\n");
+    }
+}

src/platform/mbed/plat.py

+"""__NATIVE__
+#include "mbed.h"
+#include "TextLCD.h"
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+AnalogIn *adc;
+AnalogOut *dac;
+DigitalIn *din;
+DigitalOut *dout;
+PwmOut *pwm;
+TextLCD *lcd;
+"""
+
+
+# Imitation of a AnalogIn class
+def AnalogIn(pin):
+
+    def _adc_init(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Instantiate the object */
+        n = ((pPmInt_t)pn)->val;
+        adc = new AnalogIn(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+        return retval;
+        """
+        pass
+
+
+    def _adc_read_u16():
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 0)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Return input value on the stack */
+        n = adc->read_u16();
+        retval = int_new(n, &pn);
+        NATIVE_SET_TOS(pn);
+
+        return retval;
+        """
+        pass
+
+
+    # Run initializer and set attrs (methods)
+    _adc_init(pin)
+    AnalogIn.read_u16 = _adc_read_u16
+
+    return AnalogIn
+
+
+# Imitation of a AnalogOut class
+def AnalogOut(pin):
+
+    def _dac_init(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Instantiate the object */
+        n = ((pPmInt_t)pn)->val;
+        dac = new AnalogOut(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+        return retval;
+        """
+        pass
+
+
+    def _dac_write_u16(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Write value to output */
+        n = ((pPmInt_t)pn)->val;
+        dac->write_u16(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+
+        return retval;
+        """
+        pass
+
+
+    # Run initializer and set attrs (methods)
+    _dac_init(pin)
+    AnalogOut.write = _dac_write_u16
+
+    return AnalogOut
+
+
+# Imitation of a DigitalIn class
+def DigitalIn(pin):
+
+    def _din_init(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Instantiate the object */
+        n = ((pPmInt_t)pn)->val;
+        din = new DigitalIn(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+        return retval;
+        """
+        pass
+
+
+    def _din_read():
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 0)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Return input value on the stack */
+        n = din->read();
+        retval = int_new(n, &pn);
+        NATIVE_SET_TOS(pn);
+
+        return retval;
+        """
+        pass
+
+
+    # Run initializer and set attrs (methods)
+    _din_init(pin)
+    DigitalIn.read = _din_read
+
+    return DigitalIn
+
+
+# Imitation of a DigitalOut class
+def DigitalOut(pin):
+
+    def _dout_init(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Instantiate the object */
+        n = ((pPmInt_t)pn)->val;
+        dout = new DigitalOut(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+        return retval;
+        """
+        pass
+
+
+    def _dout_read():
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 0)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Return input value on the stack */
+        n = dout->read();
+        retval = int_new(n, &pn);
+        NATIVE_SET_TOS(pn);
+
+        return retval;
+        """
+        pass
+
+
+    def _dout_write(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Write value to output */
+        n = ((pPmInt_t)pn)->val;
+        dout->write(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+
+        return retval;
+        """
+        pass
+
+
+    # Run initializer and set attrs (methods)
+    _dout_init(pin)
+    DigitalOut.read = _dout_read
+    DigitalOut.write = _dout_write
+
+    return DigitalOut
+
+
+# Imitation of a PwmOut class
+def PwmOut(pin):
+
+    def _pwm_init(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Instantiate the object */
+        n = ((pPmInt_t)pn)->val;
+        pwm = new PwmOut(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+        return retval;
+        """
+        pass
+
+
+    def _pwm_period_us(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Write value to output */
+        n = ((pPmInt_t)pn)->val;
+        pwm->period_us(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+
+        return retval;
+        """
+        pass
+
+
+    def _pwm_pulsewidth_us(n):
+        """__NATIVE__
+        pPmObj_t pn;
+        int32_t n;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pn = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(pn) != OBJ_TYPE_INT)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Write value to output */
+        n = ((pPmInt_t)pn)->val;
+        pwm->pulsewidth_us(n);
+
+        NATIVE_SET_TOS(PM_NONE);
+
+        return retval;
+        """
+        pass
+
+
+    # Run initializer and set attrs (methods)
+    _pwm_init(pin)
+    PwmOut.period_us = _pwm_period_us
+    PwmOut.pulsewidth_us = _pwm_pulsewidth_us
+
+    return PwmOut
+
+
+# Imitation of a TextLCD class
+def TextLCD():
+
+    def _lcd_init():
+        """__NATIVE__
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 0)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        lcd = new TextLCD(24, 25, 26, 27, 28, 29, 30);
+
+        /* Return none obj on stack */
+        NATIVE_SET_TOS(PM_NONE);
+
+        return retval;
+        """
+        pass
+
+
+    def _lcd_printf(s):
+        """__NATIVE__
+        pPmObj_t ps = C_NULL;
+        uint8_t *s = C_NULL;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 1)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        ps = NATIVE_GET_LOCAL(0);
+        if (OBJ_GET_TYPE(ps) != OBJ_TYPE_STR)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get a pointer to the string */
+        s = ((pPmString_t)ps)->val;
+
+        /* Print the string on the lcd */
+        lcd->printf((char *)s);
+
+        /* Return none obj on stack */
+        NATIVE_SET_TOS(PM_NONE);
+
+        return retval;
+        """
+        pass
+
+
+    def _lcd_cls():
+        """__NATIVE__
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 0)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Clear the lcd */
+        lcd->cls();
+
+        /* Return none obj on stack */
+        NATIVE_SET_TOS(PM_NONE);
+
+        return retval;
+        """
+        pass
+
+
+    def _lcd_locate(column, row):
+        """__NATIVE__
+        pPmObj_t pc = C_NULL;
+        pPmObj_t pr = C_NULL;
+        int32_t nc;
+        int32_t nr;
+        PmReturn_t retval = PM_RET_OK;
+
+        /* If wrong number of args, throw type exception */
+        if (NATIVE_GET_NUM_ARGS() != 2)
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get the arg, throw type exception if needed */
+        pc = NATIVE_GET_LOCAL(0);
+        pr = NATIVE_GET_LOCAL(1);
+        if ((OBJ_GET_TYPE(pc) != OBJ_TYPE_INT)
+            || (OBJ_GET_TYPE(pr) != OBJ_TYPE_INT))
+        {
+            PM_RAISE(retval, PM_RET_EX_TYPE);
+            return retval;
+        }
+
+        /* Get a pointer to the values */
+        nc = ((pPmInt_t)pc)->val;
+        nr = ((pPmInt_t)pr)->val;
+
+        /* Print the string on the lcd */
+        lcd->locate(nc, nr);
+
+        /* Return none obj on stack */
+        NATIVE_SET_TOS(PM_NONE);
+
+        return retval;
+        """
+        pass
+
+
+    # Run initializer and set attrs (methods)
+    _lcd_init()
+    TextLCD.printf = _lcd_printf
+    TextLCD.cls = _lcd_cls
+    TextLCD.locate = _lcd_locate
+
+    return TextLCD
+
+
+
+def set_led(led, val):
+    """__NATIVE__
+    pPmObj_t pled;
+    pPmObj_t pval;
+    int32_t nled;
+    int32_t nval;
+    PmReturn_t retval = PM_RET_OK;
+
+    /* If wrong number of args, raise TypeError */
+    if (NATIVE_GET_NUM_ARGS() > 2)
+    {
+        PM_RAISE(retval, PM_RET_EX_TYPE);
+        return retval;
+    }
+
+    /* If arg is not an int, raise TypeError */
+    pled = NATIVE_GET_LOCAL(0);
+    pval = NATIVE_GET_LOCAL(1);
+    if ((OBJ_GET_TYPE(pled) != OBJ_TYPE_INT)
+        || (OBJ_GET_TYPE(pval) != OBJ_TYPE_INT))
+    {
+        PM_RAISE(retval, PM_RET_EX_TYPE);
+        return retval;
+    }
+
+    /* Get int value from the arg */
+    nled = ((pPmInt_t)pled)->val;
+    nval = ((pPmInt_t)pval)->val;
+
+    /* Set the LED to the given value */
+    switch (nled)
+    {
+        case 1: led1 = nval; break;
+        case 2: led2 = nval; break;
+        case 3: led3 = nval; break;
+        case 4: led4 = nval; break;
+    }
+
+    NATIVE_SET_TOS(PM_NONE);
+    return retval;
+    """
+    pass
+
+# :mode=c:

src/tools/pmImgCreator.py

                           )
                        )
         fileBuff.append("/* Place the image into %s */\n"
-                        "const unsigned char\n"
+                        "#ifdef __cplusplus\n"
+                        "extern\n"
+                        "#endif\n"
+                        "unsigned char const\n"
                         % self.memspace.upper()
                        )
 
     /* This does not use snprintf because glibc's snprintf is only
      * included for compiles without strict-ansi.
      */
-    bytesWritten = sprintf((void *)&tBuffer, "%f", ((pPmFloat_t) pf)->val);
+    bytesWritten = sprintf((char *)&tBuffer, "%f", ((pPmFloat_t) pf)->val);
 
     /* Sanity check */
     C_ASSERT(bytesWritten != 0);
 #include "pm.h"
 
 
-extern unsigned char stdlib_img[];
-
+extern unsigned char const *stdlib_img;
 
 static uint8_t const *bistr = (uint8_t const *)"__bi";
 
 
 
 /**
- * Static initial size of the heap.
- * A value should be provided by the makefile
- */
-#ifndef HEAP_SIZE
-#error HEAP_SIZE not defined by the build environment
-#endif
-#if HEAP_SIZE & 3
-#error HEAP_SIZE is not a multiple of four
-#endif
-
-/**
  * The maximum size a live chunk can be (a live chunk is one that is in use).
  * The live chunk size is limited by the size field in the *object* descriptor.
  * That field is nine bits with two assumed least significant bits (zeros):
     /* The object must not already be free */
     C_ASSERT(OBJ_GET_FREE(pobj) == 0);
 
-    type = OBJ_GET_TYPE(pobj);
+    type = (PmType_t)OBJ_GET_TYPE(pobj);
     switch (type)
     {
             /* Objects with no references to other objects */
 
 /* Enables or disables automatic garbage collection */
 PmReturn_t
-heap_gcSetAuto(uint8_t bool)
+heap_gcSetAuto(uint8_t auto_gc)
 {
-    pmHeap.auto_gc = bool;
+    pmHeap.auto_gc = auto_gc;
     return PM_RET_OK;
 }
 #endif /* HAVE_GC */
  * @param   bool Value to enable or disable auto GC
  * @return  Return code
  */
-PmReturn_t heap_gcSetAuto(uint8_t bool);
+PmReturn_t heap_gcSetAuto(uint8_t auto_gc);
 #endif /* HAVE_GC */
 
 #endif /* __HEAP_H__ */
         *paddr = imgtop + CI_NAMES_FIELD;
 
         /* Ensure it's a tuple */
-        type = mem_getByte(memspace, paddr);
+        type = (PmType_t)mem_getByte(memspace, paddr);
         C_ASSERT(type == OBJ_TYPE_TUP);
 
         /* Scan to last name in tuple (it's the module's name) */
         for (; i > 0; i--)
         {
             /* Ensure obj is a string */
-            type = mem_getByte(memspace, paddr);
+            type = (PmType_t)mem_getByte(memspace, paddr);
             C_ASSERT(type == OBJ_TYPE_STR);
 
             /* Skip the length of the string */
         }
 
         /* Ensure it's a string */
-        type = mem_getByte(memspace, paddr);
+        type = (PmType_t)mem_getByte(memspace, paddr);
         C_ASSERT(type == OBJ_TYPE_STR);
 
         /* If strings match, return the address of this image */
         *paddr = imgtop;
 
         /* Check if another img follows this one */
-        type = mem_getByte(memspace, paddr);
+        type = (PmType_t)mem_getByte(memspace, paddr);
     }
     return PM_RET_NO;
 }
      * included for compiles without strict-ansi.
      */
     bytesWritten =
-        sprintf((void *)&tBuffer, "%li", (long int)((pPmInt_t)pint)->val);
+        sprintf((char *)&tBuffer, "%li", (long int)((pPmInt_t)pint)->val);
 
 
     /* Sanity check */
                 if ((OBJ_GET_TYPE(TOS) == OBJ_TYPE_FLT)
                     || (OBJ_GET_TYPE(TOS1) == OBJ_TYPE_FLT))
                 {
-                    retval = float_compare(TOS1, TOS, &pobj3, t16);
+                    retval = float_compare(TOS1, TOS, &pobj3, (PmCompare_t)t16);
                     SP--;
                     TOS = pobj3;
                     continue;
             return seq_compare(pobj1, pobj2);
 
         case OBJ_TYPE_DIC:
+            /* #17: PyMite does not support Dict comparisons (yet) */
         default:
-            /* #17: PyMite does not support Dict comparisons (yet) */
-            return C_DIFFER;
+            break;
     }
 
     /* All other types would need same pointer to be true */
  */
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <stdint.h>
 #include <stdio.h>
 
  */
 #define PM_RELEASE 7
 
+/** Static initial size of the heap. */
+#ifndef HEAP_SIZE
+#warning HEAP_SIZE not defined by the build environment, defaulting to 0x7000
+#define HEAP_SIZE 0x7000
+#endif
+#if HEAP_SIZE & 3
+#error HEAP_SIZE is not a multiple of four
+#endif
+
 
 /** null for C code */
 #define C_NULL 0
 PmReturn_t pm_vmPeriodic(uint16_t usecsSinceLastCall);
 
 #endif /* __PM_H__ */
+
+
+#ifdef __cplusplus
+}
+#endif
     int16_t length;
 
     /** Array of ptrs to objs */
-    pPmObj_t val[0];
+    pPmObj_t val[1];
 } PmTuple_t,
  *pPmTuple_t;