You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
54 lines
1.2 KiB
1 year ago
|
/*
|
||
|
* Copyright (C) 2023 Riyyi
|
||
|
*
|
||
|
* SPDX-License-Identifier: MIT
|
||
|
*/
|
||
|
|
||
|
#include "ast.h"
|
||
|
#include "env/macro.h"
|
||
|
#include "error.h"
|
||
|
#include "forward.h"
|
||
|
#include "util.h"
|
||
|
|
||
|
namespace blaze {
|
||
|
|
||
|
// (meta [1 2 3])
|
||
|
ADD_FUNCTION(
|
||
|
"meta",
|
||
|
{
|
||
|
CHECK_ARG_COUNT_IS("meta", SIZE(), 1);
|
||
|
|
||
|
auto front = *begin;
|
||
|
Value* front_raw_ptr = begin->get();
|
||
|
|
||
|
if (!is<Collection>(front_raw_ptr) && // List / Vector
|
||
|
!is<HashMap>(front_raw_ptr) && // HashMap
|
||
|
!is<Callable>(front_raw_ptr)) { // Function / Lambda
|
||
|
Error::the().add(::format("wrong argument type: Collection, HashMap or Callable, {}", front));
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
|
return front->meta();
|
||
|
});
|
||
|
|
||
|
// (with-meta [1 2 3] "some metadata")
|
||
|
ADD_FUNCTION(
|
||
|
"with-meta",
|
||
|
{
|
||
|
CHECK_ARG_COUNT_IS("with-meta", SIZE(), 2);
|
||
|
|
||
|
auto front = *begin;
|
||
|
Value* front_raw_ptr = begin->get();
|
||
|
|
||
|
if (!is<Collection>(front_raw_ptr) && // List / Vector
|
||
|
!is<HashMap>(front_raw_ptr) && // HashMap
|
||
|
!is<Callable>(front_raw_ptr)) { // Function / Lambda
|
||
|
Error::the().add(::format("wrong argument type: Collection, HashMap or Callable, {}", front));
|
||
|
return nullptr;
|
||
|
}
|
||
|
|
||
|
return front->withMeta(*(begin + 1));
|
||
|
});
|
||
|
|
||
|
} // namespace blaze
|