Add %% operator (divisor modulo)

This commit is contained in:
Ginger Bill
2017-05-09 16:21:31 +01:00
parent 8677c81da7
commit c6d531df95
5 changed files with 21 additions and 1 deletions
+10
View File
@@ -2073,6 +2073,7 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
case Token_Mul:
case Token_Quo:
case Token_Mod:
case Token_ModMod:
case Token_And:
case Token_Or:
case Token_Xor:
@@ -2081,6 +2082,14 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
break;
}
if (op == Token_ModMod) {
irValue *n = left;
irValue *m = right;
irValue *a = ir_emit(proc, ir_instr_binary_op(proc, Token_Mod, n, m, type));
irValue *b = ir_emit(proc, ir_instr_binary_op(proc, Token_Add, a, m, type));
return ir_emit(proc, ir_instr_binary_op(proc, Token_Mod, b, m, type));
}
return ir_emit(proc, ir_instr_binary_op(proc, op, left, right, type));
}
@@ -3744,6 +3753,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
case Token_Mul:
case Token_Quo:
case Token_Mod:
case Token_ModMod:
case Token_And:
case Token_Or:
case Token_Xor: