Skip to content

Commit

Permalink
Major performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
psde committed Dec 14, 2013
1 parent 9e53d3d commit 6c82b92
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 149 deletions.
2 changes: 1 addition & 1 deletion src/codepeiler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int main(int argc, char *argv[])
std::cout << "done." << std::endl;

std::cout << "Generating code... " << std::endl;
*out << tree->makeCode() << std::endl;
tree->makeCode(out);

/*Token token;
while(lexerOut && true)
Expand Down
3 changes: 2 additions & 1 deletion src/libLexer/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ String LexerStateStrings[] =
Lexer::Lexer(BufferReader *buffer)
{
this->buffer = buffer;
this->symtable = new Symtable(4096);
//this->symtable = new Symtable(4096);
this->symtable = new Symtable(32);
this->setup();

this->pos.line = 1;
Expand Down
44 changes: 24 additions & 20 deletions src/libParser/ParseTree.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <iostream>

#include <libStd/String.hpp>
#include <libStd/Vector.hpp>
#include <libLexer/Token.hpp>
Expand All @@ -11,7 +13,9 @@ class ParseTree
protected:

public:
virtual String makeCode() = 0;
virtual ~ParseTree()
{}
virtual void makeCode(std::ostream *out) = 0;
virtual String dump() = 0;
virtual String typeCheck() = 0;
};
Expand Down Expand Up @@ -50,7 +54,7 @@ class Decl : public IdentifierParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Decls : public ParseTree
Expand All @@ -68,7 +72,7 @@ class Decls : public ParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Op : public ParseTree
Expand All @@ -95,7 +99,7 @@ class Op : public ParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Exp;
Expand All @@ -116,7 +120,7 @@ class OpExp : public ParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Index : public ParseTree
Expand All @@ -133,7 +137,7 @@ class Index : public ParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Exp2 : public ParseTree
Expand All @@ -155,7 +159,7 @@ class Exp2_1 : public Exp2

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

/* identifier INDEX */
Expand All @@ -175,7 +179,7 @@ class Exp2_2 : public Exp2, public IdentifierParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

/* integer */
Expand All @@ -192,7 +196,7 @@ class Exp2_3 : public Exp2

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

/* - EXP2 */
Expand All @@ -211,7 +215,7 @@ class Exp2_4 : public Exp2

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

/* ! EXP2 */
Expand All @@ -230,7 +234,7 @@ class Exp2_5 : public Exp2

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Exp : public ParseTree
Expand All @@ -254,7 +258,7 @@ class Exp : public ParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Statement : public ParseTree
Expand All @@ -281,7 +285,7 @@ class Statement_1 : public Statement, public IdentifierParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

/* print ( EXP ) */
Expand All @@ -300,7 +304,7 @@ class Statement_2 : public Statement

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

/* read ( identifier INDEX )*/
Expand All @@ -313,7 +317,7 @@ class Statement_3 : public Statement, public IdentifierParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Statements;
Expand All @@ -332,7 +336,7 @@ class Statement_4 : public Statement

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

/* if ( EXP ) STATEMENT else STATEMENT */
Expand All @@ -357,7 +361,7 @@ class Statement_5 : public Statement

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

/* while ( EXP ) statement */
Expand All @@ -382,7 +386,7 @@ class Statement_6 : public Statement

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Statements : public ParseTree
Expand All @@ -399,7 +403,7 @@ class Statements : public ParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};

class Prog : public ParseTree
Expand All @@ -420,5 +424,5 @@ class Prog : public ParseTree

String dump();
String typeCheck();
String makeCode();
void makeCode(std::ostream *out);
};
2 changes: 1 addition & 1 deletion src/libParser/ParseTreeDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ String OpExp::dump()

String Op::dump()
{
String items[] = { "+", "-", "*", "/", "<", "=", ">", "<=>", "&", "!" };
static String items[] = { "+", "-", "*", "/", "<", "=", ">", "<=>", "&", "!" };

String str = " ";
str += items[this->type];
Expand Down
Loading

0 comments on commit 6c82b92

Please sign in to comment.