コード例 #1
0
ファイル: vector.cpp プロジェクト: SangitaSingh/elmerfem
void Vector :: ChangeLength (INDEX alength)
{
  (*mycout) << "Vector::ChangeLength called" << endl;
  if (length == alength) return;
  
  if (alength == 0)
    {
      //    delete [] data;
      DeleteDouble (length, data);
      length = 0;
      return;
    }
  
  double * olddata = data;

  data = NewDouble (alength);
  //  data = new double[alength];
  if (!data)
    {
    length = 0;
    (*myerr) << "Vector::SetLength: Vector not allocated" << endl;
    delete [] olddata;
    }

  memcpy (data, olddata, min2(alength, length));

  delete [] olddata;
  length = alength;
  }
コード例 #2
0
ファイル: vector.cpp プロジェクト: SangitaSingh/elmerfem
Vector :: Vector (INDEX alength) : BaseVector (alength)
  {
  if (length)
    {
      //    data = new double[length];
      data = NewDouble (length);

    if (!data)
      {
      length = 0;
      (*myerr) << "Vector not allocated" << endl;
      }
    }
  else
    data = NULL;
  }
コード例 #3
0
jobject wrapJSObject(JNIEnv *pEnv, v8::Handle<v8::Value> value)
{
  v8::HandleScope handle_scope;

  if (value.IsEmpty() || value->IsNull() || value->IsUndefined()) return NULL;
  if (value->IsTrue()) return NewBoolean(pEnv, JNI_TRUE);
  if (value->IsFalse()) return NewBoolean(pEnv, JNI_FALSE);

  if (value->IsInt32()) return NewInt(pEnv, value->Int32Value());
  if (value->IsUint32()) return NewLong(pEnv, value->IntegerValue());
  if (value->IsString()) return NewString(pEnv, v8::Handle<v8::String>::Cast(value));
  if (value->IsDate()) return NewDate(pEnv, v8::Handle<v8::Date>::Cast(value));
  if (value->IsNumber()) return NewDouble(pEnv, value->NumberValue());

//  return wrap(value->ToObject());
  return NULL;
}
コード例 #4
0
ファイル: vector.cpp プロジェクト: SangitaSingh/elmerfem
void Vector :: SetLength (INDEX alength)
  {
  if (length == alength) return;

  if (data) 
    {
      DeleteDouble (length, data);
      //      delete [] data;
    }
  data = NULL;
  length = alength;

  if (length == 0) return;
  //  data = new double[length];
  data = NewDouble (length);

  if (!data)
    {
    length = 0;
    (*myerr) << "Vector::SetLength: Vector not allocated" << endl;
    }
  }
コード例 #5
0
ファイル: vector.cpp プロジェクト: SangitaSingh/elmerfem
Vector :: Vector (const Vector & v2)
  {
  length = v2.length;

  if (length)
    {
      //    data = new double[length];
      data = NewDouble (length);

    if (data)
      {
      memcpy (data, v2.data, length * sizeof (double));
      }
    else
      {
      length = 0;
      (*myerr) << "Vector::Vector : Vector not allocated" << endl;
      }
    }
  else
    data = NULL;
  }
