This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
namespace vm_test | ||
{ | ||
using System.Linq; | ||
using ancient.runtime; | ||
using ancient.runtime.emit; | ||
using ancient.runtime.emit.sys; | ||
using ancient.runtime.hardware; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class ModulesTest : VMBehaviour | ||
{ | ||
[OneTimeSetUp] | ||
public void Setup() => IntConverter.Register<char>(); | ||
|
||
|
||
[Test] | ||
[Author("Yuuki Wesp", "[email protected]")] | ||
[Description("parse functions in module class test")] | ||
public void ParseFunctionsTest() | ||
{ | ||
Module.Boot(bus); | ||
var mem = new Instruction[] | ||
{ | ||
new ldx(0x11, 0x1), | ||
new sig("test1", 0, "void"), | ||
new lpstr("test1"), | ||
new ldi(0x0, 0x5), | ||
new ret(), | ||
new sig("test2", 0, "void"), | ||
new lpstr("test2"), | ||
new ldi(0x1, 0x6), | ||
new call_i("test1()"), | ||
new ret(), | ||
new sig("test3", 0, "void"), new lpstr("test3"), | ||
new call_i("test2()"), | ||
new mul(0x3, 0x0, 0x1), | ||
new ret(), | ||
new call_i("test3()"), | ||
new nop(), | ||
}.Reverse().ToArray(); | ||
|
||
var assembly = new DynamicAssembly("test"); | ||
var ilGen = assembly.GetGenerator(); | ||
ilGen.Emit(mem.Select(x => (OpCode)x).ToArray()); | ||
var module = new Module("test.module"); | ||
Module.modules.Add(module.GetHashCode(), module); | ||
state.LoadMeta(mem.Reverse().SelectMany(x => x.GetMetaDataILBytes()).ToArray()); | ||
|
||
var functions = Module.ImportFunctions(assembly.GetILCode(), module); | ||
|
||
Assert.AreEqual(3, functions.Length); | ||
} | ||
} | ||
} |