Add missing bits operator and power
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
403be35aa3
commit
60a9003b0c
@ -716,18 +716,26 @@ class HyASTCompiler(object):
|
||||
@builds("/")
|
||||
@builds("//")
|
||||
@builds("*")
|
||||
@builds("**")
|
||||
@builds("<<")
|
||||
@builds(">>")
|
||||
@builds("|")
|
||||
@builds("^")
|
||||
@builds("&")
|
||||
@checkargs(min=2)
|
||||
def compile_maths_expression(self, expression):
|
||||
# operator = Mod | Pow | LShift | RShift | BitOr |
|
||||
# BitXor | BitAnd | FloorDiv
|
||||
# (to implement list) XXX
|
||||
|
||||
ops = {"+": ast.Add,
|
||||
"/": ast.Div,
|
||||
"//": ast.FloorDiv,
|
||||
"*": ast.Mult,
|
||||
"-": ast.Sub,
|
||||
"%": ast.Mod}
|
||||
"%": ast.Mod,
|
||||
"**": ast.Pow,
|
||||
"<<": ast.LShift,
|
||||
">>": ast.RShift,
|
||||
"|": ast.BitOr,
|
||||
"^": ast.BitXor,
|
||||
"&": ast.BitAnd}
|
||||
|
||||
inv = expression.pop(0)
|
||||
op = ops[inv]
|
||||
|
@ -79,7 +79,7 @@ def _resolve_atom(obj):
|
||||
if obj.startswith(":"):
|
||||
return HyKeyword(obj)
|
||||
|
||||
if obj.startswith("*") and obj.endswith("*") and obj != "*":
|
||||
if obj.startswith("*") and obj.endswith("*") and obj not in ("*", "**"):
|
||||
obj = obj[1:-1].upper()
|
||||
|
||||
if "-" in obj and obj != "-":
|
||||
|
@ -39,3 +39,27 @@
|
||||
(defn test-modulo []
|
||||
"NATIVE: test mod"
|
||||
(assert (= (% 10 2) 0)))
|
||||
|
||||
(defn test-pow []
|
||||
"NATIVE: test pow"
|
||||
(assert (= (** 10 2) 100)))
|
||||
|
||||
(defn test-lshift []
|
||||
"NATIVE: test lshift"
|
||||
(assert (= (<< 1 2) 4)))
|
||||
|
||||
(defn test-rshift []
|
||||
"NATIVE: test lshift"
|
||||
(assert (= (>> 8 1) 4)))
|
||||
|
||||
(defn test-bitor []
|
||||
"NATIVE: test lshift"
|
||||
(assert (= (| 1 2) 3)))
|
||||
|
||||
(defn test-bitxor []
|
||||
"NATIVE: test xor"
|
||||
(assert (= (^ 1 2) 3)))
|
||||
|
||||
(defn test-bitand []
|
||||
"NATIVE: test lshift"
|
||||
(assert (= (& 1 2) 0)))
|
||||
|
Loading…
Reference in New Issue
Block a user