Skip to content

C# wrapper for the SAL-8 C99 implementation.

License

Notifications You must be signed in to change notification settings

exom-dev/SAL-8-Sharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

About .Net Framework 4.5

This is a C# wrapper for the SAL-8 C99 implementation, an interpreted 8-bit simple assembly-like language.

For more details, see the SAL-8 repository.

Usage

The wrapper is already documented (see the source file). Here's an example showcasing most of the wrapper functionality:

using SAL8;

...

static void Main(string[] args) {
    try
    {
        string src = File.ReadAllText("script.sal8");
        
        Compiler compiler = new Compiler();

        Cluster cl = compiler.Compile(src);

        VM vm = new VM();

        vm.Load(cl);
        vm.Run(); // Runs all instructions. You can also run a limited number of them like this:
        
        /* while(!vm.Finished())
         *     vm.Run(1); // One at a time. You can do anything between the runs.
         *
         * // To get the index of the first instruction that will be executed next time you call Run(),
         * // use the vm.GetCurrentInstructionIndex() function. You can combine this with Run(1) to create
         * // a simple step-by-step debugging feature for your game/project.
         */

        // Outputs the values of all registers.
        for(byte i = 0; i < vm.GetRegisterCount(); ++i)
            Console.WriteLine("R" + i + "  " + vm.GetRegisterValue(i));

        // Outputs the value of the CMP register.
        Console.WriteLine("\nCMP " + vm.GetCmpRegisterValue() + "\n");

        // Outputs the whole stack.
        for(byte i = (byte)(vm.GetStackCapacity() - 1); ; --i)
        {
            Console.WriteLine("S" + i + "  " + vm.GetStackValue(i));

            if(i == 0)
                break;
        }

        // Important: after you're done using the Cluster object, destroy it.
        cl.Destroy();
    }
    catch(CompileTimeException)
    {
        // Compile time error
    }
    catch(RuntimeException)
    {
        // Runtime error
    }
    catch(Exception ex)
    {
        // Something else
    }
}
...

License License: MIT

This project was created by The Exom Developers. It is licensed under the MIT license.

About

C# wrapper for the SAL-8 C99 implementation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages