Now you can break, continue and return in try statements

This commit is contained in:
2025-05-17 19:26:49 -05:00
parent bb19d2444c
commit 4beb22cef4
5 changed files with 150 additions and 8 deletions

View File

@ -5153,6 +5153,57 @@ namespace Tesses::CrossLang {
}
return false;
}
bool InterperterThread::JumpIfBreak(GC* gc)
{
std::vector<CallStackEntry*>& cse=this->call_stack_entries;
auto stk = cse.back();
if(stk->ip + 4 <= stk->callable->closure->code.size())
{
uint32_t n=BitConverter::ToUint32BE(stk->callable->closure->code[stk->ip]);
GCList ls(gc);
auto _res2 = stk->Pop(ls);
stk->ip = stk->ip + 4;
if(std::holds_alternative<TBreak>(_res2))
stk->ip = n;
else
stk->Push(gc,_res2);
}
else
throw VMException("Can't read jmpifbreak pc.");
return false;
}
bool InterperterThread::JumpIfContinue(GC* gc)
{
std::vector<CallStackEntry*>& cse=this->call_stack_entries;
auto stk = cse.back();
if(stk->ip + 4 <= stk->callable->closure->code.size())
{
uint32_t n=BitConverter::ToUint32BE(stk->callable->closure->code[stk->ip]);
GCList ls(gc);
auto _res2 = stk->Pop(ls);
stk->ip = stk->ip + 4;
if(std::holds_alternative<TContinue>(_res2))
stk->ip = n;
else
stk->Push(gc,_res2);
}
else
throw VMException("Can't read jmpifcontinue pc.");
return false;
}
bool InterperterThread::JumpUndefined(GC* gc)
{
@ -5201,6 +5252,24 @@ namespace Tesses::CrossLang {
stk->Push(gc,nullptr);
return false;
}
bool InterperterThread::PushBreak(GC* gc)
{
std::vector<CallStackEntry*>& cse=this->call_stack_entries;
auto stk = cse.back();
stk->Push(gc,TBreak());
return false;
}
bool InterperterThread::PushContinue(GC* gc)
{
std::vector<CallStackEntry*>& cse=this->call_stack_entries;
auto stk = cse.back();
stk->Push(gc,TContinue());
return false;
}
bool InterperterThread::PushUndefined(GC* gc)
{