Fixed reporting of unbound names, and restricted late binding to global functions.
Fixed reporting of unbound names, and restricted late binding to global functions.
1.1 --- a/jitcraft/API.cpp Wed Jul 18 22:02:11 2012 -0700
1.2 +++ b/jitcraft/API.cpp Fri Jul 20 00:03:10 2012 -0700
1.3 @@ -100,7 +100,7 @@
1.4 return NULL;
1.5 tree->dump(stdout);
1.6
1.7 - if (!Scope::Bind(tree))
1.8 + if (!Scope::Bind(cc, tree))
1.9 return NULL;
1.10
1.11 SemanticAnalysis semantics(ZONE(), cc, tree);
2.1 --- a/jitcraft/Messages.tbl Wed Jul 18 22:02:11 2012 -0700
2.2 +++ b/jitcraft/Messages.tbl Fri Jul 20 00:03:10 2012 -0700
2.3 @@ -58,4 +58,5 @@
2.4 MSG(MissingReturnValue, SyntaxError, "tagged function must return a value")
2.5 MSG(NotAllPathsReturnValue, SyntaxError, "not all paths through function return a value")
2.6 MSG(UsedVoidReturn, SyntaxError, "return value expected, but function does not return a value")
2.7 -MSG(FunctionDoesNotReturnValue, SyntaxError, "cannot use the result of a function with no return value")
2.8 \ No newline at end of file
2.9 +MSG(FunctionDoesNotReturnValue, SyntaxError, "cannot use the result of a function with no return value")
2.10 +MSG(IdentifierNotFound, SyntaxError, "identifier '%s' could not be found")
2.11 \ No newline at end of file
3.1 --- a/jitcraft/Parser.cpp Wed Jul 18 22:02:11 2012 -0700
3.2 +++ b/jitcraft/Parser.cpp Fri Jul 20 00:03:10 2012 -0700
3.3 @@ -1079,6 +1079,8 @@
3.4 // case TOK_NEW:
3.5 // {
3.6 // if ((statement = variableDeclaration()) == NULL)
3.7 + // return NULL;
3.8 + // if (!matchSemicolon())
3.9 // return NULL;
3.10 // break;
3.11 // }
4.1 --- a/jitcraft/Scopes.cpp Wed Jul 18 22:02:11 2012 -0700
4.2 +++ b/jitcraft/Scopes.cpp Fri Jul 20 00:03:10 2012 -0700
4.3 @@ -21,6 +21,7 @@
4.4 #include "Types.h"
4.5 #include "TypeManager.h"
4.6 #include "Strings.h"
4.7 +#include "CompileContext.h"
4.8
4.9 using namespace ke;
4.10
4.11 @@ -201,15 +202,24 @@
4.12 }
4.13
4.14 bool
4.15 -Scope::Bind(ParseTree *tree)
4.16 +Scope::Bind(CompileContext &cc, ParseTree *tree)
4.17 {
4.18 Local<String> name(ZONE());
4.19 for (size_t i = 0; i < tree->unbound()->length(); i++) {
4.20 NameProxy *proxy = tree->unbound()->at(i);
4.21 name = proxy->name();
4.22 BoundName *binding = tree->scope()->lookup(name);
4.23 +
4.24 if (!binding) {
4.25 - assert(false);
4.26 + cc.reportError(proxy->pos(), Message_IdentifierNotFound, name->chars());
4.27 + return false;
4.28 + }
4.29 +
4.30 + // We only allow global functions to be late-bound.
4.31 + if (binding->kind() != BoundName::FUNCTION ||
4.32 + binding->scope()->kind() != Scope::GLOBAL)
4.33 + {
4.34 + cc.reportError(proxy->pos(), Message_IdentifierNotFound, name->chars());
4.35 return false;
4.36 }
4.37
5.1 --- a/jitcraft/Scopes.h Wed Jul 18 22:02:11 2012 -0700
5.2 +++ b/jitcraft/Scopes.h Fri Jul 20 00:03:10 2012 -0700
5.3 @@ -24,6 +24,8 @@
5.4
5.5 namespace ke {
5.6
5.7 +class CompileContext;
5.8 +
5.9 class Scope : public PoolObject
5.10 {
5.11 PoolAllocator &pool_;
5.12 @@ -96,7 +98,7 @@
5.13 void allocateGlobals();
5.14
5.15 public:
5.16 - static bool Bind(ParseTree *tree);
5.17 + static bool Bind(CompileContext &cc, ParseTree *tree);
5.18 static void Allocate(ParseTree *tree);
5.19
5.20 private: