2 # This file is Copyright 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.
17 #define __FILE_ID__ 0x16
24 * Encapsulating a frame pointer, a root code object and thread state.
32 thread_new(pPmObj_t pframe
, pPmObj_t
*r_pobj
)
34 PmReturn_t retval
= PM_RET_OK
;
35 pPmThread_t pthread
= C_NULL
;
37 C_ASSERT(pframe
!= C_NULL
);
39 /* If it's not a frame, raise TypeError */
40 if (OBJ_GET_TYPE(pframe
) != OBJ_TYPE_FRM
)
42 PM_RAISE(retval
, PM_RET_EX_TYPE
);
46 /* Allocate a thread */
47 retval
= heap_getChunk(sizeof(PmThread_t
), (uint8_t **)r_pobj
);
48 PM_RETURN_IF_ERROR(retval
);
50 /* Set type, frame and initialize status */
51 pthread
= (pPmThread_t
)*r_pobj
;
52 OBJ_SET_TYPE(pthread
, OBJ_TYPE_THR
);
53 pthread
->pframe
= (pPmFrame_t
)pframe
;
54 pthread
->interpctrl
= INTERP_CTRL_CONT
;