Exemple #1
0
void libfunc_typeof(void){
	unsigned n = avm_totalactuals();
	if(n != 1)
		avm_error("one argument expected in 'typeof'!");
	else{
		avm_memcellclear(&retval);
		retval.type = string_m;
		retval.data.strVal = strdup(typeStrings[avm_getactual(0)->type]);
	}
}
Exemple #2
0
/******************LIBRARY FUNCTIONS********************/
void libfunc_print(void){
	unsigned n = avm_totalactuals();
	unsigned i;
	char* s;
	for(i = 0; i < n; ++i){
		s = (char*)avm_tostring(avm_getactual(i));
		puts(s);
		//free(s);												//provlhma me boolean
	}
}
void libfunc_input(void){
	unsigned n=avm_totalactuals();
	if(n!=0){
		avm_error("no argument expected at 'input'");
		return ;
	}
	char* input=malloc(sizeof(char)*100);
	fgets(input,99,stdin);
	avm_memcellclear(&retval);
	retval.type=string_m;
	retval.data.strVal=input;
}
void libfunc_objecttotalmembers(void){
	if(avm_totalactuals()!=1){
		avm_error("one argument  expected at 'objecttotalmembers'");
		return;
	}
	avm_memcell* m =avm_getactual(0);
	if(m==NULL|| m->type!=table_m){
		avm_error("argument of 'objecttotalmemers' must be a table");
		return;
	}
	retval.type=number_m;
	retval.data.numVal=(int)m->data.tableVal->total;
}
void libfunc_print(void){
	unsigned n=avm_totalactuals();
	unsigned i;
	for(i=0;i<n;i++){
		avm_memcell* m=avm_getactual(i);
		char *s=avm_tostring(m);
		if(!s) continue;
		printf("%s",s);
		free(s);
		if(m->type==string_m || m->type==libfunc_m)
			continue;
	}
}
void libfunc_strtonum(void){
	unsigned n=avm_totalactuals();
	avm_memcellclear(&retval);
	if(n==0){
		avm_error("too few arguments for strtonum");
		retval.type=nil_m;
		return;
	}
	avm_memcell* m=avm_getactual(0);
	if(m->type!=string_m){
		avm_error("argument of strtonum must be a string");
		retval.type=nil_m;
		return;
	}
	retval.type=number_m;
	retval.data.numVal=atof(m->data.strVal);
}
void libfunc_argument(void){
	unsigned p_topsp=avm_get_envvalue(topsp+AVM_SAVEDTOPSP_OFFSET);
        avm_memcellclear(&retval);
        unsigned i;
        if(p_topsp>=AVM_STACKSIZE-1-programVarOffset){
                avm_error("'argument' called outside of a function");
                retval.type=nil_m;
        }
	unsigned n=avm_totalactuals();
	if(n!=1){
		avm_error("one argument expected at 'argument'");
		return ;
	}
	avm_memcell* m=avm_getactual(0);
	if(m->type!=number_m){
		avm_error("argument of 'argument' must be a number");
		return;
	}
	int doubletoint=m->data.numVal;
	retval=stack[p_topsp+AVM_STACKENV_SIZE +1 +doubletoint];
}
Exemple #8
0
avm_memcell* avm_getactual(unsigned i){
	assert(i < avm_totalactuals());
	return &stack[topsp + AVM_STACKENV_SIZE + 1 + i];
}