Skip to content

Commit

Permalink
refactor parseInteractive
Browse files Browse the repository at this point in the history
  • Loading branch information
galchinsky committed Nov 25, 2012
1 parent 6f62bc2 commit 67017c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
11 changes: 4 additions & 7 deletions compiler/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,11 @@ namespace clay {
replCommand(line.substr(1, line.size() - 1));
} else {
SourcePtr source = new Source(line, 0);
vector<StatementPtr> stmts;
vector<TopLevelItemPtr> toplevels;
vector<ImportPtr> imports;
try {
parseInteractive(source, 0, source->size(), toplevels, imports, stmts);
loadImports(imports);
jitTopLevel(toplevels);
jitStatements(stmts);
ReplItem x = parseInteractive(source, 0, source->size());
loadImports(x.imports);
jitTopLevel(x.toplevels);
jitStatements(x.stmts);
}
catch (CompilerError) {
continue;
Expand Down
19 changes: 4 additions & 15 deletions compiler/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3110,13 +3110,7 @@ static bool module(llvm::StringRef moduleName, ModulePtr &x) {
// REPL
//

struct REPLitem {
vector<TopLevelItemPtr> toplevels;
vector<ImportPtr> imports;
vector<StatementPtr> stmts;
};

static bool replItems(REPLitem& x, bool = false) {
static bool replItems(ReplItem& x, bool = false) {
x.toplevels.clear();
x.imports.clear();
x.stmts.clear();
Expand Down Expand Up @@ -3244,16 +3238,11 @@ void parseTopLevelItems(SourcePtr source, int offset, int length,
// parseInteractive
//

void parseInteractive(SourcePtr source, int offset, int length,
vector<TopLevelItemPtr>& toplevels,
vector<ImportPtr>& imports,
vector<StatementPtr>& stmts)
ReplItem parseInteractive(SourcePtr source, int offset, int length)
{
REPLitem x;
ReplItem x;
applyParser(source, offset, length, replItems, false, x);
toplevels = x.toplevels;
imports = x.imports;
stmts = x.stmts;
return x;
}

}
11 changes: 7 additions & 4 deletions compiler/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ enum ParserFlags
ParserKeepDocumentation = 1
};

struct ReplItem {
vector<TopLevelItemPtr> toplevels;
vector<ImportPtr> imports;
vector<StatementPtr> stmts;
};

ModulePtr parse(llvm::StringRef moduleName, SourcePtr source, ParserFlags flags = NoParserFlags);
ExprPtr parseExpr(SourcePtr source, int offset, int length);
ExprListPtr parseExprList(SourcePtr source, int offset, int length);
void parseStatements(SourcePtr source, int offset, int length,
vector<StatementPtr> &statements);
void parseTopLevelItems(SourcePtr source, int offset, int length,
vector<TopLevelItemPtr> &topLevels, Module *);
void parseInteractive(SourcePtr source, int offset, int length,
vector<TopLevelItemPtr>& toplevels,
vector<ImportPtr>& imports,
vector<StatementPtr>& stmts);
ReplItem parseInteractive(SourcePtr source, int offset, int length);

typedef vector<Token>(*AddTokensCallback)();
void setAddTokens(AddTokensCallback f);
Expand Down

0 comments on commit 67017c3

Please sign in to comment.