Update cspell for compiler

This commit is contained in:
Jeong YunWon 2023-03-16 21:27:02 +09:00
parent 5d2228999b
commit 70f8e04af3
32 changed files with 234 additions and 284 deletions

View file

@ -48,10 +48,10 @@ impl<'a> Unparser<'a> {
} }
fn unparse_expr<U>(&mut self, ast: &Expr<U>, level: u8) -> fmt::Result { fn unparse_expr<U>(&mut self, ast: &Expr<U>, level: u8) -> fmt::Result {
macro_rules! opprec { macro_rules! op_prec {
($opty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => { ($op_ty:ident, $x:expr, $enu:path, $($var:ident($op:literal, $prec:ident)),*$(,)?) => {
match $x { match $x {
$(<$enu>::$var => (opprec!(@space $opty, $op), precedence::$prec),)* $(<$enu>::$var => (op_prec!(@space $op_ty, $op), precedence::$prec),)*
} }
}; };
(@space bin, $op:literal) => { (@space bin, $op:literal) => {
@ -72,7 +72,7 @@ impl<'a> Unparser<'a> {
} }
match &ast.node { match &ast.node {
ExprKind::BoolOp { op, values } => { ExprKind::BoolOp { op, values } => {
let (op, prec) = opprec!(bin, op, Boolop, And("and", AND), Or("or", OR)); let (op, prec) = op_prec!(bin, op, Boolop, And("and", AND), Or("or", OR));
group_if!(prec, { group_if!(prec, {
let mut first = true; let mut first = true;
for val in values { for val in values {
@ -89,8 +89,8 @@ impl<'a> Unparser<'a> {
}) })
} }
ExprKind::BinOp { left, op, right } => { ExprKind::BinOp { left, op, right } => {
let rassoc = matches!(op, Operator::Pow); let right_associative = matches!(op, Operator::Pow);
let (op, prec) = opprec!( let (op, prec) = op_prec!(
bin, bin,
op, op,
Operator, Operator,
@ -109,13 +109,13 @@ impl<'a> Unparser<'a> {
FloorDiv("//", TERM), FloorDiv("//", TERM),
); );
group_if!(prec, { group_if!(prec, {
self.unparse_expr(left, prec + rassoc as u8)?; self.unparse_expr(left, prec + right_associative as u8)?;
self.p(op)?; self.p(op)?;
self.unparse_expr(right, prec + !rassoc as u8)?; self.unparse_expr(right, prec + !right_associative as u8)?;
}) })
} }
ExprKind::UnaryOp { op, operand } => { ExprKind::UnaryOp { op, operand } => {
let (op, prec) = opprec!( let (op, prec) = op_prec!(
un, un,
op, op,
crate::Unaryop, crate::Unaryop,
@ -131,8 +131,8 @@ impl<'a> Unparser<'a> {
} }
ExprKind::Lambda { args, body } => { ExprKind::Lambda { args, body } => {
group_if!(precedence::TEST, { group_if!(precedence::TEST, {
let npos = args.args.len() + args.posonlyargs.len(); let pos = args.args.len() + args.posonlyargs.len();
self.p(if npos > 0 { "lambda " } else { "lambda" })?; self.p(if pos > 0 { "lambda " } else { "lambda" })?;
self.unparse_args(args)?; self.unparse_args(args)?;
write!(self, ": {}", **body)?; write!(self, ": {}", **body)?;
}) })
@ -260,7 +260,7 @@ impl<'a> Unparser<'a> {
[], [],
) = (&**args, &**keywords) ) = (&**args, &**keywords)
{ {
// make sure a single genexp doesn't get double parens // make sure a single genexpr doesn't get double parens
self.unparse_expr(elt, precedence::TEST)?; self.unparse_expr(elt, precedence::TEST)?;
self.unparse_comp(generators)?; self.unparse_comp(generators)?;
} else { } else {
@ -287,7 +287,7 @@ impl<'a> Unparser<'a> {
conversion, conversion,
format_spec, format_spec,
} => self.unparse_formatted(value, *conversion, format_spec.as_deref())?, } => self.unparse_formatted(value, *conversion, format_spec.as_deref())?,
ExprKind::JoinedStr { values } => self.unparse_joinedstr(values, false)?, ExprKind::JoinedStr { values } => self.unparse_joined_str(values, false)?,
ExprKind::Constant { value, kind } => { ExprKind::Constant { value, kind } => {
if let Some(kind) = kind { if let Some(kind) = kind {
self.p(kind)?; self.p(kind)?;
@ -490,7 +490,7 @@ impl<'a> Unparser<'a> {
unreachable!() unreachable!()
} }
} }
ExprKind::JoinedStr { values } => self.unparse_joinedstr(values, is_spec), ExprKind::JoinedStr { values } => self.unparse_joined_str(values, is_spec),
ExprKind::FormattedValue { ExprKind::FormattedValue {
value, value,
conversion, conversion,
@ -505,7 +505,7 @@ impl<'a> Unparser<'a> {
self.p(&s) self.p(&s)
} }
fn unparse_joinedstr<U>(&mut self, values: &[Expr<U>], is_spec: bool) -> fmt::Result { fn unparse_joined_str<U>(&mut self, values: &[Expr<U>], is_spec: bool) -> fmt::Result {
if is_spec { if is_spec {
self.unparse_fstring_body(values, is_spec) self.unparse_fstring_body(values, is_spec)
} else { } else {

View file

@ -189,14 +189,14 @@ macro_rules! emit {
($c:expr, Instruction::$op:ident { $arg:ident$(,)? }$(,)?) => { ($c:expr, Instruction::$op:ident { $arg:ident$(,)? }$(,)?) => {
$c.emit_arg($arg, |x| Instruction::$op { $arg: x }) $c.emit_arg($arg, |x| Instruction::$op { $arg: x })
}; };
($c:expr, Instruction::$op:ident { $arg:ident : $argval:expr $(,)? }$(,)?) => { ($c:expr, Instruction::$op:ident { $arg:ident : $arg_val:expr $(,)? }$(,)?) => {
$c.emit_arg($argval, |x| Instruction::$op { $arg: x }) $c.emit_arg($arg_val, |x| Instruction::$op { $arg: x })
}; };
($c:expr, Instruction::$op:ident( $argval:expr $(,)? )$(,)?) => { ($c:expr, Instruction::$op:ident( $arg_val:expr $(,)? )$(,)?) => {
$c.emit_arg($argval, Instruction::$op) $c.emit_arg($arg_val, Instruction::$op)
}; };
($c:expr, Instruction::$op:ident$(,)?) => { ($c:expr, Instruction::$op:ident$(,)?) => {
$c.emit_noarg(Instruction::$op) $c.emit_no_arg(Instruction::$op)
}; };
} }
@ -331,7 +331,7 @@ impl Compiler {
cache: impl FnOnce(&mut ir::CodeInfo) -> &mut IndexSet<String>, cache: impl FnOnce(&mut ir::CodeInfo) -> &mut IndexSet<String>,
) -> bytecode::NameIdx { ) -> bytecode::NameIdx {
let name = self.mangle(name); let name = self.mangle(name);
let cache = cache(self.current_codeinfo()); let cache = cache(self.current_code_info());
cache cache
.get_index_of(name.as_ref()) .get_index_of(name.as_ref())
.unwrap_or_else(|| cache.insert_full(name.into_owned()).0) .unwrap_or_else(|| cache.insert_full(name.into_owned()).0)
@ -821,7 +821,7 @@ impl Compiler {
Some(v) => { Some(v) => {
if self.ctx.func == FunctionContext::AsyncFunction if self.ctx.func == FunctionContext::AsyncFunction
&& self && self
.current_codeinfo() .current_code_info()
.flags .flags
.contains(bytecode::CodeFlags::IS_GENERATOR) .contains(bytecode::CodeFlags::IS_GENERATOR)
{ {
@ -929,12 +929,12 @@ impl Compiler {
); );
} }
let mut funcflags = bytecode::MakeFunctionFlags::empty(); let mut func_flags = bytecode::MakeFunctionFlags::empty();
if have_defaults { if have_defaults {
funcflags |= bytecode::MakeFunctionFlags::DEFAULTS; func_flags |= bytecode::MakeFunctionFlags::DEFAULTS;
} }
if !args.kw_defaults.is_empty() { if !args.kw_defaults.is_empty() {
funcflags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS; func_flags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS;
} }
self.push_output( self.push_output(
@ -954,15 +954,15 @@ impl Compiler {
} }
if let Some(name) = args.vararg.as_deref() { if let Some(name) = args.vararg.as_deref() {
self.current_codeinfo().flags |= bytecode::CodeFlags::HAS_VARARGS; self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARARGS;
self.varname(&name.node.arg)?; self.varname(&name.node.arg)?;
} }
if let Some(name) = args.kwarg.as_deref() { if let Some(name) = args.kwarg.as_deref() {
self.current_codeinfo().flags |= bytecode::CodeFlags::HAS_VARKEYWORDS; self.current_code_info().flags |= bytecode::CodeFlags::HAS_VARKEYWORDS;
self.varname(&name.node.arg)?; self.varname(&name.node.arg)?;
} }
Ok(funcflags) Ok(func_flags)
} }
fn prepare_decorators(&mut self, decorator_list: &[ast::Expr]) -> CompileResult<()> { fn prepare_decorators(&mut self, decorator_list: &[ast::Expr]) -> CompileResult<()> {
@ -1133,8 +1133,8 @@ impl Compiler {
// Create bytecode for this function: // Create bytecode for this function:
self.prepare_decorators(decorator_list)?; self.prepare_decorators(decorator_list)?;
let mut funcflags = self.enter_function(name, args)?; let mut func_flags = self.enter_function(name, args)?;
self.current_codeinfo() self.current_code_info()
.flags .flags
.set(bytecode::CodeFlags::IS_COROUTINE, is_async); .set(bytecode::CodeFlags::IS_COROUTINE, is_async);
@ -1157,7 +1157,7 @@ impl Compiler {
let (doc_str, body) = split_doc(body); let (doc_str, body) = split_doc(body);
self.current_codeinfo() self.current_code_info()
.constants .constants
.insert_full(ConstantData::None); .insert_full(ConstantData::None);
@ -1210,7 +1210,7 @@ impl Compiler {
} }
if num_annotations > 0 { if num_annotations > 0 {
funcflags |= bytecode::MakeFunctionFlags::ANNOTATIONS; func_flags |= bytecode::MakeFunctionFlags::ANNOTATIONS;
emit!( emit!(
self, self,
Instruction::BuildMap { Instruction::BuildMap {
@ -1220,7 +1220,7 @@ impl Compiler {
} }
if self.build_closure(&code) { if self.build_closure(&code) {
funcflags |= bytecode::MakeFunctionFlags::CLOSURE; func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
} }
self.emit_constant(ConstantData::Code { self.emit_constant(ConstantData::Code {
@ -1231,7 +1231,7 @@ impl Compiler {
}); });
// Turn code object into function object: // Turn code object into function object:
emit!(self, Instruction::MakeFunction(funcflags)); emit!(self, Instruction::MakeFunction(func_flags));
emit!(self, Instruction::Duplicate); emit!(self, Instruction::Duplicate);
self.load_docstring(doc_str); self.load_docstring(doc_str);
@ -1388,10 +1388,10 @@ impl Compiler {
self.qualified_path.append(global_path_prefix.as_mut()); self.qualified_path.append(global_path_prefix.as_mut());
self.ctx = prev_ctx; self.ctx = prev_ctx;
let mut funcflags = bytecode::MakeFunctionFlags::empty(); let mut func_flags = bytecode::MakeFunctionFlags::empty();
if self.build_closure(&code) { if self.build_closure(&code) {
funcflags |= bytecode::MakeFunctionFlags::CLOSURE; func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
} }
self.emit_constant(ConstantData::Code { self.emit_constant(ConstantData::Code {
@ -1402,7 +1402,7 @@ impl Compiler {
}); });
// Turn code object into function object: // Turn code object into function object:
emit!(self, Instruction::MakeFunction(funcflags)); emit!(self, Instruction::MakeFunction(func_flags));
self.emit_constant(ConstantData::Str { self.emit_constant(ConstantData::Str {
value: name.to_owned(), value: name.to_owned(),
@ -1417,7 +1417,7 @@ impl Compiler {
} }
fn load_docstring(&mut self, doc_str: Option<String>) { fn load_docstring(&mut self, doc_str: Option<String>) {
// TODO: __doc__ must be default None and no bytecodes unless it is Some // TODO: __doc__ must be default None and no bytecode unless it is Some
// Duplicate top of stack (the function or class object) // Duplicate top of stack (the function or class object)
// Doc string value: // Doc string value:
@ -1603,12 +1603,12 @@ impl Compiler {
&mut self, &mut self,
left: &ast::Expr, left: &ast::Expr,
ops: &[ast::Cmpop], ops: &[ast::Cmpop],
vals: &[ast::Expr], exprs: &[ast::Expr],
) -> CompileResult<()> { ) -> CompileResult<()> {
assert!(!ops.is_empty()); assert!(!ops.is_empty());
assert_eq!(vals.len(), ops.len()); assert_eq!(exprs.len(), ops.len());
let (last_op, mid_ops) = ops.split_last().unwrap(); let (last_op, mid_ops) = ops.split_last().unwrap();
let (last_val, mid_vals) = vals.split_last().unwrap(); let (last_val, mid_exprs) = exprs.split_last().unwrap();
use bytecode::ComparisonOperator::*; use bytecode::ComparisonOperator::*;
use bytecode::TestOperator::*; use bytecode::TestOperator::*;
@ -1626,7 +1626,7 @@ impl Compiler {
}; };
// a == b == c == d // a == b == c == d
// compile into (pseudocode): // compile into (pseudo code):
// result = a == b // result = a == b
// if result: // if result:
// result = b == c // result = b == c
@ -1636,7 +1636,7 @@ impl Compiler {
// initialize lhs outside of loop // initialize lhs outside of loop
self.compile_expression(left)?; self.compile_expression(left)?;
let end_blocks = if mid_vals.is_empty() { let end_blocks = if mid_exprs.is_empty() {
None None
} else { } else {
let break_block = self.new_block(); let break_block = self.new_block();
@ -1645,7 +1645,7 @@ impl Compiler {
}; };
// for all comparisons except the last (as the last one doesn't need a conditional jump) // for all comparisons except the last (as the last one doesn't need a conditional jump)
for (op, val) in mid_ops.iter().zip(mid_vals) { for (op, val) in mid_ops.iter().zip(mid_exprs) {
self.compile_expression(val)?; self.compile_expression(val)?;
// store rhs for the next comparison in chain // store rhs for the next comparison in chain
emit!(self, Instruction::Duplicate); emit!(self, Instruction::Duplicate);
@ -2206,7 +2206,7 @@ impl Compiler {
let prev_ctx = self.ctx; let prev_ctx = self.ctx;
let name = "<lambda>".to_owned(); let name = "<lambda>".to_owned();
let mut funcflags = self.enter_function(&name, args)?; let mut func_flags = self.enter_function(&name, args)?;
self.ctx = CompileContext { self.ctx = CompileContext {
loop_data: Option::None, loop_data: Option::None,
@ -2214,7 +2214,7 @@ impl Compiler {
func: FunctionContext::Function, func: FunctionContext::Function,
}; };
self.current_codeinfo() self.current_code_info()
.constants .constants
.insert_full(ConstantData::None); .insert_full(ConstantData::None);
@ -2222,14 +2222,14 @@ impl Compiler {
emit!(self, Instruction::ReturnValue); emit!(self, Instruction::ReturnValue);
let code = self.pop_code_object(); let code = self.pop_code_object();
if self.build_closure(&code) { if self.build_closure(&code) {
funcflags |= bytecode::MakeFunctionFlags::CLOSURE; func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
} }
self.emit_constant(ConstantData::Code { self.emit_constant(ConstantData::Code {
code: Box::new(code), code: Box::new(code),
}); });
self.emit_constant(ConstantData::Str { value: name }); self.emit_constant(ConstantData::Str { value: name });
// Turn code object into function object: // Turn code object into function object:
emit!(self, Instruction::MakeFunction(funcflags)); emit!(self, Instruction::MakeFunction(func_flags));
self.ctx = prev_ctx; self.ctx = prev_ctx;
} }
@ -2345,24 +2345,24 @@ impl Compiler {
fn compile_keywords(&mut self, keywords: &[ast::Keyword]) -> CompileResult<()> { fn compile_keywords(&mut self, keywords: &[ast::Keyword]) -> CompileResult<()> {
let mut size = 0; let mut size = 0;
let groupby = keywords.iter().group_by(|e| e.node.arg.is_none()); let groupby = keywords.iter().group_by(|e| e.node.arg.is_none());
for (is_unpacking, subkeywords) in &groupby { for (is_unpacking, sub_keywords) in &groupby {
if is_unpacking { if is_unpacking {
for keyword in subkeywords { for keyword in sub_keywords {
self.compile_expression(&keyword.node.value)?; self.compile_expression(&keyword.node.value)?;
size += 1; size += 1;
} }
} else { } else {
let mut subsize = 0; let mut sub_size = 0;
for keyword in subkeywords { for keyword in sub_keywords {
if let Some(name) = &keyword.node.arg { if let Some(name) = &keyword.node.arg {
self.emit_constant(ConstantData::Str { self.emit_constant(ConstantData::Str {
value: name.to_owned(), value: name.to_owned(),
}); });
self.compile_expression(&keyword.node.value)?; self.compile_expression(&keyword.node.value)?;
subsize += 1; sub_size += 1;
} }
} }
emit!(self, Instruction::BuildMap { size: subsize }); emit!(self, Instruction::BuildMap { size: sub_size });
size += 1; size += 1;
} }
} }
@ -2634,9 +2634,9 @@ impl Compiler {
self.ctx = prev_ctx; self.ctx = prev_ctx;
let mut funcflags = bytecode::MakeFunctionFlags::empty(); let mut func_flags = bytecode::MakeFunctionFlags::empty();
if self.build_closure(&code) { if self.build_closure(&code) {
funcflags |= bytecode::MakeFunctionFlags::CLOSURE; func_flags |= bytecode::MakeFunctionFlags::CLOSURE;
} }
// List comprehension code: // List comprehension code:
@ -2650,7 +2650,7 @@ impl Compiler {
}); });
// Turn code object into function object: // Turn code object into function object:
emit!(self, Instruction::MakeFunction(funcflags)); emit!(self, Instruction::MakeFunction(func_flags));
// Evaluate iterated item: // Evaluate iterated item:
self.compile_expression(&generators[0].iter)?; self.compile_expression(&generators[0].iter)?;
@ -2694,7 +2694,7 @@ impl Compiler {
}); });
} }
fn emit_noarg(&mut self, ins: Instruction) { fn emit_no_arg(&mut self, ins: Instruction) {
self._emit(ins, OpArg::null(), ir::BlockIdx::NULL) self._emit(ins, OpArg::null(), ir::BlockIdx::NULL)
} }
@ -2710,29 +2710,29 @@ impl Compiler {
// fn block_done() // fn block_done()
fn emit_constant(&mut self, constant: ConstantData) { fn emit_constant(&mut self, constant: ConstantData) {
let info = self.current_codeinfo(); let info = self.current_code_info();
let idx = info.constants.insert_full(constant).0.to_u32(); let idx = info.constants.insert_full(constant).0.to_u32();
self.emit_arg(idx, |idx| Instruction::LoadConst { idx }) self.emit_arg(idx, |idx| Instruction::LoadConst { idx })
} }
fn current_codeinfo(&mut self) -> &mut ir::CodeInfo { fn current_code_info(&mut self) -> &mut ir::CodeInfo {
self.code_stack.last_mut().expect("no code on stack") self.code_stack.last_mut().expect("no code on stack")
} }
fn current_block(&mut self) -> &mut ir::Block { fn current_block(&mut self) -> &mut ir::Block {
let info = self.current_codeinfo(); let info = self.current_code_info();
&mut info.blocks[info.current_block] &mut info.blocks[info.current_block]
} }
fn new_block(&mut self) -> ir::BlockIdx { fn new_block(&mut self) -> ir::BlockIdx {
let code = self.current_codeinfo(); let code = self.current_code_info();
let idx = ir::BlockIdx(code.blocks.len().to_u32()); let idx = ir::BlockIdx(code.blocks.len().to_u32());
code.blocks.push(ir::Block::default()); code.blocks.push(ir::Block::default());
idx idx
} }
fn switch_to_block(&mut self, block: ir::BlockIdx) { fn switch_to_block(&mut self, block: ir::BlockIdx) {
let code = self.current_codeinfo(); let code = self.current_code_info();
let prev = code.current_block; let prev = code.current_block;
assert_eq!( assert_eq!(
code.blocks[block].next, code.blocks[block].next,
@ -2762,7 +2762,7 @@ impl Compiler {
} }
fn mark_generator(&mut self) { fn mark_generator(&mut self) {
self.current_codeinfo().flags |= bytecode::CodeFlags::IS_GENERATOR self.current_code_info().flags |= bytecode::CodeFlags::IS_GENERATOR
} }
} }
@ -2882,7 +2882,7 @@ mod tests {
($value:expr) => { ($value:expr) => {
insta::assert_snapshot!( insta::assert_snapshot!(
insta::internals::AutoName, insta::internals::AutoName,
$value.display_expand_codeobjects().to_string(), $value.display_expand_code_objects().to_string(),
stringify!($value) stringify!($value)
) )
}; };
@ -2925,7 +2925,7 @@ if (True and False) or (False and True):
for stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')): for stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):
with self.subTest(type=type(stop_exc)): with self.subTest(type=type(stop_exc)):
try: try:
async with woohoo(): async with egg():
raise stop_exc raise stop_exc
except Exception as ex: except Exception as ex:
self.assertIs(ex, stop_exc) self.assertIs(ex, stop_exc)

View file

@ -45,6 +45,7 @@ pub struct InstructionInfo {
pub location: Location, pub location: Location,
} }
// spell-checker:ignore petgraph
// TODO: look into using petgraph for handling blocks and stuff? it's heavier than this, but it // TODO: look into using petgraph for handling blocks and stuff? it's heavier than this, but it
// might enable more analysis/optimizations // might enable more analysis/optimizations
#[derive(Debug)] #[derive(Debug)]
@ -223,12 +224,12 @@ impl CodeInfo {
fn max_stackdepth(&self) -> u32 { fn max_stackdepth(&self) -> u32 {
let mut maxdepth = 0u32; let mut maxdepth = 0u32;
let mut stack = Vec::with_capacity(self.blocks.len()); let mut stack = Vec::with_capacity(self.blocks.len());
let mut startdepths = vec![u32::MAX; self.blocks.len()]; let mut start_depths = vec![u32::MAX; self.blocks.len()];
startdepths[0] = 0; start_depths[0] = 0;
stack.push(BlockIdx(0)); stack.push(BlockIdx(0));
const DEBUG: bool = false; const DEBUG: bool = false;
'process_blocks: while let Some(block) = stack.pop() { 'process_blocks: while let Some(block) = stack.pop() {
let mut depth = startdepths[block.idx()]; let mut depth = start_depths[block.idx()];
if DEBUG { if DEBUG {
eprintln!("===BLOCK {}===", block.0); eprintln!("===BLOCK {}===", block.0);
} }
@ -266,14 +267,14 @@ impl CodeInfo {
if target_depth > maxdepth { if target_depth > maxdepth {
maxdepth = target_depth maxdepth = target_depth
} }
stackdepth_push(&mut stack, &mut startdepths, i.target, target_depth); stackdepth_push(&mut stack, &mut start_depths, i.target, target_depth);
} }
depth = new_depth; depth = new_depth;
if instr.unconditional_branch() { if instr.unconditional_branch() {
continue 'process_blocks; continue 'process_blocks;
} }
} }
stackdepth_push(&mut stack, &mut startdepths, block.next, depth); stackdepth_push(&mut stack, &mut start_depths, block.next, depth);
} }
if DEBUG { if DEBUG {
eprintln!("DONE: {maxdepth}"); eprintln!("DONE: {maxdepth}");
@ -293,7 +294,7 @@ impl InstrDisplayContext for CodeInfo {
fn get_varname(&self, i: usize) -> &str { fn get_varname(&self, i: usize) -> &str {
self.varname_cache[i].as_ref() self.varname_cache[i].as_ref()
} }
fn get_cellname(&self, i: usize) -> &str { fn get_cell_name(&self, i: usize) -> &str {
self.cellvar_cache self.cellvar_cache
.get_index(i) .get_index(i)
.unwrap_or_else(|| &self.freevar_cache[i - self.cellvar_cache.len()]) .unwrap_or_else(|| &self.freevar_cache[i - self.cellvar_cache.len()])
@ -303,11 +304,11 @@ impl InstrDisplayContext for CodeInfo {
fn stackdepth_push( fn stackdepth_push(
stack: &mut Vec<BlockIdx>, stack: &mut Vec<BlockIdx>,
startdepths: &mut [u32], start_depths: &mut [u32],
target: BlockIdx, target: BlockIdx,
depth: u32, depth: u32,
) { ) {
let block_depth = &mut startdepths[target.idx()]; let block_depth = &mut start_depths[target.idx()];
if *block_depth == u32::MAX || depth > *block_depth { if *block_depth == u32::MAX || depth > *block_depth {
*block_depth = depth; *block_depth = depth;
stack.push(target); stack.push(target);

View file

@ -1,6 +1,6 @@
--- ---
source: compiler/codegen/src/compile.rs source: compiler/codegen/src/compile.rs
expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):\n with self.subTest(type=type(stop_exc)):\n try:\n async with woohoo():\n raise stop_exc\n except Exception as ex:\n self.assertIs(ex, stop_exc)\n else:\n self.fail(f'{stop_exc} was suppressed')\n\")" expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):\n with self.subTest(type=type(stop_exc)):\n try:\n async with egg():\n raise stop_exc\n except Exception as ex:\n self.assertIs(ex, stop_exc)\n else:\n self.fail(f'{stop_exc} was suppressed')\n\")"
--- ---
1 0 SetupLoop 1 0 SetupLoop
1 LoadNameAny (0, StopIteration) 1 LoadNameAny (0, StopIteration)
@ -26,7 +26,7 @@ expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyn
3 20 SetupExcept (40) 3 20 SetupExcept (40)
4 21 LoadNameAny (6, woohoo) 4 21 LoadNameAny (6, egg)
22 CallFunctionPositional(0) 22 CallFunctionPositional(0)
23 BeforeAsyncWith 23 BeforeAsyncWith
24 GetAwaitable 24 GetAwaitable

View file

@ -16,7 +16,7 @@ use rustpython_ast as ast;
use rustpython_compiler_core::Location; use rustpython_compiler_core::Location;
use std::{borrow::Cow, fmt}; use std::{borrow::Cow, fmt};
/// Captures all symbols in the current scope, and has a list of subscopes in this scope. /// Captures all symbols in the current scope, and has a list of sub-scopes in this scope.
#[derive(Clone)] #[derive(Clone)]
pub struct SymbolTable { pub struct SymbolTable {
/// The name of this symbol table. Often the name of the class or function. /// The name of this symbol table. Often the name of the class or function.
@ -25,7 +25,7 @@ pub struct SymbolTable {
/// The type of symbol table /// The type of symbol table
pub typ: SymbolTableType, pub typ: SymbolTableType,
/// The line number in the sourcecode where this symboltable begins. /// The line number in the source code where this symboltable begins.
pub line_number: usize, pub line_number: usize,
// Return True if the block is a nested class or function // Return True if the block is a nested class or function
@ -34,7 +34,7 @@ pub struct SymbolTable {
/// A set of symbols present on this scope level. /// A set of symbols present on this scope level.
pub symbols: IndexMap<String, Symbol>, pub symbols: IndexMap<String, Symbol>,
/// A list of subscopes in the order as found in the /// A list of sub-scopes in the order as found in the
/// AST nodes. /// AST nodes.
pub sub_tables: Vec<SymbolTable>, pub sub_tables: Vec<SymbolTable>,
} }
@ -107,7 +107,7 @@ bitflags! {
// this is required to correct the scope in the analysis. // this is required to correct the scope in the analysis.
const ASSIGNED_IN_COMPREHENSION = 0x040; const ASSIGNED_IN_COMPREHENSION = 0x040;
// indicates that the symbol is used a bound iterator variable. We distinguish this case // indicates that the symbol is used a bound iterator variable. We distinguish this case
// from normal assignment to detect unallowed re-assignment to iterator variables. // from normal assignment to detect disallowed re-assignment to iterator variables.
const ITER = 0x080; const ITER = 0x080;
/// indicates that the symbol is a free variable in a class method from the scope that the /// indicates that the symbol is a free variable in a class method from the scope that the
/// class is defined in, e.g.: /// class is defined in, e.g.:
@ -531,7 +531,7 @@ enum SymbolUsage {
AnnotationAssigned, AnnotationAssigned,
Parameter, Parameter,
AnnotationParameter, AnnotationParameter,
AssignedNamedExprInCompr, AssignedNamedExprInComprehension,
Iter, Iter,
} }
@ -741,7 +741,7 @@ impl SymbolTableBuilder {
Import { names } | ImportFrom { names, .. } => { Import { names } | ImportFrom { names, .. } => {
for name in names { for name in names {
if let Some(alias) = &name.node.asname { if let Some(alias) = &name.node.asname {
// `import mymodule as myalias` // `import my_module as my_alias`
self.register_name(alias, SymbolUsage::Imported, location)?; self.register_name(alias, SymbolUsage::Imported, location)?;
} else { } else {
// `import module` // `import module`
@ -1042,7 +1042,11 @@ impl SymbolTableBuilder {
if let Name { id, .. } = &target.node { if let Name { id, .. } = &target.node {
let table = self.tables.last().unwrap(); let table = self.tables.last().unwrap();
if table.typ == SymbolTableType::Comprehension { if table.typ == SymbolTableType::Comprehension {
self.register_name(id, SymbolUsage::AssignedNamedExprInCompr, location)?; self.register_name(
id,
SymbolUsage::AssignedNamedExprInComprehension,
location,
)?;
} else { } else {
// omit one recursion. When the handling of an store changes for // omit one recursion. When the handling of an store changes for
// Identifiers this needs adapted - more forward safe would be // Identifiers this needs adapted - more forward safe would be
@ -1256,7 +1260,7 @@ impl SymbolTableBuilder {
SymbolUsage::Assigned => { SymbolUsage::Assigned => {
flags.insert(SymbolFlags::ASSIGNED); flags.insert(SymbolFlags::ASSIGNED);
} }
SymbolUsage::AssignedNamedExprInCompr => { SymbolUsage::AssignedNamedExprInComprehension => {
flags.insert(SymbolFlags::ASSIGNED | SymbolFlags::ASSIGNED_IN_COMPREHENSION); flags.insert(SymbolFlags::ASSIGNED | SymbolFlags::ASSIGNED_IN_COMPREHENSION);
} }
SymbolUsage::Global => { SymbolUsage::Global => {
@ -1273,7 +1277,7 @@ impl SymbolTableBuilder {
// and even more checking // and even more checking
// it is not allowed to assign to iterator variables (by named expressions) // it is not allowed to assign to iterator variables (by named expressions)
if flags.contains(SymbolFlags::ITER | SymbolFlags::ASSIGNED) if flags.contains(SymbolFlags::ITER | SymbolFlags::ASSIGNED)
/*&& symbol.is_assign_namedexpr_in_comprehension*/ /*&& symbol.is_assign_named_expr_in_comprehension*/
{ {
return Err(SymbolTableError { return Err(SymbolTableError {
error: error:

View file

@ -1,4 +1,4 @@
//! Implement python as a virtual machine with bytecodes. This module //! Implement python as a virtual machine with bytecode. This module
//! implements bytecode structure. //! implements bytecode structure.
use crate::{marshal, Location}; use crate::{marshal, Location};
@ -85,7 +85,7 @@ impl ConstantBag for BasicBag {
} }
/// Primary container of a single code object. Each python function has /// Primary container of a single code object. Each python function has
/// a codeobject. Also a module has a codeobject. /// a code object. Also a module has a code object.
#[derive(Clone)] #[derive(Clone)]
pub struct CodeObject<C: Constant = ConstantData> { pub struct CodeObject<C: Constant = ConstantData> {
pub instructions: Box<[CodeUnit]>, pub instructions: Box<[CodeUnit]>,
@ -147,7 +147,7 @@ impl fmt::Debug for OpArgByte {
} }
} }
/// a full 32-bit oparg, including any possible ExtendedArg extension /// a full 32-bit op_arg, including any possible ExtendedArg extension
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
#[repr(transparent)] #[repr(transparent)]
pub struct OpArg(pub u32); pub struct OpArg(pub u32);
@ -156,7 +156,7 @@ impl OpArg {
OpArg(0) OpArg(0)
} }
/// Returns how many CodeUnits a instruction with this oparg will be encoded as /// Returns how many CodeUnits a instruction with this op_arg will be encoded as
#[inline] #[inline]
pub fn instr_size(self) -> usize { pub fn instr_size(self) -> usize {
(self.0 > 0xff) as usize + (self.0 > 0xff_ff) as usize + (self.0 > 0xff_ff_ff) as usize + 1 (self.0 > 0xff) as usize + (self.0 > 0xff_ff) as usize + (self.0 > 0xff_ff_ff) as usize + 1
@ -204,46 +204,46 @@ impl OpArgState {
} }
pub trait OpArgType: Copy { pub trait OpArgType: Copy {
fn from_oparg(x: u32) -> Option<Self>; fn from_op_arg(x: u32) -> Option<Self>;
fn to_oparg(self) -> u32; fn to_op_arg(self) -> u32;
} }
impl OpArgType for u32 { impl OpArgType for u32 {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(x) Some(x)
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self self
} }
} }
impl OpArgType for bool { impl OpArgType for bool {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(x != 0) Some(x != 0)
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self as u32 self as u32
} }
} }
macro_rules! oparg_enum { macro_rules! op_arg_enum {
($(#[$attr:meta])* $vis:vis enum $name:ident { $($(#[$var_attr:meta])* $var:ident = $discr:literal,)* }) => { ($(#[$attr:meta])* $vis:vis enum $name:ident { $($(#[$var_attr:meta])* $var:ident = $value:literal,)* }) => {
$(#[$attr])* $(#[$attr])*
$vis enum $name { $vis enum $name {
$($(#[$var_attr])* $var = $discr,)* $($(#[$var_attr])* $var = $value,)*
} }
impl OpArgType for $name { impl OpArgType for $name {
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self as u32 self as u32
} }
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(match u8::try_from(x).ok()? { Some(match u8::try_from(x).ok()? {
$($discr => Self::$var,)* $($value => Self::$var,)*
_ => return None, _ => return None,
}) })
} }
@ -261,7 +261,7 @@ impl<T: OpArgType> Arg<T> {
} }
#[inline] #[inline]
pub fn new(arg: T) -> (Self, OpArg) { pub fn new(arg: T) -> (Self, OpArg) {
(Self(PhantomData), OpArg(arg.to_oparg())) (Self(PhantomData), OpArg(arg.to_op_arg()))
} }
#[inline] #[inline]
pub fn new_single(arg: T) -> (Self, OpArgByte) pub fn new_single(arg: T) -> (Self, OpArgByte)
@ -276,13 +276,13 @@ impl<T: OpArgType> Arg<T> {
} }
#[inline(always)] #[inline(always)]
pub fn try_get(self, arg: OpArg) -> Option<T> { pub fn try_get(self, arg: OpArg) -> Option<T> {
T::from_oparg(arg.0) T::from_op_arg(arg.0)
} }
#[inline(always)] #[inline(always)]
/// # Safety /// # Safety
/// T::from_oparg(self) must succeed /// T::from_op_arg(self) must succeed
pub unsafe fn get_unchecked(self, arg: OpArg) -> T { pub unsafe fn get_unchecked(self, arg: OpArg) -> T {
match T::from_oparg(arg.0) { match T::from_op_arg(arg.0) {
Some(t) => t, Some(t) => t,
None => std::hint::unreachable_unchecked(), None => std::hint::unreachable_unchecked(),
} }
@ -310,11 +310,11 @@ pub struct Label(pub u32);
impl OpArgType for Label { impl OpArgType for Label {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(Label(x)) Some(Label(x))
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self.0 self.0
} }
} }
@ -325,7 +325,7 @@ impl fmt::Display for Label {
} }
} }
oparg_enum!( op_arg_enum!(
/// Transforms a value prior to formatting it. /// Transforms a value prior to formatting it.
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -344,11 +344,11 @@ oparg_enum!(
impl TryFrom<usize> for ConversionFlag { impl TryFrom<usize> for ConversionFlag {
type Error = usize; type Error = usize;
fn try_from(b: usize) -> Result<Self, Self::Error> { fn try_from(b: usize) -> Result<Self, Self::Error> {
u32::try_from(b).ok().and_then(Self::from_oparg).ok_or(b) u32::try_from(b).ok().and_then(Self::from_op_arg).ok_or(b)
} }
} }
oparg_enum!( op_arg_enum!(
/// The kind of Raise that occurred. /// The kind of Raise that occurred.
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -634,11 +634,11 @@ bitflags! {
} }
impl OpArgType for MakeFunctionFlags { impl OpArgType for MakeFunctionFlags {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
Some(unsafe { MakeFunctionFlags::from_bits_unchecked(x as u8) }) Some(unsafe { MakeFunctionFlags::from_bits_unchecked(x as u8) })
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
self.bits().into() self.bits().into()
} }
} }
@ -793,7 +793,7 @@ impl<C: Constant> BorrowedConstant<'_, C> {
} }
} }
oparg_enum!( op_arg_enum!(
/// The possible comparison operators /// The possible comparison operators
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -809,7 +809,7 @@ oparg_enum!(
} }
); );
oparg_enum!( op_arg_enum!(
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
pub enum TestOperator { pub enum TestOperator {
@ -822,7 +822,7 @@ oparg_enum!(
} }
); );
oparg_enum!( op_arg_enum!(
/// The possible Binary operators /// The possible Binary operators
/// # Examples /// # Examples
/// ///
@ -850,7 +850,7 @@ oparg_enum!(
} }
); );
oparg_enum!( op_arg_enum!(
/// The possible unary operators /// The possible unary operators
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
@ -870,12 +870,12 @@ pub struct UnpackExArgs {
impl OpArgType for UnpackExArgs { impl OpArgType for UnpackExArgs {
#[inline(always)] #[inline(always)]
fn from_oparg(x: u32) -> Option<Self> { fn from_op_arg(x: u32) -> Option<Self> {
let [before, after, ..] = x.to_le_bytes(); let [before, after, ..] = x.to_le_bytes();
Some(Self { before, after }) Some(Self { before, after })
} }
#[inline(always)] #[inline(always)]
fn to_oparg(self) -> u32 { fn to_op_arg(self) -> u32 {
u32::from_le_bytes([self.before, self.after, 0, 0]) u32::from_le_bytes([self.before, self.after, 0, 0])
} }
} }
@ -925,20 +925,20 @@ impl<C: Constant> CodeObject<C> {
pub fn arg_names(&self) -> Arguments<C::Name> { pub fn arg_names(&self) -> Arguments<C::Name> {
let nargs = self.arg_count as usize; let nargs = self.arg_count as usize;
let nkwargs = self.kwonlyarg_count as usize; let nkwargs = self.kwonlyarg_count as usize;
let mut varargspos = nargs + nkwargs; let mut varargs_pos = nargs + nkwargs;
let posonlyargs = &self.varnames[..self.posonlyarg_count as usize]; let posonlyargs = &self.varnames[..self.posonlyarg_count as usize];
let args = &self.varnames[..nargs]; let args = &self.varnames[..nargs];
let kwonlyargs = &self.varnames[nargs..varargspos]; let kwonlyargs = &self.varnames[nargs..varargs_pos];
let vararg = if self.flags.contains(CodeFlags::HAS_VARARGS) { let vararg = if self.flags.contains(CodeFlags::HAS_VARARGS) {
let vararg = &self.varnames[varargspos]; let vararg = &self.varnames[varargs_pos];
varargspos += 1; varargs_pos += 1;
Some(vararg) Some(vararg)
} else { } else {
None None
}; };
let varkwarg = if self.flags.contains(CodeFlags::HAS_VARKEYWORDS) { let varkwarg = if self.flags.contains(CodeFlags::HAS_VARKEYWORDS) {
Some(&self.varnames[varargspos]) Some(&self.varnames[varargs_pos])
} else { } else {
None None
}; };
@ -968,7 +968,7 @@ impl<C: Constant> CodeObject<C> {
fn display_inner( fn display_inner(
&self, &self,
f: &mut fmt::Formatter, f: &mut fmt::Formatter,
expand_codeobjects: bool, expand_code_objects: bool,
level: usize, level: usize,
) -> fmt::Result { ) -> fmt::Result {
let label_targets = self.label_targets(); let label_targets = self.label_targets();
@ -1007,14 +1007,14 @@ impl<C: Constant> CodeObject<C> {
write!(f, "{arrow} {offset:offset_digits$} ")?; write!(f, "{arrow} {offset:offset_digits$} ")?;
// instruction // instruction
instruction.fmt_dis(arg, f, self, expand_codeobjects, 21, level)?; instruction.fmt_dis(arg, f, self, expand_code_objects, 21, level)?;
writeln!(f)?; writeln!(f)?;
} }
Ok(()) Ok(())
} }
/// Recursively display this CodeObject /// Recursively display this CodeObject
pub fn display_expand_codeobjects(&self) -> impl fmt::Display + '_ { pub fn display_expand_code_objects(&self) -> impl fmt::Display + '_ {
struct Display<'a, C: Constant>(&'a CodeObject<C>); struct Display<'a, C: Constant>(&'a CodeObject<C>);
impl<C: Constant> fmt::Display for Display<'_, C> { impl<C: Constant> fmt::Display for Display<'_, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -1287,7 +1287,7 @@ impl Instruction {
arg: OpArg, arg: OpArg,
f: &mut fmt::Formatter, f: &mut fmt::Formatter,
ctx: &impl InstrDisplayContext, ctx: &impl InstrDisplayContext,
expand_codeobjects: bool, expand_code_objects: bool,
pad: usize, pad: usize,
level: usize, level: usize,
) -> fmt::Result { ) -> fmt::Result {
@ -1295,26 +1295,26 @@ impl Instruction {
($variant:ident) => { ($variant:ident) => {
write!(f, stringify!($variant)) write!(f, stringify!($variant))
}; };
($variant:ident, $map:ident = $argmarker:expr) => {{ ($variant:ident, $map:ident = $arg_marker:expr) => {{
let arg = $argmarker.get(arg); let arg = $arg_marker.get(arg);
write!(f, "{:pad$}({}, {})", stringify!($variant), arg, $map(arg)) write!(f, "{:pad$}({}, {})", stringify!($variant), arg, $map(arg))
}}; }};
($variant:ident, $argmarker:expr) => { ($variant:ident, $arg_marker:expr) => {
write!(f, "{:pad$}({})", stringify!($variant), $argmarker.get(arg)) write!(f, "{:pad$}({})", stringify!($variant), $arg_marker.get(arg))
}; };
($variant:ident, ?$argmarker:expr) => { ($variant:ident, ?$arg_marker:expr) => {
write!( write!(
f, f,
"{:pad$}({:?})", "{:pad$}({:?})",
stringify!($variant), stringify!($variant),
$argmarker.get(arg) $arg_marker.get(arg)
) )
}; };
} }
let varname = |i: u32| ctx.get_varname(i as usize); let varname = |i: u32| ctx.get_varname(i as usize);
let name = |i: u32| ctx.get_name(i as usize); let name = |i: u32| ctx.get_name(i as usize);
let cellname = |i: u32| ctx.get_cellname(i as usize); let cell_name = |i: u32| ctx.get_cell_name(i as usize);
match self { match self {
ImportName { idx } => w!(ImportName, name = idx), ImportName { idx } => w!(ImportName, name = idx),
@ -1324,17 +1324,17 @@ impl Instruction {
LoadFast(idx) => w!(LoadFast, varname = idx), LoadFast(idx) => w!(LoadFast, varname = idx),
LoadNameAny(idx) => w!(LoadNameAny, name = idx), LoadNameAny(idx) => w!(LoadNameAny, name = idx),
LoadGlobal(idx) => w!(LoadGlobal, name = idx), LoadGlobal(idx) => w!(LoadGlobal, name = idx),
LoadDeref(idx) => w!(LoadDeref, cellname = idx), LoadDeref(idx) => w!(LoadDeref, cell_name = idx),
LoadClassDeref(idx) => w!(LoadClassDeref, cellname = idx), LoadClassDeref(idx) => w!(LoadClassDeref, cell_name = idx),
StoreFast(idx) => w!(StoreFast, varname = idx), StoreFast(idx) => w!(StoreFast, varname = idx),
StoreLocal(idx) => w!(StoreLocal, name = idx), StoreLocal(idx) => w!(StoreLocal, name = idx),
StoreGlobal(idx) => w!(StoreGlobal, name = idx), StoreGlobal(idx) => w!(StoreGlobal, name = idx),
StoreDeref(idx) => w!(StoreDeref, cellname = idx), StoreDeref(idx) => w!(StoreDeref, cell_name = idx),
DeleteFast(idx) => w!(DeleteFast, varname = idx), DeleteFast(idx) => w!(DeleteFast, varname = idx),
DeleteLocal(idx) => w!(DeleteLocal, name = idx), DeleteLocal(idx) => w!(DeleteLocal, name = idx),
DeleteGlobal(idx) => w!(DeleteGlobal, name = idx), DeleteGlobal(idx) => w!(DeleteGlobal, name = idx),
DeleteDeref(idx) => w!(DeleteDeref, cellname = idx), DeleteDeref(idx) => w!(DeleteDeref, cell_name = idx),
LoadClosure(i) => w!(LoadClosure, cellname = i), LoadClosure(i) => w!(LoadClosure, cell_name = i),
Subscript => w!(Subscript), Subscript => w!(Subscript),
StoreSubscript => w!(StoreSubscript), StoreSubscript => w!(StoreSubscript),
DeleteSubscript => w!(DeleteSubscript), DeleteSubscript => w!(DeleteSubscript),
@ -1343,7 +1343,7 @@ impl Instruction {
LoadConst { idx } => { LoadConst { idx } => {
let value = ctx.get_constant(idx.get(arg) as usize); let value = ctx.get_constant(idx.get(arg) as usize);
match value.borrow_constant() { match value.borrow_constant() {
BorrowedConstant::Code { code } if expand_codeobjects => { BorrowedConstant::Code { code } if expand_code_objects => {
write!(f, "{:pad$}({:?}):", "LoadConst", code)?; write!(f, "{:pad$}({:?}):", "LoadConst", code)?;
code.display_inner(f, true, level + 1)?; code.display_inner(f, true, level + 1)?;
Ok(()) Ok(())
@ -1434,7 +1434,7 @@ pub trait InstrDisplayContext {
fn get_constant(&self, i: usize) -> &Self::Constant; fn get_constant(&self, i: usize) -> &Self::Constant;
fn get_name(&self, i: usize) -> &str; fn get_name(&self, i: usize) -> &str;
fn get_varname(&self, i: usize) -> &str; fn get_varname(&self, i: usize) -> &str;
fn get_cellname(&self, i: usize) -> &str; fn get_cell_name(&self, i: usize) -> &str;
} }
impl<C: Constant> InstrDisplayContext for CodeObject<C> { impl<C: Constant> InstrDisplayContext for CodeObject<C> {
@ -1448,7 +1448,7 @@ impl<C: Constant> InstrDisplayContext for CodeObject<C> {
fn get_varname(&self, i: usize) -> &str { fn get_varname(&self, i: usize) -> &str {
self.varnames[i].as_ref() self.varnames[i].as_ref()
} }
fn get_cellname(&self, i: usize) -> &str { fn get_cell_name(&self, i: usize) -> &str {
self.cellvars self.cellvars
.get(i) .get(i)
.unwrap_or_else(|| &self.freevars[i - self.cellvars.len()]) .unwrap_or_else(|| &self.freevars[i - self.cellvars.len()])
@ -1491,7 +1491,7 @@ pub mod frozen_lib {
} }
impl<B: AsRef<[u8]>> FrozenCodeObject<B> { impl<B: AsRef<[u8]>> FrozenCodeObject<B> {
/// Decode a frozen codeobject /// Decode a frozen code object
#[inline] #[inline]
pub fn decode<Bag: AsBag>( pub fn decode<Bag: AsBag>(
&self, &self,

View file

@ -1,7 +1,7 @@
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Sourcecode location. /// Source code location.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Location { pub struct Location {

View file

@ -112,7 +112,7 @@ fn gen_phf(out_dir: &Path) {
.entry("False", "Tok::False") .entry("False", "Tok::False")
.entry("None", "Tok::None") .entry("None", "Tok::None")
.entry("True", "Tok::True") .entry("True", "Tok::True")
// moreso "standard" keywords // more so "standard" keywords
.entry("and", "Tok::And") .entry("and", "Tok::And")
.entry("as", "Tok::As") .entry("as", "Tok::As")
.entry("assert", "Tok::Assert") .entry("assert", "Tok::Assert")

View file

@ -241,6 +241,7 @@ where
lxr.window.slide(); lxr.window.slide();
lxr.window.slide(); lxr.window.slide();
// TODO: Handle possible mismatch between BOM and explicit encoding declaration. // TODO: Handle possible mismatch between BOM and explicit encoding declaration.
// spell-checker:ignore feff
if let Some('\u{feff}') = lxr.window[0] { if let Some('\u{feff}') = lxr.window[0] {
lxr.window.slide(); lxr.window.slide();
} }
@ -1085,7 +1086,7 @@ where
} }
} }
' ' | '\t' | '\x0C' => { ' ' | '\t' | '\x0C' => {
// Skip whitespaces // Skip white-spaces
self.next_char(); self.next_char();
while let Some(' ' | '\t' | '\x0C') = self.window[0] { while let Some(' ' | '\t' | '\x0C') = self.window[0] {
self.next_char(); self.next_char();
@ -1327,7 +1328,7 @@ mod tests {
lexer.map(|x| x.unwrap().1).collect() lexer.map(|x| x.unwrap().1).collect()
} }
fn stok(s: &str) -> Tok { fn str_tok(s: &str) -> Tok {
Tok::String { Tok::String {
value: s.to_owned(), value: s.to_owned(),
kind: StringKind::String, kind: StringKind::String,
@ -1335,7 +1336,7 @@ mod tests {
} }
} }
fn raw_stok(s: &str) -> Tok { fn raw_str_tok(s: &str) -> Tok {
Tok::String { Tok::String {
value: s.to_owned(), value: s.to_owned(),
kind: StringKind::RawString, kind: StringKind::RawString,
@ -1434,13 +1435,13 @@ mod tests {
#[test] #[test]
fn test_assignment() { fn test_assignment() {
let source = r"avariable = 99 + 2-0"; let source = r"a_variable = 99 + 2-0";
let tokens = lex_source(source); let tokens = lex_source(source);
assert_eq!( assert_eq!(
tokens, tokens,
vec![ vec![
Tok::Name { Tok::Name {
name: String::from("avariable"), name: String::from("a_variable"),
}, },
Tok::Equal, Tok::Equal,
Tok::Int { Tok::Int {
@ -1663,13 +1664,13 @@ mod tests {
vec![ vec![
Tok::Lpar, Tok::Lpar,
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
stok("a"), str_tok("a"),
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
stok("b"), str_tok("b"),
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
stok("c"), str_tok("c"),
stok("d"), str_tok("d"),
Tok::NonLogicalNewline, Tok::NonLogicalNewline,
Tok::Rpar, Tok::Rpar,
Tok::Newline, Tok::Newline,
@ -1716,15 +1717,15 @@ mod tests {
assert_eq!( assert_eq!(
tokens, tokens,
vec![ vec![
stok("double"), str_tok("double"),
stok("single"), str_tok("single"),
stok(r"can\'t"), str_tok(r"can\'t"),
stok(r#"\\\""#), str_tok(r#"\\\""#),
stok(r"\t\r\n"), str_tok(r"\t\r\n"),
stok(r"\g"), str_tok(r"\g"),
raw_stok(r"raw\'"), raw_str_tok(r"raw\'"),
stok(r"\420"), str_tok(r"\420"),
stok(r"\200\0a"), str_tok(r"\200\0a"),
Tok::Newline, Tok::Newline,
] ]
); );
@ -1740,7 +1741,7 @@ mod tests {
assert_eq!( assert_eq!(
tokens, tokens,
vec![ vec![
stok("abc\\\ndef"), str_tok("abc\\\ndef"),
Tok::Newline, Tok::Newline,
] ]
) )
@ -1759,7 +1760,7 @@ mod tests {
fn test_escape_unicode_name() { fn test_escape_unicode_name() {
let source = r#""\N{EN SPACE}""#; let source = r#""\N{EN SPACE}""#;
let tokens = lex_source(source); let tokens = lex_source(source);
assert_eq!(tokens, vec![stok(r"\N{EN SPACE}"), Tok::Newline]) assert_eq!(tokens, vec![str_tok(r"\N{EN SPACE}"), Tok::Newline])
} }
macro_rules! test_triple_quoted { macro_rules! test_triple_quoted {

View file

@ -433,14 +433,14 @@ class Foo(A, B):
} }
#[test] #[test]
fn test_parse_boolop_or() { fn test_parse_bool_op_or() {
let source = "x or y"; let source = "x or y";
let parse_ast = parse_expression(source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_boolop_and() { fn test_parse_bool_op_and() {
let source = "x and y"; let source = "x and y";
let parse_ast = parse_expression(source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
@ -513,10 +513,10 @@ with (0 as a, 1 as b,): pass
#[test] #[test]
fn test_star_index() { fn test_star_index() {
let source = "\ let source = "\
array_slice = array[0, *idxs, -1] array_slice = array[0, *indexes, -1]
array[0, *idxs, -1] = array_slice array[0, *indexes, -1] = array_slice
array[*idxs_to_select, *idxs_to_select] array[*indexes_to_select, *indexes_to_select]
array[3:5, *idxs_to_select] array[3:5, *indexes_to_select]
"; ";
let parse_ast = parse_program(source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);

View file

@ -1,42 +0,0 @@
---
source: compiler/parser/src/context.rs
expression: parse_ast
---
[
Located {
location: Location {
row: 1,
column: 1,
},
custom: (),
node: Assign {
targets: [
Located {
location: Location {
row: 1,
column: 1,
},
custom: (),
node: Name {
id: "x",
ctx: Store,
},
},
],
value: Located {
location: Location {
row: 1,
column: 5,
},
custom: (),
node: Constant {
value: Int(
1,
),
kind: None,
},
},
type_comment: None,
},
},
]

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/function.rs source: compiler/parser/src/function.rs
assertion_line: 165
expression: parse_ast expression: parse_ast
--- ---
Ok( Ok(

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/function.rs source: compiler/parser/src/function.rs
assertion_line: 165
expression: parse_ast expression: parse_ast
--- ---
Ok( Ok(

View file

@ -1,5 +1,5 @@
--- ---
source: parser/src/parser.rs source: compiler/parser/src/parser.rs
expression: parse_ast expression: parse_ast
--- ---
[] []

View file

@ -11,7 +11,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 33, column: 36,
}, },
), ),
custom: (), custom: (),
@ -43,7 +43,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 33, column: 36,
}, },
), ),
custom: (), custom: (),
@ -73,7 +73,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 32, column: 35,
}, },
), ),
custom: (), custom: (),
@ -106,7 +106,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 28, column: 31,
}, },
), ),
custom: (), custom: (),
@ -119,12 +119,12 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 28, column: 31,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs", id: "indexes",
ctx: Load, ctx: Load,
}, },
}, },
@ -134,12 +134,12 @@ expression: parse_ast
Located { Located {
location: Location { location: Location {
row: 1, row: 1,
column: 30, column: 33,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 32, column: 35,
}, },
), ),
custom: (), custom: (),
@ -148,12 +148,12 @@ expression: parse_ast
operand: Located { operand: Located {
location: Location { location: Location {
row: 1, row: 1,
column: 31, column: 34,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 1, row: 1,
column: 32, column: 35,
}, },
), ),
custom: (), custom: (),
@ -184,7 +184,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 33, column: 36,
}, },
), ),
custom: (), custom: (),
@ -198,7 +198,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 19, column: 22,
}, },
), ),
custom: (), custom: (),
@ -228,7 +228,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 18, column: 21,
}, },
), ),
custom: (), custom: (),
@ -261,7 +261,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 14, column: 17,
}, },
), ),
custom: (), custom: (),
@ -274,12 +274,12 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 14, column: 17,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs", id: "indexes",
ctx: Load, ctx: Load,
}, },
}, },
@ -289,12 +289,12 @@ expression: parse_ast
Located { Located {
location: Location { location: Location {
row: 2, row: 2,
column: 16, column: 19,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 18, column: 21,
}, },
), ),
custom: (), custom: (),
@ -303,12 +303,12 @@ expression: parse_ast
operand: Located { operand: Located {
location: Location { location: Location {
row: 2, row: 2,
column: 17, column: 20,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 18, column: 21,
}, },
), ),
custom: (), custom: (),
@ -332,12 +332,12 @@ expression: parse_ast
value: Located { value: Located {
location: Location { location: Location {
row: 2, row: 2,
column: 22, column: 25,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 2, row: 2,
column: 33, column: 36,
}, },
), ),
custom: (), custom: (),
@ -357,7 +357,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 39, column: 45,
}, },
), ),
custom: (), custom: (),
@ -370,7 +370,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 39, column: 45,
}, },
), ),
custom: (), custom: (),
@ -400,7 +400,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 38, column: 44,
}, },
), ),
custom: (), custom: (),
@ -414,7 +414,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 21, column: 24,
}, },
), ),
custom: (), custom: (),
@ -427,12 +427,12 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 21, column: 24,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs_to_select", id: "indexes_to_select",
ctx: Load, ctx: Load,
}, },
}, },
@ -442,12 +442,12 @@ expression: parse_ast
Located { Located {
location: Location { location: Location {
row: 3, row: 3,
column: 23, column: 26,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 38, column: 44,
}, },
), ),
custom: (), custom: (),
@ -455,17 +455,17 @@ expression: parse_ast
value: Located { value: Located {
location: Location { location: Location {
row: 3, row: 3,
column: 24, column: 27,
}, },
end_location: Some( end_location: Some(
Location { Location {
row: 3, row: 3,
column: 38, column: 44,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs_to_select", id: "indexes_to_select",
ctx: Load, ctx: Load,
}, },
}, },
@ -489,7 +489,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 27, column: 30,
}, },
), ),
custom: (), custom: (),
@ -502,7 +502,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 27, column: 30,
}, },
), ),
custom: (), custom: (),
@ -532,7 +532,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 26, column: 29,
}, },
), ),
custom: (), custom: (),
@ -604,7 +604,7 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 26, column: 29,
}, },
), ),
custom: (), custom: (),
@ -617,12 +617,12 @@ expression: parse_ast
end_location: Some( end_location: Some(
Location { Location {
row: 4, row: 4,
column: 26, column: 29,
}, },
), ),
custom: (), custom: (),
node: Name { node: Name {
id: "idxs_to_select", id: "indexes_to_select",
ctx: Load, ctx: Load,
}, },
}, },

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 698
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 706
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 714
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 690
expression: "parse_fstring(\"\").unwrap()" expression: "parse_fstring(\"\").unwrap()"
--- ---
[] []

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 669
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 766
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 677
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 759
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 685
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 773
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 780
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -1,6 +1,5 @@
--- ---
source: compiler/parser/src/string.rs source: compiler/parser/src/string.rs
assertion_line: 787
expression: parse_ast expression: parse_ast
--- ---
[ [

View file

@ -27,7 +27,7 @@ where
{ {
pub fn new(lexer: I, mode: Mode) -> Self { pub fn new(lexer: I, mode: Mode) -> Self {
Self { Self {
underlying: lexer.multipeek(), underlying: lexer.multipeek(), // spell-checker:ignore multipeek
start_of_line: matches!(mode, Mode::Interactive | Mode::Module), start_of_line: matches!(mode, Mode::Interactive | Mode::Module),
} }
} }

View file

@ -179,7 +179,7 @@ impl<'a> StringParser<'a> {
let mut expression = String::new(); let mut expression = String::new();
let mut spec = None; let mut spec = None;
let mut delims = Vec::new(); let mut delimiters = Vec::new();
let mut conversion = ConversionFlag::None; let mut conversion = ConversionFlag::None;
let mut self_documenting = false; let mut self_documenting = false;
let mut trailing_seq = String::new(); let mut trailing_seq = String::new();
@ -194,7 +194,7 @@ impl<'a> StringParser<'a> {
expression.push('='); expression.push('=');
self.next_char(); self.next_char();
} }
'!' if delims.is_empty() && self.peek() != Some(&'=') => { '!' if delimiters.is_empty() && self.peek() != Some(&'=') => {
if expression.trim().is_empty() { if expression.trim().is_empty() {
return Err(FStringError::new(EmptyExpression, self.get_pos()).into()); return Err(FStringError::new(EmptyExpression, self.get_pos()).into());
} }
@ -223,11 +223,11 @@ impl<'a> StringParser<'a> {
// match a python 3.8 self documenting expression // match a python 3.8 self documenting expression
// format '{' PYTHON_EXPRESSION '=' FORMAT_SPECIFIER? '}' // format '{' PYTHON_EXPRESSION '=' FORMAT_SPECIFIER? '}'
'=' if self.peek() != Some(&'=') && delims.is_empty() => { '=' if self.peek() != Some(&'=') && delimiters.is_empty() => {
self_documenting = true; self_documenting = true;
} }
':' if delims.is_empty() => { ':' if delimiters.is_empty() => {
let parsed_spec = self.parse_spec(nested)?; let parsed_spec = self.parse_spec(nested)?;
spec = Some(Box::new(self.expr(ExprKind::JoinedStr { spec = Some(Box::new(self.expr(ExprKind::JoinedStr {
@ -236,10 +236,10 @@ impl<'a> StringParser<'a> {
} }
'(' | '{' | '[' => { '(' | '{' | '[' => {
expression.push(ch); expression.push(ch);
delims.push(ch); delimiters.push(ch);
} }
')' => { ')' => {
let last_delim = delims.pop(); let last_delim = delimiters.pop();
match last_delim { match last_delim {
Some('(') => { Some('(') => {
expression.push(ch); expression.push(ch);
@ -257,7 +257,7 @@ impl<'a> StringParser<'a> {
} }
} }
']' => { ']' => {
let last_delim = delims.pop(); let last_delim = delimiters.pop();
match last_delim { match last_delim {
Some('[') => { Some('[') => {
expression.push(ch); expression.push(ch);
@ -274,8 +274,8 @@ impl<'a> StringParser<'a> {
} }
} }
} }
'}' if !delims.is_empty() => { '}' if !delimiters.is_empty() => {
let last_delim = delims.pop(); let last_delim = delimiters.pop();
match last_delim { match last_delim {
Some('{') => { Some('{') => {
expression.push(ch); expression.push(ch);
@ -800,7 +800,7 @@ mod tests {
} }
#[test] #[test]
fn test_fstring_parse_selfdocumenting_base() { fn test_fstring_parse_self_documenting_base() {
let src = "{user=}"; let src = "{user=}";
let parse_ast = parse_fstring(src).unwrap(); let parse_ast = parse_fstring(src).unwrap();
@ -808,7 +808,7 @@ mod tests {
} }
#[test] #[test]
fn test_fstring_parse_selfdocumenting_base_more() { fn test_fstring_parse_self_documenting_base_more() {
let src = "mix {user=} with text and {second=}"; let src = "mix {user=} with text and {second=}";
let parse_ast = parse_fstring(src).unwrap(); let parse_ast = parse_fstring(src).unwrap();
@ -816,7 +816,7 @@ mod tests {
} }
#[test] #[test]
fn test_fstring_parse_selfdocumenting_format() { fn test_fstring_parse_self_documenting_format() {
let src = "{user=:>10}"; let src = "{user=:>10}";
let parse_ast = parse_fstring(src).unwrap(); let parse_ast = parse_fstring(src).unwrap();
@ -877,14 +877,14 @@ mod tests {
} }
#[test] #[test]
fn test_parse_fstring_selfdoc_prec_space() { fn test_parse_fstring_self_doc_prec_space() {
let source = "{x =}"; let source = "{x =}";
let parse_ast = parse_fstring(source).unwrap(); let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_fstring_selfdoc_trailing_space() { fn test_parse_fstring_self_doc_trailing_space() {
let source = "{x= }"; let source = "{x= }";
let parse_ast = parse_fstring(source).unwrap(); let parse_ast = parse_fstring(source).unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
@ -979,7 +979,7 @@ mod tests {
#[test] #[test]
fn test_escape_char_in_byte_literal() { fn test_escape_char_in_byte_literal() {
// backslash does not escape // backslash does not escape
let source = r##"b"omkmok\Xaa""##; let source = r##"b"omkmok\Xaa""##; // spell-checker:ignore omkmok
let parse_ast = parse_program(source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }

View file

@ -50,7 +50,7 @@ fn error_from_parse(error: parser::ParseError, source: &str) -> CompileError {
CompileError::from(error, source) CompileError::from(error, source)
} }
/// Compile a given sourcecode into a bytecode object. /// Compile a given source code into a bytecode object.
pub fn compile( pub fn compile(
source: &str, source: &str,
mode: compile::Mode, mode: compile::Mode,