enhanced the main program to show prompt in the interactive mode
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							
								
								
									
										42
									
								
								bin/main.c
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								bin/main.c
									
									
									
									
									
								
							@ -102,7 +102,6 @@ struct xtn_t
 | 
				
			|||||||
	const char* udo_path;
 | 
						const char* udo_path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int vm_running;
 | 
						int vm_running;
 | 
				
			||||||
	int lang_flags;
 | 
					 | 
				
			||||||
	/*hcl_oop_t sym_errstr;*/
 | 
						/*hcl_oop_t sym_errstr;*/
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -388,6 +387,12 @@ static void print_synerr (hcl_t* hcl)
 | 
				
			|||||||
	hcl_logbfmt (hcl, HCL_LOG_STDERR, "\n");
 | 
						hcl_logbfmt (hcl, HCL_LOG_STDERR, "\n");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void show_prompt (hcl_t* hcl, int level)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					/* TODO: different prompt per level */
 | 
				
			||||||
 | 
						hcl_logbfmt (hcl, HCL_LOG_STDOUT, "HCL> ");
 | 
				
			||||||
 | 
						hcl_logbfmt (hcl, HCL_LOG_STDOUT, HCL_NULL); /* flushing */
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static hcl_oop_t execute_in_interactive_mode (hcl_t* hcl)
 | 
					static hcl_oop_t execute_in_interactive_mode (hcl_t* hcl)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -481,6 +486,8 @@ static int on_fed_cnode_in_interactive_mode (hcl_t* hcl, hcl_cnode_t* obj)
 | 
				
			|||||||
	xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl);
 | 
						xtn_t* xtn = (xtn_t*)hcl_getxtn(hcl);
 | 
				
			||||||
	if (hcl_compile(hcl, obj, HCL_COMPILE_CLEAR_CODE | HCL_COMPILE_CLEAR_FNBLK) <= -1) return -1;
 | 
						if (hcl_compile(hcl, obj, HCL_COMPILE_CLEAR_CODE | HCL_COMPILE_CLEAR_FNBLK) <= -1) return -1;
 | 
				
			||||||
	execute_in_interactive_mode (hcl);
 | 
						execute_in_interactive_mode (hcl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						show_prompt (hcl, 0);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -526,7 +533,8 @@ static int feed_loop (hcl_t* hcl, xtn_t* xtn, int verbose)
 | 
				
			|||||||
		goto oops;
 | 
							goto oops;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* [NOTE] it isn't a very nice idea to get this internal data and use it with read_input() */
 | 
						if (is_tty) show_prompt (hcl, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (1)
 | 
						while (1)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (is_tty)
 | 
							if (is_tty)
 | 
				
			||||||
@ -582,7 +590,7 @@ oops:
 | 
				
			|||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//#define DEFAULT_HEAPSIZE (512000ul)
 | 
					/* #define DEFAULT_HEAPSIZE (512000ul) */
 | 
				
			||||||
#define DEFAULT_HEAPSIZE (0ul) /* don't use the pre-allocated heap */
 | 
					#define DEFAULT_HEAPSIZE (0ul) /* don't use the pre-allocated heap */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main (int argc, char* argv[])
 | 
					int main (int argc, char* argv[])
 | 
				
			||||||
@ -599,7 +607,7 @@ int main (int argc, char* argv[])
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
		{ ":heapsize",    '\0' },
 | 
							{ ":heapsize",    '\0' },
 | 
				
			||||||
		{ ":log",         'l'  },
 | 
							{ ":log",         'l'  },
 | 
				
			||||||
		{ ":info",        '\0' },
 | 
							{ "info",         '\0' },
 | 
				
			||||||
		{ ":modlibdirs",  '\0' },
 | 
							{ ":modlibdirs",  '\0' },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		{ HCL_NULL,       '\0' }
 | 
							{ HCL_NULL,       '\0' }
 | 
				
			||||||
@ -691,7 +699,7 @@ int main (int argc, char* argv[])
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((opt.ind + 1) != argc) goto print_usage;
 | 
						if ((opt.ind + 1) != argc && !show_info) goto print_usage;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	hcl = hcl_openstd(HCL_SIZEOF(xtn_t), HCL_NULL);
 | 
						hcl = hcl_openstd(HCL_SIZEOF(xtn_t), HCL_NULL);
 | 
				
			||||||
@ -716,17 +724,11 @@ int main (int argc, char* argv[])
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		hcl_bitmask_t trait = 0;
 | 
							hcl_bitmask_t trait = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (enable_block) xtn->lang_flags |= HCL_TRAIT_LANG_ENABLE_BLOCK;
 | 
					 | 
				
			||||||
		if (nl_terminator) xtn->lang_flags |= HCL_TRAIT_LANG_ENABLE_EOL;;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		/*trait |= HCL_TRAIT_NOGC;*/
 | 
							/*trait |= HCL_TRAIT_NOGC;*/
 | 
				
			||||||
		trait |= HCL_TRAIT_AWAIT_PROCS;
 | 
							trait |= HCL_TRAIT_AWAIT_PROCS;
 | 
				
			||||||
		trait |= xtn->lang_flags;
 | 
							if (enable_block) trait |= HCL_TRAIT_LANG_ENABLE_BLOCK;
 | 
				
			||||||
 | 
							if (nl_terminator) trait |= HCL_TRAIT_LANG_ENABLE_EOL;;
 | 
				
			||||||
		hcl_setoption (hcl, HCL_TRAIT, &trait);
 | 
							hcl_setoption (hcl, HCL_TRAIT, &trait);
 | 
				
			||||||
 | 
					 | 
				
			||||||
		/* disable GC logs */
 | 
					 | 
				
			||||||
		/*trait = ~HCL_LOG_GC;
 | 
					 | 
				
			||||||
		hcl_setoption (hcl, HCL_LOG_MASK, &trait);*/
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (modlibdirs)
 | 
						if (modlibdirs)
 | 
				
			||||||
@ -756,7 +758,6 @@ int main (int argc, char* argv[])
 | 
				
			|||||||
	#endif
 | 
						#endif
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
	memset (&hclcb, 0, HCL_SIZEOF(hclcb));
 | 
						memset (&hclcb, 0, HCL_SIZEOF(hclcb));
 | 
				
			||||||
	hclcb.gc = gc_hcl;
 | 
						hclcb.gc = gc_hcl;
 | 
				
			||||||
	hclcb.vm_startup = vm_startup;
 | 
						hclcb.vm_startup = vm_startup;
 | 
				
			||||||
@ -809,19 +810,6 @@ int main (int argc, char* argv[])
 | 
				
			|||||||
		goto oops;
 | 
							goto oops;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		hcl_ooch_t errstr[] =  { 'E', 'R', 'R', 'S', 'T', 'R' };
 | 
					 | 
				
			||||||
		xtn->sym_errstr = hcl_makesymbol(hcl, errstr, 6);
 | 
					 | 
				
			||||||
		if (!xtn->sym_errstr)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			hcl_logbfmt (hcl, HCL_LOG_STDERR, "ERROR: cannot create the ERRSTR symbol - [%d] %js\n", hcl_geterrnum(hcl), hcl_geterrmsg(hcl));
 | 
					 | 
				
			||||||
			goto oops;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		HCL_OBJ_SET_FLAGS_KERNEL (xtn->sym_errstr, 1);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	*/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* -- from this point onward, any failure leads to jumping to the oops label
 | 
						/* -- from this point onward, any failure leads to jumping to the oops label
 | 
				
			||||||
	 * -- instead of returning -1 immediately. --*/
 | 
						 * -- instead of returning -1 immediately. --*/
 | 
				
			||||||
	set_signal (SIGINT, handle_sigint);
 | 
						set_signal (SIGINT, handle_sigint);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										26
									
								
								lib/fmt.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								lib/fmt.c
									
									
									
									
									
								
							@ -1696,6 +1696,18 @@ hcl_ooi_t hcl_logbfmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_bch_t* fmt, va
 | 
				
			|||||||
		mask |= HCL_LOG_UNTYPED;
 | 
							mask |= HCL_LOG_UNTYPED;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!fmt)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							/* perform flushing only if fmt is NULL */
 | 
				
			||||||
 | 
							if (hcl->log.len > 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len);
 | 
				
			||||||
 | 
								hcl->log.len = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, HCL_NULL, 0); /* forced flushing */
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo));
 | 
						HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo));
 | 
				
			||||||
	fo.fmt_type = HCL_FMTOUT_FMT_TYPE_BCH;
 | 
						fo.fmt_type = HCL_FMTOUT_FMT_TYPE_BCH;
 | 
				
			||||||
	fo.fmt_str = fmt;
 | 
						fo.fmt_str = fmt;
 | 
				
			||||||
