[Fix] 修复builtin type的方法可能会导致 bad_variant_access的问题。现在Function严格区分3中函数:
Normal, Builtin, MemberType
[Feat] 增加了 Repl! 通过 Fig -r/--repl进入。目前必须写分号,且异常产生时因为获取不到源文件会有意想不到的问题 :(
[Impl] 精简了Context类,减少内存占用。当然,一些内置函数名获取不了了
后续的 Fig lang standard (目前还没有)中内置函数(MemberType/Builtin)严格无异常抛出
[Feat] 写了个Simple Compiler 和 Bytecode VM作为测试。性能拉跨。优化目前停止
[...] 剩下的忘了~
75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <Evaluator/Value/value.hpp>
|
|
#include <Bytecode/CallFrame.hpp>
|
|
|
|
#include <vector>
|
|
|
|
namespace Fig
|
|
{
|
|
class VirtualMachine
|
|
{
|
|
private:
|
|
std::vector<CallFrame> frames;
|
|
CallFrame *currentFrame;
|
|
|
|
std::vector<Object> stack;
|
|
Object *stack_top;
|
|
|
|
public:
|
|
void Clean()
|
|
{
|
|
frames.clear();
|
|
stack.clear();
|
|
|
|
currentFrame = nullptr;
|
|
stack_top = nullptr;
|
|
}
|
|
|
|
void addFrame(const CallFrame &_frame)
|
|
{
|
|
frames.push_back(_frame);
|
|
currentFrame = &frames.back();
|
|
}
|
|
|
|
CallFrame popFrame()
|
|
{
|
|
assert((!frames.empty()) && "frames is empty!");
|
|
|
|
CallFrame back = *currentFrame;
|
|
frames.pop_back();
|
|
currentFrame = (frames.empty() ? nullptr : &frames.back());
|
|
|
|
return back;
|
|
}
|
|
|
|
void push(const Object &_object)
|
|
{
|
|
stack.push_back(_object);
|
|
stack_top = &stack.back();
|
|
}
|
|
|
|
void nextIns(CallFrame &frame) const
|
|
{
|
|
frame.ip += 1;
|
|
}
|
|
|
|
Object pop()
|
|
{
|
|
assert((!stack.empty()) && "stack is empty!");
|
|
|
|
Object back = *stack_top;
|
|
stack.pop_back();
|
|
stack_top = (stack.empty() ? nullptr : &stack.back());
|
|
|
|
return back;
|
|
}
|
|
|
|
VirtualMachine(const CallFrame &_frame)
|
|
{
|
|
addFrame(_frame);
|
|
}
|
|
|
|
Object Execute();
|
|
};
|
|
}; |