Skip to content

Commit

Permalink
replace hardcoded symbols with proc macro
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Dec 27, 2023
1 parent 323602c commit 100ed25
Show file tree
Hide file tree
Showing 35 changed files with 1,078 additions and 1,209 deletions.
80 changes: 40 additions & 40 deletions crates/dash_compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,12 @@ impl<'interner> FunctionCompiler<'interner> {
let mut ib = InstructionBuilder::new(self);
let for_of_iter_id = ib
.current_scope_mut()
.add_local(sym::FOR_OF_ITER, VariableDeclarationKind::Unnameable, None)
.add_local(sym::for_of_iter, VariableDeclarationKind::Unnameable, None)
.map_err(|_| Error::LocalLimitExceeded(expr.span))?;

let for_of_gen_step_id = ib
.current_scope_mut()
.add_local(sym::FOR_OF_GEN_STEP, VariableDeclarationKind::Unnameable, None)
.add_local(sym::for_of_gen_step, VariableDeclarationKind::Unnameable, None)
.map_err(|_| Error::LocalLimitExceeded(expr.span))?;

ib.accept_expr(expr)?;
Expand Down Expand Up @@ -376,7 +376,7 @@ impl<'interner> FunctionCompiler<'interner> {
},
Expr {
span: Span::COMPILER_GENERATED,
kind: ExprKind::identifier(sym::VALUE),
kind: ExprKind::identifier(sym::value),
},
),
}),
Expand Down Expand Up @@ -423,7 +423,7 @@ impl<'interner> FunctionCompiler<'interner> {
},
Expr {
span: Span::COMPILER_GENERATED,
kind: ExprKind::identifier(sym::NEXT),
kind: ExprKind::identifier(sym::next),
},
),
},
Expand All @@ -436,7 +436,7 @@ impl<'interner> FunctionCompiler<'interner> {
},
Expr {
span: Span::COMPILER_GENERATED,
kind: ExprKind::identifier(sym::DONE),
kind: ExprKind::identifier(sym::done),
},
),
},
Expand Down Expand Up @@ -682,11 +682,11 @@ impl<'interner> Visitor<Result<(), Error>> for FunctionCompiler<'interner> {
let mut ib = InstructionBuilder::new(self);

match ident {
sym::THIS => ib.build_this(),
sym::SUPER => ib.build_super(),
sym::GLOBAL_THIS => ib.build_global(),
sym::INFINITY => ib.build_infinity(),
sym::NAN => ib.build_nan(),
sym::this => ib.build_this(),
sym::super_ => ib.build_super(),
sym::globalThis => ib.build_global(),
sym::Infinity => ib.build_infinity(),
sym::NaN => ib.build_nan(),
ident => match ib.find_local(ident) {
Some((index, _, is_extern)) => ib.build_local_load(index, is_extern),
_ => ib
Expand Down Expand Up @@ -1246,33 +1246,33 @@ impl<'interner> Visitor<Result<(), Error>> for FunctionCompiler<'interner> {
}

match (target, property) {
(sym::MATH, sym::EXP) => emit_spec!(InstructionBuilder::build_exp),
(sym::MATH, sym::LOG2) => emit_spec!(InstructionBuilder::build_log2),
(sym::MATH, sym::EXPM1) => emit_spec!(InstructionBuilder::build_expm1),
(sym::MATH, sym::CBRT) => emit_spec!(InstructionBuilder::build_cbrt),
(sym::MATH, sym::CLZ32) => emit_spec!(InstructionBuilder::build_clz32),
(sym::MATH, sym::ATANH) => emit_spec!(InstructionBuilder::build_atanh),
(sym::MATH, sym::ATAN2) => emit_spec!(InstructionBuilder::build_atanh2),
(sym::MATH, sym::ROUND) => emit_spec!(InstructionBuilder::build_round),
(sym::MATH, sym::ACOSH) => emit_spec!(InstructionBuilder::build_acosh),
(sym::MATH, sym::ABS) => emit_spec!(InstructionBuilder::build_abs),
(sym::MATH, sym::SINH) => emit_spec!(InstructionBuilder::build_sinh),
(sym::MATH, sym::SIN) => emit_spec!(InstructionBuilder::build_sin),
(sym::MATH, sym::CEIL) => emit_spec!(InstructionBuilder::build_ceil),
(sym::MATH, sym::TAN) => emit_spec!(InstructionBuilder::build_tan),
(sym::MATH, sym::TRUNC) => emit_spec!(InstructionBuilder::build_trunc),
(sym::MATH, sym::ASINH) => emit_spec!(InstructionBuilder::build_asinh),
(sym::MATH, sym::LOG10) => emit_spec!(InstructionBuilder::build_log10),
(sym::MATH, sym::ASIN) => emit_spec!(InstructionBuilder::build_asin),
(sym::MATH, sym::RANDOM) => emit_spec!(InstructionBuilder::build_random),
(sym::MATH, sym::LOG1P) => emit_spec!(InstructionBuilder::build_log1p),
(sym::MATH, sym::SQRT) => emit_spec!(InstructionBuilder::build_sqrt),
(sym::MATH, sym::ATAN) => emit_spec!(InstructionBuilder::build_atan),
(sym::MATH, sym::LOG) => emit_spec!(InstructionBuilder::build_log),
(sym::MATH, sym::FLOOR) => emit_spec!(InstructionBuilder::build_floor),
(sym::MATH, sym::COSH) => emit_spec!(InstructionBuilder::build_cosh),
(sym::MATH, sym::ACOS) => emit_spec!(InstructionBuilder::build_acos),
(sym::MATH, sym::COS) => emit_spec!(InstructionBuilder::build_cos),
(sym::Math, sym::exp) => emit_spec!(InstructionBuilder::build_exp),
(sym::Math, sym::log2) => emit_spec!(InstructionBuilder::build_log2),
(sym::Math, sym::expm1) => emit_spec!(InstructionBuilder::build_expm1),
(sym::Math, sym::cbrt) => emit_spec!(InstructionBuilder::build_cbrt),
(sym::Math, sym::clz32) => emit_spec!(InstructionBuilder::build_clz32),
(sym::Math, sym::atanh) => emit_spec!(InstructionBuilder::build_atanh),
(sym::Math, sym::atan2) => emit_spec!(InstructionBuilder::build_atanh2),
(sym::Math, sym::round) => emit_spec!(InstructionBuilder::build_round),
(sym::Math, sym::acosh) => emit_spec!(InstructionBuilder::build_acosh),
(sym::Math, sym::abs) => emit_spec!(InstructionBuilder::build_abs),
(sym::Math, sym::sinh) => emit_spec!(InstructionBuilder::build_sinh),
(sym::Math, sym::sin) => emit_spec!(InstructionBuilder::build_sin),
(sym::Math, sym::ceil) => emit_spec!(InstructionBuilder::build_ceil),
(sym::Math, sym::tan) => emit_spec!(InstructionBuilder::build_tan),
(sym::Math, sym::trunc) => emit_spec!(InstructionBuilder::build_trunc),
(sym::Math, sym::asinh) => emit_spec!(InstructionBuilder::build_asinh),
(sym::Math, sym::log10) => emit_spec!(InstructionBuilder::build_log10),
(sym::Math, sym::asin) => emit_spec!(InstructionBuilder::build_asin),
(sym::Math, sym::random) => emit_spec!(InstructionBuilder::build_random),
(sym::Math, sym::log1p) => emit_spec!(InstructionBuilder::build_log1p),
(sym::Math, sym::sqrt) => emit_spec!(InstructionBuilder::build_sqrt),
(sym::Math, sym::atan) => emit_spec!(InstructionBuilder::build_atan),
(sym::Math, sym::log) => emit_spec!(InstructionBuilder::build_log),
(sym::Math, sym::floor) => emit_spec!(InstructionBuilder::build_floor),
(sym::Math, sym::cosh) => emit_spec!(InstructionBuilder::build_cosh),
(sym::Math, sym::acos) => emit_spec!(InstructionBuilder::build_acos),
(sym::Math, sym::cos) => emit_spec!(InstructionBuilder::build_cos),
_ => {}
}
}
Expand Down Expand Up @@ -1924,7 +1924,7 @@ impl<'interner> Visitor<Result<(), Error>> for FunctionCompiler<'interner> {

let constructor = class.members.iter().find_map(|member| {
if let ClassMemberKind::Method(method) = &member.kind {
if method.name == Some(sym::CONSTRUCTOR) {
if method.name == Some(sym::constructor) {
return Some(method.clone());
}
}
Expand All @@ -1939,7 +1939,7 @@ impl<'interner> Visitor<Result<(), Error>> for FunctionCompiler<'interner> {
.map_err(|_| Error::LocalLimitExceeded(span))?,
None => ib
.current_scope_mut()
.add_local(sym::DESUGARED_CLASS, VariableDeclarationKind::Unnameable, None)
.add_local(sym::DesugaredClass, VariableDeclarationKind::Unnameable, None)
.map_err(|_| Error::LocalLimitExceeded(span))?,
};

Expand Down Expand Up @@ -2011,7 +2011,7 @@ impl<'interner> Visitor<Result<(), Error>> for FunctionCompiler<'interner> {
load_class_binding.clone(),
Expr {
span: Span::COMPILER_GENERATED,
kind: ExprKind::identifier(sym::PROTOTYPE),
kind: ExprKind::identifier(sym::prototype),
},
),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/dash_compiler/src/transformations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn insert_initializer_in_constructor(class: &Class, statements: &mut Vec<Sta
}),
target: Box::new(Expr {
span: Span::COMPILER_GENERATED,
kind: ExprKind::identifier(sym::THIS),
kind: ExprKind::identifier(sym::this),
}),
}),
})),
Expand Down
2 changes: 1 addition & 1 deletion crates/dash_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl<'a, 'interner> Lexer<'a, 'interner> {
self.advance(); // identifier reading requires one character to be read
self.read_identifier_raw()
} else {
sym::EMPTY
sym::empty
};

self.create_contextified_token(TokenType::RegexLiteral {
Expand Down
Loading

0 comments on commit 100ed25

Please sign in to comment.