use magic type for do

This commit is contained in:
Mylloon 2022-12-10 16:49:51 +01:00
parent c5c2fd2d1c
commit db78e69267
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 10 additions and 2 deletions

1
ast.ml
View file

@ -1,4 +1,5 @@
type type_t =
| Magic_t
| Void_t
| Int_t
| Bool_t

View file

@ -24,7 +24,7 @@ let rec analyze_expr env ua t = function
| Syntax.Call c ->
(match Env.find c.func env with
| Func_t (ret_t, tl) ->
if ret_t != t then errt ret_t t c.pos;
if ret_t != t && t != Magic_t then errt ret_t t c.pos;
if List.length tl != List.length c.args
then
raise
@ -63,7 +63,7 @@ let analyze_instr env ua ret_t = function
let ae, et = analyze_expr env ua (Env.find a.var env) a.expr in
Assign (a.var, ae), env, List.filter (fun x -> x <> a.var) ua
| Syntax.Do d ->
let ae, _ = analyze_expr env ua Int_t d.expr in
let ae, _ = analyze_expr env ua Magic_t d.expr in
Do ae, env, []
| Syntax.Return r ->
let ae, _ = analyze_expr env ua ret_t r.expr in

View file

@ -0,0 +1,7 @@
int foo(int a) {
return a;
}
void main() {
void b = foo(1);
}