Skip to content

Commit be565d3

Browse files
committed
Make incognito a CodeFlag bit
1 parent 5b2cfb4 commit be565d3

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

bytecode/src/bytecode.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ pub struct CodeObject {
4646
pub source_path: String,
4747
pub first_line_number: usize,
4848
pub obj_name: String, // Name of the object that created this code object
49-
pub incognito: bool,
5049
}
5150

5251
bitflags! {
5352
#[derive(Serialize, Deserialize)]
54-
pub struct CodeFlags: u8 {
53+
pub struct CodeFlags: u16 {
5554
const HAS_DEFAULTS = 0x01;
5655
const HAS_KW_ONLY_DEFAULTS = 0x02;
5756
const HAS_ANNOTATIONS = 0x04;
5857
const NEW_LOCALS = 0x08;
5958
const IS_GENERATOR = 0x10;
6059
const IS_COROUTINE = 0x20;
60+
const INCOGNITO = 1 << 15;
6161
}
6262
}
6363

@@ -394,7 +394,6 @@ impl CodeObject {
394394
source_path,
395395
first_line_number,
396396
obj_name,
397-
incognito: false,
398397
}
399398
}
400399

@@ -451,6 +450,10 @@ impl CodeObject {
451450
}
452451
Display(self)
453452
}
453+
454+
pub fn incognito(&self) -> bool {
455+
self.flags.contains(CodeFlags::INCOGNITO)
456+
}
454457
}
455458

456459
impl fmt::Display for CodeObject {

compiler/src/compile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ impl<O: OutputStream> Compiler<O> {
189189
}
190190

191191
fn push_output(&mut self, mut code: CodeObject) {
192-
code.incognito = self.opts.incognito;
192+
code.flags
193+
.set(bytecode::CodeFlags::INCOGNITO, self.opts.incognito);
193194
self.output_stack.push(code.into());
194195
}
195196

vm/src/obj/objcode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl PyCodeRef {
103103
}
104104

105105
#[pyproperty]
106-
fn co_flags(self) -> u8 {
106+
fn co_flags(self) -> u16 {
107107
self.code.flags.bits()
108108
}
109109
}

vm/src/obj/objframe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl FrameRef {
3131

3232
#[pyproperty]
3333
fn f_globals(self, vm: &VirtualMachine) -> PyResult<PyDictRef> {
34-
if self.code.incognito {
34+
if self.code.incognito() {
3535
Err(vm.new_type_error("Can't get f_globals on an incognito frame".to_owned()))
3636
} else {
3737
Ok(self.scope.globals.clone())
@@ -40,7 +40,7 @@ impl FrameRef {
4040

4141
#[pyproperty]
4242
fn f_locals(self, vm: &VirtualMachine) -> PyResult<PyDictRef> {
43-
if self.code.incognito {
43+
if self.code.incognito() {
4444
Err(vm.new_type_error("Can't get f_locals on an incognito frame".to_owned()))
4545
} else {
4646
Ok(self.scope.get_locals())

vm/src/obj/objfunction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl PyFunction {
281281

282282
#[pyproperty(magic)]
283283
fn globals(&self, vm: &VirtualMachine) -> PyResult<PyDictRef> {
284-
if self.code.incognito {
284+
if self.code.incognito() {
285285
Err(vm.new_type_error("Can't get __globals__ on an incognito function".to_owned()))
286286
} else {
287287
Ok(self.scope.globals.clone())

0 commit comments

Comments
 (0)