Exemplo n.º 1
0
void LuaInterface::newEnvironment()
{
    newTable(); // pushes the new environment table
    newTable(); // pushes the new environment metatable
    getGlobalEnvironment();  // pushes the global environment
    setField("__index"); // sets metatable __index to the global environment
    setMetatable(); // assigns environment metatable
}
Exemplo n.º 2
0
int LuaInterface::newSandboxEnv()
{
    newTable(); // pushes the new environment table
    newTable(); // pushes the new environment metatable
    getRef(getGlobalEnvironment());  // pushes the global environment
    setField("__index"); // sets metatable __index to the global environment
    setMetatable(); // assigns environment metatable
    return ref(); // return a reference to the environment table
}
int main(void)
{
	HashTable ht = newTable(SIZE);
	
	insertItem(ht, "Friend"); // insert items into ht
	insertItem(ht, "Yolo");
	insertItem(ht, "Lookin fors for the holidays"); 

	showHashTable(ht);
	removeItem(ht, "Friend"); // remove item in ht
	removeItem(ht, "asbdfb"); // remove item not in ht
	showHashTable(ht);

	insertItem(ht, "Matthew");
	insertItem(ht, "Matthew"); // collision
	showHashTable(ht);

	Item *it = searchItem(ht, "Matthew"); // search for item in ht
	assert(it != NULL);
	
	it = searchItem(ht, "friend"); // search for item not in ht
	assert(it == NULL);
	printf("it = %p\n", it);
		
	ht = hashTableExpand(ht, 30);
	showHashTable(ht);

	disposeTable(ht);
	return EXIT_SUCCESS;
}
Exemplo n.º 4
0
void LuaInterface::registerSingletonClass(const std::string& className)
{
    newTable();
    pushValue();
    setGlobal(className);
    pop();
}
Exemplo n.º 5
0
    bool Environment::init() {
        getGlobal("_E");

        if (!isTable(-1)) {
            newTable(regFunctions->length());
            lua_setglobal(L, "_E");
        }
        pop(1);


        loopv(*regFunctions) {
            (*regFunctions)[i]();

        }

        delete regFunctions;

    luvit_init(L, uv_default_loop());
#ifdef SERVER

      /* Pull up the preload table */
    select("package", "preload");

    pushRow("native_server", server::lua::luaopen_server);

    pop(2);
#endif
#ifdef LUA_PANIC_DEBUG
    #pragma message("Using lua atpanic crasher.")
    lua_atpanic(L, crash);
#endif
        isInitialized = true;

        return true;
    }
Exemplo n.º 6
0
int bestMoveForState(GameState* gs, int player, int other_player, int look_ahead) {
	TranspositionTable* t1 = newTable();
	GameTreeNode* n = newGameTreeNode(gs, player, other_player, 1, INT_MIN, INT_MAX, t1);
	int move = getBestMove(n, look_ahead);
	free(n);
	freeTranspositionTable(t1);
	return move;
}
Exemplo n.º 7
0
// Adds the row to the next element of the string labelTable lt 
struct labelTable * addRowToTable(struct labelTable * lt, struct labelTableRow *ltr)
{
  if(lt->down != NULL)
    ErrorDeal(TableRow, 0);
  lt->down = newTable();
  lt = lt->down;
  lt->down = NULL;
  lt->row = ltr;

