1.1 --- a/src/BytecodeCompiler.h Mon Sep 17 00:10:01 2012 -0700
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,159 +0,0 @@
1.4 -/* vim: set ts=4 sw=4 tw=99 et:
1.5 - *
1.6 - * Copyright (C) 2012 David Anderson
1.7 - *
1.8 - * This file is part of JITCraft.
1.9 - *
1.10 - * JITCraft is free software: you can redistribute it and/or modify it under
1.11 - * the terms of the GNU General Public License as published by the Free
1.12 - * Software Foundation, either version 3 of the License, or (at your option)
1.13 - * any later version.
1.14 - *
1.15 - * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
1.16 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.18 - *
1.19 - * You should have received a copy of the GNU General Public License along with
1.20 - * JITCraft. If not, see http://www.gnu.org/licenses/.
1.21 - */
1.22 -#ifndef _include_bytecode_compiler_h_
1.23 -#define _include_bytecode_compiler_h_
1.24 -
1.25 -#include "AST.h"
1.26 -#include "BytecodeEmitter.h"
1.27 -#include "Functions.h"
1.28 -
1.29 -namespace ke {
1.30 -
1.31 -class Module;
1.32 -class Array;
1.33 -class ArrayMap;
1.34 -
1.35 -struct ModuleData
1.36 -{
1.37 - ScopedRoot<Module> module;
1.38 - PoolList<ScopedRoot<Function> > publics;
1.39 - ScopedRoot<FixedArray> natives;
1.40 -};
1.41 -
1.42 -class BytecodeCompiler : public AstVisitor
1.43 -{
1.44 - Zone *zone_;
1.45 - ParseTree *tree_;
1.46 - BytecodeEmitter emitter_;
1.47 - ScopedRoot<FixedArray> locals_;
1.48 - Scope *scope_;
1.49 - ModuleData *moduleData_;
1.50 -
1.51 - class LoopScope
1.52 - {
1.53 - Scope *scope_;
1.54 - BytecodeEmitter::Label *bk_;
1.55 - BytecodeEmitter::Label *ct_;
1.56 - LoopScope **prevp_;
1.57 - LoopScope *prev_;
1.58 -
1.59 - public:
1.60 - LoopScope(Scope *scope, BytecodeEmitter::Label *bk, BytecodeEmitter::Label *ct,
1.61 - LoopScope **prevp)
1.62 - : scope_(scope),
1.63 - bk_(bk),
1.64 - ct_(ct),
1.65 - prevp_(prevp),
1.66 - prev_(*prevp)
1.67 - {
1.68 - *prevp_ = this;
1.69 - }
1.70 -
1.71 - ~LoopScope()
1.72 - {
1.73 - *prevp_ = prev_;
1.74 - }
1.75 -
1.76 - BytecodeEmitter::Label *break_() {
1.77 - return bk_;
1.78 - }
1.79 - BytecodeEmitter::Label *continue_() {
1.80 - return ct_;
1.81 - }
1.82 - Scope *scope() {
1.83 - return scope_;
1.84 - }
1.85 - };
1.86 -
1.87 - LoopScope *loop_;
1.88 -
1.89 - public:
1.90 - class AutoEnterScope
1.91 - {
1.92 - BytecodeCompiler *bc_;
1.93 - Scope *saved_;
1.94 -
1.95 - public:
1.96 - AutoEnterScope(BytecodeCompiler *bc, Scope *scope)
1.97 - : bc_(bc),
1.98 - saved_(bc->scope_)
1.99 - {
1.100 - if (scope)
1.101 - bc->scope_ = scope;
1.102 - }
1.103 - ~AutoEnterScope() {
1.104 - bc_->scope_ = saved_;
1.105 - }
1.106 - };
1.107 -
1.108 - private:
1.109 - void recordLifoSlot(Scope *scope);
1.110 - void unwindTo(Scope *scope);
1.111 - void visitForTest(Expression *expression,
1.112 - BytecodeEmitter::Label *trueBranch,
1.113 - BytecodeEmitter::Label *falseBranch,
1.114 - BytecodeEmitter::Label *fallthrough);
1.115 - Code *compileCode(Scope *scope, unsigned lineno);
1.116 - Function *compileFunction(ModuleData *module, FunctionStatement *fun);
1.117 - void visitForALU(Type *needed, Expression *node);
1.118 -
1.119 - void getEnvSlot(Variable *var);
1.120 - void setEnvSlot(Variable *var);
1.121 -
1.122 - bool tableswitch(SwitchStatement *node);
1.123 -
1.124 - public:
1.125 - BytecodeCompiler(Zone *zone, ParseTree *tree, ModuleData *module);
1.126 -
1.127 - Module *compile();
1.128 -
1.129 - public:
1.130 - void visit(NameProxy *name);
1.131 - void visit(Assignment *node);
1.132 - void visit(BinaryExpression *node);
1.133 - void visit(ReturnStatement *node);
1.134 - void visit(ForStatement *node);
1.135 - void visit(BlockStatement *node);
1.136 - void visit(VariableDeclaration *node);
1.137 - void visit(IntegerLiteral *node);
1.138 - void visit(BooleanLiteral *node);
1.139 - void visit(FloatLiteral *node);
1.140 - void visit(StringLiteral *node);
1.141 - void visit(ExpressionStatement *node);
1.142 - void visit(FunctionStatement *node);
1.143 - void visit(CallExpression *node);
1.144 - void visit(IfStatement *node);
1.145 - void visit(IndexExpression *node);
1.146 - void visit(EnumStatement *node);
1.147 - void visit(WhileStatement *node);
1.148 - void visit(BreakStatement *node);
1.149 - void visit(ContinueStatement *node);
1.150 - void visit(IncDecExpression *node);
1.151 - void visit(UnaryExpression *node);
1.152 - void visit(TernaryExpression *node);
1.153 - void visit(StructureStatement *node);
1.154 - void visit(FieldExpression *node);
1.155 - void visit(SwitchStatement *node);
1.156 - void visit(FunctionTypeStatement *node);
1.157 - void visit(ArrayLiteral *node);
1.158 -};
1.159 -
1.160 -}
1.161 -
1.162 -#endif // _include_bytecode_generator_h_