Skip to content

Commit

Permalink
OK, make some constant flags in LaTeXML::Global for the bitmasks
Browse files Browse the repository at this point in the history
  • Loading branch information
brucemiller committed Jul 4, 2023
1 parent 3157c7c commit 2db2d7c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/LaTeXML/Core/Definition/Conditional.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions lib/LaTeXML/Core/Definition/Constructor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions lib/LaTeXML/Core/Definition/Primitive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/LaTeXML/Core/Definition/Register.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Core/Whatsit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion lib/LaTeXML/Global.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions lib/LaTeXML/Package/TeX.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions lib/LaTeXML/Package/latexml.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -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'); });
Expand Down

0 comments on commit 2db2d7c

Please sign in to comment.