redscript-mc 1.1.0 → 1.2.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/CHANGELOG.md +54 -0
- package/dist/__tests__/cli.test.js +138 -0
- package/dist/__tests__/codegen.test.js +25 -0
- package/dist/__tests__/e2e.test.js +190 -12
- package/dist/__tests__/lexer.test.js +12 -2
- package/dist/__tests__/lowering.test.js +164 -9
- package/dist/__tests__/mc-integration.test.js +145 -51
- package/dist/__tests__/optimizer-advanced.test.js +3 -3
- package/dist/__tests__/parser.test.js +80 -0
- package/dist/__tests__/runtime.test.js +8 -8
- package/dist/__tests__/typechecker.test.js +158 -0
- package/dist/ast/types.d.ts +20 -1
- package/dist/codegen/mcfunction/index.js +30 -1
- package/dist/codegen/structure/index.js +25 -0
- package/dist/compile.d.ts +10 -0
- package/dist/compile.js +36 -5
- package/dist/events/types.d.ts +35 -0
- package/dist/events/types.js +59 -0
- package/dist/index.js +3 -2
- package/dist/ir/types.d.ts +4 -0
- package/dist/lexer/index.d.ts +1 -1
- package/dist/lexer/index.js +2 -0
- package/dist/lowering/index.d.ts +32 -1
- package/dist/lowering/index.js +439 -15
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/index.js +79 -10
- package/dist/typechecker/index.d.ts +17 -0
- package/dist/typechecker/index.js +343 -17
- package/docs/ENTITY_TYPE_SYSTEM.md +242 -0
- package/editors/vscode/CHANGELOG.md +9 -0
- package/editors/vscode/out/extension.js +1144 -72
- package/editors/vscode/package-lock.json +2 -2
- package/editors/vscode/package.json +1 -1
- package/package.json +1 -1
- package/src/__tests__/cli.test.ts +166 -0
- package/src/__tests__/codegen.test.ts +27 -0
- package/src/__tests__/e2e.test.ts +201 -12
- package/src/__tests__/fixtures/event-test.mcrs +13 -0
- package/src/__tests__/fixtures/impl-test.mcrs +46 -0
- package/src/__tests__/fixtures/interval-test.mcrs +11 -0
- package/src/__tests__/fixtures/is-check-test.mcrs +20 -0
- package/src/__tests__/fixtures/timeout-test.mcrs +7 -0
- package/src/__tests__/lexer.test.ts +14 -2
- package/src/__tests__/lowering.test.ts +178 -9
- package/src/__tests__/mc-integration.test.ts +166 -51
- package/src/__tests__/optimizer-advanced.test.ts +3 -3
- package/src/__tests__/parser.test.ts +91 -5
- package/src/__tests__/runtime.test.ts +8 -8
- package/src/__tests__/typechecker.test.ts +171 -0
- package/src/ast/types.ts +25 -1
- package/src/codegen/mcfunction/index.ts +31 -1
- package/src/codegen/structure/index.ts +27 -0
- package/src/compile.ts +54 -6
- package/src/events/types.ts +69 -0
- package/src/index.ts +4 -3
- package/src/ir/types.ts +4 -0
- package/src/lexer/index.ts +3 -1
- package/src/lowering/index.ts +528 -16
- package/src/parser/index.ts +90 -12
- package/src/stdlib/README.md +34 -4
- package/src/stdlib/tags.mcrs +951 -0
- package/src/stdlib/timer.mcrs +54 -33
- package/src/typechecker/index.ts +404 -18
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVENT_TYPES = void 0;
|
|
4
|
+
exports.isEventTypeName = isEventTypeName;
|
|
5
|
+
exports.getEventParamSpecs = getEventParamSpecs;
|
|
6
|
+
exports.EVENT_TYPES = {
|
|
7
|
+
PlayerDeath: {
|
|
8
|
+
tag: 'rs.just_died',
|
|
9
|
+
params: ['player: Player'],
|
|
10
|
+
detection: 'scoreboard',
|
|
11
|
+
},
|
|
12
|
+
PlayerJoin: {
|
|
13
|
+
tag: 'rs.just_joined',
|
|
14
|
+
params: ['player: Player'],
|
|
15
|
+
detection: 'tag',
|
|
16
|
+
},
|
|
17
|
+
BlockBreak: {
|
|
18
|
+
tag: 'rs.just_broke_block',
|
|
19
|
+
params: ['player: Player', 'block: string'],
|
|
20
|
+
detection: 'advancement',
|
|
21
|
+
},
|
|
22
|
+
EntityKill: {
|
|
23
|
+
tag: 'rs.just_killed',
|
|
24
|
+
params: ['player: Player'],
|
|
25
|
+
detection: 'scoreboard',
|
|
26
|
+
},
|
|
27
|
+
ItemUse: {
|
|
28
|
+
tag: 'rs.just_used_item',
|
|
29
|
+
params: ['player: Player'],
|
|
30
|
+
detection: 'scoreboard',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
function isEventTypeName(value) {
|
|
34
|
+
return value in exports.EVENT_TYPES;
|
|
35
|
+
}
|
|
36
|
+
function getEventParamSpecs(eventType) {
|
|
37
|
+
return exports.EVENT_TYPES[eventType].params.map(parseEventParam);
|
|
38
|
+
}
|
|
39
|
+
function parseEventParam(spec) {
|
|
40
|
+
const match = spec.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*:\s*([A-Za-z_][A-Za-z0-9_]*)$/);
|
|
41
|
+
if (!match) {
|
|
42
|
+
throw new Error(`Invalid event parameter spec: ${spec}`);
|
|
43
|
+
}
|
|
44
|
+
const [, name, typeName] = match;
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
type: toTypeNode(typeName),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function toTypeNode(typeName) {
|
|
51
|
+
if (typeName === 'Player') {
|
|
52
|
+
return { kind: 'entity', entityType: 'Player' };
|
|
53
|
+
}
|
|
54
|
+
if (typeName === 'string' || typeName === 'int' || typeName === 'bool' || typeName === 'float' || typeName === 'void' || typeName === 'BlockPos' || typeName === 'byte' || typeName === 'short' || typeName === 'long' || typeName === 'double') {
|
|
55
|
+
return { kind: 'named', name: typeName };
|
|
56
|
+
}
|
|
57
|
+
return { kind: 'struct', name: typeName };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=types.js.map
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,8 @@ function compile(source, options = {}) {
|
|
|
28
28
|
const shouldOptimize = options.optimize ?? true;
|
|
29
29
|
const shouldTypeCheck = options.typeCheck ?? true;
|
|
30
30
|
const filePath = options.filePath;
|
|
31
|
-
const
|
|
31
|
+
const preprocessed = (0, compile_1.preprocessSourceWithMetadata)(source, { filePath });
|
|
32
|
+
const preprocessedSource = preprocessed.source;
|
|
32
33
|
// Lexing
|
|
33
34
|
const tokens = new lexer_1.Lexer(preprocessedSource, filePath).tokenize();
|
|
34
35
|
// Parsing
|
|
@@ -40,7 +41,7 @@ function compile(source, options = {}) {
|
|
|
40
41
|
typeErrors = checker.check(ast);
|
|
41
42
|
}
|
|
42
43
|
// Lowering to IR
|
|
43
|
-
const lowering = new lowering_1.Lowering(namespace);
|
|
44
|
+
const lowering = new lowering_1.Lowering(namespace, preprocessed.ranges);
|
|
44
45
|
const ir = lowering.lower(ast);
|
|
45
46
|
let optimizedIR = ir;
|
|
46
47
|
let generated = (0, mcfunction_1.generateDatapackWithStats)(ir, { optimizeCommands: shouldOptimize });
|
package/dist/ir/types.d.ts
CHANGED
|
@@ -110,6 +110,10 @@ export interface IRFunction {
|
|
|
110
110
|
kind: 'advancement' | 'craft' | 'death' | 'login' | 'join_team';
|
|
111
111
|
value?: string;
|
|
112
112
|
};
|
|
113
|
+
eventHandler?: {
|
|
114
|
+
eventType: string;
|
|
115
|
+
tag: string;
|
|
116
|
+
};
|
|
113
117
|
}
|
|
114
118
|
export interface GlobalVar {
|
|
115
119
|
name: string;
|
package/dist/lexer/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Handles special cases like entity selectors vs decorators,
|
|
6
6
|
* range literals, and raw commands.
|
|
7
7
|
*/
|
|
8
|
-
export type TokenKind = 'fn' | 'let' | 'const' | 'if' | 'else' | 'while' | 'for' | 'foreach' | 'match' | 'return' | 'as' | 'at' | 'in' | 'struct' | 'enum' | 'trigger' | 'namespace' | 'execute' | 'run' | 'unless' | 'int' | 'bool' | 'float' | 'string' | 'void' | 'BlockPos' | 'true' | 'false' | 'selector' | 'decorator' | 'int_lit' | 'float_lit' | 'byte_lit' | 'short_lit' | 'long_lit' | 'double_lit' | 'string_lit' | 'range_lit' | '+' | '-' | '*' | '/' | '%' | '~' | '^' | '==' | '!=' | '<' | '<=' | '>' | '>=' | '&&' | '||' | '!' | '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '{' | '}' | '(' | ')' | '[' | ']' | ',' | ';' | ':' | '::' | '->' | '=>' | '.' | 'ident' | 'mc_name' | 'raw_cmd' | 'eof';
|
|
8
|
+
export type TokenKind = 'fn' | 'let' | 'const' | 'if' | 'else' | 'while' | 'for' | 'foreach' | 'match' | 'return' | 'as' | 'at' | 'in' | 'is' | 'struct' | 'impl' | 'enum' | 'trigger' | 'namespace' | 'execute' | 'run' | 'unless' | 'int' | 'bool' | 'float' | 'string' | 'void' | 'BlockPos' | 'true' | 'false' | 'selector' | 'decorator' | 'int_lit' | 'float_lit' | 'byte_lit' | 'short_lit' | 'long_lit' | 'double_lit' | 'string_lit' | 'range_lit' | '+' | '-' | '*' | '/' | '%' | '~' | '^' | '==' | '!=' | '<' | '<=' | '>' | '>=' | '&&' | '||' | '!' | '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '{' | '}' | '(' | ')' | '[' | ']' | ',' | ';' | ':' | '::' | '->' | '=>' | '.' | 'ident' | 'mc_name' | 'raw_cmd' | 'eof';
|
|
9
9
|
export interface Token {
|
|
10
10
|
kind: TokenKind;
|
|
11
11
|
value: string;
|
package/dist/lexer/index.js
CHANGED
package/dist/lowering/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Handles control flow, function extraction for foreach, and builtin calls.
|
|
6
6
|
*/
|
|
7
7
|
import type { IRModule } from '../ir/types';
|
|
8
|
+
import type { SourceRange } from '../compile';
|
|
8
9
|
import type { Program } from '../ast/types';
|
|
9
10
|
export interface Warning {
|
|
10
11
|
message: string;
|
|
@@ -14,18 +15,25 @@ export interface Warning {
|
|
|
14
15
|
}
|
|
15
16
|
export declare class Lowering {
|
|
16
17
|
private namespace;
|
|
18
|
+
private readonly sourceRanges;
|
|
17
19
|
private functions;
|
|
18
20
|
private globals;
|
|
19
21
|
private globalNames;
|
|
20
22
|
private fnDecls;
|
|
23
|
+
private implMethods;
|
|
21
24
|
private specializedFunctions;
|
|
22
25
|
private currentFn;
|
|
26
|
+
private currentStdlibCallSite?;
|
|
23
27
|
private foreachCounter;
|
|
24
28
|
private lambdaCounter;
|
|
29
|
+
private timeoutCounter;
|
|
30
|
+
private intervalCounter;
|
|
25
31
|
readonly warnings: Warning[];
|
|
26
32
|
private builder;
|
|
27
33
|
private varMap;
|
|
28
34
|
private lambdaBindings;
|
|
35
|
+
private intervalBindings;
|
|
36
|
+
private intervalFunctions;
|
|
29
37
|
private currentCallbackBindings;
|
|
30
38
|
private currentContext;
|
|
31
39
|
private blockPosVars;
|
|
@@ -37,7 +45,7 @@ export declare class Lowering {
|
|
|
37
45
|
private varTypes;
|
|
38
46
|
private floatVars;
|
|
39
47
|
private worldObjCounter;
|
|
40
|
-
constructor(namespace: string);
|
|
48
|
+
constructor(namespace: string, sourceRanges?: SourceRange[]);
|
|
41
49
|
lower(program: Program): IRModule;
|
|
42
50
|
private lowerFn;
|
|
43
51
|
private getTickRate;
|
|
@@ -47,6 +55,7 @@ export declare class Lowering {
|
|
|
47
55
|
private lowerLetStmt;
|
|
48
56
|
private lowerReturnStmt;
|
|
49
57
|
private lowerIfStmt;
|
|
58
|
+
private lowerIsCheckIfStmt;
|
|
50
59
|
private lowerWhileStmt;
|
|
51
60
|
private lowerForStmt;
|
|
52
61
|
private lowerForRangeStmt;
|
|
@@ -67,20 +76,31 @@ export declare class Lowering {
|
|
|
67
76
|
private lowerUnaryExpr;
|
|
68
77
|
private lowerAssignExpr;
|
|
69
78
|
private lowerCallExpr;
|
|
79
|
+
private lowerStaticCallExpr;
|
|
70
80
|
private lowerInvokeExpr;
|
|
71
81
|
private inlineLambdaInvoke;
|
|
72
82
|
private emitDirectFunctionCall;
|
|
83
|
+
private emitMethodCall;
|
|
73
84
|
private resolveFunctionRefExpr;
|
|
74
85
|
private resolveFunctionRefByName;
|
|
75
86
|
private ensureSpecializedFunction;
|
|
87
|
+
private ensureSpecializedFunctionWithContext;
|
|
76
88
|
private lowerLambdaExpr;
|
|
77
89
|
private withSavedFunctionState;
|
|
78
90
|
private lowerBuiltinCall;
|
|
91
|
+
private lowerSetTimeout;
|
|
92
|
+
private lowerSetInterval;
|
|
93
|
+
private lowerClearInterval;
|
|
94
|
+
private lowerNamedLambdaFunction;
|
|
95
|
+
private lowerIntervalWrapperFunction;
|
|
96
|
+
private resolveIntervalFunctionName;
|
|
79
97
|
private lowerRichTextBuiltin;
|
|
80
98
|
private getRichTextArgIndex;
|
|
81
99
|
private buildRichTextJson;
|
|
82
100
|
private appendRichTextExpr;
|
|
83
101
|
private exprToString;
|
|
102
|
+
private exprToEntitySelector;
|
|
103
|
+
private appendTypeFilter;
|
|
84
104
|
private exprToSnbt;
|
|
85
105
|
private exprToTargetString;
|
|
86
106
|
private exprToLiteral;
|
|
@@ -88,12 +108,23 @@ export declare class Lowering {
|
|
|
88
108
|
private exprToTextComponent;
|
|
89
109
|
private exprToBoolString;
|
|
90
110
|
private isTeamTextOption;
|
|
111
|
+
private exprToScoreboardObjective;
|
|
112
|
+
private resolveScoreboardObjective;
|
|
113
|
+
private getObjectiveNamespace;
|
|
114
|
+
private tryGetStdlibInternalObjective;
|
|
115
|
+
private getStdlibInternalResourceBase;
|
|
116
|
+
private getStdlibCallSiteContext;
|
|
117
|
+
private serializeCallSite;
|
|
118
|
+
private shortHash;
|
|
119
|
+
private isStdlibFile;
|
|
120
|
+
private filePathForSpan;
|
|
91
121
|
private lowerCoordinateBuiltin;
|
|
92
122
|
private lowerTpCommand;
|
|
93
123
|
private resolveBlockPosExpr;
|
|
94
124
|
private getArrayStorageName;
|
|
95
125
|
private inferLambdaReturnType;
|
|
96
126
|
private inferExprType;
|
|
127
|
+
private resolveInstanceMethod;
|
|
97
128
|
private normalizeType;
|
|
98
129
|
private readArrayElement;
|
|
99
130
|
private emitRawSubFunction;
|