| | 1 | #ifdef RCSID |
| | 2 | static char RCSid[] = |
| | 3 | "$Header: d:/cvsroot/tads/tads3/VMSTACK.CPP,v 1.3 1999/07/11 00:46:58 MJRoberts Exp $"; |
| | 4 | #endif |
| | 5 | |
| | 6 | /* |
| | 7 | * Copyright (c) 1998, 2002 Michael J. Roberts. All Rights Reserved. |
| | 8 | * |
| | 9 | * Please see the accompanying license file, LICENSE.TXT, for information |
| | 10 | * on using and copying this software. |
| | 11 | */ |
| | 12 | /* |
| | 13 | Name |
| | 14 | vmstack.cpp - VM stack implementation |
| | 15 | Function |
| | 16 | |
| | 17 | Notes |
| | 18 | |
| | 19 | Modified |
| | 20 | 10/28/98 MJRoberts - Creation |
| | 21 | */ |
| | 22 | |
| | 23 | #include "t3std.h" |
| | 24 | #include "vmtype.h" |
| | 25 | #include "vmstack.h" |
| | 26 | #include "vmfile.h" |
| | 27 | |
| | 28 | /* |
| | 29 | * allocate the stack |
| | 30 | */ |
| | 31 | CVmStack::CVmStack(size_t max_depth, size_t reserve) |
| | 32 | { |
| | 33 | /* |
| | 34 | * Allocate the array of stack elements. Allocate the requested |
| | 35 | * maximum depth plus the requested reserve space. Overallocate by a |
| | 36 | * few elements to leave ourselves a little buffer against mild |
| | 37 | * overages - for the most part, we count on the compiler to check for |
| | 38 | * proper stack usage at entry to each function, but intrinsics |
| | 39 | * sometimes push a few elements without checking. |
| | 40 | */ |
| | 41 | arr_ = (vm_val_t *)t3malloc((max_depth + reserve + 25) * sizeof(arr_[0])); |
| | 42 | |
| | 43 | /* remember the maximum depth and the reserve depth */ |
| | 44 | max_depth_ = max_depth; |
| | 45 | reserve_depth_ = reserve; |
| | 46 | |
| | 47 | /* the reserve is not yet in use */ |
| | 48 | reserve_in_use_ = FALSE; |
| | 49 | |
| | 50 | /* initialize the stack pointer */ |
| | 51 | init(); |
| | 52 | } |
| | 53 | |
| | 54 | /* |
| | 55 | * delete the stack |
| | 56 | */ |
| | 57 | CVmStack::~CVmStack() |
| | 58 | { |
| | 59 | /* delete the stack element array */ |
| | 60 | t3free(arr_); |
| | 61 | } |
| | 62 | |