[DEV] add AutoDec

This commit is contained in:
Edouard DUPIN 2018-06-27 21:15:43 +02:00
parent 2fb1234972
commit d92da4207d
4 changed files with 46 additions and 11 deletions

View File

@ -32,6 +32,7 @@ def configure(target, my_module):
'rabbit/sqapi.cpp',
'rabbit/sqlexer.cpp',
'rabbit/sqclass.cpp',
'rabbit/AutoDec.cpp',
'rabbit/VirtualMachine.cpp',
'rabbit/sqtable.cpp',
'rabbit/sqstate.cpp',
@ -51,6 +52,7 @@ def configure(target, my_module):
])
my_module.add_header_file([
'rabbit/sqclass.hpp',
'rabbit/AutoDec.hpp',
'rabbit/VirtualMachine.hpp',
'rabbit/sqstate.hpp',
'rabbit/rabbit.hpp',

18
rabbit/AutoDec.cpp Normal file
View File

@ -0,0 +1,18 @@
/**
* @author Alberto DEMICHELIS
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @copyright 2003-2017, Alberto DEMICHELIS, all right reserved
* @license MPL-2 (see license file)
*/
#include <rabbit/AutoDec.hpp>
rabbit::AutoDec::AutoDec(int64_t* _count) {
m_countPointer = _count;
}
rabbit::AutoDec::~AutoDec() {
(*m_countPointer)--;
}

22
rabbit/AutoDec.hpp Normal file
View File

@ -0,0 +1,22 @@
/**
* @author Alberto DEMICHELIS
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @copyright 2003-2017, Alberto DEMICHELIS, all right reserved
* @license MPL-2 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <rabbit/rabbit.hpp>
namespace rabbit {
class AutoDec {
public:
AutoDec(int64_t* _count);
~AutoDec();
private:
int64_t* m_countPointer;
};
}

View File

@ -9,6 +9,7 @@
#include <rabbit/sqopcodes.hpp>
#include <rabbit/sqobject.hpp>
#include <rabbit/AutoDec.hpp>
#define MAX_NATIVE_CALLS 100
#define MIN_STACK_OVERHEAD 15
@ -20,6 +21,7 @@
#define GET_FLAG_RAW 0x00000001
#define GET_FLAG_DO_NOT_RAISE_ERROR 0x00000002
//base lib
void sq_base_register(rabbit::VirtualMachine* v);
@ -40,7 +42,6 @@ namespace rabbit {
{
public:
struct callInfo{
//callInfo() { _generator = NULL;}
SQInstruction *_ip;
SQObjectPtr *_literals;
SQObjectPtr _closure;
@ -187,15 +188,6 @@ namespace rabbit {
int64_t _suspended_traps;
};
struct AutoDec{
AutoDec(int64_t *n) {
_n = n;
}
~AutoDec() {
(*_n)--;
}
int64_t *_n;
};
inline SQObjectPtr &stack_get(rabbit::VirtualMachine* _vm,int64_t _idx) {
if (_idx>=0) {
@ -204,6 +196,7 @@ namespace rabbit {
return _vm->getUp(_idx);
}
}
#define _ss(_vm_) (_vm_)->_sharedstate
#define PUSH_CALLINFO(v,nci){ \