.he Fido/FidoNet/FidoTerm Script Language Copyright Tom Jennings # Tom Jennings Fido Software 164 Shipley San Francisco CA 94107 SCRIPT LANGUAGE MACHINE MODEL Fido/FidoNet's script language is a machine language, and like all¨ machine languages, there is an underlying "model" machine that¨ the script instructions manipulate. The buckets and Beetles, that¨ is. The script machine model has the following components at your¨ disposal: NAME DESCRIPTION &A The numeric "accumulator", values 0 - 65535 &C The "clock", counts up, in seconds &T The "trap register", 0 or 1 - 65535 seconds &E The "error register", either 0 or 1 &R The general purpose Recognizer &S The "shift register", 20 characters, &1 - &8 General purpose registers stack 10 levels of data stack &A: The "accumulator" (such a quaint word) is a simple¨ register for storing or manipulating numbers. It can be set to¨ any value from 0 to 65535. It can be stored into any other¨ register. There are instructions to test when the accumulator is¨ zero. &T: The "trap register" is part of a mechanism to break¨ endless loops; the "TRAP" instruction is used to set a failsafe¨ if a script or part of a script takes too long to execute. &E: The "error register" can be either 0 or 1, with 1¨ generally indicating an error condition. There are instructions¨ to set and test the error register. &R: The Recognizer can be used to store text or numbers. &1 - &8: These are general purpose registers, and can hold¨ numbers or text. They are used to pass parameters to subroutines.¨ Each subroutine level has it's own set of these registers. When a¨ subroutine is called, the initial values are those of the calling¨ routine. &S: The "shift register" is a special register that contains¨ the last 20 characters received from the modem, and is what¨ patterns are matched against. Characters are shifted in from the¨ right, and the left most character "falls off" the end. You can¨ also store text in &S and use the "IF" instruction to do string¨ comparisons. &1 through &8 are "local variables"; they are not shared amongst¨ all subroutine levels. When a CALL is executed, the called script¨ "inherits" the calling scripts initial values for these¨ registers, but any changes made are lost upon RETURN. The stack is a general purpose "push down" stack; you PUSH items¨ onto the stack, and POP them off. Items can only be accessed from¨ the top of the stack. There is room for up to ten items on the¨ stack. If there are (for instance) five items on the stack, to¨ get at the first one pushed (the "bottom" of the stack) you must¨ first pop off the four on "top" of it. .pa INSTRUCTION SYNTAX All instructions are of the form: INSTRUCTION OPERAND OPERAND Blank lines or lines beginning with a semicolon are ignored.¨ Lines beginning with a colon (label statements) are ignored when¨ processing instructions. Operands are usually text strings, and all strings should be¨ quoted. INSTRUCTION PROCESSING The script processor is basically a text processor. The macro¨ language applies to all commands at all times. Anything to the¨ right of the instruction itself is expanded by the macro¨ processor. Macros are expanded from left to right, once. There are two¨ special tokens the macro processor understands: &(one letter register name) \(special text character) The language chosen allows just about every disgusting trick¨ possible with machine language; self-modifying code, computer¨ GOTOs, etc. I'll dispense with the formality, and show some¨ generalized examples and leave it at that: Message "This is a string" The MESSAGE command merely displays what it's given on the¨ command status line. It makes for a simple example. In this case,¨ centered in the status line you'd see: This is a string If the recognizer (&R) contained the string "HELLO DUDE" the¨ instruction: Message "The recognizer contains &R" Would display: The recognizer contains HELLO DUDE To display the same thing, but with quotes surrounding the¨ contents of the recognizer, you would use: Message "The recognizer contains \"&R\"" Displayed as: The recognizer contains "HELLO DUDE" Note the \ before the quote character merely quotes what follows.¨ There are some convenient exceptions: \r carriage return, 13 decimal \n line feed, 10 decimal \e escape, 27 decimal \b backspace, 8 decimal \c etx (Control-C), 3 decimal \1 SOH character, decimal 1 \127 DEL character, decimal 127 ... ... If you don't like that, ("C" programmers will like it though) you¨ can enter control characters like so: ^A 1 decimal, ASCII SOH ^M carriage return, 13 decimal ^J linefeed, 10 decimal ... ... The ADD instruction adds a value to the accumulator. For example: ADD 27 Would add 27 to the accumulator; if it had contained 3, it would¨ now contain 30. If the &2 register contained "34", the following: ADD &2 Would add the numeric value 34 to &A. If &2 contained "ABRACADAB"¨ then it would add zero to &A. Here are some further examples. Assume first: &A contains 20 &R contains "Text" &1 contains "764-1629" &2 contains 300 INSTRUCTION OPERAND EXPANDED message "sample text" sample text message &R 20 message "pattern is &r, OK?" pattern is 20, OK? message "&A&R&A" 20Text20 message "Dialing &1 at &2 baud" Dialing 764-1629 at 300 baud You can take this to absurd extremes. The instruction JMP