davide carboni / Mbed 2 deprecated pymite_http_get

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers func.c Source File

func.c

Go to the documentation of this file.
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__ 0x04
00018 
00019 
00020 /**
00021  * \file
00022  * \brief Function Object Type
00023  *
00024  * Function object type operations.
00025  */
00026 
00027 
00028 #include "pm.h"
00029 
00030 
00031 PmReturn_t
00032 func_new(pPmObj_t pco, pPmObj_t pglobals, pPmObj_t *r_pfunc)
00033 {
00034     PmReturn_t retval = PM_RET_OK;
00035     pPmFunc_t pfunc = C_NULL;
00036     uint8_t *pchunk;
00037     pPmObj_t pobj;
00038 
00039     C_ASSERT(OBJ_GET_TYPE(pco) != OBJ_TYPE_COB
00040              || OBJ_GET_TYPE(pco) != OBJ_TYPE_NOB);
00041     C_ASSERT(OBJ_GET_TYPE(pglobals) == OBJ_TYPE_DIC);
00042 
00043     /* Allocate a func obj */
00044     retval = heap_getChunk(sizeof(PmFunc_t), &pchunk);
00045     PM_RETURN_IF_ERROR(retval);
00046     pfunc = (pPmFunc_t)pchunk;
00047 
00048     /* Init func */
00049     OBJ_SET_TYPE(pfunc, OBJ_TYPE_FXN);
00050     pfunc->f_co = (pPmCo_t)pco;
00051 
00052     /* Create attrs dict for regular func (not native) */
00053     if (OBJ_GET_TYPE(pco) == OBJ_TYPE_COB)
00054     {
00055         retval = dict_new(&pobj);
00056         PM_RETURN_IF_ERROR(retval);
00057         pfunc->f_attrs = (pPmDict_t)pobj;
00058 
00059         /* Store the given globals dict */
00060         pfunc->f_globals = (pPmDict_t)pglobals;
00061     }
00062     else
00063     {
00064         pfunc->f_attrs = C_NULL;
00065     }
00066 
00067 #ifdef HAVE_DEFAULTARGS
00068     /* Clear default args (will be set later, if at all) */
00069     pfunc->f_defaultargs = C_NULL;
00070 #endif /* HAVE_DEFAULTARGS */
00071 
00072 #ifdef HAVE_CLOSURES
00073     /* Clear field for closure tuple */
00074     pfunc->f_closure = C_NULL;
00075 #endif /* HAVE_CLOSURES */
00076 
00077     *r_pfunc = (pPmObj_t)pfunc;
00078     return PM_RET_OK;
00079 }