Esempio n. 1
0
OBJ
readNumber(OBJ inStream, char firstChar, int isNegative){
	//printf(YEL "\nreadNumber>" RESET);

	/*
 	* TO-DO refactor!	
 	*/	
	jscheme_int64 *iVal = NULL;
	char ch;
	OBJ retVal;

	// substract the ASCII value of '0' from char to get the actual value between 0 and 9.
	jscheme_int64 start = (jscheme_int64) firstChar - '0';
	if(isNegative) start *= -1;

	iVal = &start;
	while( isDigit( ch = nextChar(inStream) )){
		//iVal = iVal * 10 + ( (int)ch - '0');

		jscheme_int64 ch_val = (jscheme_int64) ch - '0';
		
		if(isNegative){
			int mul = __builtin_smull_overflow(*iVal, 10, iVal);
			int sub = __builtin_ssubl_overflow(*iVal, ch_val, iVal);
			if( mul || sub ){
				if(thisIsTheEnd(inStream)){
					prompt_on();
				}
				js_error("readNumber: integer underflow", newInteger(*iVal));
			}
		}else{
			int mul = __builtin_smull_overflow(*iVal, 10, iVal);
			int add = __builtin_saddl_overflow(*iVal, ch_val, iVal);
			if( mul || add ){
				if(thisIsTheEnd(inStream)){
					prompt_on();
				}
				js_error("readNumber: integer overflow", newInteger(*iVal));
			}
		
		}
	}
	unreadChar(inStream, ch);
	retVal = newInteger( *iVal );
	return retVal;
}
Esempio n. 2
0
VOIDPTRFUNC
CP_jREPL2(){
	
	//fprintf(stdout, "\nStack in CP_jREPL2:\n");
	//printJStack(__FILE__,__LINE__,__FUNCTION__);
	DEBUGCODE(PRINT_STACK->state, printJStack(__FILE__,__LINE__,__FUNCTION__));

	OBJ result = RETVAL;

#ifdef DEBUG
	if( (SP <= 5) || PRINT_INCLUDE->state){
		printIndent(indentLevelForInclude);
#else
	if( (SP <= 5)) {
#endif
		js_print(stdout, result, 1);		// P rint
		printf("\n");
	}
							// L oop
	OBJ inputStream = ARG(0);
	TAILCALL1((VOIDPTRFUNC)CP_jREPL, inputStream);	
}

int
main() {
	initSymbolTable();
	initializeWellKnownObjects();
	initJStack();
#ifdef DEBUG
	initDebugOptions();	
	initGlobalEnvironment();
	setupInitialEnvironment();
	setupBuiltinSyntax();
	selftest();
#endif
	
	printf("hello friend...\n");
	initGlobalEnvironment();
	setupInitialEnvironment();
	printf("Welcome to (JS)cheme\n");

	if( setjmp(whereEverythingWasFine) ){
#ifdef DEBUG
		indentLevel = 0;
		indentLevelForInclude = 0;
#endif
		// reset Stack index
		SP = 0;
		AP = 0;
		BP = 0;
		prompt_on();
		printf("back in wonderland\n");
	}	
	printf("...starting a REPL for you.\n");
	OBJ inputStream = newFileStream(stdin);
	
#ifdef DEBUG
	if(CONTINUATION_PASSING->state){
		CP_setupBuiltinSyntax();
		enterTrampoline1(inputStream);
	}else{
		setupBuiltinSyntax();
		jREPL(inputStream);
	}
#else 
	//jREPL(inputStream);
	CP_setupBuiltinSyntax();
	enterTrampoline1(inputStream);
#endif

	return 0;
}
Esempio n. 3
0
OBJ
js_read(OBJ inStream){

	OBJ retVal;
	prompt_off();
	char ch = skipWhiteSpace(inStream);

	if( ch == -1){
		retVal = js_eof;
		unreadChar(inStream, ch);
	}
	else if(ch == '('){
		retVal = readList(inStream);
	}
	else if(ch =='\''){
		OBJ expr = js_read(inStream);

		// (quote (expr* (nil))) -> expr must be a cons
		return newCons(symbolTableGetOrAdd("quote"), 
				newCons(expr, js_nil));
	}
	else if(ch == '"'){
		retVal = readString(inStream);
	}
	else if(isDigit(ch)){
		retVal = readNumber(inStream, ch, 0);
	
	}else if(ch == '-'){
		/*
		 * TO-DO refactor: implement proper read ahead solution
		 */
		// simple read ahead to catch negative numbers
		char nextCh = nextChar(inStream);
		if(isDigit(nextCh)){
			retVal = readNumber(inStream, nextCh, 1);	
		}else{
			unreadChar(inStream, nextCh);
			retVal = readSymbol(inStream, ch);
		}
	}
#ifdef DEBUG
	else if(ch == '%'){
		ch = nextChar(inStream);
		OBJ debugOption;
		if(ch == '\n' ){
		       	unreadChar(inStream, ch);
			debugOption = newSymbol("");
		}else{
			debugOption = readSymbol(inStream, ch);
		}
		switchDebugOptions( debugOption );
		retVal = js_void;
	}
#endif
	else {
		retVal = readSymbol(inStream, ch);
	}
	
	if(thisIsTheEnd(inStream)){
		prompt_on();
	};

	return retVal;
}
Esempio n. 4
0
File: ball.c Progetto: taysom/tau
int main (int argc, char *argv[])
{
	msg_s	msg;
	ki_t	key;
	int	c;
	int	rc;
	char	*send_color;
	char	*recv_color;
	unint	i;
	unint	n = 1000;
	u64	start = 0;
	u64	finish;

	setprogname(argv[0]);

	while ((c = getopt(argc, argv, "p?")) != -1) {
		switch (c) {
		case 'p':
			prompt_on();
			break;
		default:
			usage();
			break;
		}
	}
	if (argc < optind+2) usage();

	send_color = argv[optind];
	recv_color = argv[optind+1];

	if (argc > optind+2) {
		n = strtoll(argv[optind+2], NULL, 0);
	}

prompt("start");
	if (init_msg_tau(send_color)) {
		exit(2);
	}
prompt("sw_register");
	sw_register(send_color);

prompt("create_gate_tau");
	key = make_gate(0, REQUEST);

prompt("sw_post");
	rc = sw_post(send_color, key);
	if (rc) failure("sw_post", rc);

prompt("sw_any");
	rc = sw_any(recv_color, &key);
	if (rc) failure("sw_any", rc);

	for (i = 0; i < n; i++) {
		if (i == 2) start = nsecs();
prompt("send_tau");
		rc = send_tau(key, &msg);
		if (rc) failure("send_tau", rc);

prompt("receive_tau");
		rc = receive_tau( &msg);
		if (rc) failure("receive", rc);
	}
	finish = nsecs();
	printf("%s %g nsecs per send/receive\n", send_color,
		((double)(finish - start))/(n-2));
	return 0;
}