*** empty log message ***
[chuck-blob.git] / exile / v1 / src / chuck_frame.cpp
bloba334918c6f2ae7ded9f22123a8452fda91e267e0
1 /*----------------------------------------------------------------------------
2 ChucK Concurrent, On-the-fly Audio Programming Language
3 Compiler and Virtual Machine
5 Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.cs.princeton.edu/
7 http://soundlab.cs.princeton.edu/
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 U.S.A.
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_frame.cpp
27 // desc: ...
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
31 // date: Autumn 2002
32 //-----------------------------------------------------------------------------
33 #include "chuck_frame.h"
34 #include <vector>
35 using namespace std;
39 //-----------------------------------------------------------------------------
40 // name: struct F_Frame_
41 // desc: ...
42 //-----------------------------------------------------------------------------
43 struct F_Frame_
45 Temp_Label label;
46 F_Access_List head;
47 F_Access_List tail;
48 unsigned int num_access;
49 unsigned int curr_offset;
50 vector<F_Access> stack;
56 //-----------------------------------------------------------------------------
57 // name: F_new_frame()
58 // desc: ...
59 //-----------------------------------------------------------------------------
60 F_Frame F_new_frame( Temp_Label name )
62 F_Frame f = new F_Frame_;
63 f->label = name;
64 // f->tail = f->head = (F_Access_List)checked_malloc( sizeof(F_Access_List_) );
65 // f->head->head = NULL;
66 // f->head->tail = NULL;
67 f->num_access = 0;
68 f->curr_offset = 0;
70 return f;
76 //-----------------------------------------------------------------------------
77 // name: F_name()
78 // desc: ...
79 //-----------------------------------------------------------------------------
80 Temp_Label F_name( F_Frame f )
82 return f->label;
88 //-----------------------------------------------------------------------------
89 // name: F_formals()
90 // desc: ...
91 //-----------------------------------------------------------------------------
92 F_Access_List F_formals( F_Frame f )
94 return NULL;
95 // return f->head->tail;
101 //-----------------------------------------------------------------------------
102 // name: F_formals()
103 // desc: ...
104 //-----------------------------------------------------------------------------
105 unsigned int F_offset( F_Access a )
107 return a->offset;
113 //-----------------------------------------------------------------------------
114 // name: F_alloc_local()
115 // desc: ...
116 //-----------------------------------------------------------------------------
117 F_Access F_alloc_local( F_Frame f, unsigned int size, unsigned int is_global )
119 F_Access a = (F_Access)checked_malloc( sizeof( F_Access_ ) );
120 a->offset = f->curr_offset;
121 a->global = is_global;
122 a->size = size;
123 f->curr_offset += size;
124 f->stack.push_back( a );
125 //f->num_access++;
126 //f->tail->tail = (F_Access_List)checked_malloc( sizeof( F_Access_List_ ) );
127 //f->tail->head = a;
128 //f->tail = f->tail->tail;
130 return a;
136 //-----------------------------------------------------------------------------
137 // name: F_begin_scope()
138 // desc: ...
139 //-----------------------------------------------------------------------------
140 void F_begin_scope( F_Frame f )
142 f->stack.push_back( NULL );
148 //-----------------------------------------------------------------------------
149 // name: F_remove_locals()
150 // desc: ....
151 //-----------------------------------------------------------------------------
152 void F_end_scope( F_Frame f )
154 F_Access v = NULL;
155 do {
156 v = f->stack[f->stack.size()-1];
157 f->stack.pop_back();
158 if( !v ) break;
159 f->curr_offset -= v->size;
160 free(v);
161 }while( TRUE );
167 //-----------------------------------------------------------------------------
168 // name: F_stack_depth()
169 // desc: ...
170 //-----------------------------------------------------------------------------
171 unsigned int F_stack_depth( F_Frame f )
173 return f->curr_offset;