From f85dd54040f584787256d63e335b92ad5122ef0d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 11 Feb 2024 16:39:16 +0900 Subject: [PATCH] minor code cleanup --- lib/hcl-cmn.h | 2 -- lib/hcl.h | 18 +++++++++--------- pas/hcl.pas | 35 +++++++++++++++++++++++++++++++++-- pas/main.pas | 4 +++- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/lib/hcl-cmn.h b/lib/hcl-cmn.h index 2f3310e..fc1fd6a 100644 --- a/lib/hcl-cmn.h +++ b/lib/hcl-cmn.h @@ -487,8 +487,6 @@ struct hcl_ptlc_t typedef unsigned int hcl_bitmask_t; -typedef unsigned int hcl_bitmask_t; - /* ========================================================================= * BIGINT TYPES AND MACROS * ========================================================================= */ diff --git a/lib/hcl.h b/lib/hcl.h index 07d60ce..0472b54 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -221,24 +221,24 @@ typedef enum hcl_option_dflval_t hcl_option_dflval_t; enum hcl_trait_t { #if defined(HCL_BUILD_DEBUG) - HCL_TRAIT_DEBUG_GC = (1u << 0), - HCL_TRAIT_DEBUG_BIGINT = (1u << 1), + HCL_TRAIT_DEBUG_GC = (((hcl_bitmask_t)1) << 0), + HCL_TRAIT_DEBUG_BIGINT = (((hcl_bitmask_t)1) << 1), #endif - HCL_TRAIT_INTERACTIVE = (1u << 7), + HCL_TRAIT_INTERACTIVE = (((hcl_bitmask_t)1) << 7), /* perform no garbage collection when the heap is full. * you still can use hcl_gc() explicitly. */ - HCL_TRAIT_NOGC = (1u << 8), + HCL_TRAIT_NOGC = (((hcl_bitmask_t)1) << 8), /* wait for running process when exiting from the main method */ - HCL_TRAIT_AWAIT_PROCS = (1u << 9), + HCL_TRAIT_AWAIT_PROCS = (((hcl_bitmask_t)1) << 9), /* return EOL as a token */ /* TODO: make this pragma controllable */ - HCL_TRAIT_LANG_ENABLE_EOL = (1u << 14), + HCL_TRAIT_LANG_ENABLE_EOL = (((hcl_bitmask_t)1) << 14), /* enable block expression as mandatory argument to some expresions */ - HCL_TRAIT_LANG_ENABLE_BLOCK = (1u << 15), + HCL_TRAIT_LANG_ENABLE_BLOCK = (((hcl_bitmask_t)1) << 15), }; typedef enum hcl_trait_t hcl_trait_t; @@ -2331,14 +2331,14 @@ HCL_EXPORT int hcl_print ( HCL_EXPORT hcl_ooi_t hcl_proutbfmt ( hcl_t* hcl, - hcl_bitmask_t mask, + hcl_bitmask_t mask, const hcl_bch_t* fmt, ... ); HCL_EXPORT hcl_ooi_t hcl_proutufmt ( hcl_t* hcl, - hcl_bitmask_t mask, + hcl_bitmask_t mask, const hcl_uch_t* fmt, ... ); diff --git a/pas/hcl.pas b/pas/hcl.pas index bda8ab6..291e325 100644 --- a/pas/hcl.pas +++ b/pas/hcl.pas @@ -9,6 +9,24 @@ unit HCL; interface type + BitMask = longword; (* this must match hcl_bitmask_t in hcl.h *) + +(*const + TRAIT_LANG_ENABLE_EOF = (BitMask(1) shl 14); + TRAIT_LANG_ENABLE_BLOCK = (BitMask(1) shl 15);*) + +type + TraitBit = ( + LANG_ENABLE_EOF = (BitMask(1) shl 14), + LANG_ENABLE_BLOCK = (BitMask(1) shl 15) + ); + + Option = ( + TRAIT, + LOG_MASK, + LOG_MAXCAPA + ); + Interp = class protected handle: pointer; @@ -50,13 +68,17 @@ function hcl_errnum_is_synerr(errnum: integer): boolean; cdecl; external; function hcl_openstd(xtnsize: sizeint; errnum: pointer): pointer; cdecl; external; procedure hcl_close(handle: pointer); cdecl; external; + +function hcl_setoption(handle: pointer; option: Option; value: pointer): integer; cdecl; external; +function hcl_getoption(handle: pointer; option: Option; value: pointer): integer; cdecl; external; + function hcl_geterrnum(handle: pointer): integer; cdecl; external; function hcl_geterrbmsg(handle: pointer): pansichar; cdecl; external; function hcl_ignite(handle: pointer; heapsize: sizeint): integer; cdecl; external; function hcl_addbuiltinprims(handle: pointer): integer; cdecl; external; function hcl_beginfeed(handle: pointer; on_cnode: pointer): integer; cdecl; external; function hcl_feedbchars(handle: pointer; data: pansichar; len: sizeint): integer; cdecl; external; -function hcl_feeduchars(handle: pointer; data: pwidechar; len: sizeint): integer; cdecl; external; (* this is wrong in deed *) +function hcl_feeduchars(handle: pointer; data: pwidechar; len: sizeint): integer; cdecl; external; (* this is wrong in deed - hcl_uchar_t may not been widechar ..*) function hcl_endfeed(handle: pointer): integer; cdecl; external; function hcl_attachcciostdwithbcstr(handle: pointer; cci: pansichar): integer; cdecl; external; @@ -80,10 +102,19 @@ var h: pointer; errnum: integer; errmsg: array[0..255] of AnsiChar; + tb: BitMask; begin + h := hcl_openstd(0, @errnum); if h = nil then begin - hcl_errnum_to_errbcstr (errnum, @errmsg, length(errmsg)); + hcl_errnum_to_errbcstr(errnum, @errmsg, length(errmsg)); + raise Exception.Create(errmsg); + end; + + tb := BitMask(TraitBit.LANG_ENABLE_EOF) or BitMask(TraitBit.LANG_ENABLE_BLOCK); + if hcl_setoption(h, Option.TRAIT, @tb) <= -1 then begin + hcl_errnum_to_errbcstr(errnum, @errmsg, length(errmsg)); + hcl_close(h); raise Exception.Create(errmsg); end; self.handle := h; diff --git a/pas/main.pas b/pas/main.pas index 42950f2..ff1a731 100644 --- a/pas/main.pas +++ b/pas/main.pas @@ -18,7 +18,9 @@ begin x.Compile(pwidechar('(printf "hello 동키콩\n")')); x.Compile('(printf "hello 동키콩월드\n") '); x.Compile('(동가리오 := 20)'); - x.Compile('(printf "%d %d\n" 동가리오 (* 동가리오 동가리오))'); + x.Compile('(printf "%d %d\n" 동가리오 (+ 동가리오 동가리오))'); + + x.Compile(pwidechar('(printf "%d %d\n" 동가리오 (동가리오 * 동가리오))'#10'printf "hello, world\n";;;'#10)); x.Execute(); // check if exception... except