@forthic/interp 0.19.1 → 0.20.1
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/README.md +10 -0
- package/dist/cjs/forthic/interpreter.d.ts +4 -4
- package/dist/cjs/forthic/interpreter.js +13 -13
- package/dist/cjs/forthic/interpreter.js.map +1 -1
- package/dist/esm/forthic/interpreter.d.ts +4 -4
- package/dist/esm/forthic/interpreter.js +13 -13
- package/dist/esm/forthic/interpreter.js.map +1 -1
- package/package.json +5 -5
- package/dist/cjs/forthic/module-flag-manager.d.ts +0 -53
- package/dist/cjs/forthic/module-flag-manager.js +0 -87
- package/dist/cjs/forthic/module-flag-manager.js.map +0 -1
- package/dist/cjs/forthic/profiling-manager.d.ts +0 -39
- package/dist/cjs/forthic/profiling-manager.js +0 -77
- package/dist/cjs/forthic/profiling-manager.js.map +0 -1
- package/dist/cjs/forthic/streaming-manager.d.ts +0 -46
- package/dist/cjs/forthic/streaming-manager.js +0 -123
- package/dist/cjs/forthic/streaming-manager.js.map +0 -1
- package/dist/cjs/forthic/types.d.ts +0 -21
- package/dist/cjs/forthic/types.js +0 -6
- package/dist/cjs/forthic/types.js.map +0 -1
- package/dist/esm/forthic/module-flag-manager.d.ts +0 -53
- package/dist/esm/forthic/module-flag-manager.js +0 -83
- package/dist/esm/forthic/module-flag-manager.js.map +0 -1
- package/dist/esm/forthic/profiling-manager.d.ts +0 -39
- package/dist/esm/forthic/profiling-manager.js +0 -73
- package/dist/esm/forthic/profiling-manager.js.map +0 -1
- package/dist/esm/forthic/streaming-manager.d.ts +0 -46
- package/dist/esm/forthic/streaming-manager.js +0 -119
- package/dist/esm/forthic/streaming-manager.js.map +0 -1
- package/dist/esm/forthic/types.d.ts +0 -21
- package/dist/esm/forthic/types.js +0 -5
- package/dist/esm/forthic/types.js.map +0 -1
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProfilingManager = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Manages profiling functionality for the Forthic interpreter
|
|
6
|
-
*/
|
|
7
|
-
class ProfilingManager {
|
|
8
|
-
is_profiling = false;
|
|
9
|
-
start_profile_time = null;
|
|
10
|
-
timestamps = [];
|
|
11
|
-
word_counts = {};
|
|
12
|
-
/**
|
|
13
|
-
* Start profiling execution
|
|
14
|
-
*/
|
|
15
|
-
start_profiling() {
|
|
16
|
-
this.is_profiling = true;
|
|
17
|
-
this.timestamps = [];
|
|
18
|
-
this.start_profile_time = Date.now();
|
|
19
|
-
this.add_timestamp("START");
|
|
20
|
-
this.word_counts = {};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Stop profiling execution
|
|
24
|
-
*/
|
|
25
|
-
stop_profiling() {
|
|
26
|
-
this.add_timestamp("END");
|
|
27
|
-
this.is_profiling = false;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Count execution of a word (for profiling)
|
|
31
|
-
*/
|
|
32
|
-
count_word(word) {
|
|
33
|
-
if (!this.is_profiling)
|
|
34
|
-
return;
|
|
35
|
-
const name = word.name;
|
|
36
|
-
if (!this.word_counts[name])
|
|
37
|
-
this.word_counts[name] = 0;
|
|
38
|
-
this.word_counts[name] += 1;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Add a timestamp with label (for profiling)
|
|
42
|
-
*/
|
|
43
|
-
add_timestamp(label) {
|
|
44
|
-
if (!this.is_profiling)
|
|
45
|
-
return;
|
|
46
|
-
const timestamp = {
|
|
47
|
-
label: label,
|
|
48
|
-
time_ms: Date.now() - (this.start_profile_time || 0),
|
|
49
|
-
};
|
|
50
|
-
this.timestamps.push(timestamp);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Get word execution histogram sorted by count
|
|
54
|
-
*/
|
|
55
|
-
word_histogram() {
|
|
56
|
-
const items = [];
|
|
57
|
-
Object.keys(this.word_counts).forEach((name) => {
|
|
58
|
-
items.push({ word: name, count: this.word_counts[name] });
|
|
59
|
-
});
|
|
60
|
-
const result = items.sort((l, r) => r.count - l.count);
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Get all profile timestamps
|
|
65
|
-
*/
|
|
66
|
-
profile_timestamps() {
|
|
67
|
-
return this.timestamps;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Check if profiling is currently active
|
|
71
|
-
*/
|
|
72
|
-
is_profiling_active() {
|
|
73
|
-
return this.is_profiling;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.ProfilingManager = ProfilingManager;
|
|
77
|
-
//# sourceMappingURL=profiling-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profiling-manager.js","sourceRoot":"","sources":["../../../src/forthic/profiling-manager.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACH,MAAa,gBAAgB;IACnB,YAAY,GAAY,KAAK,CAAC;IAC9B,kBAAkB,GAAkB,IAAI,CAAC;IACzC,UAAU,GAAuB,EAAE,CAAC;IACpC,WAAW,GAA8B,EAAE,CAAC;IAEpD;;OAEG;IACH,eAAe;QACb,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACrC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,IAAU;QACnB,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,OAAO;QAC/B,MAAM,IAA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, CodeLocation } from "./tokenizer";
|
|
2
|
-
import { StringDelta } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Manages streaming execution functionality for the Forthic interpreter
|
|
5
|
-
*/
|
|
6
|
-
export declare class StreamingManager {
|
|
7
|
-
private streaming_token_index;
|
|
8
|
-
private stream;
|
|
9
|
-
private previous_delta_length;
|
|
10
|
-
/**
|
|
11
|
-
* Start streaming mode
|
|
12
|
-
*/
|
|
13
|
-
startStream(): void;
|
|
14
|
-
/**
|
|
15
|
-
* End streaming mode
|
|
16
|
-
*/
|
|
17
|
-
endStream(): void;
|
|
18
|
-
/**
|
|
19
|
-
* Check if streaming is currently active
|
|
20
|
-
*/
|
|
21
|
-
isStreaming(): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Get current streaming token index
|
|
24
|
-
*/
|
|
25
|
-
getStreamingTokenIndex(): number;
|
|
26
|
-
/**
|
|
27
|
-
* Set streaming token index
|
|
28
|
-
*/
|
|
29
|
-
setStreamingTokenIndex(index: number): void;
|
|
30
|
-
/**
|
|
31
|
-
* Get previous delta length
|
|
32
|
-
*/
|
|
33
|
-
getPreviousDeltaLength(): number;
|
|
34
|
-
/**
|
|
35
|
-
* Set previous delta length
|
|
36
|
-
*/
|
|
37
|
-
setPreviousDeltaLength(length: number): void;
|
|
38
|
-
/**
|
|
39
|
-
* Process streaming execution and yield tokens/deltas
|
|
40
|
-
*/
|
|
41
|
-
processStreamingExecution(codeStream: string, done: boolean, reference_location: CodeLocation | null, tokenHandler: (token: Token) => Promise<void>): AsyncGenerator<string | StringDelta, void, unknown>;
|
|
42
|
-
/**
|
|
43
|
-
* Find the last word or EOS token in the tokens array
|
|
44
|
-
*/
|
|
45
|
-
private findLastWordOrEOS;
|
|
46
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StreamingManager = void 0;
|
|
4
|
-
const tokenizer_1 = require("./tokenizer");
|
|
5
|
-
/**
|
|
6
|
-
* Manages streaming execution functionality for the Forthic interpreter
|
|
7
|
-
*/
|
|
8
|
-
class StreamingManager {
|
|
9
|
-
streaming_token_index = 0;
|
|
10
|
-
stream = false;
|
|
11
|
-
previous_delta_length = 0;
|
|
12
|
-
/**
|
|
13
|
-
* Start streaming mode
|
|
14
|
-
*/
|
|
15
|
-
startStream() {
|
|
16
|
-
this.stream = true;
|
|
17
|
-
this.previous_delta_length = 0;
|
|
18
|
-
this.streaming_token_index = 0;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* End streaming mode
|
|
22
|
-
*/
|
|
23
|
-
endStream() {
|
|
24
|
-
this.stream = false;
|
|
25
|
-
this.previous_delta_length = 0;
|
|
26
|
-
this.streaming_token_index = 0;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Check if streaming is currently active
|
|
30
|
-
*/
|
|
31
|
-
isStreaming() {
|
|
32
|
-
return this.stream;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Get current streaming token index
|
|
36
|
-
*/
|
|
37
|
-
getStreamingTokenIndex() {
|
|
38
|
-
return this.streaming_token_index;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Set streaming token index
|
|
42
|
-
*/
|
|
43
|
-
setStreamingTokenIndex(index) {
|
|
44
|
-
this.streaming_token_index = index;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Get previous delta length
|
|
48
|
-
*/
|
|
49
|
-
getPreviousDeltaLength() {
|
|
50
|
-
return this.previous_delta_length;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Set previous delta length
|
|
54
|
-
*/
|
|
55
|
-
setPreviousDeltaLength(length) {
|
|
56
|
-
this.previous_delta_length = length;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Process streaming execution and yield tokens/deltas
|
|
60
|
-
*/
|
|
61
|
-
async *processStreamingExecution(codeStream, done, reference_location, tokenHandler) {
|
|
62
|
-
// Create a new Tokenizer for the full string.
|
|
63
|
-
const tokenizer = new tokenizer_1.Tokenizer(codeStream, reference_location, done ? false : true);
|
|
64
|
-
const tokens = [];
|
|
65
|
-
let eosFound = false;
|
|
66
|
-
// Gather tokens from the beginning.
|
|
67
|
-
while (true) {
|
|
68
|
-
const token = tokenizer.next_token();
|
|
69
|
-
if (!token) {
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
// If we hit an EOS token then push it and break.
|
|
73
|
-
if (token.type === tokenizer_1.TokenType.EOS) {
|
|
74
|
-
tokens.push(token);
|
|
75
|
-
eosFound = true;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
tokens.push(token);
|
|
79
|
-
}
|
|
80
|
-
const delta = eosFound ? "" : tokenizer.get_string_delta();
|
|
81
|
-
let newStop = this.findLastWordOrEOS(tokens);
|
|
82
|
-
if (eosFound && !done) {
|
|
83
|
-
newStop--;
|
|
84
|
-
}
|
|
85
|
-
if (!eosFound && !done) {
|
|
86
|
-
newStop++;
|
|
87
|
-
}
|
|
88
|
-
// Execute only tokens we have not executed previously.
|
|
89
|
-
for (let i = this.streaming_token_index; i < newStop; i++) {
|
|
90
|
-
const token = tokens[i];
|
|
91
|
-
if (!token) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
await tokenHandler(token);
|
|
95
|
-
if (this.stream &&
|
|
96
|
-
(token.type !== tokenizer_1.TokenType.WORD || token.string !== "START_LOG")) {
|
|
97
|
-
yield token.string;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (this.stream && !eosFound) {
|
|
101
|
-
// Yield string delta if we're streaming and tokenizer has a delta
|
|
102
|
-
const newPortion = delta?.substring(this.previous_delta_length) || "";
|
|
103
|
-
if (newPortion) {
|
|
104
|
-
yield { stringDelta: newPortion };
|
|
105
|
-
}
|
|
106
|
-
this.previous_delta_length = delta?.length || 0;
|
|
107
|
-
}
|
|
108
|
-
if (done) {
|
|
109
|
-
this.endStream();
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
// Update our pointer and reset if done
|
|
113
|
-
this.streaming_token_index = newStop;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Find the last word or EOS token in the tokens array
|
|
117
|
-
*/
|
|
118
|
-
findLastWordOrEOS(tokens) {
|
|
119
|
-
return tokens.findLastIndex((token) => token.type === tokenizer_1.TokenType.WORD || token.type === tokenizer_1.TokenType.EOS);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
exports.StreamingManager = StreamingManager;
|
|
123
|
-
//# sourceMappingURL=streaming-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming-manager.js","sourceRoot":"","sources":["../../../src/forthic/streaming-manager.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAGxE;;GAEG;AACH,MAAa,gBAAgB;IACnB,qBAAqB,GAAW,CAAC,CAAC;IAClC,MAAM,GAAY,KAAK,CAAC;IACxB,qBAAqB,GAAW,CAAC,CAAC;IAE1C;;OAEG;IACH,WAAW;QACT,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,qBAAqB,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,qBAAqB,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,SAAS;QACP,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,qBAAqB,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,qBAAqB,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,sBAAsB;QACpB,OAAO,IAAI,CAAC,qBAAqB,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,sBAAsB,CAAC,KAAa;QAClC,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC;IACrC,CAAC;IAED;;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1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for the Forthic interpreter
|
|
3
|
-
*/
|
|
4
|
-
export interface ModuleFlags {
|
|
5
|
-
[key: string]: unknown;
|
|
6
|
-
}
|
|
7
|
-
export interface ScreenData {
|
|
8
|
-
[key: string]: string;
|
|
9
|
-
}
|
|
10
|
-
export interface WordCount {
|
|
11
|
-
word: string;
|
|
12
|
-
count: number;
|
|
13
|
-
}
|
|
14
|
-
export interface ProfileTimestamp {
|
|
15
|
-
label: string;
|
|
16
|
-
time_ms: number;
|
|
17
|
-
}
|
|
18
|
-
export type ModuleImportSpec = string | [string, string];
|
|
19
|
-
export interface StringDelta {
|
|
20
|
-
stringDelta: string;
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/forthic/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ModuleFlags } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Manages module flags for the Forthic interpreter.
|
|
4
|
-
*
|
|
5
|
-
* Module flags are temporary configuration values that affect word behavior.
|
|
6
|
-
* Key behavior: get_flags() returns current flags and resets them to defaults.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ModuleFlagManager {
|
|
9
|
-
private default_module_flags;
|
|
10
|
-
private module_flags;
|
|
11
|
-
/**
|
|
12
|
-
* Set default flags for a module
|
|
13
|
-
*
|
|
14
|
-
* @param module_id Unique identifier for the module
|
|
15
|
-
* @param flags Default flag values for the module
|
|
16
|
-
*/
|
|
17
|
-
set_flags(module_id: string, flags: ModuleFlags): void;
|
|
18
|
-
/**
|
|
19
|
-
* Get current flags for a module and reset them to defaults
|
|
20
|
-
*
|
|
21
|
-
* IMPORTANT: This method has side effects - it resets flags after reading them.
|
|
22
|
-
* This is the intended behavior for the Forthic flag system.
|
|
23
|
-
*
|
|
24
|
-
* @param module_id Unique identifier for the module
|
|
25
|
-
* @returns Current flag values (before reset)
|
|
26
|
-
*/
|
|
27
|
-
get_flags(module_id: string): ModuleFlags;
|
|
28
|
-
/**
|
|
29
|
-
* Modify (set) flags for a module without resetting to defaults
|
|
30
|
-
*
|
|
31
|
-
* @param module_id Unique identifier for the module
|
|
32
|
-
* @param flags Flag values to set/update
|
|
33
|
-
*/
|
|
34
|
-
modify_flags(module_id: string, flags: ModuleFlags): void;
|
|
35
|
-
/**
|
|
36
|
-
* Get current flags without resetting (for testing/debugging)
|
|
37
|
-
*
|
|
38
|
-
* @param module_id Unique identifier for the module
|
|
39
|
-
* @returns Current flag values (without reset)
|
|
40
|
-
*/
|
|
41
|
-
peek_flags(module_id: string): ModuleFlags;
|
|
42
|
-
/**
|
|
43
|
-
* Get default flags for a module (for testing/debugging)
|
|
44
|
-
*
|
|
45
|
-
* @param module_id Unique identifier for the module
|
|
46
|
-
* @returns Default flag values
|
|
47
|
-
*/
|
|
48
|
-
get_default_flags(module_id: string): ModuleFlags;
|
|
49
|
-
/**
|
|
50
|
-
* Reset all flags to defaults (useful for interpreter reset)
|
|
51
|
-
*/
|
|
52
|
-
reset_all_flags(): void;
|
|
53
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manages module flags for the Forthic interpreter.
|
|
3
|
-
*
|
|
4
|
-
* Module flags are temporary configuration values that affect word behavior.
|
|
5
|
-
* Key behavior: get_flags() returns current flags and resets them to defaults.
|
|
6
|
-
*/
|
|
7
|
-
export class ModuleFlagManager {
|
|
8
|
-
default_module_flags = {};
|
|
9
|
-
module_flags = {};
|
|
10
|
-
/**
|
|
11
|
-
* Set default flags for a module
|
|
12
|
-
*
|
|
13
|
-
* @param module_id Unique identifier for the module
|
|
14
|
-
* @param flags Default flag values for the module
|
|
15
|
-
*/
|
|
16
|
-
set_flags(module_id, flags) {
|
|
17
|
-
if (!this.default_module_flags) {
|
|
18
|
-
this.default_module_flags = {};
|
|
19
|
-
}
|
|
20
|
-
if (!this.module_flags) {
|
|
21
|
-
this.module_flags = {};
|
|
22
|
-
}
|
|
23
|
-
this.default_module_flags[module_id] = flags;
|
|
24
|
-
this.module_flags[module_id] = flags;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get current flags for a module and reset them to defaults
|
|
28
|
-
*
|
|
29
|
-
* IMPORTANT: This method has side effects - it resets flags after reading them.
|
|
30
|
-
* This is the intended behavior for the Forthic flag system.
|
|
31
|
-
*
|
|
32
|
-
* @param module_id Unique identifier for the module
|
|
33
|
-
* @returns Current flag values (before reset)
|
|
34
|
-
*/
|
|
35
|
-
get_flags(module_id) {
|
|
36
|
-
const module_flags = this.module_flags[module_id] || {};
|
|
37
|
-
const result = {};
|
|
38
|
-
// Copy current flag values
|
|
39
|
-
Object.keys(module_flags).forEach((k) => {
|
|
40
|
-
result[k] = module_flags[k];
|
|
41
|
-
});
|
|
42
|
-
// Reset flags to defaults
|
|
43
|
-
this.module_flags[module_id] = { ...this.default_module_flags[module_id] };
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Modify (set) flags for a module without resetting to defaults
|
|
48
|
-
*
|
|
49
|
-
* @param module_id Unique identifier for the module
|
|
50
|
-
* @param flags Flag values to set/update
|
|
51
|
-
*/
|
|
52
|
-
modify_flags(module_id, flags) {
|
|
53
|
-
const module_flags = this.module_flags[module_id] || {};
|
|
54
|
-
this.module_flags[module_id] = { ...module_flags, ...flags };
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Get current flags without resetting (for testing/debugging)
|
|
58
|
-
*
|
|
59
|
-
* @param module_id Unique identifier for the module
|
|
60
|
-
* @returns Current flag values (without reset)
|
|
61
|
-
*/
|
|
62
|
-
peek_flags(module_id) {
|
|
63
|
-
return this.module_flags[module_id] ? { ...this.module_flags[module_id] } : {};
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Get default flags for a module (for testing/debugging)
|
|
67
|
-
*
|
|
68
|
-
* @param module_id Unique identifier for the module
|
|
69
|
-
* @returns Default flag values
|
|
70
|
-
*/
|
|
71
|
-
get_default_flags(module_id) {
|
|
72
|
-
return this.default_module_flags[module_id] ? { ...this.default_module_flags[module_id] } : {};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Reset all flags to defaults (useful for interpreter reset)
|
|
76
|
-
*/
|
|
77
|
-
reset_all_flags() {
|
|
78
|
-
Object.keys(this.default_module_flags).forEach(module_id => {
|
|
79
|
-
this.module_flags[module_id] = { ...this.default_module_flags[module_id] };
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=module-flag-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module-flag-manager.js","sourceRoot":"","sources":["../../../src/forthic/module-flag-manager.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IACpB,oBAAoB,GAAmC,EAAE,CAAC;IAC1D,YAAY,GAAmC,EAAE,CAAC;IAE1D;;;;;OAKG;IACH,SAAS,CAAC,SAAiB,EAAE,KAAkB;QAC7C,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC/B,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;QACjC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACzB,CAAC;QAED,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QAC7C,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;IACvC,CAAC;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,SAAiB;QACzB,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QACxD,MAAM,MAAM,GAAgB,EAAE,CAAC;QAE/B,2B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CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Word } from "./module";
|
|
2
|
-
import { ProfileTimestamp, WordCount } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Manages profiling functionality for the Forthic interpreter
|
|
5
|
-
*/
|
|
6
|
-
export declare class ProfilingManager {
|
|
7
|
-
private is_profiling;
|
|
8
|
-
private start_profile_time;
|
|
9
|
-
private timestamps;
|
|
10
|
-
private word_counts;
|
|
11
|
-
/**
|
|
12
|
-
* Start profiling execution
|
|
13
|
-
*/
|
|
14
|
-
start_profiling(): void;
|
|
15
|
-
/**
|
|
16
|
-
* Stop profiling execution
|
|
17
|
-
*/
|
|
18
|
-
stop_profiling(): void;
|
|
19
|
-
/**
|
|
20
|
-
* Count execution of a word (for profiling)
|
|
21
|
-
*/
|
|
22
|
-
count_word(word: Word): void;
|
|
23
|
-
/**
|
|
24
|
-
* Add a timestamp with label (for profiling)
|
|
25
|
-
*/
|
|
26
|
-
add_timestamp(label: string): void;
|
|
27
|
-
/**
|
|
28
|
-
* Get word execution histogram sorted by count
|
|
29
|
-
*/
|
|
30
|
-
word_histogram(): WordCount[];
|
|
31
|
-
/**
|
|
32
|
-
* Get all profile timestamps
|
|
33
|
-
*/
|
|
34
|
-
profile_timestamps(): ProfileTimestamp[];
|
|
35
|
-
/**
|
|
36
|
-
* Check if profiling is currently active
|
|
37
|
-
*/
|
|
38
|
-
is_profiling_active(): boolean;
|
|
39
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manages profiling functionality for the Forthic interpreter
|
|
3
|
-
*/
|
|
4
|
-
export class ProfilingManager {
|
|
5
|
-
is_profiling = false;
|
|
6
|
-
start_profile_time = null;
|
|
7
|
-
timestamps = [];
|
|
8
|
-
word_counts = {};
|
|
9
|
-
/**
|
|
10
|
-
* Start profiling execution
|
|
11
|
-
*/
|
|
12
|
-
start_profiling() {
|
|
13
|
-
this.is_profiling = true;
|
|
14
|
-
this.timestamps = [];
|
|
15
|
-
this.start_profile_time = Date.now();
|
|
16
|
-
this.add_timestamp("START");
|
|
17
|
-
this.word_counts = {};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Stop profiling execution
|
|
21
|
-
*/
|
|
22
|
-
stop_profiling() {
|
|
23
|
-
this.add_timestamp("END");
|
|
24
|
-
this.is_profiling = false;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Count execution of a word (for profiling)
|
|
28
|
-
*/
|
|
29
|
-
count_word(word) {
|
|
30
|
-
if (!this.is_profiling)
|
|
31
|
-
return;
|
|
32
|
-
const name = word.name;
|
|
33
|
-
if (!this.word_counts[name])
|
|
34
|
-
this.word_counts[name] = 0;
|
|
35
|
-
this.word_counts[name] += 1;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Add a timestamp with label (for profiling)
|
|
39
|
-
*/
|
|
40
|
-
add_timestamp(label) {
|
|
41
|
-
if (!this.is_profiling)
|
|
42
|
-
return;
|
|
43
|
-
const timestamp = {
|
|
44
|
-
label: label,
|
|
45
|
-
time_ms: Date.now() - (this.start_profile_time || 0),
|
|
46
|
-
};
|
|
47
|
-
this.timestamps.push(timestamp);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get word execution histogram sorted by count
|
|
51
|
-
*/
|
|
52
|
-
word_histogram() {
|
|
53
|
-
const items = [];
|
|
54
|
-
Object.keys(this.word_counts).forEach((name) => {
|
|
55
|
-
items.push({ word: name, count: this.word_counts[name] });
|
|
56
|
-
});
|
|
57
|
-
const result = items.sort((l, r) => r.count - l.count);
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get all profile timestamps
|
|
62
|
-
*/
|
|
63
|
-
profile_timestamps() {
|
|
64
|
-
return this.timestamps;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Check if profiling is currently active
|
|
68
|
-
*/
|
|
69
|
-
is_profiling_active() {
|
|
70
|
-
return this.is_profiling;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=profiling-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profiling-manager.js","sourceRoot":"","sources":["../../../src/forthic/profiling-manager.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACnB,YAAY,GAAY,KAAK,CAAC;IAC9B,kBAAkB,GAAkB,IAAI,CAAC;IACzC,UAAU,GAAuB,EAAE,CAAC;IACpC,WAAW,GAA8B,EAAE,CAAC;IAEpD;;OAEG;IACH,eAAe;QACb,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACrC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,IAAU;QACnB,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,OAAO;QAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,KAAa;QACzB,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,OAAO;QAC/B,MAAM,SAAS,GAAqB;YAClC,KAAK,EAAE,KAAK;YACZ,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,CAAC;SACrD,CAAC;QACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,MAAM,KAAK,GAAgB,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC7C,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Token, CodeLocation } from "./tokenizer";
|
|
2
|
-
import { StringDelta } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Manages streaming execution functionality for the Forthic interpreter
|
|
5
|
-
*/
|
|
6
|
-
export declare class StreamingManager {
|
|
7
|
-
private streaming_token_index;
|
|
8
|
-
private stream;
|
|
9
|
-
private previous_delta_length;
|
|
10
|
-
/**
|
|
11
|
-
* Start streaming mode
|
|
12
|
-
*/
|
|
13
|
-
startStream(): void;
|
|
14
|
-
/**
|
|
15
|
-
* End streaming mode
|
|
16
|
-
*/
|
|
17
|
-
endStream(): void;
|
|
18
|
-
/**
|
|
19
|
-
* Check if streaming is currently active
|
|
20
|
-
*/
|
|
21
|
-
isStreaming(): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Get current streaming token index
|
|
24
|
-
*/
|
|
25
|
-
getStreamingTokenIndex(): number;
|
|
26
|
-
/**
|
|
27
|
-
* Set streaming token index
|
|
28
|
-
*/
|
|
29
|
-
setStreamingTokenIndex(index: number): void;
|
|
30
|
-
/**
|
|
31
|
-
* Get previous delta length
|
|
32
|
-
*/
|
|
33
|
-
getPreviousDeltaLength(): number;
|
|
34
|
-
/**
|
|
35
|
-
* Set previous delta length
|
|
36
|
-
*/
|
|
37
|
-
setPreviousDeltaLength(length: number): void;
|
|
38
|
-
/**
|
|
39
|
-
* Process streaming execution and yield tokens/deltas
|
|
40
|
-
*/
|
|
41
|
-
processStreamingExecution(codeStream: string, done: boolean, reference_location: CodeLocation | null, tokenHandler: (token: Token) => Promise<void>): AsyncGenerator<string | StringDelta, void, unknown>;
|
|
42
|
-
/**
|
|
43
|
-
* Find the last word or EOS token in the tokens array
|
|
44
|
-
*/
|
|
45
|
-
private findLastWordOrEOS;
|
|
46
|
-
}
|