fixed the go wrapper code further
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3b9b02de83
commit
85a2152be4
@ -42,15 +42,18 @@ hclgo_DEPENDENCIES = hclgo.bin
|
|||||||
## let the linker to move hclgo.bin to the actual target
|
## let the linker to move hclgo.bin to the actual target
|
||||||
hclgo_LINK = mv -f hclgo.bin hclgo$(EXEEXT) || echo "FAILED TO LINK"
|
hclgo_LINK = mv -f hclgo.bin hclgo$(EXEEXT) || echo "FAILED TO LINK"
|
||||||
|
|
||||||
hclgo.bin:
|
hclgo.bin: lib/libhcl.la
|
||||||
cp -pf $(srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true
|
cp -pf $(srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true
|
||||||
chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change
|
chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change
|
||||||
sed -r -i -e "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod
|
sed -r -i -e "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod
|
||||||
echo -e "\nreplace cfg => $(abs_builddir)/go/cfg" >> $(builddir)/go.mod
|
echo -e "\nreplace cfg => $(abs_builddir)/go/cfg" >> $(builddir)/go.mod
|
||||||
[ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true
|
[ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true
|
||||||
|
## ---------------------------------------------------------------
|
||||||
|
CC=$(CC) \
|
||||||
CGO_CFLAGS="-I$(abs_srcdir)/lib -I$(abs_builddir)/lib $(CFLAGS)" \
|
CGO_CFLAGS="-I$(abs_srcdir)/lib -I$(abs_builddir)/lib $(CFLAGS)" \
|
||||||
CGO_LDFLAGS="-L$(abs_builddir)/lib -L$(abs_builddir)/lib/.libs -lhcl -ldl -lquadmath" \
|
CGO_LDFLAGS="-L$(abs_builddir)/lib -L$(abs_builddir)/lib/.libs -lhcl -ldl -lquadmath" \
|
||||||
go build -C $(srcdir) -x -o $(abs_builddir)/hclgo.bin -modfile $(abs_builddir)/go.mod
|
go build -C $(srcdir) -x -o $(abs_builddir)/hclgo.bin -modfile $(abs_builddir)/go.mod
|
||||||
|
## ---------------------------------------------------------------
|
||||||
go clean -C $(srcdir) -x -modfile $(abs_builddir)/go.mod
|
go clean -C $(srcdir) -x -modfile $(abs_builddir)/go.mod
|
||||||
rm -rf $(builddir)/go.mod $(builddir)/go.sum
|
rm -rf $(builddir)/go.mod $(builddir)/go.sum
|
||||||
|
|
||||||
|
@ -937,12 +937,13 @@ distclean-local:
|
|||||||
clean-local:
|
clean-local:
|
||||||
rm -rf $(builddir)/go.mod $(builddir)/go.sum
|
rm -rf $(builddir)/go.mod $(builddir)/go.sum
|
||||||
|
|
||||||
@ENABLE_HCLGO_TRUE@hclgo.bin:
|
@ENABLE_HCLGO_TRUE@hclgo.bin: lib/libhcl.la
|
||||||
@ENABLE_HCLGO_TRUE@ cp -pf $(srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true
|
@ENABLE_HCLGO_TRUE@ cp -pf $(srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true
|
||||||
@ENABLE_HCLGO_TRUE@ chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change
|
@ENABLE_HCLGO_TRUE@ chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change
|
||||||
@ENABLE_HCLGO_TRUE@ sed -r -i -e "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod
|
@ENABLE_HCLGO_TRUE@ sed -r -i -e "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod
|
||||||
@ENABLE_HCLGO_TRUE@ echo -e "\nreplace cfg => $(abs_builddir)/go/cfg" >> $(builddir)/go.mod
|
@ENABLE_HCLGO_TRUE@ echo -e "\nreplace cfg => $(abs_builddir)/go/cfg" >> $(builddir)/go.mod
|
||||||
@ENABLE_HCLGO_TRUE@ [ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true
|
@ENABLE_HCLGO_TRUE@ [ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true
|
||||||
|
@ENABLE_HCLGO_TRUE@ CC=$(CC) \
|
||||||
@ENABLE_HCLGO_TRUE@ CGO_CFLAGS="-I$(abs_srcdir)/lib -I$(abs_builddir)/lib $(CFLAGS)" \
|
@ENABLE_HCLGO_TRUE@ CGO_CFLAGS="-I$(abs_srcdir)/lib -I$(abs_builddir)/lib $(CFLAGS)" \
|
||||||
@ENABLE_HCLGO_TRUE@ CGO_LDFLAGS="-L$(abs_builddir)/lib -L$(abs_builddir)/lib/.libs -lhcl -ldl -lquadmath" \
|
@ENABLE_HCLGO_TRUE@ CGO_LDFLAGS="-L$(abs_builddir)/lib -L$(abs_builddir)/lib/.libs -lhcl -ldl -lquadmath" \
|
||||||
@ENABLE_HCLGO_TRUE@ go build -C $(srcdir) -x -o $(abs_builddir)/hclgo.bin -modfile $(abs_builddir)/go.mod
|
@ENABLE_HCLGO_TRUE@ go build -C $(srcdir) -x -o $(abs_builddir)/hclgo.bin -modfile $(abs_builddir)/go.mod
|
||||||
|
12
go/cb.go
12
go/cb.go
@ -80,8 +80,8 @@ func (io *IOHandleTable) slot_to_io_handle(slot int) IOHandle {
|
|||||||
|
|
||||||
var io_tab IOHandleTable = IOHandleTable{}
|
var io_tab IOHandleTable = IOHandleTable{}
|
||||||
|
|
||||||
//export go_read_handler
|
//export hcl_go_read_handler
|
||||||
func go_read_handler(c *C.hcl_t, cmd C.hcl_iocmd_t, arg unsafe.Pointer) C.int {
|
func hcl_go_read_handler(c *C.hcl_t, cmd C.hcl_iocmd_t, arg unsafe.Pointer) C.int {
|
||||||
var (
|
var (
|
||||||
g *HCL
|
g *HCL
|
||||||
err error
|
err error
|
||||||
@ -154,8 +154,8 @@ func go_read_handler(c *C.hcl_t, cmd C.hcl_iocmd_t, arg unsafe.Pointer) C.int {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
//export go_scan_handler
|
//export hcl_go_scan_handler
|
||||||
func go_scan_handler(c *C.hcl_t, cmd C.hcl_iocmd_t, arg unsafe.Pointer) C.int {
|
func hcl_go_scan_handler(c *C.hcl_t, cmd C.hcl_iocmd_t, arg unsafe.Pointer) C.int {
|
||||||
var (
|
var (
|
||||||
g *HCL
|
g *HCL
|
||||||
err error
|
err error
|
||||||
@ -202,8 +202,8 @@ func go_scan_handler(c *C.hcl_t, cmd C.hcl_iocmd_t, arg unsafe.Pointer) C.int {
|
|||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
//export go_print_handler
|
//export hcl_go_print_handler
|
||||||
func go_print_handler(c *C.hcl_t, cmd C.hcl_iocmd_t, arg unsafe.Pointer) C.int {
|
func hcl_go_print_handler(c *C.hcl_t, cmd C.hcl_iocmd_t, arg unsafe.Pointer) C.int {
|
||||||
var (
|
var (
|
||||||
g *HCL
|
g *HCL
|
||||||
err error
|
err error
|
||||||
|
56
go/hcl.go
56
go/hcl.go
@ -3,6 +3,20 @@ package hcl
|
|||||||
/*
|
/*
|
||||||
#include <hcl.h>
|
#include <hcl.h>
|
||||||
#include <hcl-utl.h>
|
#include <hcl-utl.h>
|
||||||
|
|
||||||
|
extern int hcl_go_read_handler (hcl_t hcl, hcl_iocmd_t cmd, void* arg);
|
||||||
|
extern int hcl_go_scan_handler (hcl_t hcl, hcl_iocmd_t cmd, void* arg);
|
||||||
|
extern int hcl_go_print_handler (hcl_t hcl, hcl_iocmd_t cmd, void* arg);
|
||||||
|
|
||||||
|
int hcl_read_handler_for_go (hcl_t hcl, hcl_iocmd_t cmd, void* arg) {
|
||||||
|
return hcl_go_read_handler(hcl, cmd, arg);
|
||||||
|
}
|
||||||
|
int hcl_scan_handler_for_go (hcl_t hcl, hcl_iocmd_t cmd, void* arg) {
|
||||||
|
return hcl_go_scan_handler(hcl, cmd, arg);
|
||||||
|
}
|
||||||
|
int hcl_print_handler_for_go (hcl_t hcl, hcl_iocmd_t cmd, void* arg) {
|
||||||
|
return hcl_go_print_handler(hcl, cmd, arg);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@ -12,24 +26,36 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IOImpl interface {
|
type IOReadImpl interface {
|
||||||
Open(g *HCL, name string, includer_name string) (int, error)
|
Open(g *HCL, name string, includer_name string) (int, error)
|
||||||
Close(fd int)
|
Close(fd int)
|
||||||
Read(fd int, buf []rune) (int, error)
|
Read(fd int, buf []rune) (int, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type IOScanImpl interface {
|
||||||
|
Open(g *HCL) error
|
||||||
|
Close()
|
||||||
|
Read(buf []rune) (int, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type IOPrintImpl interface {
|
||||||
|
Open(g *HCL) error
|
||||||
|
Close()
|
||||||
Write(data []rune) error
|
Write(data []rune) error
|
||||||
WriteBytes(data []byte) error
|
WriteBytes(data []byte) error
|
||||||
Flush() error
|
Flush() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IOImplSet struct {
|
||||||
|
r IOReadImpl
|
||||||
|
s IOScanImpl
|
||||||
|
p IOPrintImpl
|
||||||
|
}
|
||||||
|
|
||||||
type HCL struct {
|
type HCL struct {
|
||||||
c *C.hcl_t
|
c *C.hcl_t
|
||||||
inst_no int
|
inst_no int
|
||||||
|
io IOImplSet
|
||||||
io struct {
|
|
||||||
r IOImpl
|
|
||||||
s IOImpl
|
|
||||||
p IOImpl
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ext struct {
|
type Ext struct {
|
||||||
@ -92,12 +118,22 @@ func (hcl *HCL) AddBuiltinPrims() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hcl *HCL) AttachIO(r IOImpl, w IOImpl, p IOImpl) error {
|
func (hcl *HCL) AttachIO(r IOReadImpl, s IOScanImpl, p IOPrintImpl) error {
|
||||||
|
var x C.int
|
||||||
|
var io IOImplSet
|
||||||
|
|
||||||
|
io = hcl.io
|
||||||
|
|
||||||
hcl.io.r = r
|
hcl.io.r = r
|
||||||
hcl.io.s = s
|
hcl.io.s = s
|
||||||
hcl.io.p = p
|
hcl.io.p = p
|
||||||
if C.hcl_attachio(hcl.c, go_read_handler, go_scan_handler, go_print_handler) <= -1 {
|
|
||||||
// TODO: restore to the old value..
|
x = C.hcl_attachio(hcl.c,
|
||||||
|
C.hcl_ioimpl_t(C.hcl_read_handler_for_go),
|
||||||
|
C.hcl_ioimpl_t(C.hcl_scan_handler_for_go),
|
||||||
|
C.hcl_ioimpl_t(C.hcl_print_handler_for_go))
|
||||||
|
if x <= -1 {
|
||||||
|
hcl.io = io // restore the set
|
||||||
return fmt.Errorf("unable to attach I/O handlers: %s", string(ucstr_to_rune_slice(C.hcl_geterrstr(hcl.c))))
|
return fmt.Errorf("unable to attach I/O handlers: %s", string(ucstr_to_rune_slice(C.hcl_geterrstr(hcl.c))))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
6
main.go
6
main.go
@ -126,14 +126,14 @@ func main() {
|
|||||||
goto oops
|
goto oops
|
||||||
}
|
}
|
||||||
|
|
||||||
err = x.AttachIO(rfh, sfh, pfh)
|
err = x.AttachIO(&rfh, &sfh, &pfh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error - %s", err.Error())
|
fmt.Printf("Error - %s", err.Error())
|
||||||
}
|
}
|
||||||
x.FeedString(`(printf ">>>>>>>>> [%d]\n" (+ 30 455))
|
x.FeedString([]rune(`(printf ">>>>>>>>> [%d]\n" (+ 30 455))
|
||||||
(printf ">>>>>>>>> [%d]\n" (+ 11 455))
|
(printf ">>>>>>>>> [%d]\n" (+ 11 455))
|
||||||
#include "a.hcl"
|
#include "a.hcl"
|
||||||
(printf ">>>>>>>>> [%d]\n" (+ 20 455))`)
|
(printf ">>>>>>>>> [%d]\n" (+ 20 455))`))
|
||||||
|
|
||||||
x.EndFeed()
|
x.EndFeed()
|
||||||
x.Execute()
|
x.Execute()
|
||||||
|
Loading…
Reference in New Issue
Block a user