Magicard!

Magicard! is a theme language created by User:Quintopia in 2013 in which programs consist of instructions for performing card tricks. It is rich with means of moving data from place to place, but there is no way of creating numeric literals singly. To get large literals, you must swamp yourself with smaller ones, then wade through the swamp to find the one you wanted. In addition, the only means of storing the result of an arithmetic operation is again, to wade through a swamp of literals looking for an answer that matches the one you wanted.

Data Organization
All data in Magicard is positive arbitrary-length integers. These integers are stored on cards which can be face-up or face-down, which are themselves initially stored in decks, which are deques. Every integer can be mapped to a deck, so there can be arbitrarily many decks. Each deck initially contains some number n of face-down cards, which contain the values 1 to n in ascending order from top to bottom. E.g., a freshly unboxed deck always has a 1 on top of it.

In addition to being in a deck, a card can be moved to one of four other places: table, spectator's hand, lap, or current packet. Cards can be retrieved from all of these places except lap, which is the clearing-house for all those unwanted extra literals.

There are several means of marking cards within the current deck or packet which may or may not remain in effect after certain operations are performed: side-jogs, in-jogs, up-jogs, pinky marks, and crimps. For instance, any command which squares the deck removes all jog marks.

Program
Magicard programs are imperative in nature, consisting of a series of instructions. Every instruction starts with a capital letter and ends with a period. Any string falling between valid instructions, which ends with a period or newline, but does not match an instruction, is a comment. Every program must begin with an Unbox instruction and end with TA-DA!

Some instructions take numbers and/or expressions as arguments. Numbers must be either entirely numeric, a unicode character enclosed in single quotes (with \ acting as an escape character in the usual way), or the token CRC. Expressions must be logical expression strings (evaluating to zero if false in the C fashion), not containing any spaces, which contain only numbers, the variables i,x, or d, and the operators ^, ||, &&, |, &, ~,, -, +, *, **, /, %, =, &lt;, >, !=, &lt;=, and >=. ( means the unary Kronecker delta.) The variable x will evaluate to the value of the card for which the expression is evaluated if it is face-up, and an implementation-dependent value (such as NaN) which must cause any logical expression with which it is conjoined to evaluate to false if it is face-down. The variable i will evaluate to the position of the card for which the expression is evaluated within the deck or packet at the moment the command containing the expression was first invoked. The variable d will evaluate to the number of the current deck.

I/O
Magicard programs produce output in UTF-8, and assume all input is encoded the same way.

Instruction Set
First, we have the commands that select the current deck:

These commands operate on the current deck. If the current deck does not contain at least the number of cards specified in the first column, that command will emit a runtime error.

The following operations move cards between the current deck and the current packet. They will cause a runtime error if the deck (if cards are leaving the deck) or the packet (if cards are leaving the packet) contains fewer cards than the value in the first column. Furthermore, unless otherwise stated, up-jogged cards which move between the deck and the packet will remain up-jogged, while all pinky, in-jog and side-jog marks will be removed. Moving a crimped card to a deck or packet which already contains a crimped card will cause a runtime error.

The following instructions operate on the current packet only when it is also the current deck. In other words, if they are issued before a Set down deck., there will be a runtime error. In addition, they will emit a runtime error if the size of the packet is less than the number in parens. All of these operations remove ALL jog marks and pinky marks.

The following instructions work on the packet even when it is not the current deck. They also emit errors when their packet size requirement isn't met.

The following instructions are the only means of flow control.

Computational Class
MAYBE Turing-complete. Maybe just total. WHO KNOWS?

Examples
Cat: Unbox deck 0 of 4294967296 cards. Have a card selected face-up. Name. Deal 1 card with a flourish. Ring in a cooler. Do last 4 steps again if CNC!=10. TA-DA!

Long Hello World: Unbox deck 0 of 127 cards. Take packet of 127 from top. Repeat on next 11 decks. Put packet on top of deck. Pinky-break 'H'. Charlier cut. Riffle down 'H'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'e'. Charlier cut. Riffle down 'e'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'l'. Charlier cut. Riffle down 'l'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'l'. Charlier cut. Riffle down 'l'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'o'. Charlier cut. Riffle down 'o'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break ' '. Charlier cut. Riffle down ' '. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'W'. Charlier cut. Riffle down 'W'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'o'. Charlier cut. Riffle down 'o'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'r'. Charlier cut. Riffle down 'r'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'l'. Charlier cut. Riffle down 'l'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 'd'. Charlier cut. Riffle down 'd'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break '!'. Charlier cut. Riffle down '!'. Hot-shot cut. Pinky break 126. Charlier cut. Pinky-break 10. Charlier cut. Riffle down 10. Hot-shot cut. Set down deck. Bottom Deal 12 cards flipping each one with a flourish. TA-DA!

Hello World without using packet: Unbox deck 0 of 127 cards. Crimp. Flip deck. Riffle down 'H'. Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down 'e' Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down 'l' Charlier cut. Deal 1 card with a flourish. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down 'o'. Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down ' '. Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down 'W'. Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down 'o'. Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down 'r'. Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down 'l'. Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down 'd'. Charlier cut. Deal 1 card with a flourish. Pinky-break at crimp. Charlier cut. Riffle down '!'. Charlier cut. Deal 1 card with a flourish. TA-DA!

Shorter Hello World: Unbox deck 0 of 127 cards. Take packet of 127 from top. Repeat on next 5 decks. Put packet on top of deck. Biddle count 127 stealing when i='H'||i='e'||i='l'. Biddle count 127 stealing when i='l'||i='o'. Biddle count 127 stealing when i=' '||i='W'||i='o'||i='r' Biddle count 127 stealing when i='l'. Biddle count 127 stealing when i='d'. Biddle count 127 stealing when i='!'. Deal 12 cards flipping each one with a flourish. TA-DA!

Faster Hello World: Unbox deck 0 of 122 cards. Flip deck. Upjog x='H'||x='e'||x='l'||x='o'||x=' '||x='W'||x='r'||x='d'||x='!'||x='z'. Strip out. Set down deck. Flustration count. # !HWdelorz Roadrunner cull x='H'||x='e'||x='l'||x='o'||x='z'. # !WdrHeloz Roadrunner cull x=' '||x='W'||x='r'||x='z'. #!dHelo Wrz Roadrunner cull x='!'||x='d'||x='z'                                        #Helo Wr!dz Deal 2 cards to spectator with a flourish. #lo Wr!dz Deal 1 card with a flourish. Deal 1 card with a flourish. Gemini count. #o Wr!dlz Deal 1 card with a flourish. Gemini Count. # Wr!dloz Deal 2 cards to spectator with a flourish. #r!dloz Flustration count. #zold!r Deal 1 card to spectator. #old!r Elmsley count. #orld! Deal 5 cards with a flourish. TA-DA!

LSB Radix Sort (also known as the Chinese Shuffle): Unbox deck 0 of 127 cards. Flip deck. Biddle count 127 stealing when x>='A'&&x<='Z'. Lap. Shuffle. Take packet of 26 from top. Unbox deck 1 of 0 cards. Put packet on top of deck. Roadrunner cull x%2**d>2**(d-1). Take packet of 26 from top. Repeat on next 4 decks. Put packet on top of deck. Deal 26 cards with a flourish. TA-DA!
 * 1) shuffle the capital letters, then sort them, and print them in order again.