示例#1
0
int luaK_numberK (FuncState *fs, lua_Number r) {
  int n;
  lua_State *L = fs->ls->L;
  TValue o;
  setnvalue(&o, r);
  if (r == 0 || luai_numisnan(NULL, r)) {  /* handle -0 and NaN */
    /* use raw representation as key to avoid numeric problems */
    setsvalue(L, L->top, luaS_newlstr(L, (char *)&r, sizeof(r)));
     incr_top(L);
     n = addk(fs, L->top - 1, &o);
     L->top--;
  }
  else
    n = addk(fs, &o, &o);  /* regular case */
  return n;
}
示例#2
0
文件: code.c 项目: unixbhaskar/ktap
int codegen_numberK(ktap_funcstate *fs, ktap_number r)
{
	int n;
	ktap_value o, s;

	setnvalue(&o, r);
	if (r == 0 || ktap_numisnan(NULL, r)) {  /* handle -0 and NaN */
		/* use raw representation as key to avoid numeric problems */
		setsvalue(&s, ktapc_ts_newlstr((char *)&r, sizeof(r)));
		//   incr_top(L);
		n = addk(fs, &s, &o);
		//   L->top--;
	} else
		n = addk(fs, &o, &o);  /* regular case */
	return n;
}
示例#3
0
文件: lcode.cpp 项目: swizl/lua
/*static*/ int FuncState::nilK (/*FuncState *fs*/) {
	TValue k, v;
	setnilvalue(&v);
	/* cannot use nil as key; instead use table itself to represent nil */
	sethvalue(ls->L, &k, ls->h);
	return addk(&k, &v);
}
示例#4
0
static int nilK (FuncState *fs) {
  TValue k, v;
  setnilvalue(&v);
  /* cannot use nil as key; instead use table itself to represent nil */
  sethvalue(fs->ls->L, &k, fs->h);
  return addk(fs, &k, &v);
}
示例#5
0
文件: code.c 项目: unixbhaskar/ktap
int codegen_stringK(ktap_funcstate *fs, ktap_string *s)
{
	ktap_value o;

	setsvalue(&o, s);
	return addk(fs, &o, &o);
}
示例#6
0
文件: code.c 项目: unixbhaskar/ktap
static int nilK(ktap_funcstate *fs)
{
	ktap_value k, v;
	setnilvalue(&v);
	/* cannot use nil as key; instead use table itself to represent nil */
	sethvalue(&k, fs->h);
	return addk(fs, &k, &v);
}
示例#7
0
文件: simp.c 项目: Zhouxiaoqing/mc
static Node *patval(Simp *s, Node *n, Type *t)
{
    if (exprop(n) == Oucon)
        return n->expr.args[1];
    else if (exprop(n) == Olit)
        return n;
    else
        return load(addk(addr(s, n, t), Wordsz));
}
示例#8
0
int main(){
system("clear");	
	srand (time(NULL));
	
	int m1[ORD][ORD], m2[ORD][ORD], m3[ORD][ORD], i, j, digitado;	
	
	//SORTEIA AS MATRIZES M1 E M2
	for (i=0; i<ORD; i++)
	{
		for (j=0; j<ORD; j++)
		{
		m1[i][j] = rand()%5;
		m2[i][j] = rand()%5;
		}
	}

	do
	{	
	        printf("---------- Digite o número da opção desejada ----------\n");
	        printf("|                                                     |\n");
	        printf("|         1 - Somar                                   |\n");
	        printf("|         2 - Subtrair                                |\n");
	        printf("|         3 - Adicionar uma constante                 |\n");
	        printf("|         4 - Imprimir as matrizes                    |\n");
	        printf("|         5 - Sair                                    |\n");
	        printf("|                                                     |\n");
	        printf("-------------------------------------------------------\n");	
		scanf("%d", &digitado);
		
		system("clear");
	
		switch (digitado)
		{
	
		case 1:	
		soma(&m1[0][0],&m2[0][0],&m3[0][0]);
		break;
	
		case 2:
		subtrai(&m1[0][0],&m2[0][0],&m3[0][0]);	
		break;	
	
		case 3:
		addk(&m1[0][0],&m2[0][0]);
		break;
	
		case 4:
		printa(&m1[0][0], &m2[0][0], &m3[0][0]);
		break;
		}
	}
	while (digitado != 5);
	
return(0);
}
示例#9
0
static int nilK (FuncState *fs) {
  TValue k, v;
#if LUA_REFCOUNT
  lua_State *L = fs->L;
  int ret;
  setnilvalue2n(L, &v);
  luarc_newvalue(&k);
  /* cannot use nil as key; instead use table itself to represent nil */
  sethvalue(fs->L, &k, fs->h);
  ret = addk(fs, &k, &v);
  luarc_cleanvalue(&k);
  luarc_cleanvalue(&v);
  return ret;
#else
  setnilvalue(&v);
  /* cannot use nil as key; instead use table itself to represent nil */
  sethvalue(fs->L, &k, fs->h);
  return addk(fs, &k, &v);
#endif /* LUA_REFCOUNT */
}
示例#10
0
文件: simp.c 项目: Zhouxiaoqing/mc
static Node *simpucon(Simp *s, Node *n, Node *dst)
{
    Node *tmp, *u, *tag, *elt, *sz;
    Node *r;
    Type *ty;
    Ucon *uc;
    size_t i;

    /* find the ucon we're constructing here */
    ty = tybase(n->expr.type);
    uc = NULL;
    for (i = 0; i < ty->nmemb; i++) {
        if (!strcmp(namestr(n->expr.args[0]), namestr(ty->udecls[i]->name))) {
            uc = ty->udecls[i];
            break;
        }
    }
    if (!uc)
        die("Couldn't find union constructor");

    if (dst)
        tmp = dst;
    else
        tmp = temp(s, n);

    /* Set the tag on the ucon */
    u = addr(s, tmp, mktype(n->line, Tyuint));
    tag = mkintlit(n->line, uc->id);
    tag->expr.type = mktype(n->line, Tyuint);
    append(s, set(deref(u), tag));


    /* fill the value, if needed */
    if (!uc->etype)
        return tmp;
    elt = rval(s, n->expr.args[1], NULL);
    u = addk(u, Wordsz);
    if (stacktype(uc->etype)) {
        elt = addr(s, elt, uc->etype);
        sz = disp(n->line, tysize(uc->etype));
        r = mkexpr(n->line, Oblit, u, elt, sz, NULL);
    } else {
        r = set(deref(u), elt);
    }
    append(s, r);
    return tmp;
}
示例#11
0
文件: simp.c 项目: Zhouxiaoqing/mc
/* pat; seq; 
 *      body;;
 *
 * =>
 *      .pseudo = seqinit
 *      jmp :cond
 *      :body
 *           ...body...
 *      :step
 *           ...step...
 *      :cond
 *           ...cond...
 *           cjmp (cond) :match :end
 *      :match
 *           ...match...
 *           cjmp (match) :body :step
 *      :end
 */
