-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * Add SampleNames * Cleanup * fix: NullReference * feat: Add Automatic Sample Registration From Resources
- Loading branch information
Showing
11 changed files
with
138 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/MimaSim/MimaSim/Resources/samples/assembly/Addition.sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
load 0x01 | ||
mov accumulator, x | ||
load 0x02 | ||
mov accumulator, y | ||
add |
1 change: 1 addition & 0 deletions
1
src/MimaSim/MimaSim/Resources/samples/hochsprache/Addition.sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var z = 1 + 2 |
1 change: 1 addition & 0 deletions
1
src/MimaSim/MimaSim/Resources/samples/maschinencode/Addition.sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
04 01 00 40 01 02 04 02 00 40 01 03 08 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using MimaSim.Core; | ||
|
||
namespace MimaSim.Samples; | ||
|
||
public class SampleLoader | ||
{ | ||
private Dictionary<(LanguageName lang, string name), string> _samples = new(); | ||
public void Register(LanguageName language, string name, string src) | ||
{ | ||
_samples.TryAdd((language, name), src); | ||
} | ||
|
||
private const string BaseResourcePath = "MimaSim.Resources.samples."; | ||
public void FromResources(Assembly assembly) | ||
{ | ||
foreach (LanguageName language in Enum.GetValues(typeof(LanguageName))) | ||
{ | ||
var languagePath = $"{BaseResourcePath}{language.ToString().ToLower()}."; | ||
var resourceNames = assembly.GetManifestResourceNames(); | ||
|
||
foreach (var resourceName in resourceNames) | ||
{ | ||
if (resourceName.StartsWith(languagePath) && resourceName.EndsWith(".sample")) | ||
{ | ||
var sampleName = Path.GetFileNameWithoutExtension(resourceName).Split('.').Last(); | ||
|
||
using var stream = assembly.GetManifestResourceStream(resourceName); | ||
using var reader = new StreamReader(stream!); | ||
var sampleContent = reader.ReadToEnd(); | ||
|
||
Register(language, sampleName, sampleContent); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public string? GetSample(LanguageName language, string? name) | ||
{ | ||
return name is null ? null : _samples.GetValueOrDefault((language, name)); | ||
} | ||
|
||
public IEnumerable<string> GetSampleNamesFor(LanguageName language) | ||
{ | ||
return _samples.Keys.Where(_ => _.lang == language).Select(_ => _.name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.