void SignatureBuilder::writeParam(gc<Pattern> pattern) { // If it's a record, destructure it into the signature. RecordPattern* record = pattern->asRecordPattern(); if (record != NULL) { for (int i = 0; i < record->fields().count(); i++) { add(record->fields()[i].name); add(":"); } return; } // Any other pattern is implicitly a single-field record. add("0:"); }
void Resolver::allocateSlotsForParam(gc<Pattern> pattern) { // No parameter so do nothing. if (pattern.isNull()) return; RecordPattern* record = pattern->asRecordPattern(); if (record != NULL) { // Allocate each field. for (int i = 0; i < record->fields().count(); i++) { makeParamSlot(record->fields()[i].value); } } else { // If we got here, the pattern isn't a record, so it's a single slot. makeParamSlot(pattern); } }
void Resolver::destructureParam(gc<Pattern> pattern) { // No parameter so do nothing. if (pattern.isNull()) return; RecordPattern* record = pattern->asRecordPattern(); if (record != NULL) { // Resolve each field. for (int i = 0; i < record->fields().count(); i++) { resolveParam(record->fields()[i].value); } } else { // If we got here, the pattern isn't a record, so its a single slot. resolveParam(pattern); } }
void ExprCompiler::compileParam(PatternCompiler& compiler, gc<Pattern> param, int& slot) { // No parameter so do nothing. if (param.isNull()) return; RecordPattern* record = param->asRecordPattern(); if (record != NULL) { // Compile each field. for (int i = 0; i < record->fields().count(); i++) { compileParamField(compiler, record->fields()[i].value, slot++); } } else { // If we got here, the pattern isn't a record, so it's a single slot. compileParamField(compiler, param, slot++); } }
void Compiler::declareVariables(gc<Pattern> pattern, Module* module) { RecordPattern* record = pattern->asRecordPattern(); if (record != NULL) { for (int i = 0; i < record->fields().count(); i++) { declareVariables(record->fields()[i].value, module); } return; } VariablePattern* variable = pattern->asVariablePattern(); if (variable != NULL) { declareVariable(variable->pos(), variable->name(), module); if (!variable->pattern().isNull()) { declareVariables(variable->pattern(), module); } } }