Skip to content

Commit

Permalink
cast of char
Browse files Browse the repository at this point in the history
  • Loading branch information
keiichiw committed Feb 25, 2015
1 parent b088a8a commit 46a263e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/emitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,19 @@ let rec ex ret_reg = function
(* (x^flg)-flg equals (flg==-1?-x:x) *)
emit "xor r%d, r%d, r%d" ret_reg ret_reg flg;
emit "sub r%d, r%d, r%d" ret_reg ret_reg flg;
if t1 = TChar then
emit "and r%d, r%d, 0xff" ret_reg ret_reg;
reg_free flg
| t1, t2 when is_real t1 || is_real t2 ->
if is_real t1 && is_real t2 then
ex ret_reg e
else
raise_error "ECast: float"
| t1, t2 when sizeof t1 = 1 && sizeof t2 > 1 ->
ex ret_reg e;
emit "and r%d, r%d, 0xff\n" ret_reg ret_reg
| _ ->
ex ret_reg e
ex ret_reg e
end
| ESpace _ ->
raise_error "ex: ESpace"
Expand Down
16 changes: 16 additions & 0 deletions test/char-cast.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
260
4
4
*/
#include <stdio.h>

int main() {
float f = 260;
int a, b;
char c;
a = f;
b = (char)f;
c = a;
printf("%d\n%d\n%d\n", a, b, c);
}

0 comments on commit 46a263e

Please sign in to comment.