XTs

In Smojo, a word can be treated like a Literal: It is possible to put them on the stack, print their contents and of course, execute them. In actuality, we don't really put the Word on the stack, but rather something called an XT (from eXecuTable).

An XT contains the following information:

  1. The Word's code section that performs the action,
  2. The Word's data section, which I'll discuss later,
  3. An indicator if the Word is immediate.

As we've seen, you can access the XT of any word in the dictionary using the word 
'
(called TICK) mainly in interpretation mode or
[']
(called BRACKET-TICK) in compilation mode only. (NB:
'
can be also used in compilation mode - see the Quiz below.). You can run an XT using the word
EXECUTE
.

An Example


		Recall that 
.S
simply displays the contents of the stack. This program:
		' * .S
		
will display the XT like so:
		<1> com.terraweather.mini.XT@7a01fdb2 
		ok		
		
This XT has the action of multiplying two numbers. We can demonstrate this:
		>R 2 3 R> .S 
		
It helps to check the stack again:
 	
		<3> 2 3 com.terraweather.mini.XT@7a01fdb2 
		ok
		
And we finally run the XT:
 	
		execute . 
		6 ok		
		

Quiz

Question 1

What is the difference between the tick 
'
and the bracket-tick
[']
? Write programs to test out your answer.



Question 2

In the example, what is the alternative to using 
>R
and
R>
? Rewrite the demonstration to test your answer.



Question 3

Write a program to test if a given XT's word is immediate.



Question 4

What does the word 
XX
do?
: xx ' immediate? . ;
Test your answer with a program using the word
XX
. Hint: (a) Try
xx DUP
and
xx IF
Can you use the results to explain how
XX
works?



Next: Quotations