static void simpiter(Simp *s, Node *n)
{
    Node *lbody, *lstep, *lcond, *lmatch, *lend;
    Node *idx, *len, *dcl, *seq, *val, *done;
    Node *zero;

    lbody = genlbl();
    lstep = genlbl();
    lcond = genlbl();
    lmatch = genlbl();
    lend = genlbl();

    lappend(&s->loopstep, &s->nloopstep, lstep);
    lappend(&s->loopexit, &s->nloopexit, lend);

    zero = mkintlit(n->line, 0);
    zero->expr.type = tyintptr;

    seq = rval(s, n->iterstmt.seq, NULL);
    idx = gentemp(s, n, tyintptr, &dcl);
    declarelocal(s, dcl);

    /* setup */
    append(s, assign(s, idx, zero));
    jmp(s, lcond);
    simp(s, lbody);
    /* body */
    simp(s, n->iterstmt.body);
    /* step */
    simp(s, lstep);
    simp(s, assign(s, idx, addk(idx, 1)));
    /* condition */
    simp(s, lcond);
    len = seqlen(s, seq, tyintptr);
    done = mkexpr(n->line, Olt, idx, len, NULL);
    cjmp(s, done, lmatch, lend);
    simp(s, lmatch);
    val = load(idxaddr(s, seq, idx));
    umatch(s, n->iterstmt.elt, val, val->expr.type, lbody, lstep);
    simp(s, lend);

    s->nloopstep--;
    s->nloopexit--;
}
示例#12
0
static int addk (FuncState *fs, TValue *k, TValue *v) {
  lua_State *L = fs->L;
  TValue *idx = luaH_set(L, fs->h, k);
#ifdef LUA_TINT
  /* Note: Integer-valued LUA_TNUMBER's are handled as in unpatched Lua (below)
  */
  if (ttype(idx)==LUA_TINT) {
    int i;
# ifdef LNUM_INT64
    lua_assert( (int)ivalue(idx) == ivalue(idx) );  /* make sure no data is lost in the casting */
# endif
    i= (int)ivalue(idx);
    lua_assert(luaO_rawequalObj(&fs->f->k[i], v));
    return i;
  }
  else if (ttype(idx)==LUA_TNUMBER) {
#else
  if (ttisnumber(idx)) {
#endif
    int i= cast_int(nvalue_fast(idx));
    lua_assert(luaO_rawequalObj(&fs->f->k[i], v));
    return i;
  }
  else {  /* constant not found; create a new entry */
    Proto *f = fs->f;
    int oldsize = f->sizek;
    setivalue(idx, fs->nk);
    luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
                    MAXARG_Bx, "constant table overflow");
    while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
    setobj(L, &f->k[fs->nk], v);
    luaC_barrier(L, f, v);
    return fs->nk++;
  }
}


int luaK_stringK (FuncState *fs, TString *s) {
  TValue o;
  setsvalue(fs->L, &o, s);
  return addk(fs, &o, &o);
}
示例#13
0
static int luaK_imagK (FuncState *fs, lua_Number r) {
  TValue o;
  setnvalue_complex(&o, r*I);
  return addk(fs, &o, &o);
}
示例#14
0
文件: lcode.c 项目: celskeggs/selkie
/*
** Add a boolean to list of constants and return its index.
*/
static int boolK (FuncState *fs, int b) {
  TValue o;
  setbvalue(&o, b);
  return addk(fs, &o, &o);  /* use boolean itself as key */
}
示例#15
0
文件: lcode.c 项目: celskeggs/selkie
/*
** Add a float to list of constants and return its index.
*/
static int luaK_numberK (FuncState *fs, lua_Number r) {
  TValue o;
  setfltvalue(&o, r);
  return addk(fs, &o, &o);  /* use number itself as key */
}
示例#16
0
文件: lcode.c 项目: celskeggs/selkie
/*
** Add an integer to list of constants and return its index.
** Integers use userdata as keys to avoid collision with floats with
** same value; conversion to 'void*' is used only for hashing, so there
** are no "precision" problems.
*/
int luaK_intK (FuncState *fs, lua_Integer n) {
  TValue k, o;
  setpvalue(&k, cast(void*, cast(size_t, n)));
  setivalue(&o, n);
  return addk(fs, &k, &o);
}
示例#17
0
文件: lcode.c 项目: celskeggs/selkie
/*
** Add a string to list of constants and return its index.
*/
int luaK_stringK (FuncState *fs, TString *s) {
  TValue o;
  setsvalue(fs->ls->L, &o, s);
  return addk(fs, &o, &o);  /* use string itself as key */
}
示例#18
0
static int boolK (FuncState *fs, int b) {
  TValue o;
  setbvalue(&o, b);
  return addk(fs, &o, &o);
}
示例#19
0
文件: lcode.cpp 项目: swizl/lua
/*
** Integers use userdata as keys to avoid collision with floats with same
** value; conversion to 'void*' used only for hashing, no "precision"
** problems
*/
int FuncState::luaK_intK (/*FuncState *fs,*/ lua_Integer n) {
	TValue k, o;
	setpvalue(&k, cast(void*, cast(size_t, n)));
	setivalue(&o, n);
	return addk(&k, &o);
}
示例#20
0
int luaK_integerK (FuncState *fs, lua_Integer r) {
  TValue o;
  setivalue(&o, r);
  return addk(fs, &o, &o);
}
示例#21
0
文件: simp.c 项目: Zhouxiaoqing/mc
static Node *slicelen(Simp *s, Node *sl)
{
    /* *(&sl + sizeof(size_t)) */
    return load(addk(addr(s, sl, tyintptr), Ptrsz));
}
示例#22
0
文件: lcode.cpp 项目: swizl/lua
/*static*/ int FuncState::luaK_numberK (/*FuncState *fs,*/ lua_Number r) {
	TValue o;
	setfltvalue(&o, r);
	return addk(&o, &o);
}
示例#23
0
文件: lcode.c 项目: Squonk42/nodelua
static int ICACHE_FLASH_ATTR boolK (FuncState *fs, int b) {
  TValue o;
  setbvalue(&o, b);
  return addk(fs, &o, &o);
}
示例#24
0
文件: lcode.c 项目: Squonk42/nodelua
int ICACHE_FLASH_ATTR luaK_numberK (FuncState *fs, lua_Number r) {
  TValue o;
  setnvalue(&o, r);
  return addk(fs, &o, &o);
}
示例#25
0
文件: lcode.c 项目: Squonk42/nodelua
int ICACHE_FLASH_ATTR luaK_stringK (FuncState *fs, TString *s) {
  TValue o;
  setsvalue(fs->L, &o, s);
  return addk(fs, &o, &o);
}
示例#26
0
/*
** Both NaN and -0.0 should not go to the constant table, as they have
** problems with the hashing. (NaN is not a valid key, -0.0 collides
** with +0.0.)
*/ 
static int luaK_numberK (FuncState *fs, lua_Number r) {
  TValue o;
  lua_assert(!luai_numisnan(r) && !isminuszero(r));
  setfltvalue(&o, r);
  return addk(fs, &o, &o);
}
示例#27
0
int luaK_stringK (FuncState *fs, TString *s) {
  TValue o;
  setsvalue(fs->L, &o, s);
  return addk(fs, &o, &o);
}
示例#28
0
int luaK_numberK (FuncState *fs, lua_Number r) {
  TValue o;
  setnvalue(&o, r);
  return addk(fs, &o, &o);
}
示例#29
0
文件: simp.c 项目: Zhouxiaoqing/mc
static void umatch(Simp *s, Node *pat, Node *val, Type *t, Node *iftrue, Node *iffalse)
{
    Node *v, *x, *y;
    Node *deeper, *next;
    Node **patarg;
    Ucon *uc;
    size_t i;
    size_t off;

    assert(pat->type == Nexpr);
    t = tybase(t);
    if (exprop(pat) == Ovar && !decls[pat->expr.did]->decl.isconst) {
        v = assign(s, pat, val);
        append(s, v);
        jmp(s, iftrue);
        return;
    }
    switch (t->type) {
        /* Never supported */
        case Tyvoid: case Tybad: case Tyvalist: case Tyvar:
        case Typaram: case Tyunres: case Tyname: case Ntypes:
        /* Should never show up */
        case Tyslice:
            die("Unsupported type for compare");
            break;
        case Tybool: case Tychar: case Tybyte:
        case Tyint8: case Tyint16: case Tyint32: case Tyint:
        case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint:
        case Tyint64: case Tyuint64: case Tylong:  case Tyulong:
        case Tyfloat32: case Tyfloat64:
        case Typtr: case Tyfunc:
            v = mkexpr(pat->line, Oeq, pat, val, NULL);
            v->expr.type = mktype(pat->line, Tybool);
            cjmp(s, v, iftrue, iffalse);
            break;
        /* We got lucky. The structure of tuple, array, and struct literals
         * is the same, so long as we don't inspect the type, so we can
         * share the code*/
        case Tystruct: case Tytuple: case Tyarray: 
            patarg = pat->expr.args;
            off = 0;
            for (i = 0; i < pat->expr.nargs; i++) {
                off = tyalign(off, size(patarg[i]));
                next = genlbl();
                v = load(addk(addr(s, val, exprtype(patarg[i])), off));
                umatch(s, patarg[i], v, exprtype(patarg[i]), next, iffalse);
                append(s, next);
                off += size(patarg[i]);
            }
            jmp(s, iftrue);
            break;
        case Tyunion:
            uc = finducon(pat);
            if (!uc)
                uc = finducon(val);

            deeper = genlbl();

            x = uconid(s, pat);
            y = uconid(s, val);
            v = mkexpr(pat->line, Oeq, x, y, NULL);
            v->expr.type = tyintptr;
            cjmp(s, v, deeper, iffalse);
            append(s, deeper);
            if (uc->etype) {
                pat = patval(s, pat, uc->etype);
                val = patval(s, val, uc->etype);
                umatch(s, pat, val, uc->etype, iftrue, iffalse);
            }
            break;
    }
}
示例#30
0
文件: lcode.cpp 项目: swizl/lua
/*static*/ int FuncState::boolK (/*FuncState *fs,*/ int b) {
	TValue o;
	setbvalue(&o, b);
	return addk(&o, &o);
}