Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/VM/src/ldo.h
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
// This code is based on Lua 5.x implementation licensed under MIT License; see lua_LICENSE.txt for details
3
#pragma once
4
5
#include "lobject.h"
6
#include "lstate.h"
7
#include "luaconf.h"
8
#include "ldebug.h"
9
10
// returns target stack for 'n' extra elements to reallocate
11
// if possible, stack size growth factor is 2x
12
#define getgrownstacksize(L, n) ((n) <= L->stacksize ? 2 * L->stacksize : L->stacksize + (n))
13
#define stacklimitreached(L, n) ((char*)L->stack_last - (char*)L->top <= (n) * (int)sizeof(TValue))
14
15
#define luaD_checkstackfornewci(L, n) \
16
if (stacklimitreached(L, (n))) \
17
luaD_reallocstack(L, getgrownstacksize(L, (n)), 1); \
18
else \
19
condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK, 1));
20
21
#define luaD_checkstack(L, n) \
22
if (stacklimitreached(L, (n))) \
23
luaD_growstack(L, n); \
24
else \
25
condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK, 0));
26
27
#define incr_top(L) \
28
{ \
29
luaD_checkstack(L, 1); \
30
L->top++; \
31
}
32
33
#define savestack(L, p) ((char*)(p) - (char*)L->stack)
34
#define restorestack(L, n) ((TValue*)((char*)L->stack + (n)))
35
36
#define expandstacklimit(L, p) \
37
{ \
38
LUAU_ASSERT((p) <= (L)->stack_last); \
39
if ((L)->ci->top < (p)) \
40
(L)->ci->top = (p); \
41
}
42
43
#define incr_ci(L) ((L->ci == L->end_ci) ? luaD_growCI(L) : (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci))
44
45
#define saveci(L, p) ((char*)(p) - (char*)L->base_ci)
46
#define restoreci(L, n) ((CallInfo*)((char*)L->base_ci + (n)))
47
48
#define isyielded(L) ((L)->status == LUA_YIELD || (L)->status == LUA_BREAK || (L)->status == SCHEDULED_REENTRY)
49
50
// results from luaD_precall
51
#define PCRLUA 0 // initiated a call to a Lua function
52
#define PCRC 1 // did a call to a C function
53
#define PCRYIELD 2 // C function yielded
54
55
// return value for a yielded C call
56
#define C_CALL_YIELD -1
57
58
// luaD_call can 'yield' into an immediate reentry
59
// reentry will remove extra call frames from C call stack and continue execution
60
// this lua_State::status code is internal and should not be used by users
61
#define SCHEDULED_REENTRY 0x7f
62
63
// type of protected functions, to be ran by `runprotected'
64
typedef void (*Pfunc)(lua_State* L, void* ud);
65
66
LUAI_FUNC CallInfo* luaD_growCI(lua_State* L);
67
68
LUAI_FUNC void luaD_callint(lua_State* L, StkId func, int nresults, bool forreentry);
69
LUAI_FUNC void luaD_call(lua_State* L, StkId func, int nresults);
70
LUAI_FUNC void luaD_callny(lua_State* L, StkId func, int nresults);
71
LUAI_FUNC int luaD_pcall(lua_State* L, Pfunc func, void* u, ptrdiff_t oldtop, ptrdiff_t ef);
72
LUAI_FUNC void luaD_reallocCI(lua_State* L, int newsize);
73
LUAI_FUNC void luaD_reallocstack(lua_State* L, int newsize, int fornewci);
74
LUAI_FUNC void luaD_growstack(lua_State* L, int n);
75
LUAI_FUNC void luaD_checkCstack(lua_State* L);
76
LUAI_FUNC void luaD_seterrorobj(lua_State* L, int errcode, StkId oldtop);
77
78
LUAI_FUNC l_noret luaD_throw(lua_State* L, int errcode);
79
LUAI_FUNC int luaD_rawrunprotected(lua_State* L, Pfunc f, void* ud);
80
81