00001 /* 00002 # This file is Copyright 2007, 2009, 2010 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__ 0x16 00018 00019 00028 #include "pm.h" 00029 00030 00031 PmReturn_t 00032 thread_new(pPmObj_t pframe, pPmObj_t *r_pobj) 00033 { 00034 PmReturn_t retval = PM_RET_OK; 00035 pPmThread_t pthread = C_NULL; 00036 00037 C_ASSERT(pframe != C_NULL); 00038 00039 /* If it's not a frame, raise TypeError */ 00040 if (OBJ_GET_TYPE(pframe) != OBJ_TYPE_FRM) 00041 { 00042 PM_RAISE(retval, PM_RET_EX_TYPE); 00043 return retval; 00044 } 00045 00046 /* Allocate a thread */ 00047 retval = heap_getChunk(sizeof(PmThread_t), (uint8_t **)r_pobj); 00048 PM_RETURN_IF_ERROR(retval); 00049 00050 /* Set type, frame and initialize status */ 00051 pthread = (pPmThread_t)*r_pobj; 00052 OBJ_SET_TYPE(pthread, OBJ_TYPE_THR); 00053 pthread->pframe = (pPmFrame_t)pframe; 00054 pthread->interpctrl = INTERP_CTRL_CONT; 00055 00056 return retval; 00057 }