redscript-mc 1.0.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/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +31 -0
- package/.github/ISSUE_TEMPLATE/wrong_output.md +33 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +34 -0
- package/.github/workflows/ci.yml +29 -0
- package/.github/workflows/publish-extension.yml +35 -0
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/README.zh.md +261 -0
- package/dist/__tests__/cli.test.d.ts +1 -0
- package/dist/__tests__/cli.test.js +140 -0
- package/dist/__tests__/codegen.test.d.ts +1 -0
- package/dist/__tests__/codegen.test.js +121 -0
- package/dist/__tests__/diagnostics.test.d.ts +4 -0
- package/dist/__tests__/diagnostics.test.js +149 -0
- package/dist/__tests__/e2e.test.d.ts +6 -0
- package/dist/__tests__/e2e.test.js +1528 -0
- package/dist/__tests__/lexer.test.d.ts +1 -0
- package/dist/__tests__/lexer.test.js +316 -0
- package/dist/__tests__/lowering.test.d.ts +1 -0
- package/dist/__tests__/lowering.test.js +819 -0
- package/dist/__tests__/mc-integration.test.d.ts +12 -0
- package/dist/__tests__/mc-integration.test.js +395 -0
- package/dist/__tests__/mc-syntax.test.d.ts +1 -0
- package/dist/__tests__/mc-syntax.test.js +112 -0
- package/dist/__tests__/nbt.test.d.ts +1 -0
- package/dist/__tests__/nbt.test.js +82 -0
- package/dist/__tests__/optimizer-advanced.test.d.ts +1 -0
- package/dist/__tests__/optimizer-advanced.test.js +124 -0
- package/dist/__tests__/optimizer.test.d.ts +1 -0
- package/dist/__tests__/optimizer.test.js +118 -0
- package/dist/__tests__/parser.test.d.ts +1 -0
- package/dist/__tests__/parser.test.js +717 -0
- package/dist/__tests__/repl.test.d.ts +1 -0
- package/dist/__tests__/repl.test.js +27 -0
- package/dist/__tests__/runtime.test.d.ts +1 -0
- package/dist/__tests__/runtime.test.js +276 -0
- package/dist/__tests__/structure-optimizer.test.d.ts +1 -0
- package/dist/__tests__/structure-optimizer.test.js +33 -0
- package/dist/__tests__/typechecker.test.d.ts +1 -0
- package/dist/__tests__/typechecker.test.js +364 -0
- package/dist/ast/types.d.ts +357 -0
- package/dist/ast/types.js +9 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +407 -0
- package/dist/codegen/cmdblock/index.d.ts +26 -0
- package/dist/codegen/cmdblock/index.js +45 -0
- package/dist/codegen/mcfunction/index.d.ts +34 -0
- package/dist/codegen/mcfunction/index.js +413 -0
- package/dist/codegen/structure/index.d.ts +18 -0
- package/dist/codegen/structure/index.js +249 -0
- package/dist/compile.d.ts +30 -0
- package/dist/compile.js +152 -0
- package/dist/data/arena/function/__load.mcfunction +6 -0
- package/dist/data/arena/function/__tick.mcfunction +2 -0
- package/dist/data/arena/function/announce_leaders/else_1.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/then_0.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0.mcfunction +7 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders/foreach_1.mcfunction +6 -0
- package/dist/data/arena/function/announce_leaders/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders.mcfunction +6 -0
- package/dist/data/arena/function/arena_tick/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/arena_tick/then_0.mcfunction +4 -0
- package/dist/data/arena/function/arena_tick.mcfunction +11 -0
- package/dist/data/counter/function/__load.mcfunction +5 -0
- package/dist/data/counter/function/__tick.mcfunction +2 -0
- package/dist/data/counter/function/counter_tick/merge_2.mcfunction +1 -0
- package/dist/data/counter/function/counter_tick/then_0.mcfunction +3 -0
- package/dist/data/counter/function/counter_tick.mcfunction +11 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/minecraft/tags/function/tick.json +5 -0
- package/dist/data/quiz/function/__load.mcfunction +16 -0
- package/dist/data/quiz/function/__tick.mcfunction +6 -0
- package/dist/data/quiz/function/__trigger_quiz_a_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_b_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_c_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_start_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/answer_a.mcfunction +4 -0
- package/dist/data/quiz/function/answer_b.mcfunction +4 -0
- package/dist/data/quiz/function/answer_c.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_4.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_7.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/merge_2.mcfunction +1 -0
- package/dist/data/quiz/function/ask_question/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/then_0.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_3.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_6.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question.mcfunction +7 -0
- package/dist/data/quiz/function/finish_quiz.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/else_10.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_16.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_4.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_7.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/merge_11.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_14.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_17.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_2.mcfunction +8 -0
- package/dist/data/quiz/function/handle_answer/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/then_0.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_12.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_15.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_3.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_6.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_9.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer.mcfunction +11 -0
- package/dist/data/quiz/function/start_quiz.mcfunction +5 -0
- package/dist/data/shop/function/__load.mcfunction +7 -0
- package/dist/data/shop/function/__tick.mcfunction +3 -0
- package/dist/data/shop/function/__trigger_shop_buy_dispatch.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/else_1.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_4.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_7.mcfunction +3 -0
- package/dist/data/shop/function/complete_purchase/merge_2.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_5.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_8.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/then_0.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_3.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_6.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase.mcfunction +7 -0
- package/dist/data/shop/function/handle_shop_trigger.mcfunction +3 -0
- package/dist/data/turret/function/__load.mcfunction +5 -0
- package/dist/data/turret/function/__tick.mcfunction +4 -0
- package/dist/data/turret/function/__trigger_deploy_turret_dispatch.mcfunction +4 -0
- package/dist/data/turret/function/deploy_turret.mcfunction +8 -0
- package/dist/data/turret/function/turret_tick/at_1.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_0.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_2.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/tick_body.mcfunction +3 -0
- package/dist/data/turret/function/turret_tick/tick_skip.mcfunction +1 -0
- package/dist/data/turret/function/turret_tick.mcfunction +5 -0
- package/dist/diagnostics/index.d.ts +44 -0
- package/dist/diagnostics/index.js +140 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +126 -0
- package/dist/ir/builder.d.ts +32 -0
- package/dist/ir/builder.js +99 -0
- package/dist/ir/types.d.ts +117 -0
- package/dist/ir/types.js +15 -0
- package/dist/lexer/index.d.ts +36 -0
- package/dist/lexer/index.js +458 -0
- package/dist/lowering/index.d.ts +106 -0
- package/dist/lowering/index.js +2041 -0
- package/dist/mc-test/client.d.ts +128 -0
- package/dist/mc-test/client.js +174 -0
- package/dist/mc-test/runner.d.ts +28 -0
- package/dist/mc-test/runner.js +150 -0
- package/dist/mc-test/setup.d.ts +11 -0
- package/dist/mc-test/setup.js +98 -0
- package/dist/mc-validator/index.d.ts +17 -0
- package/dist/mc-validator/index.js +322 -0
- package/dist/nbt/index.d.ts +86 -0
- package/dist/nbt/index.js +250 -0
- package/dist/optimizer/commands.d.ts +36 -0
- package/dist/optimizer/commands.js +349 -0
- package/dist/optimizer/passes.d.ts +34 -0
- package/dist/optimizer/passes.js +227 -0
- package/dist/optimizer/structure.d.ts +8 -0
- package/dist/optimizer/structure.js +344 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/parser/index.d.ts +76 -0
- package/dist/parser/index.js +1193 -0
- package/dist/repl.d.ts +16 -0
- package/dist/repl.js +165 -0
- package/dist/runtime/index.d.ts +101 -0
- package/dist/runtime/index.js +1288 -0
- package/dist/typechecker/index.d.ts +42 -0
- package/dist/typechecker/index.js +629 -0
- package/docs/COMPILATION_STATS.md +142 -0
- package/docs/IMPLEMENTATION_GUIDE.md +512 -0
- package/docs/LANGUAGE_REFERENCE.md +415 -0
- package/docs/MC_MAPPING.md +280 -0
- package/docs/STRUCTURE_TARGET.md +80 -0
- package/docs/mc-reference/commands.md +259 -0
- package/editors/vscode/.vscodeignore +10 -0
- package/editors/vscode/LICENSE +21 -0
- package/editors/vscode/README.md +78 -0
- package/editors/vscode/build.mjs +28 -0
- package/editors/vscode/icon.png +0 -0
- package/editors/vscode/mcfunction-language-configuration.json +28 -0
- package/editors/vscode/out/extension.js +7236 -0
- package/editors/vscode/package-lock.json +566 -0
- package/editors/vscode/package.json +137 -0
- package/editors/vscode/redscript-language-configuration.json +28 -0
- package/editors/vscode/snippets/redscript.json +114 -0
- package/editors/vscode/src/codeactions.ts +89 -0
- package/editors/vscode/src/completion.ts +130 -0
- package/editors/vscode/src/extension.ts +239 -0
- package/editors/vscode/src/hover.ts +1120 -0
- package/editors/vscode/src/symbols.ts +207 -0
- package/editors/vscode/syntaxes/mcfunction.tmLanguage.json +740 -0
- package/editors/vscode/syntaxes/redscript.tmLanguage.json +357 -0
- package/editors/vscode/tsconfig.json +13 -0
- package/jest.config.js +5 -0
- package/package.json +38 -0
- package/src/__tests__/cli.test.ts +130 -0
- package/src/__tests__/codegen.test.ts +128 -0
- package/src/__tests__/diagnostics.test.ts +195 -0
- package/src/__tests__/e2e.test.ts +1721 -0
- package/src/__tests__/fixtures/mc-commands-1.21.4.json +18734 -0
- package/src/__tests__/formatter.test.ts +46 -0
- package/src/__tests__/lexer.test.ts +356 -0
- package/src/__tests__/lowering.test.ts +962 -0
- package/src/__tests__/mc-integration.test.ts +409 -0
- package/src/__tests__/mc-syntax.test.ts +96 -0
- package/src/__tests__/nbt.test.ts +58 -0
- package/src/__tests__/optimizer-advanced.test.ts +144 -0
- package/src/__tests__/optimizer.test.ts +129 -0
- package/src/__tests__/parser.test.ts +800 -0
- package/src/__tests__/repl.test.ts +33 -0
- package/src/__tests__/runtime.test.ts +289 -0
- package/src/__tests__/structure-optimizer.test.ts +38 -0
- package/src/__tests__/typechecker.test.ts +395 -0
- package/src/ast/types.ts +248 -0
- package/src/cli.ts +445 -0
- package/src/codegen/cmdblock/index.ts +63 -0
- package/src/codegen/mcfunction/index.ts +471 -0
- package/src/codegen/structure/index.ts +305 -0
- package/src/compile.ts +188 -0
- package/src/diagnostics/index.ts +186 -0
- package/src/examples/README.md +77 -0
- package/src/examples/SHOWCASE_GAME.md +43 -0
- package/src/examples/arena.rs +44 -0
- package/src/examples/counter.rs +12 -0
- package/src/examples/pvp_arena.rs +131 -0
- package/src/examples/quiz.rs +90 -0
- package/src/examples/rpg.rs +13 -0
- package/src/examples/shop.rs +30 -0
- package/src/examples/showcase_game.rs +552 -0
- package/src/examples/stdlib_demo.rs +181 -0
- package/src/examples/turret.rs +27 -0
- package/src/examples/world_manager.rs +23 -0
- package/src/formatter/index.ts +22 -0
- package/src/index.ts +161 -0
- package/src/ir/builder.ts +114 -0
- package/src/ir/types.ts +119 -0
- package/src/lexer/index.ts +555 -0
- package/src/lowering/index.ts +2406 -0
- package/src/mc-test/client.ts +259 -0
- package/src/mc-test/runner.ts +140 -0
- package/src/mc-test/setup.ts +70 -0
- package/src/mc-validator/index.ts +367 -0
- package/src/nbt/index.ts +321 -0
- package/src/optimizer/commands.ts +416 -0
- package/src/optimizer/passes.ts +233 -0
- package/src/optimizer/structure.ts +441 -0
- package/src/parser/index.ts +1437 -0
- package/src/repl.ts +165 -0
- package/src/runtime/index.ts +1403 -0
- package/src/stdlib/README.md +156 -0
- package/src/stdlib/combat.rs +20 -0
- package/src/stdlib/cooldown.rs +45 -0
- package/src/stdlib/math.rs +49 -0
- package/src/stdlib/mobs.rs +99 -0
- package/src/stdlib/player.rs +29 -0
- package/src/stdlib/strings.rs +7 -0
- package/src/stdlib/timer.rs +51 -0
- package/src/templates/README.md +126 -0
- package/src/templates/combat.rs +96 -0
- package/src/templates/economy.rs +40 -0
- package/src/templates/mini-game-framework.rs +117 -0
- package/src/templates/quest.rs +78 -0
- package/src/test_programs/zombie_game.rs +25 -0
- package/src/typechecker/index.ts +737 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RedScript Compile API
|
|
3
|
+
*
|
|
4
|
+
* Main compile function with proper error handling and diagnostics.
|
|
5
|
+
*/
|
|
6
|
+
import { DatapackFile } from './codegen/mcfunction';
|
|
7
|
+
import { DiagnosticError } from './diagnostics';
|
|
8
|
+
import type { IRModule } from './ir/types';
|
|
9
|
+
import type { Program } from './ast/types';
|
|
10
|
+
export interface CompileOptions {
|
|
11
|
+
namespace?: string;
|
|
12
|
+
filePath?: string;
|
|
13
|
+
optimize?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface CompileResult {
|
|
16
|
+
success: boolean;
|
|
17
|
+
files?: DatapackFile[];
|
|
18
|
+
advancements?: DatapackFile[];
|
|
19
|
+
ast?: Program;
|
|
20
|
+
ir?: IRModule;
|
|
21
|
+
error?: DiagnosticError;
|
|
22
|
+
}
|
|
23
|
+
interface PreprocessOptions {
|
|
24
|
+
filePath?: string;
|
|
25
|
+
seen?: Set<string>;
|
|
26
|
+
}
|
|
27
|
+
export declare function preprocessSource(source: string, options?: PreprocessOptions): string;
|
|
28
|
+
export declare function compile(source: string, options?: CompileOptions): CompileResult;
|
|
29
|
+
export declare function formatCompileError(result: CompileResult): string;
|
|
30
|
+
export {};
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* RedScript Compile API
|
|
4
|
+
*
|
|
5
|
+
* Main compile function with proper error handling and diagnostics.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.preprocessSource = preprocessSource;
|
|
42
|
+
exports.compile = compile;
|
|
43
|
+
exports.formatCompileError = formatCompileError;
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const lexer_1 = require("./lexer");
|
|
47
|
+
const parser_1 = require("./parser");
|
|
48
|
+
const lowering_1 = require("./lowering");
|
|
49
|
+
const passes_1 = require("./optimizer/passes");
|
|
50
|
+
const mcfunction_1 = require("./codegen/mcfunction");
|
|
51
|
+
const diagnostics_1 = require("./diagnostics");
|
|
52
|
+
const IMPORT_RE = /^\s*import\s+"([^"]+)"\s*;?\s*$/;
|
|
53
|
+
function preprocessSource(source, options = {}) {
|
|
54
|
+
const { filePath } = options;
|
|
55
|
+
const seen = options.seen ?? new Set();
|
|
56
|
+
if (filePath) {
|
|
57
|
+
seen.add(path.resolve(filePath));
|
|
58
|
+
}
|
|
59
|
+
const lines = source.split('\n');
|
|
60
|
+
const imports = [];
|
|
61
|
+
const bodyLines = [];
|
|
62
|
+
let parsingHeader = true;
|
|
63
|
+
for (let i = 0; i < lines.length; i++) {
|
|
64
|
+
const line = lines[i];
|
|
65
|
+
const trimmed = line.trim();
|
|
66
|
+
const match = line.match(IMPORT_RE);
|
|
67
|
+
if (parsingHeader && match) {
|
|
68
|
+
if (!filePath) {
|
|
69
|
+
throw new diagnostics_1.DiagnosticError('ParseError', 'Import statements require a file path', { line: i + 1, col: 1 }, lines);
|
|
70
|
+
}
|
|
71
|
+
const importPath = path.resolve(path.dirname(filePath), match[1]);
|
|
72
|
+
if (!seen.has(importPath)) {
|
|
73
|
+
seen.add(importPath);
|
|
74
|
+
let importedSource;
|
|
75
|
+
try {
|
|
76
|
+
importedSource = fs.readFileSync(importPath, 'utf-8');
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
throw new diagnostics_1.DiagnosticError('ParseError', `Cannot import '${match[1]}'`, { file: filePath, line: i + 1, col: 1 }, lines);
|
|
80
|
+
}
|
|
81
|
+
imports.push(preprocessSource(importedSource, { filePath: importPath, seen }));
|
|
82
|
+
}
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (parsingHeader && (trimmed === '' || trimmed.startsWith('//'))) {
|
|
86
|
+
bodyLines.push(line);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
parsingHeader = false;
|
|
90
|
+
bodyLines.push(line);
|
|
91
|
+
}
|
|
92
|
+
return [...imports, bodyLines.join('\n')].filter(Boolean).join('\n');
|
|
93
|
+
}
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
// Main Compile Function
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
function compile(source, options = {}) {
|
|
98
|
+
const { namespace = 'redscript', filePath, optimize: shouldOptimize = true } = options;
|
|
99
|
+
let sourceLines = source.split('\n');
|
|
100
|
+
try {
|
|
101
|
+
const preprocessedSource = preprocessSource(source, { filePath });
|
|
102
|
+
sourceLines = preprocessedSource.split('\n');
|
|
103
|
+
// Lexing
|
|
104
|
+
const tokens = new lexer_1.Lexer(preprocessedSource, filePath).tokenize();
|
|
105
|
+
// Parsing
|
|
106
|
+
const ast = new parser_1.Parser(tokens, preprocessedSource, filePath).parse(namespace);
|
|
107
|
+
// Lowering
|
|
108
|
+
const ir = new lowering_1.Lowering(namespace).lower(ast);
|
|
109
|
+
// Optimization
|
|
110
|
+
const optimized = shouldOptimize
|
|
111
|
+
? { ...ir, functions: ir.functions.map(fn => (0, passes_1.optimize)(fn)) }
|
|
112
|
+
: ir;
|
|
113
|
+
// Code generation
|
|
114
|
+
const generated = (0, mcfunction_1.generateDatapackWithStats)(optimized);
|
|
115
|
+
return {
|
|
116
|
+
success: true,
|
|
117
|
+
files: [...generated.files, ...generated.advancements],
|
|
118
|
+
advancements: generated.advancements,
|
|
119
|
+
ast,
|
|
120
|
+
ir: optimized,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
// Already a DiagnosticError
|
|
125
|
+
if (err instanceof diagnostics_1.DiagnosticError) {
|
|
126
|
+
return { success: false, error: err };
|
|
127
|
+
}
|
|
128
|
+
// Try to parse the error message for line/col info
|
|
129
|
+
if (err instanceof Error) {
|
|
130
|
+
const diagnostic = (0, diagnostics_1.parseErrorMessage)('ParseError', err.message, sourceLines, filePath);
|
|
131
|
+
return { success: false, error: diagnostic };
|
|
132
|
+
}
|
|
133
|
+
// Unknown error
|
|
134
|
+
return {
|
|
135
|
+
success: false,
|
|
136
|
+
error: new diagnostics_1.DiagnosticError('ParseError', String(err), { file: filePath, line: 1, col: 1 }, sourceLines)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
// Format Compile Error
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
function formatCompileError(result) {
|
|
144
|
+
if (result.success) {
|
|
145
|
+
return 'Compilation successful';
|
|
146
|
+
}
|
|
147
|
+
if (result.error) {
|
|
148
|
+
return (0, diagnostics_1.formatError)(result.error, result.error.sourceLines?.join('\n'));
|
|
149
|
+
}
|
|
150
|
+
return 'Unknown error';
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# block: merge_2
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# block: entry
|
|
2
|
+
execute store result score $t0 rs run scoreboard players get @s kills
|
|
3
|
+
scoreboard players operation $kills rs = $t0 rs
|
|
4
|
+
scoreboard players set $t1 rs 0
|
|
5
|
+
execute if score $t0 rs > $top_kills rs run scoreboard players set $t1 rs 1
|
|
6
|
+
execute if score $t1 rs matches 1.. run function arena:announce_leaders/foreach_0/then_0
|
|
7
|
+
execute if score $t1 rs matches ..0 run function arena:announce_leaders/foreach_0/merge_2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# block: merge_2
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# block: entry
|
|
2
|
+
execute store result score $t0 rs run scoreboard players get @s kills
|
|
3
|
+
scoreboard players set $t1 rs 0
|
|
4
|
+
execute if score $t0 rs = $top_kills rs run scoreboard players set $t1 rs 1
|
|
5
|
+
execute if score $t1 rs matches 1.. run function arena:announce_leaders/foreach_1/then_0
|
|
6
|
+
execute if score $t1 rs matches ..0 run function arena:announce_leaders/foreach_1/merge_2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# block: merge_2
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# block: entry
|
|
2
|
+
execute as @a run function arena:announce_leaders/foreach_0
|
|
3
|
+
scoreboard players set $t0 rs 0
|
|
4
|
+
execute if score $const_0 rs > $const_0 rs run scoreboard players set $t0 rs 1
|
|
5
|
+
execute if score $t0 rs matches 1.. run function arena:announce_leaders/then_0
|
|
6
|
+
execute if score $t0 rs matches ..0 run function arena:announce_leaders/else_1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# block: merge_2
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# block: entry
|
|
2
|
+
execute store result score $t0 rs run scoreboard players get arena ticks
|
|
3
|
+
scoreboard players operation $t1 rs = $t0 rs
|
|
4
|
+
scoreboard players operation $t1 rs += $const_1 rs
|
|
5
|
+
execute store result score arena ticks run scoreboard players get $t2 rs
|
|
6
|
+
scoreboard players operation $t3 rs = $t1 rs
|
|
7
|
+
scoreboard players operation $t3 rs %= $const_200 rs
|
|
8
|
+
scoreboard players set $t4 rs 0
|
|
9
|
+
execute if score $t3 rs = $const_0 rs run scoreboard players set $t4 rs 1
|
|
10
|
+
execute if score $t4 rs matches 1.. run function arena:arena_tick/then_0
|
|
11
|
+
execute if score $t4 rs matches ..0 run function arena:arena_tick/merge_2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# block: merge_2
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# block: entry
|
|
2
|
+
execute store result score $t0 rs run scoreboard players get counter ticks
|
|
3
|
+
scoreboard players operation $t1 rs = $t0 rs
|
|
4
|
+
scoreboard players operation $t1 rs += $const_1 rs
|
|
5
|
+
execute store result score counter ticks run scoreboard players get $t2 rs
|
|
6
|
+
scoreboard players operation $t3 rs = $t1 rs
|
|
7
|
+
scoreboard players operation $t3 rs %= $const_100 rs
|
|
8
|
+
scoreboard players set $t4 rs 0
|
|
9
|
+
execute if score $t3 rs = $const_0 rs run scoreboard players set $t4 rs 1
|
|
10
|
+
execute if score $t4 rs matches 1.. run function counter:counter_tick/then_0
|
|
11
|
+
execute if score $t4 rs matches ..0 run function counter:counter_tick/merge_2
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# RedScript runtime init
|
|
2
|
+
scoreboard objectives add rs dummy
|
|
3
|
+
scoreboard objectives add quiz_start trigger
|
|
4
|
+
scoreboard players enable @a quiz_start
|
|
5
|
+
scoreboard objectives add quiz_a trigger
|
|
6
|
+
scoreboard players enable @a quiz_a
|
|
7
|
+
scoreboard objectives add quiz_b trigger
|
|
8
|
+
scoreboard players enable @a quiz_b
|
|
9
|
+
scoreboard objectives add quiz_c trigger
|
|
10
|
+
scoreboard players enable @a quiz_c
|
|
11
|
+
scoreboard players set $const_1 rs 1
|
|
12
|
+
scoreboard players set $const_2 rs 2
|
|
13
|
+
scoreboard players set $const_3 rs 3
|
|
14
|
+
scoreboard players set $const_1 rs 1
|
|
15
|
+
scoreboard players set $const_2 rs 2
|
|
16
|
+
scoreboard players set $const_3 rs 3
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# RedScript tick dispatcher
|
|
2
|
+
# Trigger checks
|
|
3
|
+
execute as @a[scores={quiz_start=1..}] run function quiz:__trigger_quiz_start_dispatch
|
|
4
|
+
execute as @a[scores={quiz_a=1..}] run function quiz:__trigger_quiz_a_dispatch
|
|
5
|
+
execute as @a[scores={quiz_b=1..}] run function quiz:__trigger_quiz_b_dispatch
|
|
6
|
+
execute as @a[scores={quiz_c=1..}] run function quiz:__trigger_quiz_c_dispatch
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: else_1
|
|
2
|
+
scoreboard players set $t2 rs 0
|
|
3
|
+
execute if score $question rs = $const_2 rs run scoreboard players set $t2 rs 1
|
|
4
|
+
execute if score $t2 rs matches 1.. run function quiz:ask_question/then_3
|
|
5
|
+
execute if score $t2 rs matches ..0 run function quiz:ask_question/else_4
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: else_4
|
|
2
|
+
scoreboard players set $t3 rs 0
|
|
3
|
+
execute if score $question rs = $const_3 rs run scoreboard players set $t3 rs 1
|
|
4
|
+
execute if score $t3 rs matches 1.. run function quiz:ask_question/then_6
|
|
5
|
+
execute if score $t3 rs matches ..0 run function quiz:ask_question/else_7
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# block: merge_2
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# block: entry
|
|
2
|
+
execute store result score $t0 rs run scoreboard players get @s quiz_question
|
|
3
|
+
scoreboard players operation $question rs = $t0 rs
|
|
4
|
+
scoreboard players set $t1 rs 0
|
|
5
|
+
execute if score $t0 rs = $const_1 rs run scoreboard players set $t1 rs 1
|
|
6
|
+
execute if score $t1 rs matches 1.. run function quiz:ask_question/then_0
|
|
7
|
+
execute if score $t1 rs matches ..0 run function quiz:ask_question/else_1
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# block: entry
|
|
2
|
+
execute store result score $t0 rs run scoreboard players get @s quiz_score
|
|
3
|
+
title @s title {"text":"Quiz Complete"}
|
|
4
|
+
tellraw @s {"text":"Your final quiz score is recorded in quiz_score."}
|
|
5
|
+
scoreboard players set @s quiz_question 0
|
|
6
|
+
execute store result score @s quiz_score run scoreboard players get $t1 rs
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: else_1
|
|
2
|
+
scoreboard players set $t5 rs 0
|
|
3
|
+
execute if score $question rs = $const_2 rs run scoreboard players set $t5 rs 1
|
|
4
|
+
execute if score $t5 rs matches 1.. run function quiz:handle_answer/then_6
|
|
5
|
+
execute if score $t5 rs matches ..0 run function quiz:handle_answer/else_7
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: else_7
|
|
2
|
+
scoreboard players set $t8 rs 0
|
|
3
|
+
execute if score $question rs = $const_3 rs run scoreboard players set $t8 rs 1
|
|
4
|
+
execute if score $t8 rs matches 1.. run function quiz:handle_answer/then_12
|
|
5
|
+
execute if score $t8 rs matches ..0 run function quiz:handle_answer/merge_14
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# block: merge_2
|
|
2
|
+
execute store result score @s quiz_score run scoreboard players get $t11 rs
|
|
3
|
+
scoreboard players operation $t12 rs = $question rs
|
|
4
|
+
scoreboard players operation $t12 rs += $const_1 rs
|
|
5
|
+
scoreboard players operation $question rs = $t12 rs
|
|
6
|
+
execute store result score @s quiz_question run scoreboard players get $t13 rs
|
|
7
|
+
function quiz:ask_question
|
|
8
|
+
scoreboard players operation $t14 rs = $ret rs
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: then_0
|
|
2
|
+
scoreboard players set $t3 rs 0
|
|
3
|
+
execute if score $choice rs = $const_1 rs run scoreboard players set $t3 rs 1
|
|
4
|
+
execute if score $t3 rs matches 1.. run function quiz:handle_answer/then_3
|
|
5
|
+
execute if score $t3 rs matches ..0 run function quiz:handle_answer/else_4
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: then_12
|
|
2
|
+
scoreboard players set $t9 rs 0
|
|
3
|
+
execute if score $choice rs = $const_2 rs run scoreboard players set $t9 rs 1
|
|
4
|
+
execute if score $t9 rs matches 1.. run function quiz:handle_answer/then_15
|
|
5
|
+
execute if score $t9 rs matches ..0 run function quiz:handle_answer/else_16
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: then_6
|
|
2
|
+
scoreboard players set $t6 rs 0
|
|
3
|
+
execute if score $choice rs = $const_2 rs run scoreboard players set $t6 rs 1
|
|
4
|
+
execute if score $t6 rs matches 1.. run function quiz:handle_answer/then_9
|
|
5
|
+
execute if score $t6 rs matches ..0 run function quiz:handle_answer/else_10
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# block: entry
|
|
2
|
+
scoreboard players operation $choice rs = $p0 rs
|
|
3
|
+
scoreboard players operation $choice rs = $p0 rs
|
|
4
|
+
execute store result score $t0 rs run scoreboard players get @s quiz_question
|
|
5
|
+
scoreboard players operation $question rs = $t0 rs
|
|
6
|
+
execute store result score $t1 rs run scoreboard players get @s quiz_score
|
|
7
|
+
scoreboard players operation $score rs = $t1 rs
|
|
8
|
+
scoreboard players set $t2 rs 0
|
|
9
|
+
execute if score $t0 rs = $const_1 rs run scoreboard players set $t2 rs 1
|
|
10
|
+
execute if score $t2 rs matches 1.. run function quiz:handle_answer/then_0
|
|
11
|
+
execute if score $t2 rs matches ..0 run function quiz:handle_answer/else_1
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: else_1
|
|
2
|
+
scoreboard players set $t2 rs 0
|
|
3
|
+
execute if score $choice rs = $const_2 rs run scoreboard players set $t2 rs 1
|
|
4
|
+
execute if score $t2 rs matches 1.. run function shop:complete_purchase/then_3
|
|
5
|
+
execute if score $t2 rs matches ..0 run function shop:complete_purchase/else_4
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# block: else_4
|
|
2
|
+
scoreboard players set $t3 rs 0
|
|
3
|
+
execute if score $choice rs = $const_3 rs run scoreboard players set $t3 rs 1
|
|
4
|
+
execute if score $t3 rs matches 1.. run function shop:complete_purchase/then_6
|
|
5
|
+
execute if score $t3 rs matches ..0 run function shop:complete_purchase/else_7
|