Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ashish-auroraAR committed Jul 5, 2017
2 parents 45da6cd + abcfa08 commit 480d271
Show file tree
Hide file tree
Showing 35 changed files with 1,110 additions and 203 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ PineconeBin
Pinecone
pinecone

#KDevelop
.kdev4

# stupid OSX stuff
*.DS_Store
1 change: 1 addition & 0 deletions codeblocks/Pinecone.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
</Target>
</Build>
<Compiler>
<Add option="-O" />
<Add option="-Wall" />
<Add option="-std=c++11" />
<Add option="-fexceptions" />
Expand Down
7 changes: 5 additions & 2 deletions h/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>
#include <vector>
#include <string>
#include "utils/stringDrawing.h"


#include <stdlib.h> // malloc() and free() on some systems
Expand Down Expand Up @@ -84,7 +85,7 @@ Action orAction(Action firstActionIn, Action secondActionIn);
Action ifAction(Action conditionIn, Action ifActionIn);
Action ifElseAction(Action conditionIn, Action ifActionIn, Action elseAction);

Action listAction(const std::vector<Action>& actionsIn);
Action listAction(const std::vector<Action>& actionsIn, const std::vector<Action>& destroyersIn);

Action loopAction(Action conditionIn, Action loopActionIn);
Action loopAction(Action conditionIn, Action endActionIn, Action loopActionIn);
Expand All @@ -98,7 +99,9 @@ Action varGetAction(size_t in, Type typeIn, string idIn);
Action varSetAction(size_t in, Type typeIn, string idIn);
Action globalGetAction(size_t in, Type typeIn, string idIn);
Action globalSetAction(size_t in, Type typeIn, string idIn);
Action constGetAction(const void* in, Type typeIn, string idIn);

class NamespaceData;
Action constGetAction(const void* in, Type typeIn, string idIn, shared_ptr<NamespaceData> ns);

Action typeGetAction(Type typeIn);

16 changes: 16 additions & 0 deletions h/Namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ class NamespaceData: public std::enable_shared_from_this<NamespaceData>
// returns UnknownType if it cant find the requested type
Type getType(string name, bool throwSourceError, Token tokenForError);

// returns the destructor of the given type, or nullptr if there isn't one
Action getDestroyer(Type type);

// returns the copier of the given type, or nullptr if there isn't one
Action getCopier(Type type);

// returns an action that takes the input types
// on error, it will throw a source error if throwSourceError is true. otherwise, it will return nullptr
Action getActionForTokenWithInput(Token token, Type left, Type right, bool dynamic, bool throwSourceError, Token tokenForError);

vector<Action>* getDestroyerActions() {return &destructorActions;}
Action wrapInDestroyer(Action in);

private:

Expand Down Expand Up @@ -101,5 +109,13 @@ class NamespaceData: public std::enable_shared_from_this<NamespaceData>

// contains all types in this namespace
IdMap types;

// contains destructors for types, the key string is a pointer to the type fed through ptrToUniqueStr with 6 digits
//IdMap destructors;

// like destructors, but for making copies
//IdMap copiers;

vector<Action> destructorActions;
};

1 change: 1 addition & 0 deletions h/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TokenData
typedef shared_ptr<TokenData> Token;

Token makeToken(string textIn, shared_ptr<SourceFile> fileIn, int lineIn, int charPosIn, TokenData::Type tokenTypeIn, Operator opIn=Operator(nullptr));
Token makeToken(string textIn);

string stringFromTokens(const vector<Token>& tokens, int left, int right);
string tableStringFromTokens(const vector<Token>& tokens, string tableName);
12 changes: 11 additions & 1 deletion h/utils/stringDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ namespace str
// if max width is -1, it will autodetect
string getBoxedString(const string& in, string boxName="", bool showLineNums=false, bool alwaysWidthMax=false, int maxWidth=-1);

string makeTreeSection(const string& root, vector<string>& leaves);
// it is assumed that the data is already padded
void putArrayInTreeNodeBox(vector<string>& data);

string putStringInTreeNodeBox(const string& in);

// note that the input may have newlines in each element
string makeList(vector<string>& data);

string makeRootUpBinaryTree(const string& root, const string& leftBranch, const string& rightBranch, const string& leftLeaf, const string& rightLeaf);

//string makeTreeSection(const string& root, vector<string>& leaves);

}

8 changes: 6 additions & 2 deletions h/utils/stringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ inline int seek(const string& in, int distGlyph, int startPosByte=0);
// currently is a straight equals, but in the future could do things such as evaluate strings with different types of newlines to equal
inline bool subMatches(const string& in, int posBytes, const string& sub);

// if endGlyph is -1 it takes till the end of the string
inline string sub(const string& in, int startGlyph, int endGlyph);

