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
23 -----------------------------------------------------------------------------*/
25 //-----------------------------------------------------------------------------
26 // file: chuck_frame.cpp
29 // author: Ge Wang (gewang@cs.princeton.edu)
30 // Perry R. Cook (prc@cs.princeton.edu)
32 //-----------------------------------------------------------------------------
33 #include "chuck_frame.h"
39 //-----------------------------------------------------------------------------
40 // name: struct F_Frame_
42 //-----------------------------------------------------------------------------
48 unsigned int num_access
;
49 unsigned int curr_offset
;
50 vector
<F_Access
> stack
;
56 //-----------------------------------------------------------------------------
57 // name: F_new_frame()
59 //-----------------------------------------------------------------------------
60 F_Frame
F_new_frame( Temp_Label name
)
62 F_Frame f
= new F_Frame_
;
64 // f->tail = f->head = (F_Access_List)checked_malloc( sizeof(F_Access_List_) );
65 // f->head->head = NULL;
66 // f->head->tail = NULL;
76 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
80 Temp_Label
F_name( F_Frame f
)
88 //-----------------------------------------------------------------------------
91 //-----------------------------------------------------------------------------
92 F_Access_List
F_formals( F_Frame f
)
95 // return f->head->tail;
101 //-----------------------------------------------------------------------------
104 //-----------------------------------------------------------------------------
105 unsigned int F_offset( F_Access a
)
113 //-----------------------------------------------------------------------------
114 // name: F_alloc_local()
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
;
123 f
->curr_offset
+= size
;
124 f
->stack
.push_back( a
);
126 //f->tail->tail = (F_Access_List)checked_malloc( sizeof( F_Access_List_ ) );
128 //f->tail = f->tail->tail;
136 //-----------------------------------------------------------------------------
137 // name: F_begin_scope()
139 //-----------------------------------------------------------------------------
140 void F_begin_scope( F_Frame f
)
142 f
->stack
.push_back( NULL
);
148 //-----------------------------------------------------------------------------
149 // name: F_remove_locals()
151 //-----------------------------------------------------------------------------
152 void F_end_scope( F_Frame f
)
156 v
= f
->stack
[f
->stack
.size()-1];
159 f
->curr_offset
-= v
->size
;
167 //-----------------------------------------------------------------------------
168 // name: F_stack_depth()
170 //-----------------------------------------------------------------------------
171 unsigned int F_stack_depth( F_Frame f
)
173 return f
->curr_offset
;