Skip to content

Commit 3b18b02

Browse files
committed
[[ UnsafeAttrib ]] Add unsafe handlers and unsafe blocks
This patch adds the idea of unsafe handlers and unsafe blocks to LCB. An unsafe handler can be declared by using the 'unsafe' keyword: unsafe handler Foo() end handler An unsafe statement block can be written as: unsafe ... do unsafe things ... end unsafe Calls to unsafe handlers, foreign handlers and usage of bytecode blocks can only occur within either an unsafe handler, or unsafe block.
1 parent 0177099 commit 3b18b02

28 files changed

Lines changed: 715 additions & 245 deletions

File tree

docs/guides/LiveCode Builder Language Reference.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ a value.
334334
### Handlers
335335

336336
HandlerDefinition
337-
: 'handler' <Name: Identifier> '(' [ ParameterList ] ')' [ 'returns' <ReturnType: Type> ] SEPARATOR
337+
: [ 'unsafe' ] 'handler' <Name: Identifier> '(' [ ParameterList ] ')' [ 'returns' <ReturnType: Type> ] SEPARATOR
338338
{ Statement }
339339
'end' 'handler'
340340

@@ -383,6 +383,10 @@ to be *optional any* meaning it can be of any type.
383383
> inout or out parameters. It is a checked compile-time error to pass a
384384
> non-assignable expression to such a parameter.
385385
386+
If 'unsafe' is specified for the handler, then the handler itself is considered
387+
to be unsafe, and may only be called from other unsafe handlers or unsafe
388+
statement blocks.
389+
386390
### Foreign Handlers
387391

388392
ForeignHandlerDefinition
@@ -476,6 +480,10 @@ non-Windows platform then it is taken to be 'default'.
476480
Foreign handler's bound symbols are resolved on first use and an error
477481
is thrown if the symbol cannot be found.
478482

483+
Foreign handlers are always considered unsafe, and thus may only be called
484+
from unsafe context - i.e. from within an unsafe handler, or unsafe statement
485+
block.
486+
479487
> **Note:** The current foreign handler definition is an initial
480488
> version, mainly existing to allow binding to implementation of the
481489
> syntax present in the standard language modules. It will be expanded
@@ -529,6 +537,7 @@ environment.
529537
| GetStatement
530538
| CallStatement
531539
| BytecodeStatement
540+
| UnsafeStatement
532541

533542
There are a number of built-in statements which define control flow,
534543
variables, and basic variable transfer. The remaining syntax for
@@ -760,9 +769,25 @@ Register definitions define a named register which is local to the current
760769
bytecode block. Registers are the same as handler-local variables except
761770
that they do not undergo default initialization.
762771

772+
Bytecode statements are considered to be unsafe and can only appear inside
773+
unsafe handlers or unsafe statement blocks.
774+
763775
> **Note:** Bytecode blocks are not intended for general use and the actual
764776
> available operations are subject to change.
765777
778+
### Unsafe Statements
779+
780+
UnsafeStatement
781+
: 'unsafe' SEPARATOR
782+
{ Statement }
783+
'end' 'unsafe'
784+
785+
The unsafe statement allows a block of unsafe code to be written in a safe
786+
context.
787+
788+
In particular, calls to unsafe handlers (including all foreign handlers) and
789+
bytecode blocks are allowed in unsafe statement blocks but nowhere else.
790+
766791
## Expressions
767792

768793
Expression
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# LiveCode Builder Language
2+
## Unsafe Attributes
3+
4+
* The compiler now understands the idea of 'safety' of handlers and blocks of
5+
code.
6+
7+
* Handlers can be marked as being 'unsafe', e.g.
8+
9+
unsafe handler Foo()
10+
... do unsafe things ...
11+
end handler
12+
13+
* Blocks of statements can be marked as being 'unsafe', e.g.
14+
15+
unsafe
16+
... do unsafe things ...
17+
end unsafe
18+
19+
* All foreign handlers are considered to be 'unsafe'.
20+
21+
* All bytecode blocks are considered to be 'unsafe'.
22+
23+
* Calls to foreign handlers and unsafe handlers can only be made within unsafe
24+
handlers or unsafe statement blocks.
25+
26+
* Usage of bytecode blocks can only be made within unsafe handlers or unsafe
27+
statement blocks.

0 commit comments

Comments
 (0)