Example #1
0
struct lterm_t* chCopySimpleExpr(struct lterm_t* chain, allocate_result* res)
{
    if (!chain)
        PRINT_AND_EXIT(GC_NULL_CHAIN_SIMPLE_CHAIN_COPY);

    if (chain->tag != L_TERM_CHAIN_TAG)
        PRINT_AND_EXIT(GC_BAD_CHAIN_SIMPLE_CHAIN_COPY);


    GC_DATA_HEAP_CHECK_RETURN(CHAIN_LTERM_SIZE, *res);

    struct lterm_t* newChain = allocateSimpleChain();
    struct lterm_t* currTerm = chain->next;

    while (currTerm != chain)
    {
        if (currTerm->tag != L_TERM_FRAGMENT_TAG)
            PRINT_AND_EXIT(OBJ_EXPR_CONTAINS_ONLY_FRAGS);

        GC_DATA_HEAP_CHECK_RETURN(FRAGMENT_LTERM_SIZE, *res);

        struct lterm_t* newTerm = allocateFragmentLTerm(1);
        memcpy(newTerm->fragment, currTerm->fragment, sizeof(struct fragment_t));

        ADD_TO_CHAIN(newChain, newTerm);

        currTerm = currTerm->next;
    }

    return newChain;
}
Example #2
0
static struct lterm_t* constructStartFunc(const char* funcName, RefalFunc entryFuncPointer)
{
    allocate_result     res;
    struct vstring_t*   ident;
    struct lterm_t*     fragTerm;
    struct lterm_t*     gofuncCallTerm;

    CHECK_ALLOCATION_EXIT(gofuncCallTerm, chAllocateFuncCallLTerm(&res), res);
    CHECK_ALLOCATION_EXIT(gofuncCallTerm->funcCall->fieldOfView, chAllocateSimpleChainLTerm(&res), res);

    CHECK_ALLOCATION_EXIT(fragTerm, chAllocateFragmentLTerm(1, &res), res);
    CHECK_ALLOCATION_EXIT(fragTerm->fragment->offset, chAllocateClosureVTerm(&res), res);

    fragTerm->fragment->length = 1;

    CHECK_ALLOCATION_EXIT(ident, chAllocateVStringFromASCIIName(funcName, &res), res);

    CHECK_ALLOCATION_EXIT(_memMngr.vterms[fragTerm->fragment->offset].closure,
            chAllocateClosureStruct(entryFuncPointer, 0, ident, 0, &res),
            res);

    ADD_TO_CHAIN(gofuncCallTerm->funcCall->fieldOfView, fragTerm);

    return gofuncCallTerm;
}
Example #3
0
void SQInstance::Init( SQSharedState *ss ) {
	_userpointer = NULL;
	_hook = NULL;
	__ObjAddRef( _class );
	_delegate = _class->_members;
	INIT_CHAIN();
	ADD_TO_CHAIN( &_sharedstate->_gc_chain, this );
}
Example #4
0
SQTable::SQTable(SQSharedState *ss,SQInteger nInitialSize)
{
	SQInteger pow2size=MINPOWER2;
	while(nInitialSize>pow2size)pow2size=pow2size<<1;
	AllocNodes(pow2size);
	_usednodes = 0;
	_delegate = NULL;
	INIT_CHAIN();
	ADD_TO_CHAIN(&_sharedstate->_gc_chain,this);
}
struct lterm_t* allocateBuiltinsResult(uint64_t offset, uint64_t length)
{
    struct lterm_t* fragmentLTerm = allocateFragmentLTerm(1);
    fragmentLTerm->fragment->offset = offset;
    fragmentLTerm->fragment->length = length;

    struct lterm_t* chain = allocateSimpleChain();

    ADD_TO_CHAIN(chain, fragmentLTerm);

    return chain;
}
Example #6
0
static struct lterm_t* constructStartFieldOfView(const char* funcName, RefalFunc entryFuncPointer)
{
    allocate_result     res;
    struct lterm_t*     fieldOfView;

    CHECK_ALLOCATION_EXIT(fieldOfView, chAllocateSimpleChainLTerm(&res), res);

    struct lterm_t* goFuncCallTerm = constructStartFunc(funcName, entryFuncPointer);

    ADD_TO_CHAIN(fieldOfView, goFuncCallTerm);

    return fieldOfView;
}
Example #7
0
SQClass::SQClass( SQSharedState *ss, SQClass *base ) {
	_base = base;
	_typetag = 0;
	_metamethods.resize( MT_LAST ); //size it to max size
	if ( _base ) {
		_defaultvalues.copy( base->_defaultvalues );
		_methods.copy( base->_methods );
		_metamethods.copy( base->_metamethods );
		__ObjAddRef( _base );
	}
	_members = base ? base->_members->Clone() : SQTable::Create( ss, 0 );
	__ObjAddRef( _members );
	_locked = false;
	INIT_CHAIN();
	ADD_TO_CHAIN( &_sharedstate->_gc_chain, this );
}
struct lterm_t* chCopyFieldOfView(struct lterm_t* chain, allocate_result* result)
{
    struct lterm_t* newChain = 0;
    struct lterm_t* newTerm = 0;
    struct lterm_t* currTerm = chain->next;

    CHECK_ALLOCATION_RETURN(newChain, chAllocateSimpleChainLTerm(result), *result);

    while (currTerm != chain)
    {
        newTerm = 0;

        switch (currTerm->tag)
        {
            case L_TERM_FRAGMENT_TAG:
                CHECK_ALLOCATION_RETURN(newTerm, chCopyFragmentLTerm(currTerm, result), *result);
                break;

            case L_TERM_CHAIN_KEEPER_TAG:
                CHECK_ALLOCATION_RETURN(newTerm, chCopyChainKeeperLTerm(currTerm, result), *result);
                break;

            case L_TERM_FUNC_CALL:
                PRINT_AND_EXIT(FOV_CONTAINS_FUNC_CALL);
                break;

            case L_TERM_CHAIN_TAG:
                PRINT_AND_EXIT(FOV_CONTAINS_SIMPLE_CHAIN);
                break;
        }

        if (newTerm)
            ADD_TO_CHAIN(newChain, newTerm);
        else
            PRINT_AND_EXIT(GC_CANT_COPY_TERM);

        currTerm = currTerm->next;
    }

    return newChain;
}
Example #9
0
SQClass::SQClass(SQSharedState *ss,SQClass *base)
{
	_base = base;
	_typetag = 0;
	_hook = NULL;
	_udsize = 0;
	_locked = false;
	_constructoridx = -1;
	if(_base) {
		_constructoridx = _base->_constructoridx;
		_udsize = _base->_udsize;
		_defaultvalues.copy(base->_defaultvalues);
		_methods.copy(base->_methods);
		_COPY_VECTOR(_metamethods,base->_metamethods,MT_LAST);
		__ObjAddRef(_base);
	}
	_members = base?base->_members->Clone() : SQTable::Create(ss,0);
	__ObjAddRef(_members);
	
	INIT_CHAIN();
	ADD_TO_CHAIN(&_sharedstate->_gc_chain, this);
}