Пример #1
0
GoomSL *gsl_new(void)
{ /* {{{ */
  GoomSL *gss = (GoomSL*)malloc(sizeof(GoomSL));

  gss->iflow = iflow_new();
  gss->vars  = goom_hash_new();
  gss->functions = goom_hash_new();
  gss->nbStructID  = 0;
  gss->structIDS   = goom_hash_new();
  gss->gsl_struct_size = 32;
  gss->gsl_struct = (GSL_Struct**)malloc(gss->gsl_struct_size * sizeof(GSL_Struct*));
  gss->currentNS = 0;
  gss->namespaces[0] = gss->vars;
  gss->data_heap = goom_heap_new();

  reset_scanner(gss);

  gss->compilationOK = 0;
  gss->nbPtr=0;
  gss->ptrArraySize=256;
  gss->ptrArray = (void**)malloc(gss->ptrArraySize * sizeof(void*));
#ifdef USE_JITC_X86
  gss->jitc = NULL;
#endif
  return gss;
} /* }}} */
Пример #2
0
void gsl_compile(GoomSL *_currentGoomSL, const char *script)
{ /* {{{ */
  char *script_and_externals;
  static const char *sBinds =
    "external <charAt: string value, int index> : int\n"
    "external <f2i: float value> : int\n"
    "external <i2f: int value> : float\n";

#ifdef VERBOSE
  printf("\n=== Starting Compilation ===\n");
#endif

  script_and_externals = malloc(strlen(script) + strlen(sBinds) + 2);
  strcpy(script_and_externals, sBinds);
  strcat(script_and_externals, script);

  /* 0- reset */
  currentGoomSL = _currentGoomSL;
  reset_scanner(currentGoomSL);

  /* 1- create the syntaxic tree */
  yy_scan_string(script_and_externals);
  yyparse();

  /* 2- generate code */
  gsl_commit_compilation();

  /* 3- resolve symbols */
  calculate_labels(currentGoomSL->iflow);

  /* 4- optimize code */
  gsl_create_fast_iflow();

  /* 5- bind a few internal functions */
  gsl_bind_function(currentGoomSL, "charAt", ext_charAt);
  gsl_bind_function(currentGoomSL, "f2i", ext_f2i);
  gsl_bind_function(currentGoomSL, "i2f", ext_i2f);
  free(script_and_externals);
  
#ifdef VERBOSE
  printf("=== Compilation done. # of lines: %d. # of instr: %d ===\n", currentGoomSL->num_lines, currentGoomSL->iflow->number);
#endif
} /* }}} */
Пример #3
0
static int rx_matcher(void *data, const char *s, int len, int pos)
{
#ifndef FLEX_SCANNER
    int required_len = len - pos + DATA_LEN;
    if (required_len > MAX_LEX_TOKEN_SIZE)
    {
	static int max_reported_len = 0;
	if (required_len > max_reported_len)
	{
	    std::cerr << "Warning: LEX buffer overflow.\n";
	    std::cerr << "Please raise the value of "
		"MAX_LEX_TOKEN_SIZE in `ddd/rxscan.L'\n"
		"from " << MAX_LEX_TOKEN_SIZE << " to " 
		 << required_len << " or more and recompile.  "
		"Better yet, use FLEX instead of LEX.\n";
	    max_reported_len = required_len;
	}

	// Only look at the first MAX_LEX_TOKEN_SIZE characters
	len = pos + MAX_LEX_TOKEN_SIZE - DATA_LEN;
	assert(len - pos + DATA_LEN == MAX_LEX_TOKEN_SIZE);
    }
#endif

    the_prefix = STATIC_CAST(char *,data);
    the_text   = s + pos;
    the_length = len - pos;

    assert(strlen(the_prefix) == DATA_LEN);

    // Restart the scanner
    reset_scanner();
    BEGIN(INITIAL);

    int ret;
    if (dddlex() == 0)
	ret = -1;		// not matched
    else
	ret = dddleng - DATA_LEN; // # of characters matched

    return ret;
}
Пример #4
0
int
main(int argc, char **argv)
{
	int c;
	char *lfname = NULL;
	char *cfname = NULL;
	char *wfname = NULL;
	DIR *dir;

	init_charmap();
	init_collate();
	init_ctype();
	init_messages();
	init_monetary();
	init_numeric();
	init_time();

	yydebug = 0;

	(void) setlocale(LC_ALL, "");

	while ((c = getopt(argc, argv, "w:i:cf:u:vUD")) != -1) {
		switch (c) {
		case 'D':
			dragonfly = 1;
			break;
		case 'v':
			verbose++;
			break;
		case 'i':
			lfname = optarg;
			break;
		case 'u':
			set_wide_encoding(optarg);
			break;
		case 'f':
			cfname = optarg;
			break;
		case 'U':
			undefok++;
			break;
		case 'c':
			warnok++;
			break;
		case 'w':
			wfname = optarg;
			break;
		case '?':
			usage();
			break;
		}
	}

	if ((argc - 1) != (optind)) {
		usage();
	}
	locname = argv[argc - 1];
	if (verbose) {
		(void) printf("Processing locale %s.\n", locname);
	}

	if (cfname) {
		if (verbose)
			(void) printf("Loading charmap %s.\n", cfname);
		reset_scanner(cfname);
		(void) yyparse();
	}

	if (wfname) {
		if (verbose)
			(void) printf("Loading widths %s.\n", wfname);
		reset_scanner(wfname);
		(void) yyparse();
	}

	if (verbose) {
		(void) printf("Loading POSIX portable characters.\n");
	}
	add_charmap_posix();

	if (lfname) {
		reset_scanner(lfname);
	} else {
		reset_scanner(NULL);
	}

	/* make the directory for the locale if not already present */
	if (!dragonfly) {
		while ((dir = opendir(locname)) == NULL) {
			if ((errno != ENOENT) ||
			    (mkdir(locname, 0755) <  0)) {
				errf(strerror(errno));
			}
		}
		(void) closedir(dir);
		(void) mkdir(dirname(category_file()), 0755);
	}

	(void) yyparse();
	if (verbose) {
		(void) printf("All done.\n");
	}
	return (warnings ? 1 : 0);
}
Пример #5
0
/*
 * reset_parser: resets the scanner and parser when a syntax error occurs
 *
 * No return value
 */
void reset_parser(void)
{
    reset_scanner();
    nodeptr = 0;
}