A few simplifications of object conversion
This commit is contained in:
parent
82b75e1448
commit
51dfe6ac5a
6 changed files with 19 additions and 7 deletions
|
@ -1163,6 +1163,13 @@ Result<Value> reverse(Value& val);
|
|||
Result<void> debug_print(const String& val);
|
||||
Result<void> debug_print(const Value& val);
|
||||
|
||||
template <class T>
|
||||
Result<void> debug_print(const T& val)
|
||||
requires std::derived_from<T, Object>
|
||||
{
|
||||
return debug_print(TRY(val.copy_value()));
|
||||
}
|
||||
|
||||
template <class K, class V>
|
||||
Result<Dict> Dict::insert(const K& key, const V& value) {
|
||||
Value k = TRY(Value::create(key));
|
||||
|
|
|
@ -610,9 +610,9 @@ Result<Expression> Compiler::compile_fn(Context& context, Symbol& op,
|
|||
TRY(Array::create())));
|
||||
|
||||
// std::cout << "--------------- LAMBDA " << arity << "\n";
|
||||
// TRY(debug_print(TRY(expr.copy_value())));
|
||||
// TRY(debug_print(TRY(ctx.constants.copy())));
|
||||
// TRY(debug_print(TRY(ex.code.copy())));
|
||||
// TRY(debug_print(expr));
|
||||
// TRY(debug_print(ctx.constants));
|
||||
// TRY(debug_print(ex.code));
|
||||
|
||||
Expression ex_res = TRY(Expression::create());
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ Result<void> run_repl() {
|
|||
}
|
||||
|
||||
Result<void> run(int argc, const char* argv[]) {
|
||||
String src = DIEX(String::create(""));
|
||||
String src = TRY(String::create(""));
|
||||
if (argc == 1) {
|
||||
if (stdin_isatty()) {
|
||||
return run_repl();
|
||||
|
|
|
@ -231,7 +231,7 @@ Result<void> VM::step() {
|
|||
if (!opcode.is<Opcode>()) return ERROR(TypeMismatch);
|
||||
Opcode& oc = *opcode.to<Opcode>();
|
||||
|
||||
// TRY(debug_print(TRY(oc.copy_value())));
|
||||
// TRY(debug_print(oc));
|
||||
|
||||
switch (oc.opcode()) {
|
||||
case Oc::Mov:
|
||||
|
|
|
@ -36,7 +36,7 @@ Result<String> write_one(const T& value)
|
|||
requires std::derived_from<T, Object>
|
||||
{
|
||||
auto w = Writer();
|
||||
auto v = DIEX(value.copy_value());
|
||||
auto v = TRY(value.copy_value());
|
||||
return w.write_one(v);
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,6 @@ Result<String> write_multiple(const T& value)
|
|||
requires std::derived_from<T, Object>
|
||||
{
|
||||
auto w = Writer();
|
||||
auto v = DIEX(value.copy_value());
|
||||
auto v = TRY(value.copy_value());
|
||||
return w.write_multiple(v);
|
||||
}
|
||||
|
|
|
@ -11,3 +11,8 @@
|
|||
(let ((square (fn (x) (* x x))))
|
||||
(assert (= (square 4) 16))
|
||||
)
|
||||
|
||||
(let ((x 42))
|
||||
(assert (= ((fn (y) (+ x y) 1)
|
||||
43)))
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue