From 2db2d7cbeadd2f8c766401c0a6e53a7e85ef3908 Mon Sep 17 00:00:00 2001 From: Bruce Miller Date: Mon, 3 Jul 2023 13:31:54 -0400 Subject: [PATCH] OK, make some constant flags in LaTeXML::Global for the bitmasks --- lib/LaTeXML/Core/Definition/Conditional.pm | 4 ++-- lib/LaTeXML/Core/Definition/Constructor.pm | 4 ++-- lib/LaTeXML/Core/Definition/Primitive.pm | 4 ++-- lib/LaTeXML/Core/Definition/Register.pm | 4 ++-- lib/LaTeXML/Core/Whatsit.pm | 2 +- lib/LaTeXML/Global.pm | 8 +++++++- lib/LaTeXML/Package/TeX.pool.ltxml | 8 ++++---- lib/LaTeXML/Package/latexml.sty.ltxml | 12 ++++++++---- 8 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/LaTeXML/Core/Definition/Conditional.pm b/lib/LaTeXML/Core/Definition/Conditional.pm index d98053f7d1..2686e2f354 100644 --- a/lib/LaTeXML/Core/Definition/Conditional.pm +++ b/lib/LaTeXML/Core/Definition/Conditional.pm @@ -169,7 +169,7 @@ sub invoke_else { Debug('{' . ToString($LaTeXML::CURRENT_TOKEN) . '}' . " [for " . ToString($$LaTeXML::IFFRAME{token}) . " #" . $$LaTeXML::IFFRAME{ifid} . " skipping to " . ToString($t) . "]") - if ($STATE->lookupValue('TRACING') || 0) & 2; + if ($STATE->lookupValue('TRACING') || 0) & TRACE_COMMANDS; return; } } sub invoke_fi { @@ -187,7 +187,7 @@ sub invoke_fi { $STATE->shiftValue('if_stack'); # Done with this frame Debug('{' . ToString($LaTeXML::CURRENT_TOKEN) . '}' . " [for " . Stringify($$LaTeXML::IFFRAME{token}) . " #" . $$LaTeXML::IFFRAME{ifid} . "]") - if ($STATE->lookupValue('TRACING') || 0) & 2; + if ($STATE->lookupValue('TRACING') || 0) & TRACE_COMMANDS; return; } } sub equals { diff --git a/lib/LaTeXML/Core/Definition/Constructor.pm b/lib/LaTeXML/Core/Definition/Constructor.pm index 06014208cb..2fc65df7df 100644 --- a/lib/LaTeXML/Core/Definition/Constructor.pm +++ b/lib/LaTeXML/Core/Definition/Constructor.pm @@ -77,8 +77,8 @@ sub invoke { my ($self, $stomach) = @_; # Call any `Before' code. my $_tracing = $STATE->lookupValue('TRACING') || 0; - my $tracing = ($_tracing & 2); - my $profiled = ($_tracing & 4) && ($LaTeXML::CURRENT_TOKEN || $$self{cs}); + my $tracing = ($_tracing & TRACE_COMMANDS); + my $profiled = ($_tracing & TRACE_PROFILE) && ($LaTeXML::CURRENT_TOKEN || $$self{cs}); LaTeXML::Core::Definition::startProfiling($profiled, 'digest') if $profiled; diff --git a/lib/LaTeXML/Core/Definition/Primitive.pm b/lib/LaTeXML/Core/Definition/Primitive.pm index 5baece489f..06f3863880 100644 --- a/lib/LaTeXML/Core/Definition/Primitive.pm +++ b/lib/LaTeXML/Core/Definition/Primitive.pm @@ -52,8 +52,8 @@ sub executeAfterDigest { sub invoke { my ($self, $stomach) = @_; my $_tracing = $STATE->lookupValue('TRACING') || 0; - my $tracing = ($_tracing & 2); # tracing commands - my $profiled = ($_tracing & 4) && ($LaTeXML::CURRENT_TOKEN || $$self{cs}); + my $tracing = ($_tracing & TRACE_COMMANDS); + my $profiled = ($_tracing & TRACE_PROFILE) && ($LaTeXML::CURRENT_TOKEN || $$self{cs}); LaTeXML::Core::Definition::startProfiling($profiled, 'digest') if $profiled; Debug('{' . $self->tracingCSName . '}') if $tracing; diff --git a/lib/LaTeXML/Core/Definition/Register.pm b/lib/LaTeXML/Core/Definition/Register.pm index d51a1c8c76..c998de408f 100644 --- a/lib/LaTeXML/Core/Definition/Register.pm +++ b/lib/LaTeXML/Core/Definition/Register.pm @@ -57,7 +57,7 @@ sub valueOf { sub setValue { my ($self, $value, $scope, @args) = @_; - my $tracing = (($STATE->lookupValue('TRACING') || 0) & 2); # tracing commands + my $tracing = (($STATE->lookupValue('TRACING') || 0) & TRACE_COMMANDS); if ($tracing) { my $scope = $STATE->getPrefix('global') ? 'globally ' : ''; my $csname = ToString($$self{cs}); @@ -97,7 +97,7 @@ sub addValue { sub invoke { my ($self, $stomach) = @_; my $_tracing = $STATE->lookupValue('TRACING') || 0; - my $profiled = ($_tracing & 4) && ($LaTeXML::CURRENT_TOKEN || $$self{cs}); + my $profiled = ($_tracing & TRACE_PROFILE) && ($LaTeXML::CURRENT_TOKEN || $$self{cs}); LaTeXML::Core::Definition::startProfiling($profiled, 'digest') if $profiled; my $gullet = $stomach->getGullet; diff --git a/lib/LaTeXML/Core/Whatsit.pm b/lib/LaTeXML/Core/Whatsit.pm index 623066d745..2176f00c22 100644 --- a/lib/LaTeXML/Core/Whatsit.pm +++ b/lib/LaTeXML/Core/Whatsit.pm @@ -210,7 +210,7 @@ sub beAbsorbed { "Whatsit absorb limit of $LaTeXML::ABSORB_LIMIT exceeded, infinite loop?"); } } my $defn = $self->getDefinition; - my $profiled = (($STATE->lookupValue('TRACING') || 0) & 4) && $defn->getCS; + my $profiled = (($STATE->lookupValue('TRACING') || 0) & TRACE_PROFILE) && $defn->getCS; LaTeXML::Core::Definition::startProfiling($profiled, 'absorb') if $profiled; my @result = $defn->doAbsorbtion($document, $self); LaTeXML::Core::Definition::stopProfiling($profiled, 'absorb') if $profiled; diff --git a/lib/LaTeXML/Global.pm b/lib/LaTeXML/Global.pm index beb1caa480..c0242d1f33 100644 --- a/lib/LaTeXML/Global.pm +++ b/lib/LaTeXML/Global.pm @@ -24,11 +24,17 @@ use strict; use warnings; use base qw(Exporter); our @EXPORT = ( # Global STATE; This gets bound by LaTeXML.pm - qw( *STATE), + qw( *STATE + TRACE_MACROS TRACE_COMMANDS TRACE_ALL TRACE_PROFILE + ), ); #local $LaTeXML::STATE; +use constant TRACE_MACROS => 0x1; +use constant TRACE_COMMANDS => 0x2; +use constant TRACE_ALL => 0x3; # MACROS | COMMANDS +use constant TRACE_PROFILE => 0x4; #********************************************************************** 1; diff --git a/lib/LaTeXML/Package/TeX.pool.ltxml b/lib/LaTeXML/Package/TeX.pool.ltxml index f8432f0033..0bb221aa28 100644 --- a/lib/LaTeXML/Package/TeX.pool.ltxml +++ b/lib/LaTeXML/Package/TeX.pool.ltxml @@ -1073,13 +1073,13 @@ DefMacro('\the Register', sub { # Integer registers; TeXBook p. 272-273 DefRegister('\tracingmacros', Number(0), - getter => sub { Number((LookupValue('TRACING') || 0) & 1); }, + getter => sub { Number((LookupValue('TRACING') || 0) & TRACE_MACROS); }, setter => sub { my $p = (LookupValue('TRACING') || 0); - AssignValue(TRACING => ($_[0]->valueOf ? $p | 1 : $p & ~1)); }); + AssignValue(TRACING => ($_[0]->valueOf ? $p | TRACE_MACROS : $p & ~TRACE_MACROS)); }); DefRegister('\tracingcommands', Number(0), - getter => sub { Number((LookupValue('TRACING') || 0) & 2); }, + getter => sub { Number((LookupValue('TRACING') || 0) & TRACE_COMMANDS); }, setter => sub { my $p = (LookupValue('TRACING') || 0); - AssignValue(TRACING => ($_[0]->valueOf ? $p | 2 : $p & ~2)); }); + AssignValue(TRACING => ($_[0]->valueOf ? $p | TRACE_COMMANDS : $p & ~TRACE_COMMANDS)); }); { my %iparms = ( pretolerance => 100, tolerance => 200, hbadness => 1000, vbadness => 1000, diff --git a/lib/LaTeXML/Package/latexml.sty.ltxml b/lib/LaTeXML/Package/latexml.sty.ltxml index 89a00f9bf4..98592a9573 100644 --- a/lib/LaTeXML/Package/latexml.sty.ltxml +++ b/lib/LaTeXML/Package/latexml.sty.ltxml @@ -34,10 +34,14 @@ DeclareOption('noids', sub { AssignValue('GENERATE_IDS' => 0, 'global'); }); DeclareOption('comments', sub { AssignValue('INCLUDE_COMMENTS' => 1, 'global'); }); DeclareOption('nocomments', sub { AssignValue('INCLUDE_COMMENTS' => 0, 'global'); }); -DeclareOption('tracing', sub { AssignValue(TRACING => (LookupValue('TRACING') || 0) | 3); }); -DeclareOption('notracing', sub { AssignValue(TRACING => (LookupValue('TRACING') || 0) & ~3); }); -DeclareOption('profiling', sub { AssignValue(TRACING => (LookupValue('TRACING') || 0) | 4); }); -DeclareOption('noprofiling', sub { AssignValue(TRACING => (LookupValue('TRACING') || 0) & ~4); }); +DeclareOption('tracing', sub { + AssignValue(TRACING => (LookupValue('TRACING') || 0) | TRACE_ALL); }); +DeclareOption('notracing', sub { + AssignValue(TRACING => (LookupValue('TRACING') || 0) & ~TRACE_ALL); }); +DeclareOption('profiling', sub { + AssignValue(TRACING => (LookupValue('TRACING') || 0) | TRACE_PROFILE); }); +DeclareOption('noprofiling', sub { + AssignValue(TRACING => (LookupValue('TRACING') || 0) & ~TRACE_PROFILE); }); DeclareOption('mathparserspeculate', sub { AssignValue('MATHPARSER_SPECULATE' => 1, 'global'); }); DeclareOption('nomathparserspeculate', sub { AssignValue('MATHPARSER_SPECULATE' => 0, 'global'); });