/devel/p5-Module-Pluggable-Fast/

ef='/~lantw44/cgit/'>cgit logo index : dexon-solidity
DEXON fork of Solidity (https://github.com/dexon-foundation/dsolidity)
aboutsummaryrefslogtreecommitdiffstats
path: root/docs/control-structures.rst
diff options
context:
space:
mode:
authorDenton Liu <liu.denton+github@gmail.com>2016-05-24 23:36:37 +0800
committerDenton Liu <liu.denton+github@gmail.com>2016-05-30 21:42:30 +0800
commit80600a5a42f6da105fb85be6386c8759f7ccb275 (patch)
treee6d168ee16ce674e0311390ef80de8bab7b4c8de /docs/control-structures.rst
parentc8e4ba4b52a16f77b2f3c16df2ea344a3f5ff5c3 (diff)
downloaddexon-solidity-80600a5a42f6da105fb85be6386c8759f7ccb275.tar.gz
dexon-solidity-80600a5a42f6da105fb85be6386c8759f7ccb275.tar.zst
dexon-solidity-80600a5a42f6da105fb85be6386c8759f7ccb275.zip
Modified control-structures.rst
Changed inline code syntax
Diffstat (limited to 'docs/control-structures.rst')
-rw-r--r--docs/control-structures.rst92
1 files changed, 46 insertions, 46 deletions
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 4b2363f5..4081f013 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -8,15 +8,15 @@ Control Structures
===================
Most of the control structures from C/JavaScript are available in Solidity
-except for `switch` and `goto`. So
-there is: `if`, `else`, `while`, `for`, `break`, `continue`, `return`, `? :`, with
+except for :code:`switch` and :code:`goto`. So
+there is: :code:`if`, :code:`else`, :code:`while`, :code:`for`, :code:`break`, :code:`continue`, :code:`return`, :code:`? :`, with
the usual semantics known from C / JavaScript.
Parentheses can *not* be omitted for conditionals, but curly brances can be omitted
around single-statement bodies.
Note that there is no type conversion from non-boolean to boolean types as
-there is in C and JavaScript, so `if (1) { ... }` is *not* valid Solidity.
+there is in C and JavaScript, so :code:`if (1) { ... }` is *not* valid Solidity.
.. index:: ! function;call, function;internal, function;external
@@ -44,7 +44,7 @@ contract can be called internally.
External Function Calls
-----------------------
-The expression `this.g(8);` is also a valid function call, but this time, the function
+The expression :code:`this.g(8);` is also a valid function call, but this time, the function
will be called "externally", via a message call and not directly via jumps.
Functions of other contracts have to be called externally. For an external call,
all function arguments have to be copied to memory.
@@ -63,9 +63,9 @@ of other contracts, the amount of Wei sent with the call and the gas can be spec
function callFeed() { feed.info.value(10).gas(800)(); }
}
-Note that the expression `InfoFeed(addr)` performs an explicit type conversion stating
-that "we know that the type of the contract at the given address is `InfoFeed`" and
-this does not execute a constructor. We could also have used `function setFeed(InfoFeed _feed) { feed = _feed; }` directly. Be careful about the fact that `feed.info.value(10).gas(800)`
+Note that the expression :code:`InfoFeed(addr)` performs an explicit type conversion stating
+that "we know that the type of the contract at the given address is :code:`InfoFeed`" and
+this does not execute a constructor. We could also have used :code:`function setFeed(InfoFeed _feed) { feed = _feed; }` directly. Be careful about the fact that :code:`feed.info.value(10).gas(800)`
only (locally) sets the value and amount of gas sent with the function call and only the
parentheses at the end perform the actual call.
@@ -144,7 +144,7 @@ Complications for Arrays and Structs
------------------------------------
The semantics of assignment are a bit more complicated for non-value types like arrays and structs.
-Assigning *to* a state variable always creates an independent copy. On the other hand, assigning to a local variable creates an independent copy only for elementary types, i.e. static types that fit into 32 bytes. If structs or arrays (including `bytes` and `string`) are assigned from a state variable to a local variable, the local variable holds a reference to the original state variable. A second assignment to the local variable does not modify the state but only changes the reference. Assignments to members (or elements) of the local variable *do* change the state.
+Assigning *to* a state variable always creates an independent copy. On the other hand, assigning to a local variable creates an independent copy only for elementary types, i.e. static types that fit into 32 bytes. If structs or arrays (including :code:`bytes` and :code:`string`) are assigned from a state variable to a local variable, the local variable holds a reference to the original state variable. A second assignment to the local variable does not modify the state but only changes the reference. Assignments to members (or elements) of the local variable *do* change the state.
.. index:: ! exception, ! throw
@@ -156,7 +156,7 @@ Scoping and Declarations
In Solidity, a variable declared anywhere within a function will be in scope for the *entire function*, regardless of where it is declared.
This happens because Solidity inherits its scoping rules from JavaScript.
This is in contrast to many languages where variables are only scoped where they are declared until the end of the semantic block.
-As a result, the following code is illegal and cause the compiler to throw an error, `Identifier already declared`::
+As a result, the following code is illegal and cause the compiler to throw an error, :code:`Identifier already declared`::
contract ScopingErrors {
function scoping() {
@@ -208,11 +208,11 @@ As a result, the following code is legal, despite being poorly written::
Exceptions
==========
-There are some cases where exceptions are thrown automatically (see below). You can use the `throw` instruction to throw an exception manually. The effect of an exception is that the currently executing call is stopped and reverted (i.e. all changes to the state and balances are undone) and the exception is also "bubbled up" through Solidity function calls (exceptions are `send` and the low-level functions `call`, `delegatecall` and `callcode`, those return `false` in case of an exception).
+There are some cases where exceptions are thrown automatically (see below). You can use the :code:`throw` instruction to throw an exception manually. The effect of an exception is that the currently executing call is stopped and reverted (i.e. all changes to the state and balances are undone) and the exception is also "bubbled up" through Solidity function calls (exceptions are :code:`send` and the low-level functions :code:`call`, :code:`delegatecall` and :code:`callcode`, those return :code:`false` in case of an exception).
Catching exceptions is not yet possible.
-In the following example, we show how `throw` can be used to easily revert an Ether transfer and also how to check the return value of `send`::
+In the following example, we show how :code:`throw` can be used to easily revert an Ether transfer and also how to check the return value of :code:`send`::
contract Sharer {
function sendHalf(address addr) returns (uint balance) {
@@ -224,7 +224,7 @@ In the following example, we show how `throw` can be used to easily revert an Et
Currently, there are three situations, where exceptions happen automatically in Solidity:
-1. If you access an array beyond its length (i.e. `x[i]` where `i >= x.length`)
+1. If you access an array beyond its length (i.e. :code:`x[i]` where :code:`i >= x.length`)
2. If a function called via a message call does not finish properly (i.e. it runs out of gas or throws an exception itself).
3. If a non-existent function on a library is called or Ether is sent to a library.
@@ -242,10 +242,10 @@ often hard to address the correct stack slot and provide arguments to opcodes at
point on the stack. Solidity's inline assembly tries to facilitate that and other issues
arising when writing manual assembly by the following features:
-* functional-style opcodes: `mul(1, add(2, 3))` instead of `push1 3 push1 2 add push1 1 mul`
-* assembly-local variables: `let x := add(2, 3) let y := mload(0x40) x := add(x, y)`
-* access to external variables: `function f(uint x) { assembly { x := sub(x, 1) } }`
-* labels: `let x := 10 repeat: x := sub(x, 1) jumpi(repeat, eq(x, 0))`
+* functional-style opcodes: :code:`mul(1, add(2, 3))` instead of :code:`push1 3 push1 2 add push1 1 mul`
+* assembly-local variables: :code:`let x := add(2, 3) let y := mload(0x40) x := add(x, y)`
+* access to external variables: :code:`function f(uint x) { assembly { x := sub(x, 1) } }`
+* labels: :code:`let x := 10 repeat: x := sub(x, 1) jumpi(repeat, eq(x, 0))`
We now want to describe the inline assembly language in detail.
@@ -257,7 +257,7 @@ Example
-------
The following example provides library code to access the code of another contract and
-load it into a `bytes` variable. This is not possible at all with "plain Solidity" and the
+load it into a :code:`bytes` variable. This is not possible at all with "plain Solidity" and the
idea is that assembly libraries will be used to enhance the language in such ways.
.. code::
@@ -311,18 +311,18 @@ Syntax
------
Inline assembly parses comments, literals and identifiers exactly as Solidity, so you can use the
-usual `//` and `/* */` comments. Inline assembly is initiated by `assembly { ... }` and inside
+usual :code:`//` and :code:`/* */` comments. Inline assembly is initiated by :code:`assembly { ... }` and inside
these curly braces, the following can be used (see the later sections for more details)
- - literals, i.e. `0x123`, `42` or `"abc"` (strings up to 32 characters)
- - opcodes (in "instruction style"), e.g. `mload sload dup1 sstore`, for a list see below
- - opcode in functional style, e.g. `add(1, mlod(0))`
- - labels, e.g. `name:`
- - variable declarations, e.g. `let x := 7` or `let x := add(y, 3)`
- - identifiers (externals, labels or assembly-local variables), e.g. `jump(name)`, `3 x add`
- - assignments (in "instruction style"), e.g. `3 =: x`
- - assignments in functional style, e.g. `x := add(y, 3)`
- - blocks where local variables are scoped inside, e.g. `{ let x := 3 { let y := add(x, 1) } }`
+ - literals, i.e. :code:`0x123`, :