@ -1751,6 +1763,19 @@ hcl_ooi_t hcl_logufmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_uch_t* fmt, va
 | 
				
			|||||||
		mask |= HCL_LOG_UNTYPED;
 | 
							mask |= HCL_LOG_UNTYPED;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!fmt)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							/* perform flushing only if fmt is NULL */
 | 
				
			||||||
 | 
							if (hcl->log.len > 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len);
 | 
				
			||||||
 | 
								hcl->log.len = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, HCL_NULL, 0); /* forced flushing */
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo));
 | 
						HCL_MEMSET (&fo, 0, HCL_SIZEOF(fo));
 | 
				
			||||||
	fo.fmt_type = HCL_FMTOUT_FMT_TYPE_UCH;
 | 
						fo.fmt_type = HCL_FMTOUT_FMT_TYPE_UCH;
 | 
				
			||||||
	fo.fmt_str = fmt;
 | 
						fo.fmt_str = fmt;
 | 
				
			||||||
@ -1768,6 +1793,7 @@ hcl_ooi_t hcl_logufmtv (hcl_t* hcl, hcl_bitmask_t mask, const hcl_uch_t* fmt, va
 | 
				
			|||||||
		HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len);
 | 
							HCL_VMPRIM_LOG_WRITE (hcl, hcl->log.last_mask, hcl->log.ptr, hcl->log.len);
 | 
				
			||||||
		hcl->log.len = 0;
 | 
							hcl->log.len = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (x <= -1)? -1: fo.count;
 | 
						return (x <= -1)? -1: fo.count;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								lib/std.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								lib/std.c
									
									
									
									
									
								
							@ -534,10 +534,10 @@ static int write_log (hcl_t* hcl, int fd, const hcl_bch_t* ptr, hcl_oow_t len)
 | 
				
			|||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void flush_log (hcl_t* hcl, int fd)
 | 
					static void flush_log (hcl_t* hcl, int fd, int force)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	xtn_t* xtn = GET_XTN(hcl);
 | 
						xtn_t* xtn = GET_XTN(hcl);
 | 
				
			||||||
	if (xtn->log.out.len > 0)
 | 
						if (xtn->log.out.len > 0 || force)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		write_all (fd, xtn->log.out.buf, xtn->log.out.len);
 | 
							write_all (fd, xtn->log.out.buf, xtn->log.out.len);
 | 
				
			||||||
		xtn->log.out.len = 0;
 | 
							xtn->log.out.len = 0;
 | 
				
			||||||
