// Numbers are dynamically created when needed. All references to succ##num or predec##num must use deep assign unless guaranteed to be heading towards zero. // Must initialise numbers at least as far as any hard-coded numbers in the generator: mediumpositiveinteger goes up to 7, so I must define succ_7 and predec_-_7 // ChrisHowlett/BetaExaltedStatsGenerator goes up to 9...
nothing ::= nothing2 nothing2 ::= "" storenewnum ::= incinitialisednumbers <<nextnum::=bothdigits>> storenum <succ##currnum::=getnextpositivenum> <predec##-##currnum::=getnextnegativenum> bothdigits ::= tensdigit unitsdigit incinitialisednumbers ::= <unitsdigit::=digitsucc##unitsdigit> <initnewnum##unitsdigit::=nothing> <initnewnum##0::=inctensdigit> initnewnum##unitsdigit inctensdigit ::= <tensdigit::=digitsucc##tensdigit> // The below is what gets evaluated-on-demand when numbers are requested beyond what's currently initialised. // By the time storenewnum is done, the requested number has been moved to "prevnum" getnextpositivenum ::= storenewnum prevnum getnextnegativenum ::= storenewnum <prevnegnum::=-##prevnum> prevnegnum
// storenum mustn't store any ways to reach numbers that haven't been fully initialised. Setting succ##currnum::=nextnum is forbidden, because nextnum isn't fully initialised by this run through storenum. We can store links like predec##nextnum::=currnum, however. storenum ::= <succ##prevnum::=currnum> <predec##nextnum::=currnum> <succ##-##nextnum::=-##currnum> <predec##-##prevnum::=-##currnum> <sign##currnum::=positive> <sign##-##currnum::=negative> <abs##-##currnum::=currnum> <abs##currnum::=currnum> <thisparity::=parity##currnum> storehalfandparity##thisparity <-##-##currnum::=currnum> <prevnum::=currnum> <currnum::=nextnum> storehalfandparity_0 ::= <parity##nextnum::=1> <parity##-##nextnum::=1> <half##currnum::=currhalf> <half##-##currnum::=-##currhalf> storehalfandparity_1 ::= <parity##nextnum::=0> <parity##-##nextnum::=0> <half##currnum::=currhalf> <half##-##currnum::=-##currhalf> <currhalf::=succ##currhalf>
// special cases that don't get set up correctly by the above initspecialcasenumbers ::= <sign_0::=0> <succ_-_1::=0> <predec_0::=-_1> <half_-_1::=0>
// For X > Y, we calculate X-Y, and return true if the result is positive _greaterthan ::= <minus_op1::=gt_op1> <minus_op2::=gt_op2> _minus <tmp::=sign##minus_output> <gt_output::=_greaterthanresult##tmp> _greaterthanresult_0 ::= 0 _greaterthanresult_positive ::= true _greaterthanresult_negative ::= false
// max(X,Y) is X if X>Y or X==Y, Y if X<Y // this could probably be more efficiently rephrased to use _minus directly, rather than going via _greaterthan _max ::= <gt_op1::=max_op1> <gt_op2::=max_op2> _greaterthan _maxresult##gt_output _maxresult_0 ::= <max_output::=gt_op1> _maxresult_true ::= <max_output::=gt_op1> _maxresult_false ::= <max_output::=gt_op2>