コード例 #6
0
static int yp_yajl_double(void *o, double doubleVal)
{
	JsonParserCtx *ctx = static_cast<JsonParserCtx*>(o);
	JsonEl *el = NewDouble(doubleVal);
	return jp_add_element(ctx, el);
}
コード例 #7
0
ファイル: init_.c プロジェクト: anishmaharjan/Camel-game
void init_literal()
{
    extern double sqrt();
    _532 = NewString("CHICKEN! ");
    _524 = NewString("Want another camel and a new game? ");
    _522 = NewString("Turkeys should fly, not ride camels. ");
    _520 = NewString("stay out of the desert. ");
    _519 = NewString("People with little inteligence should ");
    _517 = NewString("chain purse!!!!!! ");
    _516 = NewString("The local shiek now uses your skull for a ");
    _514 = NewString("imported cannon balls!!!!!! ");
    _513 = NewString("Your body was eaten by voltures and ");
    _511 = NewString("your funeral!!!!!! ");
    _510 = NewString("The National's Camel Union is not attending ");
    _508 = NewString("Your body and soul lay a rest in the sand. ");
    _505 = NewString("Computer Braille and don't press ENTER. ");
    _504 = NewString("Simply type the command in by number using ");
    _503 = NewString("6 hope for help ");
    _502 = NewString("5 status check ");
    _501 = NewString("4 stop for a rest ");
    _500 = NewString("3 move ahead fast speed ");
    _499 = NewString("2 move ahead moderate speed ");
    _498 = NewString("1 drink from your canteen ");
    _497 = NewString("The commands you can choose from are: ");
    _496 = NewString("Invalid Option. ");
    _495 = NewString("unconsciousness. ");
    _494 = NewString("Help has found you in a state of ");
    _487 = NewString("BETTER WATCH FOR AN OASES. ");
    _486 = NewString("You can go %d commands without drinking. ");
    _485 = NewString("You have %d drinks left in the canteen. ");
    _484 = NewString("Your camel has %d good days left. ");
    _480 = NewString("Your camel thanks you. ");
    _476 = NewString("sands. ");
    _475 = NewString("Your camel is burning across the desert ");
    _469 = NewString("Just Wait ");
    _468 = NewString("free to go. The local sultin is collecting. ");
    _467 = NewString("Your ransom has been payed and you are ");
    _464 = NewString("while trying to escape. ");
    _463 = NewString("You were mortally wounded by a pig stabber ");
    _462 = NewString("CONGRATULATIONS! YOU SUCCESSFULLY ESCAPED! ");
    _457 = NewString("Your sub-command? ");
    _456 = NewString("#7 attempt an escape, or #8 wait for payment.");
    _455 = NewString("You have a new set of commands. ");
    _454 = NewString("ransom-demands... But... watch for thePigmies. ");
    _453 = NewString("Luckily the local sheik has agreed to their ");
    _452 = NewString("YOU HAVE BEEN CAPTURED BY A HIDDENSAND-BERBER. ");
    _450 = NewString("filling your canteen and eating figs. ");
    _449 = NewString("You have stopped at an Oases. Your camel is ");
    _445 = NewString("GOOD LUCK! ");
    _444 = NewString("YOU HAVE BEEN CAUGHT IN A SAND-STORM... ");
    _437 = NewString("Your camel likes this paste! ");
    _431 = NewString("BETTER WATCH FOR A OASIS. ");
    _429 = NewString("YOU RAN OUT OF WATER. SORRY CHUM!!!!!! ");
    _424 = NewString("Your command? ");
    _419 = NewString("and have %d more miles to go. ");
    _418 = NewString("You have travelled %d miles altogether, ");
    _415 = NewString("The Pigmies are %d miles behind you. ");
    _412 = NewString("Oases. ");
    _411 = NewString("You are in the middle of the desert at an ");
    _409 = NewString("YOU RAN YOUR INNOCENT CAMEL TO DEATH! ");
    _408 = NewString("\n YOU DIRTY LOUSY RAP SCALLION!!! ");
    _406 = NewString("YOU RAN OUT OF WATER... SORRY CHUM!!!!!! ");
    _404 = NewString("W A R N I N G -- GET A DRINK ");
    _402 = NewString("PEOPLE SOUP IS THEIR FAVORITE DISH. ");
    _401 = NewString("THE PIGMIES HAVE CAPTURED YOU! CAMEL AND ");
    _384 = NewString("The Pigmies are %d miles ahead of you.");
    _381 = NewString("The Pigmies are planning to attend. ");
    _380 = NewString("YOU WIN! A party is given in your honor! ");
    _376 = NewString("Good luck and good cameling. ");
    _375 = NewString("'6', you lose. ");
    _374 = NewString("If help does not find you after command ");
    _373 = NewString("You get a half quart if found by help. ");
    _372 = NewString("Oases completely. ");
    _371 = NewString("You must renew your water supply at an ");
    _370 = NewString("you six drinks. ");
    _369 = NewString("You will get a quart of water which will last");
    _368 = NewString("and 6 hope for help. ");
    _367 = NewString("5 status check, ");
    _366 = NewString("4 stop for a rest, ");
    _365 = NewString("3 move ahead fast speed, ");
    _364 = NewString("2 move ahead moderate speed, ");
    _363 = NewString("1 drink from your canteen, ");
    _362 = NewString("C O M M A N D S: ");
    _361 = NewString("often. ");
    _360 = NewString("You will be asked for commands every so ");
    _359 = NewString("chasing you. ");
    _358 = NewString("A tribe of knocked kneed Pigmies will be ");
    _357 = NewString("miles across the Great Gobi Desert. ");
    _356 = NewString("The object of the game is to travel 200 ");
    _355 = NewString("Welcome to the game of Camel. ");
    _344 = NewString("yes or N for no. ");
    _343 = NewString("Would you like instructions? Type Y for ");
    _341 = NewString("\n Welcome to The Game Of Camel. ");
    _324 = NewDouble((double)1.0000000000000000e+00);
    _314 = NewDouble((double)2.0000000000000000e+00);
    _313 = NewDouble((double)3.1415926535897931e+00);
    _44 = NewString("");
    _216 = NewString("%.10g");
    _286 = NewString("%d");
    _278 = NewString(" ...");
    _226 = NewString("}");
    _218 = NewString("{");
    _175 = NewString("A number from %g to %g is expected here - try again\n");
    _164 = NewString("A number is expected - try again\n");
    _29 = NewString("\n\t'\"\\\r");
    _28 = NewString("nt'\"\\r");
    _26 = NewString(" \t\n\r");
    _12 = NewString("-+.#");
    _10 = NewString("ABCDEF");
    _9 = NewString("0123456789");
}
コード例 #8
0
ファイル: be_callc.c プロジェクト: jesserayadkins/Gyroe
object call_c(int func, object proc_ad, object arg_list)
/* Call a WIN32 or Linux C function in a DLL or shared library.
   Alternatively, call a machine-code routine at a given address. */
{
    volatile unsigned long arg;  // !!!! magic var to push values on the stack
    volatile int argsize;        // !!!! number of bytes to pop

    s1_ptr arg_list_ptr, arg_size_ptr;
    object_ptr next_arg_ptr, next_size_ptr;
    object next_arg, next_size;
    int iresult, i;
    double dbl_arg, dresult;
    float flt_arg, fresult;
    unsigned long size;
    int proc_index;
    int cdecl_call;
    int (*int_proc_address)();
    unsigned return_type;
    char NameBuff[100];

    // Setup and Check for Errors

    proc_index = get_pos_int("c_proc/c_func", proc_ad);
    if ((unsigned)proc_index >= c_routine_next) {
	sprintf(TempBuff, "c_proc/c_func: bad routine number (%d)", proc_index);
	RTFatal(TempBuff);
    }

    int_proc_address = c_routine[proc_index].address;
#if defined(EWINDOWS) && !defined(EWATCOM)
    cdecl_call = c_routine[proc_index].convention;
#endif
    if (IS_ATOM(arg_list)) {
	RTFatal("c_proc/c_func: argument list must be a sequence");
    }

    arg_list_ptr = SEQ_PTR(arg_list);
    next_arg_ptr = arg_list_ptr->base + arg_list_ptr->length;

    // only look at length of arg size sequence for now
    arg_size_ptr = c_routine[proc_index].arg_size;
    next_size_ptr = arg_size_ptr->base + arg_size_ptr->length;

    return_type = c_routine[proc_index].return_size; // will be INT

    if (func && return_type == 0 || !func && return_type != 0) {
	if (c_routine[proc_index].name->length < 100)
	    MakeCString(NameBuff, MAKE_SEQ(c_routine[proc_index].name));
	else
	    NameBuff[0] = '\0';
	sprintf(TempBuff, func ? "%s does not return a value" :
				 "%s returns a value",
				 NameBuff);
	RTFatal(TempBuff);
    }

    if (arg_list_ptr->length != arg_size_ptr->length) {
	if (c_routine[proc_index].name->length < 100)
	    MakeCString(NameBuff, MAKE_SEQ(c_routine[proc_index].name));
	else
	    NameBuff[0] = '\0';
	sprintf(TempBuff, "C routine %s() needs %d argument%s, not %d",
			  NameBuff,
			  arg_size_ptr->length,
			  (arg_size_ptr->length == 1) ? "" : "s",
			  arg_list_ptr->length);
	RTFatal(TempBuff);
    }

    argsize = arg_list_ptr->length << 2;


    // Push the Arguments

    for (i = 1; i <= arg_list_ptr->length; i++) {

	next_arg = *next_arg_ptr--;
	next_size = *next_size_ptr--;

	if (IS_ATOM_INT(next_size))
	    size = INT_VAL(next_size);
	else if (IS_ATOM(next_size))
	    size = (unsigned long)DBL_PTR(next_size)->dbl;
	else
	    RTFatal("This C routine was defined using an invalid argument type");

	if (size == C_DOUBLE || size == C_FLOAT) {
	    /* push 8-byte double or 4-byte float */
	    if (IS_ATOM_INT(next_arg))
		dbl_arg = (double)next_arg;
	    else if (IS_ATOM(next_arg))
		dbl_arg = DBL_PTR(next_arg)->dbl;
	    else {
		arg = arg+argsize+9999; // 9999 = 270f hex - just a marker for asm code
		RTFatal("arguments to C routines must be atoms");
	    }

	    if (size == C_DOUBLE) {
		arg = *(1+(unsigned long *)&dbl_arg);

		push();  // push high-order half first
		argsize += 4;
		arg = *(unsigned long *)&dbl_arg;
		push(); // don't combine this with the push() below - Lcc bug
	    }
	    else {
		/* C_FLOAT */
		flt_arg = (float)dbl_arg;
		arg = *(unsigned long *)&flt_arg;
		push();
	    }
	}
	else {
	    /* push 4-byte integer */
	    if (size >= E_INTEGER) {
		if (IS_ATOM_INT(next_arg)) {
		    if (size == E_SEQUENCE)
			RTFatal("passing an integer where a sequence is required");
		}
		else {
		    if (IS_SEQUENCE(next_arg)) {
			if (size != E_SEQUENCE && size != E_OBJECT)
			    RTFatal("passing a sequence where an atom is required");
		    }
		    else {
			if (size == E_SEQUENCE)
			    RTFatal("passing an atom where a sequence is required");
		    }
		    RefDS(next_arg);
		}
		arg = next_arg;
		push();
	    }
	    else if (IS_ATOM_INT(next_arg)) {
		arg = next_arg;
		push();
	    }
	    else if (IS_ATOM(next_arg)) {
		// atoms are rounded to integers

		arg = (unsigned long)DBL_PTR(next_arg)->dbl; //correct
		// if it's a -ve f.p. number, Watcom converts it to int and
		// then to unsigned int. This is exactly what we want.
		// Works with the others too.
		push();
	    }
	    else {
		arg = arg+argsize+9999; // just a marker for asm code
		RTFatal("arguments to C routines must be atoms");
	    }
	}
    }

    // Make the Call - The C compiler thinks it's a 0-argument call

    // might be VOID C routine, but shouldn't crash

    if (return_type == C_DOUBLE) {
	// expect double to be returned from C routine
#if defined(EWINDOWS) && !defined(EWATCOM)
	if (cdecl_call) {
	    dresult = (*((double (  __cdecl *)())int_proc_address))();
	    pop();
	}
	else
#endif
	    dresult = (*((double (__stdcall *)())int_proc_address))();

#ifdef ELINUX
	pop();
#endif
	return NewDouble(dresult);
    }

    else if (return_type == C_FLOAT) {
	// expect float to be returned from C routine
#if defined(EWINDOWS) && !defined(EWATCOM)
	if (cdecl_call) {
	    fresult = (*((float (  __cdecl *)())int_proc_address))();
	    pop();
	}
	else
#endif
	    fresult = (*((float (__stdcall *)())int_proc_address))();

#ifdef ELINUX
	pop();
#endif
	return NewDouble((double)fresult);
    }

    else {
	// expect integer to be returned
#if defined(EWINDOWS) && !defined(EWATCOM)
	if (cdecl_call) {
	    iresult = (*((int (  __cdecl *)())int_proc_address))();
	    pop();
	}
	else
#endif
	    iresult = (*((int (__stdcall *)())int_proc_address))();
#ifdef ELINUX
	pop();
#endif
	if ((return_type & 0x000000FF) == 04) {
	    /* 4-byte integer - usual case */
	    // check if unsigned result is required
	    if ((return_type & C_TYPE) == 0x02000000) {
		// unsigned integer result
		if ((unsigned)iresult <= (unsigned)MAXINT) {
		    return iresult;
		}
		else
		    return NewDouble((double)(unsigned)iresult);
	    }
	    else {
		// signed integer result
		if (return_type >= E_INTEGER ||
		    (iresult >= MININT && iresult <= MAXINT)) {
		    return iresult;
		}
		else
		    return NewDouble((double)iresult);
	    }
	}
	else if (return_type == 0) {
	    return 0; /* void - procedure */
	}
	/* less common cases */
	else if (return_type == C_UCHAR) {
	    return (unsigned char)iresult;
	}
	else if (return_type == C_CHAR) {
	    return (signed char)iresult;
	}
	else if (return_type == C_USHORT) {
	    return (unsigned short)iresult;
	}
	else if (return_type == C_SHORT) {
	    return (short)iresult;
	}
	else
	    return 0; // unknown function return type
    }
}