@@ -68,6 +68,7 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
68
68
69
69
while i < cap. len ( ) {
70
70
cur = cap[ i] as char ;
71
+ debug ! ( "current char: %c" , cur) ;
71
72
let mut old_state = state;
72
73
match state {
73
74
Nothing => {
@@ -132,9 +133,36 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
132
133
(Number(x), Number(y)) => stack.push(Number(x | y)),
133
134
(_, _) => return Err(~" non-numbers on stack with |")
134
135
},
135
- 'A' => return Err(~" logical operations unimplemented") ,
136
- 'O' => return Err ( ~"logical operations unimplemented") ,
137
- '!' => return Err ( ~"logical operations unimplemented") ,
136
+ 'A' => match (stack.pop(), stack.pop()) {
137
+ (Number(x), Number(y)) => {
138
+ if x == 1 && y == 1 {
139
+ stack.push(Number(1));
140
+ } else {
141
+ stack.push(Number(0));
142
+ }
143
+ },
144
+ (_, _) => return Err(~" non-numbers on stack with logical and")
145
+ } ,
146
+ 'O' => match ( stack. pop ( ) , stack. pop ( ) ) {
147
+ ( Number ( x) , Number ( y) ) => {
148
+ if x == 1 && y == 1 {
149
+ stack. push ( Number ( 1 ) ) ;
150
+ } else {
151
+ stack. push ( Number ( 0 ) ) ;
152
+ }
153
+ } ,
154
+ ( _, _) => return Err ( ~"non-numbers on stack with logical or")
155
+ } ,
156
+ '!' => match stack. pop ( ) {
157
+ Number ( x) => {
158
+ if x == 1 {
159
+ stack. push ( Number ( 0 ) )
160
+ } else {
161
+ stack. push ( Number ( 1 ) )
162
+ }
163
+ } ,
164
+ _ => return Err ( ~"non-number on stack with logical not")
165
+ } ,
138
166
'~' => match stack. pop ( ) {
139
167
Number ( x) => stack. push ( Number ( !x) ) ,
140
168
_ => return Err ( ~"non-number on stack with %~")
@@ -181,7 +209,9 @@ pub fn expand(cap: &[u8], params: &mut [Param], sta: &mut [Param], dyn: &mut [Pa
181
209
state = CharClose ;
182
210
} ,
183
211
CharClose => {
184
- assert ! ( cur == '\'' , "malformed character constant" ) ;
212
+ if cur != '\'' {
213
+ return Err ( ~"malformed character constant") ;
214
+ }
185
215
} ,
186
216
IntConstant => {
187
217
if cur == '}' {
0 commit comments