Add support for float variables and basic math.
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
18 #ifndef _include_jc_stack_h_
19 #define _include_jc_stack_h_
24 #include "UnsafeArray.h"
33 UnsafeArray *unsafeArray;
41 Top(LocalSlot *sp, bytecode *pc)
59 void *prevUnsafeStack_;
62 Frame(Frame *prev, bytecode *prevpc, Code *code, void *prevUnsafeStack)
66 prevUnsafeStack_(prevUnsafeStack)
71 return reinterpret_cast<LocalSlot *>(this + 1);
73 LocalSlot *stackBase() {
74 return locals() + code_->nlocals();
82 bytecode *prevpc() const {
85 void *prevUnsafeStack() const {
86 return prevUnsafeStack_;
88 LocalSlot &arg(unsigned slot) {
89 assert(slot < code()->nargs());
90 return *(reinterpret_cast<LocalSlot *>(this) - slot - 1);
101 static const size_t STACK_SIZE = 1024 * 1024;
110 Frame *pushFrame(Frame *prev, Code *code);
111 Frame *popFrame(Frame *frame);
116 void setTop(Top *top) {
120 return Top((LocalSlot *)buffer_);
124 // The unsafe stack is designed for structures which interop unsafely with C++.
125 // In this stack, buffers can be overrun, even inside the VM - but with two
128 // The unsafe stack cannot hold safe references.
129 // Indirect reads and writes from the unsafe stack cannot escape the unsafe
138 static const size_t STACK_SIZE = 1024 * 1024;
146 void *position() const {
149 void *allocate(size_t nbytes) {
150 nbytes = Align(nbytes, kMallocAlignment);
152 if (pos_ + nbytes > end_) {
162 void unwind(void *to) {
163 char *p = (char *)to;
164 assert(p < pos_ && p >= buffer_);
171 #endif // _include_jc_stack_h_