Skip to content

Commit

Permalink
update and fix some problems with memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
meepen committed Jul 12, 2021
1 parent 6566138 commit 6f233bb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
3 changes: 0 additions & 3 deletions src/parser/chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ void chunk::initialize(lexer &lex) {
if (dynamic_cast<parser::statement *>(statement)->isfinal()) {
break;
}
lex.skipwhite();
}

lex.skipwhite();
}

LORELAI_ACCEPT_BRANCH(chunk)
14 changes: 7 additions & 7 deletions src/parser/expressions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace lorelai {
}

public:
node *lhs, *rhs;
node *lhs = nullptr, *rhs = nullptr;
string op;
};

Expand All @@ -227,7 +227,7 @@ namespace lorelai {
}

public:
node *expr;
node *expr = nullptr;
string op;
};

Expand All @@ -246,9 +246,9 @@ namespace lorelai {
}

public:
node *funcexpr;
node *funcexpr = nullptr;
optional<string> methodname { };
node *arglist;
node *arglist = nullptr;
};

class indexexpression : public branch, public varexpression {
Expand All @@ -267,7 +267,7 @@ namespace lorelai {
}

public:
node *prefix, *index;
node *prefix = nullptr, *index = nullptr;
};

class dotexpression : public branch, public varexpression {
Expand All @@ -284,7 +284,7 @@ namespace lorelai {
}

public:
node *prefix;
node *prefix = nullptr;
string index;
};

Expand All @@ -301,7 +301,7 @@ namespace lorelai {
}

public:
node *body;
node *body = nullptr;
};

}
Expand Down
11 changes: 3 additions & 8 deletions src/parser/statements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ const static std::unordered_map<string, node *(*)(lexer &lex)> lookupmap = {
{ "local", [](lexer &lex) -> node * {
lex.expect("local", "local deducer");
auto ahead = lex.lookahead();
if (ahead) {
if (ahead.value() == "function") {
return new localfunctionstatement(lex);
}
else {
return new localassignmentstatement(lex);
}
if (ahead && ahead.value() == "function") {
return new localfunctionstatement(lex);
}

return nullptr;
return new localassignmentstatement(lex);
} },
{ "for", [](lexer &lex) -> node * {
lex.expect("for", "for deducer");
Expand Down
28 changes: 19 additions & 9 deletions src/parser/statements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace lorelai {
virtual ~blockstatement() { destroy(); }

public:
node *block;
node *block = nullptr;
};

class loopstatement : public blockstatement {
Expand All @@ -56,7 +56,7 @@ namespace lorelai {
}

public:
node *conditional;
node *conditional = nullptr;
};

namespace statements {
Expand Down Expand Up @@ -89,6 +89,7 @@ namespace lorelai {
dostatement() { }
public:
dostatement(lexer &lex);
virtual ~dostatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand All @@ -97,6 +98,7 @@ namespace lorelai {
class whilestatement : public loopstatement {
public:
whilestatement(lexer &lex);
virtual ~whilestatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand All @@ -105,6 +107,7 @@ namespace lorelai {
class repeatstatement : public loopstatement {
public:
repeatstatement(lexer &lex);
virtual ~repeatstatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand Down Expand Up @@ -136,6 +139,7 @@ namespace lorelai {
class localfunctionstatement : public blockstatement {
public:
localfunctionstatement(lexer &lex);
virtual ~localfunctionstatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand All @@ -145,12 +149,13 @@ namespace lorelai {
}

public:
node *name;
node *name = nullptr;
};

class fornumstatement : public loopstatement {
public:
fornumstatement(string name, lexer &lex);
virtual ~fornumstatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand All @@ -170,12 +175,13 @@ namespace lorelai {

public:
string itername;
node *startexpr, *endexpr, *stepexpr;
node *startexpr = nullptr, *endexpr = nullptr, *stepexpr = nullptr;
};

class forinstatement : public loopstatement {
public:
forinstatement(string name, lexer &lex);
virtual ~forinstatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand Down Expand Up @@ -210,6 +216,7 @@ namespace lorelai {
class ifstatement : public blockstatement {
public:
ifstatement(lexer &lex);
virtual ~ifstatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand All @@ -230,14 +237,15 @@ namespace lorelai {
}

public:
node *conditional;
node *elseblock;
node *conditional = nullptr;
node *elseblock = nullptr;
std::vector<node *> elseifs;
};

class elseifstatement : public blockstatement {
public:
elseifstatement(lexer &lex);
virtual ~elseifstatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand All @@ -247,12 +255,13 @@ namespace lorelai {
}

public:
node *conditional;
node *conditional = nullptr;
};

class elsestatement : public blockstatement {
public:
elsestatement(lexer &lex);
virtual ~elsestatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand All @@ -261,6 +270,7 @@ namespace lorelai {
class functionstatement : public blockstatement {
public:
functionstatement(lexer &lex);
virtual ~functionstatement() { destroy(); }

void accept(visitor &visit, node *&container) override;
string tostring() override;
Expand All @@ -270,7 +280,7 @@ namespace lorelai {
}

public:
node *name;
node *name = nullptr;
optional<string> method;
};

Expand All @@ -287,7 +297,7 @@ namespace lorelai {
}

public:
node *callexpr;
node *callexpr = nullptr;
};

class assignmentstatement : public branch, public statement {
Expand Down
2 changes: 1 addition & 1 deletion tests/speedtest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ print [[-- The Computer Language Shootout
-- http://shootout.alioth.debian.org/
-- contributed by Mike Pall]]

local width = 2000
local width = 22
local height, wscale = width, 2/width
local m, limit2 = 50, 4.0
local write = io.write
Expand Down

0 comments on commit 6f233bb

Please sign in to comment.