From 316e515f227614efa263b60f2e59dad2394f0965 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 14 Jul 2019 22:46:33 +0200 Subject: [PATCH] :art: '?:' and precedence --- ast | 2 +- src/emit/emit.c | 2 +- src/parse/check.c | 2 +- src/parse/scan1.c | 2 +- src/parse/scan2.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ast b/ast index 3cbaf19d..2a9afe54 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 3cbaf19df28f60ce7b3bb5b0cb3d867902782f88 +Subproject commit 2a9afe545081756266000246a32193648f9b9618 diff --git a/src/emit/emit.c b/src/emit/emit.c index 617933aa..a63e0081 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1030,7 +1030,7 @@ ANN static Instr emit_flow(const Emitter emit, const Type type, ANN static m_bool emit_exp_if(const Emitter emit, const Exp_If* exp_if) { CHECK_BB(emit_exp(emit, exp_if->cond, 0)) const Instr op = emit_flow(emit, exp_if->cond->type, BranchEqInt, BranchEqFloat); - CHECK_BB(emit_exp(emit, exp_if->if_exp, 0)) + CHECK_BB(emit_exp(emit, exp_if->if_exp ?: exp_if->cond, 0)) const Instr op2 = emit_add_instr(emit, Goto); op->m_val = emit_code_size(emit); const m_bool ret = emit_exp(emit, exp_if->else_exp, 0); diff --git a/src/parse/check.c b/src/parse/check.c index a4a76ec1..30fc2136 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -752,7 +752,7 @@ ANN static Type check_exp_unary(const Env env, const Exp_Unary* unary) { ANN static Type check_exp_if(const Env env, const Exp_If* exp_if) { DECL_OO(const Type, cond, = check_exp(env, exp_if->cond)) - DECL_OO(const Type, if_exp, = check_exp(env, exp_if->if_exp)) + DECL_OO(const Type, if_exp, = (exp_if->if_exp ? check_exp(env, exp_if->if_exp) : cond)) DECL_OO(const Type, else_exp, = check_exp(env, exp_if->else_exp)) if(isa(cond, t_int) < 0 && isa(cond, t_float) < 0 && isa(cond, t_object) < 0) ERR_O(exp_self(exp_if)->pos, diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 7e8cc596..f64d1401 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -163,7 +163,7 @@ ANN static inline m_bool scan1_exp_dot(const Env env, const Exp_Dot* member) { ANN static m_bool scan1_exp_if(const Env env, const Exp_If* exp_if) { CHECK_BB(scan1_exp(env, exp_if->cond)) - CHECK_BB(scan1_exp(env, exp_if->if_exp)) + CHECK_BB(scan1_exp(env, exp_if->if_exp ?: exp_if->cond)) return scan1_exp(env, exp_if->else_exp); } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 9a8119c9..fee64381 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -196,7 +196,7 @@ ANN static inline m_bool scan2_exp_dot(const Env env, const Exp_Dot* member) { ANN static inline m_bool scan2_exp_if(const Env env, const Exp_If* exp_if) { CHECK_BB(scan2_exp(env, exp_if->cond)) - CHECK_BB(scan2_exp(env, exp_if->if_exp)) + CHECK_BB(scan2_exp(env, exp_if->if_exp ?: exp_if->cond)) return scan2_exp(env, exp_if->else_exp); } -- 2.43.0