1x Forth
Charles Moore, April 13, 1999
This article is written in Jeff Fox based on Charles Moore.
I asked Chuck Moore to allow me to record this conversation on the Forth language change in 15 years. We installed the camera, he talked about the problem I made on this website, but this time we no longer focus on the experience of solid physics, VLSI or chip and debugging, but the Forth language. I think he talked about the Forth language in these years, but compared to the language of 30 years ago, he talked about more aspects.
I introduced Chuck.
(Jeff Fox) Today, I invite Chuck Moore to make a introduction to Forth, I want to ask him to talk about the language of the inventive language in the last 15 years. Now let's ask Charles Moore.
(Charles Moore) This is a big topic, how long will we talk about?
(Jeff) Tape is only one hour.
(Chuck) 15 years, that is almost the entire experience of the software I use the computer. Recalling 15 years ago, there are two main motives that focus from the Forth language to the Forth microprocessor.
The first is the problem of software has been solved. Writing an application is easy, don't have much effort. All problems are hardware, hardware clumsy, zero chaotic, bad, especially if you need to write customized software for our customers' hardware. If you want to debug hardware, it is a big trouble. These are all illustrated hardware engineers do not make excellent work. Of course, they do better than software engineers in the industry, but there is no Forth software engineer to do well. So I want to see what I can do in these hardware issues. This may be an error. Forth has many interesting things to do, hardware can not be so interesting.
I don't know if you have heard these history, the first Forth processor is Novix, which may also be the first in all such processors. It is a 16-bit processor that is manufactured with a high speed process, with an average 8MIPS. This work is very interesting, we give it a good Forth system, called cmforth, smaller, simpler, simpler, and simpler, then SHBOOM is 32-bit processor, 50MIPS. Now I21 is the latest outcome, it is 20, I am very pleased to announce its speed is: 500MIPS.
Each processor has its own Forth language, the target is very simple: the complexity of hardware and software is the smalle. As long as I don't see other people doing this, it is just that people talking, no one is really doing anything about the smallestity of complexity, that is, I need to do my best.
We are building a culture, it is not able to resist a small disaster such as Y2K. One, we lost billions of dollars in packages, one, we lost the programmer team consisting of thousands, can we re-establish? Don't you care about what you can rebuild? Does the computer are worth investing in our society? It can be much simpler. If it is simpler, then I will be more confident to technological in the future.
It is a tendency to make things complicated. People like to make them complicated, which is everywhere. You can see in TV shows that you can see in the market's products, you can also see on the website web page, simply indicate that the information is insufficient, you make it wonderful. I think there is a best complexity that people can design them. You will make things simple, the public will feel bored, but you make them too complicated, and will lose the public.
I have never felt boring because it is simple. Give me a simpler method, I will not be in a hurry to get it. But in the car, aircraft, spacecraft and a large number of complex devices are not like this. Forth doesn't need to be so complicated. Classic Forth is from simple start, it is slowly surrounded by complex. In Forth Inc., this has become the company 's culture. We have a package, we sell it, we expand it, we love it. When I left Forth Inc, I had a simplified opportunity, and CMForth is the results. Unfortunately, CMForth did not have a wide application, so I'm hard to tell you how much it can work. In my memory, Shboom is as good as CMForth. The biggest application I did is to make the video work and start the customer chip design package, so I know the shortcut to use Shboom.
I21, I am using colorful Forth, I haven't used it to do effectively. It is extremely simple, it is simpler than any predecessors. I want to talk about why.
I21 itself is a simple processor, but it has not been possible to be the most simple, because it is the only hope that we can sell this processor is its speed, so I have added a lot of complexity to meet speed requirements. I hope that I got a reason for a balance. 500 MIPS is an attractive speed. We can only keep this speed for a while, but it will become smooth one day. The problem is that there is no such speed, or there is no large number of processors to require this speed. It is difficult to sell.
I have recently seen the most interesting app is SETI's family plan. In this plan, you can download data from the Arecebo website and processes two weeks on your own PC, and then transfer the results back to research institutions. So a fast processor can be easily sold and applied there. There may be some things that the SETI distributed processor system can do.
One, you got a processor, you want it to fit Forth. After that, how should Forth develop this processor? This problem introduced what is the problem. I am looking forward to someone can tell me the answer. I am constantly asking, what is FORTH?
FORTH is a highly factorized code. I don't know what to say in addition to saying FORTH is defined. If you have a lot of short definitions, you are writing the Forth program. In order to write a lot of short definitions, you need a stack. The stack is not popular, I am very strange why it is not popular. Many stresses come from vested interests, they don't like stacks, they like registers. Stacks are not a concept that can solve all problems, but it is really useful, especially for information masking, and you need two stacks.
These ideas have been more than 30 years. I have already discussed them for more than 30 years, but now I have accepted the extent to 30 years ago, it may be more concerned with the development of the industry.
Forth defintions stacks
This is Forth. Need to support definitions.
What is definition? Very classic saying is a definition that uses a colon to explain some things, words, where to end definition, etc.
: Some ~~~;
I always tried to explain the significance through abbreviations. Whether you write down here is for more common or more convenient. But it is not strictly abbreviated, it can have one or two parameters. There is a programmer related questions, or it may be related to all programming: We have entered too much parameters to a subroutine. Look at many C language programs, they are ridiculous. Each thing in the program is passed by calling a sequence, while the subroutine is just a dumb.
A Forth word should not have more than one or two parameters. There are so many troubles to handle the stack to handle the stack, absolutely should not have more than 3 to 4 elements depth.
The specific practice of our present is to make a word (:) in red. In this way you don't need to use the colon, which not only reduces the size of your storage source text, but also makes the back of the work very clear. The red word is defined: some ~~~
Definition is green, there can be a semicolon indicate returns in the definition, but does not end a definition. If you need, you can have multiple returns, you can have more than one entry point. Without a colon definition, this definition will fall into another definition and return it next; we have not indicated the status of compilation mode and execution mode. You or it is running green or is running on white. Black means executing, green means compiling, red means definition.
This is more simple and clearer for me, this is a new concept, but it has not been widely accepted, but we will see it immediately.
But for the stack, the stack should be very shallow. On the i21 chip, the stack has only 18 elements of the depth, and this size is a valid number.
Handling this stack of words is DUP, DROP, and OVER, nothing else. SWAP is also very convenient, you need it, but it is not a machine instruction. However, we don't have Pick and Roll, no complex operations allow you to discover the elements by claim. The first two elements are the stack section you need to care. of course. On a chip, they are the input of two alu, which is also hardware.
Other elements are also on the stack, because you put them there, you are ready to deal with them when the stack is returned there. They are not there because you are using them. You don't want to stack too much, because you will soon forget their meaning.
So, those who draw the stacks of pictures should understand that they are doing incorrect things, even if they are very common short icons. This method is: If you define a word, you still write a description to display the impact of the stack, such as F and X and Y
F (x - y)
In the past, when I made the stack too complicated, I also used this method, but it is no longer like this. We don't need this type of information, it should be able to get it easily from the source code, or you should write a document in another place.
So the stack operation I use is very limited, and the conditional operation is the case, in the classic Forth we use if else kil, now I have excluded Else.
I don't think Else's use can be compared to the complexity of the introduction, you can understand this through my code. I will use the IF and a semicolon, I will exit the definition or continue at one point.
IF ~~~; then
I have two branches, but I have used "semicolons that don't end a definition".
There is also a cycle, there are many cyclic structures. It turns out that the structure I use comes from other languages, I think things are developing like this. They are
Do Loop
For next
Begin Until
Do Loop comes from the Fortran language, and for next comes from the Basic language, Begin Until comes from the Algol language.
Which one is we selected in Forth? This (Do Loop has two loop control parameters, too complicated. This (for next) has a loop control parameter, which is very convenient for hardware, which is also very simple if there is enough hardware implementation. This (begin) has a variable number of parameters. Unfortunately ... (Videos Noise)
We are using ITV record devices, which is the vault. If you hear a echo, what is it? That is the vault.
I got a new loop structure, which used in Color Forth, I think it is better than those of the other. This method is: If I have a word Word, I can implement some of the conditional reference to this word word. This is my loop method. Word ~~~ if ~~~ Word; the ~~~;
I am back to the current definition, this is the only way I use a loop now, it is sufficient and convenient. It also has two marginal impacts: one is that it requires a recursive version of Forth, which must be referenced in the current definition, and cannot be predefined. This saves the smudge / unsmudge concept, and ANS is preparing to find a suitable name for this concept. But the end result is that it is simpler.
This method for nesting cycles is of course very inconvenient, but nesting cycles is an uncertain concept. You can also have nested definitions. Should you perform a word, or there should be a structure like if Ten? We have discussed this issue for 15 years. Here is an example, I think it is very clear that the only loop must be repeated.
Word ~~~ if ~~~ Word; the ~~~;
If you insist on doing this, you can achieve more thorough factorization. This is the key to Forth in my mind. You factor, reimbursement, and then factorization until most of your definitions are only one line or two.
(Jeff) You may mean that the semicolon after Word leads to a tail (you can turn the call to the Word to jump.
So you have no reason to make a call, because you will not go anywhere, you can use a jump. In fact, in all of my recent Forth, the significance competition like a semicolon is a return or a jump will depend on the context, and the optimization is done by the compiler. That is a very simple backward optimization, actually saving important resources, that is, returning to the stack.
In my I21, only 17 in the depth of the returning stack, people who use this nested structure may encounter trouble, you can't nest too deep, making it impossible to carry out the next program design. You can also use calls to get the same chaos with goto. You should remain simple.
This is the main revision I can think of of the recent forth. Maybe Block is an exception. Block is an interesting block access word for accessing a zone of the disk. Now I define it into a zone accessing the memory. Without any reason to use disk, because there is a megabyte memory, you only need to load the data into the memory and run from there. Because of the need for disk, the word block is very simple, the basic block definition is a product with 1000:
Block 1024 *;
This specifies that the memory you visited is 1024 bytes wide. Block's value is the partition value you made for the memory. It puts your memory factor into a manageable piece, you can think that the memory is composed of one megabyte or consists of thousands of blocks. of.
I have seen a web page of NASA, I think it is still very interesting now. It said that the speed of the spacecraft is 110,000 kilometers per hour. Because I have no feeling about such numbers, I feel that if I convert it into 69,000 miles per hour, it will be better. However, these numbers still have no significance for ordinary people. I want to convert it into how many kilometers per second or other smaller numbers we can feel. When we use 120M bytes of memory, use such a big number will not have any benefits, it is just a big number, although it is impressive, but there is nothing. So Block can make an appropriate calibration for us.
One statement is that Forth is completely determined by the programmer. I am willing to understand what to understand as Forth programmakers should do. I found that I taught someone Forth language, and I don't mean that he is a good Forth programmer. Before you can make effective work, there are some FORTH forms and syntax, which is already embedded in your mind. My point is: Every app I have seen, as long as I write it yourself, its code amount will be 10 times the actual needs. I also see that Forth programmers are writing applications with 10 times long code that requires code.
What I care about, I have been thinking about these years is: How can I persuade these people to write good Forth? How can I tell them that the written forth is possible? Why is people written by what they need to write 10 times?
Microsoft is doing this, I think everyone knows, but at least one reason is that they must be compatible with anything you have made. If you can't start from a clear white paper, then you have to write more code. But do you need 10 times the code? It seems to be too much.
How big should a program be? For example, how big should the TCP / IP protocol stack? I do not know. I don't know before I sit down and write the code. But it should not be large, about 1k word.
There are 4 instructions for each word of I21. Pentium computer every two byte instructions. This is difficult to judge. You should discuss the instead of the memory that the instruction resides.
It seems that about 1,000 instructions will make me do anything, and all the programs should be a 1000 instructions.
How do you get it? What is this 诀窍 this? How do you make the app very small? There are a few things here that in any case, use any language should be careful:
No hook
The first thing is that there is no hook. Don't leave an interface, think about when you can insert some code when the problem changes, because the problem will change in a way you can't foresee. Anyway, this cost is definitely a waste. Don't predict that you only solve the problem of your eyes.
Don't complicate
Simplify the problems you have encountered, at least don't make it complicated. I do this, I am very interesting. You have encountered a troublesome problem that is a more interesting question after it. So you should write code for more interesting questions, you are just its subset, it is insignificant. However, if you work hard to encode this negligible problem, you will of course prepare the code that you need to be resolved is equivalent to actually needing 10 times.
10 times the code means 10 times cost; the cost, the cost of the document, the overhead of the memory, the overhead of the disk, the overhead of the compilation, and the overhead of loading. Everything you have done is 10 times. The actual will be worse, because complexity is increased in accordance with the index.
10x code
10x cost
10x error
10x maintenance
10 times the error! 10 times the maintenance difficulties give a good description on Y2K issues. Surprisingly, I saw that people have resolved Y2K with COBOL, which makes the program significantly more complicated, larger, introduced more spaghetti code, which is more maintenance. If they are using Windows, after 50 years, the application will crash again. Programmers are not the range of expanding the date, but just move it, so when it runs to the end, it will generate another problem.
This is why we have still running 10 years or 20 years ago and why people don't have money to update, understand and rewrite these programs. Because they are too complicated, it is more than 10 times more than they should have.
So, how do you avoid this trap? How do you write a double program?
1 times, 1x should be the name of a web page
You factor, factorization, factorization, factorization, you throw away all things that are not used, unreasonable things.
All of Forth is that you can't use Forth to write programs, but use Forth to write a dictionary. When you design an application, you write about 100 words, which can describe the app, then you use this 100 words to write a row of definition to solve the problem. It is not easy to find these 100 characters, but they exist, they always exist.
Let me give an example of an application. In this example, you can reduce 90% of code, but also a situation can reduce the code. This example is our familiar file. If you use a file in the application or Forth system, you have some words:
Open close read write rebind, etc.
They may not be such short words, such as Open-file like in Windows. If you feel that these don't need it, then you will save 100% space for implementing the file system code. File systems are not a large part of a typical application, but it is an uncommon part. I have determined that you have to do, saying that we don't need to do things. We don't need to make a checksum on the top of the checksum. We don't need to encode encryption because we don't need to transfer anything at all. You can save all these things.
What you see now is a solution to all the problems encountered by all programmers in the world, this solution is common, but no one will encounter a general problem.
I hope that I will tell you how to write a good forth. I can prove it. I have proved that the application code can be reduced by 90%, which can reduce 99% in some cases, I can do it, but need a case in a case. I have always found a general principle.
(Jeff) I have a question is about your Color Forth screen. People have noticed that you use a lot of fonts on the screen, but only less information. How much is it due to your eyesight? How many information do you have when you look at it?
(Chuck) I have more and more patient about the small font, I can't read the web page. Go directly to those characters. Unclear, wear glasses, they are still ambiguous. If you increase the font, this can sometimes do it, sometimes you can't do it, you will lose some context. This is a problem, which may be a problem for increasing groups in the public. So I try to use a big character, but if you make them too big, then you will lose information.
Now a classic rule for designing slideshow flipping is that you pick up a frame and then put some topics, you can't put too much content on a slide, otherwise your listener will be confused, if you use too Small characters, people can't read these content.
In the case of Color Forth, I want characters may be too big. I can get 256 characters on one screen once. Depending on the computer used, I can get 20x14 or sometimes 24x15. that's enough. In 256 characters, the information I got will be as much as information obtained in the past 1024 bytes, because I didn't format, and even there is no wrap. Full characters on my screen.
One reason is that I want to explore the value of the color word. If I have some color word, how will different colors work? I found that they did it, I don't need to use definition words to format them. Of course, it is actually not good, because there is a red wall on the left side of the screen, if you use this way, it is not necessarily not using red.
I think you should use this philosophy when you are doing a webpage. Put as little information on the web page, as long as you want to tell people what you want to tell people, don't make a speech. On the other hand, don't put an index on the page. You should only put in real information, you need to brighten important information, you need to make it clear and read. It is more difficult to change my font. I use 32x32 pixel points. Next time I can use 24x24 pixel points to try it.
This format applies very little as a screen. An application is approximately 2 or 3 screen lengths, which is quite based on the code written in an application in a context.
For example, I have an application that displays a special chip performance spectment on the screen. This is a beautiful display, which means that the information is an understandable method is a good practice and important way. If you have the opportunity to see its demonstration, it must be very interesting.
Small app. The application is not the right word, the small code is only a special thing, never doing universal things.
Jeff reminds me of another concept of Machine Forth. Machine Forth is the Forth I am very willing to recall, which uses the Forth's original language built in the machine to do something rather than using the interpreter version or macro definition to do these things. One of these things is IF.
The classic IF removal is left on the stack, which is not convenient on I21, so if if if IF leaves its parameters on the stack, so you have to write a structure like if Drop, but not always In this way, it seems to be convenient and inconvenient to each other. It no longer uses DUP IF or? DUP, that is, it is not? DUP. ? DUP is not a good word, it has left a different number in the stack, and it is very unwise to do such a thing.
IF
-IF
In addition to IF, Machine Forth has a judgment -IF. This word is used to test 0, which is only used for test symbol bits. I think you may often need to make decisions according to a number of positive or negative. But it is not working in that way. In Color Forth, I don't even care how to use it.
In the past two decades, the world has undergone significant changes, but I don't think people can predict that when I start working for the first time in the 1950s, only 7 computers were used for calculation. The computer at that time is always used to solve the large and long arithmetic expressions. The fact that we do is to make these things factors, so that these do not have to repeat the calculation, it can run faster, that is, all views of the Fortran language. This kind of tradition has been influenced today.
I have not done statistics, but I guess today's computer, most of them are not used to calculate, but in mobile bytes. If you have a browser, this browser is almost unable to calculate in addition to the size of the computer screen. Viewing a number of symbols may not be as useful as I think, almost all numbers are positive, do not need to see their symbols. Based on the same reason, Machine Forth has no subtraction operation. I handled subtraction into 1 complement.
- One COMP
This way is not convenient to make subtractions. But for today's applications, implementation agreements or display text, arithmetic operations are not required. A computer should not optimize the arithmetic operation, and my computer is not.
On the other hand, it is useful for implementing an incremental access operation for the optimization of data transmission. The address is issued on any computer, but this is a more special issue on I21. On I21, the address is a 20-bit number. In order to load an address, you'd better do a text constant, it can take out 20 extensions. An additional memory load cycle is required, then you can read the memory, which in turn needs another memory cycle. So the address of the address is very expensive, you should try our best to minimize it. Take the (@ ) operation word to help. You put an address into the address register, then it exists. If you execute @ , a will be incremented, you can read the contents in the back. Similarly, you can also store a stroke. Of course, when you need it, you have nothing to take (@) and save (!). In the classic Forth system, there is not these operations, I want to have not mentioned in the standard. They lead to a completely different program style. In the case of Do LOOP, the most efficient thing is to use the actual address as the loop parameters, then read it through the word i, and take it within the loop (I @). Do Loop works with the address if you do this, if you use a read operation (@ ), then you don't need Do Loop, you don't need I, you use read add (@ ) in the loop (@ ) You can read a different thing every time, they are different but equivalent. You can convert a convert into another, easy to read the things in the A register.
In the case of Move, you want to move some things from a region of the memory to another, you need two addresses, so the value as the address is stored in the R register, because only in one context can be Place the address in the R register, it has an automatic incremental power. So I basically have the take-on (@ ) for A, and the R or Solving R, you can effectively perform Move.
This will lead to another problem. A In addition to the use of the address register, it is also very similar to a local variable, you can save some things, read it again for a while. The reason why it is used as an address register and I use it. From the literal, it provides a mechanism for address access (@ ). From the programmer's point of view, it is more than placed on the stack The address is more convenient. But if you are ready to access this register, you must put it in a place you can increment to it. To place it you must access that register, if you can do it, you You can use this register to do something else, just like you use the return stack to do something else.
The difference is if you put some things on the back stack, you must also remember to take it down, and you don't have to use it for a register. Someone tried to make A to a stack, so that you can go in in or put it back, it is worth doing so that there is no clear answer. There must be more instructions to access A. Do you want dup a? Do you need Drop a? The way this A is now the easiest.
I may also need a register called M, and a multiplier can be saved in 40-bit multiplication. But there is no enough multiplication in my system to do, so this thing has not become a reality.
But such a register has led to a problem of local variables. There are many discussions about local variables, which is another aspect of saving 100% code in your application. I firmly believe that the local variables are not only used, but also harmful.
If you are writing a code that needs to use a local variable, then you are writing ... non-optimized code? Do not use local variables. Do not appear new syntax to describe them, do not appear new policies to implement them. If you have a partial register, you can make local variables very effective, but don't do this. It is not good. It is wrong. Variables are necessary. Color Forth requires many system variables. When you edit some things, the cursor position variable is also useful. When you return to the cursor position, because the value of the variable is still there, you can return to the original location. Variables are useful, I didn't see any cases of using only a few variables, nor did you see the use of instantaneous access variables.
Smart, explain the stack map, name a word, these are exercises. You can do all these games. I think Forth programmakers may use their tools to make too many games because there is no application. If a Forth programmer can pay more attention to the application instead of the tool, it is better.
For me, an application is a web browser. If you can do anything, write a browser. Netscape did not complete this work, not doing it, it should be able to do it, and did not implement the feature it should have. In fact, Netscape and Microsoft borrow a lot of things from Mosaic, they look like twins. If you still have written in the same language, that language is Fortran.
Write a new browser. This is a good application. It enables you to access the information world, I will pay attention to this good application in my spare time.
Thank you for listening.