void initmv3funs() { short tpl[4]; tpl[0] = tpl[3] = ULreal; tpl[1] = tpl[2] = ULreal3; newfun( "multvec3", ULmultvec3, 0, 4, tpl, (implinst)ulmultvec3, 0, 0 ); }
static void cfundecs(JF, js_Ast *list) { while (list) { js_Ast *stm = list->a; if (stm->type == AST_FUNDEC) { emitfunction(J, F, newfun(J, stm->a, stm->b, stm->c, 0)); emitstring(J, F, OP_INITVAR, stm->a->string); } list = list->b; } }
static void cobject(JF, js_Ast *list) { js_Ast *head = list; while (list) { js_Ast *kv = list->a; js_Ast *prop = kv->a; if (prop->type == AST_IDENTIFIER || prop->type == EXP_STRING) emitstring(J, F, OP_STRING, prop->string); else if (prop->type == EXP_NUMBER) emitnumber(J, F, prop->number); else jsC_error(J, prop, "invalid property name in object initializer"); if (J->strict) checkdup(J, F, head, kv); switch (kv->type) { default: /* impossible */ break; case EXP_PROP_VAL: cexp(J, F, kv->b); emit(J, F, OP_INITPROP); break; case EXP_PROP_GET: emitfunction(J, F, newfun(J, NULL, kv->b, kv->c, 0)); emit(J, F, OP_INITGETTER); break; case EXP_PROP_SET: emitfunction(J, F, newfun(J, NULL, kv->b, kv->c, 0)); emit(J, F, OP_INITSETTER); break; } list = list->b; } }
static void threadfuns() { short tpl[4]; tpl[0] = ULcom; tpl[1] = 0; newfun( "thread", ULint, 1, -1, tpl, ulstartthread, 0, NOMAP, 0 ); newfun( "loopthread", ULint, 1, 1, tpl, ulstartloopthread, 0, NOMAP, 0 ); tpl[1] = ULwin; newfun( "syncthread", ULint, 1, 2, tpl, ulstartsyncthread, 0, NOMAP, 0 ); tpl[0] = ULint; newfun( "isready", ULbool, 1, 1, tpl, ulthreadready, 0, NOMAP, 0 ); newfun( "end", ULint, 1, 1, tpl, ulthreadend, 0, NOMAP, 0 ); newfun( "threads", ULlist, 0, 0, tpl, ulthreadlist, 0, NOMAP, 0 ); }
static void solfuns() { short tpl[4]; tpl[0] = ULint; newfun( "prim", ULsol, 1, 1, tpl, ulprim, 0, NOMAP, 0 ); // tpl[1] = tpl[2] = tpl[3] = ULreal; // newfun( "isoprim", ULsol, 1, 4, tpl, ulisoprim, 0, NOMAP, 0 ); tpl[0] = ULsol; newfun( "trfof", ULtrf3, 1, 1, tpl, ultrfof, 0, NOMAP, 0 ); tpl[1] = ULint; newfun( "getnatr", ULlist, 2, 2, tpl, ulgetnatr, 0, NOMAP, 0 ); newfun( "getlatr", ULlist, 2, 2, tpl, ulgetlatr, 0, NOMAP, 0 ); tpl[2] = ULlist; newfun( "putnatr", ULsol, 3, 3, tpl, ulputnatr, 0, NOMAP, 0 ); newfun( "putlatr", ULsol, 3, 3, tpl, ulputlatr, 0, NOMAP, 0 ); }
static void cobject(JF, js_Ast *list) { while (list) { js_Ast *kv = list->a; js_Ast *prop = kv->a; if (kv->type == EXP_PROP_VAL) { if (prop->type == AST_IDENTIFIER || prop->type == EXP_STRING) { cexp(J, F, kv->b); emitstring(J, F, OP_INITPROP_S, prop->string); } else if (prop->type == EXP_NUMBER) { if (prop->number == (js_Instruction)prop->number) { cexp(J, F, kv->b); emit(J, F, OP_INITPROP_N); emitraw(J, F, (js_Instruction)prop->number); } else { emitnumber(J, F, prop->number); cexp(J, F, kv->b); emit(J, F, OP_INITPROP); } } else { jsC_error(J, list, "illegal property name in object initializer"); } } else { if (prop->type == AST_IDENTIFIER || prop->type == EXP_STRING) emitstring(J, F, OP_STRING, prop->string); if (prop->type == EXP_NUMBER) emitnumber(J, F, prop->number); emitfunction(J, F, newfun(J, NULL, kv->b, kv->c, 0)); if (kv->type == EXP_PROP_GET) emit(J, F, OP_INITGETTER); if (kv->type == EXP_PROP_SET) emit(J, F, OP_INITSETTER); } list = list->b; } }
static void cexp(JF, js_Ast *exp) { int then, end; int n; switch (exp->type) { case EXP_STRING: emitstring(J, F, OP_STRING, exp->string); break; case EXP_NUMBER: emitnumber(J, F, exp->number); break; case EXP_UNDEF: emit(J, F, OP_UNDEF); break; case EXP_NULL: emit(J, F, OP_NULL); break; case EXP_TRUE: emit(J, F, OP_TRUE); break; case EXP_FALSE: emit(J, F, OP_FALSE); break; case EXP_THIS: emit(J, F, OP_THIS); break; case EXP_REGEXP: emit(J, F, OP_NEWREGEXP); emitraw(J, F, addstring(J, F, exp->string)); emitraw(J, F, exp->number); break; case EXP_OBJECT: emit(J, F, OP_NEWOBJECT); cobject(J, F, exp->a); break; case EXP_ARRAY: emit(J, F, OP_NEWARRAY); carray(J, F, exp->a); break; case EXP_FUN: emitfunction(J, F, newfun(J, exp->a, exp->b, exp->c, 0)); break; case EXP_IDENTIFIER: emitlocal(J, F, OP_GETLOCAL, OP_GETVAR, exp); break; case EXP_INDEX: cexp(J, F, exp->a); cexp(J, F, exp->b); emit(J, F, OP_GETPROP); break; case EXP_MEMBER: cexp(J, F, exp->a); emitstring(J, F, OP_GETPROP_S, exp->b->string); break; case EXP_CALL: ccall(J, F, exp->a, exp->b); break; case EXP_NEW: cexp(J, F, exp->a); n = cargs(J, F, exp->b); emit(J, F, OP_NEW); emitraw(J, F, n); break; case EXP_DELETE: cdelete(J, F, exp->a); break; case EXP_PREINC: cassignop1(J, F, exp->a); emit(J, F, OP_INC); cassignop2(J, F, exp->a, 0); break; case EXP_PREDEC: cassignop1(J, F, exp->a); emit(J, F, OP_DEC); cassignop2(J, F, exp->a, 0); break; case EXP_POSTINC: cassignop1(J, F, exp->a); emit(J, F, OP_POSTINC); cassignop2(J, F, exp->a, 1); emit(J, F, OP_POP); break; case EXP_POSTDEC: cassignop1(J, F, exp->a); emit(J, F, OP_POSTDEC); cassignop2(J, F, exp->a, 1); emit(J, F, OP_POP); break; case EXP_VOID: cexp(J, F, exp->a); emit(J, F, OP_POP); emit(J, F, OP_UNDEF); break; case EXP_TYPEOF: ctypeof(J, F, exp->a); break; case EXP_POS: cunary(J, F, exp, OP_POS); break; case EXP_NEG: cunary(J, F, exp, OP_NEG); break; case EXP_BITNOT: cunary(J, F, exp, OP_BITNOT); break; case EXP_LOGNOT: cunary(J, F, exp, OP_LOGNOT); break; case EXP_BITOR: cbinary(J, F, exp, OP_BITOR); break; case EXP_BITXOR: cbinary(J, F, exp, OP_BITXOR); break; case EXP_BITAND: cbinary(J, F, exp, OP_BITAND); break; case EXP_EQ: cbinary(J, F, exp, OP_EQ); break; case EXP_NE: cbinary(J, F, exp, OP_NE); break; case EXP_STRICTEQ: cbinary(J, F, exp, OP_STRICTEQ); break; case EXP_STRICTNE: cbinary(J, F, exp, OP_STRICTNE); break; case EXP_LT: cbinary(J, F, exp, OP_LT); break; case EXP_GT: cbinary(J, F, exp, OP_GT); break; case EXP_LE: cbinary(J, F, exp, OP_LE); break; case EXP_GE: cbinary(J, F, exp, OP_GE); break; case EXP_INSTANCEOF: cbinary(J, F, exp, OP_INSTANCEOF); break; case EXP_IN: cbinary(J, F, exp, OP_IN); break; case EXP_SHL: cbinary(J, F, exp, OP_SHL); break; case EXP_SHR: cbinary(J, F, exp, OP_SHR); break; case EXP_USHR: cbinary(J, F, exp, OP_USHR); break; case EXP_ADD: cbinary(J, F, exp, OP_ADD); break; case EXP_SUB: cbinary(J, F, exp, OP_SUB); break; case EXP_MUL: cbinary(J, F, exp, OP_MUL); break; case EXP_DIV: cbinary(J, F, exp, OP_DIV); break; case EXP_MOD: cbinary(J, F, exp, OP_MOD); break; case EXP_ASS: cassign(J, F, exp); break; case EXP_ASS_MUL: cassignop(J, F, exp, OP_MUL); break; case EXP_ASS_DIV: cassignop(J, F, exp, OP_DIV); break; case EXP_ASS_MOD: cassignop(J, F, exp, OP_MOD); break; case EXP_ASS_ADD: cassignop(J, F, exp, OP_ADD); break; case EXP_ASS_SUB: cassignop(J, F, exp, OP_SUB); break; case EXP_ASS_SHL: cassignop(J, F, exp, OP_SHL); break; case EXP_ASS_SHR: cassignop(J, F, exp, OP_SHR); break; case EXP_ASS_USHR: cassignop(J, F, exp, OP_USHR); break; case EXP_ASS_BITAND: cassignop(J, F, exp, OP_BITAND); break; case EXP_ASS_BITXOR: cassignop(J, F, exp, OP_BITXOR); break; case EXP_ASS_BITOR: cassignop(J, F, exp, OP_BITOR); break; case EXP_COMMA: cexp(J, F, exp->a); emit(J, F, OP_POP); cexp(J, F, exp->b); break; case EXP_LOGOR: cexp(J, F, exp->a); emit(J, F, OP_DUP); end = emitjump(J, F, OP_JTRUE); emit(J, F, OP_POP); cexp(J, F, exp->b); label(J, F, end); break; case EXP_LOGAND: cexp(J, F, exp->a); emit(J, F, OP_DUP); end = emitjump(J, F, OP_JFALSE); emit(J, F, OP_POP); cexp(J, F, exp->b); label(J, F, end); break; case EXP_COND: cexp(J, F, exp->a); then = emitjump(J, F, OP_JTRUE); cexp(J, F, exp->c); end = emitjump(J, F, OP_JUMP); label(J, F, then); cexp(J, F, exp->b); label(J, F, end); break; default: jsC_error(J, exp, "unknown expression: (%s)", jsP_aststring(exp->type)); } }
js_Function *jsC_compile(js_State *J, js_Ast *prog) { return newfun(J, NULL, NULL, prog, 1); }
js_Function *jsC_compilefunction(js_State *J, js_Ast *prog) { return newfun(J, prog->a, prog->b, prog->c, 0); }
static void vecfuns() { short tpl[4]; tpl[0] = tpl[1] = tpl[2] = ULint; newfun( "int2", ULint2, 0, 2, tpl, (implinst)ulmaki2, 0, 0 ); newfun( "int3", ULint3, 0, 3, tpl, (implinst)ulmaki3, 0, 0 ); tpl[0] = tpl[1] = tpl[2] = tpl[3] = ULreal; newfun( "real2", ULreal2, 0, 2, tpl, (implinst)ulmakr2, (diffinst)dfmakr2, FUNNAME, "real2", 0 ); newfun( "real3", ULreal3, 0, 3, tpl, (implinst)ulmakr3, (diffinst)dfmakr3, FUNNAME, "real3", 0 ); newfun( "real4", ULreal4, 0, 4, tpl, (implinst)ulmakr4, 0, 0 ); tpl[0] = tpl[1] = ULint2; newfun( "intl2", ULintl2, 2, 2, tpl, (implinst)ulmakil2, 0, 0 ); tpl[0] = tpl[1] = ULint3; newfun( "intl3", ULintl3, 2, 2, tpl, (implinst)ulmakil3, 0, 0 ); tpl[0] = tpl[1] = ULreal2; newfun( "reall2", ULreall2, 2, 2, tpl, (implinst)ulmakrl2, 0, 0 ); tpl[0] = tpl[1] = ULreal3; newfun( "reall3", ULreall3, 2, 2, tpl, (implinst)ulmakrl3, 0, 0 ); tpl[0] = ULreal3; newfun( "clamp", ULreal3, 1, 1, tpl, (implinst)ulclamp3, 0, 0 ); tpl[0] = ULreal3; tpl[1] = ULreal; newfun( "real4", ULreal4, 2, 2, tpl, (implinst)ulmakr34, 0, 0 ); tpl[0] = ULreal2; newfun( "String", ULcom, 1, 1, tpl, (implinst)ulRealntoString, 0, NOMAP, 0 ); tpl[0] = ULreal3; newfun( "String", ULcom, 1, 1, tpl, (implinst)ulRealntoString, 0, NOMAP, 0 ); tpl[0] = ULreal4; newfun( "String", ULcom, 1, 1, tpl, (implinst)ulRealntoString, 0, NOMAP, 0 ); }