inline bool matches(const string& a, const string& b);
Expand All @@ -33,6 +34,9 @@ inline bool hasSuffix(const string& in, const string& suffix);
// returns the BYTE location (not glyph location), or -1 if pattern doesn't appear
//int searchFor(const string& in, string pattern, int startByte);

// returns the glyph position of the first occurrence of pattern, or -1 if it doesn't appear
int getGlyphPosOf(const string& in, string pattern);

string tabsToSpaces(const string& in, int tabWidth=4);

enum StringPadAlignment {ALIGNMENT_LEFT=1, ALIGNMENT_CENTER=0, ALIGNMENT_RIGHT=-1};
Expand Down Expand Up @@ -96,8 +100,8 @@ inline bool subMatches(const string& in, int posBytes, const string& sub)
inline string sub(const string& in, int startGlyph, int endGlyph)
{
int startByte=seek(in, startGlyph);
int endByte=seek(in, endGlyph-startGlyph, startByte);
return in.substr(startByte, startByte-endByte);
int endByte=(endGlyph < 0 ? (int)in.size() : seek(in, endGlyph-startGlyph, startByte));
return in.substr(startByte, endByte-startByte);
}

inline bool matches(const string& a, const string& b)
Expand Down
1 change: 1 addition & 0 deletions other/pinecone.pn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


cppHead: "#include <iostream>"
cppHead: "using std::cout;"
cppHead: "using std::endl;"
Expand Down
10 changes: 10 additions & 0 deletions other/pinecone.pn~
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


cppHead: "#include <iostream>"
cppHead: "using std::cout;"
cppHead: "using std::endl;"

a: 9
cppCode: "cout << a << endl;"
cppCode: "a = 2;"
print: a
10 changes: 10 additions & 0 deletions src/Actions/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class VoidAction: public ActionData
if (prog->getExprLevel()>0)
prog->comment("void");
}

string getDescription()
{
return str::putStringInTreeNodeBox("void");
}
};

class LambdaAction: public ActionData
Expand Down Expand Up @@ -98,6 +103,11 @@ class LambdaAction: public ActionData
cppWriter(inLeft, inRight, prog);
}

string getDescription()
{
return str::putStringInTreeNodeBox(description);
}

private:
function<void*(void*,void*)> lambda;
function<void(Action inLeft, Action inRight, CppProgram* prog)> cppWriter;
Expand Down
6 changes: 4 additions & 2 deletions src/Actions/BoolOpAction.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../../h/Action.h"
#include "../../h/ErrorHandler.h"
#include "../../h/utils/stringDrawing.h"

