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.
Fork of pymite by
func.c
00001 /* 00002 # This file is Copyright 2002 Dean Hall. 00003 # This file is part of the PyMite VM. 00004 # This file is licensed under the MIT License. 00005 # See the LICENSE file for details. 00006 */ 00007 00008 00009 #undef __FILE_ID__ 00010 #define __FILE_ID__ 0x04 00011 00012 00013 /** 00014 * \file 00015 * \brief Function Object Type 00016 * 00017 * Function object type operations. 00018 */ 00019 00020 00021 #include "pm.h" 00022 00023 00024 PmReturn_t 00025 func_new(pPmObj_t pco, pPmObj_t pglobals, pPmObj_t *r_pfunc) 00026 { 00027 PmReturn_t retval = PM_RET_OK; 00028 pPmFunc_t pfunc = C_NULL; 00029 uint8_t *pchunk; 00030 pPmObj_t pobj; 00031 uint8_t objid; 00032 00033 C_ASSERT(OBJ_GET_TYPE(pco) != OBJ_TYPE_COB 00034 || OBJ_GET_TYPE(pco) != OBJ_TYPE_NOB); 00035 C_ASSERT(OBJ_GET_TYPE(pglobals) == OBJ_TYPE_DIC); 00036 00037 /* Allocate a func obj */ 00038 retval = heap_getChunk(sizeof(PmFunc_t), &pchunk); 00039 PM_RETURN_IF_ERROR(retval); 00040 pfunc = (pPmFunc_t)pchunk; 00041 00042 /* Init func */ 00043 OBJ_SET_TYPE(pfunc, OBJ_TYPE_FXN); 00044 pfunc->f_co = (pPmCo_t)pco; 00045 pfunc->f_globals = C_NULL; 00046 pfunc->f_attrs = C_NULL; 00047 00048 #ifdef HAVE_DEFAULTARGS 00049 /* Clear default args (will be set later, if at all) */ 00050 pfunc->f_defaultargs = C_NULL; 00051 #endif /* HAVE_DEFAULTARGS */ 00052 00053 #ifdef HAVE_CLOSURES 00054 /* Clear field for closure tuple */ 00055 pfunc->f_closure = C_NULL; 00056 #endif /* HAVE_CLOSURES */ 00057 00058 /* Create attrs dict for regular func (not native) */ 00059 if (OBJ_GET_TYPE(pco) == OBJ_TYPE_COB) 00060 { 00061 heap_gcPushTempRoot((pPmObj_t)pfunc, &objid); 00062 retval = dict_new(&pobj); 00063 heap_gcPopTempRoot(objid); 00064 PM_RETURN_IF_ERROR(retval); 00065 pfunc->f_attrs = (pPmDict_t)pobj; 00066 00067 /* Store the given globals dict */ 00068 pfunc->f_globals = (pPmDict_t)pglobals; 00069 } 00070 00071 *r_pfunc = (pPmObj_t)pfunc; 00072 return PM_RET_OK; 00073 }
Generated on Tue Jul 12 2022 21:25:46 by
1.7.2
