diff --git a/lib/bourdoncle.js b/lib/bourdoncle.js index 835b0dec..d2ff0f52 100644 --- a/lib/bourdoncle.js +++ b/lib/bourdoncle.js @@ -3,7 +3,7 @@ /* ------------------------------------------------------------- */ /* Author : Jayanth Krishnamurthy */ /* Creation : Tue Jul 9 11:59:33 2019 */ -/* Last change : Mon Dec 4 08:21:54 2023 (serrano) */ +/* Last change : Thu Dec 7 16:32:30 2023 (serrano) */ /* Copyright : 2020-23 Inria */ /* ------------------------------------------------------------- */ /* HipHop causality error messages */ @@ -202,7 +202,7 @@ function findCausalityErrorDeep(machine, compilePhase = false) { tccLocInfo[ solComponent[ i ].debug_id ] = tcc_loc[ i ]; } - let { cycle,posFlag }= findCycleLength(tccLocInfo); + let { cycle, posFlag }= findCycleLength(tccLocInfo); cycle.len = cycle.length; let tempFileList = []; let cycleLength = 0; @@ -264,16 +264,14 @@ function findCausalityErrorDeep(machine, compilePhase = false) { const finalResult = Object.keys(tarjanComponent) .map(key => tarjanComponent[key]); - let myJSON = JSON.stringify(finalResult); - // remove nets.dfn and nets.head cleanNets(); return { - loc: myJSON, + loc: false, size: cycle.len, signals: tempSignal, - json: myJSON, + json: JSON.stringify(finalResult), posFlag: posFlag, cycles: finalResult } diff --git a/lib/error.js b/lib/error.js index c0430cff..5c764a64 100644 --- a/lib/error.js +++ b/lib/error.js @@ -3,7 +3,7 @@ /* ------------------------------------------------------------- */ /* Author : Manuel Serrano */ /* Creation : Thu Aug 2 12:32:26 2018 */ -/* Last change : Fri Dec 1 07:03:53 2023 (serrano) */ +/* Last change : Thu Dec 7 15:04:50 2023 (serrano) */ /* Copyright : 2018-23 Manuel Serrano */ /* ------------------------------------------------------------- */ /* HipHop exception constructors. */ @@ -53,7 +53,7 @@ function HHTypeError(msg, loc) { const stk = err.stack; let i = stk.indexOf("\n"); let nstk = stk.substring(0, i); - nstk += `"\n at HipHop (file://${loc.filename}:${loc.pos})` + nstk += `\n at HipHop (file://${loc.filename}:${loc.pos})` nstk += stk.substring(i); err.stack = nstk; } diff --git a/lib/machine.js b/lib/machine.js index a579e255..62ac2782 100644 --- a/lib/machine.js +++ b/lib/machine.js @@ -3,7 +3,7 @@ /* ------------------------------------------------------------- */ /* Author : Manuel Serrano */ /* Creation : Tue Jul 17 08:19:22 2018 */ -/* Last change : Thu Dec 7 14:37:13 2023 (serrano) */ +/* Last change : Thu Dec 7 16:18:43 2023 (serrano) */ /* Copyright : 2018-23 Manuel Serrano */ /* ------------------------------------------------------------- */ /* HipHop reactive machines */ @@ -579,22 +579,25 @@ function react(mach) { if (nonpropagated_nets > 0) { const { loc, size, signals, json, cycles } = findCausalityError(mach); - if (hop.isServer) { - dumpCausalityError(json); - } - - let nets = mach.nets.filter(n => !n.isInKnownList); - // Checking the error type if (size > 0) { - if (mach.verbose >=0) { - console.error(`*** CAUSALITY ERROR: cycle of length ${size} detected, involving signals "${signals.join(', ')}"`); - if (cycles && hop.isServer) { - reportCausalityCycles(cycles); + if (mach.verbose >= 0) { + console.error(`*** CAUSALITY ERROR: cycle detected involving signals "${signals.join(', ')}"`); + if (hop.isServer) { + if (cycles.length > 0) { + reportCausalityCycles(cycles); + dumpCausalityError(json); + } else { + const { json: djson, cycles: dcycles } = findCausalityErrorDefault(mach); + reportCausalityCycles(dcycles); + dumpCausalityError(djson); + } } } throw error.CausalityError("causality error"); } else { + let nets = mach.nets.filter(n => !n.isInKnownList); + throw error.CausalityError(`internal causality error: ${nets.map(n => n.debug_name).toString()}`, nets[0].ast_node.loc); } } @@ -815,6 +818,23 @@ function findCausalityErrorDefault(machine) { return res; } + function findCycleSources() { + let nets = machine.nets.filter(n => !n.isInKnownList); + const cycles = {}; + nets.forEach(nets => { + const { filename, pos } = nets.ast_node.loc; + if (typeof pos === "number") { + if (filename in cycles) { + cycles[filename].push(pos); + } else { + cycles[filename] = [pos]; + } + } + }); + + return Object.keys(cycles).map(k => [{ filename: k, locations: cycles[k] }]); + } + function cycleSize(src) { let stack = []; let res = 0; @@ -835,13 +855,14 @@ function findCausalityErrorDefault(machine) { let head = nets.find(isCyclic); if (head) { + const cycles = findCycleSources(); return { loc: head.ast_node.loc, size: cycleSize(head), signals: findCycleSignals(head), - json: null, + json: JSON.stringify(cycles), posFlag: undefined, - cycles: null + cycles: cycles }; } else { return { diff --git a/modules/http.hh.js b/modules/http.hh.js index 8c04233f..01fceaac 100644 --- a/modules/http.hh.js +++ b/modules/http.hh.js @@ -1,9 +1,9 @@ /*=====================================================================*/ -/* serrano/prgm/project/hiphop/hiphop/modules/http.hh.js */ +/* serrano/prgm/project/hiphop/1.3.x/modules/http.hh.js */ /* ------------------------------------------------------------- */ /* Author : manuel serrano */ /* Creation : Tue Jan 11 18:12:15 2022 */ -/* Last change : Fri Sep 15 16:15:44 2023 (serrano) */ +/* Last change : Thu Dec 7 14:55:48 2023 (serrano) */ /* Copyright : 2022-23 manuel serrano */ /* ------------------------------------------------------------- */ /* HTTP HipHop module. */ @@ -16,8 +16,9 @@ /*---------------------------------------------------------------------*/ import * as http from "http"; import * as https from "https"; +import { parse } from "url"; -export { request, HttpRequest }; +export { httpRequest, HttpRequest }; /*---------------------------------------------------------------------*/ /* debug ... */ @@ -36,16 +37,16 @@ function debug_url(protocol, options) { } /*---------------------------------------------------------------------*/ -/* Http ... */ +/* HttpRequest ... */ /*---------------------------------------------------------------------*/ hiphop interface HttpRequest { - out result; + out response; } /*---------------------------------------------------------------------*/ /* request ... */ /*---------------------------------------------------------------------*/ -hiphop module request(protocol, options, payload = undefined) implements HttpRequest { +hiphop module httpRequest(requestOrUrl, payload = undefined) implements HttpRequest { let state = "active"; let buf = ""; let req = false; @@ -53,13 +54,20 @@ hiphop module request(protocol, options, payload = undefined) implements HttpReq let res = undefined; let self; - async (result) { - const proto = (protocol === "https" ? https : http); + async (response) { + let request; + + if (typeof requestOrUrl === "string") { + request = parse(requestOrUrl); + } else { + request = requestOrUrl; + } + const proto = ((request?.protocol === "https:" ?? request?.protocol === "https") ? https : http); self = this; - req = proto.request(options, _res => { + req = proto.request(request, _res => { res = _res; if (debug()) { - console.error("*** HTTP_DEBUG [" + debug_url(protocol, options) + "]", + console.error("*** HTTP_DEBUG [" + debug_url(protocol, request) + "]", "statusCode: " + res.statusCode); } if (res.statusCode !== 200) { @@ -70,7 +78,7 @@ hiphop module request(protocol, options, payload = undefined) implements HttpReq res.buffer = buf; if (debug()) { - console.error("*** HTTP_DEBUG [" + debug_url(protocol, options) + "]", + console.error("*** HTTP_DEBUG [" + debug_url(protocol, request) + "]", "buf: [" + buf + "]"); } @@ -92,7 +100,7 @@ hiphop module request(protocol, options, payload = undefined) implements HttpReq req.on('error', error => { if (debug()) { - console.error("*** HTTP_DEBUG [" + debug_url(protocol, options) + "]", + console.error("*** HTTP_DEBUG [" + debug_url(protocol, request) + "]", "error: " + error); } if (state === "active") self.notify("error");