File tree 3 files changed +22
-1
lines changed
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) {
497
497
c .OpArg (vm .LOAD_CONST , c .Const (node .S ))
498
498
case * ast.Bytes :
499
499
// S py.Bytes
500
- panic ( "FIXME compile: Bytes not implemented" )
500
+ c . OpArg ( vm . LOAD_CONST , c . Const ( node . S ) )
501
501
case * ast.NameConstant :
502
502
// Value Singleton
503
503
panic ("FIXME compile: NameConstant not implemented" )
Original file line number Diff line number Diff line change @@ -63,6 +63,23 @@ var compileTestData = []struct {
63
63
Firstlineno : 1 ,
64
64
Lnotab : "" ,
65
65
}, " 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 " },
66
83
{"\" a\" +1" , "eval" , py.Code {
67
84
Argcount : 0 ,
68
85
Kwonlyargcount : 0 ,
Original file line number Diff line number Diff line change 9
9
import dis
10
10
11
11
inp = [
12
+ # Constants
12
13
('''1''' , "eval" ),
13
14
('''"hello"''' , "eval" ),
14
15
('''a''' , "eval" ),
16
+ ('''b"hello"''' , "eval" ),
15
17
# BinOps - strange operations to defeat constant optimizer!
16
18
('''"a"+1''' , "eval" ),
17
19
('''"a"-1''' , "eval" ),
@@ -84,6 +86,8 @@ def const(x):
84
86
return 'py.Int(%d)' % x
85
87
elif isinstance (x , float ):
86
88
return 'py.Float(%g)' % x
89
+ elif isinstance (x , bytes ):
90
+ return 'py.Bytes("%s")' % x .decode ("latin1" )
87
91
elif x is None :
88
92
return 'py.None'
89
93
else :
You can’t perform that action at this time.
0 commit comments