summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex')
-rw-r--r--Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex248
1 files changed, 97 insertions, 151 deletions
diff --git a/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex b/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
index 2c9e114bdc5..52cb435b2f0 100644
--- a/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
+++ b/Master/texmf-dist/tex/latex/yquant/yquant-circuit.tex
@@ -8,35 +8,45 @@
\pgfpointanchor{yquantbox}{#2}%
\edef\wirexpos{\the\pgf@x}%
\fi%
- \yquant@register@get@typeywire{#1}\wiretype\wireypos\wirelast%
- \edef\wirexprevpos{\expandafter\@firstoffour\wirelast}%
- \ifnum\wiretype=\yquant@register@type@none%
- % the clippings of the previous operator will for sure not be needed, but the type might be turned into an active one, so we need the last clipping.
- \yquant@register@set@lastwire{#1}{%
- {\wirexprevpos}{\wirexpos}{}%
- {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
- }%
- \else%
- % append the previous `last' clipping to the old list and insert the new one
- \yquant@register@set@lastwire{#1}{%
- {\wirexprevpos}{\wirexpos}%
- {\unexpanded\expandafter\expandafter\expandafter{%
- \expandafter\@thirdandfourthoffour\wirelast%
- }%
+ \ifdim\wirexpos>0pt % may be negative for init gates
+ \yquant@register@get@typeywire{#1}\wiretype\wireypos\wirelast%
+ \edef\wirexprevpos{\expandafter\@firstoffour\wirelast}%
+ \ifnum\wiretype=\yquant@register@type@none%
+ % the clippings of the previous operator will for sure not be needed, but the type might be turned into an active one, so we need the last clipping.
+ \yquant@register@set@lastwire{#1}{%
+ {\wirexprevpos}{\wirexpos}{}%
+ {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
}%
- {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
- }%
+ \else%
+ % append the previous `last' clipping to the old list and insert the new one
+ \yquant@register@set@lastwire{#1}{%
+ {\wirexprevpos}{\wirexpos}%
+ {\unexpanded\expandafter\expandafter\expandafter{%
+ \expandafter\@thirdandfourthoffour\wirelast%
+ }%
+ }%
+ {\unexpanded\expandafter{\pgfshapeclippathhorzresult}}%
+ }%
+ \fi%
\fi%
\endgroup%
}
-% finishes the wires of all registers until x position #1
-\protected\def\yquant@circuit@endwires#1{%
- \ifcsname\yquant@prefix xshift\endcsname%
- \dimdef\yquant@env@end@xpos{#1+\csname\yquant@prefix xshift\endcsname}%
- \else%
- \def\yquant@env@end@xpos{#1}%
- \fi%
+% finishes the wires of all registers
+\protected\def\yquant@circuit@endwires{%
+ \expandafter\expandafter\expandafter\yquant@register@get@maxxrange%
+ \expandafter\expandafter\expandafter\yquant@circuit@endwires@x%
+ \expandafter\expandafter\expandafter1%
+ \expandafter\expandafter\expandafter{\csname\yquant@prefix registers\endcsname}%
+ % to have a symmetric situation, we extend again one separation at the end, unless this is supposed to be seamless and we don't have outputs (for seamless circuits with outputs, extend - since this extension will be between last register and output)
+ \ifyquant@env@seamless{%
+ \expandafter\unless\expandafter\ifx\csname\yquant@prefix outputs\endcsname\relax%
+ \dimdef\yquant@circuit@endwires@x{\yquant@circuit@endwires@x+\yquant@config@operator@sep}%
+ \fi%
+ }{%
+ \dimdef\yquant@circuit@endwires@x{\yquant@circuit@endwires@x+\yquant@config@operator@sep}%
+ }%
+ \let\yquant@circuit@endwires@finalize=\relax%
\yquant@for \yquant@circuit@endwires@i := 1 to \csname\yquant@prefix registers\endcsname {%
% we only extend the wire if it does not come from the outer circuit - this one would be responsible for the extension.
\ifcsname\yquant@prefix registermap@\yquant@circuit@endwires@i\endcsname%
@@ -45,7 +55,10 @@
\edef\storedleft{\the\pgf@picminx}%
\yquant@draw@wire\yquant@circuit@endwires@i1%
\global\pgf@picminx=\storedleft%
- \yquant@register@set@type\yquant@circuit@endwires@i\yquant@register@type@none%
+ \eappto\yquant@circuit@endwires@finalize{%
+ \yquant@register@set@type%
+ \yquant@circuit@endwires@i\noexpand\yquant@register@type@none%
+ }%
}\relax%
\else%
\yquant@draw@wire\yquant@circuit@endwires@i1%
@@ -55,14 +68,7 @@
% outputs the wire according to its previous instructions and prepares for a change in the wire style
\protected\def\yquant@circuit@flushwire#1{%
- \ifcsname\yquant@prefix registermap@#1\endcsname%
- % make sure drawing the wire does not affect our left bounding box position
- \edef\storedleft{\the\pgf@picminx}%
- \yquant@draw@wire{#1}0%
- \global\pgf@picminx=\storedleft%
- \else%
- \yquant@draw@wire{#1}0%
- \fi%
+ \yquant@draw@wire{#1}0%
\begingroup%
\yquant@register@get@lastwire{#1}\wirelast%
\yquant@register@set@lastwire{#1}{%
@@ -78,13 +84,13 @@
% BEGIN_FOLD Drawing control lines
% populates a drawing macro with the current control line with style #1 at position #2. Assumes a node called yquantbox is set up, and the \pgfshapeclippathvertresult was set up appropriately for this node. At the first call, \yquant@circuit@extendcontrolline@cmd must be \let to \empty and \yquant@circuit@extendcontrolline@prev to \relax.
\protected\def\yquant@circuit@extendcontrolline#1#2{%
+ \eappto\yquant@circuit@extendcontrolline@clip{%
+ \unexpanded\expandafter{\pgfshapeclippathvertresult}%
+ }%
\begingroup%
\tikzset{/yquant/every control line}%
\expandafter%
\endgroup%
- \eappto\yquant@circuit@extendcontrolline@clip{%
- \unexpanded\expandafter{\pgfshapeclippathvertresult}%
- }%
\expandafter\@tempdima\the\pgflinewidth%
\ifcase#1%
% no control (or to a discarded target, which we don't do)
@@ -207,17 +213,35 @@
\yquant@circuit@operator@maxpctrl%
\yquant@circuit@operator@maxnctrl%
\relax%
- % obtain the required minimal x position
- \yquant@register@get@maxxrange%
- \yquant@circuit@operator@x%
- \yquant@circuit@operator@minctrl%
- \yquant@circuit@operator@maxctrl%
- \dimdef\yquant@circuit@operator@x{%
- \yquant@circuit@operator@x+\yquant@config@operator@sep%
- }%
+}
+
+% restores the data captured for an uncontrolled operator and starts preparation
+% #1: \yquant@attrs@remaining
+% #2: \yquant@circuit@operator@targets
+% #3: \yquant@circuit@operator@mintarget
+% #4: \yquant@circuit@operator@maxtarget
+% #5: \yquant@circuit@operator@numtarget
+\protected\def\yquant@circuit@restore#1#2#3#4#5{%
+ \def\yquant@attrs@remaining{#1}%
+ \def\yquant@circuit@operator@targets{#2}%
+ \def\yquant@circuit@operator@mintarget{#3}%
+ \def\yquant@circuit@operator@maxtarget{#4}%
+ \def\yquant@circuit@operator@numtarget{#5}%
+ \yquant@circuit@operator@hasControlsfalse%
+ \let\yquant@circuit@operator@pctrls=\empty%
+ \def\yquant@circuit@operator@minpctrl{2147483647}%
+ \def\yquant@circuit@operator@maxpctrl{0}%
+ \let\yquant@circuit@operator@numpctrl=\yquant@circuit@operator@maxpctrl%
+ \let\yquant@circuit@operator@nctrls=\empty%
+ \let\yquant@circuit@operator@minnctrl=\yquant@circuit@operator@minpctrl%
+ \let\yquant@circuit@operator@maxnctrl=\yquant@circuit@operator@maxpctrl%
+ \let\yquant@circuit@operator@numnctrl=\yquant@circuit@operator@numpctrl%
+ \let\yquant@circuit@operator@minctrl=\yquant@circuit@operator@mintarget%
+ \let\yquant@circuit@operator@maxctrl=\yquant@circuit@operator@maxtarget%
}
% creates a subcircuit. Parameter registers must be filled in \yquant@circuit@subcircuit@params.
+% #1: style
\protected\def\yquant@circuit@subcircuit#1{%
\numdef\yquant@circuit@subcircuit@id{\yquant@env+1}%
\listcsxadd{\yquant@prefix subcircuits}{\yquant@circuit@subcircuit@id}%
@@ -232,46 +256,6 @@
\PackageError{yquant.sty}{Invalid subcircuit parameters count}%
{Too many parameters given.}%
\fi%
- \global\cslet{\yquant@prefix parameters}\yquant@circuit@subcircuit@param%
- \dimen0=\yquant@config@register@sep%
- % the first input must count all its height plus everything that is above it in the subcircuit as the height of the outer wire it is attached to
- \edef\firstinput{%
- \expandafter\expandafter\expandafter%
- \@firstoftwo\csname\yquant@prefix firstinput\endcsname%
- }%
- \edef\outerfirst{%
- \expandafter\expandafter\expandafter%
- \@secondoftwo\csname\yquant@prefix firstinput\endcsname%
- }%
- \dimen2=\yquant@register@get@height\firstinput\relax%
- \ifnum\firstinput>1 %
- \yquant@fordown \i := \the\numexpr\firstinput-1\relax downto 1 {%
- \advance\dimen2 by \dimexpr\yquant@register@get@height\i+%
- \yquant@register@get@depth\i+\dimen0\relax%
- }%
- \fi%
- % the last input must count all its depth plus everything that is below it in the subcircuit as the depth of the outer wire it is attached to
- \edef\lastinput{%
- \expandafter\expandafter\expandafter%
- \@firstoftwo\csname\yquant@prefix lastinput\endcsname%
- }%
- \edef\outerlast{%
- \expandafter\expandafter\expandafter%
- \@secondoftwo\csname\yquant@prefix lastinput\endcsname%
- }%
- \dimen4=\yquant@register@get@depth\lastinput\relax%
- \ifnum\lastinput<\csname\yquant@prefix registers\endcsname%
- \yquant@for \i := \the\numexpr\lastinput+1\relax to \csname\yquant@prefix registers\endcsname {%
- \advance\dimen4 by \dimexpr\yquant@register@get@height\i+%
- \yquant@register@get@depth\i+\dimen0\relax%
- }%
- \fi%
- \begingroup%
- \let\yquant@prefix=\yquant@parent%
- \yquant@register@update@height\outerfirst{\the\dimen2}%
- \yquant@register@update@depth\outerlast{\the\dimen4}%
- \endgroup%
- % we cannot make more precise statements about the inputs in between - for example, if input 1 is mapped to outer wire 1 and input 2 to outer wire 5, how to split the heights/depth appropriately between the outer wires 1-5?
\yquant@env@end%
\endgroup%
}
@@ -279,7 +263,13 @@
% BEGIN_FOLD Helpers for operator callbacks
% turn a wire into a different type
\def\yquant@circuit@settype#1{%
- \yquant@circuit@flushwire{#1}%
+ \unless\if\yquant@register@get@type{#1}\yquant@circuit@settype@to %
+ \yquant@circuit@flushwire{#1}%
+ \yquant@register@set@type{#1}{\yquant@circuit@settype@to}%
+ \fi%
+}
+
+\protected\def\yquant@circuit@settype@prepare#1{%
\yquant@register@set@type{#1}{\yquant@circuit@settype@to}%
}
@@ -296,95 +286,51 @@
% performs an alignment of all registers specified in the argument; that is, the next operation on any of the listed registers will be after the maximum position of all of them
% #1: arbitrary register list
\protected\def\yquant@circuit@align#1{%
- \begingroup%
- \yquant@register@get@maxxlist\x{#1}%
- \def\do##1{%
- \yquant@register@set@x{##1}\x%
- }%
- \dolistloop{#1}%
- \endgroup%
+ \csxappto{\yquant@prefix draw}{%
+ \yquant@draw@hspace{#1}{0pt}%
+ }%
}
% introduces a horizontal skip (= invisible operator of given width) among the registers; that is, those registers are first aligned, then skipped by the given amount.
% #1: arbitrary register list
% #2: skip width
\protected\def\yquant@circuit@hspace#1#2{%
- \begingroup%
- \yquant@register@get@maxxlist\x{#1}%
- \dimdef\x{\x+#2}%
- \def\do##1{%
- \yquant@register@set@x{##1}\x%
- }%
- \dolistloop{#1}%
- \endgroup%
+ \csxappto{\yquant@prefix draw}{%
+ \yquant@draw@hspace{#1}{#2}%
+ }%
}
% applies an action to wires a list of registers and causes them to be redrawn
-% #1: action
-% #2: arbitrary register list
-% #3: parameter(s)
-\protected\def\yquant@circuit@actonwires#1#2#3{%
+% #1: action for prepare
+% #2: action for draw
+% #3: arbitrary register list
+% #4: parameter(s)
+\protected\def\yquant@circuit@actonwires#1#2#3#4{%
\begingroup%
\let\tmp=\empty%
\def\do##1{%
% We do not extend the wire: a register that is discarded somewhere does not make
% sense, only right after some application (which is supposed to already have
% extended the wire appropriately).
- \appto\tmp{#1{##1}#3}%
+ \eappto\tmp{#2{##1}#4}%
+ #1{##1}#4%
}%
- \dolistloop{#2}%
+ \dolistloop{#3}%
\csxappto{\yquant@prefix draw}{\tmp}%
\endgroup%
}
% sets the output of wires
% #1: arbitrary register list
-\protected\def\yquant@circuit@output#1{%
- \csxappto{\yquant@prefix outputs}%
- {\noexpand\yquant@circuit@output@do%
- {\noexpand#1}% there is nothing to expand - except the first token, which might be \yquant@register@multi, and we need to preserve this.
+\protected\def\yquant@circuit@output{%
+ \protected\def\idx{}%
+ \protected@csxappto{\yquant@prefix outputs}%
+ {\yquant@circuit@restore%
{\yquant@attrs@remaining}%
- {\unexpanded\expandafter{\yquant@lang@attr@value}}%
+ {\unexpanded\expandafter{\yquant@circuit@operator@targets}}%
+ {\yquant@circuit@operator@mintarget}{\yquant@circuit@operator@maxtarget}%
+ {\yquant@circuit@operator@numtarget}%
+ \yquant@prepare{\yquant@lang@attr@value}{}%
}%
}
-
-\protected\long\def\yquant@circuit@output@do#1#2#3{%
- % this must only be called at the end of an environment, where \yquant@env@end@xpos is set up properly! It not only has to provide the appropriate drawing commands for later, but also has to measure the actual width of the outputs, which is required for proper subcircuit positioning.
- \def\do##1{%
- \pgfinterruptboundingbox%
- \yquant@env@virtualize@path%
- \ifyquant@firsttoken\yquant@register@multi{##1}{%
- \csxappto{\yquant@prefix draw}%
- {\yquant@draw@output@multi%
- \yquant@circuit@output@do@multi@@extract##1{\unexpanded{#3}}}%
- \yquant@draw@@output@multi{#3}%
- }{%
- \csgappto{\yquant@prefix draw}%
- {\yquant@draw@output@single{##1}{#3}}%
- \yquant@draw@@output@single{##1}{#3}%
- \yquant@register@update@height{##1}{\the\pgf@picmaxy}%
- \yquant@register@update@depth{##1}{\the\dimexpr-\pgf@picminy\relax}%
- }%
- \ifdim\pgf@picmaxx>\csname\yquant@prefix xmax\endcsname%
- \csxdef{\yquant@prefix xmax}{\the\pgf@picmaxx}%
- \fi%
- \endpgfinterruptboundingbox%
- }%
- \yquant@draw@output@group{#2}%
- \csgappto{\yquant@prefix draw}{%
- \yquant@draw@output@group{#2}%
- }%
- % \dolistloop will carry out one \expandafter on the argument; but this expansion step
- % is already done. If #1 starts with \yquant@register@multi, this will be expanded once
- % despite \protected, so insert some expand-to-nothing token first.
- \dolistloop{\empty#1}%
- \csgappto{\yquant@prefix draw}{%
- \yquant@draw@output@endgroup%
- }%
- \yquant@draw@output@endgroup%
-}
-
-\def\yquant@circuit@output@do@multi@@extract#1#2#3#4#5{%
- {#2}{#3}{#5}%
-}
% END_FOLD \ No newline at end of file