Add "task?" predicate
This commit is contained in:
parent
9501dea85a
commit
e2247d9bc8
2 changed files with 44 additions and 26 deletions
|
@ -451,6 +451,23 @@ Result<StackFrame> stdlib_task(const StackFrame& stack) {
|
|||
return res;
|
||||
}
|
||||
|
||||
Result<StackFrame> stdlib_is_task(const StackFrame& stack) {
|
||||
auto params = TRY(stack.get(0));
|
||||
|
||||
auto size = TRY(params.size());
|
||||
if (size != 1) return ERROR(ArgumentCountMismatch);
|
||||
|
||||
Value task = TRY(params.get(0));
|
||||
|
||||
auto val = Value(TRY(Bool::create(task.is<Task>())));
|
||||
|
||||
auto res = TRY(stack.set(0, val));
|
||||
|
||||
res = TRY(res.ret(0));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Result<StackFrame> stdlib_guard(const StackFrame& stack) {
|
||||
auto stack_size = TRY(stack.size());
|
||||
auto params = TRY(stack.get(0));
|
||||
|
@ -582,34 +599,34 @@ Result<StackFrame> stdlib_disassemble(const StackFrame& stack) {
|
|||
|
||||
return res;
|
||||
}
|
||||
#define STDLIB_FUNCTION(name, id) \
|
||||
[(uint64_t)StdlibFunctionId::id] = {#name, StdlibFunctionId::id, \
|
||||
stdlib_##name}
|
||||
#define STDLIB_FUNCTION(name, fun, id) \
|
||||
[(uint64_t)StdlibFunctionId::id] = {name, StdlibFunctionId::id, stdlib_##fun}
|
||||
|
||||
static StdlibFunctionEntry function_entries[] = {
|
||||
STDLIB_FUNCTION(unknown, Unknown),
|
||||
STDLIB_FUNCTION(print, Print),
|
||||
STDLIB_FUNCTION(println, PrintLn),
|
||||
STDLIB_FUNCTION(prn, Prn),
|
||||
STDLIB_FUNCTION(slurp, Slurp),
|
||||
STDLIB_FUNCTION(spit, Spit),
|
||||
STDLIB_FUNCTION(assert, Assert),
|
||||
STDLIB_FUNCTION(dict, Dict),
|
||||
STDLIB_FUNCTION(list, List),
|
||||
STDLIB_FUNCTION(array, Array),
|
||||
STDLIB_FUNCTION(get, Get),
|
||||
STDLIB_FUNCTION(set, Set),
|
||||
STDLIB_FUNCTION(srcloc, SrcLoc),
|
||||
STDLIB_FUNCTION(size, Size),
|
||||
STDLIB_FUNCTION(map, Map),
|
||||
STDLIB_FUNCTION(error, Error),
|
||||
STDLIB_FUNCTION(raise, Raise),
|
||||
STDLIB_FUNCTION(reraise, Reraise),
|
||||
STDLIB_FUNCTION(task, Task),
|
||||
STDLIB_FUNCTION(guard, Guard),
|
||||
STDLIB_FUNCTION(serialize, Serialize),
|
||||
STDLIB_FUNCTION(deserialize, Deserialize),
|
||||
STDLIB_FUNCTION(disassemble, Disassemble),
|
||||
STDLIB_FUNCTION("unknown", unknown, Unknown),
|
||||
STDLIB_FUNCTION("print", print, Print),
|
||||
STDLIB_FUNCTION("println", println, PrintLn),
|
||||
STDLIB_FUNCTION("prn", prn, Prn),
|
||||
STDLIB_FUNCTION("slurp", slurp, Slurp),
|
||||
STDLIB_FUNCTION("spit", spit, Spit),
|
||||
STDLIB_FUNCTION("assert", assert, Assert),
|
||||
STDLIB_FUNCTION("dict", dict, Dict),
|
||||
STDLIB_FUNCTION("list", list, List),
|
||||
STDLIB_FUNCTION("array", array, Array),
|
||||
STDLIB_FUNCTION("get", get, Get),
|
||||
STDLIB_FUNCTION("set", set, Set),
|
||||
STDLIB_FUNCTION("srcloc", srcloc, SrcLoc),
|
||||
STDLIB_FUNCTION("size", size, Size),
|
||||
STDLIB_FUNCTION("map", map, Map),
|
||||
STDLIB_FUNCTION("error", error, Error),
|
||||
STDLIB_FUNCTION("raise", raise, Raise),
|
||||
STDLIB_FUNCTION("reraise", reraise, Reraise),
|
||||
STDLIB_FUNCTION("task", task, Task),
|
||||
STDLIB_FUNCTION("task?", is_task, IsTask),
|
||||
STDLIB_FUNCTION("guard", guard, Guard),
|
||||
STDLIB_FUNCTION("serialize", serialize, Serialize),
|
||||
STDLIB_FUNCTION("deserialize", deserialize, Deserialize),
|
||||
STDLIB_FUNCTION("disassemble", disassemble, Disassemble),
|
||||
[(uint64_t)StdlibFunctionId::Max] = {0, StdlibFunctionId::Max,
|
||||
stdlib_unknown},
|
||||
};
|
||||
|
|
|
@ -24,6 +24,7 @@ enum class StdlibFunctionId : uint64_t {
|
|||
Raise,
|
||||
Reraise,
|
||||
Task,
|
||||
IsTask,
|
||||
Guard,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
|
|
Loading…
Reference in a new issue