コード例 #1
0
ファイル: Compiler.cpp プロジェクト: DawidvC/magpie
  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:");
  }
コード例 #2
0
ファイル: Resolver.cpp プロジェクト: relrod/magpie
 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);
   }
 }
コード例 #3
0
ファイル: Resolver.cpp プロジェクト: relrod/magpie
 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);
   }
 }
コード例 #4
0
  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++);
    }
  }
コード例 #5
0
ファイル: Compiler.cpp プロジェクト: DawidvC/magpie
  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);
      }
    }
  }