Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
codeobj.c
00001 /* 00002 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall. 00003 # 00004 # This file is part of the PyMite VM. 00005 # The PyMite VM is free software: you can redistribute it and/or modify 00006 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2. 00007 # 00008 # The PyMite VM is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00011 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2 00012 # is seen in the file COPYING in this directory. 00013 */ 00014 00015 00016 #undef __FILE_ID__ 00017 #define __FILE_ID__ 0x01 00018 00019 00020 /** 00021 * \file 00022 * \brief CodeObj Type 00023 * 00024 * CodeObj type operations. 00025 */ 00026 00027 00028 #include "pm.h" 00029 00030 00031 PmReturn_t 00032 co_loadFromImg(PmMemSpace_t memspace, uint8_t const **paddr, pPmObj_t *r_pco) 00033 { 00034 PmReturn_t retval = PM_RET_OK; 00035 pPmObj_t pobj; 00036 pPmCo_t pco = C_NULL; 00037 uint8_t *pchunk; 00038 00039 /* Store ptr to top of code img (less type byte) */ 00040 uint8_t const *pci = *paddr - 1; 00041 00042 /* Get size of code img */ 00043 uint16_t size = mem_getWord(memspace, paddr); 00044 00045 /* Allocate a code obj */ 00046 retval = heap_getChunk(sizeof(PmCo_t), &pchunk); 00047 PM_RETURN_IF_ERROR(retval); 00048 pco = (pPmCo_t)pchunk; 00049 00050 /* Fill in the CO struct */ 00051 OBJ_SET_TYPE(pco, OBJ_TYPE_COB); 00052 pco->co_memspace = memspace; 00053 pco->co_codeimgaddr = pci; 00054 pco->co_argcount = mem_getByte(memspace, paddr);; 00055 pco->co_flags = mem_getByte(memspace, paddr);; 00056 00057 #ifdef HAVE_CLOSURES 00058 /* Get number of local and free variables */ 00059 *paddr = pci + CI_NLOCALS_FIELD; 00060 pco->co_nlocals = mem_getByte(memspace, paddr); 00061 pco->co_nfreevars = mem_getByte(memspace, paddr); 00062 #else 00063 *paddr = pci + CI_NAMES_FIELD; 00064 #endif /* HAVE_CLOSURES */ 00065 00066 /* Load names (tuple obj) */ 00067 retval = obj_loadFromImg(memspace, paddr, &pobj); 00068 PM_RETURN_IF_ERROR(retval); 00069 pco->co_names = (pPmTuple_t)pobj; 00070 00071 /* Load consts (tuple obj) assume it follows names */ 00072 retval = obj_loadFromImg(memspace, paddr, &pobj); 00073 PM_RETURN_IF_ERROR(retval); 00074 pco->co_consts = (pPmTuple_t)pobj; 00075 00076 #ifdef HAVE_CLOSURES 00077 retval = obj_loadFromImg(memspace, paddr, &pobj); 00078 PM_RETURN_IF_ERROR(retval); 00079 00080 /* Save RAM, don't keep empty tuple */ 00081 if (((pPmTuple_t)pobj)->length == 0) 00082 { 00083 heap_freeChunk(pobj); 00084 pco->co_cellvars = C_NULL; 00085 } 00086 else 00087 { 00088 pco->co_cellvars = (pPmTuple_t)pobj; 00089 } 00090 #endif /* HAVE_CLOSURES */ 00091 00092 /* Start of bcode always follows consts */ 00093 pco->co_codeaddr = *paddr; 00094 00095 /* Set addr to point one past end of img */ 00096 *paddr = pci + size; 00097 00098 *r_pco = (pPmObj_t)pco; 00099 return PM_RET_OK; 00100 } 00101 00102 00103 PmReturn_t 00104 no_loadFromImg(PmMemSpace_t memspace, uint8_t const **paddr, pPmObj_t *r_pno) 00105 { 00106 PmReturn_t retval = PM_RET_OK; 00107 pPmNo_t pno = C_NULL; 00108 uint8_t *pchunk; 00109 00110 /* Allocate a code obj */ 00111 retval = heap_getChunk(sizeof(PmNo_t), &pchunk); 00112 PM_RETURN_IF_ERROR(retval); 00113 pno = (pPmNo_t)pchunk; 00114 00115 /* Fill in the NO struct */ 00116 OBJ_SET_TYPE(pno, OBJ_TYPE_NOB); 00117 pno->no_argcount = mem_getByte(memspace, paddr); 00118 00119 /* Get index into native fxn table */ 00120 pno->no_funcindx = (int16_t)mem_getWord(memspace, paddr); 00121 00122 *r_pno = (pPmObj_t)pno; 00123 return PM_RET_OK; 00124 }
Generated on Tue Jul 12 2022 17:07:01 by
1.7.2