Permalink
Browse files

Initial commit. Basic JIT repl with interpreter mode

No optimization, grammar is limited to mathematical expressions.

Also includes some matrix code which will eventually be part of
the runtime, but not yet.

Also includes some nanojit support, likely never to be used, but
keeping my options open.

AST is templated which I am still trying to decide if that is a
mistake or not...Likely to be removed, especially since I should
really be converting it to SSA, meaning the AST itself likely
doesn't need any resolution (its not strongly typed, etc)

Main file just provides repl support and a no-iteration loop used
for basic profiling.
  • Loading branch information...
MichaelRFairhurst committed Feb 1, 2017
0 parents commit 91ca0464b9f96106f3050cc437f332bc8a67d30e
@@ -0,0 +1,4 @@
*.o
main
*.swp
*.dSYM
16 README
@@ -0,0 +1,16 @@
Installing:
```
git clone https://github.com/asmjit/asmjit.git
```
Probably won't keep using nanojit, but if so, here's some steps:
```
git clone https://github.com/doublec/nanojit-central.git
cd nanojit-central
autoconf
./configure
make
```
I did have to mess with the build here a bit: I removed -Wall from the resulting build file and had to add a pragma in clang to ignore NULL checks on the this pointer.
27 app.cpp
@@ -0,0 +1,27 @@
#include "matrix.h"
#include "stdio.h"
using namespace vaiven;
int main() {
Matrix mainWindow(10, 3);
mainWindow.printMany(fromStr("Hello world!"));
mainWindow.move(0, 2);
StyledChar a('a');
StyledChar b('b');
mainWindow.print(a);
mainWindow.write(a);
mainWindow.print(b);
mainWindow.writeMany(fromStr("Hello world again!"));
mainWindow.printMany(fromStr("overwrite all but"));
mainWindow.cursor += 5;
mainWindow.writeMany(fromStr("Goodbye world!"));
for(int i = 0; i < mainWindow.cols * mainWindow.rows; ++i) {
putchar(mainWindow.data[i].theChar);
if (i % mainWindow.cols == mainWindow.cols - 1) {
putchar('\n');
}
}
}
@@ -0,0 +1,7 @@
#include "addition_expression.h"
using namespace vaiven::ast;
//void AdditionExpression::accept(Visitor& v) {
// v.visitAdditionExpression(*this);
//}
@@ -0,0 +1,31 @@
#ifndef VAIVEN_AST_HEADER_ADDITION_EXPRESSION
#define VAIVEN_AST_HEADER_ADDITION_EXPRESSION
#include <memory>
#include "expression.h"
using std::unique_ptr;
namespace vaiven { namespace ast {
template<typename ResolvedData=void>
class AdditionExpression : public Expression<ResolvedData> {
public:
AdditionExpression(
unique_ptr<Expression<ResolvedData> > left,
unique_ptr<Expression<ResolvedData> > right)
: left(std::move(left)), right(std::move(right)) {};
void accept(Visitor<ResolvedData>& v) {
v.visitAdditionExpression(*this);
}
virtual ~AdditionExpression() {};
unique_ptr<Expression<ResolvedData> > left;
unique_ptr<Expression<ResolvedData> > right;
};
}}
#endif
@@ -0,0 +1,5 @@
#include "addition_expression.h"
#include "subtraction_expression.h"
#include "multiplication_expression.h"
#include "division_expression.h"
#include "integer_expression.h"
@@ -0,0 +1,7 @@
#include "division_expression.h"
using namespace vaiven::ast;
//void DivisionExpression::accept(Visitor& v) {
// v.visitDivisionExpression(*this);
//}
@@ -0,0 +1,31 @@
#ifndef VAIVEN_AST_HEADER_DIVISION_EXPRESSION
#define VAIVEN_AST_HEADER_DIVISION_EXPRESSION
#include <memory>
#include "expression.h"
using std::unique_ptr;
namespace vaiven { namespace ast {
template<typename ResolvedData=void>
class DivisionExpression : public Expression<ResolvedData> {
public:
DivisionExpression(
unique_ptr<Expression<ResolvedData> > left,
unique_ptr<Expression<ResolvedData> > right)
: left(std::move(left)), right(std::move(right)) {};
void accept(Visitor<ResolvedData>& v) {
v.visitDivisionExpression(*this);
}
virtual ~DivisionExpression() {};
unique_ptr<Expression<ResolvedData> > left;
unique_ptr<Expression<ResolvedData> > right;
};
}}
#endif
@@ -0,0 +1,18 @@
#ifndef VAIVEN_AST_HEADER_EXPRESSION
#define VAIVEN_AST_HEADER_EXPRESSION
#include "node.h"
namespace vaiven { namespace ast {
// nothing yet
template<typename ResolvedData=void>
class Expression : public Node<ResolvedData> {
public:
void accept(Visitor<ResolvedData>& v)=0;
virtual ~Expression() {};
};
}}
#endif
@@ -0,0 +1,7 @@
#include "integer_expression.h"
using namespace vaiven::ast;
//void IntegerExpression::accept(Visitor& v) {
// v.visitIntegerExpression(*this);
//}
@@ -0,0 +1,27 @@
#ifndef VAIVEN_AST_HEADER_INTEGER_EXPRESSION
#define VAIVEN_AST_HEADER_INTEGER_EXPRESSION
#include <memory>
#include "expression.h"
using std::unique_ptr;
namespace vaiven { namespace ast {
template<typename ResolvedData>
class IntegerExpression : public Expression<ResolvedData> {
public:
IntegerExpression(int value) : value(value) {};
void accept(Visitor<ResolvedData>& v) {
v.visitIntegerExpression(*this);
}
virtual ~IntegerExpression() {};
int value;
};
}}
#endif
@@ -0,0 +1,7 @@
#include "multiplication_expression.h"
using namespace vaiven::ast;
//void MultiplicationExpression::accept(Visitor& v) {
// v.visitMultiplicationExpression(*this);
//}
@@ -0,0 +1,31 @@
#ifndef VAIVEN_AST_HEADER_MULTIPLICATION_EXPRESSION
#define VAIVEN_AST_HEADER_MULTIPLICATION_EXPRESSION
#include <memory>
#include "expression.h"
using std::unique_ptr;
namespace vaiven { namespace ast {
template<typename ResolvedData=void>
class MultiplicationExpression : public Expression<ResolvedData> {
public:
MultiplicationExpression(
unique_ptr<Expression<ResolvedData> > left,
unique_ptr<Expression<ResolvedData> > right)
: left(std::move(left)), right(std::move(right)) {};
void accept(Visitor<ResolvedData>& v) {
v.visitMultiplicationExpression(*this);
}
virtual ~MultiplicationExpression() {};
unique_ptr<Expression<ResolvedData> > left;
unique_ptr<Expression<ResolvedData> > right;
};
}}
#endif
@@ -0,0 +1,19 @@
#ifndef VAIVEN_AST_HEADER_NODE
#define VAIVEN_AST_HEADER_NODE
#include "visitor.h"
namespace vaiven { namespace ast {
template<typename ResolvedData=void>
class Node {
public:
virtual void accept(Visitor<ResolvedData>& v)=0;
virtual ~Node() {};
ResolvedData resolvedData;
};
}}
#endif
@@ -0,0 +1,7 @@
#include "subtraction_expression.h"
using namespace vaiven::ast;
//void SubtractionExpression::accept(Visitor& v) {
// v.visitSubtractionExpression(*this);
//}
@@ -0,0 +1,31 @@
#ifndef VAIVEN_AST_HEADER_SUBTRACTION_EXPRESSION
#define VAIVEN_AST_HEADER_SUBTRACTION_EXPRESSION
#include <memory>
#include "expression.h"
using std::unique_ptr;
namespace vaiven { namespace ast {
template<typename ResolvedData=void>
class SubtractionExpression : public Expression<ResolvedData> {
public:
SubtractionExpression(
unique_ptr<Expression<ResolvedData> > left,
unique_ptr<Expression<ResolvedData> > right)
: left(std::move(left)), right(std::move(right)) {};
void accept(Visitor<ResolvedData>& v) {
v.visitSubtractionExpression(*this);
}
virtual ~SubtractionExpression() {};
unique_ptr<Expression<ResolvedData> > left;
unique_ptr<Expression<ResolvedData> > right;
};
}}
#endif
@@ -0,0 +1,33 @@
#ifndef VAIVEN_AST_HEADER_VISITOR
#define VAIVEN_AST_HEADER_VISITOR
namespace vaiven { namespace ast {
template<typename ResolvedData>
class Node;
template<typename ResolvedData>
class AdditionExpression;
template<typename ResolvedData>
class SubtractionExpression;
template<typename ResolvedData>
class MultiplicationExpression;
template<typename ResolvedData>
class DivisionExpression;
template<typename ResolvedData>
class IntegerExpression;
template<typename ResolvedData>
class Visitor {
public:
virtual void visitAdditionExpression(AdditionExpression<ResolvedData>& expr)=0;
virtual void visitSubtractionExpression(SubtractionExpression<ResolvedData>& expr)=0;
virtual void visitMultiplicationExpression(MultiplicationExpression<ResolvedData>& expr)=0;
virtual void visitDivisionExpression(DivisionExpression<ResolvedData>& expr)=0;
virtual void visitIntegerExpression(IntegerExpression<ResolvedData>& expr)=0;
};
}}
#endif
@@ -0,0 +1,37 @@
#ifndef VAIVEN_VISITOR_HEADER_LOCATION
#define VAIVEN_VISITOR_HEADER_LOCATION
#include "asmjit/src/asmjit/asmjit.h"
namespace vaiven {
enum LocationType {
LOCATION_TYPE_REG,
LOCATION_TYPE_IMM,
LOCATION_TYPE_SPILLED,
};
typedef union {
asmjit::X86Gp* reg;
int imm;
} LocationDataUnion;
class Location {
public:
Location(asmjit::X86Gp* reg) : data(), type(LOCATION_TYPE_REG) {
data.reg = reg;
}
Location(int imm) : data(), type(LOCATION_TYPE_IMM) {
data.imm = imm;
}
Location() : data(), type(LOCATION_TYPE_SPILLED) {}
LocationType type;
LocationDataUnion data;
};
}
#endif
Oops, something went wrong.

0 comments on commit 91ca046

Please sign in to comment.