File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -497,7 +497,7 @@ func (c *compiler) Expr(expr ast.Expr) {
497497 c .OpArg (vm .LOAD_CONST , c .Const (node .S ))
498498 case * ast.Bytes :
499499 // S py.Bytes
500- panic ( "FIXME compile: Bytes not implemented" )
500+ c . OpArg ( vm . LOAD_CONST , c . Const ( node . S ) )
501501 case * ast.NameConstant :
502502 // Value Singleton
503503 panic ("FIXME compile: NameConstant not implemented" )
Original file line number Diff line number Diff line change @@ -63,6 +63,23 @@ var compileTestData = []struct {
6363 Firstlineno : 1 ,
6464 Lnotab : "" ,
6565 }, " 1 0 LOAD_NAME 0 (a)\n 3 RETURN_VALUE\n " },
66+ {"b\" hello\" " , "eval" , py.Code {
67+ Argcount : 0 ,
68+ Kwonlyargcount : 0 ,
69+ Nlocals : 0 ,
70+ Stacksize : 1 ,
71+ Flags : 64 ,
72+ Code : "\x64 \x00 \x00 \x53 " ,
73+ Consts : []py.Object {py .Bytes ("hello" )},
74+ Names : []string {},
75+ Varnames : []string {},
76+ Freevars : []string {},
77+ Cellvars : []string {},
78+ Filename : "<string>" ,
79+ Name : "<module>" ,
80+ Firstlineno : 1 ,
81+ Lnotab : "" ,
82+ }, " 1 0 LOAD_CONST 0 (b'hello')\n 3 RETURN_VALUE\n " },
6683 {"\" a\" +1" , "eval" , py.Code {
6784 Argcount : 0 ,
6885 Kwonlyargcount : 0 ,
Original file line number Diff line number Diff line change 99import dis
1010
1111inp = [
12+ # Constants
1213 ('''1''' , "eval" ),
1314 ('''"hello"''' , "eval" ),
1415 ('''a''' , "eval" ),
16+ ('''b"hello"''' , "eval" ),
1517 # BinOps - strange operations to defeat constant optimizer!
1618 ('''"a"+1''' , "eval" ),
1719 ('''"a"-1''' , "eval" ),
@@ -84,6 +86,8 @@ def const(x):
8486 return 'py.Int(%d)' % x
8587 elif isinstance (x , float ):
8688 return 'py.Float(%g)' % x
89+ elif isinstance (x , bytes ):
90+ return 'py.Bytes("%s")' % x .decode ("latin1" )
8791 elif x is None :
8892 return 'py.None'
8993 else :
You can’t perform that action at this time.
0 commit comments