Skip to content

Commit b446fce

Browse files
add MEMORY to CHAIN
1 parent 2f7bc6c commit b446fce

97 files changed

Lines changed: 394 additions & 340 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
\page CHAIN CHAIN Keyword
2+
23
```basic
3-
CHAIN string-expression[,boolean-expression]
4+
CHAIN string-expression[,boolean-expression] [MEMORY SMALL|MEDIUM|LARGE|HUGE]
45
```
56

6-
Starts a new BASIC program, pausing the current program until the new one finishes.
7+
Starts a new BASIC program, pausing the current program until the new one finishes.
78
The string expression must evaluate to the **filename** of a program accessible from the filesystem.
89

9-
- Any variables marked as \ref GLOBAL "GLOBAL" will be shared with the child program.
10-
- When the chained program terminates, control returns to the line immediately following the `CHAIN` statement in the calling program.
11-
- Variables not marked as global are not visible to the chained program.
12-
- If the optional boolean expression is included and evaluates to true, the program will be launched as a task in the background and the caller will resume immediately.
10+
* Any variables marked as \ref GLOBAL "GLOBAL" will be shared with the child program.
11+
* When the chained program terminates, control returns to the line immediately following the `CHAIN` statement in the calling program.
12+
* Variables not marked as global are not visible to the chained program.
13+
* If the optional boolean expression is included and evaluates to true, the program will be launched as a task in the background and the caller will resume immediately.
14+
* The optional `MEMORY` clause selects the memory model used by the new program.
15+
16+
---
17+
18+
##### Memory Models
19+
20+
The `MEMORY` option controls the size of the allocator used by the child program:
21+
22+
* `SMALL` — up to 32 MiB per allocation
23+
* `MEDIUM` — up to 64 MiB per allocation *(default)*
24+
* `LARGE` — up to 128 MiB per allocation
25+
* `HUGE` — up to 256 MiB per allocation
1326

27+
If not specified, the child program uses the **same memory model as the caller**, or `MEDIUM` if no parent model applies.
28+
29+
If the requested memory model cannot be allocated, the `CHAIN` will fail with an out-of-memory error.
30+
31+
\remark The memory model does not limit the total memory a program may use.It limits the size of any single contiguous allocation (for example, a string or buffer), and programs may use more memory overall but individual allocations cannot exceed the selected model.
32+
33+
---
1434

1535
\remark `CHAIN` resolves relative paths from the **current working directory**.
1636
\remark Use absolute paths (e.g. `/programs/login`) if you don’t want this to depend on `CHDIR`.
1737

1838
---
1939

20-
##### Example
40+
##### Examples
2141

2242
```basic
2343
PRINT "Before chain"
@@ -26,16 +46,30 @@ CHAIN "childprog"
2646
PRINT "Back again, X = "; X
2747
```
2848

29-
If `childprog` uses the global variable `X`, it will see the value `42`.
30-
After `childprog` ends, execution resumes.
49+
```basic
50+
CHAIN "worker", TRUE MEMORY SMALL
51+
```
52+
53+
```basic
54+
CHAIN "bigdata" MEMORY LARGE
55+
```
56+
57+
```basic
58+
CHAIN "analysis" MEMORY HUGE
59+
```
3160

3261
---
3362

3463
##### Notes
35-
- Chained programs run in a **new interpreter instance** within a new process. The parent remains suspended until the child exits, unless the child is launched as a background task.
36-
- A chained program may itself issue `CHAIN` statements, nesting as required.
37-
- If the file specified in `string-expression` cannot be found, an error is raised (and can be caught with `ON ERROR`).
38-
- Unlike BBC BASIC, Retro Rocket’s `CHAIN` does **not** discard the caller - the parent program continues afterwards.
64+
65+
* Chained programs run in a **new interpreter instance** within a new process. The parent remains suspended until the child exits, unless the child is launched as a background task.
66+
* A chained program may itself issue `CHAIN` statements, nesting as required.
67+
* If the file specified in `string-expression` cannot be found, an error is raised (and can be caught with `ON ERROR`).
68+
* The memory model determines the **maximum size of any single allocation**, not the total memory usage of the program.
69+
* Unlike BBC BASIC, Retro Rocket’s `CHAIN` does **not** discard the caller - the parent program continues afterwards.
70+
71+
---
3972

4073
**See also:**
4174
\ref GLOBAL "GLOBAL", \ref LIBRARY "LIBRARY"
75+

docs/BUFFERTOSTRINGS.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ <h2 class="doxsection"><a class="anchor" id="encoding-format-1"></a>
164164
<h2 class="doxsection"><a class="anchor" id="errors-5"></a>
165165
Errors</h2>
166166
<ul>
167-
<li>Invalid memory address → error</li>
168-
<li>Negative <span class="tt">length</span> → error</li>
169-
<li>Encoded result exceeds <span class="tt">MAX_STRINGLEN</span> → error</li>
167+
<li>Invalid memory address</li>
168+
<li>Negative <span class="tt">length</span></li>
169+
<li>Encoded result is too large to allocate a string variable</li>
170170
</ul>
171171
<hr />
172172
<h2 class="doxsection"><a class="anchor" id="example-3"></a>

docs/CHAIN.html

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,38 +123,53 @@
123123
<div class="headertitle"><div class="title">CHAIN Keyword </div></div>
124124
</div><!--header-->
125125
<div class="contents">
126-
<div class="textblock"><div class="fragment"><div class="line">CHAIN string-expression[,boolean-expression]</div>
127-
</div><!-- fragment --><p>Starts a new BASIC program, pausing the current program until the new one finishes. <br />
128-
The string expression must evaluate to the <b>filename</b> of a program accessible from the filesystem.</p>
126+
<div class="textblock"><div class="fragment"><div class="line">CHAIN string-expression[,boolean-expression] [MEMORY SMALL|MEDIUM|LARGE|HUGE]</div>
127+
</div><!-- fragment --><p>Starts a new BASIC program, pausing the current program until the new one finishes. The string expression must evaluate to the <b>filename</b> of a program accessible from the filesystem.</p>
129128
<ul>
130129
<li>Any variables marked as <a class="el" href="GLOBAL.html">GLOBAL</a> will be shared with the child program.</li>
131-
<li>When the chained program terminates, control returns to the line immediately following the <span class="tt">CHAIN</span> statement in the calling program. <br />
132-
</li>
130+
<li>When the chained program terminates, control returns to the line immediately following the <span class="tt">CHAIN</span> statement in the calling program.</li>
133131
<li>Variables not marked as global are not visible to the chained program.</li>
134132
<li>If the optional boolean expression is included and evaluates to true, the program will be launched as a task in the background and the caller will resume immediately.</li>
133+
<li>The optional <span class="tt">MEMORY</span> clause selects the memory model used by the new program.</li>
135134
</ul>
135+
<hr />
136+
<h5 class="doxsection"><a class="anchor" id="memory-models"></a>
137+
Memory Models</h5>
138+
<p>The <span class="tt">MEMORY</span> option controls the size of the allocator used by the child program:</p>
139+
<ul>
140+
<li><span class="tt">SMALL</span> — up to 32 MiB per allocation</li>
141+
<li><span class="tt">MEDIUM</span> — up to 64 MiB per allocation <em>(default)</em></li>
142+
<li><span class="tt">LARGE</span> — up to 128 MiB per allocation</li>
143+
<li><span class="tt">HUGE</span> — up to 256 MiB per allocation</li>
144+
</ul>
145+
<p>If not specified, the child program uses the <b>same memory model as the caller</b>, or <span class="tt">MEDIUM</span> if no parent model applies.</p>
146+
<p>If the requested memory model cannot be allocated, the <span class="tt">CHAIN</span> will fail with an out-of-memory error.</p>
147+
<dl class="section remark"><dt>Remarks</dt><dd>The memory model does not limit the total memory a program may use.It limits the size of any single contiguous allocation (for example, a string or buffer), and programs may use more memory overall but individual allocations cannot exceed the selected model.</dd></dl>
148+
<hr />
136149
<dl class="section remark"><dt>Remarks</dt><dd><span class="tt">CHAIN</span> resolves relative paths from the <b>current working directory</b>. </dd>
137150
<dd>
138151
Use absolute paths (e.g. <span class="tt">/programs/login</span>) if you don’t want this to depend on <span class="tt">CHDIR</span>.</dd></dl>
139152
<hr />
140-
<h5 class="doxsection"><a class="anchor" id="example-7"></a>
141-
Example</h5>
153+
<h5 class="doxsection"><a class="anchor" id="examples-150"></a>
154+
Examples</h5>
142155
<div class="fragment"><div class="line">PRINT &quot;Before chain&quot;</div>
143156
<div class="line">GLOBAL X = 42</div>
144157
<div class="line">CHAIN &quot;childprog&quot;</div>
145158
<div class="line">PRINT &quot;Back again, X = &quot;; X</div>
146-
</div><!-- fragment --><p>If <span class="tt">childprog</span> uses the global variable <span class="tt">X</span>, it will see the value <span class="tt">42</span>. <br />
147-
After <span class="tt">childprog</span> ends, execution resumes.</p>
148-
<hr />
159+
</div><!-- fragment --><div class="fragment"><div class="line">CHAIN &quot;worker&quot;, TRUE MEMORY SMALL</div>
160+
</div><!-- fragment --><div class="fragment"><div class="line">CHAIN &quot;bigdata&quot; MEMORY LARGE</div>
161+
</div><!-- fragment --><div class="fragment"><div class="line">CHAIN &quot;analysis&quot; MEMORY HUGE</div>
162+
</div><!-- fragment --><hr />
149163
<h5 class="doxsection"><a class="anchor" id="notes-148"></a>
150164
Notes</h5>
151165
<ul>
152166
<li>Chained programs run in a <b>new interpreter instance</b> within a new process. The parent remains suspended until the child exits, unless the child is launched as a background task.</li>
153-
<li>A chained program may itself issue <span class="tt">CHAIN</span> statements, nesting as required. <br />
154-
</li>
167+
<li>A chained program may itself issue <span class="tt">CHAIN</span> statements, nesting as required.</li>
155168
<li>If the file specified in <span class="tt">string-expression</span> cannot be found, an error is raised (and can be caught with <span class="tt">ON ERROR</span>).</li>
169+
<li>The memory model determines the <b>maximum size of any single allocation</b>, not the total memory usage of the program.</li>
156170
<li>Unlike BBC BASIC, Retro Rocket’s <span class="tt">CHAIN</span> does <b>not</b> discard the caller - the parent program continues afterwards.</li>
157171
</ul>
172+
<hr />
158173
<p><b>See also:</b> <a class="el" href="GLOBAL.html">GLOBAL</a>, <a class="el" href="LIBRARY.html">LIBRARY</a> </p>
159174
</div></div><!-- contents -->
160175
</div><!-- PageDoc -->

