Skip to content

Commit

Permalink
Merge pull request #69 from unyt-org/fix-misc-2
Browse files Browse the repository at this point in the history
Fix misc
  • Loading branch information
jonasstrehle authored Jan 30, 2024
2 parents f8e1cb7 + db4a279 commit 447b8eb
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 15 deletions.
3 changes: 1 addition & 2 deletions compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5144,8 +5144,7 @@ export class Compiler {

// first part of scope until the stream starts
controller.enqueue(await Compiler.createBlockFromScope(SCOPE));



// read stream and insert
const reader = SCOPE.streaming!;
let next:ReadableStreamReadResult<any>,
Expand Down
1 change: 0 additions & 1 deletion js_adapter/js_class_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,6 @@ export function proxyClass<T extends { new(...args: any[]): any;}>(original_clas
else {
const instance:any = Reflect.construct(target, args, newTarget);
if (args[0]?.[INIT_PROPS]) {
console.log("auto init props");
args[0][INIT_PROPS](instance);
}
return instance;
Expand Down
3 changes: 3 additions & 0 deletions runtime/pointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3176,6 +3176,9 @@ export class Pointer<T = any> extends Ref<T> {

public addSubscriber(subscriber: Endpoint) {

// already subscribed
if (this.subscribers.has(subscriber)) return;

// TODO also check pointer permission for 'to'

// request sync endpoint is self, cannot subscribe to own pointers!
Expand Down
4 changes: 2 additions & 2 deletions runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ export class Runtime {

private static STD_TYPES_ABOUT:Map<Type,Markdown>;

static #datex_out_handler_initialized_resolve:(value: void | PromiseLike<void>) => void
static #datex_out_init_promise = new Promise<void>(resolve=>this.#datex_out_handler_initialized_resolve=resolve);
static #datex_out_handler_initialized_resolve?:(value: void | PromiseLike<void>) => void
static #datex_out_init_promise:Promise<void>|undefined = new Promise<void>(resolve=>this.#datex_out_handler_initialized_resolve=resolve);

private static local_input_handler = Runtime.getDatexInputHandler();

Expand Down
4 changes: 2 additions & 2 deletions runtime/storage-locations/deno-kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class DenoKVStorageLocation extends AsyncStorageLocation {
const entries = itemDB!.list({prefix: []});
const keys = [];
for await (const entry of entries) {
keys.push(entry.value);
keys.push(entry.key[0]);
}
return keys.values() as Generator<string>
}
Expand All @@ -62,7 +62,7 @@ export class DenoKVStorageLocation extends AsyncStorageLocation {
const entries = pointerDB!.list({prefix: []});
const keys = [];
for await (const entry of entries) {
keys.push(entry.value);
keys.push(entry.key[0]);
}
return keys.values() as Generator<string>
}
Expand Down
14 changes: 11 additions & 3 deletions types/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,13 @@ export class Function<T extends (...args: any) => any = (...args: any) => any> e
// call the function either from JS directly (meta data is automatically generated, sender is always the current endpoint) or from a DATEX scope
handleApply(value:any, SCOPE?: datex_scope):Promise<ReturnType<T>>|ReturnType<T>{

// call function remotely
if (!Runtime.endpoint.equals(this.location) && this.location != LOCAL_ENDPOINT) this.setRemoteEndpoint(this.location);
// call function remotely if not
if (!(
Runtime.endpoint.equals(this.location) || // location is own endpoint instance
Runtime.endpoint.main.equals(this.location) || // location is own endpoint
this.location == LOCAL_ENDPOINT || // location is local
this.fn // already has a local function
)) this.setRemoteEndpoint(this.location);

let meta:any; // meta (scope variables)

Expand All @@ -315,7 +320,10 @@ export class Function<T extends (...args: any) => any = (...args: any) => any> e
// is proxy function: call remote, only if has impersonation permission!
if (this.proxy_fn) {
if (SCOPE.impersonation_permission) return this.proxy_fn(value);
else throw new PermissionError("No permission to execute functions on external endpoints ("+this.name+","+this.proxy_fn.name+")", SCOPE)
else {
console.error(this.proxy_fn)
throw new PermissionError("No permission to execute functions on external endpoints ("+this.name+","+this.proxy_fn.name+")", SCOPE)
}
}
// else local call ...
meta = SCOPE.meta;
Expand Down
22 changes: 17 additions & 5 deletions utils/message_logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class MessageLogger {

static logger:Logger

static decompile(dxb:ArrayBuffer, has_header = true, colorized = true){
static decompile(dxb:ArrayBuffer, has_header = true, colorized = true, resolve_slots = true){
try {
// extract body (TODO: just temporary, rust impl does not yet support header decompilation)
if (has_header) {
Expand All @@ -22,7 +22,7 @@ export class MessageLogger {
dxb = res[1];
}

return wasm_decompile(new Uint8Array(dxb), true, colorized, true).replace(/\r\n$/, '');
return wasm_decompile(new Uint8Array(dxb), true, colorized, resolve_slots).replace(/\r\n$/, '');
} catch (e) {
return "Decompiler Error: "+ e.message;
}
Expand All @@ -36,11 +36,17 @@ export class MessageLogger {
// ignore incoming requests from own endpoint to own endpoint
const receivers = header.routing?.receivers;
if (header.sender == Runtime.endpoint && (receivers instanceof Logical && receivers?.size == 1 && receivers.has(Runtime.endpoint)) && header.type != ProtocolDataType.RESPONSE && header.type != ProtocolDataType.DEBUGGER) return;


// ignore hello messages
if (header.type == ProtocolDataType.HELLO || header.type == ProtocolDataType.GOODBYE) {
this.logger.plain(`\n#color(blue)⭠ ${header.sender||'@*'} ${header.type!=undefined? `(${ProtocolDataType[header.type]}) ` : ''}`);
return;
};

const content = MessageLogger.decompile(dxb);
if (content.trim() == "\x1b[38;2;219;45;129mvoid\x1b[39m;") return; // dont log void; messages

this.logger.plain(`\n#color(blue)⭠ ${header.sender||'@*'} `.padEnd(70, '─'));
this.logger.plain(`\n#color(blue)⭠ ${header.sender||'@*'} ${header.type!=undefined ? `(${ProtocolDataType[header.type]}) ` : ''}`.padEnd(70, '─'));
console.log(content);
this.logger.plain(`#color(blue)─────────────────────────────────────────────────────────\n`);
});
Expand All @@ -50,10 +56,16 @@ export class MessageLogger {
const receivers = header.routing?.receivers;
if (header.sender == Runtime.endpoint && (receivers instanceof Logical && receivers?.size == 1 && receivers.has(Runtime.endpoint)) && header.type != ProtocolDataType.RESPONSE && header.type != ProtocolDataType.DEBUGGER) return;

// ignore hello messages
if (header.type == ProtocolDataType.HELLO || header.type == ProtocolDataType.GOODBYE) {
this.logger.plain(`\n#color(green)${header.sender||'@*'}${receivers||'@*'} ${header.type!=undefined ? `(${ProtocolDataType[header.type]}) ` : ''}`);
return;
};

const content = MessageLogger.decompile(dxb);
if (content.trim() == "\x1b[38;2;219;45;129mvoid\x1b[39m;") return; // dont log void; messages

this.logger.plain(`\n#color(green)⭢ ${receivers||'@*'} `.padEnd(70, '─'));
this.logger.plain(`\n#color(green)⭢ ${receivers||'@*'} ${header.type!=undefined ? `(${ProtocolDataType[header.type]}) ` : ''}`.padEnd(70, '─'));
console.log(content);
this.logger.plain(`#color(green)─────────────────────────────────────────────────────────\n`);
});
Expand Down
Binary file modified wasm/adapter/pkg/datex_wasm_bg.wasm
Binary file not shown.

0 comments on commit 447b8eb

Please sign in to comment.