Added support for && and ||.
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;
66 class BytecodeCompiler : public AstVisitor
70 BytecodeEmitter emitter_;
71 ScopedRoot<FixedArray> locals_;
73 ModuleData *moduleData_;
78 BytecodeEmitter::Label *bk_;
79 BytecodeEmitter::Label *ct_;
84 LoopScope(Scope *scope, BytecodeEmitter::Label *bk, BytecodeEmitter::Label *ct,
100 BytecodeEmitter::Label *break_() {
103 BytecodeEmitter::Label *continue_() {
116 BytecodeCompiler *bc_;
120 AutoEnterScope(BytecodeCompiler *bc, Scope *scope)
128 bc_->scope_ = saved_;
133 void recordLifoSlot(Scope *scope);
134 void unwindTo(Scope *scope);
135 void visitForTest(Expression *expression,
136 BytecodeEmitter::Label *trueBranch,
137 BytecodeEmitter::Label *falseBranch,
138 BytecodeEmitter::Label *fallthrough);
139 Function *compileFunction(ModuleData *module, FunctionStatement *fun);
140 void visitForALU(Type *needed, Expression *node);
143 BytecodeCompiler(Zone *zone, ParseTree *tree, ModuleData *module);
148 void visit(NameProxy *name);
149 void visit(Assignment *node);
150 void visit(BinaryExpression *node);
151 void visit(ReturnStatement *node);
152 void visit(ForStatement *node);
153 void visit(BlockStatement *node);
154 void visit(VariableDeclaration *node);
155 void visit(IntegerLiteral *node);
156 void visit(FloatLiteral *node);
157 void visit(StringLiteral *node);
158 void visit(ExpressionStatement *node);
159 void visit(FunctionStatement *node);
160 void visit(CallExpression *node);
161 void visit(IfStatement *node);
162 void visit(IndexExpression *node);
163 void visit(EnumStatement *node);
164 void visit(WhileStatement *node);
165 void visit(BreakStatement *node);
166 void visit(ContinueStatement *node);
167 void visit(IncDecExpression *node);
172 #endif // _include_bytecode_generator_h_