More code refactor.

This commit is contained in:
Stephen Chung
2022-11-25 20:42:16 +08:00
parent fbe30b8d0e
commit d645d8271c
30 changed files with 422 additions and 434 deletions

View File

@@ -208,7 +208,8 @@ pub struct FnCallExpr {
/// Does this function call capture the parent scope?
pub capture_parent_scope: bool,
/// Is this function call a native operator?
pub op_token: Option<Token>,
/// Otherwise set to [`Token::NonToken`].
pub op_token: Token,
}
impl fmt::Debug for FnCallExpr {
@@ -223,8 +224,8 @@ impl fmt::Debug for FnCallExpr {
ff.field("hash", &self.hashes)
.field("name", &self.name)
.field("args", &self.args);
if let Some(ref token) = self.op_token {
ff.field("op_token", token);
if self.op_token != Token::NonToken {
ff.field("op_token", &self.op_token);
}
if self.capture_parent_scope {
ff.field("capture_parent_scope", &self.capture_parent_scope);
@@ -589,7 +590,7 @@ impl Expr {
hashes: calc_fn_hash(None, f.fn_name(), 1).into(),
args: once(Self::StringConstant(f.fn_name().into(), pos)).collect(),
capture_parent_scope: false,
op_token: None,
op_token: Token::NonToken,
}
.into(),
pos,

View File

@@ -24,7 +24,7 @@ pub struct EncapsulatedEnviron {
/// Imported [modules][crate::Module].
pub imports: Box<[(ImmutableString, crate::SharedModule)]>,
/// Globally-defined constants.
pub constants: Option<crate::eval::GlobalConstants>,
pub constants: Option<crate::eval::SharedGlobalConstants>,
}
/// _(internals)_ A type containing information on a script-defined function.

View File

@@ -61,10 +61,8 @@ impl OpAssignment {
#[must_use]
#[inline(always)]
pub fn new_op_assignment(name: &str, pos: Position) -> Self {
Self::new_op_assignment_from_token(
&Token::lookup_symbol_from_syntax(name).expect("operator"),
pos,
)
let op = Token::lookup_symbol_from_syntax(name).expect("operator");
Self::new_op_assignment_from_token(op, pos)
}
/// Create a new [`OpAssignment`] from a [`Token`].
///
@@ -72,10 +70,11 @@ impl OpAssignment {
///
/// Panics if the token is not an op-assignment operator.
#[must_use]
pub fn new_op_assignment_from_token(op: &Token, pos: Position) -> Self {
pub fn new_op_assignment_from_token(op: Token, pos: Position) -> Self {
let op_raw = op
.get_base_op_from_assignment()
.expect("op-assignment operator");
Self {
hash_op_assign: calc_fn_hash(None, op.literal_syntax(), 2),
hash_op: calc_fn_hash(None, op_raw.literal_syntax(), 2),
@@ -92,10 +91,8 @@ impl OpAssignment {
#[must_use]
#[inline(always)]
pub fn new_op_assignment_from_base(name: &str, pos: Position) -> Self {
Self::new_op_assignment_from_base_token(
&Token::lookup_symbol_from_syntax(name).expect("operator"),
pos,
)
let op = Token::lookup_symbol_from_syntax(name).expect("operator");
Self::new_op_assignment_from_base_token(op, pos)
}
/// Convert a [`Token`] into a new [`OpAssignment`].
///
@@ -104,8 +101,8 @@ impl OpAssignment {
/// Panics if the token is cannot be converted into an op-assignment operator.
#[inline(always)]
#[must_use]
pub fn new_op_assignment_from_base_token(op: &Token, pos: Position) -> Self {
Self::new_op_assignment_from_token(&op.convert_to_op_assignment().expect("operator"), pos)
pub fn new_op_assignment_from_base_token(op: Token, pos: Position) -> Self {
Self::new_op_assignment_from_token(op.convert_to_op_assignment().expect("operator"), pos)
}
}