Change FunctionOpArg to CodeFlags, stored in CodeObject

This commit is contained in:
coolreader18 authored and Noah committed 2019-10-14 20:20:52 +00:00
1 parent 1edf7c85aa
commit c08f11ad1b
9 files changed
+82 -83

No files matched your search

+8 -8
View File
@@ -37,6 +37,7 @@ pub struct CodeObject {
/// Jump targets.
pub label_map: HashMap<Label, usize>,
pub locations: Vec<Location>,
pub flags: CodeFlags,
pub arg_names: Vec<String>, // Names of positional arguments
pub varargs: Varargs, // *args or *
pub kwonlyarg_names: Vec<String>,
@@ -44,20 +45,20 @@ pub struct CodeObject {
pub source_path: String,
pub first_line_number: usize,
pub obj_name: String, // Name of the object that created this code object
pub is_generator: bool,
}
bitflags! {
#[derive(Serialize, Deserialize)]
pub struct FunctionOpArg: u8 {
pub struct CodeFlags: u8 {
const HAS_DEFAULTS = 0x01;
const HAS_KW_ONLY_DEFAULTS = 0x02;
const HAS_ANNOTATIONS = 0x04;
const NEW_LOCALS = 0x08;
const IS_GENERATOR = 0x10;
}
}
impl Default for FunctionOpArg {
impl Default for CodeFlags {
fn default() -> Self {
Self::NEW_LOCALS
}
@@ -176,9 +177,7 @@ pub enum Instruction {
JumpIfFalseOrPop {
target: Label,
},
MakeFunction {
flags: FunctionOpArg,
},
MakeFunction,
CallFunction {
typ: CallType,
},
@@ -355,6 +354,7 @@ pub enum BlockType {
impl CodeObject {
pub fn new(
flags: CodeFlags,
arg_names: Vec<String>,
varargs: Varargs,
kwonlyarg_names: Vec<String>,
@@ -367,6 +367,7 @@ impl CodeObject {
instructions: Vec::new(),
label_map: HashMap::new(),
locations: Vec::new(),
flags,
arg_names,
varargs,
kwonlyarg_names,
@@ -374,7 +375,6 @@ impl CodeObject {
source_path,
first_line_number,
obj_name,
is_generator: false,
}
}
@@ -513,7 +513,7 @@ impl Instruction {
JumpIfFalse { target } => w!(JumpIfFalse, label_map[target]),
JumpIfTrueOrPop { target } => w!(JumpIfTrueOrPop, label_map[target]),
JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, label_map[target]),
MakeFunction { flags } => w!(MakeFunction, format!("{:?}", flags)),
MakeFunction => w!(MakeFunction),
CallFunction { typ } => w!(CallFunction, format!("{:?}", typ)),
ForIter { target } => w!(ForIter, label_map[target]),
ReturnValue => w!(ReturnValue),