Skip to content

Commit 49228f3

Browse files
committed
Support getting the address of a value
1 parent fddd63a commit 49228f3

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

cobalt-ast/src/ast/ops.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,25 @@ impl<'src> AST<'src> for PrefixAST<'src> {
280280
return (Value::error(), errs);
281281
}
282282
(
283-
v.pre_op((self.op, self.loc), ctx).unwrap_or_else(|e| {
284-
errs.push(e);
285-
Value::error()
286-
}),
283+
if self.op == "&" {
284+
if let Some(ty) = v.data_type.downcast::<types::Reference>() {
285+
Value {
286+
data_type: types::Pointer::new(ty.base()),
287+
..v
288+
}
289+
} else {
290+
Value::new(
291+
v.addr(ctx).map(From::from),
292+
None,
293+
v.data_type.add_ref(v.frozen.is_none()),
294+
)
295+
}
296+
} else {
297+
v.pre_op((self.op, self.loc), ctx).unwrap_or_else(|e| {
298+
errs.push(e);
299+
Value::error()
300+
})
301+
},
287302
errs,
288303
)
289304
}

0 commit comments

Comments
 (0)