LP-295: uncrustify
[librepilot.git] / flight / libraries / PyMite / vm / func.c
blob0112c1e185eacfd4ca85ff425ee0ff6da19456b6
1 /*
2 # This file is Copyright 2003, 2006, 2007, 2009, 2010 Dean Hall.
4 # This file is part of the PyMite VM.
5 # The PyMite VM is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2.
8 # The PyMite VM is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2
12 # is seen in the file COPYING in this directory.
16 #undef __FILE_ID__
17 #define __FILE_ID__ 0x04
20 /**
21 * \file
22 * \brief Function Object Type
24 * Function object type operations.
28 #include "pm.h"
31 PmReturn_t
32 func_new(pPmObj_t pco, pPmObj_t pglobals, pPmObj_t *r_pfunc)
34 PmReturn_t retval = PM_RET_OK;
35 pPmFunc_t pfunc = C_NULL;
36 uint8_t *pchunk;
37 pPmObj_t pobj;
38 uint8_t objid;
40 C_ASSERT(OBJ_GET_TYPE(pco) != OBJ_TYPE_COB
41 || OBJ_GET_TYPE(pco) != OBJ_TYPE_NOB);
42 C_ASSERT(OBJ_GET_TYPE(pglobals) == OBJ_TYPE_DIC);
44 /* Allocate a func obj */
45 retval = heap_getChunk(sizeof(PmFunc_t), &pchunk);
46 PM_RETURN_IF_ERROR(retval);
47 pfunc = (pPmFunc_t)pchunk;
49 /* Init func */
50 OBJ_SET_TYPE(pfunc, OBJ_TYPE_FXN);
51 pfunc->f_co = (pPmCo_t)pco;
52 pfunc->f_globals = C_NULL;
54 #ifdef HAVE_DEFAULTARGS
55 /* Clear default args (will be set later, if at all) */
56 pfunc->f_defaultargs = C_NULL;
57 #endif /* HAVE_DEFAULTARGS */
59 #ifdef HAVE_CLOSURES
60 /* Clear field for closure tuple */
61 pfunc->f_closure = C_NULL;
62 #endif /* HAVE_CLOSURES */
64 /* Create attrs dict for regular func (not native) */
65 if (OBJ_GET_TYPE(pco) == OBJ_TYPE_COB)
67 heap_gcPushTempRoot((pPmObj_t)pfunc, &objid);
68 retval = dict_new(&pobj);
69 heap_gcPopTempRoot(objid);
70 PM_RETURN_IF_ERROR(retval);
71 pfunc->f_attrs = (pPmDict_t)pobj;
73 /* Store the given globals dict */
74 pfunc->f_globals = (pPmDict_t)pglobals;
76 else
78 pfunc->f_attrs = C_NULL;
81 *r_pfunc = (pPmObj_t)pfunc;
82 return PM_RET_OK;