!!--WARNING--!!
Now repository includes only Nan Virtual Machine. In future should includes also Nan Language Compiler for Nan Virtual Machine See library native usage
Nan Language compiler for Nan Virtual Machine. Also includes own Nan Virtual Machine. Uses cmake for build. Binary nan (./src) - test (in the future, a complete compiler for Nan Language). Binary nanvm (./vm) - Nan Virtual Machine executable for *.nb
file ak binary nvm files.
./nan
./nanvm "path/to/file"
- Virtual Machine provides in virtual.hpp.
- Virtual Machine Lib provides in virtuallib.hpp
VM uses virtual namespace. VM Lib uses virtual::lib namespace
See /nan for in code documentation
- std::console - /nan/write.nan
- std::allocator - /nan/allocator.nan
- test std - /nan/test_std.nan
- test preprocessing - /nan/preprocess.nan
- test pointers - /nan/pointers.nan
- windows - tested
- ubuntu - not full test (errored)
print 'hellow word' to console
#include "virtual.hpp"
int main() {
//! build simple code
using namespace Virtual;
CodeBuilder builder;
// puts - print wchar_t string from data which ends with zero byte
builder << Instruction_PUTS;
builder << 0U;
// !important - exit of program, else can run data bytes
// if used default vm flag HeapLockExecute should errored without 'EXIT'
builder << Instruction_EXIT;
// add data at offset +0
builder += L"hellow word";
// release code
Code* code = *builder;
//! save & execute from saved file
// save code to file
Code_SaveFromFile(*code, "./hellow_word.nb");
// execute from file
Execute("./hellow_word.nb");
//! execute from runtime
// execute from code
Execute(*code);
//! manial execution
// execute with own vm
VirtualMachine vm;
// allocate memory needs for code
Alloc(vm, *code);
// load memory from code
LoadMemory(vm, *code);
// execute code
Run(vm, *code);
}
for the inserted code, it is best to use 'virtualdub.hpp'. Otherwise, you will have to count bytes for jumps. The 'CodeBuilder' from 'virtual' is used only by internal build tools
print number from 1 to 10
#include "virtuallib.hpp"
int main() {
using namespace Virtual;
using namespace Virtual::Lib;
Builder b;
b.BeginFunction("main");
/* TEST 'for' */
b.BeginFunction("l1");
/* 'for (int i = 0; i < 10; i)' */
b.BeginForI("i", 0, 10);
/*{*/
/* */ b.Puti();
/*}*/
b.EndForI("i");
// save for read
b.Save("./vlib-for-10.nb");
// build & run code
b.Run();
}