Skip to content

Commit 9cdfa35

Browse files
committed
Initial implementation if ugc, see AssemblyScript#16; Fix tests
1 parent 461daab commit 9cdfa35

24 files changed

+715
-173
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ A few early examples to get an idea:
2020
A PSON decoder implemented in AssemblyScript.
2121

2222
* **[TLSF memory allocator](./examples/tlsf)**<br />
23-
An early port of TLSF to AssemblyScript.
23+
An port of TLSF to AssemblyScript.
24+
25+
* **[μgc garbage collector](./examples/ugc)**<br />
26+
An port of μgc to AssemblyScript.
2427

2528
Or browse the [compiler tests](./tests/compiler) for a more in-depth overview of what's supported already. One of them is a [showcase](./tests/compiler/showcase.ts).
2629

examples/tlsf/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TLSF
2-
====
1+
TLSF memory allocator
2+
=====================
33

44
A port of [Matt Conte's implementation](https://github.com/mattconte/tlsf) of the [TLSF](http://www.gii.upv.es/tlsf/) memory allocator to AssemblyScript.
55

examples/tlsf/assembly/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tlsf.ts is based on:
1+
tlsf.ts is based on https://github.com/mattconte/tlsf
22

33
Two Level Segregated Fit memory allocator, version 3.1.
44
Written by Matthew Conte

examples/tlsf/assembly/tlsf.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BlockHeader {
3535
static readonly OVERHEAD: usize = sizeof<usize>();
3636

3737
// User data starts directly after the size field in a used block.
38-
static readonly USERDATA_OFFSET: usize = sizeof<usize>() + sizeof<usize>();
38+
static readonly DATA_OFFSET: usize = sizeof<usize>() + sizeof<usize>();
3939

4040
// A free block must be large enough to store its header minus the size of
4141
// the prev_phys_block field, and no larger than the number of addressable
@@ -114,12 +114,12 @@ class BlockHeader {
114114

115115
/** Gets the block header matching the specified data pointer. */
116116
static fromDataPtr(ptr: usize): BlockHeader {
117-
return changetype<BlockHeader>(ptr - BlockHeader.USERDATA_OFFSET);
117+
return changetype<BlockHeader>(ptr - BlockHeader.DATA_OFFSET);
118118
}
119119

120120
/** Returns the address of this block's data. */
121121
toDataPtr(): usize {
122-
return changetype<usize>(this) + BlockHeader.USERDATA_OFFSET;
122+
return changetype<usize>(this) + BlockHeader.DATA_OFFSET;
123123
}
124124

125125
/** Gets the next block after this one using the specified size. */
@@ -174,7 +174,7 @@ class BlockHeader {
174174
return this.size >= BlockHeader.SIZE + size;
175175
}
176176

177-
/* Splits a block into two, the second of which is free. */
177+
/** Splits a block into two, the second of which is free. */
178178
split(size: usize): BlockHeader {
179179
// Calculate the amount of space left in the remaining block.
180180
var remain = BlockHeader.fromOffset(
@@ -194,7 +194,7 @@ class BlockHeader {
194194
return remain;
195195
}
196196

197-
/* Absorb a free block's storage into this (adjacent previous) free block. */
197+
/** Absorb a free block's storage into this (adjacent previous) free block. */
198198
absorb(block: BlockHeader): void {
199199
assert(!this.isLast,
200200
"previous block can't be last"
@@ -205,7 +205,7 @@ class BlockHeader {
205205
}
206206
}
207207

208-
/* The TLSF control structure. */
208+
/** The TLSF control structure. */
209209
@explicit
210210
class Control extends BlockHeader { // Empty lists point here, indicating free
211211

@@ -289,7 +289,7 @@ class Control extends BlockHeader { // Empty lists point here, indicating free
289289
this.insertFreeBlock(block, fl_out, sl_out);
290290
}
291291

292-
/* Inserts a free block into the free block list. */
292+
/** Inserts a free block into the free block list. */
293293
insertFreeBlock(block: BlockHeader, fl: i32, sl: i32): void {
294294
var current = this.blocks(fl, sl);
295295
assert(current,
@@ -311,7 +311,7 @@ class Control extends BlockHeader { // Empty lists point here, indicating free
311311
this.sl_bitmap_set(fl, this.sl_bitmap(fl) | (1 << sl))
312312
}
313313

314-
/* Removes a free block from the free list.*/
314+
/** Removes a free block from the free list.*/
315315
removeFreeBlock(block: BlockHeader, fl: i32, sl: i32): void {
316316
var prev = block.prev_free;
317317
var next = block.next_free;

examples/ugc/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
μgc garbage collector
2+
=====================
3+
4+
A port of [Bach Le's μgc garbage collector library](https://github.com/bullno1/ugc) to AssemblyScript.
5+
6+
Instructions
7+
------------
8+
9+
To build [assembly/ugc.ts](./assembly/ugc.ts) to an untouched and an optimized `.wasm` including their respective `.wast` representations, run:
10+
11+
```
12+
$> npm run build
13+
```
14+
15+
Afterwards, to run the included [test](./tests/index.js):
16+
17+
```
18+
$> npm install
19+
$> npm test
20+
```

examples/ugc/assembly/LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ugc.ts is based on https://github.com/bullno1/ugc
2+
3+
Copyright (c) 2017, Bach Le
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../../std/assembly.json",
3+
"include": [
4+
"./**/*.ts"
5+
]
6+
}

0 commit comments

Comments
 (0)