Skip to content

Commit

Permalink
Merge pull request #128 from CMU-17313Q/implementing-the-iroh-tool-wi…
Browse files Browse the repository at this point in the history
…th-saada

Implementing the Iroh tool
  • Loading branch information
LujainAlMansoori authored Oct 29, 2023
2 parents 483e51d + 781581e commit dc024f0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .hegelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include:
- ./src/pubsub.ts
exclude:
- ./node_modules/**
58 changes: 58 additions & 0 deletions iroh/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable */
const Iroh = require("iroh");

let stage = new Iroh.Stage(`
function factorial(n) {
if (n === 0) return 1;
return n * factorial(n - 1);
};
factorial(3);
`);

// function call
stage.addListener(Iroh.CALL)
.on("before", (e) => {
let external = e.external ? "#external" : "";
console.log(" ".repeat(e.indent) + "call", e.name, external, "(", e.arguments, ")");
//console.log(e.getSource());
})
.on("after", (e) => {
let external = e.external ? "#external" : "";
console.log(" ".repeat(e.indent) + "call", e.name, "end", external, "->", [e.return]);
//console.log(e.getSource());
});

// function
stage.addListener(Iroh.FUNCTION)
.on("enter", (e) => {
let sloppy = e.sloppy ? "#sloppy" : "";
if (e.sloppy) {
console.log(" ".repeat(e.indent) + "call", e.name, sloppy, "(", e.arguments, ")");
//console.log(e.getSource());
}
})
.on("leave", (e) => {
let sloppy = e.sloppy ? "#sloppy" : "";
if (e.sloppy) {
console.log(" ".repeat(e.indent) + "call", e.name, "end", sloppy, "->", [void 0]);
//console.log(e.getSource());
}
})
.on("return", (e) => {
let sloppy = e.sloppy ? "#sloppy" : "";
if (e.sloppy) {
console.log(" ".repeat(e.indent) + "call", e.name, "end", sloppy, "->", [e.return]);
//console.log(e.getSource());
}
});

// program
stage.addListener(Iroh.PROGRAM)
.on("enter", (e) => {
console.log(" ".repeat(e.indent) + "Program");
})
.on("leave", (e) => {
console.log(" ".repeat(e.indent) + "Program end", "->", e.return);
});

eval(stage.script);
13 changes: 7 additions & 6 deletions src/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable import/order */

/* eslint-disable */
'use strict';

const fs = require('fs');
Expand Down Expand Up @@ -96,10 +95,12 @@ const configExists = file.existsSync(configFile) || (nconf.get('url') && nconf.g
prestart.loadConfig(configFile);
prestart.versionCheck();

if (!configExists && process.argv[2] !== 'setup') {
require('./setup').webInstall();
return;
}
(function () {
if (!configExists && process.argv[2] !== 'setup') {
require('./setup').webInstall();
}
}());


process.env.CONFIG = configFile;

Expand Down

0 comments on commit dc024f0

Please sign in to comment.