From 61afa794fd26ff31b60826d3c449b89ac3af1b16 Mon Sep 17 00:00:00 2001 From: Ryan Hendrickson Date: Tue, 26 Jun 2018 20:41:56 -0400 Subject: [PATCH] reduce parentheses around %% operator Back when I wrote 4cbbd93, I didn't know about `o.level`. Now I do. --- lib/ast.js | 8 ++++++-- src/ast.ls | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index 475bfbed4..9539c8403 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -2451,9 +2451,13 @@ exports.Binary = Binary = (function(superclass){ Binary.prototype.compileMod = function(o){ var ref, code; ref = o.scope.temporary(); - code = [sn(this, "((("), this.first.compile(o), sn(this, ") % ("), sn(this, ref, " = "), this.second.compile(o), sn(this, ") + ", ref, ") % ", ref, ")")]; + code = [sn(this, "(("), this.first.compile(o), sn(this, ") % ("), sn(this, ref, " = "), this.second.compile(o), sn(this, ") + ", ref, ") % ", ref)]; o.scope.free(ref); - return sn.apply(null, [null].concat(arrayFrom$(code))); + if (o.level < LEVEL_OP + PREC['%']) { + return sn.apply(null, [null].concat(arrayFrom$(code))); + } else { + return sn.apply(null, [null, "("].concat(arrayFrom$(code), [")"])); + } }; Binary.prototype.compilePartial = function(o){ var vit, x, y; diff --git a/src/ast.ls b/src/ast.ls index abb759390..85f56e224 100644 --- a/src/ast.ls +++ b/src/ast.ls @@ -1527,9 +1527,11 @@ class exports.Binary extends Node compileMod: (o) -> ref = o.scope.temporary! - code = [sn(this, "((("), (@first.compile o), sn(this, ") % ("), sn(this, ref, " = "), (@second.compile o), sn(this, ") + ", ref, ") % ", ref, ")")] + code = [sn(this, "(("), (@first.compile o), sn(this, ") % ("), sn(this, ref, " = "), (@second.compile o), sn(this, ") + ", ref, ") % ", ref)] o.scope.free ref - sn(null, ...code) + if o.level < LEVEL_OP + PREC\% + then sn(null, ...code) + else sn(null, "(", ...code, ")") compilePartial: (o) -> vit = Var \it