File: stackframe.h

package info (click to toggle)
falconpl 0.9.6.9-git20120606-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,176 kB
  • sloc: cpp: 181,389; ansic: 109,025; yacc: 2,310; xml: 1,218; sh: 403; objc: 245; makefile: 82; sql: 20
file content (124 lines) | stat: -rw-r--r-- 2,901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
   FALCON - The Falcon Programming Language.
   FILE: stackframe.h

   Short description
   -------------------------------------------------------------------
   Author: Giancarlo Niccolai
   Begin: sab mar 18 2006

   -------------------------------------------------------------------
   (C) Copyright 2004: the FALCON developers (see list in AUTHORS file)

   See LICENSE file for licensing details.
*/

/** \file
   Short description
*/

#ifndef flc_stackframe_H
#define flc_stackframe_H

#include <falcon/setup.h>
#include <falcon/types.h>
#include <falcon/item.h>
#include <falcon/basealloc.h>
#include <falcon/itemarray.h>

namespace Falcon {

class Module;

class StackFrame: public BaseAlloc
{
public:
   enum
   {
      pa_default = 8
   } constants;

   bool m_break;

   uint32 m_ret_pc;
   uint32 m_call_pc;
   uint32 m_param_count;
   uint32 m_try_base;

   const Symbol *m_symbol;
   LiveModule *m_module;
   ext_func_frame_t m_endFrameFunc;
   StackFrame* m_prevTryFrame;

   Item m_self;
   Item m_fself;
   Item m_binding;

   // points to the parameter part in the previous area.
   Item* m_params;

   StackFrame( int preAlloc = pa_default ):
      m_symbol(0),
      m_module(0),
      m_prevTryFrame(0),
      m_prev(0),
      m_stack( preAlloc )
   {}

   StackFrame( const StackFrame& other );

   /** Retrieves the previous frame in the call stack. */
   StackFrame* prev() const { return m_prev; }
   void prev( StackFrame* p ) { m_prev = p; }

   /** Returns the items in the stack. */
   const ItemArray& stack() const { return m_stack; }
   ItemArray& stack() { return m_stack; }

   /** Remvoves N elements from thes stack */
   void pop( uint32 size )  { m_stack.resize( m_stack.length() - size ); }

   /** Allocates new space in the stack. */
   void push( uint32 size ) { m_stack.resize( m_stack.length() + size ); }

   Item* stackItems() const { return m_stack.elements(); }

   uint32 stackSize() const { return m_stack.length(); }

   void pushItem( const Item& v ) { m_stack.append(v); }
   const Item& topItem() const { return m_stack.back(); }
   Item& topItem() { return m_stack[m_stack.length()-1]; }

   void popItem( Item &tgt ) { tgt = m_stack.back(); m_stack.resize( m_stack.length() - 1 ); }

   void resizeStack( uint32 size ) { m_stack.resize( size ); }

   void prepareParams( StackFrame* previous, uint32 paramCount )
   {
      if( paramCount != 0 )
      {
         m_params = previous->m_stack.elements() + previous->m_stack.length() - paramCount;
      }
      else
         m_params = 0;
   }

   const Item& localItem( uint32 id ) const { return m_stack[id]; }
   Item& localItem( uint32 id ) { return m_stack[id]; }

   /** Copy a whole hierarcy of frames. */
   StackFrame* copyDeep( StackFrame** bottom );

   void gcMark( uint32 mark );

private:
   StackFrame* m_prev;
   ItemArray m_stack;
} ;


}

#endif

/* end of stackframe.h */