Skip to content

Commit afa160d

Browse files
committed
Merge branch 'main' of github.com:YabalLang/compiler
2 parents c9025cd + f0ffedd commit afa160d

File tree

8 files changed

+145
-13
lines changed

8 files changed

+145
-13
lines changed

.github/workflows/build.yaml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: dotnet publish
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
if: startsWith(github.ref, 'refs/tags/')
8+
runs-on: ${{ matrix.config.os }}
9+
10+
strategy:
11+
matrix:
12+
config:
13+
- { os: ubuntu-latest, arch: x64, name: linux-x64 }
14+
- { os: ubuntu-latest, arch: arm64, name: linux-arm64 }
15+
- { os: windows-latest, arch: x64, name: windows-x64 }
16+
- { os: windows-latest, arch: arm64, name: windows-arm64 }
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Setup dotnet
22+
uses: actions/setup-dotnet@v3
23+
with:
24+
dotnet-version: 8.0.x
25+
26+
- name: Install dependencies
27+
run: dotnet restore
28+
29+
- name: Publish native
30+
run: dotnet publish src/Yabal.Desktop/Yabal.Desktop.csproj -c Release -p:DesktopAot=true -p:Version=${GITHUB_REF#refs/*/} -o .output-native
31+
32+
- name: Upload native artifact
33+
uses: actions/upload-artifact@v3
34+
with:
35+
name: yabal-native-${{ matrix.config.name }}
36+
path: .output-native
37+
38+
- name: Publish
39+
run: dotnet publish src/Yabal.Desktop/Yabal.Desktop.csproj -c Release -p:Version=${GITHUB_REF#refs/*/} -o .output-runtime
40+
41+
- name: Upload artifact
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: yabal-runtime-${{ matrix.config.name }}
45+
path: .output-runtime
46+
47+
release:
48+
needs: build
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Download artifacts
52+
uses: actions/download-artifact@v3
53+
with:
54+
path: files
55+
56+
- name: Create zip files
57+
run: |
58+
mkdir -p release
59+
for f in files/*; do
60+
zip -r "release/$(basename "${f}").zip" "${f}"
61+
done
62+
63+
- name: Release
64+
uses: softprops/action-gh-release@v1
65+
with:
66+
files: release/*.zip
67+
tag_name: 0.1.0-alpha.2
68+
token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,7 @@ fabric.properties
438438
src/Yabal.Bot/appsettings.json
439439
examples/**/*.asmc
440440
examples/**/*.asmc.aexe
441-
examples/**/*.hex
441+
examples/**/*.hex
442+
443+
.output-runtime
444+
.output-native

src/Yabal.Compiler/InstructionBuildResult.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void ToAssembly(TextWriter writer, bool addComments = false)
4646

4747
var (instructionRef, pointer, raw, comment) = either.Right;
4848

49-
if (!raw && !instructionRef.HasValue && pointer is null && comment is not null && comment.StartsWith(", "))
49+
if (IsComment(either.Right))
5050
{
5151
writer.WriteLine(comment);
5252
continue;
@@ -190,6 +190,12 @@ private IEnumerable<int> GetBytes()
190190

191191
var (instruction, pointer, _, _) = either.Right;
192192

193+
if (IsComment(either.Right))
194+
{
195+
// Skip comments
196+
continue;
197+
}
198+
193199
if (!instruction.HasValue)
194200
{
195201
if (pointer is null)
@@ -225,11 +231,23 @@ private static (Dictionary<InstructionPointer, int>, int) GetPointers(ReferenceL
225231
}
226232
else
227233
{
234+
if (IsComment(either.Right))
235+
{
236+
continue;
237+
}
238+
228239
i++;
229240
length++;
230241
}
231242
}
232243

233244
return (labels, length);
234245
}
246+
247+
private static bool IsComment(InstructionItem item)
248+
{
249+
var (instruction, pointer, raw, comment) = item;
250+
251+
return !raw && !instruction.HasValue && pointer is null && comment is not null && comment.StartsWith(", ");
252+
}
235253
}

src/Yabal.Compiler/Yabal.Compiler.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Antlr4UseCSharpGenerator>True</Antlr4UseCSharpGenerator>
99
<DebugType>embedded</DebugType>
1010
<WarningsAsErrors>True</WarningsAsErrors>
11+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

src/Yabal.Core/Yabal.Core.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<DebugType>embedded</DebugType>
1010
</PropertyGroup>
1111

12+
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
13+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
14+
</PropertyGroup>
15+
1216
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
1317
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all">
1418
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/Yabal.Desktop/Program.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,12 @@ async Task BuildOutput(FileSystemInfo path, string? outPath, List<OutputFormat>
194194
var code = File.ReadAllText(path.FullName);
195195
var fs = new PhysicalFileSystem();
196196
var uri = new Uri("file:///" + fs.ConvertPathFromInternal(path.FullName));
197-
using var context = new YabalContext(fs)
198-
.AddFileLoader(FileType.Font, FontLoader.Instance)
199-
.AddFileLoader(FileType.Image, ImageLoader.Instance);
197+
using var context = new YabalContext(fs);
198+
199+
#if INCLUDE_LOADERS
200+
context.AddFileLoader(FileType.Font, FontLoader.Instance);
201+
context.AddFileLoader(FileType.Image, ImageLoader.Instance);
202+
#endif
200203

201204
var builder = new YabalBuilder(context)
202205
{
@@ -308,9 +311,12 @@ async Task Execute(InvocationContext ctx)
308311
var code = File.ReadAllText(path.Info.FullName);
309312
var fs = new PhysicalFileSystem();
310313
var uri = new Uri("file:///" + fs.ConvertPathFromInternal(path.Info.FullName));
311-
using var context = new YabalContext(fs)
312-
.AddFileLoader(FileType.Font, FontLoader.Instance)
313-
.AddFileLoader(FileType.Image, ImageLoader.Instance);
314+
using var context = new YabalContext(fs);
315+
316+
#if INCLUDE_LOADERS
317+
context.AddFileLoader(FileType.Font, FontLoader.Instance);
318+
context.AddFileLoader(FileType.Image, ImageLoader.Instance);
319+
#endif
314320

315321
var showOutput = ctx.ParseResult.GetValueForOption(output);
316322
var disableScreen = ctx.ParseResult.GetValueForOption(disableScreenOption);

src/Yabal.Desktop/Yabal.Desktop.csproj

+36-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,37 @@
1010
<LangVersion>preview</LangVersion>
1111
<AssemblyName>yabal</AssemblyName>
1212
<ApplicationIcon>icon.ico</ApplicationIcon>
13+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
14+
</PropertyGroup>
15+
16+
<PropertyGroup Condition="'$(DesktopAot)' == 'true'">
17+
<!-- Workaround for https://github.com/dotnet/runtime/issues/94406 -->
18+
<PublishAot>true</PublishAot>
19+
</PropertyGroup>
20+
21+
<PropertyGroup Condition="'$(PublishAot)' == ''">
22+
<PublishAot>false</PublishAot>
1323
</PropertyGroup>
1424

1525
<PropertyGroup>
26+
<DebugType>embedded</DebugType>
27+
<InvariantGlobalization>true</InvariantGlobalization>
28+
</PropertyGroup>
29+
30+
<PropertyGroup Condition="'$(PublishAot)' == 'true'">
31+
<DebugSymbols>false</DebugSymbols>
32+
<DebugType>None</DebugType>
33+
<NativeDebugSymbols>false</NativeDebugSymbols>
34+
<DebuggerSupport>false</DebuggerSupport>
35+
<EventSourceSupport>false</EventSourceSupport>
36+
<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
37+
<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
38+
<UseSystemResourceKeys>true</UseSystemResourceKeys>
39+
</PropertyGroup>
40+
41+
<PropertyGroup Condition="'$(PublishAot)' == 'false'">
1642
<SelfContained>true</SelfContained>
1743
<PublishTrimmed>true</PublishTrimmed>
18-
<InvariantGlobalization>true</InvariantGlobalization>
19-
<DebugType>embedded</DebugType>
2044
</PropertyGroup>
2145

2246
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
@@ -27,7 +51,7 @@
2751
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
2852
</PropertyGroup>
2953

30-
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
54+
<PropertyGroup Condition="'$(Configuration)' == 'Release' and '$(PublishAot)' == 'false'">
3155
<PublishSingleFile>true</PublishSingleFile>
3256
</PropertyGroup>
3357

@@ -56,8 +80,15 @@
5680
<ItemGroup>
5781
<ProjectReference Include="..\Yabal.Compiler\Yabal.Compiler.csproj" />
5882
<ProjectReference Include="..\Yabal.Emulator\Yabal.Emulator.csproj" />
59-
<ProjectReference Include="..\Yabal.Loaders.Font\Yabal.Loaders.Font.csproj" />
60-
<ProjectReference Include="..\Yabal.Loaders.Image\Yabal.Loaders.Image.csproj" />
83+
</ItemGroup>
84+
85+
<PropertyGroup Condition="'$(PublishAot)' == 'false'">
86+
<DefineConstants>$(DefineConstants);INCLUDE_LOADERS</DefineConstants>
87+
</PropertyGroup>
88+
89+
<ItemGroup Condition="'$(PublishAot)' == 'false'">
90+
<ProjectReference Include="..\Yabal.Loaders.Font\Yabal.Loaders.Font.csproj" />
91+
<ProjectReference Include="..\Yabal.Loaders.Image\Yabal.Loaders.Image.csproj" />
6192
</ItemGroup>
6293

6394
</Project>

src/Yabal.Emulator/Yabal.Emulator.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<RootNamespace>Yabal</RootNamespace>
99
<LangVersion>preview</LangVersion>
1010
<DebugType>embedded</DebugType>
11+
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

0 commit comments

Comments
 (0)