Skip to content

Commit

Permalink
zero-length source for slice
Browse files Browse the repository at this point in the history
  • Loading branch information
dalnefre committed Jan 9, 2025
1 parent 66a20b5 commit 3447408
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
14 changes: 12 additions & 2 deletions lib/blob.asm
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ slice_source:
alu add ; cust len' base''=base'+base
state 2 ; cust len' base'' len
msg 1 ; cust len' base'' len base'

dup 2 ; cust len' base'' len base' len base'
cmp gt ; cust len' base'' len base' len>base'
if k_slice_zero ; cust len' base'' len base'

alu sub ; cust len' base'' size'=len-base'
pick 3 ; cust len' base'' size' len'
pick 2 ; cust len' base'' size' len' size'
Expand All @@ -160,6 +165,13 @@ k_slice_fit: ; cust len' base' _
state -2 ; base',len',cust blob
ref std.send_msg

k_slice_zero: ; cust len' base'' len base'
roll 4 ; cust base'' len base' len'
drop 3 ; cust base''
push 0 ; cust base'' len'=0
roll -2 ; cust len' base''
ref k_slice_fit

;
; blob interface to a pair of consecutive blobs
;
Expand Down Expand Up @@ -289,8 +301,6 @@ k_pair_fit: ; cust len' base' _
k_pair_source2: ; --
state -1 ; base',len',cust
part 2 ; cust len' base'
roll 2 ; cust base' len'
roll 2 ; cust len' base'
msg 0 ; cust len' base' size
alu sub ; cust len' base''=base'-size
pair 2 ; base'',len',cust
Expand Down
71 changes: 64 additions & 7 deletions site/tutorial/reuse.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ <h3 name="tail">Common Tail-Sequences</h3>
if they are sequential or not!
This is because uFork memory is organized
into linked structures called <em>quad-cells</em>.
Quad-cells have 4 <em>value</em> fields.
Quad-cells are the minimum addressable unit.
They have 4 <em>value</em> fields.
Each value is a <em>fixnum</em>,
a <em>capability</em> (actor address),
or a <em>pointer</em> to a quad-cell.
Expand All @@ -98,11 +99,15 @@ <h3 name="tail">Common Tail-Sequences</h3>
<pre class="graphic">
cust_send ---> [#instr_t, "msg", 1, k]
|
V
+--------------------+
|
V
send_msg ----> [#instr_t, "actor", "send", k]
|
sink_beh ---------+ |
V V
|
sink_beh ------+---------------------------+
|
V
commit ------> [#instr_t, "end", "commit", #?]</pre>
<p class="text">
This code fragment consists of 3 instructions
Expand Down Expand Up @@ -137,7 +142,7 @@ <h3 name="tail">Common Tail-Sequences</h3>
</p>
<p class="text">
A more common approach is
to use a <code>ref</code> pseudo-instruction
to use a <a href="https://github.com/organix/uFork/blob/main/docs/asm.md#ref"><code>ref</code></a> pseudo-instruction
to provide the continuation,
as shown here:
</p>
Expand Down Expand Up @@ -191,7 +196,7 @@ <h3 name="static">Static Data</h3>
ref #nil</pre>
</p>
<p class="text">
The <code>dict_t</code> data constructor
The <a href="https://github.com/organix/uFork/blob/main/docs/asm.md#data"><code>dict_t</code></a> data constructor
defines statically-initialized instances
of type <code>#dict_t</code>.
It takes a <var>key</var>, a <var>value</var>,
Expand Down Expand Up @@ -323,7 +328,59 @@ <h3 name="CAS">Compare-and-Swap Method</h3>
The one-at-a-time transactional nature
of actor event handling ensures consistency.
</p>
<h3 name="demo">CAS Demonstration</h3>
<h3 name="usage">Usage Example</h3>
<p class="text">
An actor with <code>cas_add</code> behavior
uses a cell's "CAS" method
to safely update the cell's value.
...
</p>
<p>
<pre class="code">
cas_add: ; old,inc,cell &lt;- old'
state 1 ; old
msg 0 ; old old'
cmp eq ; old==old'
if std.commit ; --</pre>
</p>
<p class="text">
lorem ipsum
</p>
<p>
<pre class="code">
state 0 ; old,inc,cell
part 2 ; cell inc old
drop 1 ; cell inc
msg 0 ; cell inc old'</pre>
</p>
<p class="text">
lorem ipsum
</p>
<p>
<pre class="code">
dup 2 ; cell inc old' inc old'
alu add ; cell inc old' new=inc+old'
pick 2 ; cell inc old' new old'
push CAS_op ; cell inc old' new old' #CAS
actor self ; cell inc old' new old' #CAS cust=SELF
pair 3 ; cell inc old' cust,#CAS,old',new
state -2 ; cell inc old' cust,#CAS,old',new cell
actor send ; cell inc old'</pre>
</p>
<p class="text">
lorem ipsum
</p>
<p>
<pre class="code">
pair 2 ; old',inc,cell
push cas_add ; old',inc,cell cas_add
actor become ; --
ref std.commit</pre>
</p>
<p class="text">
lorem ipsum
</p>
<h3 name="source">Source Code</h3>
<p class="text">
lorem ipsum
</p>
Expand Down

0 comments on commit 3447408

Please sign in to comment.