MCPcopy Create free account
hub / github.com/Meridian59/Meridian59 / codegen_message

Function codegen_message

blakcomp/codegen.c:713–754  ·  view source on GitHub ↗

/ * codegen_message: Generate code for a single message handler. */

Source from the content-addressed store, hash-verified

711 * codegen_message: Generate code for a single message handler.
712 */
713void codegen_message(message_handler_type m)
714{
715 int numlocals, maxtemp, maxlocals;
716 list_type s, p = m->header->params;
717 long localpos;
718
719 /* Leave space for # of local variables */
720 localpos = FileCurPos(outfile);
721 OutputByte(outfile, (BYTE) 0);
722
723 /* Write out # of arguments */
724 OutputByte(outfile, (BYTE) list_length(p));
725
726 /* Write out arguments themselves */
727 for ( ; p != NULL; p = p->next)
728 codegen_parameter( (param_type) p->data);
729
730 /* # of local variables, including parameters. -1 is to start at 0. */
731 numlocals = list_length(m->locals) + list_length(m->header->params) - 1;
732 maxlocals = numlocals;
733
734 /* Write out code */
735 for (s = m->body; s != NULL; s = s->next)
736 {
737 maxtemp = codegen_statement( (stmt_type) s->data, numlocals);
738 if (maxtemp > maxlocals)
739 maxlocals = maxtemp;
740
741 /* Bomb out if statement had unforseen errors */
742 if (!codegen_ok)
743 return;
744 }
745
746 /* Backpatch in # of local variables */
747 if (maxlocals > MAX_LOCALS)
748 codegen_error("More than %d local variables in handler %s.", MAX_LOCALS,
749 m->header->message_id->name);
750
751 FileGoto(outfile, localpos);
752 OutputByte(outfile, (BYTE) (maxlocals + 1)); /* +1 because we start counting at 0 */
753 FileGotoEnd(outfile);
754}
755/************************************************************************/
756/*
757 * codegen_class: Generate code for a single class.

Callers 1

codegen_classFunction · 0.85

Calls 5

OutputByteFunction · 0.85
codegen_parameterFunction · 0.85
codegen_statementFunction · 0.85
codegen_errorFunction · 0.85
list_lengthFunction · 0.70

Tested by

no test coverage detected