Skip to content

Commit 4a73f90

Browse files
committed
rename codegen_* to compile_*
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent 2604746 commit 4a73f90

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

compiler/codegen/src/compile.rs

+33-15
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ impl Compiler {
18601860
// RETURN_IF_ERROR(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
18611861
// return SUCCESS;
18621862
// }
1863-
fn codegen_pattern_value(
1863+
fn compile_pattern_value(
18641864
&mut self,
18651865
value: &PatternMatchValue<SourceRange>,
18661866
pattern_context: &mut PatternContext,
@@ -1886,7 +1886,7 @@ impl Compiler {
18861886
// RETURN_IF_ERROR(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
18871887
// return SUCCESS;
18881888
// }
1889-
fn codegen_pattern_singleton(
1889+
fn compile_pattern_singleton(
18901890
&mut self,
18911891
singleton: &PatternMatchSingleton<SourceRange>,
18921892
pattern_context: &mut PatternContext,
@@ -1904,7 +1904,7 @@ impl Compiler {
19041904
Ok(())
19051905
}
19061906

1907-
fn codegen_pattern_helper_rotate(
1907+
fn compile_pattern_helper_rotate(
19081908
&mut self,
19091909
count: usize,
19101910
) -> CompileResult<()> {
@@ -1938,7 +1938,7 @@ impl Compiler {
19381938
// RETURN_IF_ERROR(PyList_Append(pc->stores, n));
19391939
// return SUCCESS;
19401940
// }
1941-
fn codegen_pattern_helper_store_name(
1941+
fn compile_pattern_helper_store_name(
19421942
&mut self,
19431943
n: Option<&str>,
19441944
pattern_context: &mut PatternContext,
@@ -1953,18 +1953,18 @@ impl Compiler {
19531953
return Err(self.error(CodegenErrorType::DuplicateStore(n.to_string())));
19541954
}
19551955
let rotations = pattern_context.on_top + pattern_context.stores.len() + 1;
1956-
self.codegen_pattern_helper_rotate(rotations)?;
1956+
self.compile_pattern_helper_rotate(rotations)?;
19571957
pattern_context.stores.push(n.to_string());
19581958
Ok(())
19591959
}
19601960

1961-
fn codegen_pattern_star(
1961+
fn compile_pattern_star(
19621962
&mut self,
19631963
star: &PatternMatchStar<SourceRange>,
19641964
pattern_context: &mut PatternContext,
19651965
) -> CompileResult<()> {
19661966
// codegen_pattern_helper_store_name(c, LOC(p), p->v.MatchStar.name, pc));
1967-
self.codegen_pattern_helper_store_name(
1967+
self.compile_pattern_helper_store_name(
19681968
star.name.as_deref(),
19691969
pattern_context,
19701970
)?;
@@ -2011,38 +2011,38 @@ impl Compiler {
20112011
return Err(self.error(CodegenErrorType::InvalidMatchCase));
20122012
}
20132013
}
2014-
return self.codegen_pattern_helper_store_name(
2014+
return self.compile_pattern_helper_store_name(
20152015
as_pattern.name.as_deref(),
20162016
pattern_context,
20172017
);
20182018
}
20192019
pattern_context.on_top += 1;
20202020
emit!(self, Instruction::Duplicate);
2021-
self.codegen_pattern(as_pattern.pattern.as_ref().unwrap(), pattern_context)?;
2021+
self.compile_pattern(as_pattern.pattern.as_ref().unwrap(), pattern_context)?;
20222022
pattern_context.on_top -= 1;
2023-
self.codegen_pattern_helper_store_name(
2023+
self.compile_pattern_helper_store_name(
20242024
as_pattern.name.as_deref(),
20252025
pattern_context,
20262026
)?;
20272027
Ok(())
20282028
}
20292029

2030-
fn codegen_pattern(
2030+
fn compile_pattern(
20312031
&mut self,
20322032
pattern_type: &Pattern<SourceRange>,
20332033
pattern_context: &mut PatternContext,
20342034
) -> CompileResult<()> {
20352035
match &pattern_type {
2036-
Pattern::MatchValue(value) => self.codegen_pattern_value(&value, pattern_context),
2036+
Pattern::MatchValue(value) => self.compile_pattern_value(&value, pattern_context),
20372037
Pattern::MatchSingleton(singleton) => {
2038-
self.codegen_pattern_singleton(&singleton, pattern_context)
2038+
self.compile_pattern_singleton(&singleton, pattern_context)
20392039
}
20402040
Pattern::MatchSequence(_sequence) => {
20412041
Err(self.error(CodegenErrorType::NotImplementedYet))
20422042
}
20432043
Pattern::MatchMapping(_mapping) => Err(self.error(CodegenErrorType::NotImplementedYet)),
20442044
Pattern::MatchClass(_class) => Err(self.error(CodegenErrorType::NotImplementedYet)),
2045-
Pattern::MatchStar(star) => self.codegen_pattern_star(&star, pattern_context),
2045+
Pattern::MatchStar(star) => self.compile_pattern_star(&star, pattern_context),
20462046
Pattern::MatchAs(as_pattern) => self.codegen_pattern_as(&as_pattern, pattern_context),
20472047
Pattern::MatchOr(_or_pattern) => Err(self.error(CodegenErrorType::NotImplementedYet)),
20482048
}
@@ -2076,7 +2076,7 @@ impl Compiler {
20762076
pattern_context.allow_irrefutable = m.guard.is_some() || i == cases.len() - 1;
20772077
// pc->fail_pop = NULL;
20782078
pattern_context.on_top = 0;
2079-
self.codegen_pattern(&m.pattern, pattern_context)?;
2079+
self.compile_pattern(&m.pattern, pattern_context)?;
20802080
assert_eq!(pattern_context.on_top, 0);
20812081
// It's a match! Store all of the captured names (they're on the stack).
20822082
let nstores = pattern_context.stores.len();
@@ -3727,4 +3727,22 @@ for stop_exc in (StopIteration('spam'), StopAsyncIteration('ham')):
37273727
"
37283728
));
37293729
}
3730+
3731+
#[test]
3732+
fn test_match() {
3733+
assert_dis_snapshot!(compile_exec(
3734+
r#"\
3735+
v = "one"
3736+
match v:
3737+
case "one":
3738+
v = "two"
3739+
case "two":
3740+
v = "three"
3741+
case "three":
3742+
v = "one"
3743+
case _:
3744+
v = "one"
3745+
"#
3746+
));
3747+
}
37303748
}

0 commit comments

Comments
 (0)