text: /* -*- mode: c; c-default-style: "bsd"; -*- */
  /* Copyright (c) 2020-2022 Charlie Burnett <burne251@umn.edu> */
  /* SPDX-License-Identifier: ISC OR Apache-2.0 */
  
  #include "block.h"
  #include "scope.h"
  #include "semantic_private.h"
  #include "term.h"
  
  void
  block_init(struct block *block)
  {
  	scope_init(&block->scope);
  	SIMPLEQ_INIT(&block->head);
  }
  
  /*
   * Add a term to a block, or create a block with a term if the block is null.
   *
   * @param block The block to add to, or a NULL pointer if creating one
   * @param term The term to tack on to the end of the block
   * @return The block with the appended term
   */
  
  block *
  block_add_term(struct block *block, struct term *term)
  {
  	if (block == NULL) {
  		block = ezalloc(sizeof(*block));
  		block_init(block);
  	}
  	SIMPLEQ_INSERT_TAIL(&block->head, term, entry);
  	return block;
  }
  