@ -551,6 +551,7 @@ static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hc
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	xtn_t* xtn = GET_XTN(hcl);
 | 
						xtn_t* xtn = GET_XTN(hcl);
 | 
				
			||||||
	int logfd;
 | 
						int logfd;
 | 
				
			||||||
 | 
						int force_flush = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (mask & HCL_LOG_STDERR) logfd = 2;
 | 
						if (mask & HCL_LOG_STDERR) logfd = 2;
 | 
				
			||||||
	else if (mask & HCL_LOG_STDOUT) logfd = 1;
 | 
						else if (mask & HCL_LOG_STDOUT) logfd = 1;
 | 
				
			||||||
@ -627,6 +628,12 @@ static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hc
 | 
				
			|||||||
		else if (mask & HCL_LOG_WARN) write_log (hcl, logfd, "\x1B[1;33m", 7);
 | 
							else if (mask & HCL_LOG_WARN) write_log (hcl, logfd, "\x1B[1;33m", 7);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!msg)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							force_flush = 1;
 | 
				
			||||||
 | 
							goto flush_log_msg;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(HCL_OOCH_IS_UCH)
 | 
					#if defined(HCL_OOCH_IS_UCH)
 | 
				
			||||||
	msgidx = 0;
 | 
						msgidx = 0;
 | 
				
			||||||
	while (len > 0)
 | 
						while (len > 0)
 | 
				
			||||||
@ -673,7 +680,8 @@ static void log_write (hcl_t* hcl, hcl_bitmask_t mask, const hcl_ooch_t* msg, hc
 | 
				
			|||||||
		if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (hcl, logfd, "\x1B[0m", 4);
 | 
							if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (hcl, logfd, "\x1B[0m", 4);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flush_log (hcl, logfd);
 | 
					flush_log_msg:
 | 
				
			||||||
 | 
						flush_log (hcl, logfd, force_flush);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* -----------------------------------------------------------------
 | 
					/* -----------------------------------------------------------------
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user