From 676ba7d746ff4a5af071f16a8c34976129caede7 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 22 Jan 2024 01:38:13 +0900 Subject: [PATCH] added GetTrait() and SetTrait() to go code --- go/hcl.go | 28 +++++++++++++++++++++++++++- main.go | 2 ++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/go/hcl.go b/go/hcl.go index 5ca8e2c..f4d467a 100644 --- a/go/hcl.go +++ b/go/hcl.go @@ -67,6 +67,9 @@ type Ext struct { type BitMask C.hcl_bitmask_t +const TRAIT_LANG_ENABLE_BLOCK BitMask = C.HCL_TRAIT_LANG_ENABLE_BLOCK +const TRAIT_LANG_ENABLE_EOL BitMask = C.HCL_TRAIT_LANG_ENABLE_EOL + var inst_table InstanceTable func deregister_instance(g *HCL) { @@ -109,6 +112,29 @@ func (hcl *HCL) Close() { deregister_instance(hcl) } +func (hcl *HCL) GetTrait() BitMask { + var x C.int + var log_mask BitMask = 0 + + x = C.hcl_getoption(hcl.c, C.HCL_TRAIT, unsafe.Pointer(&log_mask)) + if x <= -1 { + // this must not happen + panic(fmt.Errorf("unable to get log mask - %s", hcl.get_errmsg())) + } + + return log_mask +} + +func (hcl *HCL) SetTrait(log_mask BitMask) { + var x C.int + + x = C.hcl_setoption(hcl.c, C.HCL_TRAIT, unsafe.Pointer(&log_mask)) + if x <= -1 { + // this must not happen + panic(fmt.Errorf("unable to set log mask - %s", hcl.get_errmsg())) + } +} + func (hcl *HCL) GetLogMask() BitMask { var x C.int var log_mask BitMask = 0 @@ -326,7 +352,7 @@ func (hcl *HCL) Execute() error { func (hcl *HCL) Decode() error { var x C.int - x = C.hcl_decode(hcl.c, 0, C.hcl_getbclen(hcl.c)) + x = C.hcl_decode(hcl.c, C.hcl_getcode(hcl.c), 0, C.hcl_getbclen(hcl.c)) if x <= -1 { return fmt.Errorf("unable to decode byte codes - %s", hcl.get_errmsg()) } diff --git a/main.go b/main.go index aba60e2..7b3bad1 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,8 @@ func main() { x.SetLogTarget("/dev/stderr") } + x.SetTrait (x.GetTrait() | hcl.TRAIT_LANG_ENABLE_EOL | hcl.TRAIT_LANG_ENABLE_BLOCK) + err = x.Ignite(1000000) if err != nil { fmt.Printf("Error: failed to ignite - %s\n", err.Error())