forked from PuqiAR/Fig-TreeWalker
[VER] v0.4.1-alpha
[Fix] 修复struct定义创建instanceCtx时拷贝类方法错误的Bug,表现在同一类的2个不同实例内置函数一样的问题
(即 addr A != addr B, addr A.method == addr B.method)
修复后为 (addr A != addr B, addr A.method != addr B.method)
方法的closureContext指向instance的Context
修复后 std.time可以正常使用
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
#define __FCORE_VERSION "0.4.0-alpha"
|
||||
#define __FCORE_VERSION "0.4.1-alpha"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define __FCORE_PLATFORM "Windows"
|
||||
|
||||
@@ -984,17 +984,42 @@ namespace Fig
|
||||
}
|
||||
}
|
||||
}
|
||||
instanceCtx->merge(*structT.defContext);
|
||||
for (auto &[id, fn] : instanceCtx->getFunctions())
|
||||
// instanceCtx->merge(*structT.defContext);
|
||||
// for (auto &[id, fn] : instanceCtx->getFunctions())
|
||||
// {
|
||||
// instanceCtx->_update(*instanceCtx->getFunctionName(id),
|
||||
// std::make_shared<Object>(Function(fn.paras,
|
||||
// fn.retType,
|
||||
// fn.body,
|
||||
// instanceCtx) // change its closureContext to
|
||||
// // struct instance's context
|
||||
// ));
|
||||
// }
|
||||
|
||||
ContextPtr stDefCtx = structT.defContext;
|
||||
|
||||
// load struct method
|
||||
for (auto &[id, fn] : stDefCtx->getFunctions())
|
||||
{
|
||||
instanceCtx->_update(*instanceCtx->getFunctionName(id),
|
||||
std::make_shared<Object>(Function(fn.paras,
|
||||
fn.retType,
|
||||
fn.body,
|
||||
instanceCtx) // change its closureContext to
|
||||
// struct instance's context
|
||||
));
|
||||
auto funcNameOpt = stDefCtx->getFunctionName(id);
|
||||
assert(funcNameOpt.has_value());
|
||||
|
||||
const FString &funcName = *funcNameOpt;
|
||||
auto funcSlot = stDefCtx->get(funcName);
|
||||
|
||||
instanceCtx->def(
|
||||
funcName,
|
||||
ValueType::Function,
|
||||
funcSlot->am,
|
||||
std::make_shared<Object>(Function(
|
||||
fn.paras,
|
||||
fn.retType,
|
||||
fn.body,
|
||||
instanceCtx
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
return std::make_shared<Object>(StructInstance(structT.type, instanceCtx));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user