change pic_find_rename API
This commit is contained in:
		
							parent
							
								
									8b17e70a43
								
							
						
					
					
						commit
						c10f40acd4
					
				|  | @ -42,7 +42,7 @@ struct pic_senv *pic_minimal_syntactic_env(pic_state *); | |||
| struct pic_senv *pic_core_syntactic_env(pic_state *); | ||||
| 
 | ||||
| pic_sym pic_add_rename(pic_state *, struct pic_senv *, pic_sym); | ||||
| pic_sym pic_find_rename(pic_state *, struct pic_senv *, pic_sym); /* may return 0! */ | ||||
| bool pic_find_rename(pic_state *, struct pic_senv *, pic_sym, pic_sym * /* = NULL */); | ||||
| void pic_put_rename(pic_state *, struct pic_senv *, pic_sym, pic_sym); | ||||
| 
 | ||||
| #if defined(__cplusplus) | ||||
|  |  | |||
|  | @ -51,7 +51,7 @@ static void pop_scope(analyze_state *); | |||
| #define register_renamed_symbol(pic, state, slot, lib, id) do {         \ | ||||
|     pic_sym sym, gsym;                                                  \ | ||||
|     sym = pic_intern_cstr(pic, id);                                     \ | ||||
|     if ((gsym = pic_find_rename(pic, lib->senv, sym)) == 0) {           \ | ||||
|     if (! pic_find_rename(pic, lib->senv, sym, &gsym)) {                \ | ||||
|       pic_error(pic, "internal error! native VM procedure not found");  \ | ||||
|     }                                                                   \ | ||||
|     state->slot = gsym;                                                 \ | ||||
|  |  | |||
							
								
								
									
										24
									
								
								src/macro.c
								
								
								
								
							
							
						
						
									
										24
									
								
								src/macro.c
								
								
								
								
							|  | @ -28,17 +28,20 @@ pic_put_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym renam | |||
|   xh_put(&senv->renames, sym, &rename); | ||||
| } | ||||
| 
 | ||||
| pic_sym | ||||
| pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym) | ||||
| bool | ||||
| pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *rename) | ||||
| { | ||||
|   xh_entry *e; | ||||
| 
 | ||||
|   UNUSED(pic); | ||||
| 
 | ||||
|   if ((e = xh_get(&senv->renames, sym)) == NULL) { | ||||
|     return 0; | ||||
|     return false; | ||||
|   } | ||||
|   return xh_val(e, pic_sym); | ||||
|   if (rename != NULL) { | ||||
|     *rename = xh_val(e, pic_sym); | ||||
|   } | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| static pic_value macroexpand(pic_state *, pic_value, struct pic_senv *); | ||||
|  | @ -160,8 +163,7 @@ pic_export(pic_state *pic, pic_sym sym) | |||
| { | ||||
|   pic_sym rename; | ||||
| 
 | ||||
|   rename = pic_find_rename(pic, pic->lib->senv, sym); | ||||
|   if (rename == 0) { | ||||
|   if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) { | ||||
|     pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym)); | ||||
|   } | ||||
| 
 | ||||
|  | @ -199,7 +201,7 @@ symbol_rename(pic_state *pic, pic_sym sym, struct pic_senv *senv) | |||
|     return sym; | ||||
|   } | ||||
|   while (true) { | ||||
|     if ((rename = pic_find_rename(pic, senv, sym)) != 0) { | ||||
|     if (pic_find_rename(pic, senv, sym, &rename)) { | ||||
|       return rename; | ||||
|     } | ||||
|     if (! senv->up) | ||||
|  | @ -318,7 +320,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv) | |||
|           pic_error(pic, "binding to non-symbol object"); | ||||
|         } | ||||
|         sym = pic_sym(var); | ||||
|         if ((rename = pic_find_rename(pic, senv, sym)) == 0) { | ||||
|         if (! pic_find_rename(pic, senv, sym, &rename)) { | ||||
|           rename = pic_add_rename(pic, senv, sym); | ||||
|         } | ||||
| 
 | ||||
|  | @ -367,7 +369,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv) | |||
| 	  pic_error(pic, "syntax error"); | ||||
| 	} | ||||
|         sym = pic_sym(var); | ||||
|         if ((rename = pic_find_rename(pic, senv, sym)) == 0) { | ||||
|         if (! pic_find_rename(pic, senv, sym, &rename)) { | ||||
|           rename = pic_add_rename(pic, senv, sym); | ||||
|         } | ||||
| 
 | ||||
|  | @ -418,7 +420,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv) | |||
| 	    pic_error(pic, "binding to non-symbol object"); | ||||
| 	  } | ||||
|           sym = pic_sym(a); | ||||
|           if (pic_find_rename(pic, senv, sym) == 0) { | ||||
|           if (! pic_find_rename(pic, senv, sym, NULL)) { | ||||
|             pic_add_rename(pic, senv, sym); | ||||
|           } | ||||
| 
 | ||||
|  | @ -436,7 +438,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv) | |||
| 	  pic_error(pic, "binding to non-symbol object"); | ||||
| 	} | ||||
|         sym = pic_sym(formals); | ||||
|         if (pic_find_rename(pic, senv, sym) == 0) { | ||||
|         if (! pic_find_rename(pic, senv, sym, NULL)) { | ||||
|           pic_add_rename(pic, senv, sym); | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										2
									
								
								src/vm.c
								
								
								
								
							
							
						
						
									
										2
									
								
								src/vm.c
								
								
								
								
							|  | @ -336,7 +336,7 @@ global_ref(pic_state *pic, const char *name) | |||
|   pic_sym sym, rename; | ||||
| 
 | ||||
|   sym = pic_intern_cstr(pic, name); | ||||
|   if ((rename = pic_find_rename(pic, pic->lib->senv, sym)) == 0) { | ||||
|   if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) { | ||||
|     return SIZE_MAX; | ||||
|   } | ||||
|   if (! (e = xh_get(&pic->global_tbl, rename))) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Yuichi Nishiwaki
						Yuichi Nishiwaki