class AndAction: public ActionData
{
Expand All @@ -24,7 +25,8 @@ class AndAction: public ActionData

string getDescription()
{
return firstAction->getDescription() + " && " + firstAction->getDescription();
return str::makeRootUpBinaryTree("&&", firstAction->getReturnType()->getName(), secondAction->getReturnType()->getName(), firstAction->getDescription(), secondAction->getDescription());
//return firstAction->getDescription() + " && " + firstAction->getDescription();
}

void* execute(void* inLeft, void* inRight)
Expand Down Expand Up @@ -92,7 +94,7 @@ class OrAction: public ActionData

string getDescription()
{
return firstAction->getDescription() + " || " + firstAction->getDescription();
return str::makeRootUpBinaryTree("||", firstAction->getReturnType()->getName(), secondAction->getReturnType()->getName(), firstAction->getDescription(), secondAction->getDescription());
}

void* execute(void* inLeft, void* inRight)
Expand Down
10 changes: 7 additions & 3 deletions src/Actions/BranchAction.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../../h/Action.h"
#include "../../h/ErrorHandler.h"
#include "../../h/CppProgram.h"
#include "../../h/utils/stringDrawing.h"

class BranchAction: public ActionData
{
Expand Down Expand Up @@ -46,8 +47,9 @@ class BranchAction: public ActionData
{
if (leftInput && action && rightInput)
{
return str::makeRootUpBinaryTree(action->getDescription(), leftInput->getReturnType()->getName(), rightInput->getReturnType()->getName(), leftInput->getDescription(), rightInput->getDescription());
//return getReturnType()->toString() + " <- [" + leftInput->getDescription() + "].[" + action->getDescription() + "]:[" + rightInput->getDescription() + "]";
return "(" + leftInput->getDescription() + " -> " + action->getDescription() + " <- " + rightInput->getDescription() + ")";
//return "(" + leftInput->getDescription() + " -> " + action->getDescription() + " <- " + rightInput->getDescription() + ")";
//return getReturnType()->getName() + " <- " + leftInput->getDescription() + "." + action->getDescription() + ":" + rightInput->getDescription();
}
else
Expand Down Expand Up @@ -119,8 +121,9 @@ class RightBranchAction: public ActionData
{
if (action && rightInput)
{
return str::makeRootUpBinaryTree(action->getDescription(), "", rightInput->getReturnType()->getName(), "", rightInput->getDescription());
//return getReturnType()->toString() + " <- [" + leftInput->getDescription() + "].[" + action->getDescription() + "]:[" + rightInput->getDescription() + "]";
return "(" + action->getDescription() + " <- " + rightInput->getDescription() + ")";
//return "(" + action->getDescription() + " <- " + rightInput->getDescription() + ")";
//return getReturnType()->getName() + " <- " + leftInput->getDescription() + "." + action->getDescription() + ":" + rightInput->getDescription();
}
else
Expand Down Expand Up @@ -180,8 +183,9 @@ class LeftBranchAction: public ActionData
{
if (leftInput && action)
{
return str::makeRootUpBinaryTree(action->getDescription(), leftInput->getReturnType()->getName(), "", leftInput->getDescription(), "");
//return getReturnType()->toString() + " <- [" + leftInput->getDescription() + "].[" + action->getDescription() + "]:[" + rightInput->getDescription() + "]";
return "(" + leftInput->getDescription() + " -> " + action->getDescription() + ")";
//return "(" + leftInput->getDescription() + " -> " + action->getDescription() + ")";
//return getReturnType()->getName() + " <- " + leftInput->getDescription() + "." + action->getDescription() + ":" + rightInput->getDescription();
}
else
Expand Down
17 changes: 11 additions & 6 deletions src/Actions/FunctionAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class FunctionAction: public ActionData

if (!returnType->isVoid() && !returnType->matches(action->getReturnType()))
{
throw PineconeError("function body returns "+action->getReturnType()->getString()+" instead of "+returnType->getString(), SOURCE_ERROR, node->getToken());
// the objects that are being returned are being destroyed before the function exits
// also another problem: if a function returns a thing but nothing accepts the output, the destructor is not called
//throw PineconeError("function body returns "+action->getReturnType()->getString()+" instead of "+returnType->getString(), SOURCE_ERROR, node->getToken());
throw PineconeError("function body returns "+action->getReturnType()->getString()+" instead of "+returnType->getString()+"\n"+action->getDescription(), SOURCE_ERROR, node->getToken());
}

if (!action->getInLeftType()->isVoid() || !action->getInRightType()->isVoid())
Expand All @@ -60,9 +63,10 @@ class FunctionAction: public ActionData

string getDescription()
{
if (!action)
resolveAction();
return "func: " + description;//action->getDescription();
return str::putStringInTreeNodeBox("call func "+nameHint);
//if (!action)
// resolveAction();
//return "func: " + description;//action->getDescription();
}

bool isFunction() {return true;}
Expand Down Expand Up @@ -130,6 +134,7 @@ class FunctionAction: public ActionData
prog->name(name);

prog->pushExpr();
/*
bool hasStarted=false;
if (getInLeftType()->getType()==TypeBase::TUPLE)
{
Expand Down Expand Up @@ -176,8 +181,8 @@ class FunctionAction: public ActionData
}
//prog->code(", ");
//inRight->addToProg(prog);
*/

/*
if (getInLeftType()->isCreatable())
{
inLeft->addToProg(prog);
Expand All @@ -187,9 +192,9 @@ class FunctionAction: public ActionData
{
if (getInLeftType()->isCreatable())
prog->code(", ");

inRight->addToProg(prog);
}
*/

prog->popExpr();

Expand Down
7 changes: 5 additions & 2 deletions src/Actions/IfAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class IfAction: public ActionData

string getDescription()
{
return "if " + condition->getDescription() + " then " + ifAction->getDescription();
return str::makeRootUpBinaryTree("?", condition->getReturnType()->getName(), "", condition->getDescription(), ifAction->getDescription());
//return "if " + condition->getDescription() + " then " + ifAction->getDescription();
}

void* execute(void* inLeft, void* inRight)
Expand Down Expand Up @@ -91,7 +92,9 @@ class IfElseAction: public ActionData

string getDescription()
{
return "if " + condition->getDescription() + " then " + ifAction->getDescription();
string branch=str::makeRootUpBinaryTree("╭┴╮\n│ │", "fls", "tru", elseAction->getDescription(), ifAction->getDescription());
return str::makeRootUpBinaryTree("?", condition->getReturnType()->getName(), "", condition->getDescription(), branch);
//return "if " + condition->getDescription() + " then " + ifAction->getDescription();
}

/*
Expand Down
Loading

0 comments on commit 480d271

Please sign in to comment.