Added global variable support.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_bytecode_compiler_h_
20 #define _include_bytecode_compiler_h_
23 #include "BytecodeEmitter.h"
24 #include "Functions.h"
32 ScopedRoot<Module> module;
33 PoolList<ScopedRoot<Function> > publics;
34 ScopedRoot<FixedArray> natives;
37 class BytecodeCompiler : public AstVisitor
41 BytecodeEmitter emitter_;
42 ScopedRoot<FixedArray> locals_;
44 ModuleData *moduleData_;
49 BytecodeEmitter::Label *bk_;
50 BytecodeEmitter::Label *ct_;
55 LoopScope(Scope *scope, BytecodeEmitter::Label *bk, BytecodeEmitter::Label *ct,
71 BytecodeEmitter::Label *break_() {
74 BytecodeEmitter::Label *continue_() {
87 BytecodeCompiler *bc_;
91 AutoEnterScope(BytecodeCompiler *bc, Scope *scope)
104 void recordLifoSlot(Scope *scope);
105 void unwindTo(Scope *scope);
106 void visitForTest(Expression *expression,
107 BytecodeEmitter::Label *trueBranch,
108 BytecodeEmitter::Label *falseBranch,
109 BytecodeEmitter::Label *fallthrough);
110 Code *compileCode(Scope *scope, unsigned lineno);
111 Function *compileFunction(ModuleData *module, FunctionStatement *fun);
112 void visitForALU(Type *needed, Expression *node);
114 void getEnvSlot(Variable *var);
115 void setEnvSlot(Variable *var);
118 BytecodeCompiler(Zone *zone, ParseTree *tree, ModuleData *module);
123 void visit(NameProxy *name);
124 void visit(Assignment *node);
125 void visit(BinaryExpression *node);
126 void visit(ReturnStatement *node);
127 void visit(ForStatement *node);
128 void visit(BlockStatement *node);
129 void visit(VariableDeclaration *node);
130 void visit(IntegerLiteral *node);
131 void visit(FloatLiteral *node);
132 void visit(StringLiteral *node);
133 void visit(ExpressionStatement *node);
134 void visit(FunctionStatement *node);
135 void visit(CallExpression *node);
136 void visit(IfStatement *node);
137 void visit(IndexExpression *node);
138 void visit(EnumStatement *node);
139 void visit(WhileStatement *node);
140 void visit(BreakStatement *node);
141 void visit(ContinueStatement *node);
142 void visit(IncDecExpression *node);
143 void visit(UnaryExpression *node);
144 void visit(TernaryExpression *node);
149 #endif // _include_bytecode_generator_h_