forked from PuqiAR/Fig-TreeWalker
新增builtin函数 type,接收一个参数,获取类型字符串。(类似 js) 标准库 std.value.type函数更名 _type返回底层类型
This commit is contained in:
@@ -64,7 +64,7 @@ namespace Fig
|
|||||||
fnName.toBasicString(),
|
fnName.toBasicString(),
|
||||||
fn.builtinParamCount,
|
fn.builtinParamCount,
|
||||||
evaluatedArgs.getLength()),
|
evaluatedArgs.getLength()),
|
||||||
fnArgs.argv.back());
|
(fnArgs.getLength() > 0 ? fnArgs.argv.back() : call));
|
||||||
}
|
}
|
||||||
return executeFunction(fn, evaluatedArgs, nullptr);
|
return executeFunction(fn, evaluatedArgs, nullptr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Evaluator/Core/ExprResult.hpp"
|
#include <Evaluator/Core/ExprResult.hpp>
|
||||||
#include <Ast/AccessModifier.hpp>
|
#include <Ast/AccessModifier.hpp>
|
||||||
#include <Ast/Expressions/FunctionCall.hpp>
|
#include <Ast/Expressions/FunctionCall.hpp>
|
||||||
#include <Ast/astBase.hpp>
|
#include <Ast/astBase.hpp>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
import _builtins;
|
import _builtins;
|
||||||
|
|
||||||
public func type(object: Any) -> String
|
public func _type(object: Any) -> String
|
||||||
{
|
{
|
||||||
return __fvalue_type(object);
|
return __fvalue_type(object);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "Ast/Expressions/BinaryExpr.hpp"
|
#include <Ast/Expressions/BinaryExpr.hpp>
|
||||||
#include "Ast/Expressions/FunctionCall.hpp"
|
#include <Ast/Expressions/FunctionCall.hpp>
|
||||||
#include "Ast/Expressions/ValueExpr.hpp"
|
#include <Ast/Expressions/ValueExpr.hpp>
|
||||||
#include "Ast/Expressions/VarExpr.hpp"
|
#include <Ast/Expressions/VarExpr.hpp>
|
||||||
#include "Ast/Statements/ControlSt.hpp"
|
#include <Ast/Statements/ControlSt.hpp>
|
||||||
#include "Ast/astBase.hpp"
|
#include <Ast/astBase.hpp>
|
||||||
#include "Ast/functionParameters.hpp"
|
#include <Ast/functionParameters.hpp>
|
||||||
#include <Evaluator/Context/context.hpp>
|
#include <Evaluator/Context/context.hpp>
|
||||||
#include <Core/fig_string.hpp>
|
#include <Core/fig_string.hpp>
|
||||||
#include <Ast/AccessModifier.hpp>
|
#include <Ast/AccessModifier.hpp>
|
||||||
@@ -75,6 +75,16 @@ namespace Fig::Builtins
|
|||||||
{u8"Map", std::make_shared<Object>(StructType(ValueType::Map, nullptr, {}, true))},
|
{u8"Map", std::make_shared<Object>(StructType(ValueType::Map, nullptr, {}, true))},
|
||||||
// Type `StructType` `StructInstance` `Module` `InterfaceType`
|
// Type `StructType` `StructInstance` `Module` `InterfaceType`
|
||||||
// Not allowed to call constructor!
|
// 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;
|
return builtinValues;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user