コード例 #1
0
ファイル: compiler.c プロジェクト: gundermanc/gunderscript
/**
 * Creates a new compiler object that will contain the current state of the
 * compiler and its data structures.
 * returns: new compiler object, or NULL if the allocation fails.
 */
Compiler * compiler_new(VM * vm) {

  assert(vm != NULL);

  Compiler * compiler = calloc(1, sizeof(Compiler));

  /* check for failed allocation */
  if(compiler == NULL) {
    return NULL;
  }

  /* TODO: make this stack auto expand when full */
  compiler->compiledScripts = set_new();
  compiler->symTableStk = stk_new(maxFuncDepth);
  compiler->vm = vm;

  /* check for further malloc errors */
  if(compiler->compiledScripts == NULL
     || compiler->symTableStk == NULL 
     || vm_buffer(compiler->vm) == NULL) {
    compiler_free(compiler);
    return NULL;
  }

  return compiler;
}
コード例 #2
0
ファイル: compiler.c プロジェクト: VeloxAmbitum/gunderscript
/**
 * Creates a new compiler object that will contain the current state of the
 * compiler and its data structures.
 * returns: new compiler object, or NULL if the allocation fails.
 */
Compiler * compiler_new(VM * vm) {

  assert(vm != NULL);

  Compiler * compiler = calloc(1, sizeof(Compiler));

  /* check for failed allocation */
  if(compiler == NULL) {
    return NULL;
  }

  /* TODO: make this stack auto expand when full */
  compiler->compiledScripts = set_new();
  compiler->symTableStk = stk_new(maxFuncDepth);
  compiler->functionHT = ht_new(COMPILER_INITIAL_HTSIZE, COMPILER_HTBLOCKSIZE, COMPILER_HTLOADFACTOR);
  compiler->outBuffer = buffer_new(bufferBlockSize, bufferBlockSize);
  compiler->vm = vm;

  /* check for further malloc errors */
  if(compiler->compiledScripts == NULL
     || compiler->symTableStk == NULL 
     || compiler->functionHT == NULL 
     || compiler->outBuffer == NULL) {
    compiler_free(compiler);
    return NULL;
  }

  return compiler;
}
コード例 #3
0
/**
 * Frees a Gunderscript object.
 * instance: an instance of Gunderscript.
 * returns: a VMErr
 */
GSAPI void gunderscript_free(Gunderscript * instance) {
  assert(instance != NULL);
  if(instance->compiler != NULL) {
    compiler_free(instance->compiler);
  }

  if(instance->vm != NULL) {
    vm_free(instance->vm);
  }
}
コード例 #4
0
ファイル: chain.c プロジェクト: ahma88/magro
void chain_free(CHAIN* chain)
{
	int i;
	for( i = 0 ; i < chain->nchain ;i++ )
	{
		CHAINCORE* core = &chain->core[i];
		compiler_free(core->compiler);
		if( core->monitor_buff != NULL )
		{
			GC_FREE(core->monitor_buff);
		}
	}
}