Skip to content

Commit

Permalink
Fix some doc typos (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
pinicarus authored Mar 15, 2021
1 parent 0f54b3f commit cff49cb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
60 changes: 30 additions & 30 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Terra functions are entry-points into Terra code. Functions can be either define
[local] terra myfunctionname :: type_expresion
[local] terra myfunctionname :: {int,bool} -> {int}

_Terra function declaration_. It creates a new undefined function and stores it the Lua variable `myfunctionname`.
_Terra function declaration_. It creates a new undefined function and stores it in the Lua variable `myfunctionname`.
If the optional `local` keyword is used, then `myfunctionname` is first defined as a new local Lua variable. When used without the `local` keyword, `myfunctionname` can be a table specifier (e.g. `a.b.c`).

<!--- If `mystruct` is a [Struct](#exotypes-structs), then `mystruct:mymethod` is equivalent to using the specifier `mystruct.methods.mymethod`. --->
Expand Down Expand Up @@ -243,9 +243,9 @@ Print out a visual representation of the code in this function. By default, this

---

r0, ..., rn = myfunc(arg0, ... argN)
r0, ..., rn = myfunction(arg0, ... argN)

Invokes `myfunctiondefinition` from Lua. Arguments are converted into the expected Terra types using the [rules](#converting-between-lua-values-and-terra-values) for converting between Terra values and Lua values. Return values are converted back into Lua values using the same rules. Causes the function to be compiled to machine code.
Invokes `myfunction` from Lua. Arguments are converted into the expected Terra types using the [rules](#converting-between-lua-values-and-terra-values) for converting between Terra values and Lua values. Return values are converted back into Lua values using the same rules. Causes the function to be compiled to machine code.

---

Expand Down Expand Up @@ -276,7 +276,7 @@ Get or set the pretty name for the function. This is useful when viewing generat

func:setinlined(bool)

When `true` function when be always inlined. When `false` the function will never be inlined. By default, functions will be inlined at the descrection of LLVM's function inliner.
When `true` function when be always inlined. When `false` the function will never be inlined. By default, functions will be inlined at the discretion of LLVM's function inliner.

Types
-----
Expand Down Expand Up @@ -313,11 +313,11 @@ Constructs a vector of `N` instances of type `typ`. `N` must be an integer and `

parameters -> returntype

Constructs a function pointer. Both `parameters` and `returns` can be lists of types (e.g. `{int,int}`) or a single type `int`. If `returntype` is a list, a `tuple` of the values in the list is the type returned from the function.
Constructs a function pointer. Both `parameters` and `returns` can be lists of types (e.g. `{int,int}`) or a single type like `int`. If `returntype` is a list, a `tuple` of the values in the list is the type returned from the function.

---

struct { field0 : type2 , ..., fieldN : typeN }
struct { field0 : type0, ..., fieldN : typeN }

Constructs a user-defined type, or exotype. Each call to `struct` creates a unique type since we use a [nominative](http://en.wikipedia.org/wiki/Nominative_type_system) type systems. See [Exotypes](#exotypes-structs) for more information.

Expand Down Expand Up @@ -401,7 +401,7 @@ True if `type` is a pointer to a struct.

---

function types.type:ispointertofunction()
type:ispointertofunction()

True if `type` is a pointer to a function.

Expand Down Expand Up @@ -462,7 +462,7 @@ Wrapper around `ffi.offsetof`. Completes the `terratype` and returns the offset
Quotes
------

Quotes are the Lua objects that get returned by terra quotation operators (backtick and `quote ... in ... end`). They rerpresent a fragment of Terra code (a statement or expression) that has not been placed into a function yet. The escape operators (`[...]` and `escape ... emit ... end`) splice quotes into the surround Terra code. Quotes have a short form for generating just one _expression_ and long form for generating _statements and expressions_.
Quotes are the Lua objects that get returned by terra quotation operators (backtick and `quote ... in ... end`). They represent a fragment of Terra code (a statement or expression) that has not been placed into a function yet. The escape operators (`[...]` and `escape ... emit ... end`) splice quotes into the surround Terra code. Quotes have a short form for generating just one _expression_ and long form for generating _statements and expressions_.

---
quotation = `terraexpr
Expand Down Expand Up @@ -1321,7 +1321,7 @@ In addition to extending the syntax of expressions, you can also define new synt
This is done by specifying the `statement` and `localstatement` functions in your language table. These function behave the same way as the `expression` function, but they can optionally return a list of names that they define. The file `test/lib/def.t` shows how this would work for the `def` constructor to support statements:

def foo(a) luaexpr --defines global variable foo
local def bar(a) luaexpr --defins local variable bar
local def bar(a) luaexpr --defines local variable bar


Higher-Level Parsing via Pratt Parsers
Expand Down Expand Up @@ -1514,12 +1514,12 @@ Intermediate Representations with Abstract Syntax Description Language

[Abstract Syntax Description Language (ASDL)](https://www.usenix.org/legacy/publications/library/proceedings/dsl97/full_papers/wang/wang.pdf) is a way of describing compiler intermediate representations (IR) and other tree- or graph-based data structures in a concise way. It is similar in many ways to algebraic data types, but offers a consistent cross-language specification. ASDL is used in the Python compiler to describe its grammer, and is also used internally in Terra to represent Terra code.

We provide a Lua library for parsing ASDL specifications that can be used to implement IR and other data-structures that are useful when building domain-specific languages. It allows you to parse ASDL specifications to create a set of Lua classes (actually specially defined meta-tables) for building IR. The library automatically sets up the classes with constructors for building the IR, and additional methods can be added to the classes using standard Lua method definitions.
We provide a Lua library for parsing ASDL specifications that can be used to implement IR and other data-structures that are useful when building domain-specific languages. It allows you to parse ASDL specifications to create a set of Lua classes (actually specially defined meta-tables) for building IR. The library automatically sets up the classes with constructors for building the IR, and additional methods can be added to the classes using standard Lua method definitions.

---

local asdl = require 'asdl'

The ASDL package comes with Terra.

---
Expand Down Expand Up @@ -1547,10 +1547,10 @@ Creating ASDL Classes
# Here the type Stm has three sub-types
Stm = Compound(Stm head, Stm next)
| Assign(string lval, Exp rval)
# '*' specifies that a field is a List object
# '*' specifies that a field is a List object
# '?' marks a field optional (may be nil as well as the type)
| Print(Exp* args, string? format)



Exp = Id(string name)
Expand All @@ -1568,14 +1568,14 @@ Types can be Lua primitives returned by `type(v)` (e.g. number table function st

External types can be used by registering a name for the type and a function that returns true for objects of that type:

Types:Extern("File",function(v)
return io.type(obj) == "file"
Types:Extern("File",function(obj)
return io.type(obj) == "file"
end)

---



Using ASDL Classes
------------------

Expand All @@ -1595,26 +1595,26 @@ Fields are initialized by the constructor:
By default classes have a string representation

print(assign) -- Assign(lval = x,rval = Num(v = 1))

And you can check for membership using :isclassof

assert(Types.Assign:isclassof(assign))
assert(Types.Stm:isclassof(assign))
assert(Types.Exp:isclassof(assign) == false)

Singletons are not classes but values:

assert(Types.BinOp:isclassof(Types.Plus))

Classes are the metatables of their values and have `Class.__index = Class`

assert(getmetatable(assign) == Types.Assign)

Tagged unions have a string field .kind that identifies which variant in the union the value is

assert(assign.kind == "Assign")


---


Expand All @@ -1631,7 +1631,7 @@ You can define additional methods on the classes to add additional behavior
end
function Types.Op:eval(env)
local op = self.op
local lhs = self.lhs:eval(env)
local lhs = self.lhs:eval(env)
local rhs = self.rhs:eval(env)
if op.kind == "Plus" then
return lhs + rhs
Expand All @@ -1650,9 +1650,9 @@ You can also define methods on the super classes which will be defined for sub-c
end

assign:foo()
WARNING: To keep the metatable structure simple, this is not implemented with chained tables Instead definitions on the superclass also copy their method to the subclass because of this design YOU MUST DEFINE PARENT METHODS BEFORE CHILD METHODS. Otherwise, the parent method will clobber the child.

WARNING: To keep the metatable structure simple, this is not implemented with chained tables. Instead definitions on the superclass also copy their method to the subclass because of this design YOU MUST DEFINE PARENT METHODS BEFORE CHILD METHODS. Otherwise, the parent method will clobber the child.

IF YOU NEED TO OVERRIDE AN ALREADY DEFINE METHOD LIKE __tostring SET IT TO NILFIRST IN THE SUPERCLASS:

Types.Stm.__tostring = nil
Expand Down Expand Up @@ -1685,7 +1685,7 @@ object is returned again. This works for types containing Lists (*) and Options
Exp = Id(string name) unique
| Num(number v) unique
}

]]
assert(Types.U.Id("foo") == Types.U.Id("foo"))

24 changes: 12 additions & 12 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Setup
Installing Terra
----------------

Terra currently runs on Mac OS X, Linux, and 64-bit Windows. Binary releases for popular versions of these systems are available [online](https://github.com/zdevito/terra/releases), and we recommend you use them if possible because building Terra requires a working install of LLVM and Clang, which can be difficult to accomplish. The binaries do not require any dependencies for most operations. For interaction with the C ecosystem, such as including C header files or creating executable and shared libraries, you need to have the right development tools installed. On OSX, you need the Xcode Command Line Tools; On Linux you need the `gcc` toolchain (`build-essential` package in Ubuntu); and for Windows you need a copy of Microsoft Visual Studio 2013 installed.
Terra currently runs on Mac OS X, Linux, and 64-bit Windows. Binary releases for popular versions of these systems are available [online](https://github.com/terralang/terra/releases), and we recommend you use them if possible because building Terra requires a working install of LLVM and Clang, which can be difficult to accomplish. The binaries do not require any dependencies for most operations. For interaction with the C ecosystem, such as including C header files or creating executable and shared libraries, you need to have the right development tools installed. On OSX, you need the Xcode Command Line Tools; On Linux you need the `gcc` toolchain (`build-essential` package in Ubuntu); and for Windows you need a copy of Microsoft Visual Studio 2013 installed.

Running Terra
-------------
Expand Down Expand Up @@ -236,7 +236,7 @@ Terra has switch statements to generate them.
else
default_thing()
end

The end on the last case may be omitted if the switch statement has an else

switch expr do
Expand All @@ -260,7 +260,7 @@ Functions
We have already seen some simple function definitions. In addition to taking multiple parameters, functions in Terra (and Lua) can return multiple values:

terra sort2(a : int, b : int) : {int,int} --the return type is optional
if a < b then
if a < b then
return a, b
else
return b, a
Expand Down Expand Up @@ -386,7 +386,7 @@ See the [API reference](api.html#function) for the full behavior.
Scoping Rules
-------------

Like any language, Terra has a set of rules for how it resolves symbos like the function name `add1` when it sees them in an expression. Because Terra code is nested inside of Lua code, these scoping rules are more complicated that a non-embedded langauge.
Like any language, Terra has a set of rules for how it resolves symbols like the function name `add1` when it sees them in an expression. Because Terra code is nested inside of Lua code, these scoping rules are more complicated than in a non-embedded language.

When the Terra compiler looks up a symbol like `add1` it first looks in the local (lexical) environment of the `terra` function. If it doesn't find the symbol, then it continues the search in the enclosing (Lua) environment using Lua's scoping rules for local/global variables. If the compiler finds a Lua value, then it converts it to a Terra value where possible. Let's look at a few examples:

Expand All @@ -403,7 +403,7 @@ When the Terra compiler looks up a symbol like `add1` it first looks in the loca

Here `N` is a Lua value of type `number`. When `powN` is defined, the value of `N` is looked up in the Lua environment and inlined into the function as an `int` literal.

Since `N` is resolved when `powN` is defined, changing `N` after `powN` is compiled will not change the behavior of `powN`.
Since `N` is resolved when `powN` is defined, changing `N` after `powN` is compiled will not change the behavior of `powN`.

Think of `terra powN(...` as a _constructor_ for a Terra function. It takes some initial values like `N` to create the and initialize the Terra function. Changing `N` after this constructor runs won't change the constructed object.

Expand Down Expand Up @@ -804,7 +804,7 @@ We've already seen examples of Lua code calling Terra functions. In general, you
assert( foo( {1,2.3} ) == 3.3)
assert( foo( {b = 1, a = 2.3} ) == 3 )

More examples are in `tests/luabridge*.t`.
More examples are in `tests/luabridge*.t`.

It is also possible to call Lua functions from Terra. Again, the translation from Terra objects to Lua uses LuaJITs conversion rules. Primitive types like `double` will be converted to their respective Lua type, while aggregate and derived types will be boxed in a LuaJIT `ctype` that can be modified from Lua:

Expand Down Expand Up @@ -921,11 +921,11 @@ This behavior is actually just syntax sugar for an escape expression. In Terra,

### Quotes ###

A quote allows you to generate a single Terra expression or statement outside of a Terra function. They are frequently used in combination with escapes to generate code. Quotes create the individual expressions and escapes are used stitch them together.
A quote allows you to generate a single Terra expression or statement outside of a Terra function. They are frequently used in combination with escapes to generate code. Quotes create the individual expressions and escapes are used to stitch them together.

function addone(a)
--return quotation that
--represents adding 1 to a
--represents adding 1 to a
return `a + 1
end
terra doit()
Expand Down Expand Up @@ -1114,7 +1114,7 @@ In general, macros are just syntax sugar for escapes where each argument to the
terra f()
var a,b = 1,2
[ foo(`a,`b,`3) ]
-- equivlent
-- equivalent
mfoo(a,b,3)
end

Expand All @@ -1127,7 +1127,7 @@ If the binary releases are not appropriate, then you can also build Terra from s

### Windows ###

For instructions on installing Terra in Windows see this [readme](https://github.com/zdevito/terra/blob/master/msvc/README.md). You will need a built copy of LLVM and Clang 3.5, as well as a copy of the LuaJIT sources.
For instructions on installing Terra in Windows see this [readme](https://github.com/terralang/terra/blob/master/msvc/README.md). You will need a built copy of LLVM and Clang 3.5, as well as a copy of the LuaJIT sources.


### Linux/OSX ###
Expand All @@ -1137,7 +1137,7 @@ The easiest way to get a working LLVM/Clang install is to download the download

Now get the Terra sources:

git clone https://github.com/zdevito/terra
git clone https://github.com/terralang/terra

To point the Terra build to the version of LLVM and Clang you downloaded, create a new file `Makefile.inc` in the `terra` source directory that points to your LLVM install by including the following contents:

Expand Down Expand Up @@ -1173,7 +1173,7 @@ A simple example initializes Terra and then runs code from the file specified in
terra_init(L);
for(int i = 1; i < argc; i++)
//run the terra code in each file
if(terra_dofile(L,argv[i]))
if(terra_dofile(L,argv[i]))
return 1; //error
return 0;
}
Expand Down

0 comments on commit cff49cb

Please sign in to comment.