Inline::SMITH - write Perl subs in SMITH


    use Inline SMITH => <<EOF;
    function ascii_table {{

      ; Print ASCII table in descending order in SMITH v1
      ; (relatively easy)

      MOV R0, 126       ; Initialize register with top character
      MOV TTY, R0       ; -> Print character to terminal
      SUB R0, 1         ; -> Decrement character
      MOV R1, R0        ; -> Is character zero?
      NOT R1            ; -> Boolean NOT it twice to find out
      NOT R1            ; -> Result is 1 if true, 0 if false
      MUL R1, 7         ; -> Multiply result by seven instructions
      COR +1, -6, R1    ; -> Copy that many instructions forward




The Inline::SMITH module allows you to put SMITH source code directly "inline" in a Perl script or module.


Using Inline::SMITH will seem very similar to using a another Inline language, thanks to Inline's consistent look and feel.

For more details on Inline, see perldoc Inline.

Feeding Inline with your code

The recommended way of using Inline is the following:

    use Inline SMITH => <<EOF;

      smith source code here



But there are many more ways to use Inline. You'll find them in perldoc Inline.

Defining functions

Functions are defined in the following form:

function function_name {{ }}

The function name can contain letters, numbers and underscores. It is published into the main perl namespace, so choose something that

a) you haven't used for your own perl functions b) perl doesn't use for one of it's own functions

Passing arguments

The first parameter passed to an Inline::SMITH function is converted to a stream of bytes. This stream is then accessable using the TTY command in SMITH.

If you pass a hash instead of a string, then Inline::SMITH can change it's IO behavoir. The following keys are recognised:


A plain old input buffer (a string)


Set to 1 to enable echoing of output to the screen. It is turned off by default when passing a hash.


A function ref which is called each time a character of input is needed. The function should return a 0 to indicate end of input.


A function ref which is called whenever a byte needs outputting. The byte is passed as a single character string in the first argument.

Return values

A SMITH function returns it's output buffer as a string. If echo was enabled, or if it was implicitly on by using the scalar calling method, then this buffer will have already been echo'd. The buffer is always returned, regardless of the state of the echo flag or the existence of an output callback.


Cal Henderson, <>


Thanks to:

Brian Ingerson, for writing the Inline module.
Chris Pressey, for creating SMITH and the perl interpreter this module is based on and suggesting IO callbacks.