python-on-a-chip online compiler

Dependencies:   mbed TSI

/media/uploads/va009039/p14p-f446re.png

more info: python-on-a-chip

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?

UserRevisionLine numberNew 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 #ifndef __HEAP_H__
va009039 0:65f1469d6bfb 10 #define __HEAP_H__
va009039 0:65f1469d6bfb 11
va009039 0:65f1469d6bfb 12
va009039 0:65f1469d6bfb 13 /**
va009039 0:65f1469d6bfb 14 * \file
va009039 0:65f1469d6bfb 15 * \brief VM Heap
va009039 0:65f1469d6bfb 16 *
va009039 0:65f1469d6bfb 17 * VM heap header.
va009039 0:65f1469d6bfb 18 */
va009039 0:65f1469d6bfb 19
va009039 0:65f1469d6bfb 20
va009039 0:65f1469d6bfb 21 /**
va009039 0:65f1469d6bfb 22 * The threshold of heap.avail under which the interpreter will run the GC
va009039 0:65f1469d6bfb 23 * just before starting a native session.
va009039 0:65f1469d6bfb 24 */
va009039 0:65f1469d6bfb 25 #define HEAP_GC_NF_THRESHOLD (512)
va009039 0:65f1469d6bfb 26
va009039 0:65f1469d6bfb 27
va009039 0:65f1469d6bfb 28 #ifdef __DEBUG__
va009039 0:65f1469d6bfb 29 #define DEBUG_PRINT_HEAP_AVAIL(s) \
va009039 0:65f1469d6bfb 30 do { uint16_t n; heap_getAvail(&n); printf(s "heap avail = %d\n", n); } \
va009039 0:65f1469d6bfb 31 while (0)
va009039 0:65f1469d6bfb 32 #else
va009039 0:65f1469d6bfb 33 #define DEBUG_PRINT_HEAP_AVAIL(s)
va009039 0:65f1469d6bfb 34 #endif
va009039 0:65f1469d6bfb 35
va009039 0:65f1469d6bfb 36
va009039 0:65f1469d6bfb 37 /**
va009039 0:65f1469d6bfb 38 * Initializes the heap for use.
va009039 0:65f1469d6bfb 39 *
va009039 0:65f1469d6bfb 40 * @param base The address where the contiguous heap begins
va009039 0:65f1469d6bfb 41 * @param size The size in bytes (octets) of the given heap.
va009039 0:65f1469d6bfb 42 * @return Return code.
va009039 0:65f1469d6bfb 43 */
va009039 0:65f1469d6bfb 44 PmReturn_t heap_init(uint8_t *base, uint32_t size);
va009039 0:65f1469d6bfb 45
va009039 0:65f1469d6bfb 46 /**
va009039 0:65f1469d6bfb 47 * Returns a free chunk from the heap.
va009039 0:65f1469d6bfb 48 *
va009039 0:65f1469d6bfb 49 * The chunk will be at least the requested size.
va009039 0:65f1469d6bfb 50 * The actual size can be found in the return chunk's od.od_size.
va009039 0:65f1469d6bfb 51 *
va009039 0:65f1469d6bfb 52 * @param requestedsize Requested size of the chunk in bytes.
va009039 0:65f1469d6bfb 53 * @param r_pchunk Addr of ptr to chunk (return).
va009039 0:65f1469d6bfb 54 * @return Return code
va009039 0:65f1469d6bfb 55 */
va009039 0:65f1469d6bfb 56 PmReturn_t heap_getChunk(uint16_t requestedsize, uint8_t **r_pchunk);
va009039 0:65f1469d6bfb 57
va009039 0:65f1469d6bfb 58 /**
va009039 0:65f1469d6bfb 59 * Places the chunk back in the heap.
va009039 0:65f1469d6bfb 60 *
va009039 0:65f1469d6bfb 61 * @param ptr Pointer to object to free.
va009039 0:65f1469d6bfb 62 */
va009039 0:65f1469d6bfb 63 PmReturn_t heap_freeChunk(pPmObj_t ptr);
va009039 0:65f1469d6bfb 64
va009039 0:65f1469d6bfb 65 /** @return Return number of bytes available in the heap */
va009039 0:65f1469d6bfb 66 uint32_t heap_getAvail(void);
va009039 0:65f1469d6bfb 67
va009039 0:65f1469d6bfb 68 /** @return Return the size of the heap in bytes */
va009039 0:65f1469d6bfb 69 uint32_t heap_getSize(void);
va009039 0:65f1469d6bfb 70
va009039 0:65f1469d6bfb 71 #ifdef HAVE_GC
va009039 0:65f1469d6bfb 72 /**
va009039 0:65f1469d6bfb 73 * Runs the mark-sweep garbage collector
va009039 0:65f1469d6bfb 74 *
va009039 0:65f1469d6bfb 75 * @return Return code
va009039 0:65f1469d6bfb 76 */
va009039 0:65f1469d6bfb 77 PmReturn_t heap_gcRun(void);
va009039 0:65f1469d6bfb 78
va009039 0:65f1469d6bfb 79 /**
va009039 0:65f1469d6bfb 80 * Enables (if true) or disables automatic garbage collection
va009039 0:65f1469d6bfb 81 *
va009039 0:65f1469d6bfb 82 * @param bool Value to enable or disable auto GC
va009039 0:65f1469d6bfb 83 * @return Return code
va009039 0:65f1469d6bfb 84 */
va009039 0:65f1469d6bfb 85 PmReturn_t heap_gcSetAuto(uint8_t auto_gc);
va009039 0:65f1469d6bfb 86
va009039 0:65f1469d6bfb 87 #endif /* HAVE_GC */
va009039 0:65f1469d6bfb 88
va009039 0:65f1469d6bfb 89 /**
va009039 0:65f1469d6bfb 90 * Pushes an object onto the temporary roots stack if there is room
va009039 0:65f1469d6bfb 91 * to protect the objects from a potential garbage collection
va009039 0:65f1469d6bfb 92 *
va009039 0:65f1469d6bfb 93 * @param pobj Object to push onto the roots stack
va009039 0:65f1469d6bfb 94 * @param r_objid By reference; ID to use when popping the object from the stack
va009039 0:65f1469d6bfb 95 */
va009039 0:65f1469d6bfb 96 void heap_gcPushTempRoot(pPmObj_t pobj, uint8_t *r_objid);
va009039 0:65f1469d6bfb 97
va009039 0:65f1469d6bfb 98 /**
va009039 0:65f1469d6bfb 99 * Pops from the temporary roots stack all objects upto and including the one
va009039 0:65f1469d6bfb 100 * denoted by the given ID
va009039 0:65f1469d6bfb 101 *
va009039 0:65f1469d6bfb 102 * @param objid ID of object to pop
va009039 0:65f1469d6bfb 103 */
va009039 0:65f1469d6bfb 104 void heap_gcPopTempRoot(uint8_t objid);
va009039 0:65f1469d6bfb 105
va009039 0:65f1469d6bfb 106 #endif /* __HEAP_H__ */