新增builtin函数 type,接收一个参数,获取类型字符串。(类似 js) 标准库 std.value.type函数更名 _type返回底层类型

This commit is contained in:
2026-02-04 18:28:18 +08:00
parent b98c1b7dd8
commit e8aed221de
4 changed files with 20 additions and 10 deletions

View File

@@ -7,7 +7,7 @@
import _builtins;
public func type(object: Any) -> String
public func _type(object: Any) -> String
{
return __fvalue_type(object);
}

View File

@@ -1,10 +1,10 @@
#include "Ast/Expressions/BinaryExpr.hpp"
#include "Ast/Expressions/FunctionCall.hpp"
#include "Ast/Expressions/ValueExpr.hpp"
#include "Ast/Expressions/VarExpr.hpp"
#include "Ast/Statements/ControlSt.hpp"
#include "Ast/astBase.hpp"
#include "Ast/functionParameters.hpp"
#include <Ast/Expressions/BinaryExpr.hpp>
#include <Ast/Expressions/FunctionCall.hpp>
#include <Ast/Expressions/ValueExpr.hpp>
#include <Ast/Expressions/VarExpr.hpp>
#include <Ast/Statements/ControlSt.hpp>
#include <Ast/astBase.hpp>
#include <Ast/functionParameters.hpp>
#include <Evaluator/Context/context.hpp>
#include <Core/fig_string.hpp>
#include <Ast/AccessModifier.hpp>
@@ -75,6 +75,16 @@ namespace Fig::Builtins
{u8"Map", std::make_shared<Object>(StructType(ValueType::Map, nullptr, {}, true))},
// Type `StructType` `StructInstance` `Module` `InterfaceType`
// Not allowed to call constructor!
{u8"type", std::make_shared<Object>(Function(
u8"type",
[](const std::vector<ObjectPtr> &_args) -> ObjectPtr
{
const ObjectPtr &arg = _args[0];
return std::make_shared<Object>(prettyType(arg));
},
1
))},
};
return builtinValues;
}