Ejemplo n.º 1
0
Code stat_list(Pnode p)
{
    int env_num_vars = 0;
    push_environment();
/*
    stat_list
      /
     /
    stat --> stat --> stat
*/
    Code s = stat(p->child);
    // Scorro gli stats, dal secondo in poi
    for (p = p->child->brother; p != NULL; p = p->brother)
    {
        s = appcode(s, stat(p));
    }

    // Tolgo le variabili dichiarate in questo environment:
    if ((env_num_vars = numobj_in_current_env()) > 0)
    {
        Value v1; v1.ival = env_num_vars;
        s = appcode(s, makecode1(T_POP, v1));
    }
    pop_environment();
    return s;
}
Ejemplo n.º 2
0
static int add_private_name(lua_State * L) {
    int nargs = lua_gettop(L);
    optional<unsigned> h;
    if (nargs > 2)
        h = lua_tonumber(L, 3);
    auto p = add_private_name(to_environment(L, 1), to_name_ext(L, 2), h);
    push_environment(L, p.first);
    push_name(L, p.second);
    return 2;
}
Ejemplo n.º 3
0
/*Genera il codice per il nodo stat_list e crea lo scope del programma*/
Code stat_list(Pnode stat_list_node){
	//Definisco la variabile che contiene il codice da ritornare
	Code stat_list_code;
	stat_list_code.head = NULL;
	stat_list_code.tail = NULL;
	stat_list_code.size = 0;

	//Creo l'ambiente del programma
	push_environment();
	
	//Punto al primo stat
	Pnode stat_node = stat_list_node->child;
	//Ciclo lungo tutti gli stat_node
	while (stat_node!=NULL){
		//Creo il codice dello stat_node
		Code stat_code;
		switch (stat_node->type){
			case(N_DEF_STAT): 	stat_code = def_stat(stat_node);break;
			case(N_ASSIGN_STAT): 	stat_code = assign_stat(stat_node);break;
			case(N_IF_STAT): 	stat_code = if_stat(stat_node);break;
			case(N_WHILE_STAT): 	stat_code = while_stat(stat_node);break;
			case(N_READ_STAT): 	stat_code = read_stat(stat_node);break;
			case(N_WRITE_STAT): 	stat_code = write_stat(stat_node);break;
		}
		
		//Appendo il codice a stat_list_code
		stat_list_code = appcode(stat_list_code,stat_code);

		//Punto al fratello successivo
		stat_node = stat_node->brother;
	}
	
	//Appendo il codice per fare il pop dell'environment a stat_list_code
	if(numobj_in_current_env()!=0)
		stat_list_code = appcode(stat_list_code,makecode1(T_POP,numobj_in_current_env()));

	//elimino l'ambiente creato (elimina già le variabili dall'ambiente)
	pop_environment();

	return stat_list_code;
}
Ejemplo n.º 4
0
static int env(lua_State * L) { return push_environment(L, gparser.env()); }