Exemplo n.º 1
0
void ScriptEngine::setDeprecatedProperty(QScriptValue &object, const QString &oldName,
        const QString &newName, const QScriptValue &value)
{
    QScriptValue data = newArray();
    data.setProperty(0, oldName);
    data.setProperty(1, newName);
    data.setProperty(2, value);
    QScriptValue getterFunc = newFunction(js_deprecatedGet);
    getterFunc.setProperty(QLatin1String("qbsdata"), data);
    object.setProperty(oldName, getterFunc, QScriptValue::PropertyGetter
                       | QScriptValue::SkipInEnumeration);
}
Exemplo n.º 2
0
QScriptValue Env::loadMLScriptEnv( MeshDocument& md,PluginManager& pm )
{
	QString code;
	MeshDocumentSI* mi = new MeshDocumentSI(&md);
	QScriptValue val = newQObject(mi);
	globalObject().setProperty(ScriptAdapterGenerator::meshDocVarName(),val); 
	JavaScriptLanguage lang;
	code += lang.getExternalLibrariesCode();
	QScriptValue applyFun = newFunction(PluginInterfaceApplyXML, &pm);
	globalObject().setProperty("_applyFilter", applyFun);

	//QScriptValue res = env.evaluate(QString(PM.pluginsCode()));
	code += pm.pluginsCode();
	QScriptValue res = evaluate(code);
	return res;
}
Exemplo n.º 3
0
void ScriptEngine::setObservedProperty(QScriptValue &object, const QString &name,
                                       const QScriptValue &value, ScriptPropertyObserver *observer)
{
    if (!observer) {
        object.setProperty(name, value);
        return;
    }

    QScriptValue data = newArray();
    data.setProperty(0, object);
    data.setProperty(1, name);
    data.setProperty(2, value);
    QScriptValue getterFunc = newFunction(js_observedGet, observer);
    getterFunc.setProperty(QLatin1String("qbsdata"), data);
    object.setProperty(name, getterFunc, QScriptValue::PropertyGetter);
}
Exemplo n.º 4
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.º 5
0
void
MSinitClientPrg(Client cntxt, str mod, str nme)
{
	InstrPtr p;
	MalBlkPtr mb;

	if (cntxt->curprg && idcmp(nme, cntxt->curprg->name) == 0) {
		MSresetClientPrg(cntxt);
		return;
	}
	cntxt->curprg = newFunction(putName("user", 4), putName(nme, strlen(nme)), FUNCTIONsymbol);
	mb = cntxt->curprg->def;
	p = getSignature(cntxt->curprg);
	if (mod)
		setModuleId(p, mod);
	else
		setModuleScope(p, cntxt->nspace);
	setVarType(mb, findVariable(mb, nme), TYPE_void);
	insertSymbol(cntxt->nspace, cntxt->curprg);
	cntxt->glb = 0;
	assert(cntxt->curprg->def != NULL);
}
Exemplo n.º 6
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.º 7
0
PlotControlWindow::PlotControlWindow(const int plotId, PlotArea *parent) :
    QMainWindow(parent),
    ui(new Ui::PlotControlWindow)
{
    ui->setupUi(this);
    mPlot = parent->getPlotWidget();
    mPlotId = plotId;

    init();
    initFromConfig();

    // Dialog
    connect(this->ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(this->ui->buttonBox, SIGNAL(accepted()), this, SLOT(close()));
    connect(this->ui->buttonBox, SIGNAL(accepted()), parent, SLOT(plotConfigChanged()));
    connect(this->ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
    QPushButton* applyButton = ui->buttonBox->button(QDialogButtonBox::Apply);
    connect(applyButton, SIGNAL(clicked()), this, SLOT(apply()));
    connect(ui->autoOrdinate, SIGNAL(toggled(bool)), this, SLOT(autoOrdinateChecked(bool)));

    // Curve page
    connect(ui->newCurveButton, SIGNAL(clicked()), this, SLOT(newCurve()));
    connect(ui->curveSelection, SIGNAL(doubleClicked ( const QModelIndex &)), this, SLOT(editCurve(const QModelIndex &)));
    connect(ui->deleteCurveButton, SIGNAL(clicked()), this, SLOT(deleteSelectedCurve()));

    // Function page
    connect(ui->functionNew, SIGNAL(clicked()), this, SLOT(newFunction()));
    connect(ui->functionHierarchicalNew, SIGNAL(clicked()), this, SLOT(newHierarachicalFunction()));
    connect(ui->functionIntegralNew, SIGNAL(clicked()), this, SLOT(newIntegralFunction()));
    connect(ui->functionDifferentialNew, SIGNAL(clicked()), this, SLOT(newDifferentialFunction()));
    connect(ui->functionView, SIGNAL(doubleClicked ( const QModelIndex &)), this, SLOT(editFunction(const QModelIndex &)));
    connect(ui->functionDelete, SIGNAL(clicked()), this, SLOT(deleteFunction()));
    connect(ui->functionEditCurve, SIGNAL(clicked()), this, SLOT(editFunctionCurve()));

    setWindowModality(Qt::NonModal);
}
Exemplo n.º 8
0
void ScriptEngine::registerFunction(QScriptValue parent, const QString& name, QScriptEngine::FunctionSignature fun, int numArguments) {
    QScriptValue scriptFun = newFunction(fun, numArguments);
    parent.setProperty(name, scriptFun);
}
Exemplo n.º 9
0
void define_routines(void)
{	
	SymbolEntry *se;
	const char *name;

	name = "READ_INT";
	se = newFunction(name);
	openScope();
    endFunctionHeader(se, typeInteger);
	closeScope();

	name = "READ_BOOL";
	se = newFunction(name);
	openScope();
    endFunctionHeader(se, typeBoolean);
	closeScope();
	
	name = "getchar";
	se = newFunction(name);
	openScope();
    endFunctionHeader(se, typeInteger);
	closeScope();

	name = "READ_REAL";
	se = newFunction(name);
	openScope();
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "READ_STRING";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeInteger, PASS_BY_VALUE, se);
	newParameter("par2", typeIArray(typeChar), PASS_BY_REFERENCE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	name = "putchar";
	se = newFunction(name);
	openScope();
	newParameter("par", typeChar, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	name = "puts";
	se = newFunction(name);
	openScope();
	newParameter("par", typeIArray(typeChar), PASS_BY_REFERENCE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	name = "writeInteger";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeInteger, PASS_BY_VALUE, se);
	//newParameter("par2", typeInteger, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	name = "writeBoolean";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeBoolean, PASS_BY_VALUE, se);
	//newParameter("par2", typeInteger, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	name = "writeChar";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeChar, PASS_BY_VALUE, se);
	//newParameter("par2", typeInteger, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	name = "writeReal";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeReal, PASS_BY_VALUE, se);
	newParameter("par2", typeInteger, PASS_BY_VALUE, se);
	//newParameter("par3", typeInteger, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	name = "writeString";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeIArray(typeChar), PASS_BY_REFERENCE, se);
	//newParameter("par2", typeInteger, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();
	
	/*Math builtin functions*/
	name = "abs";
	se = newFunction(name);
	openScope();
	newParameter("par", typeInteger, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeInteger);
	closeScope();

	name = "fabs";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "sqrt";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "sin";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "cos";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "tan";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "arctan";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "exp";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();
	
	name = "ln";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();
	
	name = "pi";
	se = newFunction(name);
	openScope();
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "trunc";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "round";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeReal);
	closeScope();

	name = "TRUNC";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeInteger);
	closeScope();
	
	name = "ROUND";
	se = newFunction(name);
	openScope();
	newParameter("par", typeReal, PASS_BY_VALUE, se);
    endFunctionHeader(se, typeInteger);
	closeScope();
	
	/*End Math builtin functions*/
	
	/*String handling builtin functions*/
	name = "strlen";
	se = newFunction(name);
	openScope();
	newParameter("par", typeIArray(typeChar), PASS_BY_REFERENCE, se);
    endFunctionHeader(se, typeInteger);
	closeScope();

	name = "strcmp";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeIArray(typeChar), PASS_BY_REFERENCE, se);
	newParameter("par2", typeIArray(typeChar), PASS_BY_REFERENCE, se);
    endFunctionHeader(se, typeInteger);
	closeScope();

	name = "strcpy";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeIArray(typeChar), PASS_BY_REFERENCE, se);
	newParameter("par2", typeIArray(typeChar), PASS_BY_REFERENCE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	name = "strcat";
	se = newFunction(name);
	openScope();
	newParameter("par1", typeIArray(typeChar), PASS_BY_REFERENCE, se);
	newParameter("par2", typeIArray(typeChar), PASS_BY_REFERENCE, se);
    endFunctionHeader(se, typeVoid);
	closeScope();

	/*End String handling builtin functions*/
	

}
Exemplo n.º 10
0
void init_core() {

  object_t* (*fn)(list_t* args) = &z_fn;
  struct function* fn_ref = newFunction(fn,"fn",3);
  addFunctionToSymbolTable(clib_functions, fn_ref);

  object_t* (*lambda)(list_t* args) = &z_lambda;
  struct function* lambda_ref = newFunction(lambda,"lambda",2);
  addFunctionToSymbolTable(clib_functions, lambda_ref);

  object_t* (*eval)(list_t* args) = &z_eval;
  struct function* eval_ref = newFunction(eval,"eval",1);
  addFunctionToSymbolTable(clib_functions, eval_ref);

  object_t* (*ns)(list_t* args) = &z_ns;
  struct function* ns_ref = newFunction(ns,"ns",1);
  addFunctionToSymbolTable(clib_functions, ns_ref);

  object_t* (*let)(list_t* args) = &z_let;
  struct function* let_ref = newFunction(let,"let",2);
  addFunctionToSymbolTable(clib_functions, let_ref);

  object_t* (*_return)(list_t* args) = &z_return;
  struct function* return_ref = newFunction(_return,"return",1);
  addFunctionToSymbolTable(clib_functions, return_ref);

  object_t* (*import)(list_t* args) = &z_import;
  struct function* import_ref = newFunction(import,"import",-1);
  addFunctionToSymbolTable(clib_functions, import_ref);

  object_t* (*cond)(list_t* args) = &z_cond_placeholder;
  struct function* cond_ref = newFunction(cond,"cond",-1);
  addFunctionToSymbolTable(clib_functions, cond_ref);

  object_t* (*add)(list_t* args) = &z_add;
  struct function* add_ref = newFunction(add,"+",2);
  addFunctionToSymbolTable(clib_functions, add_ref);

  object_t* (*sub)(list_t* args) = &z_sub;
  struct function* sub_ref = newFunction(sub,"-",2);
  addFunctionToSymbolTable(clib_functions, sub_ref);

  object_t* (*div)(list_t* args) = &z_div;
  struct function* div_ref = newFunction(div,"/",2);
  addFunctionToSymbolTable(clib_functions, div_ref);

  object_t* (*mul)(list_t* args) = &z_mul;
  struct function* mul_ref = newFunction(mul,"*",2);
  addFunctionToSymbolTable(clib_functions, mul_ref);

  object_t* (*eq)(list_t* args) = &z_eq;
  struct function* eq_ref = newFunction(eq,"=",2);
  addFunctionToSymbolTable(clib_functions, eq_ref);

  object_t* (*lt)(list_t* args) = &z_lt;
  struct function* lt_ref = newFunction(lt,"<",2);
  addFunctionToSymbolTable(clib_functions, lt_ref);

  object_t* (*gt)(list_t* args) = &z_gt;
  struct function* gt_ref = newFunction(gt,">",2);
  addFunctionToSymbolTable(clib_functions, gt_ref);

  object_t* (*lteq)(list_t* args) = &z_lteq;
  struct function* lteq_ref = newFunction(lteq,"<=",2);
  addFunctionToSymbolTable(clib_functions, lteq_ref);

  object_t* (*gteq)(list_t* args) = &z_gteq;
  struct function* gteq_ref = newFunction(gteq,">=",2);
  addFunctionToSymbolTable(clib_functions, gteq_ref);

  object_t* (*_exit)(list_t* args) = &z_exit;
  struct function* exit_ref = newFunction(_exit,"exit",1);
  addFunctionToSymbolTable(clib_functions, exit_ref);

  object_t* (*print)(list_t* args) = &z_print;
  struct function* print_ref = newFunction(print,"print",1);
  addFunctionToSymbolTable(clib_functions, print_ref);

  object_t* (*println)(list_t* args) = &z_println;
  struct function* println_ref = newFunction(println,"println",1);
  addFunctionToSymbolTable(clib_functions, println_ref);


}
Exemplo n.º 11
0
int run() {
	char *str = (char*)malloc(100*sizeof(char));
	//Polynomial *poly;

	function.addAxis();
	function.setScale(50, 50);
	//registerBody("Poly", newPolynomial(-1, -1, -1, -1, '*', 2, 1, 0, 0));
	//registerBody("First", newPolynomial(-1, -1, -1, -1, 'o', 1, 1, 0));
	//registerBody("Third", newPolynomial(-1, -1, -1, -1, '+', 3, 1, 8, 10, 0));
	registerBody("Sin", newFunction(-1, -1, -1, -1, '#', invx));
	//registerBody("Cos", newFunction(-1, -1, -1, -1, '!', cosx));
	//registerBody("Tan", newFunction(-1, -1, -1, -1, '$', tanx));
	//registerBody("Abs", newFunction(-1, -1, -1, -1, '&', absolute));
	//registerBody("exp2", newFunction(-1, -1, -1, -1, 'o', exp2));
	//registerBody("ln", newFunction(-1, -1, -1, -1, '+', ln));
	//registerBody("log10", newFunction(-1, -1, -1, -1, '=', logarithm10));
	//registerBody("e^x", newFunction(-1, -1, -1, -1, 'e', eulerx));
	//registerBody("signum", newFunction(-1, -1, -1, -1, 's', signx));
	//registerBody("sqrt", newFunction(-1, -1, -1, -1, '@', sqrt));
	//registerBody("Poly2", newFunction(-1, -1, -1, -1, '~', poly2));
	//registerBody("sin(1/x)", newFunction(-1, -1, -1, -1, 'x', sinix));
	//registerBody("1/x", newFunction(-1, -1, -1, -1, '|', invx));
	//registerBody("arcsin(x)", newFunction(-1, -1, -1, -1, '?', arcsin));
	//registerBody("arccos(x)", newFunction(-1, -1, -1, -1, '?', arccos));
	//registerBody("arctan(x)", newFunction(-1, -1, -1, -1, '?', arctan));
	//registerBody("f(x)", newFunction(-1, -1, -1, -1, 'f', f));
	//registerBody("xsin(x)", newFunction(-1, -1, -1, -1, 'x', xsinx));

	//poly = (Polynomial*)getByName("Poly");
	//poly->toString(str, poly);

	draw();

	//puts("Poly:");
	//puts(str);
	//free(str);

	/*char *t = (char*)malloc(sizeof(char));
	registerBody("t1", newTextBox(50, 15, "STOP", 11, '*'));
	registerBody("t2", newTextBox(22, 10, "THAT'S WHAT SHE SAID", 1, '<'));
	registerBody("t3", newTextBox(30, 20, "Hey, Michael Scott is back!", 0, '='));
	registerBody("t4", newTextBox(40, 28, "feelings", -1, '#'));

	Body *r = newRectangle(20, 40, 20, 5, '*', 'l');
	Stroke *s = newStroke(1, newBorder("renatolordofeverything"));
	r->addStroke(r, s);
	setStrokeJoint(s, 'X');
	registerBody("rect", r);

	Body *tb = newTextBox(55, 40, "VARARGS ARE SO BEAUTIFUL!", 0, '!');
	tb->addStroke(tb, newStroke(1, newBorder("varmyargs")));
	registerBody("tb", tb);

	Body *c = newCircle(60, 10, 5, '*', 'l');
	c->addStroke(c, newStroke(1, newBorder("!@#$^&*()")));
	registerBody("c", c);

	Body *huge = newRectangle(100, 10, 50, 40, '&', 'l');
	Stroke *leStroke = newStroke(4, newBorder(" THEY SEE ME STROKIN' "), 
		newBorder("nurses are not amused "), newBorder(" THEY HATIN' "), 
		newBorder("doctors be mad "));
	setStrokeJoint(leStroke, '$');
	huge->addStroke(huge, leStroke);
	registerBody("huge", huge);

	Body *line = newLine(1, 55, 150, 'h', '-');
	Stroke *lineStroke = newStroke(1, newBorder("-="));
	line->addStroke(line, lineStroke);
	setStrokeJoint(lineStroke, 'O');
	registerBody("line", line);

	draw();
	gets(t);
	killByName(t);*/

	/*Body *t = newTable(0, 0, 5, 5, -25, -12, '!', '=');
	Stroke *s = newStroke(4, newBorder("-"), newBorder("|"), newBorder("-"), newBorder("|"));
	t->addStroke(t, s);
	setStrokeJoint(s, 'O');

	Table *tab = (Table*)t;
	Body *c = newCircle(0, 0, 4, '*', 'l');
	c->addStroke(c, newStroke(1, newBorder("!@#$^&*()-+")));
	tab->add(tab, c, 1, 1, 1);

	Body *rect = newRectangle(0, 0, 15, 8, '@', 'f');
	Stroke *rectStroke = newStroke(4, newBorder("wassup"), newBorder("dawgs"),
		newBorder("chillin'"), newBorder("much?"));
	setStrokeJoint(rectStroke, '+');
	rect->addStroke(rect, rectStroke);
	tab->add(tab, rect, 3, 3, 1);

	Body *tb = newTextBox(1, 2, " Table is so awesome! Said everyone. ", 21, '=');
	Stroke *tbStroke = newStroke(4, newBorder("amazing"), newBorder("genius"),
		newBorder("10/10_reviews_"), newBorder("WOOHO!"));
	tb->addStroke(tb, tbStroke);
	tab->add(tab, tb, 2, 4, 1);

	registerBody("t", t);
	draw();*/
}
Exemplo n.º 12
0
Arquivo: prof.c Projeto: peadar/hdmp
static void
sigprof(int sig, siginfo_t *info, void *uc_v)
{
    ucontext_t *uc = (ucontext_t *)uc_v;
    mcontext_t *mc = &uc->uc_mcontext;

    struct threadcontext context;
    int i;
    ADDR newBp, newIp;

    memset(&context, 0, sizeof context);
    assert(pthread_getspecific(tls) == 0);

    context.bp = mc->gregs[REG_EBP];
    context.ip = mc->gregs[REG_EIP];
    context.sp = mc->gregs[REG_ESP];

    updateObjects();

    pthread_setspecific(tls, &context);
    if (setjmp(context.jb) == 0) {
        for (context.frameCount = 0; context.frameCount < MAXFRAMES; ++context.frameCount) {
            struct frame *frame = &context.stack[context.frameCount];

            frame->ip = context.ip;

            // Some sanity checking...
            if (context.bp < 0x80000)
                break;

            // We can't find the current instruction pointer in any object. (Java optimiser tends to do this at a time when we can't use our segv handler to recover)
            if (elf32FindObject(elf, context.ip, &frame->obj) != 0)
                break;

            if (elf32FindFunction(frame->obj, context.ip - frame->obj->baseAddr, &frame->function) != 0)
                frame->function = 0;

            newBp = ((ADDR *)context.bp)[0];
            if (newBp <= context.bp)
                break;
            newIp = ((ADDR *)context.bp)[1];
            if (newIp == 0)
                break;
            context.ip = newIp;
            context.bp = newBp;
        }
    }
    pthread_setspecific(tls, 0);

    struct callsite *calledfrom = bottom;
    if (context.frameCount == 0)
        return;

    for (i = context.frameCount - 1;  ; --i) {
        struct callsite *site, **sitep;
        struct function *function, **functionp;
        struct frame *frame;
        ADDR ip;
        int j;

        frame = &context.stack[i];

        /*
         * Find the function for this IP.
         */
        functionp = (struct function **)bsearch((void *)frame->ip, functions, functionCount, sizeof functions[0], cmpFuncIP);

        if (functionp == 0) {
            /* New function: add to our table. */
            if (functionCount == functionMax) {
                functionMax *= 2;
                functionMax += 128;
                functions = realloc(functions, sizeof functions[0] * functionMax);
            }

            if (frame->function) {
                ADDR start = frame->function->elfSym->st_value + frame->obj->baseAddr;
                ADDR end = start + frame->function->elfSym->st_size;
                const char *name = frame->function->elfName;
                function = newFunction(frame->obj, name, start, end);
            } else {
                function = newFunction(frame->obj, "_unknown_", frame->ip, frame->ip + 1);
            }
            functions[functionCount++] = function;
            qsort(functions, functionCount, sizeof functions[0], sortFunctions);
        } else {
            function = *functionp;
        }

        // Make sure this function is on the list of those called from the call site.
        for (j = 0;; j++) {
            if (j == calledfrom->callCount) {
                // This function hasn't been called from this site before.
                if (calledfrom->callMax == calledfrom->callCount) {
                    calledfrom->callMax *= 2;
                    calledfrom->calls = realloc(calledfrom->calls, sizeof calledfrom->calls[0] * calledfrom->callMax);
                }
                calledfrom->calls[calledfrom->callCount++] = function;
                break;
            }
            if (calledfrom->calls[j] == function)
                break;
        }

        function->toCount++;

        // Don't create a callsite for the top frame: the jump from here was the asynch jump into the sigprof handler
        if (i == 0)
            break;

        // Find or create a callsite out of this function at this IP.
        for (sitep = &function->callSites;; sitep = &site->next) {
            site = *sitep;
            if (site == 0) {
                site = *sitep = newSite(ip);
                break;
            } else if (site->ip == ip) {
                break;
            }
        }

        site->fromCount++;
        calledfrom = site;
    }
}
Exemplo n.º 13
0
GMathScriptEngine::GMathScriptEngine(QObject *parent /*= 0*/)
	: QScriptEngine(parent)
{
// 	// Destroy all of the old variables and their values, including the built-in from the ECMA-262 standard (see Qt Assistant).
// 	QScriptValueIterator qsvIter(globalObject());
// 	while (qsvIter.hasNext()) {
// 		qsvIter.next();
// 		qsvIter.remove();
// 	}

	// Add the built-in functions that are expected. 
	globalObject().setProperty( "exp", newFunction(&functionExp, 1) );
	globalObject().setProperty( "pow", newFunction(&functionPow, 2) );
	globalObject().setProperty( "log", newFunction(&functionLog, 1) );
	globalObject().setProperty( "ln", newFunction(&functionLn, 1) );
	globalObject().setProperty( "cos", newFunction(&functionCos, 1) );
	globalObject().setProperty( "sin", newFunction(&functionSin, 1) );
	globalObject().setProperty( "tan", newFunction(&functionTan, 1) );
	globalObject().setProperty( "arccos", newFunction(&functionArccos, 1) );
	globalObject().setProperty( "arcsin", newFunction(&functionArcsin, 1) );
	globalObject().setProperty( "arctan", newFunction(&functionArctan, 1) );
	globalObject().setProperty( "sqrt", newFunction(&functionSqrt, 1) );
	globalObject().setProperty( "abs", newFunction(&functionAbs, 1) );
	globalObject().setProperty( "H", newFunction(&functionH, 1) );

	globalObject().setProperty( "Param", newFunction(&functionParamValueByID, 1) );
}
Exemplo n.º 14
0
void ScriptEngine::init() {
    if (_isInitialized) {
        return; // only initialize once
    }
    
    _isInitialized = true;

    _voxelsScriptingInterface.init();
    _particlesScriptingInterface.init();

    // register various meta-types
    registerMetaTypes(this);
    registerMIDIMetaTypes(this);
    registerVoxelMetaTypes(this);
    registerEventTypes(this);
    registerMenuItemProperties(this);
    registerAnimationTypes(this);
    registerAvatarTypes(this);
    Bitstream::registerTypes(this);

    qScriptRegisterMetaType(this, ParticlePropertiesToScriptValue, ParticlePropertiesFromScriptValue);
    qScriptRegisterMetaType(this, ParticleIDtoScriptValue, ParticleIDfromScriptValue);
    qScriptRegisterSequenceMetaType<QVector<ParticleID> >(this);

    qScriptRegisterMetaType(this, EntityItemPropertiesToScriptValue, EntityItemPropertiesFromScriptValue);
    qScriptRegisterMetaType(this, EntityItemIDtoScriptValue, EntityItemIDfromScriptValue);
    qScriptRegisterMetaType(this, RayToEntityIntersectionResultToScriptValue, RayToEntityIntersectionResultFromScriptValue);
    qScriptRegisterSequenceMetaType<QVector<EntityItemID> >(this);

    qScriptRegisterSequenceMetaType<QVector<glm::vec2> >(this);
    qScriptRegisterSequenceMetaType<QVector<glm::quat> >(this);
    qScriptRegisterSequenceMetaType<QVector<QString> >(this);

    QScriptValue xmlHttpRequestConstructorValue = newFunction(XMLHttpRequestClass::constructor);
    globalObject().setProperty("XMLHttpRequest", xmlHttpRequestConstructorValue);

    QScriptValue printConstructorValue = newFunction(debugPrint);
    globalObject().setProperty("print", printConstructorValue);

    QScriptValue soundConstructorValue = newFunction(soundConstructor);
    QScriptValue soundMetaObject = newQMetaObject(&Sound::staticMetaObject, soundConstructorValue);
    globalObject().setProperty("Sound", soundMetaObject);

    QScriptValue injectionOptionValue = scriptValueFromQMetaObject<AudioInjectorOptions>();
    globalObject().setProperty("AudioInjectionOptions", injectionOptionValue);

    QScriptValue localVoxelsValue = scriptValueFromQMetaObject<LocalVoxels>();
    globalObject().setProperty("LocalVoxels", localVoxelsValue);
    
    qScriptRegisterMetaType(this, injectorToScriptValue, injectorFromScriptValue);
    qScriptRegisterMetaType(this, inputControllerToScriptValue, inputControllerFromScriptValue);

    qScriptRegisterMetaType(this, animationDetailsToScriptValue, animationDetailsFromScriptValue);

    registerGlobalObject("Script", this);
    registerGlobalObject("Audio", &_audioScriptingInterface);
    registerGlobalObject("Controller", _controllerScriptingInterface);
    registerGlobalObject("Entities", &_entityScriptingInterface);
    registerGlobalObject("Particles", &_particlesScriptingInterface);
    registerGlobalObject("Quat", &_quatLibrary);
    registerGlobalObject("Vec3", &_vec3Library);
    registerGlobalObject("Uuid", &_uuidLibrary);
    registerGlobalObject("AnimationCache", &_animationCache);

    registerGlobalObject("Voxels", &_voxelsScriptingInterface);

    // constants
    globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE)));
    globalObject().setProperty("COLLISION_GROUP_ENVIRONMENT", newVariant(QVariant(COLLISION_GROUP_ENVIRONMENT)));
    globalObject().setProperty("COLLISION_GROUP_AVATARS", newVariant(QVariant(COLLISION_GROUP_AVATARS)));
    globalObject().setProperty("COLLISION_GROUP_VOXELS", newVariant(QVariant(COLLISION_GROUP_VOXELS)));
    globalObject().setProperty("COLLISION_GROUP_PARTICLES", newVariant(QVariant(COLLISION_GROUP_PARTICLES)));

    globalObject().setProperty("AVATAR_MOTION_OBEY_LOCAL_GRAVITY", newVariant(QVariant(AVATAR_MOTION_OBEY_LOCAL_GRAVITY)));
    globalObject().setProperty("AVATAR_MOTION_OBEY_ENVIRONMENTAL_GRAVITY", newVariant(QVariant(AVATAR_MOTION_OBEY_ENVIRONMENTAL_GRAVITY)));

    // let the VoxelPacketSender know how frequently we plan to call it
    _voxelsScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS);
    _particlesScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(SCRIPT_DATA_CALLBACK_USECS);
}
Exemplo n.º 15
0
int register_module( std::vector<ModuleReg> & modules, ModuleMap & functions, std::vector<ModuleFunction> & timedfunctions, const char * moduleName )
{
	/* open the module with the name moduleName */

	/* load the module (if possible) */
	void * handle = NULL;
	char * error  = NULL;

	if ( moduleName == NULL ){
		syslog( LOG_ERR, "Unable to load Module, no module name given" );
		return 0;
	}

	handle = dlopen( moduleName, RTLD_LAZY );

	if ( handle == NULL ){
		syslog( LOG_ERR, "Unable to load Module %s : %s", moduleName, dlerror() );
		return 0;
	}

	error = dlerror(); 	/* clear any possible error handler */
	
	/* now call the register_module function */
	
	int ( *registerFunction )( std::vector<CommandFunctionPair> & );

	registerFunction = ( int (*)( std::vector<CommandFunctionPair> &) ) dlsym( handle, "load" );
	
	if ( (error = dlerror()) != NULL)  {
		syslog( LOG_ERR, "Unable to load Module %s : Module lacks load method.", moduleName );
		return 0;
	}

	ModuleReg newModule( moduleName, handle );
	modules.push_back( newModule );
	
	std::vector<CommandFunctionPair> pairs;
	
	(*registerFunction)( pairs );

	for ( std::vector<CommandFunctionPair>::iterator funcref = pairs.begin();
			funcref != pairs.end();
			funcref++ ){
	
		/* create the appropriate structure to place this information in */
		ModuleFunction newFunction( funcref->function, handle, funcref->timeout, funcref->user_id, funcref->group_id, funcref->version, funcref->owner, funcref->logging);
	 
	        if ( newFunction.timeout != -1 ){
			syslog( LOG_INFO, "    Registering timed function : %s:%d", funcref->command.c_str(), newFunction.timeout );
			timedfunctions.push_back( newFunction );
			continue;
                }
		
	        syslog( LOG_INFO, "    Registering command : %s", funcref->command.c_str() );

		if ( newFunction.version == 0 ){
			syslog( LOG_ERR, "Unable to determine action for command \"%s\", skipping definition", funcref->command.c_str() );
			continue;
		}

		if ( functions[ funcref->command ].version >= newFunction.version ){
			syslog( LOG_WARNING, "    Command \"%s\" already exists and is of later version \"%d\" (thisver:%d)", funcref->command.c_str(), functions[ funcref->command ].version, newFunction.version );
			continue;
		} else if ( functions[ funcref->command ].version < newFunction.version && functions[ funcref->command ].version > 0 ){
			syslog( LOG_WARNING, "    Command \"%s\" is already defined but of an earlier version (%d), using this one instead (thisver:%d)", funcref->command.c_str(), functions[ funcref->command ].version, newFunction.version );
		}
		
		functions[ funcref->command ] = newFunction;
	}	
	return 1;
}