diff -r 2b8512340180 -r bbb498ccb4ac src/compiler/SemanticAnalysis.cpp --- a/src/compiler/SemanticAnalysis.cpp Sat Dec 22 19:48:43 2012 -0800 +++ b/src/compiler/SemanticAnalysis.cpp Sat Dec 22 23:18:57 2012 -0800 @@ -214,6 +214,11 @@ } void +SemanticAnalysis::visitEnumStatement(EnumStatement *node) +{ +} + +void SemanticAnalysis::visitExpressionStatement(ExpressionStatement *node) { // While building HIR, we enter new pool and root scopes, since HIR @@ -545,24 +550,51 @@ SemanticAnalysis::visitNameProxy(NameProxy *proxy) { Symbol *sym = proxy->sym(); - VariableSymbol *var = sym->asVariable(); - Scope *in = sym->scope(); - switch (in->kind()) { - case Scope::GLOBAL: - hir_ = new (pool_) HGlobal(proxy, sym); - return; + switch (sym->kind()) { + case Symbol::kConstant: + { + ConstantSymbol *val = sym->toConstant(); + hir_ = new (pool_) HInteger(proxy, sym->type(), val->value().toInt()); + break; + } + + // This is kind of screwy. Symbol::kFunction is like a constant we can't + // evaluate yet. Maybe we should extract the GLOBAL case and say that + // kFunction is only used for global functions (and use const vars for + // local functions). + case Symbol::kFunction: + case Symbol::kVariable: + { + Scope *in = sym->scope(); + switch (in->kind()) { + case Scope::GLOBAL: + hir_ = new (pool_) HGlobal(proxy, sym); + break; - case Scope::FUNCTION: - assert(var->storage() == VariableSymbol::Arg); - hir_ = new (pool_) HLocal(proxy, var); - return; + case Scope::FUNCTION: + { + VariableSymbol *var = sym->toVariable(); + assert(var->storage() == VariableSymbol::Arg); + hir_ = new (pool_) HLocal(proxy, var); + break; + } + + default: + { + VariableSymbol *var = sym->toVariable(); + assert(in->kind() == Scope::BLOCK); + assert(var->storage() == VariableSymbol::Local); + hir_ = new (pool_) HLocal(proxy, var); + break; + } + } + break; + } default: - assert(in->kind() == Scope::BLOCK); - assert(var->storage() == VariableSymbol::Local); - hir_ = new (pool_) HLocal(proxy, var); - return; + // :TODO: + assert(false); } } @@ -854,6 +886,15 @@ } HIR * +SemanticAnalysis::typeFailure(const SourcePosition &pos, Handle from, Handle to) +{ + cc_.reportError(pos, Message_InvalidCoercion, + GetTypeName(from), + GetTypeName(to)); + return NULL; +} + +HIR * SemanticAnalysis::coerce(HIR *hir, Handle to, CoercionKind kind) { Handle from = hir->type(); @@ -862,6 +903,9 @@ return new (pool_) HConvert(hir->node(), to, OP_CVT_I2F, hir); if (from->isInt32() && to->isBool()) return new (pool_) HConvert(hir->node(), to, OP_CVT_I2B, hir); + + if (to->isEnum() && from != to) + return typeFailure(hir->node()->pos(), from, to); if (to->isArray()) { if (!typeCheckArray(SourcePosition(), from, to, kind))