Goose  Artifact [5ea98d41a8]

Artifact 5ea98d41a8aa980031915bc131288c8c42018f072b04bc65383b8b33ab07a748:

  • File bs/builtins/api/extensibility/valuewrapper.cpp — part of check-in [ceb0b190d6] at 2020-01-12 21:10:46 on branch trunk — builtins: added wrapper types to allow terms and values to be manipulated at low level within the language itself. (user: achavasse size: 726)

#include "builtins/builtins.h"
#include "ir/ir.h"

using namespace goose::builtins;

namespace goose::ir
{
    const Term& Bridge< ValueWrapper >::Type()
    {
        static auto type = ValueToIRExpr( Value( TypeType(), VEC( TSID( ct_type ), TSID( ext_valuewrapper ) ) ) );
        return type;
    }

    Value Bridge< ValueWrapper >::ToValue( const ValueWrapper& vw )
    {
        return Value( Type(), Quote( ValueToIRExpr( vw.get() ) ) );
    }

    optional< Value > Bridge< ValueWrapper >::FromValue( const Value& v )
    {
        if( v.type() != Type() )
            return nullopt;

        auto uq = Unquote( v.val() );
        if( !uq )
            return nullopt;

        return ValueFromIRExpr( *uq );
    }
}