source: to-imperative/trunk/runtime/rf_stack.hh @ 151

Last change on this file since 151 was 151, checked in by orlov, 18 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1//
2// Copyright (C) 2000 Refal+ Development Group
3//
4// Refal+ is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// (at your option) any later version.
8//
9// Refal+ is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Refal+; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17//
18// $Source$
19// $Revision: 151 $
20// $Date: 2002-09-13 19:05:10 +0000 (Fri, 13 Sep 2002) $
21// Author: Andrey Slepuhin <pooh@msu.ru>
22
23#ifndef __rf_stack_hh__
24#define __rf_stack_hh__
25
26#include "rf_expr.hh"
27#include "pxx_heap.hh"
28
29namespace rfrt
30{
31
32class Stack :
33  public pxx::Heap
34{
35
36  friend class Result ;
37  friend class RetVal ;
38  friend class Arg ;
39
40private:
41
42  Expr* top ;
43  Expr* saved_top ;
44
45public:
46
47  inline Stack (void* const _start, size_t _size) :
48    pxx::Heap (_start, _size, _size),
49    top( static_cast<Expr*>(_start) )
50  {}
51
52  inline ~Stack ()
53  {}
54
55  inline void push (Expr const& _expr)
56  {
57    new (top++) Expr(_expr);
58  }
59
60  inline Expr const* get ()
61  {
62    return top++;
63  }
64
65  inline Stack const& operator , (Expr const& _expr) const
66  {
67    ((Stack*)this)->push((Expr&)_expr);
68    return *this;
69  }
70
71  inline Stack& operator , (Expr& _expr)
72  {
73    _expr.~Expr();
74    new(&_expr) Expr(top++);
75    return *this;
76  }
77
78  inline Stack& operator , (Result& _res) ;
79
80  inline Expr* get_top () const
81  {
82    return top;
83  }
84
85  inline void set_top (Expr* _top)
86  {
87    top = _top;
88  }
89
90  inline void destroy_results (Expr* _saved_top)
91  {
92    while (_saved_top < top) {
93      top--;
94      D( printf("destroy_results: %p(%p,%p,%p)\n",
95            top, top->get_first(), top->get_last(), top->get_mem_chunk()); )
96      if (top->get_mem_chunk() != null) top->~Expr();
97    }
98  }
99
100};
101
102extern Stack stack ;
103
104}
105
106#endif // __rf_stack_hh__
Note: See TracBrowser for help on using the repository browser.