2023-10-27 09:20:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -I/home/hyung-hwan/xxx/include -g -Wall
|
|
|
|
#cgo LDFLAGS: -L/home/hyung-hwan/xxx/lib -lhcl -ldl -lquadmath
|
|
|
|
|
|
|
|
#include <hcl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
extern int go_read_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg);
|
|
|
|
extern int go_scan_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg);
|
|
|
|
extern int go_print_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg);
|
|
|
|
|
|
|
|
int read_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg)
|
|
|
|
{
|
|
|
|
return go_read_handler(hcl, cmd, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int scan_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg)
|
|
|
|
{
|
|
|
|
return go_scan_handler(hcl, cmd, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int print_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg)
|
|
|
|
{
|
|
|
|
return go_print_handler(hcl, cmd, arg);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
//import "C"
|
|
|
|
|
|
|
|
import (
|
2023-10-31 12:17:08 +00:00
|
|
|
_ "cfg"
|
2023-10-27 09:20:02 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-10-31 12:17:08 +00:00
|
|
|
|
|
|
|
hcl "code.miflux.com/hyung-hwan/hcl/go"
|
2023-10-27 09:20:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
func run_hcl() {
|
|
|
|
var hcl *C.hcl_t = C.hcl_openstd(0, nil)
|
|
|
|
var src []uint16 = utf16.Encode(([]rune)(
|
|
|
|
`(printf ">>>>>>>>> [%d]\n" (+ 30 455))
|
|
|
|
|
|
|
|
(printf ">>>>>>>>> [%d]\n" (+ 11 455))
|
|
|
|
#include "a.hcl"
|
|
|
|
(printf ">>>>>>>>> [%d]\n" (+ 20 455))
|
|
|
|
`))
|
|
|
|
|
|
|
|
if hcl == nil {
|
|
|
|
log.Printf("Unable to open HCL\n")
|
|
|
|
} else {
|
|
|
|
var (
|
|
|
|
x C.int
|
|
|
|
logmask C.hcl_bitmask_t
|
|
|
|
tgt *C.char
|
|
|
|
empty *C.char
|
|
|
|
r C.hcl_oop_t
|
|
|
|
)
|
|
|
|
|
|
|
|
logmask = ^C.hcl_bitmask_t(0)
|
|
|
|
tgt = C.CString("/dev/stderr")
|
|
|
|
defer C.free(unsafe.Pointer(tgt))
|
|
|
|
|
|
|
|
empty = C.CString("")
|
|
|
|
defer C.free(unsafe.Pointer(empty))
|
|
|
|
|
|
|
|
C.hcl_setoption(hcl, C.HCL_LOG_MASK, unsafe.Pointer(&logmask))
|
|
|
|
C.hcl_setoption(hcl, C.HCL_LOG_TARGET_BCSTR, unsafe.Pointer(tgt))
|
|
|
|
|
|
|
|
_ = C.hcl_ignite(hcl, 1000000)
|
|
|
|
//fmt.Printf ("ignire %d\n", x)
|
|
|
|
_ = C.hcl_addbuiltinprims(hcl)
|
|
|
|
//fmt.Printf ("addbuiltinprims %d\n", x)
|
|
|
|
//_ = C.hcl_attachiostdwithbcstr(hcl, empty, empty, empty)
|
|
|
|
//x = C.hcl_attachio(hcl, (*[0]byte)(C.read_handler), (*[0]byte)(C.scan_handler), (*[0]byte)(C.print_handler))
|
|
|
|
x = C.hcl_attachio(hcl, C.hcl_ioimpl_t(C.read_handler), C.hcl_ioimpl_t(C.scan_handler), C.hcl_ioimpl_t(C.print_handler))
|
|
|
|
if x <= -1 {
|
|
|
|
log.Printf("unable to attach IO handlers - %d - %s\n", x, C.GoString(C.hcl_geterrbmsg(hcl)))
|
|
|
|
goto done
|
|
|
|
}
|
|
|
|
_ = C.hcl_beginfeed(hcl, nil)
|
|
|
|
//fmt.Printf ("beginfeed %d\n", x)
|
|
|
|
_ = C.hcl_feed(hcl, (*C.ushort)(&src[0]), (C.ulong)(len(src)))
|
|
|
|
//fmt.Printf ("feed %d\n", x)
|
|
|
|
_ = C.hcl_endfeed(hcl)
|
|
|
|
//fmt.Printf ("endfeed %d => bclen %d\n", x, C.hcl_getbclen(hcl))
|
|
|
|
_ = x
|
|
|
|
|
|
|
|
C.hcl_decode(hcl, 0, C.hcl_getbclen(hcl))
|
|
|
|
logmask = 0
|
|
|
|
C.hcl_setoption(hcl, C.HCL_LOG_MASK, unsafe.Pointer(&logmask))
|
|
|
|
r = C.hcl_execute(hcl)
|
|
|
|
if r == nil {
|
|
|
|
fmt.Printf("Error - %s\n", C.GoString(C.hcl_geterrbmsg(hcl)))
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
C.hcl_close(hcl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
func main() {
|
|
|
|
//run_hcl()
|
|
|
|
|
2023-10-29 12:40:05 +00:00
|
|
|
var x *hcl.HCL = nil
|
|
|
|
var err error = nil
|
2023-10-27 09:20:02 +00:00
|
|
|
|
2023-10-31 12:17:08 +00:00
|
|
|
var rfh hcl.ReadFileHandler
|
|
|
|
var sfh hcl.ScanFileHandler
|
|
|
|
var pfh hcl.PrintFileHandler
|
2023-10-27 09:20:02 +00:00
|
|
|
|
2023-10-29 12:40:05 +00:00
|
|
|
x, err = hcl.New()
|
2023-10-27 09:20:02 +00:00
|
|
|
if err != nil {
|
2023-10-29 12:40:05 +00:00
|
|
|
fmt.Printf("ERROR failed to instantiate hcl - %s\n", err.Error())
|
2023-10-27 09:20:02 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2023-10-29 12:40:05 +00:00
|
|
|
err = x.Ignite(1000000)
|
2023-10-27 09:20:02 +00:00
|
|
|
if err != nil {
|
2023-10-29 12:40:05 +00:00
|
|
|
fmt.Printf("ERROR failed to ignite - %s\n", err.Error())
|
|
|
|
goto oops
|
2023-10-27 09:20:02 +00:00
|
|
|
}
|
2023-10-29 12:40:05 +00:00
|
|
|
err = x.AddBuiltinPrims()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR failed to add builtin primitives - %s\n", err.Error())
|
|
|
|
goto oops
|
|
|
|
}
|
|
|
|
|
2023-10-31 12:17:08 +00:00
|
|
|
err = x.AttachIO(rfh, sfh, pfh)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error - %s", err.Error())
|
|
|
|
}
|
|
|
|
x.FeedString(`(printf ">>>>>>>>> [%d]\n" (+ 30 455))
|
2023-10-29 12:40:05 +00:00
|
|
|
(printf ">>>>>>>>> [%d]\n" (+ 11 455))
|
|
|
|
#include "a.hcl"
|
|
|
|
(printf ">>>>>>>>> [%d]\n" (+ 20 455))`)
|
|
|
|
|
2023-10-31 12:17:08 +00:00
|
|
|
x.EndFeed()
|
|
|
|
x.Execute()
|
2023-10-29 12:40:05 +00:00
|
|
|
|
2023-10-27 09:20:02 +00:00
|
|
|
x.Close()
|
2023-10-29 12:40:05 +00:00
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
oops:
|
|
|
|
if x != nil {
|
|
|
|
x.Close()
|
|
|
|
x = nil
|
|
|
|
}
|
|
|
|
os.Exit(1)
|
2023-10-27 09:20:02 +00:00
|
|
|
}
|