  return lt;
}
Exemplo n.º 8
0
Arquivo: parser.c Projeto: bieber/pm0
int main(int argc, char* argv[]){
 
  int i;

  //Checking command-line arguments
  if(argc > 3){
    printf("%s\n", USAGE);
    return 1;
  }else if(argc < 2){
    fin = stdin;
  }else if(argc == 2){
    if(strcmp(argv[1], "-q") == 0){
      verbose = 0;
      fin = stdin;
    }else{
      fin = fopen(argv[1], "r");
      if(!fin){
        printf("%s\n", USAGE);
        return 1;
      }
    }
  }else if(argc == 2){
    if(strcmp("-q", argv[1]) != 0){
      printf("%s\n", USAGE);
      return 1;
    }
    verbose = 0;
    fin = fopen(argv[2], "r");
  }
  
  //Initializing the symbol table
  symTable = newTable();

  //Initializing the disjoint set for scopes
  for(i = 0; i < MAX_CODE_LENGTH; i++)
    scopeParent[i] = 0;

  //Fetching the first token
  readToken();
  
  //Parsing the program
  program();
 
  //Generating code
  printCode();

  //END:

  deleteTable(symTable);

  return 0;
  
}
Exemplo n.º 9
0
void LuaInterface::createLuaState()
{
    // creates lua state
    L = luaL_newstate();
    if(!L)
        g_logger.fatal("Unable to create lua state");

    // load lua standard libraries
    luaL_openlibs(L);

    // load bit32 lib for bitwise operations
    luaopen_bit32(L);

    // creates weak table
    newTable();
    newTable();
    pushString("v");
    setField("__mode");
    setMetatable();
    m_weakTableRef = ref();

    // installs script loader
    getGlobal("package");
    getField("loaders");
    pushCFunction(&LuaInterface::luaScriptLoader);
    rawSeti(5);
    pop(2);

    // replace dofile
    pushCFunction(&LuaInterface::lua_dofile);
    setGlobal("dofile");

    // dofiles
    pushCFunction(&LuaInterface::lua_dofiles);
    setGlobal("dofiles");

    // replace loadfile
    pushCFunction(&LuaInterface::lua_loadfile);
    setGlobal("loadfile");
}
Exemplo n.º 10
0
void createTable(TableManager *tm, char *tableName) {
	char *fileName = buildNameToTablesFiles(tm->path, tableName);
	setArrayListObject(tm->names, (char *) fileName, tm->names->length);
	Table *t = newTable(fileName);
	setArrayListObject(tm->tables, (Table *) t, tm->tables->length);
	InsertionHandler *ih = newInsertionHandler(t);
	setArrayListObject(tm->insert, (InsertionHandler *) ih, tm->insert->length);
	SelectionHandler *sh = newSelectionHandler(t);
	setArrayListObject(tm->select, (SelectionHandler *) sh, tm->select->length);
	DeletionHandler *dh = newDeletionHandler(t);
	setArrayListObject(tm->deleter, (DeletionHandler *) dh, tm->deleter->length);
	saveTables(tm);
}
void HistogramTablesFormatter::createTypeTable()
{
	casacore::TableDesc tableDesc(TypeTableName() + "_TYPE", "1.0", casacore::TableDesc::Scratch);
	tableDesc.comment() = "Couples the TYPE column in the QUALITY_HISTOGRAM_COUNT table to the name and polarization of the histogram";
	tableDesc.addColumn(casacore::ScalarColumnDesc<int>(ColumnNameType, "Index of the statistic kind"));
	tableDesc.addColumn(casacore::ScalarColumnDesc<int>(ColumnNamePolarization, "Index of the polarization corresponding to the main table"));
	tableDesc.addColumn(casacore::ScalarColumnDesc<casacore::String>(ColumnNameName, "Name of the statistic"));

	casacore::SetupNewTable newTableSetup(TableFilename(HistogramTypeTable), tableDesc, casacore::Table::New);
	casacore::Table newTable(newTableSetup);
	openMainTable(true);
	_measurementSet->rwKeywordSet().defineTable(TypeTableName(), newTable);
}
Exemplo n.º 12
0
void LuaInterface::pushCppFunction(const LuaCppFunction& func)
{
    // create a pointer to func (this pointer will hold the function existence)
    new(newUserdata(sizeof(LuaCppFunctionPtr))) LuaCppFunctionPtr(new LuaCppFunction(func));

    // sets the userdata __gc metamethod, needed to free the function pointer when it gets collected
    newTable();
    pushCFunction(&LuaInterface::luaCollectCppFunction);
    setField("__gc");
    setMetatable();

    // actually pushes a C function callback that will call the cpp function
    pushCFunction(&LuaInterface::luaCppFunctionCallback, 1);
}
void HistogramTablesFormatter::createCountTable()
{
	casacore::TableDesc tableDesc(CountTableName() + "_TYPE", "1.0", casacore::TableDesc::Scratch);
	tableDesc.comment() = "Histograms of the data in the main table";
	tableDesc.addColumn(casacore::ScalarColumnDesc<int>(ColumnNameType, "Index of the statistic kind"));
	tableDesc.addColumn(casacore::ScalarColumnDesc<double>(ColumnNameBinStart, "Lower start value of the bin corresponding to the count"));
	tableDesc.addColumn(casacore::ScalarColumnDesc<double>(ColumnNameBinEnd, "Higher end value of the bin corresponding to the count"));
	tableDesc.addColumn(casacore::ScalarColumnDesc<double>(ColumnNameCount, "Histogram y-value"));

	casacore::SetupNewTable newTableSetup(TableFilename(HistogramCountTable), tableDesc, casacore::Table::New);
	casacore::Table newTable(newTableSetup);
	openMainTable(true);
	_measurementSet->rwKeywordSet().defineTable(CountTableName(), newTable);
}
Exemplo n.º 14
0
// this function doubles the number of slots in the hash table
HashTable hashTableExpand(HashTable ht, int n)
{
	int i = 0;
	HashTable newht = newTable(n); // create the new hash table
	assert(newht != NULL); 
	newht->nslots = n; // new ht now has 2x the num slots
	newht->nitems = 0; // nitems is 0

	// insert all the values into the new ht
	for (i = 0; i < ht->nslots; i++){
		if (ht->data[i] != NULL){ insertItem(newht, ht->data[i]); }
	}

	disposeTable(ht);
	return newht;
}
Exemplo n.º 15
0
void buildTableManager(TableManager *tm) {
	selectTables(tm);
	if(tm->names > 0) {
		int i;
		for(i = 0 ; i < tm->names->length ; i++) {
			char *tableName = (char *) getArrayListObject(tm->names, i);
			Table *t = newTable(tableName);
			setArrayListObject(tm->tables, (Table *) t, tm->tables->length);
			InsertionHandler *ih = newInsertionHandler(t);
			setArrayListObject(tm->insert, (InsertionHandler *) ih, tm->insert->length);
			SelectionHandler *sh = newSelectionHandler(t);
			setArrayListObject(tm->select, (SelectionHandler *) sh, tm->select->length);
			DeletionHandler *dh = newDeletionHandler(t);
			setArrayListObject(tm->deleter, (DeletionHandler *) dh, tm->deleter->length);
		}
	}
}
Exemplo n.º 16
0
void Table::addDataInSameLine(vector<string> components) {

	if (components.size() < this->numColumns) {  //Verifica se vector componentes tem menor número de termos
		for (size_t x = components.size(); x < numColumns; x++) {  //da tabela original e adiciona nesse caso.
			components.push_back("");
		}
	}
	if (components.size() > this->numColumns) {  //Verifica se vector componentes tem maior número de termos
		for (int x = numColumns; x < components.size(); x++) { //da tabela original e remove-os, nesse caso.  MELHORAR!!!
			components.pop_back();
		}
	}
	vector<int> spaces;
	for (size_t i = 0; i < components.size(); i++) {
		if (components.at(i).length() >= this->columnsWidth.at(i)) {
			spaces.push_back((int)components.at(i).length());
		}
		else {
			spaces.push_back(columnsWidth.at(i));
		}
	} //Redefine a largura das colunas para a tabela alterada

	tableStream.str(string());
	tableStream.clear();
	tableVector.push_back(components);
	blocks.pop_back();
	blocks.push_back(false);

	blocks.push_back(true); //concatena a penultima linha com a œltima

	Table newTable(this->tableVector, this->blocks, spaces); //Reconstroi a tabela anterior com a largura das colunas redefinida
	tableStream << newTable;
	/*tableStream << " |  ";
	for (int i = 0; i < components.size(); i++){
	tableStream << components.at(i) << string(spaces.at(i) - components.at(i).length(), ' ') << "  |  ";
	}
	tableStream << endl;
	formatTable('_', '|', spaces);*/

	this->columnsWidth = spaces;
}
void Foam::StaticHashTable<T, Key, Hash>::resize(const label sz)
{
    label newSize = StaticHashTableCore::canonicalSize(sz);

    if (newSize == keys_.size())
    {
#       ifdef FULLDEBUG
        if (debug)
        {
            Info<< "StaticHashTable<T, Key, Hash>::resize(const label) : "
                << "new table size == old table size\n";
        }
#       endif

        return;
    }

    if (newSize < 1)
    {
        FatalErrorIn
        (
            "StaticHashTable<T, Key, Hash>::resize(const label)"
        )   << "Illegal size " << newSize << " for StaticHashTable."
            << " Minimum size is 1" << abort(FatalError);
    }


    StaticHashTable<T, Key, Hash> newTable(newSize);

    for (const_iterator iter = cbegin(); iter != cend(); ++iter)
    {
        newTable.insert(iter.key(), *iter);
    }

    transfer(newTable);

    // Adapt end() iterators
    endIter_.hashIndex_ = keys_.size();
    endConstIter_.hashIndex_ = keys_.size();
}
Exemplo n.º 18
0
int
DBStock::command (PluginData *pd)
{
  int rc = 0;

  QStringList cl;
  cl << "type" << "init" << "getBars" << "setBars" << "newTable" << "transaction" << "commit";
  
  switch (cl.indexOf(pd->command))
  {
    case 0: // type
      pd->type = QString("db");
      rc = 1;
      break;
    case 1: // init
      rc = init();
      break;
    case 2: // getBars
      rc = getBars(pd);
      break;
    case 3: // setBars
      rc = setBars(pd);
      break;
    case 4: // newTable
      rc = newTable(pd);
      break;
    case 5: // transaction
      _db.transaction();
      rc = 1;
      break;
    case 6: // commit
      _db.commit();
      rc = 1;
      break;
    default:
      break;
  }
  
  return rc;
}
Exemplo n.º 19
0
//-----------------------------------------------------------------------------
MemPanel::MemPanel(QWidget *parent) : QWidget(parent)
{
	QHBoxLayout *h;
	QVBoxLayout *v;
	QToolButton *b;

	infoDlg = new InfoDialog(this);
	infoDlg->setModal(true);	infoDlg->allowRefresh=false;

	v = new QVBoxLayout(this);	h = new QHBoxLayout();	v->addLayout(h);
	b = new QToolButton(this);	b->setIcon(QPixmap(":/png/document-new.png"));
	b->setToolTip(tr("Create new data array"));		h->addWidget(b);
	connect(b, SIGNAL(clicked()), this, SLOT(newTable()));
	b = new QToolButton(this);	b->setIcon(QPixmap(table_xpm));
	b->setToolTip(tr("Edit selected data array"));	h->addWidget(b);
	connect(b, SIGNAL(clicked()), this, SLOT(editData()));
	b = new QToolButton(this);	b->setIcon(QPixmap(":/png/edit-delete.png"));
	b->setToolTip(tr("Delete selected data array"));		h->addWidget(b);
	connect(b, SIGNAL(clicked()), this, SLOT(delData()));
	b = new QToolButton(this);	b->setIcon(QPixmap(preview_xpm));
	b->setToolTip(tr("Properties of selected data array"));	h->addWidget(b);
	connect(b, SIGNAL(clicked()), this, SLOT(infoData()));
	b = new QToolButton(this);	b->setIcon(QPixmap(":/png/view-refresh.png"));
	b->setToolTip(tr("Update list of data arrays"));		h->addWidget(b);
	connect(b, SIGNAL(clicked()), this, SLOT(refresh()));
	h->addStretch(1);
	b = new QToolButton(this);	b->setIcon(QPixmap(":/png/edit-clear.png"));
	b->setToolTip(tr("Delete ALL data arrays"));	h->addWidget(b);
	connect(b, SIGNAL(clicked()), this, SLOT(delAllData()));

	colSort = 0;
	tab = new QTableWidget(this);	tab->setColumnCount(3);	v->addWidget(tab);
	QStringList sl;	sl<<tr("Name")<<tr("Sizes")<<tr("Memory");
	tab->setHorizontalHeaderLabels(sl);
	connect(tab, SIGNAL(cellClicked(int,int)), this, SLOT(tableClicked(int,int)));
	connect(tab, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(tableDClicked(int,int)));

	setWindowTitle(tr("Memory"));
}
Exemplo n.º 20
0
void Schema::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
    QString display_setting = mainwin->getDisplaySetting();

    QMenu menu;
    menu.addAction(tr("Refresh"));
    if(display_setting.compare("view") == 0){
        //menu.addAction(tr("New view"));
    }
    else if(display_setting.compare("function") == 0)
        menu.addAction(tr("New function"));
    else if (display_setting.compare("table") == 0) {
        //menu.addAction(tr("New table"));
    }

    QAction *a = menu.exec(event->screenPos());

    if(a && QString::compare(a->text(),tr("Refresh")) == 0)
    {
        if(display_setting.compare("view") == 0)
            resetViewsVertically2();
        else if(display_setting.compare("function") == 0)
            resetFunctionsVertically2();
        else if(display_setting.compare("table") == 0)
            resetTablesVertically2();
    }
    else if(a && QString::compare(a->text(),tr("New view")) == 0)
    {
        emit newView(this);
    }
    else if(a && QString::compare(a->text(),tr("New function")) == 0)
    {
        emit newFunction(this);
    }
    else if(a && QString::compare(a->text(),tr("New table")) == 0)
    {
        emit newTable(this);
    }
}
Exemplo n.º 21
0
void Schema::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
    MainWin::DisplayMode display_mode = mainwin->displayMode();

    QMenu menu;
    menu.addAction(tr("Refresh"));
    if(display_mode == MainWin::Views){
        //menu.addAction(tr("New view"));
    }
    else if(display_mode == MainWin::Functions) {
        //menu.addAction(tr("New function"));
    }
    else if (display_mode == MainWin::Tables) {
        menu.addAction(tr("New table"));
    }

    QAction *a = menu.exec(event->screenPos());

    if(a && QString::compare(a->text(),tr("Refresh")) == 0) {
        if(display_mode == MainWin::Views)
            resetViewsVertically2();
        else if(display_mode == MainWin::Functions)
            resetFunctionsVertically2();
        else if(display_mode == MainWin::Tables)
            resetTablesVertically2();
    }
    else if(a && QString::compare(a->text(),tr("New view")) == 0) {
        emit newView(this);
    }
    else if(a && QString::compare(a->text(),tr("New function")) == 0) {
        emit newFunction(this);
    }
    else if(a && QString::compare(a->text(),tr("New table")) == 0) {
        emit newTable(this);
    }
}
Exemplo n.º 22
0
 void Environment::newTable() {
     newTable(0, 0);
 }
