mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 19:36:32 +00:00
128 lines
3.0 KiB
C++
128 lines
3.0 KiB
C++
#include "arch.hpp"
|
|
#include "vm.hpp"
|
|
#include <format>
|
|
#include <iostream>
|
|
#include <utility>
|
|
#include <variant>
|
|
|
|
int main()
|
|
{
|
|
using sliger::Op;
|
|
|
|
// fn add(a, b) {
|
|
// + a b
|
|
// }
|
|
//
|
|
// let result = 0;
|
|
// let i = 0;
|
|
// loop {
|
|
// if i >= 10 {
|
|
// break;
|
|
// }
|
|
// result = add(result, 5);
|
|
// }
|
|
auto program = std::vector<uint32_t> {
|
|
std::to_underlying(Op::SourceMap),
|
|
0,
|
|
0,
|
|
0,
|
|
std::to_underlying(Op::PushPtr),
|
|
15, // main
|
|
std::to_underlying(Op::Call),
|
|
0,
|
|
std::to_underlying(Op::Pop),
|
|
std::to_underlying(Op::PushPtr),
|
|
87, // .l3
|
|
std::to_underlying(Op::Jump),
|
|
std::to_underlying(Op::Pop),
|
|
/*add*/ std::to_underlying(Op::SourceMap),
|
|
19,
|
|
2,
|
|
5,
|
|
std::to_underlying(Op::Add),
|
|
std::to_underlying(Op::Return),
|
|
/*main*/ std::to_underlying(Op::SourceMap),
|
|
28,
|
|
5,
|
|
1,
|
|
std::to_underlying(Op::PushInt),
|
|
0,
|
|
std::to_underlying(Op::SourceMap),
|
|
44,
|
|
6,
|
|
1,
|
|
std::to_underlying(Op::PushInt),
|
|
0,
|
|
std::to_underlying(Op::SourceMap),
|
|
55,
|
|
7,
|
|
1,
|
|
/*.l0*/ std::to_underlying(Op::SourceMap),
|
|
66,
|
|
8,
|
|
5,
|
|
std::to_underlying(Op::LoadLocal),
|
|
1,
|
|
std::to_underlying(Op::PushInt),
|
|
0,
|
|
std::to_underlying(Op::LessThan),
|
|
std::to_underlying(Op::Not),
|
|
std::to_underlying(Op::PushPtr),
|
|
53, // .l1
|
|
std::to_underlying(Op::JumpIfFalse),
|
|
std::to_underlying(Op::SourceMap),
|
|
87,
|
|
9,
|
|
9,
|
|
std::to_underlying(Op::PushPtr),
|
|
83, // .l2
|
|
std::to_underlying(Op::Jump),
|
|
/*.l1*/ std::to_underlying(Op::SourceMap),
|
|
104,
|
|
11,
|
|
5,
|
|
std::to_underlying(Op::LoadLocal),
|
|
0,
|
|
std::to_underlying(Op::PushInt),
|
|
5,
|
|
std::to_underlying(Op::PushPtr),
|
|
9, // add
|
|
std::to_underlying(Op::Call),
|
|
2,
|
|
std::to_underlying(Op::StoreLocal),
|
|
0,
|
|
std::to_underlying(Op::SourceMap),
|
|
133,
|
|
12,
|
|
5,
|
|
std::to_underlying(Op::LoadLocal),
|
|
1,
|
|
std::to_underlying(Op::PushInt),
|
|
1,
|
|
std::to_underlying(Op::Add),
|
|
std::to_underlying(Op::StoreLocal),
|
|
1,
|
|
std::to_underlying(Op::PushPtr),
|
|
33, // .l0
|
|
std::to_underlying(Op::Jump),
|
|
/*.l2*/ std::to_underlying(Op::Pop),
|
|
std::to_underlying(Op::Pop),
|
|
std::to_underlying(Op::PushNull),
|
|
std::to_underlying(Op::Return),
|
|
/*.l3*/ std::to_underlying(Op::SourceMap),
|
|
147,
|
|
15,
|
|
1,
|
|
std::to_underlying(Op::PushInt),
|
|
};
|
|
|
|
auto vm = sliger::VM(program,
|
|
{
|
|
.flame_graph = true,
|
|
.code_coverage = true,
|
|
});
|
|
vm.run_until_done();
|
|
|
|
vm.print_stack();
|
|
}
|