Skip to content
Browse files

:overloads command lists created function overloads

```
clay>1
1
clay>"x"
x
clay>5.0
5
clay>"y"
y
clay>:overloads println
        Static["y"] :
        Int32 :
        Static["x"] :
        Float64 :
```
  • Loading branch information...
1 parent fc28417 commit 4ce8ec5b9bb918cf516f6e88b1101cf07938bddf @galchinsky galchinsky committed Nov 26, 2012
Showing with 40 additions and 0 deletions.
  1. +26 −0 compiler/interactive.cpp
  2. +13 −0 compiler/invoketables.cpp
  3. +1 −0 compiler/invoketables.hpp
View
26 compiler/interactive.cpp
@@ -4,6 +4,7 @@
#include "codegen.hpp"
#include "error.hpp"
#include "loader.hpp"
+#include "invoketables.hpp"
#include <setjmp.h>
#include <signal.h>
@@ -91,6 +92,29 @@ namespace clay {
}
}
+ static void cmdOverloads(const vector<Token>& tokens) {
+ for (size_t i = 1; i < tokens.size(); ++i) {
+ if (tokens[i].tokenKind == T_IDENTIFIER) {
+ Str identStr = tokens[i].str;
+
+ ObjectPtr obj = lookupPrivate(module, Identifier::get(identStr));
+ if (obj == NULL || obj->objKind != PROCEDURE) {
+ llvm::errs() << identStr << " is not a procedure name\n";
+ continue;
+ }
+
+ vector<InvokeSet*> sets = lookupInvokeSets(obj.ptr());
+ for (size_t k = 0; k < sets.size(); ++k) {
+ llvm::errs() << " ";
+ for (size_t l = 0; l < sets[k]->argsKey.size(); ++l) {
+ llvm::errs() << sets[k]->argsKey[l] << " : ";
+ }
+ llvm::errs() << "\n";
+ }
+ }
+ }
+ }
+
static void cmdPrint(const vector<Token>& tokens) {
for (size_t i = 1; i < tokens.size(); ++i) {
if (tokens[i].tokenKind == T_IDENTIFIER) {
@@ -120,6 +144,8 @@ namespace clay {
cmdGlobals(tokens);
} else if (cmd == "modules") {
cmdModules(tokens);
+ } else if (cmd == "overloads") {
+ cmdOverloads(tokens);
} else if (cmd == "print") {
cmdPrint(tokens);
} else if (cmd == "ast_on") {
View
13 compiler/invoketables.cpp
@@ -171,6 +171,19 @@ InvokeSet* lookupInvokeSet(ObjectPtr callable,
return invokeSet;
}
+vector<InvokeSet*> lookupInvokeSets(ObjectPtr callable) {
+ assert(invokeTablesInitialized);
+ vector<InvokeSet*> r;
+ for (size_t i = 0; i < invokeTable.size(); ++i) {
+ for (size_t j = 0; j < invokeTable[i].size(); ++j) {
+ InvokeSet* set = invokeTable[i][j];
+ if (objectEquals(set->callable, callable)) {
+ r.push_back(set);
+ }
+ }
+ }
+ return r;
+}
//
View
1 compiler/invoketables.hpp
@@ -105,6 +105,7 @@ struct MatchFailureError {
InvokeSet *lookupInvokeSet(ObjectPtr callable,
llvm::ArrayRef<TypePtr> argsKey);
+vector<InvokeSet*> lookupInvokeSets(ObjectPtr callable);
InvokeEntry* lookupInvokeEntry(ObjectPtr callable,
llvm::ArrayRef<TypePtr> argsKey,
llvm::ArrayRef<ValueTempness> argsTempness,

0 comments on commit 4ce8ec5

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