Exemplo n.º 23
0
void LuaInterface::registerClass(const std::string& className, const std::string& baseClass)
{
    // creates the class table (that it's also the class methods table)
    newTable();
    pushValue();
    setGlobal(className);
    const int klass = getTop();

    // creates the class fieldmethods table
    newTable();
    pushValue();
    setGlobal(className + "_fieldmethods");
    int klass_fieldmethods = getTop();

    // creates the class metatable
    newTable();
    pushValue();
    setGlobal(className + "_mt");
    int klass_mt = getTop();

    // set metatable metamethods
    pushCppFunction(&LuaInterface::luaObjectGetEvent);
    setField("__index", klass_mt);
    pushCppFunction(&LuaInterface::luaObjectSetEvent);
    setField("__newindex", klass_mt);
    pushCppFunction(&LuaInterface::luaObjectEqualEvent);
    setField("__eq", klass_mt);
    pushCppFunction(&LuaInterface::luaObjectCollectEvent);
    setField("__gc", klass_mt);

    // set some fields that will be used later in metatable
    pushValue(klass);
    setField("methods", klass_mt);
    pushValue(klass_fieldmethods);
    setField("fieldmethods", klass_mt);

    // redirect methods and fieldmethods to the base class ones
    if(!className.empty() && className != "LuaObject") {
        // the following code is what create classes hierarchy for lua, by reproducing:
        // DerivedClass = { __index = BaseClass }
        // DerivedClass_fieldmethods = { __index = BaseClass_methods }

        // redirect the class methods to the base methods
        pushValue(klass);
        newTable();
        getGlobal(baseClass);
        setField("__index");
        setMetatable();
        pop();

        // redirect the class fieldmethods to the base fieldmethods
        pushValue(klass_fieldmethods);
        newTable();
        getGlobal(baseClass + "_fieldmethods");
        setField("__index");
        setMetatable();
        pop();
    }

    // pops klass, klass_mt, klass_fieldmethods
    pop(3);
}
Exemplo n.º 24
0
XImage *
read_ppm_file(Display *disp, Colormap cmap, int depth, IOSTREAM *fd)
{ XImage *img;
  long here = Stell(fd);
  int c;
  int fmt, encoding;
  int width, height, bytes_per_line, scale=0;
  char *data;
  int allocdepth;
  int pad = XBitmapPad(disp);
  Visual *v = DefaultVisual(disp, DefaultScreen(disp));

  ncolours = nmapped = nfailed = 0;	/* statistics */
  assert(pad%8 == 0);

  if ( (c=Sgetc(fd)) != 'P' )
  { Sungetc(c, fd);
    return NULL;
  }

  if ( !cmap )
    cmap = DefaultColormap(disp, DefaultScreen(disp));

  c = Sgetc(fd);
  if ( c < '1' || c > '9' )
    goto errout;
  c -= '0';
  fmt      = ((c - 1) % 3) + 1;
  encoding = c - fmt;

  width = getNum(fd);
  height = getNum(fd);

  if ( fmt == PNM_PBM )
  { depth = 1;
  } else
  { scale = getNum(fd);
    if ( !depth )
      depth = DefaultDepth(disp, DefaultScreen(disp));
  }

  if ( width < 0 || height < 0 || scale < 0 )
    goto errout;

  allocdepth = (depth >= 24 ? 32 : depth);
  bytes_per_line = roundup((width*allocdepth+7)/8, pad/8);
  data = (char *)pceMalloc(height * bytes_per_line);

  img = XCreateImage(disp,
		     v,
		     depth,
		     fmt == PNM_PBM ? XYBitmap : ZPixmap,
		     0,
		     data,
		     width, height,
		     pad, bytes_per_line);
  if ( !img )
  { perror("XCreateImage");
    pceFree(data);
    goto errout;
  }
  img->bits_per_pixel = depth;

  switch(encoding)
  { int x, y;

    case PNM_ASCII:
    { switch(fmt)
      { case PNM_PBM:
	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int value = getNum(fd);

	      if ( value < 0 || value > 1 )
		goto errout;

	      XPutPixel(img, x, y, value);
	    }
	  }
	  break;
	case PNM_PGM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int g = getNum(fd);
	      unsigned long pixel;

	      if ( g < 0 || g > scale )
		goto errout;
	      if ( scale != 255 )
		g = rescale(g, scale, 255);

	      pixel = colourPixel(disp, depth, cmap, t, g, g, g);
	      XPutPixel(img, x, y, pixel);
	    }
	  }
	  freeTable(t);

	  break;
	}
	case PNM_PPM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int r = getNum(fd);
	      int g = getNum(fd);
	      int b = getNum(fd);
	      unsigned long pixel;

	      if ( r < 0 || r > scale ||
		   g < 0 || g > scale ||
		   b < 0 || b > scale )
		goto errout;

	      if ( scale != 255 )
	      { r = rescale(r, scale, 255);
		g = rescale(g, scale, 255);
		b = rescale(b, scale, 255);
	      }

	      pixel = colourPixel(disp, depth, cmap, t, r, g, b);

	      XPutPixel(img, x, y, pixel);
	    }
	  }
	  freeTable(t);

	  break;
	}
	break;
      }
      break;
    }
    case PNM_RAWBITS:
    { switch(fmt)
      { case PNM_PBM:
	{ int byte = 0;
	  int bit = 0;

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { if ( !bit )
	      { byte = Sgetc(fd);
		bit = 8;
	      }

	      bit--;
	      XPutPixel(img, x, y, (byte & (1<<bit)) ? 1 : 0);
	    }
	    bit = 0;			/* scanlines are byte-aligned */
	  }
	  break;
	}
	case PNM_PGM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int g;
	      unsigned long pixel;

	      if ( Sfeof(fd) || (g=Sgetc(fd)) > scale )
		goto errout;
	      if ( scale != 255 )
		g = rescale(g, scale, 255);

	      pixel = colourPixel(disp, depth, cmap, t, g, g, g);
	      XPutPixel(img, x, y, pixel);
	    }
	  }
	  freeTable(t);

	  break;
	}
	case PNM_PPM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { int r, g, b;
	      unsigned long pixel;

	      if ( Sfeof(fd) ||
		   (r=Sgetc(fd)) > scale ||
		   (g=Sgetc(fd)) > scale ||
		   (b=Sgetc(fd)) > scale )
		goto errout;

	      if ( scale != 255 )
	      { r = rescale(r, scale, 255);
		g = rescale(g, scale, 255);
		b = rescale(b, scale, 255);
	      }

	      pixel = colourPixel(disp, depth, cmap, t, r, g, b);

	      XPutPixel(img, x, y, pixel);
	    }
	  }
	  freeTable(t);

	  break;
	}
	break;
      }
      break;
    }
    case PNM_RUNLEN:
    { int rlen = 0;
      unsigned long cpixel = NOPIXEL;

      switch(fmt)
      { case PNM_PGM:
	{ Table t = newTable(64);

	  DEBUG(NAME_pnm, Cprintf("Reading runlength encoded graymap\n"));

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { if ( rlen-- > 0 )
	      { XPutPixel(img, x, y, cpixel);
	      } else
	      { int g;

		if ( (g=Sgetc(fd)) > scale ||
		     (rlen = Sgetc(fd)) == EOF )
		  goto errout;
		rlen &= 0xff;
		if ( scale != 255 )
		  g = rescale(g, scale, 255);

		cpixel = colourPixel(disp, depth, cmap, t, g, g, g);
		XPutPixel(img, x, y, cpixel);
		rlen--;
	      }
	    }
	  }
	  freeTable(t);

	  break;
	}
	case PNM_PPM:
	{ Table t = newTable(64);

	  for(y=0; y<height; y++)
	  { for(x=0; x<width; x++)
	    { if ( rlen-- > 0 )
	      { XPutPixel(img, x, y, cpixel);
	      } else
	      { int r, g, b;

		if ( (r=Sgetc(fd)) > scale ||
		     (g=Sgetc(fd)) > scale ||
		     (b=Sgetc(fd)) > scale ||
		     (rlen = Sgetc(fd)) == EOF )
		  goto errout;

		rlen &= 0xff;
		if ( scale != 255 )
		{ r = rescale(r, scale, 255);
		  g = rescale(g, scale, 255);
		  b = rescale(b, scale, 255);
		}

		cpixel = colourPixel(disp, depth, cmap, t, r, g, b);

		XPutPixel(img, x, y, cpixel);
		rlen--;
	      }
	    }
	  }
	  freeTable(t);

	  break;
	}
      }
    }
  }

  DEBUG(NAME_ppm,
	Cprintf("PNM: Converted %dx%dx%d image, %d colours (%d mapped, %d failed)\n",
		width, height, depth, ncolours, nmapped, nfailed));

  return img;

