1
0
Jelajahi Sumber

Add Number >> bitNot

Herby Vojčík 6 tahun lalu
induk
melakukan
f359328555
5 mengubah file dengan 76 tambahan dan 0 penghapusan
  1. 1 0
      API-CHANGES.txt
  2. 24 0
      src/Kernel-Objects.js
  3. 4 0
      src/Kernel-Objects.st
  4. 41 0
      src/Kernel-Tests.js
  5. 6 0
      src/Kernel-Tests.st

+ 1 - 0
API-CHANGES.txt

@@ -2,6 +2,7 @@
 
 + Number >>
   + bitAnd:
+  + bitNot
   + bitOr:
   + bitXor:
   + printStringBase:

+ 24 - 0
src/Kernel-Objects.js

@@ -3827,6 +3827,30 @@ messageSends: []
 }),
 $globals.Number);
 
+$core.addMethod(
+$core.method({
+selector: "bitNot",
+protocol: "converting",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return ~self;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"bitNot",{},$globals.Number)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "bitNot\x0a\x09<inlineJS: 'return ~self'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.Number);
+
 $core.addMethod(
 $core.method({
 selector: "bitOr:",

+ 4 - 0
src/Kernel-Objects.st

@@ -892,6 +892,10 @@ bitAnd: aNumber
 	<inlineJS: 'return self & aNumber'>
 !
 
+bitNot
+	<inlineJS: 'return ~self'>
+!
+
 bitOr: aNumber
 	<inlineJS: 'return self | aNumber'>
 !

+ 41 - 0
src/Kernel-Tests.js

@@ -12304,6 +12304,47 @@ messageSends: ["assert:equals:", "bitAnd:"]
 }),
 $globals.NumberTest);
 
+$core.addMethod(
+$core.method({
+selector: "testBitNot",
+protocol: "tests",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$2;
+$1=(2)._bitNot();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["bitNot"]=1;
+//>>excludeEnd("ctx");
+$self._assert_equals_($1,(-3));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["assert:equals:"]=1;
+//>>excludeEnd("ctx");
+$2=(-1)._bitNot();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["bitNot"]=2;
+//>>excludeEnd("ctx");
+$self._assert_equals_($2,(0));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["assert:equals:"]=2;
+//>>excludeEnd("ctx");
+$self._assert_equals_((-1022)._bitNot(),(1021));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testBitNot",{},$globals.NumberTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testBitNot\x0a\x09self assert: 2 bitNot equals: -3.\x0a\x09self assert: -1 bitNot equals: 0.\x0a\x09self assert: -1022 bitNot equals: 1021",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["assert:equals:", "bitNot"]
+}),
+$globals.NumberTest);
+
 $core.addMethod(
 $core.method({
 selector: "testBitOr",

+ 6 - 0
src/Kernel-Tests.st

@@ -2284,6 +2284,12 @@ testBitAnd
 	self assert: (-1 bitAnd: 1021) equals: 1021
 !
 
+testBitNot
+	self assert: 2 bitNot equals: -3.
+	self assert: -1 bitNot equals: 0.
+	self assert: -1022 bitNot equals: 1021
+!
+
 testBitOr
 	self assert: (2 bitOr: 4) equals: 6.
 	self assert: (7 bitOr: 2) equals: 7.