changetype builtin; some namespace parsing; more stdlib ideas; compiler options for asc

This commit is contained in:
dcodeIO
2017-12-08 04:03:44 +01:00
parent 59dafc8d22
commit bbb57baecb
62 changed files with 636 additions and 469 deletions

View File

@ -1,29 +1,25 @@
/// <reference path="../../assembly.d.ts" />
/** A C-compatible Array class. */
@global()
@struct()
class CArray<T> {
/** Constructs a new C-Array of the specified capacity. */
constructor(capacity: usize) {
return unsafe_cast<usize,this>(Memory.allocate(capacity * sizeof<T>()));
return changetype<usize, this>(Heap.allocate(capacity * sizeof<T>()));
}
/** Gets the element at the specified index using bracket notation. */
@inline()
"[]"(index: usize): T {
return load<T>(unsafe_cast<this,usize>(this) + index * sizeof<T>());
return load<T>(changetype<this, usize>(this) + index * sizeof<T>());
}
/** Sets the element at the specified index using bracket notation. */
@inline()
"[]="(index: usize, value: T): T {
store<T>(unsafe_cast<this,usize>(this) + index * sizeof<T>(), value);
store<T>(changetype<this, usize>(this) + index * sizeof<T>(), value);
return value;
}
/** Disposes this instance and the memory associated with it. */
dispose(): void {
Memory.dispose(unsafe_cast<this,usize>(this));
Heap.dispose(changetype<this, usize>(this));
}
}