| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2018-02-07 14:13:13 +00:00
										 |  |  |     Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved. | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |     modification, are permitted provided that the following conditions | 
					
						
							|  |  |  |     are met: | 
					
						
							|  |  |  |     1. Redistributions of source code must retain the above copyright | 
					
						
							|  |  |  |        notice, this list of conditions and the following disclaimer. | 
					
						
							|  |  |  |     2. Redistributions in binary form must reproduce the above copyright | 
					
						
							|  |  |  |        notice, this list of conditions and the following disclaimer in the | 
					
						
							|  |  |  |        documentation and/or other materials provided with the distribution. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR | 
					
						
							|  |  |  |     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
					
						
							|  |  |  |     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 
					
						
							|  |  |  |     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 
					
						
							|  |  |  |     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 
					
						
							|  |  |  |     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
					
						
							|  |  |  |     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
					
						
							|  |  |  |     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
					
						
							|  |  |  |     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 
					
						
							|  |  |  |     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | #include "hak-prv.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-03 21:52:32 +09:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | #define PRINT_STACK_ALIGN 128
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | enum | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PRINT_STACK_CONS, | 
					
						
							|  |  |  | 	PRINT_STACK_ARRAY, | 
					
						
							|  |  |  | 	PRINT_STACK_ARRAY_END, | 
					
						
							|  |  |  | 	PRINT_STACK_DIC, | 
					
						
							|  |  |  | 	PRINT_STACK_DIC_END | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct print_stack_t print_stack_t; | 
					
						
							|  |  |  | struct print_stack_t | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int type; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	hak_oop_t obj; | 
					
						
							|  |  |  | 	hak_oop_t obj2; | 
					
						
							|  |  |  | 	hak_oow_t idx; | 
					
						
							|  |  |  | 	hak_oow_t idx2; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | static HAK_INLINE int push (hak_t* hak, print_stack_t* info) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	if (hak->p.s.size >= hak->p.s.capa) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		print_stack_t* tmp; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		hak_oow_t new_capa; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		new_capa = HAK_ALIGN (hak->p.s.capa + 1, PRINT_STACK_ALIGN); | 
					
						
							|  |  |  | 		tmp = (print_stack_t*)hak_reallocmem(hak, hak->p.s.ptr, new_capa * HAK_SIZEOF(*info)); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		if (!tmp) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		hak->p.s.ptr = tmp; | 
					
						
							|  |  |  | 		hak->p.s.capa = new_capa; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	((print_stack_t*)hak->p.s.ptr)[hak->p.s.size] = *info; | 
					
						
							|  |  |  | 	hak->p.s.size++; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | static HAK_INLINE void pop (hak_t* hak, print_stack_t* info) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 	HAK_ASSERT(hak, hak->p.s.size > 0); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	hak->p.s.size--; | 
					
						
							|  |  |  | 	*info = ((print_stack_t*)hak->p.s.ptr)[hak->p.s.size]; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | enum | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-05-05 04:03:56 +00:00
										 |  |  | 	WORD_UNDEF, | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 	WORD_NIL, | 
					
						
							|  |  |  | 	WORD_TRUE, | 
					
						
							|  |  |  | 	WORD_FALSE, | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 	WORD_SET, | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 	WORD_PRIM, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-05 09:37:26 +00:00
										 |  |  | 	WORD_FUNCTION, | 
					
						
							| 
									
										
										
										
											2024-05-31 15:16:31 +09:00
										 |  |  | 	WORD_BLOCK, | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 	WORD_CONTEXT, | 
					
						
							|  |  |  | 	WORD_PROCESS, | 
					
						
							|  |  |  | 	WORD_PROCESS_SCHEDULER, | 
					
						
							| 
									
										
										
										
											2020-10-15 12:57:05 +00:00
										 |  |  | 	WORD_SEMAPHORE, | 
					
						
							| 
									
										
										
										
											2021-05-21 09:59:35 +00:00
										 |  |  | 	WORD_SEMAPHORE_GROUP, | 
					
						
							| 
									
										
										
										
											2021-05-21 16:21:23 +00:00
										 |  |  | 	WORD_CLASS, | 
					
						
							|  |  |  | 	WORD_INSTANCE | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | static struct | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	hak_oow_t  len; | 
					
						
							|  |  |  | 	hak_ooch_t ptr[20]; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | } word[] = | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-04-04 21:16:28 +09:00
										 |  |  | 	{  8,  { '#','<','U','N','D','E','F','>' } }, | 
					
						
							| 
									
										
										
										
											2024-04-10 19:48:49 +09:00
										 |  |  | 	{  3,  { 'n','i','l' } }, | 
					
						
							| 
									
										
										
										
											2024-04-04 21:16:28 +09:00
										 |  |  | 	{  4,  { 't','r','u','e' } }, | 
					
						
							|  |  |  | 	{  5,  { 'f','a','l','s','e' } }, | 
					
						
							| 
									
										
										
										
											2018-03-02 07:58:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 	{  6,  { '#','<','S','E','T','>' } }, | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 	{  7,  { '#','<','P','R','I','M','>' } }, | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-05 09:37:26 +00:00
										 |  |  | 	{  11, { '#','<','F','U','N','C','T','I','O','N','>' } }, | 
					
						
							| 
									
										
										
										
											2024-05-31 15:16:31 +09:00
										 |  |  | 	{  8,  { '#','<','B','L','O','C','K','>' } }, | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 	{  10, { '#','<','C','O','N','T','E','X','T','>' } }, | 
					
						
							|  |  |  | 	{  10, { '#','<','P','R','O','C','E','S','S','>' } }, | 
					
						
							|  |  |  | 	{  20, { '#','<','P','R','O','C','E','S','S','-','S','C','H','E','D','U','L','E','R','>' } }, | 
					
						
							| 
									
										
										
										
											2020-10-15 12:57:05 +00:00
										 |  |  | 	{  12, { '#','<','S','E','M','A','P','H','O','R','E','>' } }, | 
					
						
							| 
									
										
										
										
											2021-05-21 09:59:35 +00:00
										 |  |  | 	{  18, { '#','<','S','E','M','A','P','H','O','R','E','-','G','R','O','U','P','>' } }, | 
					
						
							| 
									
										
										
										
											2021-05-21 16:21:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	{  8,  { '#','<','C','L','A','S','S','>' } }, | 
					
						
							|  |  |  | 	{  11, { '#','<','I','N','S','T','A','N','C','E','>' } } | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | static HAK_INLINE int print_single_char (hak_t* hak, hak_fmtout_t* fmtout, hak_ooch_t ch) | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	hak_oochu_t chu = (hak_oochu_t)ch; | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 	if (chu == '\\' || chu == '\"') | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		if (hak_bfmt_out(hak, fmtout, "\\%jc", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-29 04:47:03 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | #if defined(HAK_OOCH_IS_UCH)
 | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 	else if (chu < ' ') | 
					
						
							| 
									
										
										
										
											2018-02-28 10:17:05 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 	else if (chu < ' ' || chu >= 0x80) | 
					
						
							| 
									
										
										
										
											2018-02-28 10:17:05 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		hak_oochu_t escaped; | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-28 10:17:05 +00:00
										 |  |  | 		switch (chu) | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			case '\0': | 
					
						
							|  |  |  | 				escaped = '0'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\n': | 
					
						
							|  |  |  | 				escaped = 'n'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\r': | 
					
						
							|  |  |  | 				escaped = 'r'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\t': | 
					
						
							|  |  |  | 				escaped = 't'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\f': | 
					
						
							|  |  |  | 				escaped = 'f'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\b': | 
					
						
							|  |  |  | 				escaped = 'b'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\v': | 
					
						
							|  |  |  | 				escaped = 'v'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\a': | 
					
						
							|  |  |  | 				escaped = 'a'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 				escaped = chu; | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 		if (escaped == chu) | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		#if (HAK_SIZEOF_OOCH_T >= 4)
 | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 			if (chu >= 0x10000u) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-10-08 23:38:24 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "\\U%08X", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 		#endif
 | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		#if (HAK_SIZEOF_OOCH_T >= 2)
 | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 				if (chu >= 0x100u) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, "\\u%04X", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 		#endif
 | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, "\\x%02X", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-01 08:56:56 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, "\\%jc", escaped) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		if (hak_bfmt_out(hak, fmtout, "%jc", ch) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-17 15:42:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | static HAK_INLINE int print_single_byte_char (hak_t* hak, hak_fmtout_t* fmtout, hak_bch_t ch) | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	hak_bchu_t chu = (hak_bchu_t)ch; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 	if (chu == '\\' || chu == '\"') | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		if (hak_bfmt_out(hak, fmtout, "\\%hc", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | #if defined(HAK_OOCH_IS_UCH)
 | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 	else if (chu < ' ') | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	else if (chu < ' ' || chu >= 0x80) | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		hak_bchu_t escaped; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		switch (chu) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			case '\0': | 
					
						
							|  |  |  | 				escaped = '0'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\n': | 
					
						
							|  |  |  | 				escaped = 'n'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\r': | 
					
						
							|  |  |  | 				escaped = 'r'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\t': | 
					
						
							|  |  |  | 				escaped = 't'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\f': | 
					
						
							|  |  |  | 				escaped = 'f'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\b': | 
					
						
							|  |  |  | 				escaped = 'b'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\v': | 
					
						
							|  |  |  | 				escaped = 'v'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case '\a': | 
					
						
							|  |  |  | 				escaped = 'a'; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				escaped = chu; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (escaped == chu) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, "\\x%02X", chu) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, "\\%hc", escaped) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		if (hak_bfmt_out(hak, fmtout, "%hc", ch) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | int hak_fmt_object (hak_t* hak, hak_fmtout_t* fmtout, hak_oop_t obj) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	hak_oop_t cur; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	print_stack_t ps; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	hak_oop_class_t _class; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 	int brand; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 	int word_index; | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	int json; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	static const hak_bch_t *opening_parens[][2] = | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2024-03-10 22:38:01 +09:00
										 |  |  | 		                            /* navtive   json */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		HAK_AID(HAK_CONCODE_XLIST)     { "(",     "(" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_MLIST)     { "(",     "(" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_ALIST)     { "(",     "(" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_BLIST)     { "(",     "(" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_BLOCK)     { "{",     "{" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_ARRAY)     { "#[",    "[" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_BYTEARRAY) { "#b[",   "[" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_CHARARRAY) { "#c[",   "[" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_DIC)       { "#{",    "{" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_QLIST)     { "#(",    "[" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_TUPLE)     { "[",     "[" } | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	static const hak_bch_t *closing_parens[][2] = | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		HAK_AID(HAK_CONCODE_XLIST)     { ")",     ")" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_MLIST)     { ")",     ")" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_ALIST)     { ")",     ")" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_BLIST)     { ")",     ")" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_BLOCK)     { "}",     "}" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_ARRAY)     { "]",     "]" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_BYTEARRAY) { "]",     "]" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_CHARARRAY) { "]",     "]" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_DIC)       { "}",     "}" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_QLIST)     { ")",     "]" }, | 
					
						
							|  |  |  | 		HAK_AID(HAK_CONCODE_TUPLE)     { "]",     "]" } | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	static const hak_bch_t* breakers[][2] = | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2022-01-14 16:09:52 +00:00
										 |  |  | 		{ " ",       "," }, /* item breaker */ | 
					
						
							|  |  |  | 		{ " ",       ":" }  /* key value breaker */ | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	json = !!(fmtout->mask & HAK_LOG_PREFER_JSON); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | next: | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	_class = (hak_oop_class_t)HAK_CLASSOF(hak, obj); | 
					
						
							|  |  |  | 	brand = HAK_OOP_TO_SMOOI(_class->ibrand); | 
					
						
							| 
									
										
										
										
											2024-09-20 03:14:48 +09:00
										 |  |  | 	switch (brand) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_SMOOI: | 
					
						
							|  |  |  | 			if (hak_bfmt_out(hak, fmtout, "%zd", HAK_OOP_TO_SMOOI(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 			goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_SMPTR: | 
					
						
							|  |  |  | 			if (hak_bfmt_out(hak, fmtout, "#p%zX", (hak_oow_t)HAK_OOP_TO_SMPTR(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 			goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_ERROR: | 
					
						
							|  |  |  | 			if (hak_bfmt_out(hak, fmtout, "#e%zd", (hak_ooi_t)HAK_OOP_TO_ERROR(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 			goto done; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_CHARACTER: | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_ooch_t ch = HAK_OOP_TO_CHAR(obj); | 
					
						
							|  |  |  | 			if (hak_bfmt_out(hak, fmtout, "\'") <= -1 || | 
					
						
							|  |  |  | 			    print_single_char(hak, fmtout, ch) <= -1 || | 
					
						
							|  |  |  | 			    hak_bfmt_out(hak, fmtout, "\'") <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-23 07:17:23 +00:00
										 |  |  | 			goto done; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_UNDEF: | 
					
						
							| 
									
										
										
										
											2022-05-05 04:03:56 +00:00
										 |  |  | 			word_index = WORD_UNDEF; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_NIL: | 
					
						
							| 
									
										
										
										
											2018-04-06 08:33:25 +00:00
										 |  |  | 			word_index = WORD_NIL; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_TRUE: | 
					
						
							| 
									
										
										
										
											2018-04-06 08:33:25 +00:00
										 |  |  | 			word_index = WORD_TRUE; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_FALSE: | 
					
						
							| 
									
										
										
										
											2018-04-06 08:33:25 +00:00
										 |  |  | 			word_index = WORD_FALSE; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			goto print_word; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_PBIGINT: | 
					
						
							|  |  |  | 		case HAK_BRAND_NBIGINT: | 
					
						
							| 
									
										
										
										
											2018-02-13 16:10:41 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_oop_t tmp; | 
					
						
							| 
									
										
										
										
											2018-02-15 08:05:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			/* -1 to drive hak_inttostr() to not create a new string object.
 | 
					
						
							| 
									
										
										
										
											2018-02-15 08:05:48 +00:00
										 |  |  | 			 * not using the object memory. the result stays in the temporary | 
					
						
							|  |  |  | 			 * buffer */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			tmp = hak_inttostr(hak, obj, 10 | HAK_INTTOSTR_NONEWOBJ); | 
					
						
							| 
									
										
										
										
											2018-02-15 08:05:48 +00:00
										 |  |  | 			if (!tmp) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 			HAK_ASSERT(hak, (hak_oop_t)tmp == hak->_nil); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, "%.*js", hak->inttostr.xbuf.len, hak->inttostr.xbuf.ptr) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-02-13 16:10:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_FPDEC: | 
					
						
							| 
									
										
										
										
											2018-03-28 08:57:49 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_oop_fpdec_t f = (hak_oop_fpdec_t)obj; | 
					
						
							|  |  |  | 			hak_ooi_t scale; | 
					
						
							| 
									
										
										
										
											2018-03-28 08:57:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			scale = HAK_OOP_TO_SMOOI(f->scale); | 
					
						
							| 
									
										
										
										
											2018-03-28 08:57:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (f->value == HAK_SMOOI_TO_OOP(0)) | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				if (scale == 0) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, "0.") <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, "0.%0*d", scale, 0) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				hak_oop_t tmp; | 
					
						
							|  |  |  | 				hak_oow_t len, adj; | 
					
						
							| 
									
										
										
										
											2018-03-28 08:57:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				tmp = hak_inttostr(hak, f->value, 10 | HAK_INTTOSTR_NONEWOBJ); | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 				if (!tmp) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				adj = (hak->inttostr.xbuf.ptr[0] == '-'); | 
					
						
							|  |  |  | 				len = hak->inttostr.xbuf.len - adj; | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if (len <= scale) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					if (scale == len) | 
					
						
							|  |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 						if (hak_bfmt_out(hak, fmtout, "%.*js0.%.*js", | 
					
						
							|  |  |  | 							adj, hak->inttostr.xbuf.ptr, | 
					
						
							|  |  |  | 							len, &hak->inttostr.xbuf.ptr[adj]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 						if (hak_bfmt_out(hak, fmtout, "%.*js0.%0*d%.*js", | 
					
						
							|  |  |  | 							adj, hak->inttostr.xbuf.ptr, | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 							scale - len, 0, | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 							len, &hak->inttostr.xbuf.ptr[adj]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					hak_ooi_t ndigits; | 
					
						
							|  |  |  | 					ndigits = hak->inttostr.xbuf.len - scale; | 
					
						
							|  |  |  | 					if (hak_bfmt_out(hak, fmtout, "%.*js.%.*js", ndigits, hak->inttostr.xbuf.ptr, scale, &hak->inttostr.xbuf.ptr[ndigits]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-30 15:43:09 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-28 08:57:49 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_REAL: | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			qse_char_t buf[256]; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak->prm.sprintf ( | 
					
						
							|  |  |  | 				hak->prm.ctx, | 
					
						
							|  |  |  | 				buf, HAK_COUNTOF(buf), | 
					
						
							|  |  |  | 				HAK_T("%Lf"), | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			#ifdef __MINGW32__
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				(double)HAK_RVAL(obj) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			#else
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				(long double)HAK_RVAL(obj) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			#endif
 | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 			OUTPUT_STR(hak, buf); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_SYMBOL: | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			/* Any needs for special action if SYNT(obj) is true?
 | 
					
						
							|  |  |  | 			 * I simply treat the syntax symbol as a normal symbol | 
					
						
							|  |  |  | 			 * for printing currently. */ | 
					
						
							| 
									
										
										
										
											2024-09-05 01:12:20 +09:00
										 |  |  | 			/* TODO: escaping if needed */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			/*if (hak_bfmt_out(hak, fmtout, "#\"%.*js\"", HAK_OBJ_GET_SIZE(obj), HAK_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1;*/ | 
					
						
							|  |  |  | 			if (hak_bfmt_out(hak, fmtout, "%.*js", HAK_OBJ_GET_SIZE(obj), HAK_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_STRING: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_ooch_t ch; | 
					
						
							|  |  |  | 			hak_oow_t i; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			int escape = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			for (i = 0; i < HAK_OBJ_GET_SIZE(obj); i++) | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				ch = ((hak_oop_char_t)obj)->slot[i]; | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				if (ch < ' ' || ch == '\"' || ch == '\\') | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					escape = 1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (escape) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "\"") <= -1) return -1; | 
					
						
							|  |  |  | 				for (i = 0; i < HAK_OBJ_GET_SIZE(obj); i++) | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					ch = ((hak_oop_char_t)obj)->slot[i]; | 
					
						
							|  |  |  | 					if (print_single_char(hak, fmtout, ch) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "\"") <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "\"%.*js\"", HAK_OBJ_GET_SIZE(obj), HAK_OBJ_GET_CHAR_SLOT(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_BYTE_STRING: | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_bch_t ch; | 
					
						
							|  |  |  | 			hak_oow_t i; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 			int escape = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			for (i = 0; i < HAK_OBJ_GET_SIZE(obj); i++) | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				ch = ((hak_oop_byte_t)obj)->slot[i]; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 				if (ch < ' ' || ch == '\"' || ch == '\\') | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					escape = 1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (escape) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "b\"") <= -1) return -1; | 
					
						
							|  |  |  | 				for (i = 0; i < HAK_OBJ_GET_SIZE(obj); i++) | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					ch = ((hak_oop_byte_t)obj)->slot[i]; | 
					
						
							|  |  |  | 					if (print_single_byte_char(hak, fmtout, ch) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "\"") <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "b\"%.*hs\"", HAK_OBJ_GET_SIZE(obj), HAK_OBJ_GET_BYTE_SLOT(obj)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-09-07 00:39:46 +09:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_CONS: | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-02-06 10:16:01 +00:00
										 |  |  | 			int concode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 			/* this part is to print a linked list of cells. ignore the
 | 
					
						
							|  |  |  | 			 * request to output in the json format */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			concode = HAK_OBJ_GET_FLAGS_CONCODE(obj); | 
					
						
							|  |  |  | 			if (hak_bfmt_out(hak, fmtout, opening_parens[concode][0]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			cur = obj; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-06 13:15:15 +09:00
										 |  |  | 			/* TODO: for MLIST, print : after the first element.
 | 
					
						
							|  |  |  | 			 *       for ALIST, print := after the first element */ | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			do | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int x; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				/* Push what to print next on to the stack
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				 * the variable p is */ | 
					
						
							|  |  |  | 				ps.type = PRINT_STACK_CONS; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				ps.obj = HAK_CONS_CDR(cur); | 
					
						
							| 
									
										
										
										
											2018-02-12 16:51:38 +00:00
										 |  |  | 				ps.idx = concode; /* this is not an index but use this field to restore concode */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				x = push(hak, &ps); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				obj = HAK_CONS_CAR(cur); | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				/* Jump to the 'next' label so that the object
 | 
					
						
							|  |  |  | 				 * pointed to by 'obj' is printed. Once it | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				 * ends, a jump back to the 'resume' label | 
					
						
							|  |  |  | 				 * is made at the at of this function. */ | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				goto next; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			resume_cons: | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				HAK_ASSERT(hak, ps.type == PRINT_STACK_CONS); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				cur = ps.obj; /* Get back the CDR pushed */ | 
					
						
							| 
									
										
										
										
											2018-02-12 16:51:38 +00:00
										 |  |  | 				concode = ps.idx; /* restore the concode */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (HAK_IS_NIL(hak,cur)) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					/* The CDR part points to a NIL object, which
 | 
					
						
							|  |  |  | 					 * indicates the end of a list. break the loop */ | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (!HAK_OOP_IS_POINTER(cur) || HAK_OBJ_GET_CLASS(cur) != (hak_oop_t)hak->c_cons) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					/* The CDR part does not point to a pair. */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, " . ") <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					/* Push NIL so that the HAK_IS_NIL(hak,p) test in
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 					 * the 'if' statement above breaks the loop | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 					 * after the jump is maded back to the 'resume' | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 					 * label. */ | 
					
						
							|  |  |  | 					ps.type = PRINT_STACK_CONS; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					ps.obj = hak->_nil; | 
					
						
							|  |  |  | 					x = push(hak, &ps); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 					if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					/* Make a jump to 'next' to print the CDR part */ | 
					
						
							|  |  |  | 					obj = cur; | 
					
						
							|  |  |  | 					goto next; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* The CDR part points to a pair. proceed to it */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, breakers[0][0]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			while (1); | 
					
						
							| 
									
										
										
										
											2018-02-06 10:16:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, closing_parens[concode][0]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_ARRAY: | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_oow_t arridx; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, opening_parens[HAK_CONCODE_ARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (HAK_OBJ_GET_SIZE(obj) <= 0) | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, closing_parens[HAK_CONCODE_ARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			arridx = 0; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			ps.type = PRINT_STACK_ARRAY; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			do | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int x; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				/* Push what to print next on to the stack */ | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				ps.idx = arridx + 1; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (ps.idx >= HAK_OBJ_GET_SIZE(obj)) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					ps.type = PRINT_STACK_ARRAY_END; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 					HAK_ASSERT(hak, ps.type == PRINT_STACK_ARRAY); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 					ps.obj = obj; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				x = push(hak, &ps); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				obj = ((hak_oop_oop_t)obj)->slot[arridx]; | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				if (arridx > 0) | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, breakers[0][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				/* Jump to the 'next' label so that the object
 | 
					
						
							|  |  |  | 				 * pointed to by 'obj' is printed. Once it | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				 * ends, a jump back to the 'resume' label | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				 * is made at the end of this function. */ | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				goto next; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			resume_array: | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				HAK_ASSERT(hak, ps.type == PRINT_STACK_ARRAY); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 				arridx = ps.idx; | 
					
						
							|  |  |  | 				obj = ps.obj; | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			while (1); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_BYTE_ARRAY: | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_oow_t i; | 
					
						
							|  |  |  | 			if (hak_bfmt_out(hak, fmtout, opening_parens[HAK_CONCODE_BYTEARRAY][json]) <= -1) return -1; | 
					
						
							|  |  |  | 			if (HAK_OBJ_GET_SIZE(obj) > 0) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "%d", ((hak_oop_byte_t)obj)->slot[0]) <= -1) return -1; | 
					
						
							|  |  |  | 				for (i = 1; i < HAK_OBJ_GET_SIZE(obj); i++) | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, "%hs%d", breakers[0][json], ((hak_oop_byte_t)obj)->slot[i]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-03-02 07:44:13 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, closing_parens[HAK_CONCODE_BYTEARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_CHARACTER_ARRAY: | 
					
						
							| 
									
										
										
										
											2025-08-07 01:24:58 +09:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_oow_t i; | 
					
						
							|  |  |  | 			if (hak_bfmt_out(hak, fmtout, opening_parens[HAK_CONCODE_CHARARRAY][json]) <= -1) return -1; | 
					
						
							|  |  |  | 			if (HAK_OBJ_GET_SIZE(obj) > 0) | 
					
						
							| 
									
										
										
										
											2025-08-07 01:24:58 +09:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, "'%jc'", ((hak_oop_char_t)obj)->slot[0]) <= -1) return -1; | 
					
						
							|  |  |  | 				for (i = 1; i < HAK_OBJ_GET_SIZE(obj); i++) | 
					
						
							| 
									
										
										
										
											2025-08-07 01:24:58 +09:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, "%hs'%jc'", breakers[0][json], ((hak_oop_char_t)obj)->slot[i]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2025-08-07 01:24:58 +09:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, closing_parens[HAK_CONCODE_CHARARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2025-08-07 01:24:58 +09:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_DIC: | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_oow_t bucidx, bucsize, buctally; | 
					
						
							|  |  |  | 			hak_oop_dic_t dic; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, opening_parens[HAK_CONCODE_DIC][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			dic = (hak_oop_dic_t)obj; | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 			HAK_ASSERT(hak, HAK_OOP_IS_SMOOI(dic->tally)); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (HAK_OOP_TO_SMOOI(dic->tally) <= 0) | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, closing_parens[HAK_CONCODE_DIC][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			bucidx = 0; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			bucsize = HAK_OBJ_GET_SIZE(dic->bucket); | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 			buctally = 0; | 
					
						
							|  |  |  | 			ps.type = PRINT_STACK_DIC; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			ps.obj2 = (hak_oop_t)dic; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			do | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				int x; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if ((buctally & 1) == 0) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					while (bucidx < bucsize) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						/* skip an unoccupied slot in the bucket array */ | 
					
						
							|  |  |  | 						obj = dic->bucket->slot[bucidx]; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 						if (!HAK_IS_NIL(hak,obj)) break; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 						bucidx++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (bucidx >= bucsize) | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						/* done. scanned the entire bucket */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 						if (hak_bfmt_out(hak, fmtout, closing_parens[HAK_CONCODE_DIC][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					ps.idx = bucidx; /* no increment yet */ | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 					HAK_ASSERT(hak, ps.idx < bucsize); | 
					
						
							|  |  |  | 					HAK_ASSERT(hak, ps.type == PRINT_STACK_DIC); | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					ps.obj = dic->bucket->slot[ps.idx]; | 
					
						
							|  |  |  | 					ps.idx2 = buctally + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 					x = push(hak, &ps); | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 					if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 					HAK_ASSERT(hak, HAK_IS_CONS(hak,obj)); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					obj = HAK_CONS_CAR(obj); | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					/* Push what to print next on to the stack */ | 
					
						
							|  |  |  | 					ps.idx = bucidx + 1; | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 					if (ps.idx >= bucsize) | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 					{ | 
					
						
							|  |  |  | 						ps.type = PRINT_STACK_DIC_END; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 						HAK_ASSERT(hak, ps.type == PRINT_STACK_DIC); | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 						ps.obj = dic->bucket->slot[ps.idx]; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					ps.idx2 = buctally + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 					x = push(hak, &ps); | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 					if (x <= -1) return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 					HAK_ASSERT(hak, HAK_IS_CONS(hak,obj)); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					obj = HAK_CONS_CDR(obj); | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				if (buctally > 0) | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					if (hak_bfmt_out(hak, fmtout, breakers[buctally & 1][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				/* Jump to the 'next' label so that the object
 | 
					
						
							|  |  |  | 				 * pointed to by 'obj' is printed. Once it | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				 * ends, a jump back to the 'resume' label | 
					
						
							|  |  |  | 				 * is made at the end of this function. */ | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 				goto next; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			resume_dic: | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				HAK_ASSERT(hak, ps.type == PRINT_STACK_DIC); | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				bucidx = ps.idx; | 
					
						
							|  |  |  | 				buctally = ps.idx2; | 
					
						
							|  |  |  | 				obj = ps.obj; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				dic = (hak_oop_dic_t)ps.obj2; | 
					
						
							|  |  |  | 				bucsize = HAK_OBJ_GET_SIZE(dic->bucket); | 
					
						
							| 
									
										
										
										
											2023-11-10 00:03:03 +09:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 			while (1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_PRIM: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_PRIM; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-06 17:49:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_FUNCTION: | 
					
						
							| 
									
										
										
										
											2020-10-05 09:37:26 +00:00
										 |  |  | 			word_index = WORD_FUNCTION; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_BLOCK: | 
					
						
							| 
									
										
										
										
											2024-05-31 15:16:31 +09:00
										 |  |  | 			word_index = WORD_BLOCK; | 
					
						
							| 
									
										
										
										
											2020-10-09 07:14:32 +00:00
										 |  |  | 			goto print_word; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_CONTEXT: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_CONTEXT; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_PROCESS: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_PROCESS; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_PROCESS_SCHEDULER: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_PROCESS_SCHEDULER; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_SEMAPHORE: | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			word_index = WORD_SEMAPHORE; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							| 
									
										
										
										
											2016-10-04 17:56:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_SEMAPHORE_GROUP: | 
					
						
							| 
									
										
										
										
											2020-10-15 12:57:05 +00:00
										 |  |  | 			word_index = WORD_SEMAPHORE_GROUP; | 
					
						
							|  |  |  | 			goto print_word; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_CLASS: | 
					
						
							| 
									
										
										
										
											2024-07-19 20:50:28 +09:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_oop_class_t _class = (hak_oop_class_t)obj; | 
					
						
							|  |  |  | 			if (HAK_IS_NIL(hak, _class->name)) | 
					
						
							| 
									
										
										
										
											2024-07-19 20:50:28 +09:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				word_index = WORD_CLASS; | 
					
						
							|  |  |  | 				goto print_word; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 			HAK_ASSERT(hak, HAK_IS_SYMBOL(hak, _class->name)); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, "%.*js", HAK_OBJ_GET_SIZE(_class->name), HAK_OBJ_GET_CHAR_SLOT(_class->name)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-07-19 20:50:28 +09:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-21 09:59:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		case HAK_BRAND_INSTANCE: | 
					
						
							| 
									
										
										
										
											2024-07-19 20:50:28 +09:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			hak_oop_class_t _class = (hak_oop_class_t)HAK_CLASSOF(hak, obj); | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 			HAK_ASSERT(hak, HAK_IS_CLASS(hak, _class)); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (HAK_IS_NIL(hak, _class->name)) | 
					
						
							| 
									
										
										
										
											2024-07-19 20:50:28 +09:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				word_index = WORD_INSTANCE; | 
					
						
							|  |  |  | 				goto print_word; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 			HAK_ASSERT(hak, HAK_IS_SYMBOL(hak, _class->name)); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, "#INSTANCE OF %.*js", HAK_OBJ_GET_SIZE(_class->name), HAK_OBJ_GET_CHAR_SLOT(_class->name)) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2024-07-19 20:50:28 +09:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-21 16:21:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			HAK_DEBUG3 (hak, "Internal error - unknown object brand %d at %s:%d\n", (int)brand, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 			HAK_ASSERT(hak, "Unknown object brand" == HAK_NULL); | 
					
						
							|  |  |  | 			hak_seterrbfmt(hak, HAK_EINTERN, "unknown object brand %d", (int)brand); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		print_word: | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			if (hak_bfmt_out(hak, fmtout, "%.*js", word[word_index].len, word[word_index].ptr) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-05 15:59:32 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | done: | 
					
						
							|  |  |  | 	/* if the printing stack is not empty, we still got more to print */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	while (hak->p.s.size > 0) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 		pop(hak, &ps); | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 		switch (ps.type) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			case PRINT_STACK_CONS: | 
					
						
							|  |  |  | 				goto resume_cons; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case PRINT_STACK_ARRAY: | 
					
						
							|  |  |  | 				goto resume_array; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case PRINT_STACK_ARRAY_END: | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, closing_parens[HAK_CONCODE_ARRAY][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 			case PRINT_STACK_DIC: | 
					
						
							|  |  |  | 				goto resume_dic; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case PRINT_STACK_DIC_END: | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				if (hak_bfmt_out(hak, fmtout, closing_parens[HAK_CONCODE_DIC][json]) <= -1) return -1; | 
					
						
							| 
									
										
										
										
											2018-02-07 10:55:20 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				HAK_DEBUG3 (hak, "Internal error - unknown print stack type %d at %s:%d\n", (int)ps.type, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				hak_seterrbfmt(hak, HAK_EINTERN, "internal error - unknown print stack type %d", (int)ps.type); | 
					
						
							| 
									
										
										
										
											2016-10-01 04:36:48 +00:00
										 |  |  | 				return -1; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 10:54:13 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | int hak_outfmtobj (hak_t* hak, hak_bitmask_t mask, hak_oop_t obj, hak_outbfmt_t outbfmt) | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* the printer stack must be empty. buggy if not. */ | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 	HAK_ASSERT(hak, hak->p.s.size == 0); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	hak->p.e = obj; /* remember the head of the object to print */ | 
					
						
							|  |  |  | 	n = hak_proutbfmt(hak, mask, obj); | 
					
						
							|  |  |  | 	hak->p.e = hak->_nil; /* reset what's remembered */ | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* clear the printing stack if an error has occurred for GC not to keep
 | 
					
						
							|  |  |  | 	 * the objects in the stack */ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	if (n <= -1) hak->p.s.size = 0; | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* the printer stack must get empty when done. buggy if not */ | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 	HAK_ASSERT(hak, hak->p.s.size == 0); | 
					
						
							| 
									
										
										
										
											2016-09-28 14:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return n; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-05-31 10:54:13 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-03-01 05:25:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | int hak_print (hak_t* hak, hak_oop_t obj) | 
					
						
							| 
									
										
										
										
											2018-03-01 05:25:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 	HAK_ASSERT(hak, hak->io.udo_wrtr != HAK_NULL); | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 	/*return hak_outfmtobj(hak, HAK_LOG_APP | HAK_LOG_FATAL, obj);*/ | 
					
						
							|  |  |  | 	return hak_prbfmt(hak, "%O", obj); | 
					
						
							| 
									
										
										
										
											2018-03-01 05:25:09 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | void hak_dumpcnode (hak_t* hak, hak_cnode_t* cnode, int newline) | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | { | 
					
						
							|  |  |  | 	int t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* TODO: this is incomplete function. make it complete */ | 
					
						
							|  |  |  | 	if (cnode) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 		t = HAK_CNODE_GET_TYPE(cnode); | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | 		switch (t) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			case HAK_CNODE_CHARLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_BCHRLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_SYMBOL: | 
					
						
							|  |  |  | 			case HAK_CNODE_DSYMBOL: | 
					
						
							|  |  |  | 			case HAK_CNODE_STRLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_BSTRLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_SYMLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_NUMLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_RADNUMLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_FPDECLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_SMPTRLIT: | 
					
						
							|  |  |  | 			case HAK_CNODE_ERRLIT: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case HAK_CNODE_NIL: | 
					
						
							|  |  |  | 			case HAK_CNODE_TRUE: | 
					
						
							|  |  |  | 			case HAK_CNODE_FALSE: | 
					
						
							|  |  |  | 			case HAK_CNODE_SELF: | 
					
						
							|  |  |  | 			case HAK_CNODE_SUPER: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case HAK_CNODE_CLASS: | 
					
						
							|  |  |  | 			case HAK_CNODE_FUN: | 
					
						
							|  |  |  | 			case HAK_CNODE_DO: | 
					
						
							|  |  |  | 			case HAK_CNODE_IF: | 
					
						
							|  |  |  | 			case HAK_CNODE_ELIF: | 
					
						
							|  |  |  | 			case HAK_CNODE_ELSE: | 
					
						
							|  |  |  | 			case HAK_CNODE_THROW: | 
					
						
							|  |  |  | 			case HAK_CNODE_TRY: | 
					
						
							|  |  |  | 			case HAK_CNODE_CATCH: | 
					
						
							|  |  |  | 			case HAK_CNODE_BREAK: | 
					
						
							|  |  |  | 			case HAK_CNODE_CONTINUE: | 
					
						
							|  |  |  | 			case HAK_CNODE_UNTIL: | 
					
						
							|  |  |  | 			case HAK_CNODE_WHILE: | 
					
						
							|  |  |  | 			case HAK_CNODE_RETURN: | 
					
						
							|  |  |  | 			case HAK_CNODE_REVERT: | 
					
						
							|  |  |  | 			case HAK_CNODE_AND: | 
					
						
							|  |  |  | 			case HAK_CNODE_OR: | 
					
						
							| 
									
										
										
										
											2025-09-21 17:13:47 +09:00
										 |  |  | #if defined(USE_KW_PLUS)
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			case HAK_CNODE_PLUS: | 
					
						
							| 
									
										
										
										
											2025-09-21 17:13:47 +09:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			case HAK_CNODE_SET: | 
					
						
							|  |  |  | 			case HAK_CNODE_SET_R: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			case HAK_CNODE_ELLIPSIS: | 
					
						
							|  |  |  | 			case HAK_CNODE_TRPCOLONS: | 
					
						
							|  |  |  | 			case HAK_CNODE_DBLCOLONS: | 
					
						
							|  |  |  | 			case HAK_CNODE_COLON: | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				hak_logbfmt(hak, HAK_LOG_FATAL, " %.*js ", HAK_CNODE_GET_TOKLEN(cnode), HAK_CNODE_GET_TOKPTR(cnode)); | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			case HAK_CNODE_CONS: | 
					
						
							| 
									
										
										
										
											2024-09-01 16:28:40 +09:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				hak_concode_t cc; | 
					
						
							| 
									
										
										
										
											2024-09-01 16:28:40 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				hak_logbfmt(hak, HAK_LOG_FATAL, " ("); | 
					
						
							|  |  |  | 				hak_dumpcnode(hak, HAK_CNODE_CONS_CAR(cnode), 0); | 
					
						
							| 
									
										
										
										
											2024-09-01 16:28:40 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 				cc = HAK_CNODE_CONS_CONCODE(cnode); | 
					
						
							| 
									
										
										
										
											2024-09-01 16:28:40 +09:00
										 |  |  | 				switch (cc) | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					case HAK_CONCODE_ALIST: | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 						hak_logbfmt(hak, HAK_LOG_FATAL, " := "); | 
					
						
							| 
									
										
										
										
											2024-09-01 16:28:40 +09:00
										 |  |  | 						break; | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 					case HAK_CONCODE_BLIST: | 
					
						
							|  |  |  | 					case HAK_CONCODE_MLIST: | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 						hak_logbfmt(hak, HAK_LOG_FATAL, ":"); | 
					
						
							| 
									
										
										
										
											2024-09-03 12:18:08 +09:00
										 |  |  | 						break; | 
					
						
							| 
									
										
										
										
											2024-09-01 16:28:40 +09:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				hak_dumpcnode(hak, HAK_CNODE_CONS_CDR(cnode),0); | 
					
						
							|  |  |  | 				hak_logbfmt(hak, HAK_LOG_FATAL, ") "); | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2024-09-01 16:28:40 +09:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			case HAK_CNODE_ELIST: | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				hak_logbfmt(hak, HAK_LOG_FATAL, " () ", HAK_CNODE_GET_TOKLEN(cnode), HAK_CNODE_GET_TOKPTR(cnode)); | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 23:58:15 +09:00
										 |  |  | 			case HAK_CNODE_SHELL: | 
					
						
							| 
									
										
										
										
											2025-09-05 10:52:02 +09:00
										 |  |  | 				hak_logbfmt(hak, HAK_LOG_FATAL, " () ", HAK_CNODE_GET_TOKLEN(cnode), HAK_CNODE_GET_TOKPTR(cnode)); | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-28 00:42:01 +09:00
										 |  |  | 	if (newline) hak_logbfmt(hak, HAK_LOG_FATAL, "\n"); | 
					
						
							| 
									
										
										
										
											2023-11-12 21:54:17 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |