Skip to content

Commit

Permalink
[mmzk] (feat) Can set steps to evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
MMZK1526 committed Nov 30, 2023
1 parent 909dab4 commit e8495b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/constants/my_markdown_texts.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// ignore_for_file: unnecessary_string_escapes

import 'package:lambda_calculus_front_end/constants/my_text.dart';

class MyMarkdownTexts {
// ignore: unnecessary_string_escapes
static final introMarkdown = """
# Lambda Calculus Simulator
Expand All @@ -16,7 +17,6 @@ TODO: The [${MyText.evalTab.text}](!!evaluation) tab supports evaluating a lambd
2. Call by name. Call by name, does not reduce within abstraction. Usually corresponds to "lazy evaluation".
3. Call by value. Call by value, does not reduce within abstraction. Usually corresponds to "eager evaluation".
// ignore: unnecessary_string_escapes
The [${MyText.typeTab.text}](!!type-inference) tab supports type inference for a lambda term. It supports the vanilla Church type system without recursion.
## Syntax
Expand Down Expand Up @@ -68,5 +68,7 @@ Enter a Lambda term in the input box below to start evaluating it. You can also
Click the [${MyText.help.text}](!!help) button for syntax guides.
The "Show first XXX steps" checkbox allows you to show only the first XXX steps of the evaluation. The checkbox is checked by default, and when unchecked, the evaluation will continue until the normal form is reached, which may cause the website to freeze if there is no normal form.
""";
}
16 changes: 13 additions & 3 deletions lib/controllers/evaluation_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ class EvaluationManager extends ChangeNotifier {
/// The default number of steps to show.
final defaultSteps = 20;

/// If not null, show the first [useMaxSteps] steps of the evaluation.
bool _useMaxSteps = false;
/// The maximum number of steps to show.
int _maxSteps = 20;

int? getMaxSteps() => _useMaxSteps ? _maxSteps : null;

set maxSteps(int value) {
_maxSteps = value;
notifyListeners();
}

/// If true, show the first [maxSteps] steps of the evaluation.
bool _useMaxSteps = true;

bool get useMaxSteps => _useMaxSteps;

Expand All @@ -22,7 +32,7 @@ class EvaluationManager extends ChangeNotifier {
}

/// Invoked when the show first N steps checkbox is clicked.
void onuseMaxStepToggle() {
void onUseMaxStepToggle() {
_useMaxSteps = !_useMaxSteps;
notifyListeners();
}
Expand Down
25 changes: 15 additions & 10 deletions lib/views/evaluation_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EvaluationTab extends StatefulWidget {

class _EvaluationTabState extends State<EvaluationTab>
with AutomaticKeepAliveClientMixin<EvaluationTab> {
final _simulationManager = EvaluationManager();
final _evaluationManager = EvaluationManager();
final _lambdaInputManager = InputManager<LambdaData>();

@override
Expand All @@ -42,9 +42,9 @@ class _EvaluationTabState extends State<EvaluationTab>

@override
void initState() {
_simulationManager.initState();
_evaluationManager.initState();
_lambdaInputManager.initState();
_simulationManager.addListener(() => setState(() {}));
_evaluationManager.addListener(() => setState(() {}));
_lambdaInputManager.addListener(() => setState(() {}));

widget.markdownCallbackBinder?.withCurrentGroup(MyText.evalTab.text, () {
Expand All @@ -58,7 +58,7 @@ class _EvaluationTabState extends State<EvaluationTab>
@override
void dispose() {
_lambdaInputManager.dispose();
_simulationManager.dispose();
_evaluationManager.dispose();
widget.markdownCallbackBinder?.dispose(MyText.evalTab.text);

super.dispose();
Expand Down Expand Up @@ -108,24 +108,26 @@ class _EvaluationTabState extends State<EvaluationTab>
const Expanded(child: SizedBox()),
const SizedBox(width: 12.0),
Checkbox(
value: _simulationManager.useMaxSteps,
value: _evaluationManager.useMaxSteps,
onChanged: (value) =>
_simulationManager.onuseMaxStepToggle(),
_evaluationManager.onUseMaxStepToggle(),
),
Text(MyText.showFirst.text),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: SizedBox(
width: 60.0,
child: TextFormField(
enabled: _simulationManager.useMaxSteps,
controller: _simulationManager.stepsController,
enabled: _evaluationManager.useMaxSteps,
onChanged: (value) =>
_evaluationManager.maxSteps = int.parse(value),
controller: _evaluationManager.stepsController,
textAlignVertical: TextAlignVertical.center,
style: Theme.of(context).textTheme.bodyMedium,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(12.0),
isDense: true,
hintText: '${_simulationManager.defaultSteps}',
hintText: '${_evaluationManager.defaultSteps}',
),
maxLines: 1,
inputFormatters: [
Expand Down Expand Up @@ -154,7 +156,10 @@ class _EvaluationTabState extends State<EvaluationTab>
if (lambda == null) {
return LambdaData.parseError;
}
final result = LambdaData.buildData(baseLambda: lambda);
final result = LambdaData.buildData(
baseLambda: lambda,
maxSteps: _evaluationManager.getMaxSteps(),
);
return result;
},
),
Expand Down

0 comments on commit e8495b3

Please sign in to comment.