Norimasa Okamoto
/
pymite
python-on-a-chip online compiler
- http://pymbed.appspot.com/
- https://code.google.com/p/python-on-a-chip/
- http://www.youtube.com/watch?v=Oyqc2bFRW9I
- https://bitbucket.org/va009039/pymbed/
more info: python-on-a-chip
vm/func.c@15:94ca5c8003e5, 2016-04-14 (annotated)
- Committer:
- va009039
- Date:
- Thu Apr 14 22:32:57 2016 +0000
- Revision:
- 15:94ca5c8003e5
- Parent:
- 0:65f1469d6bfb
update Nucleo-F401RE.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:65f1469d6bfb | 1 | /* |
va009039 | 0:65f1469d6bfb | 2 | # This file is Copyright 2002 Dean Hall. |
va009039 | 0:65f1469d6bfb | 3 | # This file is part of the PyMite VM. |
va009039 | 0:65f1469d6bfb | 4 | # This file is licensed under the MIT License. |
va009039 | 0:65f1469d6bfb | 5 | # See the LICENSE file for details. |
va009039 | 0:65f1469d6bfb | 6 | */ |
va009039 | 0:65f1469d6bfb | 7 | |
va009039 | 0:65f1469d6bfb | 8 | |
va009039 | 0:65f1469d6bfb | 9 | #undef __FILE_ID__ |
va009039 | 0:65f1469d6bfb | 10 | #define __FILE_ID__ 0x04 |
va009039 | 0:65f1469d6bfb | 11 | |
va009039 | 0:65f1469d6bfb | 12 | |
va009039 | 0:65f1469d6bfb | 13 | /** |
va009039 | 0:65f1469d6bfb | 14 | * \file |
va009039 | 0:65f1469d6bfb | 15 | * \brief Function Object Type |
va009039 | 0:65f1469d6bfb | 16 | * |
va009039 | 0:65f1469d6bfb | 17 | * Function object type operations. |
va009039 | 0:65f1469d6bfb | 18 | */ |
va009039 | 0:65f1469d6bfb | 19 | |
va009039 | 0:65f1469d6bfb | 20 | |
va009039 | 0:65f1469d6bfb | 21 | #include "pm.h" |
va009039 | 0:65f1469d6bfb | 22 | |
va009039 | 0:65f1469d6bfb | 23 | |
va009039 | 0:65f1469d6bfb | 24 | PmReturn_t |
va009039 | 0:65f1469d6bfb | 25 | func_new(pPmObj_t pco, pPmObj_t pglobals, pPmObj_t *r_pfunc) |
va009039 | 0:65f1469d6bfb | 26 | { |
va009039 | 0:65f1469d6bfb | 27 | PmReturn_t retval = PM_RET_OK; |
va009039 | 0:65f1469d6bfb | 28 | pPmFunc_t pfunc = C_NULL; |
va009039 | 0:65f1469d6bfb | 29 | uint8_t *pchunk; |
va009039 | 0:65f1469d6bfb | 30 | pPmObj_t pobj; |
va009039 | 0:65f1469d6bfb | 31 | uint8_t objid; |
va009039 | 0:65f1469d6bfb | 32 | |
va009039 | 0:65f1469d6bfb | 33 | C_ASSERT(OBJ_GET_TYPE(pco) != OBJ_TYPE_COB |
va009039 | 0:65f1469d6bfb | 34 | || OBJ_GET_TYPE(pco) != OBJ_TYPE_NOB); |
va009039 | 0:65f1469d6bfb | 35 | C_ASSERT(OBJ_GET_TYPE(pglobals) == OBJ_TYPE_DIC); |
va009039 | 0:65f1469d6bfb | 36 | |
va009039 | 0:65f1469d6bfb | 37 | /* Allocate a func obj */ |
va009039 | 0:65f1469d6bfb | 38 | retval = heap_getChunk(sizeof(PmFunc_t), &pchunk); |
va009039 | 0:65f1469d6bfb | 39 | PM_RETURN_IF_ERROR(retval); |
va009039 | 0:65f1469d6bfb | 40 | pfunc = (pPmFunc_t)pchunk; |
va009039 | 0:65f1469d6bfb | 41 | |
va009039 | 0:65f1469d6bfb | 42 | /* Init func */ |
va009039 | 0:65f1469d6bfb | 43 | OBJ_SET_TYPE(pfunc, OBJ_TYPE_FXN); |
va009039 | 0:65f1469d6bfb | 44 | pfunc->f_co = (pPmCo_t)pco; |
va009039 | 0:65f1469d6bfb | 45 | pfunc->f_globals = C_NULL; |
va009039 | 0:65f1469d6bfb | 46 | pfunc->f_attrs = C_NULL; |
va009039 | 0:65f1469d6bfb | 47 | |
va009039 | 0:65f1469d6bfb | 48 | #ifdef HAVE_DEFAULTARGS |
va009039 | 0:65f1469d6bfb | 49 | /* Clear default args (will be set later, if at all) */ |
va009039 | 0:65f1469d6bfb | 50 | pfunc->f_defaultargs = C_NULL; |
va009039 | 0:65f1469d6bfb | 51 | #endif /* HAVE_DEFAULTARGS */ |
va009039 | 0:65f1469d6bfb | 52 | |
va009039 | 0:65f1469d6bfb | 53 | #ifdef HAVE_CLOSURES |
va009039 | 0:65f1469d6bfb | 54 | /* Clear field for closure tuple */ |
va009039 | 0:65f1469d6bfb | 55 | pfunc->f_closure = C_NULL; |
va009039 | 0:65f1469d6bfb | 56 | #endif /* HAVE_CLOSURES */ |
va009039 | 0:65f1469d6bfb | 57 | |
va009039 | 0:65f1469d6bfb | 58 | /* Create attrs dict for regular func (not native) */ |
va009039 | 0:65f1469d6bfb | 59 | if (OBJ_GET_TYPE(pco) == OBJ_TYPE_COB) |
va009039 | 0:65f1469d6bfb | 60 | { |
va009039 | 0:65f1469d6bfb | 61 | heap_gcPushTempRoot((pPmObj_t)pfunc, &objid); |
va009039 | 0:65f1469d6bfb | 62 | retval = dict_new(&pobj); |
va009039 | 0:65f1469d6bfb | 63 | heap_gcPopTempRoot(objid); |
va009039 | 0:65f1469d6bfb | 64 | PM_RETURN_IF_ERROR(retval); |
va009039 | 0:65f1469d6bfb | 65 | pfunc->f_attrs = (pPmDict_t)pobj; |
va009039 | 0:65f1469d6bfb | 66 | |
va009039 | 0:65f1469d6bfb | 67 | /* Store the given globals dict */ |
va009039 | 0:65f1469d6bfb | 68 | pfunc->f_globals = (pPmDict_t)pglobals; |
va009039 | 0:65f1469d6bfb | 69 | } |
va009039 | 0:65f1469d6bfb | 70 | |
va009039 | 0:65f1469d6bfb | 71 | *r_pfunc = (pPmObj_t)pfunc; |
va009039 | 0:65f1469d6bfb | 72 | return PM_RET_OK; |
va009039 | 0:65f1469d6bfb | 73 | } |