@jdeighan/coffee-utils 6.0.4 → 6.0.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "6.0.4",
4
+ "version": "6.0.5",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -1,8 +1,17 @@
1
1
  # call_stack.coffee
2
2
 
3
- import {undef, croak} from '@jdeighan/coffee-utils'
3
+ import {undef, croak, assert} from '@jdeighan/coffee-utils'
4
4
  import {log, LOG} from '@jdeighan/coffee-utils/log'
5
5
 
6
+ doDebugStack = false
7
+
8
+ # ---------------------------------------------------------------------------
9
+
10
+ export debugStack = (flag=true) ->
11
+
12
+ doDebugStack = flag
13
+ return
14
+
6
15
  # ---------------------------------------------------------------------------
7
16
 
8
17
  export class CallStack
@@ -15,26 +24,36 @@ export class CallStack
15
24
 
16
25
  call: (funcName, hInfo) ->
17
26
 
27
+ if doDebugStack
28
+ LOG "[CALL #{funcName}]"
18
29
  @lStack.push({funcName, hInfo})
19
30
  return
20
31
 
21
32
  # ........................................................................
22
33
 
23
- returnFrom: (fName) ->
34
+ returnFrom: (funcName) ->
24
35
 
36
+ if doDebugStack
37
+ LOG "[RETURN FROM #{funcName}]"
25
38
  if @lStack.length == 0
26
- LOG "returnFrom('#{fName}') but stack is empty"
39
+ LOG "returnFrom('#{funcName}') but stack is empty"
27
40
  return undef
28
- {funcName, hInfo} = @lStack.pop()
29
- if funcName != fName
41
+ TOSfName = @lStack[@lStack.length-1].funcName
42
+ if funcName == TOSfName
43
+ {funcName, hInfo} = @lStack.pop()
44
+ assert funcName==TOSfName, "Bad func name on stack"
45
+ return hInfo
46
+ else
30
47
  @dump()
31
- LOG "returnFrom('#{fName}') but TOS is '#{funcName}'"
32
- return hInfo
48
+ LOG "returnFrom('#{funcName}') but TOS is '#{TOSfName}'"
49
+ return undef
33
50
 
34
51
  # ........................................................................
35
52
 
36
53
  reset: () ->
37
54
 
55
+ if doDebugStack
56
+ LOG "RESET STACK"
38
57
  @lStack = []
39
58
 
40
59
  # ........................................................................
package/src/call_stack.js CHANGED
@@ -1,8 +1,11 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
- // call_stack.coffee
2
+ // call_stack.coffee
3
+ var doDebugStack;
4
+
3
5
  import {
4
6
  undef,
5
- croak
7
+ croak,
8
+ assert
6
9
  } from '@jdeighan/coffee-utils';
7
10
 
8
11
  import {
@@ -10,6 +13,13 @@ import {
10
13
  LOG
11
14
  } from '@jdeighan/coffee-utils/log';
12
15
 
16
+ doDebugStack = false;
17
+
18
+ // ---------------------------------------------------------------------------
19
+ export var debugStack = function(flag = true) {
20
+ doDebugStack = flag;
21
+ };
22
+
13
23
  // ---------------------------------------------------------------------------
14
24
  export var CallStack = class CallStack {
15
25
  constructor() {
@@ -18,26 +28,39 @@ export var CallStack = class CallStack {
18
28
 
19
29
  // ........................................................................
20
30
  call(funcName, hInfo) {
31
+ if (doDebugStack) {
32
+ LOG(`[CALL ${funcName}]`);
33
+ }
21
34
  this.lStack.push({funcName, hInfo});
22
35
  }
23
36
 
24
37
  // ........................................................................
25
- returnFrom(fName) {
26
- var funcName, hInfo;
38
+ returnFrom(funcName) {
39
+ var TOSfName, hInfo;
40
+ if (doDebugStack) {
41
+ LOG(`[RETURN FROM ${funcName}]`);
42
+ }
27
43
  if (this.lStack.length === 0) {
28
- LOG(`returnFrom('${fName}') but stack is empty`);
44
+ LOG(`returnFrom('${funcName}') but stack is empty`);
29
45
  return undef;
30
46
  }
31
- ({funcName, hInfo} = this.lStack.pop());
32
- if (funcName !== fName) {
47
+ TOSfName = this.lStack[this.lStack.length - 1].funcName;
48
+ if (funcName === TOSfName) {
49
+ ({funcName, hInfo} = this.lStack.pop());
50
+ assert(funcName === TOSfName, "Bad func name on stack");
51
+ return hInfo;
52
+ } else {
33
53
  this.dump();
34
- LOG(`returnFrom('${fName}') but TOS is '${funcName}'`);
54
+ LOG(`returnFrom('${funcName}') but TOS is '${TOSfName}'`);
55
+ return undef;
35
56
  }
36
- return hInfo;
37
57
  }
38
58
 
39
59
  // ........................................................................
40
60
  reset() {
61
+ if (doDebugStack) {
62
+ LOG("RESET STACK");
63
+ }
41
64
  return this.lStack = [];
42
65
  }
43
66