Skip to content

Commit

Permalink
side branch#git
Browse files Browse the repository at this point in the history
  • Loading branch information
benStre committed Nov 7, 2023
1 parent df73d2a commit 2f5d37c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions runtime/pointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export class PointerProperty<T=any> extends Ref<T> {
private constructor(public pointer: Pointer, public key: any, leak_js_properties = false) {
super();
this.#leak_js_properties = leak_js_properties;
pointer.is_persistant = true; // TODO: make unpersistant when pointer property deleted
pointer.is_persistent = true; // TODO: make unpersistant when pointer property deleted
PointerProperty.synced_pairs.get(pointer)!.set(key, this); // save in map
}

Expand Down Expand Up @@ -1626,7 +1626,7 @@ export class Pointer<T = any> extends Ref<T> {
get is_js_primitive(){return this.#is_js_primitive} // true if js primitive (number, boolean, ...) or 'single instance' class (Type, Endpoint) that cannot be directly addressed by reference
get is_anonymous(){return this.#is_anonymous}
get origin(){return this.#origin}
get is_persistant() { return this.#is_persistent;}
get is_persistent() { return this.#is_persistent;}
get labels(){return this.#labels}
get pointer_type(){return this.#pointer_type}

Expand Down Expand Up @@ -1654,7 +1654,7 @@ export class Pointer<T = any> extends Ref<T> {
}

// change the persistant state of this pointer
set is_persistant(persistant:boolean) {
set is_persistent(persistant:boolean) {
if (persistant && !this.#is_persistent) {
super.val = <any>this.current_val;
this.#is_persistent = true;
Expand Down Expand Up @@ -1717,7 +1717,7 @@ export class Pointer<T = any> extends Ref<T> {
public addLabel(label: string|number){
if (Pointer.pointer_label_map.has(label)) throw new PointerError("Label " + Runtime.formatVariableName(label, '$') + " is already assigned to a pointer");
this.#labels.add(label);
this.is_persistant = true; // make pointer persistant
this.is_persistent = true; // make pointer persistant
Pointer.pointer_label_map.set(label, this)

// add to globalThis
Expand Down Expand Up @@ -1894,7 +1894,7 @@ export class Pointer<T = any> extends Ref<T> {
if (!this.value_initialized && (Object(v) !== v || v instanceof ArrayBuffer)) {
Pointer.pointers.delete(this.id); // force remove previous non-primitive pointer (assume it has not yet been used)
Pointer.primitive_pointers.delete(this.id)
return <any>Pointer.create(this.id, v, this.sealed, this.origin, this.is_persistant, this.is_anonymous, false, this.allowed_access, this.datex_timeout)
return <any>Pointer.create(this.id, v, this.sealed, this.origin, this.is_persistent, this.is_anonymous, false, this.allowed_access, this.datex_timeout)
}
//placeholder replacement
if (Pointer.pointer_value_map.has(v)) {
Expand All @@ -1918,7 +1918,7 @@ export class Pointer<T = any> extends Ref<T> {
throw new PointerError("Cannot get value of uninitialized pointer")
}
// deref and check if not garbage collected
if (!this.is_persistant && !this.is_js_primitive && super.val instanceof WeakRef) {
if (!this.is_persistent && !this.is_js_primitive && super.val instanceof WeakRef) {
const val = super.val.deref();
// seems to be garbage collected
if (val === undefined && this.#loaded && !this.#is_js_primitive) {
Expand Down Expand Up @@ -1946,7 +1946,7 @@ export class Pointer<T = any> extends Ref<T> {
throw new PointerError("Cannot get value of uninitialized pointer")
}
// deref and check if not garbage collected
if (!this.is_persistant && !this.is_js_primitive && super.current_val instanceof WeakRef) {
if (!this.is_persistent && !this.is_js_primitive && super.current_val instanceof WeakRef) {
const val = super.current_val.deref();
// seems to be garbage collected
if (val === undefined && this.#loaded && !this.#is_js_primitive) {
Expand Down Expand Up @@ -2336,7 +2336,7 @@ export class Pointer<T = any> extends Ref<T> {
}


// enable / disable garbage collection based on subscribers & is_persistant
// enable / disable garbage collection based on subscribers & is_persistent
updateGarbageCollection(){

// primitive value cannot be garbage collected
Expand All @@ -2345,7 +2345,7 @@ export class Pointer<T = any> extends Ref<T> {
}

// remove WeakRef (keep value) if persistant, or has subscribers
else if (this.is_persistant || this.subscribers?.size != 0 || this.is_js_primitive) {
else if (this.is_persistent || this.subscribers?.size != 0 || this.is_js_primitive) {
//logger.warn("blocking " + this + " from beeing garbage collected")
this.#garbage_collectable = false;
if (super.val instanceof WeakRef) super.setVal(super.val.deref(), false);
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6518,7 +6518,7 @@ export class Runtime {
const only_load_local = true; //pointer.is_origin || SCOPE.sender?.equals(pointer.origin);
pointer = await Pointer.load(id, SCOPE, only_load_local, knows_pointer?true:false);
// console.log("has $" + Pointer.normalizePointerId(id), jmp_index, buffer2hex(SCOPE.buffer_views.uint8.slice(jmp_index), " "));
// pointer.is_persistant = true;
// pointer.is_persistent = true;
SCOPE.current_index += init_block_size; // jump to end of init block
}
// does not exist - init
Expand Down
2 changes: 1 addition & 1 deletion types/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Scope<T=any> {
// make internal vars persistent even if currently not loaded in JS (TODO: how to handle this case in the future?)
for (const internal_var of this.internal_vars) {
if (internal_var instanceof Pointer) {
internal_var.is_persistant = true;
internal_var.is_persistent = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion utils/interface-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function getValueTSCode(module_name:string, name:string, value: any, no_pointer

// disable garbage collection
const ptr = <Datex.Pointer> Datex.Pointer.getByValue(value);
if (ptr) ptr.is_persistant = true;
if (ptr) ptr.is_persistent = true;

const loader = value?.[DX_SOURCE] ? `await datex.get('${value[DX_SOURCE]}')` : `await datex('${Datex.Runtime.valueToDatexStringExperimental(value)}')`
code += `${name =='default' ? 'export default' : 'export const ' + name + ' ='} ${loader}${types ? ` as ${getValueTSType(value)}` : ''};\n`;
Expand Down

0 comments on commit 2f5d37c

Please sign in to comment.