docs/CHDIR.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
<dd>
139139
Directory traversal is only possible by specifying absolute or relative names explicitly.</dd></dl>
140140
<hr />
141-
<h4 class="doxsection"><a class="anchor" id="example-8"></a>
141+
<h4 class="doxsection"><a class="anchor" id="example-7"></a>
142142
Example</h4>
143143
<div class="fragment"><div class="line">CHDIR &quot;/programs&quot;</div>
144144
<div class="line">CHAIN &quot;demo&quot;</div>

docs/CLOSE.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
<dd>
136136
A numeric literal or expression is <b>not</b> accepted.</dd></dl>
137137
<hr />
138-
<h5 class="doxsection"><a class="anchor" id="example-9"></a>
138+
<h5 class="doxsection"><a class="anchor" id="example-8"></a>
139139
Example</h5>
140140
<div class="fragment"><div class="line">FH = OPENOUT(&quot;log.txt&quot;)</div>
141141
<div class="line">WRITE FH, &quot;hello&quot;</div>

docs/CLS.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
<li>Subsequent text and graphics draw onto a blank screen using the active colours.</li>
131131
</ul>
132132
<hr />
133-
<h5 class="doxsection"><a class="anchor" id="example-10"></a>
133+
<h5 class="doxsection"><a class="anchor" id="example-9"></a>
134134
Example</h5>
135135
<div class="fragment"><div class="line">PRINT &quot;Hello!&quot;</div>
136136
<div class="line">CIRCLE 200, 150, 50, TRUE</div>

docs/COLOUR.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
</div>
132132
<dl class="section note"><dt>Note</dt><dd>Both British and American spellings are accepted: <span class="tt">COLOUR</span> and <span class="tt">COLOR</span>.</dd></dl>
133133
<hr />
134-
<h5 class="doxsection"><a class="anchor" id="example-11"></a>
134+
<h5 class="doxsection"><a class="anchor" id="example-10"></a>
135135
Example</h5>
136136
<div class="fragment"><div class="line">COLOUR 14</div>
137137
<div class="line">PRINT &quot;This text is bright yellow.&quot;</div>

docs/CURSOR.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
</ul>
133133
<p>After moving the cursor, subsequent <a class="el" href="PRINT.html">PRINT</a> output starts at that position.</p>
134134
<hr />
135-
<h5 class="doxsection"><a class="anchor" id="example-12"></a>
135+
<h5 class="doxsection"><a class="anchor" id="example-11"></a>
136136
Example</h5>
137137
<div class="fragment"><div class="line">CLS</div>
138138
<div class="line">CURSOR 10, 5</div>

docs/DATA.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
<p>Values are stored at program load time and are not re-parsed during execution.</p>
135135
<p>Multiple <span class="tt">DATA</span> statements are concatenated into a single continuous data stream.</p>
136136
<hr />
137-
<h5 class="doxsection"><a class="anchor" id="example-13"></a>
137+
<h5 class="doxsection"><a class="anchor" id="example-12"></a>
138138
Example</h5>
139139
<div class="fragment"><div class="line">DATA 10, 20</div>
140140
<div class="line">DATA 1.5</div>

docs/DATASET.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
</div><!-- fragment --><p>Defines a named position within the <span class="tt">DATA</span> stream.</p>
128128
<p>The name is set to the current position in the <span class="tt">DATA</span> stream at that point in the program, so it can be used later with <span class="tt">RESTORE</span>.</p>
129129
<hr />
130-
<h5 class="doxsection"><a class="anchor" id="example-14"></a>
130+
<h5 class="doxsection"><a class="anchor" id="example-13"></a>
131131
Example</h5>
132132
<div class="fragment"><div class="line">DATA 10, 20</div>
133133
<div class="line">DATASET numbers</div>

0 commit comments

Comments
 (0)