Skip to content

Commit

Permalink
Auto parameters in lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Sep 14, 2023
1 parent 64b3bfa commit 0e6cb55
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 57 deletions.
62 changes: 61 additions & 1 deletion oscar64/Declaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio

Declaration::Declaration(const Location& loc, DecType type)
: mLocation(loc), mEndLocation(loc), mType(type), mScope(nullptr), mData(nullptr), mIdent(nullptr), mQualIdent(nullptr), mMangleIdent(nullptr),
mSize(0), mOffset(0), mFlags(0), mComplexity(0), mLocalSize(0),
mSize(0), mOffset(0), mFlags(0), mComplexity(0), mLocalSize(0), mNumVars(0),
mBase(nullptr), mParams(nullptr), mValue(nullptr), mNext(nullptr), mPrev(nullptr),
mConst(nullptr), mMutable(nullptr),
mDefaultConstructor(nullptr), mDestructor(nullptr), mCopyConstructor(nullptr), mCopyAssignment(nullptr), mMoveConstructor(nullptr), mMoveAssignment(nullptr),
Expand Down Expand Up @@ -964,6 +964,11 @@ Declaration* Declaration::NonRefBase(void)
return this;
}

bool Declaration::IsAuto(void) const
{
return (mType == DT_TYPE_AUTO || IsReference() && mBase->mType == DT_TYPE_AUTO);
}

Declaration* Declaration::DeduceAuto(Declaration * dec)
{
if (mType == DT_TYPE_AUTO || IsReference() && mBase->mType == DT_TYPE_AUTO)
Expand Down Expand Up @@ -1114,6 +1119,61 @@ const Ident* Declaration::MangleIdent(void)
return mMangleIdent;
}

Declaration* Declaration::ExpandTemplate(DeclarationScope* scope)
{
if (mType == DT_CONST_FUNCTION)
{
Declaration* dec = this->Clone();
dec->mBase = dec->mBase->ExpandTemplate(scope);
return dec;
}
else if (mType == DT_TYPE_FUNCTION)
{
Declaration* dec = this->Clone();
dec->mParams = mParams ? mParams->ExpandTemplate(scope) : nullptr;
dec->mBase = mBase->ExpandTemplate(scope);
Declaration* pdec = dec->mParams;
if (pdec)
{
int vi = pdec->mVarIndex;
while (pdec)
{
pdec->mVarIndex = vi;
vi += pdec->mSize;
pdec = pdec->mNext;
}
}
return dec;
}
else if (mType == DT_ARGUMENT)
{
Declaration* ndec = mNext ? mNext->ExpandTemplate(scope) : nullptr;
Declaration* bdec = mBase->ExpandTemplate(scope);
if (ndec != mNext || bdec != mBase)
{
Declaration* dec = this->Clone();
dec->mBase = bdec;
dec->mSize = bdec->mSize;
dec->mNext = ndec;
return dec;
}
}
else if (mType == DT_TYPE_REFERENCE || mType == DT_TYPE_POINTER || mType == DT_TYPE_RVALUEREF)
{
Declaration* bdec = mBase->ExpandTemplate(scope);
if (bdec != mBase)
{
Declaration* dec = this->Clone();
dec->mBase = bdec;
return dec;
}
}
else if (mType == DT_TYPE_TEMPLATE)
return scope->Lookup(mIdent);

return this;
}

bool Declaration::ResolveTemplate(Expression* pexp, Declaration* tdec)
{
Declaration* pdec = tdec->mBase->mParams;
Expand Down
30 changes: 17 additions & 13 deletions oscar64/Declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,25 @@ static const uint64 DTF_TEMPORARY = (1ULL << 29);
static const uint64 DTF_COMPLETED = (1ULL << 30);
static const uint64 DTF_CONSTEXPR = (1ULL << 31);

static const uint64 DTF_FUNC_VARIABLE = (1ULL << 32);
static const uint64 DTF_FUNC_ASSEMBLER = (1ULL << 33);
static const uint64 DTF_FUNC_RECURSIVE = (1ULL << 34);
static const uint64 DTF_FUNC_ANALYZING = (1ULL << 35);
static const uint64 DTF_AUTO_TEMPLATE = (1ULL << 32);

static const uint64 DTF_FUNC_CONSTEXPR = (1ULL << 36);
static const uint64 DTF_FUNC_INTRSAVE = (1ULL << 37);
static const uint64 DTF_FUNC_INTRCALLED = (1ULL << 38);
static const uint64 DTF_FUNC_PURE = (1ULL << 39);
static const uint64 DTF_FUNC_VARIABLE = (1ULL << 36);
static const uint64 DTF_FUNC_ASSEMBLER = (1ULL << 37);
static const uint64 DTF_FUNC_RECURSIVE = (1ULL << 38);
static const uint64 DTF_FUNC_ANALYZING = (1ULL << 39);

static const uint64 DTF_FPARAM_CONST = (1ULL << 40);
static const uint64 DTF_FPARAM_NOCONST = (1ULL << 41);
static const uint64 DTF_VAR_ADDRESS = (1ULL << 42);
static const uint64 DTF_FUNC_CONSTEXPR = (1ULL << 40);
static const uint64 DTF_FUNC_INTRSAVE = (1ULL << 41);
static const uint64 DTF_FUNC_INTRCALLED = (1ULL << 42);
static const uint64 DTF_FUNC_PURE = (1ULL << 43);

static const uint64 DTF_FUNC_THIS = (1ULL << 43);
static const uint64 DTF_FPARAM_CONST = (1ULL << 44);
static const uint64 DTF_FPARAM_NOCONST = (1ULL << 45);
static const uint64 DTF_VAR_ADDRESS = (1ULL << 46);

static const uint64 DTF_VAR_ALIASING = (1ULL << 48);
static const uint64 DTF_FUNC_THIS = (1ULL << 47);

static const uint64 DTF_VAR_ALIASING = (1ULL << 48);


class Declaration;
Expand Down Expand Up @@ -311,13 +312,16 @@ class Declaration
Declaration* BuildConstRValueRef(const Location& loc);
Declaration* NonRefBase(void);
Declaration* DeduceAuto(Declaration* dec);
bool IsAuto(void) const;

DecType ValueType(void) const;

bool CanResolveTemplate(Expression* pexp, Declaration* tdec);
bool ResolveTemplate(Declaration* fdec, Declaration * tdec);
bool ResolveTemplate(Expression* pexp, Declaration* tdec);

Declaration* ExpandTemplate(DeclarationScope* scope);

const Ident* MangleIdent(void);

int Stride(void) const;
Expand Down
2 changes: 1 addition & 1 deletion oscar64/GlobalAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void GlobalAnalyzer::AutoInline(void)
dec = dec->mNext;
}

int cost = (f->mComplexity - 20 * nparams);
int cost = (f->mComplexity - 20 * nparams - 20);

// printf("CHEK INLINING %s %d * (%d - 1)\n", f->mIdent->mString, cost, f->mCallers.Size());

Expand Down
Loading

0 comments on commit 0e6cb55

Please sign in to comment.