Merge remote-tracking branch 'origin/dev' into rinderknecht-dev

This commit is contained in:
Christian Rinderknecht 2019-08-29 17:27:36 +02:00
commit 4b4698d1f0
40 changed files with 252 additions and 81 deletions

View File

@ -4,6 +4,11 @@
The website will be available at [http://localhost:3000](http://localhost:3000)
```zsh
To get the website running you want to do the commands:
```
cd website
npm run version next
cd ..
docker-compose up
```

View File

@ -16,6 +16,7 @@ title: Cheat Sheet
|Natural numbers | `42n`, `7n`|
|Unit| `unit`|
|Boolean|<pre><code>const hasDriversLicense: bool = False;<br/>const adult: bool = True;</code></pre> |
|Boolean Logic|<pre><code>(not True) == False == (False and True) == (False or False)</code></pre>|
|Mutez (micro tez)| `42mtz`, `7mtz` |
|Address | `"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"`, `"KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"`|
|Addition |`3 + 4`, `3n + 4n`|
@ -26,16 +27,18 @@ title: Cheat Sheet
|Includes|```#include "library.ligo"```|
|Functions (short form)|<pre><code>function add (const a : int ; const b : int) : int is<br/>&nbsp;&nbsp;block { skip } with a + b</code></pre>|
|Functions (long form)|<pre><code>function add (const a : int ; const b : int) : int is<br/>&nbsp;&nbsp;block { <br/>&nbsp;&nbsp;&nbsp;&nbsp;const result: int = a + b;<br/>&nbsp;&nbsp;} with result</code></pre>|
| If Statement | <pre><code>if age < 16 <br/>then fail("Too young to drive."); <br/>else const new_id: int = prev_id + 1;</code></pre>|
|Options|<pre><code>type middleName is option(string);<br/>const middleName : middleName = Some("Foo");<br/>const middleName : middleName = None;</code></pre>|
|Assignment| ```const age: int = 5;```|
|Assignment on an existing variable <br/></br>*⚠️ This feature is not supported at the top-level scope, you can use it e.g. within functions. Works for Records and Maps as well.*| ```age := 18;```, ```p.age := 21``` |
|Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```|
|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```|
|Variants|<pre><code>type action is<br/>&#124; Increment of int<br/>&#124; Decrement of int</code></pre>|
|Variant *(pattern)* matching|<pre><code>const a: action = Increment(5);<br/>case a of<br/>&#124; Increment(n) -> n + 1<br/>&#124; Decrement(n) -> n - 1<br/>end</code></pre>|
|Records|<pre><code>type person is record<br/>&nbsp;&nbsp;age: int ;<br/>&nbsp;&nbsp;name: string ;<br/>end<br/><br/>const john : person = record<br/>&nbsp;&nbsp;age = 18;<br/>&nbsp;&nbsp;name = "John Doe";<br/>end<br/><br/>const name: string = john.name;</code></pre>|
|Maps|<pre><code>type prices is map(nat, tez);<br/><br/>const prices : prices = map<br/>&nbsp;&nbsp;10n -> 60mtz;<br/>&nbsp;&nbsp;50n -> 30mtz;<br/>&nbsp;&nbsp;100n -> 10mtz;<br/>end<br/><br/>const price: option(tez) = prices[50n];</code></pre>|
|Maps|<pre><code>type prices is map(nat, tez);<br/><br/>const prices : prices = map<br/>&nbsp;&nbsp;10n -> 60mtz;<br/>&nbsp;&nbsp;50n -> 30mtz;<br/>&nbsp;&nbsp;100n -> 10mtz;<br/>end<br/><br/>const price: option(tez) = prices[50n];<br/><br/>prices[200n] := 5mtz;</code></pre>|
|Contracts & Accounts|<pre><code>const destinationAddress : address = "tz1...";<br/>const contract : contract(unit) = get_contract(destinationAddress);</code></pre>|
|Transactions|<pre><code>const payment : operation = transaction(unit, amount, receiver);</code></pre>|
|Exception/Failure|`fail("Your descriptive error message for the user goes here.")`|
<!--END_DOCUSAURUS_CODE_TABS-->

View File

@ -11,4 +11,5 @@ title: Operators
|--- |--- |--- |
| `SENDER` | `sender` | Address that initiated the current transaction
| `SOURCE` | `source` | Address that initiated the transaction, which triggered the current transaction. (useful e.g. when there's a transaction sent by another contract)
| `AMOUNT` | `amount` | Amount of tez sent by the transaction that invoked the contract
| `AMOUNT` | `amount` | Amount of tez sent by the transaction that invoked the contract
| `NOW` | `now` | Timestamp of the block whose validation triggered execution of the contract, i.e. current time when the contract is run.

View File

@ -3,14 +3,19 @@ id: installation
title: Installation
---
There are currently two ways to get started with Ligo, both of those will allow you to use the Ligo CLI with your contracts. You can choose to use either the Docker image, or to compile & build the Ligo CLI yourself.
There are currently two ways to get started with Ligo, both of those will allow you to use the Ligo CLI with your contracts. You can choose to use either a Docker image, or to compile & build the Ligo CLI yourself.
## Dockerized installation (recommended)
> 🐳 You can find instructions on how to install Docker [here](https://docs.docker.com/install/).
Easiest way to use LIGO is through the Docker image available at [Docker Hub](https://hub.docker.com/r/ligolang/ligo). Sources for the image can be found on [Gitlab](https://gitlab.com/ligolang/ligo/blob/dev/docker/Dockerfile).
You can either run the docker image yourself, or you can setup a global ligo executable as shown below.
It's easiest to use LIGO through one of its Docker images. You have two options,
the first is to use our installation script to set up a globally available LIGO
executable (see below). This manages the Docker bits for you. The second
is to directly use the Docker image available at [Docker Hub](https://hub.docker.com/r/ligolang/ligo).
This lets you run multiple versions and keep your installation(s) self contained, but requires more familiarity with Docker.
Sources for the image can be found on [Gitlab](https://gitlab.com/ligolang/ligo/blob/master/docker/Dockerfile).
If this is your first time using Docker, you probably want to set up a global ligo executable as shown below.
### Setting up a globally available `ligo` executable

View File

@ -59,6 +59,8 @@ current_purchase_price = max_price / available_stock
In this tutorial, we'll use LIGO's dockerized version for the sake of simplicity. You can find the installation instructions [here](setup/installation.md#dockerized-installation-recommended).
The best way to install the dockerized LIGO is as a **global executable** through the installation script, as shown in the screenshot below:
<img src="/img/tutorials/get-started/tezos-taco-shop-smart-contract/install-ligo.png" />
<div style="opacity: 0.7; text-align: center; font-size: 12px; margin-top:-24px;">Installing the <b>next</b> version of LIGO's CLI</div>

View File

@ -95,7 +95,7 @@ We are looking to develop a Super Type System that has the following features:
The current version explicitly excludes non-essential features which can produce unexpected explosions in gas costs. To alleviate this constraint, we plan to integrate gas benchmarks on all top-level declarations with some fuzzing. This will allow developers and users to estimate the cost of their contracts in real time.
## Getting Started and Contact
Come visit [our website](ligolang.org)! You can also join our [Discord](https://discord.gg/CmTwFM), Riot (*#ligo-public:matrix.org*) or Telegram Chat (Ligo Public channel).
Come visit [our website](https://ligolang.org)! You can also join our [Discord](https://discord.gg/9rhYaEt), Riot (*#ligo-public:matrix.org*) or Telegram Chat (Ligo Public channel).

View File

@ -96,7 +96,7 @@ class HomeSplash extends React.Component {
<ProjectTitle siteConfig={siteConfig} />
<PromoSection>
<Button href={docUrl('setup/installation.html')}>Get Started</Button>
<Button href={docUrl('tutorials/get-started/tezos-taco-shop-smart-contract.html')}>Tutorials</Button>
<Button href={docUrl('tutorials/get-started/tezos-taco-shop-smart-contract')}>Tutorials</Button>
<Button href={docUrl('contributors/origin.html')}>Contribute</Button>
</PromoSection>
</div>

View File

@ -0,0 +1 @@
udfg-WYEzK3rTbfS71zFI7HOr3AvRoa9KMuzObp9wTs.4Dc00ftieGaWDmacztwSS7euFOKPULDHjUNzikwPvao

Binary file not shown.

25
makefile Normal file
View File

@ -0,0 +1,25 @@
# Use install-deps instead of 'install' because usually 'make install' adds a
# binary to the system path and we don't want to confuse users
install-deps:
# Install ligo/tezos specific system-level dependencies
sudo scripts/install_native_dependencies.sh
build-deps:
# Create opam dev switch locally for use with Ligo, add merlin/etc
if [ -n "`opam switch show | grep -P ".+/ligo"`" ];
then exit; else scripts/setup_dev_switch.sh;
fi
# Set up the local ligo opam repository so that it can be built
if [ -n "`opam repo list --safe | grep -P "ligo-opam-repository"`" ];
then exit; else scripts/setup_ligo_opam_repository.sh;
fi
# Install OCaml build dependencies for Ligo
scripts/install_ligo_with_dependencies.sh
build: build-deps
# Build Ligo for local dev use
scripts/build_ligo_local.sh
.ONESHELL:
test: build
scripts/test_ligo.sh

View File

@ -18,6 +18,7 @@ depends: [
"proto-alpha-utils"
"yojson"
"alcotest" { with-test }
"getopt"
]
build: [
[ "dune" "build" "-p" name "-j" jobs ]

2
repo
View File

@ -1,3 +1,3 @@
opam-version: "2.0"
archive-mirrors: "cache"
stamp: "a989886f"
stamp: "b4649b8f"

2
scripts/build_ligo_local.sh Executable file
View File

@ -0,0 +1,2 @@
eval $(opam env)
dune build -p ligo

View File

@ -0,0 +1,64 @@
# This script installs opam for the user. It should NOT be included in any makefiles/etc.
if [ -n "`which opam`" ]
then
if [ -n "`opam --version | grep -P "2\..\.."`" ]
then
echo "Opam 2.x seems to already exist, exiting..."
exit 1
else
read -p "This script will upgrade opam to the 2.x series, are you okay with that? (y/n)" choice1
case "$choice1" in
y|Y ) : ;;
n|N ) exit ;;
esac
fi
fi
sudo apt-get install -y make \
m4 \
gcc \
patch \
bubblewrap \
rsync \
curl \
if [ -n "`uname -a | grep -i ubuntu`" ]
then
sudo add-apt-repository -y ppa:avsm/ppa
sudo apt-get update
sudo apt-get install opam
else
# I'm going to assume here that we're on x86_64, 32-bit users should be basically
# extinct at this point right?
curl -L https://github.com/ocaml/opam/releases/download/2.0.4/opam-2.0.4-x86_64-linux \
--output opam_temp_version_2_0_4.bin
if [ "`openssl sha256 -r opam_temp_version_2_0_4.bin`" = "373e34f92f282273d482537f8103caad0d17b6f2699ff504bed77f474cb0c951 *opam_temp_version_2_0_4.bin" ]
then
# Stay paranoid, in case other checks fail don't want to overrwrite
# user's opam on accident
chmod +x opam_temp_version_2_0_4.bin # Set execute so we can get version
if [ -e /usr/local/bin/opam ]
then
opam_old_v=`/usr/local/bin/opam --version`
opam_new_v=`opam_temp_version_2_0_4.bin --version`
read -p "This will overrwrite the opam you have in /usr/local/bin (version $opam_old_v) with version $opam_new_v, do you actually want to do that? Type yes. (yes/n)" choice2
else
choice2="yes"
fi
if [ $choice2 = "yes" ]
then
sudo mv opam_temp_version_2_0_4.bin /usr/local/bin/opam
else
rm opam_temp_version_2_0_4.bin
exit
fi
else
echo "opam file hash doesn't match what was recorded at time of signature verification!"
echo "(If you actually get this message, you should probably file an issue)"
echo "https://gitlab.com/ligolang/ligo/issues"
exit 1
fi
fi
opam init -a --bare

4
scripts/setup_dev_switch.sh Executable file
View File

@ -0,0 +1,4 @@
opam switch create . ocaml-base-compiler.4.06.1
eval $(opam env)
opam install -y ocp-indent tuareg merlin alcotest-lwt crowbar
opam -y user-setup install

2
scripts/test_ligo.sh Executable file
View File

@ -0,0 +1,2 @@
eval $(opam env)
dune build @ligo-test

View File

@ -17,6 +17,7 @@ depends: [
"proto-alpha-utils"
"yojson"
"alcotest" { with-test }
"getopt"
]
build: [
[ "dune" "build" "-p" name "-j" jobs ]

View File

@ -21,7 +21,7 @@
(rule
(targets parser.ml parser.mli)
(deps parser_generated.mly ast.ml)
(action (system "menhir --explain --external-tokens Lex.Token lex/token.mly parser_generated.mly --base parser"))
(action (system "menhir --explain --unused-tokens --external-tokens Lex.Token lex/token.mly parser_generated.mly --base parser"))
)
(rule

View File

@ -4,6 +4,7 @@
(libraries
simple-utils
tezos-utils
parser_shared
parser_pascaligo
parser_camligo
parser_ligodity
@ -11,5 +12,5 @@
(preprocess
(pps simple-utils.ppx_let_generalized)
)
(flags (:standard -w +1..62-4-9-44-40-42-48-30@39@33 -open Simple_utils ))
(flags (:standard -w +1..62-4-9-44-40-42-48-30@39@33 -open Simple_utils -open Parser_shared ))
)

View File

@ -15,6 +15,7 @@
zarith
simple-utils
tezos-utils
getopt
)
(flags (:standard -open Simple_utils ))
)

View File

@ -4,4 +4,18 @@ $HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.mli
$HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.ml
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.mli
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml
$HOME/git/ligo/src/parser/shared/Lexer.mli
$HOME/git/ligo/src/parser/shared/Lexer.mll
$HOME/git/ligo/src/parser/shared/Error.mli
$HOME/git/ligo/src/parser/shared/EvalOpt.ml
$HOME/git/ligo/src/parser/shared/EvalOpt.mli
$HOME/git/ligo/src/parser/shared/FQueue.ml
$HOME/git/ligo/src/parser/shared/FQueue.mli
$HOME/git/ligo/src/parser/shared/LexerLog.mli
$HOME/git/ligo/src/parser/shared/LexerLog.ml
$HOME/git/ligo/src/parser/shared/Markup.ml
$HOME/git/ligo/src/parser/shared/Markup.mli
$HOME/git/ligo/src/parser/shared/Utils.mli
$HOME/git/ligo/src/parser/shared/Utils.ml
$HOME/git/ligo/src/parser/shared/Version.ml
Stubs/Simple_utils.ml

View File

@ -11,10 +11,6 @@ The directory contains the following:
Tests
The directory containing tests.
Version.ml
A source containing a commit hash. It should be deleted, as Dune
knows how to generate and updated version.
dune
The Dune file for building the Pascaligo parser.
@ -46,11 +42,6 @@ The directory contains the following:
build only a standalone lexer or a standalone parser. Do not
change, unless you change EvalOpt and use Christian's build system.
LexerLog.ml
LexerLog.mli
Source for instantiating a standalone lexer for LexerMain.ml and
ParserMain.ml. Ignore them.
ParserLog.mli
ParserLog.ml
Source for printing the AST. Used by ParserMain.ml, pascaligo.ml
@ -65,51 +56,6 @@ The directory contains the following:
AST.ml
The abstract syntax tree of Pascaligo.
EvalOpt.mli
EvalOpt.ml
The module EvalOpt parses the command-line for options to the
parser. That action is performed as a side-effect when the module
is initialised at run-time: this is ugly and easy to fix. See
ligo/src/parser/ligodity/EvalOpt.ml{i} for the right way to do
it. Ignore them: the file actually calling directly the parser is
ligo/src/parser/parser.ml. Note that, as a consequence, no option
is currently passed to the parser when building Pascaligo with
Dune. This should be made available.
Markup.mli
Markup.ml
The definition of markup in Pascaligo source files, and some some
functions to print or convert it to strings. You are unlikely
going to modify those files, as markup is pretty much the same for
all LIGO flavours.
FQueue.mli
FQueue.ml
A naive implementation of purely functional queues. Replace by an
imperative implementation if worst-case performance of single
operations (queue/enqueue) is an issue.
Error.mli
The definition of the open type for errors: the lexer will add its
own errors, the downside being that matching on errors requires a
catch-all clause "| _ -> assert false" at the end. Note: the rest
of the compiler uses an error monad.
Lexer.mli
Lexer.mll
The Pascaligo lexer is generated from two ocamllex
specifications. Lexer.mll is the first-level lexer. It exports a
functor [Make] parameterised over a module [Token] defining the
tokens, and returning a module whose signature is [Lexer.S]. (See
Lexer.mli for a rationale.) If you write a new flavour of LIGO,
this lexer is likely to be reused as is. Note that a great deal of
the complexity of this lexer stems from its purpose to report
stylistic errors (hence keeping temporarily scanned markup) and
handling UTF-8 encoded comments. The first goal implies sometimes
reading more than one token, and an extra-buffer has to be managed
above the ocamllex one, so the parser is not confused about the
location (region) of the token it has just read.
LexToken.mli
LexToken.mll
The second-level lexer of Pascaligo, scanning the (lexical)

View File

@ -1,5 +1,4 @@
(ocamllex LexToken)
(ocamllex Lexer)
(menhir
(merge_into Parser)
@ -9,17 +8,27 @@
(library
(name parser_pascaligo)
(public_name ligo.parser.pascaligo)
(modules AST FQueue Markup pascaligo Utils Version Lexer Error Parser ParserLog LexToken)
(modules_without_implementation Error)
(modules AST pascaligo Parser ParserLog LexToken)
(libraries
hex
str
uutf
zarith
parser_shared
hex
simple-utils
tezos-utils
)
(flags (:standard -open Simple_utils ))
(flags (:standard -open Parser_shared -open Simple_utils))
)
(executable
(name LexerMain)
(libraries
hex
simple-utils
tezos-utils
parser_pascaligo)
(modules
LexerMain
)
(flags (:standard -open Parser_shared -open Parser_pascaligo))
)
;; Les deux directives (rule) qui suivent sont pour le dev local.
@ -36,9 +45,3 @@
; (deps LexerMain.exe)
; (action (copy LexerMain.exe Lexer.exe))
; (mode promote-until-clean))
(rule
(targets Version.ml)
(action
(progn (run "sh" "-c" "printf 'let version = \"%s\"'\\\\n \"$(echo UNKNOWN)\" > Version.ml")))
(mode promote-until-clean))

7
src/parser/shared/.links Normal file
View File

@ -0,0 +1,7 @@
$HOME/git/OCaml-build/Makefile
$HOME/git/OCaml-build/Makefile.cfg
$HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.mli
$HOME/git/ligo/vendors/ligo-utils/simple-utils/pos.ml
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.mli
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml
$HOME/git/ligo/vendors/ligo-utils/simple-utils/region.ml

View File

@ -0,0 +1,55 @@
INTERNAL DOCUMENTATION OF THE SHARED PARSER FUNCTIONALITY
Version.ml
A source containing a commit hash. It should be deleted, as Dune
knows how to generate and updated version.
EvalOpt.mli
EvalOpt.ml
The module EvalOpt parses the command-line for options to the
parser. That action is performed as a side-effect when the module
is initialised at run-time: this is ugly and easy to fix. See
ligo/src/parser/ligodity/EvalOpt.ml{i} for the right way to do
it. Ignore them: the file actually calling directly the parser is
ligo/src/parser/parser.ml. Note that, as a consequence, no option
is currently passed to the parser when building Pascaligo with
Dune. This should be made available.
Markup.mli
Markup.ml
The definition of markup in source files, and some functions to
print or convert it to strings. You are unlikely going to modify
those files, as markup is pretty much the same for all LIGO
flavours.
FQueue.mli
FQueue.ml
A naive implementation of purely functional queues. Replace by an
imperative implementation if worst-case performance of single
operations (queue/enqueue) is an issue.
Error.mli
The definition of the open type for errors: the lexer will add its
own errors, the downside being that matching on errors requires a
catch-all clause "| _ -> assert false" at the end. Note: the rest
of the compiler uses an error monad.
Lexer.mli
Lexer.mll
The Pascaligo lexer is generated from two ocamllex
specifications. Lexer.mll is the first-level lexer. It exports a
functor [Make] parameterised over a module [Token] defining the
tokens, and returning a module whose signature is [Lexer.S]. (See
Lexer.mli for a rationale.) If you write a new flavour of LIGO,
this lexer is likely to be reused as is. Note that a great deal of
the complexity of this lexer stems from its purpose to report
stylistic errors (hence keeping temporarily scanned markup) and
handling UTF-8 encoded comments. The first goal implies sometimes
reading more than one token, and an extra-buffer has to be managed
above the ocamllex one, so the parser is not confused about the
location (region) of the token it has just read.
LexerLog.ml
LexerLog.mli
Source for instantiating a standalone lexer for LexerMain.ml and
ParserMain.ml. Ignore them.

28
src/parser/shared/dune Normal file
View File

@ -0,0 +1,28 @@
(ocamllex Lexer)
(library
(name parser_shared)
(public_name ligo.parser.shared)
(libraries
simple-utils
uutf
getopt
)
(modules
Error
Lexer
LexerLog
Utils
Markup
FQueue
EvalOpt
Version
)
(modules_without_implementation Error)
)
(rule
(targets Version.ml)
(action
(progn (run "sh" "-c" "printf 'let version = \"%s\"'\\\\n \"$(echo UNKNOWN)\" > Version.ml")))
(mode promote-until-clean))

View File

@ -1 +1 @@
repo 604d7d8c5eb209596f929225538c2c3c 420
repo f9ec38c6d4dfb4ef9f64edb361326b32 420