Skip to content

Commit

Permalink
fix(swingset): Finish vat tool RESM to NESM conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Aug 11, 2021
1 parent 6eb6ba6 commit b6e943b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 58 deletions.
1 change: 1 addition & 0 deletions packages/SwingSet/bin/rekernelize
58 changes: 0 additions & 58 deletions packages/SwingSet/bin/vat

This file was deleted.

1 change: 1 addition & 0 deletions packages/SwingSet/bin/vat
File renamed without changes.
63 changes: 63 additions & 0 deletions packages/SwingSet/tools/vat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node

// TODO Remove babel-standalone preinitialization
// https://github.com/endojs/endo/issues/768
import '@agoric/babel-standalone';
import '@agoric/install-ses';
import process from 'process';
import repl from 'repl';
import util from 'util';
import { loadBasedir, buildVatController } from '../src/index.js';
import { buildLoopbox } from '../src/devices/loopbox.js';

function deepLog(item) {
console.log(util.inspect(item, false, null, true));
}

async function main() {
const argv = process.argv.splice(2);
let withSES = true;
if (argv[0] === '--no-ses') {
withSES = false;
argv.shift();
}
const command = argv.shift();
if (command !== 'run' && command !== 'shell') {
throw new Error(`use 'vat run' or 'vat shell', not 'vat ${command}'`);
}
const basedir =
argv[0] === '--' || argv[0] === undefined ? '.' : argv.shift();
const vatArgv = argv[0] === '--' ? argv.slice(1) : argv;

const config = await loadBasedir(basedir);
const { loopboxSrcPath, loopboxEndowments } = buildLoopbox('immediate');
config.devices = [['loopbox', loopboxSrcPath, loopboxEndowments]];

const controller = await buildVatController(config, withSES, vatArgv);
if (command === 'run') {
await controller.run();
console.log('= vat finished');
} else if (command === 'shell') {
const r = repl.start({ prompt: 'vat> ', replMode: repl.REPL_MODE_STRICT });
r.context.dump = () => {
const d = controller.dump();
console.log('Kernel Table:');
deepLog(d.kernelTable);
console.log('Promises:');
deepLog(d.promises);
console.log('Run Queue:');
deepLog(d.runQueue);
};
r.context.dump2 = () => controller.dump();
r.context.run = () => {
console.log('run!');
controller.run();
};
r.context.step = () => {
console.log('step!');
controller.step();
};
}
}

main();

0 comments on commit b6e943b

Please sign in to comment.