mirror of
https://github.com/louisrubet/rpn
synced 2025-01-04 11:01:35 +01:00
#34: going to significand stored in stack [first part]
This commit is contained in:
parent
2bdc1c4f72
commit
e786df74a8
3 changed files with 77 additions and 10 deletions
|
@ -544,7 +544,16 @@ static ret_value parse(const char* entry, program& prog)
|
|||
// ex: entry="1 2+" -> vector<string> = {"1", "2+"} -> first "1", second "2" and remaining_entry="+"
|
||||
// this remaining entry is treated as an entry
|
||||
if(_obj_from_string(main_entry, obj, obj_size, type, remaining_entry))
|
||||
{
|
||||
if (type == cmd_number)
|
||||
{
|
||||
void* significand;
|
||||
prog.allocate_back(obj_size, type, MPFR_128BITS_STORING_LENGTH, &significand);
|
||||
|
||||
}
|
||||
else
|
||||
prog.push_back(obj, obj_size, type);
|
||||
}
|
||||
main_entry = remaining_entry;
|
||||
}
|
||||
}
|
||||
|
|
68
src/stack.h
68
src/stack.h
|
@ -10,7 +10,9 @@ using namespace std;
|
|||
|
||||
#include "debug.h"
|
||||
|
||||
#define ALLOC_BLOB (2*1024)
|
||||
// allocation base size
|
||||
#define ALLOC_STACK_CHUNK (64*1024)
|
||||
#define ALLOC_BLOB_CHUNK (64*1024)
|
||||
#define LOCAL_COPY_PLACES 3
|
||||
#define LOCAL_COPY_SIZE 128
|
||||
|
||||
|
@ -28,9 +30,11 @@ private:
|
|||
public:
|
||||
stack()
|
||||
{
|
||||
_base = (char*)malloc(ALLOC_BLOB);
|
||||
_total_size = ALLOC_BLOB;
|
||||
_base = (char*)malloc(ALLOC_STACK_CHUNK);
|
||||
_blob = (char*)malloc(ALLOC_BLOB_CHUNK);
|
||||
_total_size = ALLOC_STACK_CHUNK;
|
||||
_current = _base;
|
||||
_current_blob = _base;
|
||||
_count = 0;
|
||||
}
|
||||
virtual ~stack() { free(_base); }
|
||||
|
@ -40,7 +44,7 @@ public:
|
|||
if (_current + size > _base + _total_size)
|
||||
{
|
||||
//TODO gerer les pbs de memoire
|
||||
_total_size += ALLOC_BLOB;
|
||||
_total_size += ALLOC_STACK_CHUNK;
|
||||
_base = (char*)realloc(_base, _total_size);
|
||||
}
|
||||
|
||||
|
@ -48,11 +52,46 @@ public:
|
|||
memcpy(_current, obj, size);
|
||||
_vlen.push_back(size);
|
||||
_vpointer.push_back(_current);
|
||||
_vlen_blob.push_back(0);
|
||||
_vtype.push_back(type);
|
||||
_count++;
|
||||
_current += size;
|
||||
}
|
||||
|
||||
void* allocate_back(unsigned int size, int type, unsigned int blob_size = 0, void** blob = NULL)
|
||||
{
|
||||
void* allocated;
|
||||
|
||||
if (_current + size > _base + _total_size)
|
||||
{
|
||||
//TODO gerer les pbs de memoire
|
||||
_total_size += ALLOC_STACK_CHUNK;
|
||||
_base = (char*)realloc(_base, _total_size);
|
||||
}
|
||||
if (_current_blob + blob_size > _blob + _total_blob_size)
|
||||
{
|
||||
//TODO gerer les pbs de memoire
|
||||
_total_blob_size += ALLOC_BLOB_CHUNK;
|
||||
_blob = (char*)realloc(_base, _total_blob_size);
|
||||
}
|
||||
|
||||
_vlen.push_back(size);
|
||||
_vpointer.push_back(_current);
|
||||
allocated = _current;
|
||||
_current += size;
|
||||
|
||||
_vlen_blob.push_back(blob_size);
|
||||
_vpointer_blob.push_back(_current_blob);
|
||||
if (blob != NULL)
|
||||
*blob = _current_blob;
|
||||
_current_blob += blob_size;
|
||||
|
||||
_vtype.push_back(type);
|
||||
_count++;
|
||||
|
||||
return allocated;
|
||||
}
|
||||
|
||||
void* pop_back()
|
||||
{
|
||||
void* back = NULL;
|
||||
|
@ -62,6 +101,11 @@ public:
|
|||
_current = _vpointer[_count - 1];
|
||||
_vlen.pop_back();
|
||||
_vpointer.pop_back();
|
||||
|
||||
_current_blob = _vpointer_blob[_count - 1];
|
||||
_vlen_blob.pop_back();
|
||||
_vpointer_blob.pop_back();
|
||||
|
||||
_vtype.pop_back();
|
||||
_count--;
|
||||
|
||||
|
@ -98,6 +142,14 @@ public:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void* back_blob()
|
||||
{
|
||||
if (_count>0)
|
||||
return _vpointer[_count-1];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int get_len(unsigned int index)
|
||||
{
|
||||
if (index<_count)
|
||||
|
@ -163,12 +215,18 @@ public:
|
|||
|
||||
private:
|
||||
char* _base;
|
||||
char* _blob;
|
||||
char* _current;
|
||||
vector<unsigned int> _vlen;// size of each entry in bytes
|
||||
char* _current_blob;
|
||||
|
||||
vector<char*> _vpointer;//pointer on each entry
|
||||
vector<char*> _vpointer_blob;//pointer on each entry blob
|
||||
vector<unsigned int> _vlen;// size of each entry in bytes
|
||||
vector<unsigned int> _vlen_blob;// size of each blob entry in bytes
|
||||
vector<int> _vtype;//type of each entry
|
||||
unsigned int _count;// =_vlen.size()=_vpointer.size()=_vtype.size()
|
||||
unsigned int _total_size;//total allocated size in bytes
|
||||
unsigned int _total_blob_size;//total allocated blob size in bytes
|
||||
|
||||
char _places[LOCAL_COPY_PLACES][LOCAL_COPY_SIZE];
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue