Fix stdlib value returns

This commit is contained in:
Konstantin Nazarov 2024-09-15 20:09:11 +01:00
parent 2e37e4160d
commit 1733b0e433
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22

View file

@ -20,24 +20,32 @@ Result<StackFrame> stdlib_unknown(const StackFrame& stack) {
Result<StackFrame> stdlib_print(const StackFrame& stack) {
auto params = TRY(stack.get(0));
auto size = TRY(params.size());
String str = TRY(String::create(""));
for (uint64_t i = 0; i < size; i++) {
Value param = TRY(params.get(i));
if (i != 0) {
std::cout << " ";
str = TRY(str.concat(" "));
}
if (param.is<String>()) {
TRY(print_string(*param.to<String>()));
str = TRY(str.concat(*param.to<String>()));
} else {
auto s = TRY(write_one(param));
TRY(print_string(s));
str = TRY(str.concat(s));
}
}
TRY(print_string(str));
auto nil = Value(TRY(Nil::create()));
auto res = TRY(stack.set(0, nil));
return res.ret(0);
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
Result<StackFrame> stdlib_println(const StackFrame& stack) {
@ -64,7 +72,10 @@ Result<StackFrame> stdlib_assert(const StackFrame& stack) {
auto nil = Value(TRY(Nil::create()));
auto res = TRY(stack.set(0, nil));
return res.ret(0);
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
Result<StackFrame> stdlib_dict(const StackFrame& stack) {
@ -73,7 +84,11 @@ Result<StackFrame> stdlib_dict(const StackFrame& stack) {
Value d = TRY(Dict::create(*params.to<Array>()));
auto res = TRY(stack.set(0, d));
return res.ret(0);
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
Result<StackFrame> stdlib_list(const StackFrame& stack) {
@ -82,14 +97,22 @@ Result<StackFrame> stdlib_list(const StackFrame& stack) {
Value d = TRY(Pair::create(*params.to<Array>()));
auto res = TRY(stack.set(0, d));
return res.ret(0);
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
Result<StackFrame> stdlib_array(const StackFrame& stack) {
auto params = TRY(stack.get(0));
auto res = TRY(stack.set(0, params));
return res.ret(0);
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
Result<StackFrame> stdlib_get(const StackFrame& stack) {
@ -103,7 +126,11 @@ Result<StackFrame> stdlib_get(const StackFrame& stack) {
auto val = TRY(collection.get(key));
auto res = TRY(stack.set(0, val));
return res.ret(0);
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
Result<StackFrame> stdlib_srcloc(const StackFrame& stack) {
@ -143,7 +170,11 @@ Result<StackFrame> stdlib_srcloc(const StackFrame& stack) {
auto val = Value(TRY(SrcLoc::create(sr)));
auto res = TRY(stack.set(0, val));
return res.ret(0);
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
Result<StackFrame> stdlib_size(const StackFrame& stack) {
@ -158,7 +189,11 @@ Result<StackFrame> stdlib_size(const StackFrame& stack) {
auto val = Value(TRY(Int64::create((int64_t)psize)));
auto res = TRY(stack.set(0, val));
return res.ret(0);
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
Result<StackFrame> stdlib_map(const StackFrame& stack_param) {