Refactor mode

This commit is contained in:
d0cd 2023-02-10 21:21:06 -08:00
parent 05ffefbb79
commit 47fa89b012
3 changed files with 7 additions and 7 deletions

View File

@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Mode {
None,
Const,
Constant,
Private,
Public,
}
@ -32,7 +32,7 @@ impl fmt::Display for Mode {
match self {
None => write!(f, ""),
Const => write!(f, "const"),
Constant => write!(f, "constant"),
Private => write!(f, "private"),
Public => write!(f, "public"),
}

View File

@ -219,7 +219,7 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
// Note that this unwrap is safe since we assign to `self.variant` above.
match self.variant.unwrap() {
// If the function is a transition function, then check that the parameter mode is not a constant.
Variant::Transition if input_var.mode() == Mode::Const => self.emit_err(
Variant::Transition if input_var.mode() == Mode::Constant => self.emit_err(
TypeCheckerError::transition_function_inputs_cannot_be_const(input_var.span()),
),
// If the function is not a transition function, then check that the parameters do not have an associated mode.
@ -277,7 +277,7 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
}
// Check that the mode of the output is valid.
// For functions, only public and private outputs are allowed
if function_output.mode == Mode::Const {
if function_output.mode == Mode::Constant {
self.emit_err(TypeCheckerError::cannot_have_constant_output_mode(function_output.span));
}
}
@ -334,7 +334,7 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
self.emit_err(TypeCheckerError::finalize_cannot_take_tuple_as_input(input_var.span()))
}
// Check that the input parameter is not constant or private.
if input_var.mode() == Mode::Const || input_var.mode() == Mode::Private {
if input_var.mode() == Mode::Constant || input_var.mode() == Mode::Private {
self.emit_err(TypeCheckerError::finalize_input_mode_must_be_public(input_var.span()));
}
// Check for conflicting variable names.
@ -361,7 +361,7 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
}
// Check that the mode of the output is valid.
// Note that a finalize block can have only public outputs.
if matches!(output_type.mode(), Mode::Const | Mode::Private) {
if matches!(output_type.mode(), Mode::Constant | Mode::Private) {
self.emit_err(TypeCheckerError::finalize_output_mode_must_be_public(
output_type.span(),
));

View File

@ -72,7 +72,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
let var_type = if let Some(var) = self.symbol_table.borrow_mut().lookup_variable(var_name.name) {
match &var.declaration {
VariableType::Const => self.emit_err(TypeCheckerError::cannot_assign_to_const_var(var_name, var.span)),
VariableType::Input(Mode::Const) => {
VariableType::Input(Mode::Constant) => {
self.emit_err(TypeCheckerError::cannot_assign_to_const_input(var_name, var.span))
}
_ => {}