Commit b5747e87 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Make stack_size a variable.

parent f10b0bc0
2003-07-17 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/memory.hh: stack_size is an argument of Memory constructor.
2003-07-17 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/virtual_machine.hh: (step) Return a boolean that
......
......@@ -29,7 +29,7 @@
# ifndef INT32_MAX
# define INT32_MAX 2147483647
# endif
# include <string.h>
//# include <string.h>
namespace vm
{
......@@ -37,15 +37,14 @@ namespace vm
class Memory
{
public:
static const int stack_size = 128 * 1024;
static const int stack_bottom = INT32_MAX - 3;
static const int stack_top = stack_bottom - stack_size + 4;
static const int stack_bottom = INT32_MAX - 3;
static const int default_stack_size = 128 * 1024;
public:
Memory():
_heap(0),
_stack(stack_size)
Memory(int stack_size = default_stack_size):
heap(0), stack(stack_size), stack_top(stack_bottom - stack_size + 4)
{
assertion(stack_size > 0);
}
protected:
......@@ -60,47 +59,47 @@ namespace vm
int sbrk(int size)
{
precondition(size >= 0);
int ptr = _heap.size();
int ptr = heap.size();
if (size)
// FIXME: check collision with stack
_heap.resize(size + _heap.size());
heap.resize(size + heap.size());
return ptr;
}
public:
int get_heap_size()
int heap_size() const
{
return _heap.size ();
return heap.size ();
}
int get_stack_size()
int stack_size() const
{
return _stack.size ();
return stack.size ();
}
public:
void store(const inst::DataSection& data_section)
{
_heap.resize(data_section.size());
heap.resize(data_section.size());
for (int i = 0; i < data_section.size(); ++i)
_heap.store_byte(i, data_section.load_byte(i));
heap.store_byte(i, data_section.load_byte(i));
}
void store_byte(int offset, int b)
{
precondition(offset >= 0);
if (offset < _heap.size())
_heap.store_byte(offset, b);
if (offset < heap.size())
heap.store_byte(offset, b);
else
_stack.store_byte(translate(offset), b);
stack.store_byte(translate(offset), b);
}
void store_word(int offset, int w)
{
precondition(offset >= 0);
if (offset < _heap.size())
_heap.store_word(offset, w);
if (offset < heap.size())
heap.store_word(offset, w);
else
_stack.store_word(translate(offset), w);
stack.store_word(translate(offset), w);
}
......@@ -108,23 +107,24 @@ namespace vm
int load_byte(int offset) const
{
precondition(offset >= 0);
if (offset < _heap.size())
return _heap.load_byte(offset);
return _stack.load_byte(translate(offset));
if (offset < heap.size())
return heap.load_byte(offset);
return stack.load_byte(translate(offset));
}
int load_word(int offset) const
{
precondition(offset >= 0);
if (offset < _heap.size())
return _heap.load_word(offset);
return _stack.load_word(translate(offset));
if (offset < heap.size())
return heap.load_word(offset);
return stack.load_word(translate(offset));
}
protected:
Segment _heap;
Segment _stack;
Segment heap;
Segment stack;
const int stack_top;
};
} // namespace vm
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment