├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── ast
├── addition_expression.h
├── all.h
├── assignment_expression.h
├── block.h
├── bool_literal.h
├── division_expression.h
├── double_expression.h
├── dynamic_access_expression.h
├── dynamic_store_expression.h
├── equality_expression.h
├── expression.h
├── expression_statement.h
├── for_cond.h
├── func_call_expression.h
├── funcdecl.h
├── gt_expression.h
├── gte_expression.h
├── if_statement.h
├── inequality_expression.h
├── integer_expression.h
├── list_literal_expression.h
├── lt_expression.h
├── lte_expression.h
├── multiplication_expression.h
├── node.h
├── not_expression.h
├── pre_assignment_op.h
├── return_statement.h
├── statement.h
├── static_access_expression.h
├── static_store_expression.h
├── string_expression.h
├── subtraction_expression.h
├── var_decl.h
├── variable_expression.h
├── visitor.h
└── void_literal.h
├── bench
├── bench.sh
├── fib_45.dart
├── fib_45.js
├── fib_45.vvn.sh
├── loop_empty.js
├── loop_empty_cc.vvn.sh
├── loop_empty_hot.vvn.sh
├── loop_empty_interp.vvn.sh
├── loop_with_function_cc.vvn.sh
├── loop_with_function_hot.vvn.sh
├── loop_with_function_interp.vvn.sh
├── loop_with_garbagemem.js
├── loop_with_garbagemem_cc.vvn.sh
├── loop_with_ops_cc.vvn.sh
├── loop_with_ops_hot.vvn.sh
├── loop_with_ops_interp.vvn.sh
├── lowest_common_factor.js
├── lowest_common_factor.vvn
├── recurse_with_ops.vvn.sh
└── repeat_functions.vvn.sh
├── error_compiler.cpp
├── error_compiler.h
├── firstcompile.cpp
├── firstcompile.h
├── function_usage.h
├── functions.h
├── heap.cpp
├── heap.h
├── main.cpp
├── makefile
├── optimize.cpp
├── optimize.h
├── parser.cpp
├── parser.h
├── runtime_error.cpp
├── runtime_error.h
├── scope.h
├── ssa
├── cfg.h
├── common_subexpression.cpp
├── common_subexpression.h
├── constant_inliner.cpp
├── constant_inliner.h
├── constant_propagation.cpp
├── constant_propagation.h
├── dominator_builder.cpp
├── dominator_builder.h
├── emitter.cpp
├── emitter.h
├── forward_visitor.cpp
├── forward_visitor.h
├── function_merge.cpp
├── function_merge.h
├── inliner.cpp
├── inliner.h
├── instruction_combiner.cpp
├── instruction_combiner.h
├── jmp_threader.cpp
├── jmp_threader.h
├── loop_invariant.cpp
├── loop_invariant.h
├── print_visitor.cpp
├── print_visitor.h
├── reg_alloc.cpp
├── reg_alloc.h
├── ssa.cpp
├── ssa.h
├── type_analysis.cpp
├── type_analysis.h
├── unused_code.cpp
└── unused_code.h
├── stack.cpp
├── stack.h
├── std.cpp
├── std.h
├── test
├── assemble
│ ├── doubles.vvn
│ ├── instruction_combiner.vvn
│ ├── jmpcc.vvn
│ ├── lists.vvn
│ ├── modeq.vvn
│ ├── objects.vvn
│ └── strings.vvn
├── deoptimize
│ ├── ints.vvn
│ ├── ints.vvn_expectederrors
│ ├── strings.vvn
│ └── strings.vvn_expectederrors
├── error
│ ├── interpret_type_errors.vvn
│ └── interpret_type_errors.vvn_expectederrors
├── interpret
│ ├── doubles.vvn
│ ├── lists.vvn
│ ├── modeq.vvn
│ ├── objects.vvn
│ └── strings.vvn
├── parser
│ ├── comments_test.vvn
│ ├── control_flow.vvn
│ ├── functions_test.vvn
│ ├── fuzz_test.vvn
│ ├── fuzz_test.vvn_expectederrors
│ ├── fuzz_test_generate.js
│ ├── onliner.vvn
│ ├── recovery_test.vvn
│ ├── recovery_test.vvn_expectederrors
│ ├── strings.vvn
│ └── terms.vvn
├── run.sh
└── std
│ ├── lists_test.vvn
│ ├── objects_test.vvn
│ └── strings_test.vvn
├── tokenizer.cpp
├── tokenizer.h
├── type_info.h
├── ui_runtime
├── app.cpp
├── matrix.cpp
├── matrix.h
├── styled_char.cpp
└── styled_char.h
├── util.h
├── value.cpp
├── value.h
└── visitor
├── assignment_producer.cpp
├── assignment_producer.h
├── interpreter.cpp
├── interpreter.h
├── print_visitor.cpp
├── print_visitor.h
├── ssa_builder.cpp
└── ssa_builder.h
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | vvn
3 | *.swp
4 | *.dSYM
5 | bench/bench_log*
6 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution,
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
--------------------------------------------------------------------------------
/ast/addition_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_ADDITION_EXPRESSION
2 | #define VAIVEN_AST_HEADER_ADDITION_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class AdditionExpression : public Expression {
13 |
14 | public:
15 | AdditionExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitAdditionExpression(*this);
22 | }
23 | virtual ~AdditionExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/all.h:
--------------------------------------------------------------------------------
1 | #include "expression.h"
2 | #include "addition_expression.h"
3 | #include "assignment_expression.h"
4 | #include "subtraction_expression.h"
5 | #include "multiplication_expression.h"
6 | #include "division_expression.h"
7 | #include "integer_expression.h"
8 | #include "double_expression.h"
9 | #include "string_expression.h"
10 | #include "variable_expression.h"
11 | #include "bool_literal.h"
12 | #include "void_literal.h"
13 | #include "not_expression.h"
14 | #include "equality_expression.h"
15 | #include "inequality_expression.h"
16 | #include "gt_expression.h"
17 | #include "gte_expression.h"
18 | #include "lt_expression.h"
19 | #include "lte_expression.h"
20 | #include "statement.h"
21 | #include "expression_statement.h"
22 | #include "block.h"
23 | #include "funcdecl.h"
24 | #include "func_call_expression.h"
25 | #include "list_literal_expression.h"
26 | #include "dynamic_access_expression.h"
27 | #include "dynamic_store_expression.h"
28 | #include "static_access_expression.h"
29 | #include "static_store_expression.h"
30 | #include "var_decl.h"
31 | #include "if_statement.h"
32 | #include "for_cond.h"
33 | #include "return_statement.h"
34 |
--------------------------------------------------------------------------------
/ast/assignment_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_ASSIGNMENT_EXPRESSION
2 | #define VAIVEN_AST_HEADER_ASSIGNMENT_EXPRESSION
3 |
4 | #include
5 | #include
6 | #include "expression.h"
7 | #include "pre_assignment_op.h"
8 |
9 | using std::unique_ptr;
10 | using std::string;
11 |
12 | namespace vaiven { namespace ast {
13 |
14 | template
15 | class AssignmentExpression : public Expression {
16 |
17 | public:
18 | AssignmentExpression(
19 | string varname, unique_ptr > expr,
20 | PreAssignmentOp preAssignmentOp)
21 | : varname(varname), expr(std::move(expr)), preAssignmentOp(preAssignmentOp) {};
22 |
23 | void accept(Visitor& v) {
24 | return v.visitAssignmentExpression(*this);
25 | }
26 | virtual ~AssignmentExpression() {};
27 |
28 | string varname;
29 | unique_ptr > expr;
30 | PreAssignmentOp preAssignmentOp;
31 | };
32 |
33 | }}
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/ast/block.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_BLOCK
2 | #define VAIVEN_AST_HEADER_BLOCK
3 |
4 | #include
5 | #include
6 | #include "statement.h"
7 |
8 | using std::unique_ptr;
9 | using std::vector;
10 |
11 | namespace vaiven { namespace ast {
12 |
13 | template
14 | class Block : public Statement {
15 |
16 | public:
17 | Block(
18 | vector > > statements)
19 | : statements(std::move(statements)) {};
20 |
21 | void accept(Visitor& v) {
22 | return v.visitBlock(*this);
23 | }
24 | virtual ~Block() {};
25 |
26 | vector > > statements;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/bool_literal.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_BOOL_LITERAL
2 | #define VAIVEN_AST_HEADER_BOOL_LITERAL
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class BoolLiteral : public Expression {
13 |
14 | public:
15 | BoolLiteral(bool value) : value(value) {};
16 |
17 | void accept(Visitor& v) {
18 | return v.visitBoolLiteral(*this);
19 | }
20 | virtual ~BoolLiteral() {};
21 |
22 | bool value;
23 | };
24 |
25 | }}
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/ast/division_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_DIVISION_EXPRESSION
2 | #define VAIVEN_AST_HEADER_DIVISION_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class DivisionExpression : public Expression {
13 |
14 | public:
15 | DivisionExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitDivisionExpression(*this);
22 | }
23 | virtual ~DivisionExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/double_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_DOUBLE_EXPRESSION
2 | #define VAIVEN_AST_HEADER_DOUBLE_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class DoubleExpression : public Expression {
13 |
14 | public:
15 | DoubleExpression(double value) : value(value) {};
16 |
17 | void accept(Visitor& v) {
18 | return v.visitDoubleExpression(*this);
19 | }
20 | virtual ~DoubleExpression() {};
21 |
22 | double value;
23 | };
24 |
25 | }}
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/ast/dynamic_access_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_DYNAMIC_ACCESS_EXPRESSION
2 | #define VAIVEN_AST_HEADER_DYNAMIC_ACCESS_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class DynamicAccessExpression : public Expression {
13 |
14 | public:
15 | DynamicAccessExpression(
16 | unique_ptr > subject,
17 | unique_ptr > property)
18 | : subject(std::move(subject)), property(std::move(property)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitDynamicAccessExpression(*this);
22 | }
23 | virtual ~DynamicAccessExpression() {};
24 |
25 | unique_ptr > subject;
26 | unique_ptr > property;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/dynamic_store_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_DYNAMIC_STORE_EXPRESSION
2 | #define VAIVEN_AST_HEADER_DYNAMIC_STORE_EXPRESSION
3 |
4 | #include
5 | #include
6 | #include "expression.h"
7 | #include "pre_assignment_op.h"
8 |
9 | using std::unique_ptr;
10 | using std::string;
11 |
12 | namespace vaiven { namespace ast {
13 |
14 | template
15 | class DynamicStoreExpression : public Expression {
16 |
17 | public:
18 | DynamicStoreExpression(
19 | unique_ptr > subject,
20 | unique_ptr > property,
21 | unique_ptr > rhs,
22 | PreAssignmentOp preAssignmentOp)
23 | : property(std::move(property)), subject(std::move(subject)), rhs(std::move(rhs)), preAssignmentOp(preAssignmentOp) {};
24 |
25 | void accept(Visitor& v) {
26 | return v.visitDynamicStoreExpression(*this);
27 | }
28 | virtual ~DynamicStoreExpression() {};
29 |
30 | unique_ptr > subject;
31 | unique_ptr > property;
32 | unique_ptr > rhs;
33 | PreAssignmentOp preAssignmentOp;
34 | };
35 |
36 | }}
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/ast/equality_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_EQUALITY_EXPRESSION
2 | #define VAIVEN_AST_HEADER_EQUALITY_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class EqualityExpression : public Expression {
13 |
14 | public:
15 | EqualityExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitEqualityExpression(*this);
22 | }
23 | virtual ~EqualityExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_EXPRESSION
2 | #define VAIVEN_AST_HEADER_EXPRESSION
3 |
4 | #include "node.h"
5 |
6 | namespace vaiven { namespace ast {
7 |
8 | // nothing yet
9 | template
10 | class Expression : public Node {
11 | public:
12 | virtual ~Expression() {};
13 | };
14 |
15 | }}
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/ast/expression_statement.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_EXPRESSION_STATEMENT
2 | #define VAIVEN_AST_HEADER_EXPRESSION_STATEMENT
3 |
4 | #include
5 | #include "statement.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class ExpressionStatement : public Statement {
13 |
14 | public:
15 | ExpressionStatement(
16 | unique_ptr > expr)
17 | : expr(std::move(expr)) {};
18 |
19 | void accept(Visitor& v) {
20 | return v.visitExpressionStatement(*this);
21 | }
22 | virtual ~ExpressionStatement() {};
23 |
24 | unique_ptr > expr;
25 | };
26 |
27 | }}
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/ast/for_cond.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_FOR_COND
2 | #define VAIVEN_AST_HEADER_FOR_COND
3 |
4 | #include
5 | #include
6 | #include "statement.h"
7 | #include "expression.h"
8 |
9 | using std::unique_ptr;
10 | using std::vector;
11 |
12 | namespace vaiven { namespace ast {
13 |
14 | template
15 | class ForCondition : public Statement {
16 |
17 | public:
18 | ForCondition(
19 | unique_ptr > condition,
20 | vector > > statements)
21 | : condition(std::move(condition))
22 | , statements(std::move(statements)) {};
23 |
24 | void accept(Visitor& v) {
25 | return v.visitForCondition(*this);
26 | }
27 | virtual ~ForCondition() {};
28 |
29 | unique_ptr > condition;
30 | vector > > statements;
31 | };
32 |
33 | }}
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/ast/func_call_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_FUNC_CALL_EXPRESSION
2 | #define VAIVEN_AST_HEADER_FUNC_CALL_EXPRESSION
3 |
4 | #include
5 | #include
6 | #include
7 | #include "expression.h"
8 |
9 | using std::unique_ptr;
10 | using std::vector;
11 | using std::string;
12 |
13 | namespace vaiven { namespace ast {
14 |
15 | template
16 | class FuncCallExpression : public Expression {
17 |
18 | public:
19 | FuncCallExpression(string name, vector > > parameters) :
20 | name(name),
21 | parameters(std::move(parameters)) {};
22 |
23 | void accept(Visitor& v) {
24 | return v.visitFuncCallExpression(*this);
25 | }
26 | virtual ~FuncCallExpression() {};
27 |
28 | vector > > parameters;
29 | string name;
30 | };
31 |
32 | }}
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ast/funcdecl.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_FUNCDECL
2 | #define VAIVEN_AST_HEADER_FUNCDECL
3 |
4 | #include
5 | #include
6 | #include
7 | #include "statement.h"
8 |
9 | using std::unique_ptr;
10 | using std::vector;
11 | using std::string;
12 |
13 | namespace vaiven { namespace ast {
14 |
15 | template
16 | class FuncDecl : public Node {
17 |
18 | public:
19 | FuncDecl(
20 | string name,
21 | vector args,
22 | vector > > statements)
23 | : statements(std::move(statements)), name(name), args(args) {};
24 |
25 | void accept(Visitor& v) {
26 | return v.visitFuncDecl(*this);
27 | }
28 | virtual ~FuncDecl() {};
29 |
30 | string name;
31 | vector > > statements;
32 | vector args;
33 | };
34 |
35 | }}
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/ast/gt_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_GT_EXPRESSION
2 | #define VAIVEN_AST_HEADER_GT_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class GtExpression : public Expression {
13 |
14 | public:
15 | GtExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitGtExpression(*this);
22 | }
23 | virtual ~GtExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/gte_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_GTE_EXPRESSION
2 | #define VAIVEN_AST_HEADER_GTE_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class GteExpression : public Expression {
13 |
14 | public:
15 | GteExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitGteExpression(*this);
22 | }
23 | virtual ~GteExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/if_statement.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_IF_STATEMENT
2 | #define VAIVEN_AST_HEADER_IF_STATEMENT
3 |
4 | #include
5 | #include
6 | #include "statement.h"
7 | #include "expression.h"
8 |
9 | using std::unique_ptr;
10 | using std::vector;
11 |
12 | namespace vaiven { namespace ast {
13 |
14 | template
15 | class IfStatement : public Statement {
16 |
17 | public:
18 | IfStatement(
19 | unique_ptr > condition,
20 | vector > > trueStatements,
21 | vector > > falseStatements)
22 | : condition(std::move(condition))
23 | , trueStatements(std::move(trueStatements))
24 | , falseStatements(std::move(falseStatements)) {};
25 |
26 | void accept(Visitor& v) {
27 | return v.visitIfStatement(*this);
28 | }
29 | virtual ~IfStatement() {};
30 |
31 | unique_ptr > condition;
32 | vector > > trueStatements;
33 | vector > > falseStatements;
34 | };
35 |
36 | }}
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/ast/inequality_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_INEQUALITY_EXPRESSION
2 | #define VAIVEN_AST_HEADER_INEQUALITY_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class InequalityExpression : public Expression {
13 |
14 | public:
15 | InequalityExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitInequalityExpression(*this);
22 | }
23 | virtual ~InequalityExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/integer_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_INTEGER_EXPRESSION
2 | #define VAIVEN_AST_HEADER_INTEGER_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class IntegerExpression : public Expression {
13 |
14 | public:
15 | IntegerExpression(int value) : value(value) {};
16 |
17 | void accept(Visitor& v) {
18 | return v.visitIntegerExpression(*this);
19 | }
20 | virtual ~IntegerExpression() {};
21 |
22 | int value;
23 | };
24 |
25 | }}
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/ast/list_literal_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_LIST_LITERAL_EXPRESSION
2 | #define VAIVEN_AST_HEADER_LIST_LITERAL_EXPRESSION
3 |
4 | #include
5 | #include
6 | #include
7 | #include "expression.h"
8 |
9 | using std::unique_ptr;
10 | using std::vector;
11 | using std::string;
12 |
13 | namespace vaiven { namespace ast {
14 |
15 | template
16 | class ListLiteralExpression : public Expression {
17 |
18 | public:
19 | ListLiteralExpression(vector > > items) :
20 | items(std::move(items)) {};
21 |
22 | void accept(Visitor& v) {
23 | return v.visitListLiteralExpression(*this);
24 | }
25 | virtual ~ListLiteralExpression() {};
26 |
27 | vector > > items;
28 | };
29 |
30 | }}
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/ast/lt_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_LT_EXPRESSION
2 | #define VAIVEN_AST_HEADER_LT_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class LtExpression : public Expression {
13 |
14 | public:
15 | LtExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitLtExpression(*this);
22 | }
23 | virtual ~LtExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/lte_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_LTE_EXPRESSION
2 | #define VAIVEN_AST_HEADER_LTE_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class LteExpression : public Expression {
13 |
14 | public:
15 | LteExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitLteExpression(*this);
22 | }
23 | virtual ~LteExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/multiplication_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_MULTIPLICATION_EXPRESSION
2 | #define VAIVEN_AST_HEADER_MULTIPLICATION_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class MultiplicationExpression : public Expression {
13 |
14 | public:
15 | MultiplicationExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitMultiplicationExpression(*this);
22 | }
23 | virtual ~MultiplicationExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/node.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_NODE
2 | #define VAIVEN_AST_HEADER_NODE
3 |
4 | #include "visitor.h"
5 |
6 | namespace vaiven { namespace ast {
7 |
8 | template
9 | class Node {
10 | public:
11 | virtual void accept(Visitor& v)=0;
12 | virtual ~Node() {};
13 |
14 | RD resolvedData;
15 | };
16 |
17 | // save space on Node<>
18 | template<>
19 | class Node {
20 | public:
21 | virtual void accept(Visitor<>& v)=0;
22 | virtual ~Node() {};
23 | };
24 |
25 |
26 | }}
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/ast/not_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_NOT_EXPRESSION
2 | #define VAIVEN_AST_HEADER_NOT_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class NotExpression : public Expression {
13 |
14 | public:
15 | NotExpression(unique_ptr > expr) : expr(std::move(expr)) {};
16 |
17 | void accept(Visitor& v) {
18 | return v.visitNotExpression(*this);
19 | }
20 | virtual ~NotExpression() {};
21 |
22 | unique_ptr > expr;
23 | };
24 |
25 | }}
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/ast/pre_assignment_op.h:
--------------------------------------------------------------------------------
1 | // Copyright 2017 Google Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #ifndef VAIVEN_AST_HEADER_PRE_ASSIGNMENT_OP
16 | #define VAIVEN_AST_HEADER_PRE_ASSIGNMENT_OP
17 |
18 | namespace vaiven { namespace ast {
19 |
20 | enum PreAssignmentOp {
21 | kPreAssignmentOpNone,
22 | kPreAssignmentOpAdd,
23 | kPreAssignmentOpSub,
24 | kPreAssignmentOpMul,
25 | kPreAssignmentOpDiv,
26 | };
27 |
28 | } }
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/ast/return_statement.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_RETURN_STATEMENT
2 | #define VAIVEN_AST_HEADER_RETURN_STATEMENT
3 |
4 | #include
5 | #include "statement.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class ReturnStatement : public Statement {
13 |
14 | public:
15 | ReturnStatement(
16 | unique_ptr > expr)
17 | : expr(std::move(expr)) {};
18 |
19 | void accept(Visitor& v) {
20 | return v.visitReturnStatement(*this);
21 | }
22 | virtual ~ReturnStatement() {};
23 |
24 | unique_ptr > expr;
25 | };
26 |
27 | }}
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/ast/statement.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_STATEMENT
2 | #define VAIVEN_AST_HEADER_STATEMENT
3 |
4 | #include "node.h"
5 |
6 | namespace vaiven { namespace ast {
7 |
8 | // nothing yet
9 | template
10 | class Statement : public Node {
11 | public:
12 | virtual ~Statement() {};
13 | };
14 |
15 | }}
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/ast/static_access_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_STATIC_ACCESS_EXPRESSION
2 | #define VAIVEN_AST_HEADER_STATIC_ACCESS_EXPRESSION
3 |
4 | #include
5 | #include
6 | #include "expression.h"
7 |
8 | using std::unique_ptr;
9 | using std::string;
10 |
11 | namespace vaiven { namespace ast {
12 |
13 | template
14 | class StaticAccessExpression : public Expression {
15 |
16 | public:
17 | StaticAccessExpression(
18 | unique_ptr > subject,
19 | string property)
20 | : subject(std::move(subject)), property(property) {};
21 |
22 | void accept(Visitor& v) {
23 | return v.visitStaticAccessExpression(*this);
24 | }
25 | virtual ~StaticAccessExpression() {};
26 |
27 | unique_ptr > subject;
28 | string property;
29 | };
30 |
31 | }}
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/ast/static_store_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_STATIC_STORE_EXPRESSION
2 | #define VAIVEN_AST_HEADER_STATIC_STORE_EXPRESSION
3 |
4 | #include
5 | #include
6 | #include "expression.h"
7 | #include "pre_assignment_op.h"
8 |
9 | using std::unique_ptr;
10 | using std::string;
11 |
12 | namespace vaiven { namespace ast {
13 |
14 | template
15 | class StaticStoreExpression : public Expression {
16 |
17 | public:
18 | StaticStoreExpression(
19 | unique_ptr > subject,
20 | string property,
21 | unique_ptr > rhs,
22 | PreAssignmentOp preAssignmentOp)
23 | : subject(std::move(subject)), property(property), rhs(std::move(rhs)), preAssignmentOp(preAssignmentOp) {};
24 |
25 | void accept(Visitor& v) {
26 | return v.visitStaticStoreExpression(*this);
27 | }
28 | virtual ~StaticStoreExpression() {};
29 |
30 | unique_ptr > subject;
31 | string property;
32 | unique_ptr > rhs;
33 | PreAssignmentOp preAssignmentOp;
34 | };
35 |
36 | }}
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/ast/string_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_STRING_EXPRESSION
2 | #define VAIVEN_AST_HEADER_STRING_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 | #include "../heap.h"
7 |
8 | using std::unique_ptr;
9 |
10 | namespace vaiven { namespace ast {
11 |
12 | template
13 | class StringExpression : public Expression {
14 |
15 | public:
16 | StringExpression(GcableString* value) : value(value) {};
17 | virtual ~StringExpression() {
18 | if (globalHeap == NULL) {
19 | delete value;
20 | } else {
21 | globalHeap->owned_ptrs.insert(value);
22 | }
23 | }
24 |
25 | void accept(Visitor& v) {
26 | return v.visitStringExpression(*this);
27 | }
28 |
29 | GcableString* value;
30 | };
31 |
32 | }}
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ast/subtraction_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_SUBTRACTION_EXPRESSION
2 | #define VAIVEN_AST_HEADER_SUBTRACTION_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::unique_ptr;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class SubtractionExpression : public Expression {
13 |
14 | public:
15 | SubtractionExpression(
16 | unique_ptr > left,
17 | unique_ptr > right)
18 | : left(std::move(left)), right(std::move(right)) {};
19 |
20 | void accept(Visitor& v) {
21 | return v.visitSubtractionExpression(*this);
22 | }
23 | virtual ~SubtractionExpression() {};
24 |
25 | unique_ptr > left;
26 | unique_ptr > right;
27 | };
28 |
29 | }}
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/ast/var_decl.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_VAR_DECL
2 | #define VAIVEN_AST_HEADER_VAR_DECL
3 |
4 | #include
5 | #include
6 | #include "statement.h"
7 |
8 | using std::unique_ptr;
9 | using std::string;
10 |
11 | namespace vaiven { namespace ast {
12 |
13 | template
14 | class VarDecl : public Statement {
15 |
16 | public:
17 | VarDecl(
18 | string varname, unique_ptr > expr)
19 | : varname(varname), expr(std::move(expr)) {};
20 |
21 | void accept(Visitor& v) {
22 | return v.visitVarDecl(*this);
23 | }
24 | virtual ~VarDecl() {};
25 |
26 | unique_ptr > expr;
27 | string varname;
28 | };
29 |
30 | }}
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/ast/variable_expression.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_VARIABLE_EXPRESSION
2 | #define VAIVEN_AST_HEADER_VARIABLE_EXPRESSION
3 |
4 | #include
5 | #include "expression.h"
6 |
7 | using std::string;
8 |
9 | namespace vaiven { namespace ast {
10 |
11 | template
12 | class VariableExpression : public Expression {
13 |
14 | public:
15 | VariableExpression(string id) : id(id) {};
16 |
17 | void accept(Visitor& v) {
18 | return v.visitVariableExpression(*this);
19 | }
20 | virtual ~VariableExpression() {};
21 |
22 | string id;
23 | };
24 |
25 | }}
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/ast/visitor.h:
--------------------------------------------------------------------------------
1 | #ifndef VAIVEN_AST_HEADER_VISITOR
2 | #define VAIVEN_AST_HEADER_VISITOR
3 |
4 | namespace vaiven { namespace ast {
5 |
6 | template
7 | class Node;
8 | template
9 | class AssignmentExpression;
10 | template
11 | class AdditionExpression;
12 | template
13 | class SubtractionExpression;
14 | template
15 | class MultiplicationExpression;
16 | template
17 | class DivisionExpression;
18 | template
19 | class IntegerExpression;
20 | template
21 | class DoubleExpression;
22 | template
23 | class StringExpression;
24 | template
25 | class VariableExpression;
26 | template
27 | class BoolLiteral;
28 | template
29 | class VoidLiteral;
30 | template
31 | class NotExpression;
32 | template
33 | class EqualityExpression;
34 | template
35 | class InequalityExpression;
36 | template
37 | class GtExpression;
38 | template
39 | class GteExpression;
40 | template
41 | class LtExpression;
42 | template
43 | class LteExpression;
44 | template
45 | class ExpressionStatement;
46 | template
47 | class Block;
48 | template
49 | class FuncDecl;
50 | template
51 | class FuncCallExpression;
52 | template
53 | class ListLiteralExpression;
54 | template
55 | class DynamicAccessExpression;
56 | template
57 | class DynamicStoreExpression;
58 | template
59 | class StaticAccessExpression;
60 | template