static JsonElement *RlistToJson(Rlist *list) { JsonElement *array = JsonArrayCreate(RlistLen(list)); for (Rlist *rp = list; rp; rp = rp->next) { switch (rp->val.type) { case RVAL_TYPE_SCALAR: JsonArrayAppendString(array, RlistScalarValue(rp)); break; case RVAL_TYPE_LIST: JsonArrayAppendArray(array, RlistToJson(RlistRlistValue(rp))); break; case RVAL_TYPE_FNCALL: JsonArrayAppendObject(array, FnCallToJson(RlistFnCallValue(rp))); break; default: assert(false && "Unsupported item type in rlist"); break; } } return array; }
JsonElement *RvalToJson(Rval rval) { assert(rval.item); switch (rval.type) { case RVAL_TYPE_SCALAR: return JsonStringCreate(RvalScalarValue(rval)); case RVAL_TYPE_LIST: return RlistToJson(RvalRlistValue(rval)); case RVAL_TYPE_FNCALL: return FnCallToJson(RvalFnCallValue(rval)); default: assert(false && "Invalid rval type"); return JsonStringCreate(""); } }
JsonElement *RvalToJson(Rval rval) { assert(rval.item); switch (rval.type) { case RVAL_TYPE_SCALAR: return JsonStringCreate(RvalScalarValue(rval)); case RVAL_TYPE_LIST: return RlistToJson(RvalRlistValue(rval)); case RVAL_TYPE_FNCALL: return FnCallToJson(RvalFnCallValue(rval)); case RVAL_TYPE_CONTAINER: return JsonCopy(RvalContainerValue(rval)); case RVAL_TYPE_NOPROMISEE: assert(false); return JsonObjectCreate(1); } assert(false); return NULL; }