diff --git a/Source/Backlang.Driver/ExtensionUtils.cs b/NewSource/BacklangC/Core/ExtensionUtils.cs similarity index 94% rename from Source/Backlang.Driver/ExtensionUtils.cs rename to NewSource/BacklangC/Core/ExtensionUtils.cs index 36a4828a..3324013e 100644 --- a/Source/Backlang.Driver/ExtensionUtils.cs +++ b/NewSource/BacklangC/Core/ExtensionUtils.cs @@ -1,4 +1,7 @@ -namespace Backlang.Driver; +using Backlang.Codeanalysis.Parsing.AST; +using Loyc.Syntax; + +namespace BacklangC.Core; public static class ExtensionUtils { diff --git a/Source/Backlang.Driver/InternalMacros/SyntacticMacros.cs b/NewSource/BacklangC/Core/SyntacticMacros.cs similarity index 96% rename from Source/Backlang.Driver/InternalMacros/SyntacticMacros.cs rename to NewSource/BacklangC/Core/SyntacticMacros.cs index 6c1236b2..ff890421 100644 --- a/Source/Backlang.Driver/InternalMacros/SyntacticMacros.cs +++ b/NewSource/BacklangC/Core/SyntacticMacros.cs @@ -1,7 +1,12 @@ -using LeMP; +using System.Text; using System.Text.RegularExpressions; +using Backlang.Codeanalysis.Parsing; +using Backlang.Codeanalysis.Parsing.AST; +using LeMP; +using Loyc; +using Loyc.Syntax; -namespace Backlang.Driver.InternalMacros; +namespace BacklangC.Core; [ContainsMacros] public static class SyntacticMacros @@ -126,7 +131,7 @@ private static LNode ExpandOperator(LNode @operator, IMacroContext context) }; var modChanged = @operator.WithAttrs(newAttrs); var fnName = @operator.Args[1]; - var compContext = (CompilerContext)context.ScopedProperties["Context"]; + var compContext = (Driver)context.ScopedProperties["Context"]; if (fnName is var (_, (_, name)) && OpMap.ContainsKey(name.Name.Name)) { @@ -134,8 +139,8 @@ private static LNode ExpandOperator(LNode @operator, IMacroContext context) if (@operator[2].ArgCount != op.ArgumentCount) { - compContext.AddError(@operator, - $"Cannot overload operator, parameter count mismatch. {op.ArgumentCount} parameters expected"); + // compContext.AddError(@operator, + // $"Cannot overload operator, parameter count mismatch. {op.ArgumentCount} parameters expected"); } var newTarget = SyntaxTree.Type("op_" + op.OperatorName, LNode.List()).WithRange(fnName.Range); diff --git a/Source/Backlang.Driver/Compiling/Stages/ExpandingStages/ExpandMacrosStage.cs b/NewSource/BacklangC/Stages/ExpandMacrosStage.cs similarity index 71% rename from Source/Backlang.Driver/Compiling/Stages/ExpandingStages/ExpandMacrosStage.cs rename to NewSource/BacklangC/Stages/ExpandMacrosStage.cs index bb9d7adf..7519f5ec 100644 --- a/Source/Backlang.Driver/Compiling/Stages/ExpandingStages/ExpandMacrosStage.cs +++ b/NewSource/BacklangC/Stages/ExpandMacrosStage.cs @@ -1,14 +1,17 @@ -using Backlang.Core.Macros; -using Backlang.Driver.InternalMacros; +using System.Runtime.Loader; +using Backlang.Codeanalysis.Parsing; +using Backlang.Core.Macros; +using BacklangC.Core; using Flo; using LeMP; using LeMP.Prelude; +using Loyc; using Loyc.Collections; -using System.Runtime.Loader; +using Loyc.Syntax; -namespace Backlang.Driver.Compiling.Stages.ExpandingStages; +namespace BacklangC.Stages; -public sealed class ExpandMacrosStage : IHandler +public sealed class ExpandMacrosStage : IHandler { private readonly MacroProcessor _macroProcessor; @@ -23,19 +26,16 @@ public ExpandMacrosStage() _macroProcessor.PreOpenedNamespaces.Add((Symbol)typeof(SyntacticMacros).Namespace); } - public async Task HandleAsync(CompilerContext context, - Func> next) + public async Task HandleAsync(Driver context, + Func> next) { - context.CompilationTarget.BeforeExpandMacros(_macroProcessor); //Only calls once - - if (context.MacroReferences != null) + if (context.Settings.MacroReferences != null) { var loadContext = new AssemblyLoadContext("Macros"); - foreach (var ml in context.MacroReferences) + foreach (var ml in context.Settings.MacroReferences) { - var basePath = new FileInfo(context.ProjectFile).Directory.FullName; - var directory = new FileInfo(context.ResultingOutputPath).Directory.FullName; - var assembly = loadContext.LoadFromAssemblyPath(Path.Combine(basePath, directory, ml)); + var directory = new FileInfo(context.Settings.OutputPath).Directory?.FullName; + var assembly = loadContext.LoadFromAssemblyPath(Path.Combine(directory, ml)); if (assembly == null) { @@ -48,7 +48,6 @@ public async Task HandleAsync(CompilerContext context, } } - _macroProcessor.DefaultScopedProperties.Add("Target", context.Options.Target); _macroProcessor.DefaultScopedProperties.Add("Context", context); foreach (var tree in context.Trees)