errout:
  DEBUG(NAME_ppm,
	Cprintf("PNM: Format error, index = %d\n", Stell(fd)));
  Sseek(fd, here, SEEK_SET);
  return NULL;
}
Exemplo n.º 25
0
Table *check(Absyn * program, boolean showSymbolTables)
{
	Table *globalTable;
	Entry *e;
	globalTable = newTable(NULL);

	if (showSymbolTables) {
	  local_debug = TRUE;
	}

	/* generate built-in types */
	builtinType_int  = newPrimitiveType("int",  INT_BYTE_SIZE);
	builtinType_bool = newPrimitiveType("bool", BOOL_BYTE_SIZE);

	Entry *builtinProc_exit =
	    newProcEntry(emptyParamTypes(), newTable(globalTable), NULL);
	Entry *builtinProc_time =
	    newProcEntry(newParamTypes
			 (builtinType_int, TRUE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_readi =
	    newProcEntry(newParamTypes
			 (builtinType_int, TRUE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_readc =
	    newProcEntry(newParamTypes
			 (builtinType_int, TRUE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_printi =
	    newProcEntry(newParamTypes
			 (builtinType_int, FALSE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_printc =
	    newProcEntry(newParamTypes
			 (builtinType_int, FALSE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_clearAll =
	    newProcEntry(newParamTypes
			 (builtinType_int, FALSE, emptyParamTypes()),
			 newTable(globalTable), NULL);
	Entry *builtinProc_setPixel =
	    newProcEntry(newParamTypes(builtinType_int, FALSE,
				       newParamTypes(builtinType_int, FALSE,
						     newParamTypes
						     (builtinType_int, FALSE,
						      emptyParamTypes()))),
			 newTable(globalTable), NULL);
	Entry *builtinProc_drawCircle =
	    newProcEntry(newParamTypes(builtinType_int, FALSE,
				       newParamTypes(builtinType_int, FALSE,
						     newParamTypes
						     (builtinType_int, FALSE,
						      newParamTypes
						      (builtinType_int, FALSE,
						       emptyParamTypes())))),
			 newTable(globalTable), NULL);
	Entry *builtinProc_drawLine =
	    newProcEntry(newParamTypes(builtinType_int, FALSE,
				       newParamTypes(builtinType_int, FALSE,
						     newParamTypes
						     (builtinType_int, FALSE,
						      newParamTypes
						      (builtinType_int, FALSE,
						       newParamTypes
						       (builtinType_int, FALSE,
							emptyParamTypes()))))),
			 newTable(globalTable), NULL);

	/* setup global symbol table */
	enter(globalTable, newSym("int"), newTypeEntry(builtinType_int));
	enter(globalTable, newSym("exit"), builtinProc_exit);
	enter(globalTable, newSym("time"), builtinProc_time);
	enter(globalTable, newSym("readi"), builtinProc_readi);
	enter(globalTable, newSym("readc"), builtinProc_readc);
	enter(globalTable, newSym("printi"), builtinProc_printi);
	enter(globalTable, newSym("printc"), builtinProc_printc);
	enter(globalTable, newSym("clearAll"), builtinProc_clearAll);
	enter(globalTable, newSym("setPixel"), builtinProc_setPixel);
	enter(globalTable, newSym("drawCircle"), builtinProc_drawCircle);
	enter(globalTable, newSym("drawLine"), builtinProc_drawLine);

	/* enter all procs into global symtable */
	enter_proc_decs(program, globalTable);

	/* do semantic checks */
	checkNode(program, globalTable);

	/* check if "main()" is present */
	e = lookup(globalTable, newSym("main"));
	if (e == NULL)
		error("procedure 'main' is missing");
	if (e->kind != ENTRY_KIND_PROC)
		error("'main' is not a procedure");
	// check that main has no params
	if (!e->u.procEntry.paramTypes->isEmpty)
		error("procedure 'main' must not have any parameters");

	/* return global symbol table */
	return globalTable;
}
Exemplo n.º 26
0
void enter_proc_decs(Absyn * program, Table * symtab)
{
	ParamTypes *paramTypes, *p_last, *p_new;
	Table *localSymtab;
	Entry *entry;
	Absyn *tmp, *node;
	Sym *name;

	while (!program->u.decList.isEmpty) {
		node = program->u.decList.head;
		if (node->type == ABSYN_PROCDEC) {

			// determine parameter types
			paramTypes = NULL;
			tmp = node->u.procDec.params;
			if (tmp->u.decList.isEmpty)
				paramTypes = emptyParamTypes();
			else {
				while (!(tmp->u.decList.isEmpty)) {
					p_new =
					    newParamTypes(checkNode
							  (tmp->u.decList.head,
							   symtab),
							  tmp->u.decList.
							  head->u.parDec.isRef,
							  NULL);
					if (paramTypes == NULL)
						paramTypes = p_new;
					else
						p_last->next = p_new;
					p_last = p_new;
					tmp = tmp->u.decList.tail;
				}
				p_last->next = emptyParamTypes();
			}

			// enter proc into global symbol table
			localSymtab = newTable(symtab);
			entry = newProcEntry(paramTypes, localSymtab, node);

			if (enter(symtab, node->u.procDec.name, entry) == NULL) {
				error("redeclaration of '%s' in line %d",
				      symToString(node->u.procDec.name),
				      node->line);
			}
			// enter parameters into local symbol table
			tmp = node->u.procDec.params;
			while (!(tmp->u.decList.isEmpty)) {
				name = tmp->u.decList.head->u.varDec.name;
				entry =
				    newVarEntry(checkNode
						(tmp->u.decList.head->u.
						 parDec.ty, symtab),
						tmp->u.decList.head->u.
						parDec.isRef, ENTRY_SOURCE_PARAM);
				enter(localSymtab, name, entry);
				tmp = tmp->u.decList.tail;
			}

		}
		if (node->type == ABSYN_TYPEDEC) {
			checkTypeDec(node, symtab);
		}
		program = program->u.decList.tail;
	}
	return;
}