Skip to content
Browse files

Bindings updates

  • Loading branch information...
1 parent 1ff5f8e commit c27bbb54eac975666bd12412f205af829642b36e Jeremy Clifford committed
Showing with 92 additions and 16 deletions.
  1. +32 −9 compiler/src/analyzer.cpp
  2. +58 −5 compiler/src/codegen.cpp
  3. +2 −2 packages/archlinux/clay-git/PKGBUILD
View
41 compiler/src/analyzer.cpp
@@ -463,6 +463,7 @@ MultiPValuePtr analyzeMulti(ExprListPtr exprs, EnvPtr env, unsigned wantCount)
static MultiPValuePtr analyzeMulti2(ExprListPtr exprs, EnvPtr env, unsigned wantCount)
{
+ // llvm::errs() << "analyzeMulti2\n";
MultiPValuePtr out = new MultiPValue();
ExprPtr unpackExpr = implicitUnpackExpr(wantCount, exprs);
if (unpackExpr != NULL) {
@@ -610,6 +611,7 @@ static MultiPValuePtr analyzeExpr2(ExprPtr expr, EnvPtr env);
MultiPValuePtr analyzeExpr(ExprPtr expr, EnvPtr env)
{
+ // llvm::errs() << "analyzeExpr\n";
if (analysisCachingDisabled > 0)
return analyzeExpr2(expr, env);
if (!expr->cachedAnalysis)
@@ -620,7 +622,7 @@ MultiPValuePtr analyzeExpr(ExprPtr expr, EnvPtr env)
static MultiPValuePtr analyzeExpr2(ExprPtr expr, EnvPtr env)
{
LocationContext loc(expr->location);
-
+ // llvm::errs() << "analyzeExpr2, " << expr->exprKind << "\n";
switch (expr->exprKind) {
case BOOL_LITERAL : {
@@ -2028,6 +2030,7 @@ StatementAnalysis analyzeStatement(StatementPtr stmt, EnvPtr env, AnalysisContex
static StatementAnalysis analyzeBlockStatement(StatementPtr stmt, EnvPtr &env, AnalysisContext* ctx)
{
if (stmt->stmtKind == BINDING) {
+ llvm::errs() << "analyzeBindinginBlock\n";
env = analyzeBinding((Binding *)stmt.ptr(), env);
if (!env) {
ctx->hasRecursivePropagation = true;
@@ -2056,6 +2059,7 @@ static EnvPtr analyzeStatementExpressionStatements(vector<StatementPtr> const &s
{
switch ((*i)->stmtKind) {
case BINDING:
+ llvm::errs() << "analyzeStatementExprBindingStatement\n";
env2 = analyzeBinding((Binding*)i->ptr(), env2);
if (env2 == NULL)
return NULL;
@@ -2078,7 +2082,7 @@ static EnvPtr analyzeStatementExpressionStatements(vector<StatementPtr> const &s
StatementAnalysis analyzeStatement(StatementPtr stmt, EnvPtr env, AnalysisContext* ctx)
{
LocationContext loc(stmt->location);
-
+
switch (stmt->stmtKind) {
case BLOCK : {
@@ -2093,8 +2097,13 @@ StatementAnalysis analyzeStatement(StatementPtr stmt, EnvPtr env, AnalysisContex
return SA_FALLTHROUGH;
}
+ case BINDING : {
+ llvm::errs() << "analyzeBindingStatement\n";
+ return SA_FALLTHROUGH;
+
+ }
+
case LABEL :
- case BINDING :
case ASSIGNMENT :
case INIT_ASSIGNMENT :
case VARIADIC_ASSIGNMENT :
@@ -2286,7 +2295,13 @@ EnvPtr analyzeBinding(BindingPtr x, EnvPtr env)
default: llvm::errs() << "analyzeBinding:FORWARD " << x->args[0]->name << "\n";
}
-
+ // for (llvm::StringMap<ObjectPtr>::const_iterator i = env->entries.begin(), end = env->entries.end();
+ // i != end;
+ // ++i)
+ // {
+ // llvm::errs() << i->first().str() << "\n";
+ // }
+
vector<TypePtr> argsKey;
vector<ValueTempness> argsTempness;
vector<PatternCellPtr> cells;
@@ -2359,24 +2374,24 @@ EnvPtr analyzeBinding(BindingPtr x, EnvPtr env)
// matchFailureError(new MatchMultiArgumentError(formalArgs.size(), types, x->varg));
}
- EnvPtr env2 = new Env(patternEnv);
+ EnvPtr staticEnv = new Env(env);
for (unsigned i = 0; i < pvars.size(); ++i) {
if (pvars[i].isMulti) {
MultiStaticPtr ms = derefDeep(multiCells[i].ptr());
if (!ms)
error(pvars[i].name, "unbound pattern variable");
- addLocal(env2, pvars[i].name, ms.ptr());
+ addLocal(staticEnv, pvars[i].name, ms.ptr());
}
else {
ObjectPtr v = derefDeep(cells[i].ptr());
if (!v)
error(pvars[i].name, "unbound pattern variable");
- addLocal(env2, pvars[i].name, v.ptr());
+ addLocal(staticEnv, pvars[i].name, v.ptr());
}
}
- // x->env = staticEnv;
- // EnvPtr env2 = new Env(staticEnv);
+ x->env = staticEnv;
+ EnvPtr env2 = new Env(staticEnv);
for (unsigned i = 0; i < formalArgs.size(); ++i) {
FormalArgPtr y = formalArgs[i];
x->fixedArgNames.push_back(y->name);
@@ -2395,6 +2410,14 @@ EnvPtr analyzeBinding(BindingPtr x, EnvPtr env)
llvm::errs() << "addLocal: " << x->varArgName << "\n";
addLocal(env2, x->varArgName, varArgs.ptr());
}
+
+ for (llvm::StringMap<ObjectPtr>::const_iterator i = env->entries.begin(), end = env->entries.end();
+ i != end;
+ ++i)
+ {
+ llvm::errs() << i->first().str() << "\n";
+ }
+
return env2;
}
View
63 compiler/src/codegen.cpp
@@ -4056,16 +4056,25 @@ EnvPtr codegenBinding(BindingPtr x, EnvPtr env, CodegenContext* ctx)
int line, column;
llvm::DIFile file = getDebugLineCol(x->location, line, column);
-
- switch (x->bindingKind) {
case VAR : {
llvm::errs() << "codegenBinding:VAR\n";
+
MultiPValuePtr mpv = safeAnalyzeMulti(x->values, env, x->args.size());
MultiCValuePtr mcv = new MultiCValue();
+ llvm::errs() << "codegenBinding:VAR 2\n";
+ for (llvm::StringMap<ObjectPtr>::const_iterator i = env->entries.begin(), end = env->entries.end();
+ i != end;
+ ++i)
+ {
+ llvm::errs() << i->first().str() << "\n";
+ }
+ llvm::errs() << "codegenBinding:VAR 3\n";
for (unsigned i = 0; i < mpv->values.size(); ++i) {
+ llvm::errs() << "codegenBinding:VAR 4\n";
CValuePtr cv = codegenAllocNewValue(mpv->values[i].type, ctx);
mcv->add(cv);
+ llvm::errs() << "codegenBinding:VAR 5\n";
if (llvmDIBuilder != NULL) {
llvm::DILexicalBlock debugBlock = ctx->getDebugScope();
llvm::DIVariable debugVar = llvmDIBuilder->createLocalVariable(
@@ -4086,30 +4095,40 @@ EnvPtr codegenBinding(BindingPtr x, EnvPtr env, CodegenContext* ctx)
->setDebugLoc(ctx->builder->getCurrentDebugLocation());
}
}
+ llvm::errs() << "codegenBinding:VAR 6\n";
int tempMarker = markTemps(ctx);
int marker = cgMarkStack(ctx);
codegenMultiInto(x->values, env, ctx, mcv, x->args.size());
cgDestroyAndPopStack(marker, ctx, false);
clearTemps(tempMarker, ctx);
EnvPtr env2 = new Env(env);
+ llvm::errs() << "codegenBinding:VAR 7 "<< x->fixedArgNames.size()<< " \n";
for (unsigned i = 0; i < x->fixedArgNames.size(); ++i) {
CValuePtr cv = mcv->values[i];
+ llvm::errs() << "codegenBinding:VAR 7a\n";
cgPushStackValue(cv, ctx);
addLocal(env2, x->fixedArgNames[i], cv.ptr());
+ llvm::errs() << "codegenBinding:VAR 7b\n";
llvm::SmallString<128> buf;
llvm::raw_svector_ostream ostr(buf);
ostr << x->fixedArgNames[i]->str << ":" << cv->type;
+ llvm::errs() << "codegenBinding:VAR 7c\n";
cv->llValue->setName(ostr.str());
if(x->args[i]->type != NULL) {
+ llvm::errs() << "codegenBinding:VAR 7d\n";
TypePtr rt = evaluateType(x->args[i]->type, x->env);
- if (cv->type != rt)
+ llvm::errs() << "codegenBinding:VAR 7e\n";
+ if (cv->type != rt) {
+ llvm::errs() << "codegenBinding:VAR 7f\n";
argumentTypeError(i, rt, cv->type);
- else {
+ } else {
+ llvm::errs() << "codegenBinding:VAR 7g\n";
addLocal(env2, ((NameRef *)x->args[i]->type.ptr())->name, cv->type.ptr());
}
}
}
-
+ llvm::errs() << "codegenBinding:VAR 8\n";
+
if (x->varArgName.ptr()) {
unsigned nFixed = x->fixedArgTypes.size();
MultiCValuePtr varArgs = new MultiCValue();
@@ -4127,6 +4146,13 @@ EnvPtr codegenBinding(BindingPtr x, EnvPtr env, CodegenContext* ctx)
addLocal(env2, ((NameRef *)x->varg->type.ptr())->name, vt.ptr());
}
}
+ llvm::errs() << "codegenBinding:VAR 9\n";
+ for (llvm::StringMap<ObjectPtr>::const_iterator i = env2->entries.begin(), end = env2->entries.end();
+ i != end;
+ ++i)
+ {
+ llvm::errs() << i->first().str() << "\n";
+ }
return env2;
}
@@ -4134,7 +4160,15 @@ EnvPtr codegenBinding(BindingPtr x, EnvPtr env, CodegenContext* ctx)
llvm::errs() << "codegenBinding:REF\n";
MultiPValuePtr mpv = safeAnalyzeMulti(x->values, env, x->args.size());
MultiCValuePtr mcv = new MultiCValue();
+ llvm::errs() << "codegenBinding:REF 2\n";
+ for (llvm::StringMap<ObjectPtr>::const_iterator i = env->entries.begin(), end = env->entries.end();
+ i != end;
+ ++i)
+ {
+ llvm::errs() << i->first().str() << "\n";
+ }
for (unsigned i = 0; i < mpv->values.size(); ++i) {
+ llvm::errs() << "codegenBinding:REF 3\n";
PVData const &pv = mpv->values[i];
if (pv.isTemp)
argumentError(i, "ref can only bind to an lvalue");
@@ -4168,15 +4202,25 @@ EnvPtr codegenBinding(BindingPtr x, EnvPtr env, CodegenContext* ctx)
cgDestroyAndPopStack(marker, ctx, false);
clearTemps(tempMarker, ctx);
EnvPtr env2 = new Env(env);
+ llvm::errs() << "codegenBinding:REF 6\n";
+ for (llvm::StringMap<ObjectPtr>::const_iterator i = env2->entries.begin(), end = env2->entries.end();
+ i != end;
+ ++i)
+ {
+ llvm::errs() << i->first().str() << "\n";
+ }
for (unsigned i = 0; i < x->fixedArgNames.size(); ++i) {
+ llvm::errs() << "codegenBinding:REF 7a\n";
CValuePtr cv = derefValue(mcv->values[i], ctx);
cgPushStackValue(cv, ctx);
addLocal(env2, x->fixedArgNames[i], cv.ptr());
+ llvm::errs() << "codegenBinding:REF 7b\n";
llvm::SmallString<128> buf;
llvm::raw_svector_ostream ostr(buf);
ostr << x->fixedArgNames[i]->str << ":" << cv->type;
cv->llValue->setName(ostr.str());
if(x->args[i]->type != NULL) {
+ llvm::errs() << "codegenBinding:REF 7c\n";
TypePtr rt = evaluateType(x->args[i]->type, x->env);
if (cv->type != rt)
argumentTypeError(i, rt, cv->type);
@@ -4187,6 +4231,7 @@ EnvPtr codegenBinding(BindingPtr x, EnvPtr env, CodegenContext* ctx)
}
if (x->varArgName.ptr()) {
+ llvm::errs() << "codegenBinding:REF 8\n";
unsigned nFixed = x->fixedArgTypes.size();
MultiCValuePtr varArgs = new MultiCValue();
for (unsigned i = 0; i < x->varArgTypes.size(); ++i) {
@@ -4204,6 +4249,14 @@ EnvPtr codegenBinding(BindingPtr x, EnvPtr env, CodegenContext* ctx)
}
}
+ llvm::errs() << "codegenBinding:REF 10\n";
+ for (llvm::StringMap<ObjectPtr>::const_iterator i = env2->entries.begin(), end = env2->entries.end();
+ i != end;
+ ++i)
+ {
+ llvm::errs() << i->first().str() << "\n";
+ }
+
return env2;
}
View
4 packages/archlinux/clay-git/PKGBUILD
@@ -7,8 +7,8 @@ pkgdesc='Clay is a programming language designed for Generic Programming.'
arch=('i686' 'x86_64')
url='http://claylabs.com/clay/'
license=('BSD')
-depends=('llvm=3.0' 'clang=3.0') #'python' 'ocaml' really needed?
-optdepends=('llvm-clay-git: llvm+clang with Clay patches')
+depends=('llvm=3.1' 'clang=3.1') #'python' 'ocaml' really needed?
+optdepends=()
makedepends=('git' 'cmake>=2.6')
provides=('clay')
conflicts=('clay-hg')

0 comments on commit c27bbb5

Please sign in to comment.
Something went wrong with that request. Please try again.