/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/ScriptEngine/Compiler/CompilerBackendSelector.cs
63 строки
2 KB
Mr-Rm
v2 к #1295: работа параметра runtime.default
19 фев 2025, 14:46
19 фев 2025, 14:46
a5fe637
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System; using System.Linq; using OneScript.Compilation; using OneScript.Language.SyntaxAnalysis; using OneScript.Language.SyntaxAnalysis.AstNodes; using OneScript.Native.Compiler; namespace ScriptEngine.Compiler { public class CompilerBackendSelector : BslSyntaxWalker { private bool _isNative; public CompilerBackendSelector(OneScriptCoreOptions options) { _isNative = options.UseNativeAsDefaultRuntime; } public Func<ICompilerBackend> StackBackendInitializer { get; set; } public Func<ICompilerBackend> NativeBackendInitializer { get; set; } public ICompilerBackend Select(ModuleNode ast) { VisitModule(ast); if (_isNative) { return NativeBackendInitializer?.Invoke(); } return StackBackendInitializer?.Invoke(); } protected override void VisitModuleAnnotation(AnnotationNode node) { if (string.Equals(node.Name, NativeRuntimeAnnotationHandler.NativeDirectiveName, StringComparison.CurrentCultureIgnoreCase)) { _isNative = true; } else if (string.Equals(node.Name, NativeRuntimeAnnotationHandler.StackRuntimeDirectiveName, StringComparison.CurrentCultureIgnoreCase)) { _isNative = false; } } protected override void VisitModule(ModuleNode node) { foreach (var child in node.Children.Where(x => x.Kind == NodeKind.Annotation)) { VisitModuleAnnotation((AnnotationNode)child); } } } }