From 05edd05f7a329968a41e6c6ff4005fc0de717c91 Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Wed, 24 Sep 2008 15:18:17 +0000 Subject: [PATCH] added ~ unary operator --- Test.hx | 1 + hscript/Interp.hx | 6 ++++++ hscript/Parser.hx | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Test.hx b/Test.hx index 6693e0e..35fba99 100644 --- a/Test.hx +++ b/Test.hx @@ -30,6 +30,7 @@ class Test { test("0 < 0",false); test("-1 <= -1",true); test("1 + 2",3); + test("~545",-546); test("'abc' + 55","abc55"); test("'abc' + 'de'","abcde"); test("-1 + 2",1); diff --git a/hscript/Interp.hx b/hscript/Interp.hx index f593a8e..611fe7e 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -246,6 +246,12 @@ class Interp { return increment(e,prefix,1); case "--": return increment(e,prefix,-1); + case "~": + #if neko + return haxe.Int32.complement(expr(e)); + #else + return ~expr(e); + #end default: throw Error.EInvalidOp(op); } diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 1f9ebf5..4268cb1 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -61,7 +61,7 @@ class Parser { public function new() { line = 1; - opChars = "+*/-=!><&|^%"; + opChars = "+*/-=!><&|^%~"; identChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; opPriority = [ "...", @@ -74,7 +74,7 @@ class Parser { "*","/", "%" ]; - unopsPrefix = ["!","++","--","-"]; + unopsPrefix = ["!","++","--","-","~"]; unopsSuffix = ["++","--"]; }