From 3616a8a41581795ce9e0e3e23ffe08dddd676d32 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 7 Nov 2007 06:06:38 +0000 Subject: edits for chapter 7 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43810 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/tutorial/LangImpl6.html | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'docs/tutorial/LangImpl6.html') diff --git a/docs/tutorial/LangImpl6.html b/docs/tutorial/LangImpl6.html index 8976acf50e..b6420c990a 100644 --- a/docs/tutorial/LangImpl6.html +++ b/docs/tutorial/LangImpl6.html @@ -52,9 +52,9 @@ One of the great things about creating your own language is that you get to decide what is good or bad. In this tutorial we'll assume that it is okay and use this as a way to show some interesting parsing techniques.

-

At the end of this tutorial, we'll run through a nice -little example that shows an example application that you can build with -Kaleidoscope and the feature set it now has.

+

At the end of this tutorial, we'll run through an example Kaleidoscope +application that renders the Mandelbrot set. This gives +an example of what you can build with Kaleidoscope and its feature set.

@@ -69,8 +69,8 @@ The "operator overloading" that we will add to Kaleidoscope is more general than languages like C++. In C++, you are only allowed to redefine existing operators: you can't programatically change the grammar, introduce new operators, change precedence levels, etc. In this chapter, we will add this -capability to Kaleidoscope, which will allow us to round out the set of -operators that are supported, culminating in a more interesting example app.

+capability to Kaleidoscope, which will let the user round out the set of +operators that are supported.

The point of going into user-defined operators in a tutorial like this is to show the power and flexibility of using a hand-written parser. The parser we @@ -262,7 +262,7 @@ a lot of similar code in the past. One interesting piece of this is the part that sets up FnName for binary operators. This builds names like "binary@" for a newly defined "@" operator. This takes advantage of the fact that symbol names in the LLVM symbol table are allowed to have any character in -them, inluding embedded nul characters.

+them, even including embedded nul characters.

The next interesting piece is codegen support for these binary operators. Given our current structure, this is a simple addition of a default case for our @@ -335,7 +335,7 @@ precedence parser, this is all we need to do to "extend the grammar".

With that, we have useful user-defined binary operators. This builds a lot on the previous framework we built for other operators. Adding unary operators -is a bit more challenging, because we don't have any framework for it yet, lets +is a bit more challenging, because we don't have any framework for it yet - lets see what it takes.

@@ -347,7 +347,7 @@ see what it takes.

Since we don't currently support unary operators in the Kaleidoscope -langugage, we'll need to add everything for them. Above, we added simple +language, we'll need to add everything for them. Above, we added simple support for the 'unary' keyword to the lexer. In addition to that, we need an AST node:

@@ -530,8 +530,7 @@ def unary!(v) def unary-(v) 0-v; -# Define > with the same precedence as >. We could also easily define -# <= etc. +# Define > with the same precedence as >. def binary> 10 (LHS RHS) !(LHS < RHS); @@ -615,13 +614,13 @@ href="http://en.wikipedia.org/wiki/Mandelbrot_set">Mandelbrot Set. Our mandelconverge function returns the number of iterations that it takes for a complex orbit to escape, saturating to 255. This is not a very useful function by itself, but if you plot its value over a two-dimensional plane, -you can see the mandelbrot set. Given that we are limited to using putchard +you can see the Mandelbrot set. Given that we are limited to using putchard here, our amazing graphical output is limited, but we can whip together something using the density plotter above:

-# compute and plot the mandlebrot set with the specified 2 dimentional range
+# compute and plot the mandlebrot set with the specified 2 dimensional range
 # info.
 def mandelhelp(xmin xmax xstep   ymin ymax ystep)
   for y = ymin, y < ymax, ystep in (
@@ -631,7 +630,7 @@ def mandelhelp(xmin xmax xstep   ymin ymax ystep)
   )
  
 # mandel - This is a convenient helper function for ploting the mandelbrot set
-# from the specified position with the specified magnification.
+# from the specified position with the specified Magnification.
 def mandel(realstart imagstart realmag imagmag) 
   mandelhelp(realstart, realstart+realmag*78, realmag,
              imagstart, imagstart+imagmag*40, imagmag);
@@ -782,12 +781,12 @@ plot things that are!

With this, we conclude the "adding user-defined operators" chapter of the tutorial. We successfully extended our language with the ability to extend the language in the library, and showed how this can be used to build a simple but -interesting end user application in Kaleidoscope. At this point, Kaleidoscope +interesting end-user application in Kaleidoscope. At this point, Kaleidoscope can build a variety of applications that are functional and can call functions with side-effects, but it can't actually define and mutate a variable itself.

-

Strikingly, lack of this feature is an important limitation for some +

Strikingly, variable mutation is an important feature of some languages, and it is not at all obvious how to add support for mutable variables without having to add an "SSA construction" phase to your front-end. In the next chapter, we will describe how you can -- cgit v1.2.3