File tree Expand file tree Collapse file tree
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4343
4444import com .oracle .graal .python .builtins .Builtin ;
4545import com .oracle .graal .python .builtins .CoreFunctions ;
46+ import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
4647import com .oracle .graal .python .builtins .PythonBuiltins ;
4748import com .oracle .graal .python .builtins .objects .PNone ;
4849import com .oracle .graal .python .builtins .objects .PNotImplemented ;
@@ -1767,4 +1768,26 @@ Object doGeneric(@SuppressWarnings("unused") Object self) {
17671768 return PNotImplemented .NOT_IMPLEMENTED ;
17681769 }
17691770 }
1771+
1772+ @ Builtin (name = "to_bytes" , minNumOfArguments = 1 , maxNumOfArguments = 2 )
1773+ @ GenerateNodeFactory
1774+ abstract static class ToBytesNode extends PythonBuiltinNode {
1775+ @ Specialization
1776+ PBytes doInt (int self , int length ) {
1777+ byte [] bytes = new byte [length ];
1778+ for (int i = 0 ; i < length ; i ++) {
1779+ bytes [i ] = (byte ) ((self >> i ) & 0xFF );
1780+ }
1781+ return factory ().createBytes (bytes );
1782+ }
1783+
1784+ @ Specialization
1785+ PBytes doLong (long self , int length ) {
1786+ byte [] bytes = new byte [length ];
1787+ for (int i = 0 ; i < length ; i ++) {
1788+ bytes [i ] = (byte ) ((self >> i ) & 0xFF );
1789+ }
1790+ return factory ().createBytes (bytes );
1791+ }
1792+ }
17701793}
You can’t perform that action at this time.
0 commit comments