Skip to content

Commit 9b2aead

Browse files
committed
compile: implement Bytes
1 parent b881849 commit 9b2aead

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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")

compile/compile_data_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

compile/make_compile_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import dis
1010

1111
inp = [
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:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy