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> 2003-07-17 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/virtual_machine.hh: (step) Return a boolean that * src/vm/virtual_machine.hh: (step) Return a boolean that
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
# ifndef INT32_MAX # ifndef INT32_MAX
# define INT32_MAX 2147483647 # define INT32_MAX 2147483647
# endif # endif
# include <string.h> //# include <string.h>
namespace vm namespace vm
{ {
...@@ -37,15 +37,14 @@ namespace vm ...@@ -37,15 +37,14 @@ namespace vm
class Memory class Memory
{ {
public: public:
static const int stack_size = 128 * 1024; static const int stack_bottom = INT32_MAX - 3;
static const int stack_bottom = INT32_MAX - 3; static const int default_stack_size = 128 * 1024;
static const int stack_top = stack_bottom - stack_size + 4;
public: public:
Memory(): Memory(int stack_size = default_stack_size):
_heap(0), heap(0), stack(stack_size), stack_top(stack_bottom - stack_size + 4)
_stack(stack_size)
{ {
assertion(stack_size > 0);
} }
protected: protected:
...@@ -60,47 +59,47 @@ namespace vm ...@@ -60,47 +59,47 @@ namespace vm
int sbrk(int size) int sbrk(int size)
{ {
precondition(size >= 0); precondition(size >= 0);
int ptr = _heap.size(); int ptr = heap.size();
if (size) if (size)
// FIXME: check collision with stack // FIXME: check collision with stack
_heap.resize(size + _heap.size()); heap.resize(size + heap.size());
return ptr; return ptr;
} }
public: 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: public:
void store(const inst::DataSection& data_section) 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) 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) void store_byte(int offset, int b)
{ {
precondition(offset >= 0); precondition(offset >= 0);
if (offset < _heap.size()) if (offset < heap.size())
_heap.store_byte(offset, b); heap.store_byte(offset, b);
else else
_stack.store_byte(translate(offset), b); stack.store_byte(translate(offset), b);
} }
void store_word(int offset, int w) void store_word(int offset, int w)
{ {
precondition(offset >= 0); precondition(offset >= 0);
if (offset < _heap.size()) if (offset < heap.size())
_heap.store_word(offset, w); heap.store_word(offset, w);
else else
_stack.store_word(translate(offset), w); stack.store_word(translate(offset), w);
} }
...@@ -108,23 +107,24 @@ namespace vm ...@@ -108,23 +107,24 @@ namespace vm
int load_byte(int offset) const int load_byte(int offset) const
{ {
precondition(offset >= 0); precondition(offset >= 0);
if (offset < _heap.size()) if (offset < heap.size())
return _heap.load_byte(offset); return heap.load_byte(offset);
return _stack.load_byte(translate(offset)); return stack.load_byte(translate(offset));
} }
int load_word(int offset) const int load_word(int offset) const
{ {
precondition(offset >= 0); precondition(offset >= 0);
if (offset < _heap.size()) if (offset < heap.size())
return _heap.load_word(offset); return heap.load_word(offset);
return _stack.load_word(translate(offset)); return stack.load_word(translate(offset));
} }
protected: protected:
Segment _heap; Segment heap;
Segment _stack; Segment stack;
const int stack_top;
}; };
} // namespace vm } // 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