mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-05 12:16:53 +08:00
fiber ret updated before loading native modules
This commit is contained in:
parent
f249d118b2
commit
e316d53fa7
@ -370,7 +370,14 @@ static Module* _importDL(PKVM* vm, String* resolved, String* name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Since the DL library can use stack via slots api, we need to update
|
||||
// ret and then restore it back. We're using offset instead of a pointer
|
||||
// because the stack might be reallocated if it grows.
|
||||
uintptr_t ret_offset = vm->fiber->ret - vm->fiber->stack;
|
||||
vm->fiber->ret = vm->fiber->sp;
|
||||
PkHandle* pkhandle = vm->config.import_dl_fn(vm, handle);
|
||||
vm->fiber->ret = vm->fiber->stack + ret_offset;
|
||||
|
||||
if (pkhandle == NULL) {
|
||||
VM_SET_ERROR(vm, stringFormat(vm, "Error loading module at \"@\"",
|
||||
resolved));
|
||||
|
@ -169,6 +169,19 @@ DEF(stdMathArcTangent,
|
||||
pkSetSlotNumber(vm, 0, atan(num));
|
||||
}
|
||||
|
||||
DEF(stdMathArcTan2,
|
||||
"math.atan2(y:Number, x:Number) -> Number",
|
||||
"These functions calculate the principal value of the arc tangent "
|
||||
"of y / x, using the signs of the two arguments to determine the "
|
||||
"quadrant of the result") {
|
||||
|
||||
double y, x;
|
||||
if (!pkValidateSlotNumber(vm, 1, &y)) return;
|
||||
if (!pkValidateSlotNumber(vm, 2, &x)) return;
|
||||
|
||||
pkSetSlotNumber(vm, 0, atan2(y, x));
|
||||
}
|
||||
|
||||
DEF(stdMathLog10,
|
||||
"math.log10(value:Number) -> Number",
|
||||
"Return the logarithm to base 10 of argument [value]") {
|
||||
@ -226,6 +239,7 @@ void registerModuleMath(PKVM* vm) {
|
||||
REGISTER_FN(math, "asin", stdMathArcSine, 1);
|
||||
REGISTER_FN(math, "acos", stdMathArcCosine, 1);
|
||||
REGISTER_FN(math, "atan", stdMathArcTangent, 1);
|
||||
REGISTER_FN(math, "atan2", stdMathArcTan2, 2);
|
||||
REGISTER_FN(math, "log10", stdMathLog10, 1);
|
||||
REGISTER_FN(math, "round", stdMathRound, 1);
|
||||
REGISTER_FN(math, "rand", stdMathRand, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user