@remix_labs/machine-starter 2.2216.0-dev → 2.2220.0-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/common.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { GROOVEBOX_BUILD } from "./groovebox_build.js";
2
- import { mixcoreFFIs } from "./mixcore-common.js";
2
+ import { filterFFINames } from "./mixcore-common.js";
3
3
  import { nanoid } from "nanoid";
4
4
 
5
5
  let workers = {};
@@ -57,8 +57,7 @@ function StartWASM(hub, baseURL, org, workspace, vmID, user, token, noOutputViaM
57
57
  })
58
58
  }
59
59
 
60
- function makeLocalFFIs(mixcore, names) {
61
- console.log("Mixcore FFIs (local)", names);
60
+ function mixcoreLocalFFIs(mixcore, names) {
62
61
  return Object.fromEntries(
63
62
  names.map(name => [name, {
64
63
  isRaw: true,
@@ -66,41 +65,44 @@ function makeLocalFFIs(mixcore, names) {
66
65
  }]));
67
66
  }
68
67
 
69
- // See `mix-rs/mixcore/bindings/javascript/mixcore.js` for a description of the
70
- // values of config.mixcore.
68
+ // See `mix-rs/mixcore/README.md` for a description of the values of
69
+ // config.mixcore.
71
70
  async function StartWASM2(hub, config) {
72
71
  console.log("GROOVEBOX_BUILD (machine-starter)", GROOVEBOX_BUILD);
73
72
  let channel = await hub.newChannel();
74
73
  // injected by either index.js or node.js
75
74
  let worker = globalThis.GetMachineWASMWorker();
76
75
  workers[config.vmID] = worker;
76
+ let mixcore = null;
77
77
  let localFFIs = config.localFFIs || {};
78
78
  if (config.mixcore && config.mixcore.kind == 'mixcore') {
79
- let {mixcore, enableFFIs, disableFFIs} = config.mixcore;
80
- let ffiNames = await mixcoreFFIs(mixcore, enableFFIs, disableFFIs);
81
- let ffis = makeLocalFFIs(mixcore, ffiNames);
82
- localFFIs = {...localFFIs, ...ffis};
83
- config.mixcore = null;
79
+ let enableFFIs, disableFFIs;
80
+ ({mixcore, enableFFIs, disableFFIs} = config.mixcore);
81
+ let ffiNames = filterFFINames(await mixcore.ffiNames(), enableFFIs, disableFFIs);
82
+ console.log("Mixcore (starter)", mixcore, ffiNames, mixcore.registerDebugObject);
83
+ localFFIs = {...localFFIs, ...mixcoreLocalFFIs(mixcore, ffiNames)};
84
+ config.mixcore = {};
85
+ if (mixcore.registerDebugObject) {
86
+ config.mixcore.publishDebugObjects = true;
87
+ subscribeDebugObjects(mixcore, hub, config);
88
+ }
84
89
  }
85
90
  let localFFIkind = {};
86
91
  let localFFIfuns = {};
87
- if (localFFIs) {
88
- for (const [k, v] of Object.entries(localFFIs)) {
89
- console.log("local FFI", k, v);
90
- localFFIfuns[k] = {...v};
91
- if (v.isRaw && (v.canFail || v.useJsonDecoder)) {
92
- console.error("A raw, local FFI must neither be failing nor use the JSON decoder: " + k);
93
- } else {
94
- localFFIkind[k] = {...v};
95
- delete localFFIkind[k].run;
96
- }
97
- };
98
- let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
99
- localFFIkind["$vm_start"] = vm_kind;
100
- localFFIfuns["$vm_start"] = ffi_vm_start;
101
- localFFIkind["$vm_stop"] = vm_kind;
102
- localFFIfuns["$vm_stop"] = ffi_vm_stop;
103
- }
92
+ for (const [k, v] of Object.entries(localFFIs)) {
93
+ localFFIfuns[k] = {...v};
94
+ if (v.isRaw && (v.canFail || v.useJsonDecoder)) {
95
+ console.error("A raw, local FFI must neither be failing nor use the JSON decoder: " + k);
96
+ } else {
97
+ localFFIkind[k] = {...v};
98
+ delete localFFIkind[k].run;
99
+ }
100
+ };
101
+ let vm_kind = { isRaw:false, canFail:false, useJsonDecoder:false};
102
+ localFFIkind["$vm_start"] = vm_kind;
103
+ localFFIfuns["$vm_start"] = ffi_vm_start;
104
+ localFFIkind["$vm_stop"] = vm_kind;
105
+ localFFIfuns["$vm_stop"] = ffi_vm_stop;
104
106
  let config_msg =
105
107
  { "_rmx_type": "msg_vm_configure",
106
108
  "baseURL": config.baseURL,
@@ -120,8 +122,7 @@ async function StartWASM2(hub, config) {
120
122
  "mixcore": config.mixcore,
121
123
  };
122
124
  worker.postMessage(config_msg, [ channel.port ]);
123
- if (localFFIs)
124
- setupLocalFFIs(hub, config, localFFIfuns); // don't await!
125
+ setupLocalFFIs(hub, config, localFFIfuns); // don't await!
125
126
  return worker;
126
127
  }
127
128
 
@@ -281,8 +282,7 @@ async function setupLocalFFIs(hub, config, localFFIs) {
281
282
  let args = decode(msg.payload.args);
282
283
  let fun = localFFIs[name];
283
284
  try {
284
- if (!fun)
285
- throw new Error("no such local FFI: " + name);
285
+ if (!fun) throw new Error("no such local FFI: " + name);
286
286
  let connector =
287
287
  { call_id: call_id,
288
288
  hub: hub,
@@ -305,6 +305,19 @@ async function setupLocalFFIs(hub, config, localFFIs) {
305
305
  }
306
306
  }
307
307
 
308
+ async function subscribeDebugObjects(mixcore, hub, config) {
309
+ let channel = await hub.newChannel();
310
+ let vmID = config.vmID;
311
+ await channel.setLocalSubTopic(`/debug-objects/${vmID}`);
312
+ let sub = await channel.subscribe(`/debug-objects/${vmID}`);
313
+ while (true) {
314
+ let msg = await sub.next();
315
+ let id = msg.payload.id;
316
+ let code = msg.payload.code;
317
+ mixcore.registerDebugObject(id, code);
318
+ }
319
+ }
320
+
308
321
  class FFIComm {
309
322
  constructor(vmID, hub, channel) {
310
323
  this.vmID = vmID;
@@ -1,2 +1,2 @@
1
- var GROOVEBOX_BUILD = "2393";
1
+ var GROOVEBOX_BUILD = "2397";
2
2
  export { GROOVEBOX_BUILD }