Imported Upstream version 0.1beta
[debian/yforth] / memall.c
1 /* yForth? - Written by Luca Padovani (C) 1996/97
2  * ------------------------------------------------------------------------
3  * This software is FreeWare as long as it comes with this header in each
4  * source file, anyway you can use it or any part of it whatever
5  * you want. It comes without any warranty, so use it at your own risk.
6  * ------------------------------------------------------------------------
7  * Module name: memall.c
8  * Abstract:    Memory allocation word set
9  */
10
11 #include <string.h>
12 #include <malloc.h>
13 #include "yforth.h"
14 #include "core.h"
15 #include "coree.h"
16
17 /**************************************************************************/
18 /* WORDS ******************************************************************/
19 /**************************************************************************/
20
21 void _allocate() {
22     register void *addr = malloc(*sp);
23     if (addr == NULL) *sp = 0;
24     else *sp = (Cell) addr;
25     *--sp = FFLAG(addr == NULL);
26 }
27
28 void _free() {
29     free((void *) *sp);
30     *sp = FFLAG(0);
31 }
32
33 void _resize() {
34     register void *addr = realloc((void *) sp[1], sp[0]);
35     if (addr == NULL) sp[1] = 0;
36     else sp[1] = (Cell) addr;
37     *sp = FFLAG(addr == NULL);
38 }
39
40