Commits

Anonymous committed bbc8f03

#4: Mainlined directly.

  • Participants
  • Parent commits 24b416e

Comments (0)

Files changed (18)

File src/lib/__bi.py

     }
 
     /* Return object's address as an int on the stack */
+#ifdef TARGET_AVR
+    retval = int_new((S32)(S16)NATIVE_GET_LOCAL(0), &pr);
+#elif defined(TARGET_DESKTOP)
     retval = int_new((S32)NATIVE_GET_LOCAL(0), &pr);
+#else
+#error Code is not implemented for the desired target
+#endif
     NATIVE_SET_TOS(pr);
 
     return retval;
     """__NATIVE__
     PyReturn_t retval;
     pPyClass_t pexn;
+    P_U8 pchunk;
 
     /* Alloc a class object with attributes dict */
-    retval = heap_getChunk(sizeof(PyClass_t), (P_U8 *)&pexn);
+    retval = heap_getChunk(sizeof(PyClass_t), &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    pexn = (pPyClass_t)pchunk;
     pexn->od.od_type = OBJ_TYPE_EXN;
     retval = dict_new((pPyObj_t *)&pexn->cl_attrs);
 

File src/sample/Makefile

 CFLAGS += $(CDEFS) $(CINCS)
 CFLAGS += -O$(OPT)
 CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
-CFLAGS += -Wall -Wstrict-prototypes
+CFLAGS += -Wall -Wstrict-prototypes -Werror
 CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 CFLAGS += $(CSTANDARD)

File src/sample/libmmb103.h

  * Includes
  **************************************************************/
 
-/*
- * The MMB103 uses an Atmel atMega103
- * (this must be before system includes)
- */
-#define  __AVR_ATmega103__
-
 /* avr system headers */
 #ifdef __AVR__
 #include <avr/io.h>

File src/sample/sample.c

     P_U8 pimg;
     pPyObj_t pstring = C_NULL;
     /* ptr to module obj */
-    pPyFunc_t pmod;
+    pPyObj_t pmod;
     /* name of module to run */
     P_U8 modstr = (P_U8)"sample";
     PyReturn_t retval = PY_RET_OK;
     retval = mod_import(pstring, &pmod);
     PY_RETURN_IF_ERROR(retval);
     /* load builtins into root module */
-    retval = global_loadBuiltins(pmod);
+    retval = global_loadBuiltins((pPyFunc_t)pmod);
     PY_RETURN_IF_ERROR(retval);
 
     /* XXX set "__name__" == "__main__" in mod's attrs here? */
 
     /* interpret the module's bcode */
-    retval = interpret(pmod);
+    retval = interpret((pPyFunc_t)pmod);
 
     return retval;
 }

File src/tests/Makefile

 
 PMIMGCREATOR := ../tools/pmImgCreator.py
 DEFS = -DHEAP_SIZE=$(HEAP_SIZE) -DTARGET_$(TARGET)
-CFLAGS = -g -Os -Wall -gstabs -Wstrict-prototypes $(DEFS)
+CFLAGS = -g -Os -Wall -gstabs -Wstrict-prototypes -Werror $(DEFS)
 CFLAGS += -I../vm
 SOURCES = $(wildcard t???.c)
 PY_SOURCES = $(SOURCES:.c=.py)

File src/vm/Makefile

 
 PMIMGCREATOR := ../tools/pmImgCreator.py
 DEFS = -DTARGET_$(TARGET) -DHEAP_SIZE=$(HEAP_SIZE)
-CFLAGS = -g -Os -Wall -gstabs -Wstrict-prototypes $(DEFS)
+CFLAGS = -g -Os -Wall -gstabs -Wstrict-prototypes -Werror $(DEFS)
 ARFLAGS := rcs
 SOURCE_IMG := pmstdlib_img.c
 SOURCE_NAT := pmstdlib_nat.c

File src/vm/codeobj.c

     S8 i;
     pPyObj_t pobj;
     pPyCo_t pco = C_NULL;
+    P_U8 pchunk;
 
     /* store ptr to top of code img (less type byte) */
     P_U8 pci = *paddr - 1;
     U16 size = mem_getWord(memspace, paddr);
 
     /* allocate a code obj */
-    retval = heap_getChunk(sizeof(PyCo_t), (P_U8 *)&pco);
+    retval = heap_getChunk(sizeof(PyCo_t), &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    pco = (pPyCo_t)pchunk;
 
     /* fill in the CO struct */
     pco->od.od_type = OBJ_TYPE_COB;
 {
     PyReturn_t retval = PY_RET_OK;
     pPyNo_t pno = C_NULL;
+    P_U8 pchunk;
 
     /* allocate a code obj */
-    retval = heap_getChunk(sizeof(PyNo_t), (P_U8 *)&pno);
+    retval = heap_getChunk(sizeof(PyNo_t), &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    pno = (pPyNo_t)pchunk;
 
     /* fill in the NO struct */
     pno->od.od_type = OBJ_TYPE_NOB;

File src/vm/frame.c

     pPyCo_t pco = C_NULL;
     pPyFrame_t pframe = C_NULL;
     P_U8 paddr = C_NULL;
+    P_U8 pchunk;
 
     /* get fxn's code obj */
     pco = ((pPyFunc_t)pfunc)->f_co;
     fsize = sizeof(PyFrame_t) + (stacksz + nlocals) *
             sizeof(pPyObj_t);
     /* allocate a frame */
-    retval = heap_getChunk(fsize, (P_U8 *)&pframe);
+    retval = heap_getChunk(fsize, &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    pframe = (pPyFrame_t)pchunk;
 
     /* set frame fields */
     pframe->od.od_type = OBJ_TYPE_FRM;
     pframe->fo_attrs = ((pPyFunc_t)pfunc)->f_attrs;
     /* empty stack points to one past locals */
     pframe->fo_sp = &(pframe->fo_locals[nlocals]);
-    
+
     /* return ptr to frame */
     * r_pobj = (pPyObj_t)pframe;
     return retval;

File src/vm/func.c

 {
     PyReturn_t retval = PY_RET_OK;
     pPyFunc_t pfunc = C_NULL;
+    P_U8 pchunk;
 
     /* ensure pco pts to code obj or native obj */
     if ((pco->od.od_type != OBJ_TYPE_COB) &&
     }
 
     /* allocate a func obj */
-    retval = heap_getChunk(sizeof(PyFunc_t), (P_U8 *)&pfunc);
+    retval = heap_getChunk(sizeof(PyFunc_t), &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    pfunc = (pPyFunc_t)pchunk;
 
     /* init func */
     pfunc->od.od_type = OBJ_TYPE_FXN;

File src/vm/global.c

     P_U8 bistr = (P_U8)"__bi";
     P_U8 nonestr = (P_U8)"None";
     pPyObj_t pstr = C_NULL;
-    pPyFunc_t pbimod = C_NULL;
+    pPyObj_t pbimod;
 
     /* import the builtins */
     retval = string_new(&bistr, &pstr);
     PY_RETURN_IF_ERROR(retval);
 
     /* must interpret builtins' root code to set the attrs */
-    retval = interpret(pbimod);
+    retval = interpret((pPyFunc_t)pbimod);
     PY_RETURN_IF_ERROR(retval);
 
     /* reset interpreter to run */
     gVmGlobal.interpctrl = INTERP_CTRL_CONT;
 
     /* builtins points to the builtins module's attrs dict */
-    gVmGlobal.builtins = pbimod->f_attrs;
+    gVmGlobal.builtins = ((pPyFunc_t)pbimod)->f_attrs;
 
     /* set None manually */
     retval = string_new(&nonestr, &pkey);

File src/vm/img.c

     S8 n = 0;
     pPyImgInfo_t pii = C_NULL;
     pPyObj_t pnamestr = C_NULL;
+    P_U8 pchunk;
 
     /* addr is top of img */
     imgtop = *paddr;
     {
         /* use size field to calc addr of next potential img */
         size = mem_getWord(memspace, paddr);
-        
+
         /* get name of img */
         /* point to names tuple */
         *paddr = imgtop + CI_NAMES_FIELD;
         PY_RETURN_IF_ERROR(retval);
 
         /* alloc and fill imginfo struct */
-        retval = heap_getChunk(sizeof(PyImgInfo_t), (P_U8 *)&pii);
+        retval = heap_getChunk(sizeof(PyImgInfo_t), &pchunk);
         PY_RETURN_IF_ERROR(retval);
+        pii = (pPyImgInfo_t)pchunk;
         pii->ii_name = (pPyString_t)pnamestr;
         pii->ii_memspace = memspace;
         pii->ii_addr = imgtop;
 {
     PyType_t type;
     U8 b;
-    
+
     /* XXX ensure it's a tuple */
     /* skip past type and size bytes */
     *paddr += 2;
     {
         return PY_RET_EX_TYPE;
     }
-    
+
     /* backtrack paddr to point to top of string img */
     (*paddr)--;
     /* return name string obj */

File src/vm/interp.c

     pPyFrame_t pframe = C_NULL; /* tmp: until thread contains fp */
 
     /* create a frame for the func */
-    retval = frame_new((pPyObj_t)pfunc, (pPyObj_t *)&FP);
+    retval = frame_new((pPyObj_t)pfunc, &pobj1);
     PY_RETURN_IF_ERROR(retval);
+    FP = (pPyFrame_t)pobj1;
 
     /*
      * set globals dict to same as root frame's attrs.
                 pobj1 = FP->fo_func->f_co->co_names->val[t16];
                 /* XXX check if module is already loaded */
                 /* load module from image */
-                retval = mod_import(pobj1, (pPyFunc_t *)&pobj2);
+                retval = mod_import(pobj1, &pobj2);
                 PY_BREAK_IF_ERROR(retval);
                 /* module overwrites None on stack */
                 TOS = pobj2;
                 break;
 
             case SETUP_LOOP:
+            {
+                P_U8 pchunk;
+
                 /* get block span (bytes) */
                 t16 = GET_ARG();
                 /* create block */
-                retval = heap_getChunk(sizeof(PyBlock_t), (P_U8 *)&pobj1);
+                retval = heap_getChunk(sizeof(PyBlock_t), &pchunk);
                 PY_BREAK_IF_ERROR(retval);
+                pobj1 = (pPyObj_t)pchunk;
                 ((pPyBlock_t)pobj1)->od.od_type = OBJ_TYPE_BLK;
                 /* store current stack pointer */
                 ((pPyBlock_t)pobj1)->b_sp = SP;
                 ((pPyBlock_t)pobj1)->next = FP->fo_blockstack;
                 FP->fo_blockstack = (pPyBlock_t)pobj1;
                 continue;
+            }
 
             case SETUP_EXCEPT:
             case SETUP_FINALLY:

File src/vm/module.c

  **************************************************************/
 
 PyReturn_t
-mod_new(pPyCo_t pco, pPyFunc_t * pmod)
+mod_new(pPyObj_t pco, pPyObj_t * pmod)
 {
-    PyReturn_t retval = PY_RET_OK;
+    PyReturn_t retval;
+    P_U8 pchunk;
 
-    /* XXX ensure pco pts to code obj? */
+    /* if it's not a code obj, raise TypeError */
+    if (pco->od.od_type != OBJ_TYPE_COB)
+    {
+        return PY_RET_EX_TYPE;
+    }
 
     /* alloc and init func obj */
-    retval = heap_getChunk(sizeof(PyFunc_t), (P_U8 *)pmod);
+    retval = heap_getChunk(sizeof(PyFunc_t), &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    *pmod = (pPyObj_t)pchunk;
     (*pmod)->od.od_type = OBJ_TYPE_MOD;
-    (*pmod)->f_co = pco;
+    ((pPyFunc_t)*pmod)->f_co = (pPyCo_t)pco;
 
     /* alloc and init attrs dict */
-    retval = dict_new((pPyObj_t *)&((*pmod)->f_attrs));
+    retval = dict_new((pPyObj_t *)&((pPyFunc_t)*pmod)->f_attrs);
     return retval;
 }
 
 
 PyReturn_t
-mod_import(pPyObj_t pstr, pPyFunc_t * pmod)
+mod_import(pPyObj_t pstr, pPyObj_t * pmod)
 {
     pPyImgInfo_t pii = C_NULL;
     P_U8 imgaddr = C_NULL;
     pPyCo_t pco = C_NULL;
     PyReturn_t retval = PY_RET_OK;
+    pPyObj_t pobj;
 
-    /* if it's not a string obj, raise SystemError */
+    /* if it's not a string obj, raise SyntaxError */
     if (pstr->od.od_type != OBJ_TYPE_STR)
     {
-        return PY_RET_EX_SYS;
+        return PY_RET_EX_SYNTAX;
     }
 
     /* iterate through the global img list */
     imgaddr = pii->ii_addr;
 
     /* load img into code obj */
-    retval = obj_loadFromImg(pii->ii_memspace, &imgaddr, (pPyObj_t *)&pco);
+    retval = obj_loadFromImg(pii->ii_memspace, &imgaddr, &pobj);
     PY_RETURN_IF_ERROR(retval);
+    pco = (pPyCo_t)pobj;
 
-    return mod_new(pco, pmod);
+    return mod_new((pPyObj_t)pco, pmod);
 }
 
 

File src/vm/module.h

  * @param   return parameter; ptr to new module obj
  * @return  return status
  */
-PyReturn_t mod_new(pPyCo_t pco, pPyFunc_t * pmod);
+PyReturn_t mod_new(pPyObj_t pco, pPyObj_t * pmod);
 
 /**
  * Import a module of the given name.
  * @param   return parameter; ptr to imported module
  * @return  return status
  */
-PyReturn_t mod_import(pPyObj_t pstr, pPyFunc_t * pmod);
+PyReturn_t mod_import(pPyObj_t pstr, pPyObj_t * pmod);
 
 #endif /* __MODULE_H__ */
 PyReturn_t pm_run(P_U8 modstr)
 {
     PyReturn_t retval;
-    pPyFunc_t pmod;
+    pPyObj_t pmod;
     pPyObj_t pstring;
     P_U8 pmodstr = modstr;
 
     PY_RETURN_IF_ERROR(retval);
 
     /* Load builtins into root module */
-    retval = global_loadBuiltins(pmod);
+    retval = global_loadBuiltins((pPyFunc_t)pmod);
     PY_RETURN_IF_ERROR(retval);
 
     /* Interpret the module's bcode */
-    retval = interpret(pmod);
+    retval = interpret((pPyFunc_t)pmod);
 
     return retval;
 }

File src/vm/seglist.c

  * to the last segment in the list.
  * The function seglist_appendItem() should be used to append
  * items to the List.
- * Inserting and deleting List items is a more complicated 
+ * Inserting and deleting List items is a more complicated
  * matter.
  *
  * Dict implementation:
  * Macros
  **************************************************************/
 
-/** 
+/**
  * Set this to 1 if seglist_clear() should manually free its segments.
  * Set this to 0 if seglist_clear() should do nothing
- * and let the GC reclaim objects. 
+ * and let the GC reclaim objects.
  */
 #define SEGLIST_CLEAR_SEGMENTS 1
 
     PyReturn_t retval = PY_RET_OK;
     pSegment_t pseg = C_NULL;
     U8 i = 0;
+    P_U8 pchunk;
 
     /* if this is first item in seg, alloc and link seg */
     if (pseglist->sl_lastindx == 0)
     {
         /* alloc and init new segment */
-        retval = heap_getChunk(sizeof(Segment_t), (P_U8 *)&pseg);
+        retval = heap_getChunk(sizeof(Segment_t), &pchunk);
         PY_RETURN_IF_ERROR(retval);
+        pseg = (pSegment_t)pchunk;
         pseg->od.od_type = OBJ_TYPE_SEG;
         for (i = 1; i < SEGLIST_OBJS_PER_SEG; i++)
         {
 
     /* put object into segment */
     pseg->s_val[pseglist->sl_lastindx] = pobj;
-    
+
     /* increment last index and reset if necessary */
     if (++(pseglist->sl_lastindx) >= SEGLIST_OBJS_PER_SEG)
     {
         /* seglist refers to the new segment */
         pseglist->sl_lastseg = pseglist->sl_rootseg;
         pseglist->sl_lastindx = 0;
-        
+
         /* if past end of list */
         if ((segnum != 0) || (segindx != 0))
         {
         pseglist->sl_lastindx++;
         return PY_RET_OK;
     }
-        
+
     /* else, iterate until pseg pts to segnum'th segment */
     for (pseg = pseglist->sl_rootseg; segnum > 0; segnum--)
     {
         pseg = pseg->next;
 
         /* if ran past end of list */
-        /* XXX what about inserting several indices past end? 
+        /* XXX what about inserting several indices past end?
          * Not knowing the numSegs in the seglist is a reason to dislike seglists.
          */
         if (pseg == C_NULL)
             {
                 retval = heap_getChunk(sizeof(Segment_t),
                                        (P_U8 *)&pseg->next);
-                /* 
+                /*
                  * XXX exception with hosed list,
                  * need to roll-back!
                  */

File src/vm/string.c

 #if USE_STRING_CACHE
     pPyString_t pcacheentry = C_NULL;
 #endif /* USE_STRING_CACHE */
+    P_U8 pchunk;
 
     /* if not loading from image */
     if (isimg == 0)
     }
 
     /* get space for String obj */
-    retval = heap_getChunk(sizeof(PyString_t) + len, (P_U8 *)&pstr);
+    retval = heap_getChunk(sizeof(PyString_t) + len, &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    pstr = (pPyString_t)pchunk;
 
     /* fill the string obj */
     pstr->od.od_type = OBJ_TYPE_STR;
 #if USE_STRING_CACHE
     pPyString_t pcacheentry = C_NULL;
 #endif /* USE_STRING_CACHE */
+    P_U8 pchunk;
 
     /* Get space for String obj */
-    retval = heap_getChunk(sizeof(PyString_t) + 1, (P_U8 *)&pstr);
+    retval = heap_getChunk(sizeof(PyString_t) + 1, &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    pstr = (pPyString_t)pchunk;
 
     /* Fill the string obj */
     pstr->od.od_type = OBJ_TYPE_STR;
 {
     PyReturn_t retval = PY_RET_OK;
     pPyString_t pnew = C_NULL;
+    P_U8 pchunk;
 
     /* ensure string obj */
     if (pstr->od.od_type != OBJ_TYPE_STR)
 
     /* allocate string obj */
     retval = heap_getChunk(sizeof(PyString_t) + ((pPyString_t)pstr)->length,
-                           (P_U8 *)&pnew
+                           &pchunk
                           );
-    /* XXX handle retval */
+    PY_RETURN_IF_ERROR(retval);
+    pnew = (pPyString_t)pchunk;
     pnew->od.od_const = 0;
     pnew->od.od_type = OBJ_TYPE_STR;
 #if USE_STRING_CACHE

File src/vm/tuple.c

 {
     PyReturn_t retval = PY_RET_OK;
     pPyTuple_t pnew = C_NULL;
+    P_U8 pchunk;
+    P_U8 pdest;
+    P_U8 psrc;
 
     /* ensure type */
     if (ptup->od.od_type != OBJ_TYPE_TUP)
     }
 
     /* duplicate src tuple */
-    retval = heap_getChunk(ptup->od.od_size, (P_U8 *)&pnew);
+    retval = heap_getChunk(ptup->od.od_size, &pchunk);
     PY_RETURN_IF_ERROR(retval);
+    pnew = (pPyTuple_t)pchunk;
 
-    mem_copy(MEMSPACE_RAM, (P_U8 *)&pnew, (P_U8 *)&ptup, ptup->od.od_size);
+    pdest = (P_U8)pnew;
+    psrc = (P_U8)ptup;
+    mem_copy(MEMSPACE_RAM, &pdest, &psrc, ptup->od.od_size);
     *r_ptuple = (pPyObj_t)pnew;
     return PY_RET_OK;
 }