rooklang 0.3.3 → 0.4.0
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 +34 -7
- package/README.ru.md +34 -7
- package/dist/ast/declarations.d.ts +39 -4
- package/dist/ast/expressions.d.ts +34 -8
- package/dist/ast/markup.d.ts +6 -1
- package/dist/ast/statements.d.ts +28 -2
- package/dist/auto-import.d.ts +11 -0
- package/dist/auto-import.js +81 -0
- package/dist/breaks.d.ts +6 -0
- package/dist/breaks.js +36 -0
- package/dist/build.d.ts +7 -0
- package/dist/build.js +23 -2
- package/dist/checker/array-literals.d.ts +6 -0
- package/dist/checker/array-literals.js +59 -0
- package/dist/checker/assignments.d.ts +4 -0
- package/dist/checker/assignments.js +23 -3
- package/dist/checker/base.d.ts +8 -2
- package/dist/checker/base.js +7 -7
- package/dist/checker/builtins.js +22 -8
- package/dist/checker/bytes.d.ts +2 -2
- package/dist/checker/bytes.js +2 -2
- package/dist/checker/calls.js +3 -0
- package/dist/checker/channel-objects.d.ts +3 -0
- package/dist/checker/channel-objects.js +40 -0
- package/dist/checker/channels.d.ts +1 -0
- package/dist/checker/channels.js +17 -4
- package/dist/checker/checker.d.ts +1 -1
- package/dist/checker/checker.js +19 -0
- package/dist/checker/class-members.d.ts +22 -0
- package/dist/checker/class-members.js +105 -0
- package/dist/checker/classes.d.ts +5 -4
- package/dist/checker/classes.js +48 -13
- package/dist/checker/closing.d.ts +21 -0
- package/dist/checker/closing.js +164 -0
- package/dist/checker/completion.d.ts +3 -3
- package/dist/checker/completion.js +4 -3
- package/dist/checker/component-bindings.d.ts +7 -0
- package/dist/checker/component-bindings.js +45 -0
- package/dist/checker/component-values.js +10 -7
- package/dist/checker/components.d.ts +2 -2
- package/dist/checker/components.js +8 -3
- package/dist/checker/context.d.ts +41 -5
- package/dist/checker/context.js +23 -0
- package/dist/checker/control-flow.d.ts +11 -5
- package/dist/checker/control-flow.js +65 -40
- package/dist/checker/declarations.d.ts +2 -2
- package/dist/checker/declarations.js +4 -2
- package/dist/checker/decode.d.ts +8 -0
- package/dist/checker/decode.js +32 -0
- package/dist/checker/decorator-exports.js +4 -0
- package/dist/checker/decorator-includes.d.ts +9 -0
- package/dist/checker/decorator-includes.js +71 -0
- package/dist/checker/decorator-members.d.ts +8 -10
- package/dist/checker/decorator-members.js +28 -31
- package/dist/checker/decorator-wrappers.d.ts +1 -1
- package/dist/checker/decorator-wrappers.js +3 -2
- package/dist/checker/decorators.d.ts +14 -5
- package/dist/checker/decorators.js +52 -25
- package/dist/checker/expressions.d.ts +6 -2
- package/dist/checker/expressions.js +20 -40
- package/dist/checker/flow.d.ts +25 -3
- package/dist/checker/flow.js +56 -12
- package/dist/checker/functions.d.ts +2 -2
- package/dist/checker/functions.js +9 -5
- package/dist/checker/helpers.d.ts +5 -2
- package/dist/checker/helpers.js +16 -4
- package/dist/checker/imports.js +5 -2
- package/dist/checker/iterables.d.ts +3 -1
- package/dist/checker/iterables.js +13 -0
- package/dist/checker/iterators.d.ts +4 -1
- package/dist/checker/iterators.js +12 -4
- package/dist/checker/json.d.ts +5 -0
- package/dist/checker/json.js +92 -0
- package/dist/checker/loops.d.ts +2 -0
- package/dist/checker/loops.js +50 -5
- package/dist/checker/markup.js +14 -2
- package/dist/checker/members.js +10 -1
- package/dist/checker/operators.d.ts +2 -2
- package/dist/checker/operators.js +7 -5
- package/dist/checker/queues.d.ts +2 -2
- package/dist/checker/queues.js +2 -2
- package/dist/checker/resolution.js +5 -3
- package/dist/checker/shared-state.d.ts +11 -0
- package/dist/checker/shared-state.js +37 -0
- package/dist/checker/signals.d.ts +8 -0
- package/dist/checker/signals.js +48 -0
- package/dist/checker/statements.d.ts +5 -2
- package/dist/checker/statements.js +51 -22
- package/dist/checker/tagged-unions.d.ts +37 -0
- package/dist/checker/tagged-unions.js +132 -0
- package/dist/checker/topics.d.ts +6 -0
- package/dist/checker/topics.js +17 -0
- package/dist/checker/transfer.d.ts +3 -1
- package/dist/checker/transfer.js +25 -5
- package/dist/checker/try.d.ts +6 -0
- package/dist/checker/try.js +19 -0
- package/dist/checker/types/constructors.d.ts +1 -1
- package/dist/checker/types/constructors.js +2 -2
- package/dist/checker/types/generics.js +1 -1
- package/dist/checker/types/iterables.d.ts +13 -0
- package/dist/checker/types/iterables.js +52 -0
- package/dist/checker/types/model.d.ts +25 -0
- package/dist/checker/types/params.js +22 -3
- package/dist/checker/types/printing.js +4 -3
- package/dist/checker/types/relations.js +19 -25
- package/dist/checker/types/topic.d.ts +6 -0
- package/dist/checker/types/topic.js +23 -0
- package/dist/checker/types.d.ts +2 -0
- package/dist/checker/types.js +2 -0
- package/dist/checker/untyped-globals.d.ts +1 -0
- package/dist/checker/untyped-globals.js +3 -1
- package/dist/cli.js +18 -36
- package/dist/codegen/attributes.d.ts +4 -0
- package/dist/codegen/attributes.js +24 -2
- package/dist/codegen/calls.d.ts +23 -0
- package/dist/codegen/calls.js +88 -7
- package/dist/codegen/component-helpers.d.ts +6 -1
- package/dist/codegen/component-helpers.js +6 -1
- package/dist/codegen/component-props.d.ts +11 -2
- package/dist/codegen/component-props.js +50 -5
- package/dist/codegen/components.d.ts +6 -5
- package/dist/codegen/components.js +44 -21
- package/dist/codegen/control-flow.d.ts +2 -0
- package/dist/codegen/control-flow.js +23 -9
- package/dist/codegen/control-statements.d.ts +10 -2
- package/dist/codegen/control-statements.js +56 -19
- package/dist/codegen/creation.js +5 -2
- package/dist/codegen/decode.d.ts +14 -0
- package/dist/codegen/decode.js +93 -0
- package/dist/codegen/early-returns.d.ts +4 -3
- package/dist/codegen/early-returns.js +17 -5
- package/dist/codegen/emitter.d.ts +13 -41
- package/dist/codegen/emitter.js +27 -8
- package/dist/codegen/expressions.d.ts +9 -0
- package/dist/codegen/expressions.js +15 -26
- package/dist/codegen/functions.d.ts +11 -1
- package/dist/codegen/functions.js +31 -3
- package/dist/codegen/js.d.ts +2 -2
- package/dist/codegen/js.js +5 -2
- package/dist/codegen/live.d.ts +60 -0
- package/dist/codegen/live.js +29 -0
- package/dist/codegen/mutations.d.ts +7 -0
- package/dist/codegen/mutations.js +43 -2
- package/dist/codegen/options.d.ts +42 -0
- package/dist/codegen/options.js +1 -0
- package/dist/codegen/reactive.d.ts +4 -59
- package/dist/codegen/reactive.js +34 -72
- package/dist/codegen/runtime.d.ts +7 -3
- package/dist/codegen/runtime.js +33 -14
- package/dist/codegen/shared.d.ts +22 -0
- package/dist/codegen/shared.js +93 -0
- package/dist/codegen/simple-statements.d.ts +11 -5
- package/dist/codegen/simple-statements.js +40 -15
- package/dist/codegen/statements.d.ts +5 -0
- package/dist/codegen/statements.js +99 -4
- package/dist/codegen/try.d.ts +5 -0
- package/dist/codegen/try.js +40 -0
- package/dist/codegen/updates.d.ts +11 -3
- package/dist/codegen/updates.js +52 -4
- package/dist/codegen/web-components.d.ts +2 -2
- package/dist/codegen/web-components.js +2 -2
- package/dist/compile.d.ts +9 -0
- package/dist/compile.js +25 -8
- package/dist/completion.d.ts +4 -2
- package/dist/completion.js +10 -5
- package/dist/declarations.js +32 -6
- package/dist/decorator-copy.d.ts +1 -1
- package/dist/decorator-copy.js +6 -2
- package/dist/decorator-names.d.ts +14 -0
- package/dist/decorator-names.js +56 -0
- package/dist/decorators.d.ts +2 -3
- package/dist/decorators.js +36 -14
- package/dist/goroutines.d.ts +1 -1
- package/dist/goroutines.js +5 -4
- package/dist/index.d.ts +6 -2
- package/dist/index.js +14 -5
- package/dist/inline-packages.d.ts +2 -1
- package/dist/inline-packages.js +9 -4
- package/dist/lexer/base.d.ts +2 -0
- package/dist/lexer/base.js +6 -1
- package/dist/lexer/lexer.js +3 -0
- package/dist/lexer/literals.d.ts +5 -0
- package/dist/lexer/literals.js +51 -1
- package/dist/lexer/markup.js +3 -4
- package/dist/lexer/tables.js +2 -0
- package/dist/lexer/token.d.ts +4 -3
- package/dist/lexer/token.js +0 -2
- package/dist/loader.js +30 -8
- package/dist/names.d.ts +4 -0
- package/dist/names.js +29 -0
- package/dist/parser/base.d.ts +5 -0
- package/dist/parser/base.js +2 -1
- package/dist/parser/classes.d.ts +2 -0
- package/dist/parser/classes.js +88 -23
- package/dist/parser/control-flow.d.ts +8 -1
- package/dist/parser/control-flow.js +49 -26
- package/dist/parser/declarations.d.ts +5 -12
- package/dist/parser/declarations.js +14 -79
- package/dist/parser/decorators.d.ts +6 -2
- package/dist/parser/decorators.js +43 -19
- package/dist/parser/expressions.js +27 -3
- package/dist/parser/jumps.d.ts +11 -0
- package/dist/parser/jumps.js +77 -0
- package/dist/parser/literals.d.ts +9 -0
- package/dist/parser/literals.js +45 -6
- package/dist/parser/markup.js +1 -1
- package/dist/parser/params.d.ts +21 -0
- package/dist/parser/params.js +143 -0
- package/dist/parser/simple-statements.d.ts +2 -1
- package/dist/parser/simple-statements.js +38 -15
- package/dist/parser/statements.d.ts +5 -5
- package/dist/parser/statements.js +39 -35
- package/dist/parser/syntax.d.ts +11 -1
- package/dist/parser/syntax.js +16 -2
- package/dist/parser/types.js +8 -3
- package/dist/project-modules.d.ts +12 -0
- package/dist/project-modules.js +106 -0
- package/dist/run-file.d.ts +6 -0
- package/dist/run-file.js +111 -0
- package/dist/runtime/sources.js +13 -6
- package/dist/source-map.d.ts +17 -0
- package/dist/source-map.js +75 -0
- package/dist/ts-types.js +4 -1
- package/dist/typescript/convert-objects.d.ts +2 -1
- package/dist/typescript/convert-objects.js +18 -9
- package/dist/vite.js +12 -4
- package/dist/walk-types.js +1 -0
- package/dist/walk.d.ts +0 -2
- package/dist/walk.js +14 -31
- package/package.json +2 -2
- package/src/runtime/chan.js +15 -5
- package/src/runtime/channel.js +28 -0
- package/src/runtime/classes.js +32 -0
- package/src/runtime/core.js +10 -1
- package/src/runtime/decode.js +221 -0
- package/src/runtime/go.js +3 -0
- package/src/runtime/index.js +7 -0
- package/src/runtime/markup.js +27 -17
- package/src/runtime/select.js +14 -9
- package/src/runtime/shared.js +17 -0
- package/src/runtime/signals.js +59 -0
- package/src/runtime/threads.js +32 -5
- package/src/runtime/topic.js +118 -0
- package/src/runtime/try.js +45 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Topics: values that go to the other tabs of a site, and to its workers, over a BroadcastChannel
|
|
2
|
+
// of their name. A topic is data, `{ $$topic: name, zero }`, so it goes to a worker as its name,
|
|
3
|
+
// and there it is a topic of its own. Each topic listens from its first receive on, into a channel
|
|
4
|
+
// without a limit, so that `<-t`, `for v in t` and `select` are those of channels. `Topic` has
|
|
5
|
+
// what Rook code and the code compiled from it do with topics, by name.
|
|
6
|
+
|
|
7
|
+
import { $$chan, $$closeHere, $$send } from './chan.js';
|
|
8
|
+
import { $$Channel } from './channel.js';
|
|
9
|
+
import { $$walk } from './threads.js';
|
|
10
|
+
|
|
11
|
+
export const $$Topic = Object.freeze({
|
|
12
|
+
// The zero value of topic types: it has no name, it is closed, and what is sent to it goes
|
|
13
|
+
// nowhere.
|
|
14
|
+
EMPTY: Object.freeze({ $$topic: null, zero: null }),
|
|
15
|
+
make: $$topic,
|
|
16
|
+
publish: $$publish,
|
|
17
|
+
listen: $$listen,
|
|
18
|
+
close: $$closeTopic,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// What the modules of a thread share: one BroadcastChannel for each name, so that the topics of
|
|
22
|
+
// this thread do not hear what it sends, as one BroadcastChannel does not hear itself; the channel
|
|
23
|
+
// that each topic listens into, and the topics that are closed.
|
|
24
|
+
function $$topics() {
|
|
25
|
+
return (globalThis[Symbol.for('rook.topics')] ??= {
|
|
26
|
+
names: new Map(),
|
|
27
|
+
channels: new WeakMap(),
|
|
28
|
+
closed: new WeakSet(),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function $$topic(name, zero) {
|
|
33
|
+
return { $$topic: name, zero };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// `t <- v`: the value goes to the other threads that listen and is not kept here, so nothing waits.
|
|
37
|
+
export function $$publish(topic, value) {
|
|
38
|
+
if (topic.$$topic === null) return;
|
|
39
|
+
if ($$topics().closed.has(topic)) throw new Error('send on a closed topic');
|
|
40
|
+
$$named(topic.$$topic).channel.postMessage(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The channel that a topic listens into, from the first receive on; a closed topic gives a closed
|
|
44
|
+
// one, and Topic.EMPTY gives Channel.EMPTY. A null topic turns off its case of `select`, as a null
|
|
45
|
+
// channel does.
|
|
46
|
+
export function $$listen(topic) {
|
|
47
|
+
if (topic === null) return null;
|
|
48
|
+
if (topic.$$topic === null) return $$Channel.EMPTY;
|
|
49
|
+
|
|
50
|
+
const { channels, closed } = $$topics();
|
|
51
|
+
let channel = channels.get(topic);
|
|
52
|
+
|
|
53
|
+
if (channel) return channel;
|
|
54
|
+
channel = $$chan(Infinity, topic.zero);
|
|
55
|
+
channels.set(topic, channel);
|
|
56
|
+
if (closed.has(topic)) $$closeHere(channel.$$chan);
|
|
57
|
+
else $$listening(topic, true);
|
|
58
|
+
|
|
59
|
+
return channel;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// `close(t)`: the topic stops listening and sending; what it has received can still be received.
|
|
63
|
+
export function $$closeTopic(topic) {
|
|
64
|
+
const { channels, closed } = $$topics();
|
|
65
|
+
|
|
66
|
+
if (topic.$$topic === null) return;
|
|
67
|
+
if (closed.has(topic)) throw new Error('close of a closed topic');
|
|
68
|
+
closed.add(topic);
|
|
69
|
+
|
|
70
|
+
const channel = channels.get(topic);
|
|
71
|
+
|
|
72
|
+
if (!channel) return;
|
|
73
|
+
$$closeHere(channel.$$chan);
|
|
74
|
+
$$listening(topic, false);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The BroadcastChannel of a name and the topics of this thread that listen to it, each of which
|
|
78
|
+
// gets a copy of its own.
|
|
79
|
+
function $$named(name) {
|
|
80
|
+
const { names, channels } = $$topics();
|
|
81
|
+
const found = names.get(name);
|
|
82
|
+
|
|
83
|
+
if (found) return found;
|
|
84
|
+
|
|
85
|
+
const entry = { channel: new BroadcastChannel(name), listening: new Set() };
|
|
86
|
+
|
|
87
|
+
entry.channel.onmessage = ({ data }) => {
|
|
88
|
+
let first = true;
|
|
89
|
+
|
|
90
|
+
for (const topic of entry.listening) {
|
|
91
|
+
const value = first ? data : structuredClone(data);
|
|
92
|
+
|
|
93
|
+
first = false;
|
|
94
|
+
$$walk(value);
|
|
95
|
+
$$send(channels.get(topic), value);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
names.set(name, entry);
|
|
100
|
+
$$keepAlive(entry);
|
|
101
|
+
|
|
102
|
+
return entry;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function $$listening(topic, on) {
|
|
106
|
+
const entry = $$named(topic.$$topic);
|
|
107
|
+
|
|
108
|
+
if (on) entry.listening.add(topic);
|
|
109
|
+
else entry.listening.delete(topic);
|
|
110
|
+
$$keepAlive(entry);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// In Node, a BroadcastChannel keeps the program running only while a topic listens to it, as a
|
|
114
|
+
// `tick` does until it is closed.
|
|
115
|
+
function $$keepAlive({ channel, listening }) {
|
|
116
|
+
if (listening.size > 0) channel.ref?.();
|
|
117
|
+
else channel.unref?.();
|
|
118
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// `try expr`: an exception in the expression becomes the error of `(T, error)`. `results` is how
|
|
2
|
+
// many values the expression gives: 0 for none, and then the error comes alone, 1 for a value, more
|
|
3
|
+
// for several. With `withError` the last of them is an error already, as of `(User, error)` or of a
|
|
4
|
+
// function that returns only an error, and an exception takes its place.
|
|
5
|
+
|
|
6
|
+
export function $$catch(f, results = 1, withError = false) {
|
|
7
|
+
let value;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
value = f();
|
|
11
|
+
} catch (error) {
|
|
12
|
+
return failed(error, results, withError);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return succeeded(value, results, withError);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** `try` of an expression that waits: a rejected Promise is caught as an exception is. */
|
|
19
|
+
export async function $$catchAsync(f, results = 1, withError = false) {
|
|
20
|
+
let value;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
value = await f();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return failed(error, results, withError);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return succeeded(value, results, withError);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function succeeded(value, results, withError) {
|
|
32
|
+
if (results === 0) return null;
|
|
33
|
+
if (withError) return value;
|
|
34
|
+
|
|
35
|
+
return results === 1 ? [value, null] : [...value, null];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** JS can throw anything; what is not an Error becomes one, so that the error has a message. */
|
|
39
|
+
function failed(thrown, results, withError) {
|
|
40
|
+
const error = thrown instanceof Error ? thrown : new Error(String(thrown));
|
|
41
|
+
|
|
42
|
+
if (results === 0 || (withError && results === 1)) return error;
|
|
43
|
+
|
|
44
|
+
return [...Array(withError ? results - 1 : results).fill(null), error];
|
|
45
|
+
}
|