@fraczak/k 4.0.2 → 4.0.3
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 +44 -4
- package/demo.cast +1772 -0
- package/demo.gif +0 -0
- package/demo2.cast +1705 -0
- package/demo_optimized.gif +0 -0
- package/package.json +1 -1
- package/repl.mjs +10 -10
- package/sc.py +25 -0
|
Binary file
|
package/package.json
CHANGED
package/repl.mjs
CHANGED
|
@@ -15,11 +15,11 @@ console.log("Very! experimental repl shell for 'k-language'...");
|
|
|
15
15
|
const help = function () {
|
|
16
16
|
// console.log(" --debug loads codes and relations as value");
|
|
17
17
|
console.log(" --c print aliased codes");
|
|
18
|
-
console.log(" --C code print code definition");
|
|
19
|
-
console.log(" --r print
|
|
20
|
-
console.log(" --R rel print
|
|
18
|
+
console.log(" --C code print 'code' definition");
|
|
19
|
+
console.log(" --r print relations");
|
|
20
|
+
console.log(" --R rel print 'rel' definition with type patterns");
|
|
21
21
|
console.log(" --p (--pp) pretty-print last value");
|
|
22
|
-
console.log(" --s (--g) reg store (get) the
|
|
22
|
+
console.log(" --s (--g) reg store (get) the current value in (from) register 'reg'");
|
|
23
23
|
console.log(" --regs print register names");
|
|
24
24
|
console.log(" --l file.k load 'file.k'");
|
|
25
25
|
};
|
|
@@ -54,7 +54,7 @@ const printVal = function (v = val) {
|
|
|
54
54
|
if (v === undefined)
|
|
55
55
|
console.log("...",v);
|
|
56
56
|
else
|
|
57
|
-
console.log(
|
|
57
|
+
console.log(`--> ${JSON.stringify(v)}`);
|
|
58
58
|
rl.setPrompt('> ');
|
|
59
59
|
}
|
|
60
60
|
const registers = {};
|
|
@@ -100,10 +100,9 @@ function evaluate(line) {
|
|
|
100
100
|
return result;
|
|
101
101
|
}
|
|
102
102
|
return (function (prettyRel) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
result[relName] = prettyRel(ref1[relName].def);
|
|
103
|
+
for (const relName in defs.rels) {
|
|
104
|
+
if (relName != "__main__")
|
|
105
|
+
result[relName] = prettyRel(defs.rels[relName].def);
|
|
107
106
|
}
|
|
108
107
|
return result;
|
|
109
108
|
})(
|
|
@@ -172,7 +171,8 @@ function evaluate(line) {
|
|
|
172
171
|
// for (const filter of filters) {
|
|
173
172
|
const pcodef= prettyCode.bind(null, run.defs.representatives);
|
|
174
173
|
const filtersStr = filters.map( x => prettyRel(pcodef, {op: "filter", filter: x}));
|
|
175
|
-
console.log(` ${relName} :
|
|
174
|
+
console.log(` ${relName} : ${filtersStr[0]} --> ${filtersStr[1]}`);
|
|
175
|
+
console.log(` ${relName} = ${prettyRel(pcodef,rel.def)};`);
|
|
176
176
|
// }
|
|
177
177
|
// ------ k code
|
|
178
178
|
} else if (!line.match(/^[ \n\t]*(?:#.*)?$/)) {
|
package/sc.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
# Check if file is provided
|
|
5
|
+
if len(sys.argv) != 3:
|
|
6
|
+
print("Usage: python speedup_cast.py input.cast output.cast")
|
|
7
|
+
sys.exit(1)
|
|
8
|
+
|
|
9
|
+
input_file = sys.argv[1]
|
|
10
|
+
output_file = sys.argv[2]
|
|
11
|
+
speedup_factor = 0.5 # 2x speed
|
|
12
|
+
|
|
13
|
+
# Load the original cast file
|
|
14
|
+
with open(input_file, 'r') as f:
|
|
15
|
+
cast = json.load(f)
|
|
16
|
+
|
|
17
|
+
# Update the timing of each event
|
|
18
|
+
for event in cast['stdout']:
|
|
19
|
+
event[0] = event[0] * speedup_factor
|
|
20
|
+
|
|
21
|
+
# Save the modified cast file
|
|
22
|
+
with open(output_file, 'w') as f:
|
|
23
|
+
json.dump(cast, f)
|
|
24
|
+
|
|
25
|
+
print(f"Successfully sped up {input_file} and saved to {output_file}")
|