コード例 #1
0
ファイル: ic_accumulator.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::accumulator::construct() */
cx_int16 ic_accumulator_construct(ic_accumulator _this) {
/* $begin(::cortex::ic::accumulator::construct) */
    char name[15];
    ic_storage(_this)->kind = IC_ACCUMULATOR;
    sprintf(name, "#%d", ic_program_getAccId(ic_program_get()));
    ic_storage(_this)->name = cx_strdup(name);

    ic_scope_addStorage(ic_program_get()->scope, ic_storage(_this));

    return ic_storage_construct(ic_storage(_this));
/* $end */
}
コード例 #2
0
ファイル: ic_program.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::program::declareVariable(string name,type type,bool isReference,bool holdsReturn,bool isParameter,bool isReturn) */
ic_variable ic_program_declareVariable(ic_program _this, cx_string name, cx_type type, cx_bool isReference, cx_bool holdsReturn, cx_bool isParameter, cx_bool isReturn) {
/* $begin(::cortex::ic::program::declareVariable) */
    ic_variable result = ic_variable(ic_scope_lookupStorage(_this->scope, name, FALSE));
    if (!result) {
        result = ic_variable__create(name, type, isReference, holdsReturn, isParameter, isReturn);
        ic_scope_addStorage(_this->scope, ic_storage(result));
    }
    return result;
/* $end */
}
コード例 #3
0
ファイル: ic_program.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::program::popAccumulator() */
cx_void ic_program_popAccumulator(ic_program _this) {
/* $begin(::cortex::ic::program::popAccumulator) */
    ic_storage acc;
    
    _this->accumulatorSp--;
    acc = ic_storage(_this->accumulatorStack[_this->accumulatorSp]);
    
    if (acc->holdsReturn) {
        ic_storage_free(acc);
    }
/* $end */
}
コード例 #4
0
ファイル: ic_program.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::program::getMember(storage base,member m) */
ic_member ic_program_getMember(ic_program _this, ic_storage base, cx_member m) {
/* $begin(::cortex::ic::program::getMember) */
    cx_id name;
    ic_member result;
    sprintf(name, "%s.%s", base->name, cx_nameof(m));
    result = ic_member(ic_scope_lookupStorage(base->scope, name, FALSE));
    if (!result) {
        result = ic_member__create(base, m);
        ic_scope_addStorage(_this->scope, ic_storage(result));
    }
    return result;
/* $end */
}
コード例 #5
0
ファイル: Fast_Element.c プロジェクト: jeffplourde/cortex
/* ::cortex::Fast::Element::toIc(ic::program program,ic::storage storage,bool stored) */
ic_node Fast_Element_toIc_v(Fast_Element _this, ic_program program, ic_storage storage, cx_bool stored) {
/* $begin(::cortex::Fast::Element::toIc) */
    ic_element result;
    ic_node lvalue, rvalue;
    CX_UNUSED(stored);
    CX_UNUSED(storage);

    /* Get lvalue & rvalue */
    lvalue = Fast_Node_toIc(Fast_Node(_this->lvalue), program, NULL, TRUE);
    rvalue = Fast_Node_toIc(Fast_Node(_this->rvalue), program, NULL, TRUE);

    result = ic_program_getElement(program, ic_storage(lvalue), rvalue);

    return (ic_node)result;
/* $end */
}
コード例 #6
0
ファイル: ic_program.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::program::getObject(object o) */
ic_object ic_program_getObject(ic_program _this, cx_object o) {
/* $begin(::cortex::ic::program::getObject) */
    cx_id id;
    ic_scope root = _this->scope;
    ic_object result = NULL;
    while(root->parent) {
        root = root->parent;
    }
    result = ic_object(ic_scope_lookupStorage(root, cx_fullname(o, id), FALSE));
    if (!result) {
        result = ic_object__create(o);
        ic_scope_addStorage(root, ic_storage(result));
    }
    return result;
/* $end */
}
コード例 #7
0
ファイル: ic_program.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::program::getElement(storage base,node index) */
ic_element ic_program_getElement(ic_program _this, ic_storage base, ic_node index) {
/* $begin(::cortex::ic::program::getElement) */
    cx_id name;
    ic_element result;
    if (index) {
        cx_string elemStr = ic_node_str(index, NULL);
        sprintf(name, "%s[%s]", base->name, elemStr);
        cx_dealloc(elemStr);
    } else {
        sprintf(name, "*%s", base->name);
    }
    result = ic_element(ic_scope_lookupStorage(base->scope, name, FALSE));
    if (!result) {
        result = ic_element__create(base, index);
        ic_scope_addStorage(_this->scope, ic_storage(result));
    }
    return result;
/* $end */
}
コード例 #8
0
ファイル: Fast_Member.c プロジェクト: jeffplourde/cortex
/* ::cortex::Fast::Member::toIc(ic::program program,ic::storage storage,bool stored) */
ic_node Fast_Member_toIc_v(Fast_Member _this, ic_program program, ic_storage storage, cx_bool stored) {
/* $begin(::cortex::Fast::Member::toIc) */
    ic_member result = NULL;
    cx_member member;
    ic_node lvalue;
    CX_UNUSED(stored);
    CX_UNUSED(storage);

    /* Get lvalue & rvalue */
    lvalue = Fast_Node_toIc(Fast_Node(_this->lvalue), program, NULL, FALSE);

    if (Fast_Node(_this->rvalue)->kind == Fast_LiteralExpr) {
        if (Fast_Literal(_this->rvalue)->kind == Fast_Text) {
            cx_type t = Fast_Expression_getType(_this->lvalue);
            if (cx_instanceof(cx_type(cx_interface_o), t)) {
                cx_interface baseType = cx_interface(t);
                member = cx_interface_resolveMember(baseType, Fast_String(_this->rvalue)->value);
            } else {
                cx_id id;
                Fast_Parser_error(yparser(), "cannot resolve members on non-interface type '%s'", Fast_Parser_id(t, id));
                goto error;
            }
        } else {
            Fast_Parser_error(yparser(), "dynamic resolving of members not yet supported.");
            goto error;
        }
    } else {
        Fast_Parser_error(yparser(), "dynamic resolving of members not yet supported.");
        goto error;
    }

    if (member) {
        result = ic_program_getMember(program, ic_storage(lvalue), member);
    }

    return (ic_node)result;
error:
    return NULL;
/* $end */
}
コード例 #9
0
ファイル: op.c プロジェクト: cortoproject/corto-language
static corto_string ic_op_derefToString(corto_string string, ic_node s, ic_derefKind mode) {
    if (s->kind == IC_STORAGE) {
        corto_type t = ic_storage(s)->type;
        if (t->reference) {
            if (mode == IC_DEREF_VALUE) {
                string = strappend(string, " *");
            } else {
                string = strappend(string, " ");
            }
        } else {
            if (mode == IC_DEREF_ADDRESS) {
                string = strappend(string, " &");
            } else {
                string = strappend(string, " ");
            }
        }
    } else {
        string = strappend(string, " ");
    }

    return string;
}
コード例 #10
0
ファイル: ic_element.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::element::construct() */
cx_int16 ic_element_construct(ic_element _this) {
/* $begin(::cortex::ic::element::construct) */
    cx_id name;
    cx_collection type = cx_collection(_this->base->type);

    ic_storage(_this)->kind = IC_ELEMENT;
    cx_set(&ic_storage(_this)->type, type->elementType);
    cx_set(&ic_storage(_this)->base, _this->base);
    ic_storage(_this)->isReference = type->elementType->reference;

    if (_this->index) {
        cx_string elemStr = ic_node_str(_this->index, NULL);
        sprintf(name, "%s[%s]", _this->base->name, elemStr);
        cx_dealloc(elemStr);
    } else {
        sprintf(name, "*%s", _this->base->name);
    }

    ic_storage(_this)->name = cx_strdup(name);

    return ic_storage_construct(ic_storage(_this));

/* $end */
}
コード例 #11
0
ファイル: ic_variable.c プロジェクト: jeffplourde/cortex
/* ::cortex::ic::variable::construct() */
cx_int16 ic_variable_construct(ic_variable _this) {
/* $begin(::cortex::ic::variable::construct) */
    ic_storage(_this)->kind = IC_VARIABLE;
    return ic_storage_construct(ic_storage(_this));
/* $end */
}