mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-22 19:21:47 +00:00
CString/CArray was an illusion; Update and test tsconfig files
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
/// <reference path="../../assembly.d.ts" />
|
||||
|
||||
const ALIGN_LOG2: usize = 3;
|
||||
const ALIGN_SIZE: usize = 1 << ALIGN_LOG2;
|
||||
const ALIGN_MASK: usize = ALIGN_SIZE - 1;
|
9
std/assembly/tsconfig.json
Normal file
9
std/assembly/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../assembly.json",
|
||||
"compilerOptions": {
|
||||
"diagnostics": true
|
||||
},
|
||||
"include": [
|
||||
"./**/*.ts"
|
||||
]
|
||||
}
|
12
std/carray.d.ts
vendored
12
std/carray.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
/// <reference path="../assembly.d.ts" />
|
||||
|
||||
/** A C-compatible array class. */
|
||||
declare class CArray<T> {
|
||||
[key: number]: T;
|
||||
|
||||
/** Constructs a new C-Array of the specified capacity. */
|
||||
constructor(capacity: usize);
|
||||
|
||||
/** Disposes this instance and the memory associated with it. */
|
||||
dispose(): void;
|
||||
}
|
12
std/cstring.d.ts
vendored
12
std/cstring.d.ts
vendored
@ -1,12 +0,0 @@
|
||||
/// <reference path="../assembly.d.ts" />
|
||||
|
||||
/** A C-compatible string class. */
|
||||
declare class CString {
|
||||
readonly [key: number]: u8;
|
||||
|
||||
/** Constructs a new C-String from a standard string. */
|
||||
constructor(string: string);
|
||||
|
||||
/** Disposes this instance and the memory associated with it. */
|
||||
dispose(): void;
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
/// <reference path="../../assembly.d.ts" />
|
||||
|
||||
@global()
|
||||
@struct()
|
||||
class CArray<T> {
|
||||
|
||||
constructor(capacity: usize) {
|
||||
return changetype<usize, this>(Heap.allocate(capacity * sizeof<T>()));
|
||||
}
|
||||
|
||||
@inline()
|
||||
"[]"(index: usize): T {
|
||||
return load<T>(changetype<this, usize>(this) + index * sizeof<T>());
|
||||
}
|
||||
|
||||
@inline()
|
||||
"[]="(index: usize, value: T): T {
|
||||
store<T>(changetype<this, usize>(this) + index * sizeof<T>(), value);
|
||||
return value;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
Heap.dispose(changetype<this, usize>(this));
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/// <reference path="../../assembly.d.ts" />
|
||||
|
||||
@global()
|
||||
@struct()
|
||||
class CString {
|
||||
|
||||
constructor(string: string) {
|
||||
const ptr: usize = Heap.allocate(<usize>string.length * 2 + 1);
|
||||
let idx: usize = ptr;
|
||||
for (let i: usize = 0, k: usize = <usize>(<string>str).length; i < k; ++i) {
|
||||
let u: i32 = string.charCodeAt(i);
|
||||
if (u >= 0xD800 && u <= 0xDFFF && i + 1 < k)
|
||||
u = 0x10000 + ((u & 0x3FF) << 10) | (string.charCodeAt(++i) & 0x3FF);
|
||||
if (u <= 0x7F)
|
||||
store<u8>(idx++, u as u8);
|
||||
else if (u <= 0x7FF) {
|
||||
// TODO: maybe combine multiple stores into the next larger one
|
||||
store<u8>(idx++, (0xC0 | (u >>> 6) ) as u8);
|
||||
store<u8>(idx++, (0x80 | ( u & 63)) as u8);
|
||||
} else if (u <= 0xFFFF) {
|
||||
store<u8>(idx++, (0xE0 | (u >>> 12) ) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 6) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ( u & 63)) as u8);
|
||||
} else if (u <= 0x1FFFFF) {
|
||||
store<u8>(idx++, (0xF0 | (u >>> 18) ) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 12) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 6) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ( u & 63)) as u8);
|
||||
} else if (u <= 0x3FFFFFF) {
|
||||
store<u8>(idx++, (0xF8 | (u >>> 24) ) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 18) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 12) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 6) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ( u & 63)) as u8);
|
||||
} else {
|
||||
store<u8>(idx++, (0xFC | (u >>> 30) ) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 24) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 18) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 12) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ((u >>> 6) & 63)) as u8);
|
||||
store<u8>(idx++, (0x80 | ( u & 63)) as u8);
|
||||
}
|
||||
}
|
||||
store<u8>(idx, 0);
|
||||
return changetype<usize, this>(ptr);
|
||||
}
|
||||
|
||||
@inline()
|
||||
"[]"(index: usize): u8 {
|
||||
return load<u8>(changetype<this, usize>(this) + index /* * sizeof<u8>() */);
|
||||
}
|
||||
|
||||
// read-only
|
||||
|
||||
dispose(): void {
|
||||
Heap.dispose(changetype<this, usize>(this));
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noLib": true,
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"files": [
|
||||
"carray.ts",
|
||||
"cstring.ts",
|
||||
"heap.ts"
|
||||
]
|
||||
}
|
8
std/heap.ts → std/portable/heap.d.ts
vendored
8
std/heap.ts → std/portable/heap.d.ts
vendored
@ -1,5 +1,3 @@
|
||||
/// <reference path="../assembly.d.ts" />
|
||||
|
||||
/** A static class representing the heap. */
|
||||
declare class Heap {
|
||||
|
||||
@ -10,11 +8,11 @@ declare class Heap {
|
||||
static dispose(ptr: usize): void;
|
||||
|
||||
/** Gets the amount of used heap space, in bytes. */
|
||||
static get used(): usize;
|
||||
static readonly used: usize;
|
||||
|
||||
/** Gets the amount of free heap space, in bytes. */
|
||||
static get free(): usize;
|
||||
static readonly free: usize;
|
||||
|
||||
/** Gets the size of the heap, in bytes. */
|
||||
static get size(): usize;
|
||||
static readonly size: usize;
|
||||
}
|
9
std/portable/heap.js
Normal file
9
std/portable/heap.js
Normal file
@ -0,0 +1,9 @@
|
||||
var globalScope = typeof window !== "undefined" && window || typeof global !== "undefined" && global || self;
|
||||
|
||||
globalScope["Heap"] = {
|
||||
allocate: function() { throw new Error("not implemented"); },
|
||||
dispose: function() { throw new Error("not implemented"); },
|
||||
used: 0,
|
||||
free: 0,
|
||||
size: 0
|
||||
};
|
9
std/portable/tsconfig.json
Normal file
9
std/portable/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../portable-assembly.json",
|
||||
"compilerOptions": {
|
||||
"diagnostics": true
|
||||
},
|
||||
"include": [
|
||||
"./**/*.ts"
|
||||
]
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noLib": true,
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"files": [
|
||||
"carray.d.ts",
|
||||
"cstring.d.ts",
|
||||
"heap.d.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user