Compare commits

...
5 Commits
12 changed files with 623 additions and 209 deletions
+38 -36
View File
@@ -249,8 +249,8 @@ static int handle_logopt (hak_t* hak, const hak_bch_t* logstr)
} }
fname.ptr = (hak_bch_t*)logstr; fname.ptr = (hak_bch_t*)logstr;
hak_setoption (hak, HAK_LOG_TARGET_BCS, &fname); hak_setoption (hak, HAK_OPT_LOG_TARGET_BCS, &fname);
hak_setoption (hak, HAK_LOG_MASK, &logmask); hak_setoption (hak, HAK_OPT_LOG_MASK, &logmask);
return 0; return 0;
} }
@@ -280,9 +280,9 @@ static int handle_dbgopt (hak_t* hak, const hak_bch_t* str)
} }
while (cm); while (cm);
hak_getoption(hak, HAK_TRAIT, &trait); hak_getoption(hak, HAK_OPT_TRAIT, &trait);
trait |= dbgopt; trait |= dbgopt;
hak_setoption(hak, HAK_TRAIT, &trait); hak_setoption(hak, HAK_OPT_TRAIT, &trait);
return 0; return 0;
} }
#endif #endif
@@ -865,6 +865,7 @@ int main (int argc, char* argv[])
{ ":debug", '\0' }, { ":debug", '\0' },
#endif #endif
{ ":heapsize", '\0' }, { ":heapsize", '\0' },
{ ":incdirs", 'I' },
{ ":log", 'l' }, { ":log", 'l' },
{ "info", '\0' }, { "info", '\0' },
{ ":modlibdirs", '\0' }, { ":modlibdirs", '\0' },
@@ -873,7 +874,7 @@ int main (int argc, char* argv[])
}; };
static hak_bopt_t opt = static hak_bopt_t opt =
{ {
"l:v", "I:l:v",
lopt lopt
}; };
@@ -882,6 +883,7 @@ int main (int argc, char* argv[])
int verbose = 0; int verbose = 0;
int show_info = 0; int show_info = 0;
const char* modlibdirs = HAK_NULL; const char* modlibdirs = HAK_NULL;
const char* incdirs = HAK_NULL;
#if defined(HAK_BUILD_DEBUG) #if defined(HAK_BUILD_DEBUG)
const char* dbgopt = HAK_NULL; const char* dbgopt = HAK_NULL;
@@ -895,10 +897,11 @@ int main (int argc, char* argv[])
print_usage: print_usage:
fprintf(stderr, "Usage: %s [options] script-filename [output-filename]\n", argv[0]); fprintf(stderr, "Usage: %s [options] script-filename [output-filename]\n", argv[0]);
fprintf(stderr, "Options are:\n"); fprintf(stderr, "Options are:\n");
fprintf(stderr, " --info show build information\n"); fprintf(stderr, " --info show build information\n");
fprintf(stderr, " -l, --log string specify the log file path and options\n"); fprintf(stderr, " -I, --incdirs string specify the list of include directories\n");
fprintf(stderr, " --modlibdirs string specify directories to load modules from\n"); fprintf(stderr, " -l, --log string specify the log file path and options\n");
fprintf(stderr, " -v show verbose messages\n"); fprintf(stderr, " --modlibdirs string specify directories to load modules from\n");
fprintf(stderr, " -v show verbose messages\n");
return -1; return -1;
} }
@@ -907,6 +910,10 @@ int main (int argc, char* argv[])
{ {
switch (c) switch (c)
{ {
case 'I':
incdirs = opt.arg;
break;
case 'l': case 'l':
logopt = opt.arg; logopt = opt.arg;
break; break;
@@ -980,15 +987,15 @@ int main (int argc, char* argv[])
{ {
hak_oow_t tab_size; hak_oow_t tab_size;
tab_size = HAK_DFL_SYMTAB_SIZE; tab_size = HAK_DFL_SYMTAB_SIZE;
hak_setoption (hak, HAK_SYMTAB_SIZE, &tab_size); hak_setoption (hak, HAK_OPT_SYMTAB_SIZE, &tab_size);
tab_size = HAK_DFL_SYSDIC_SIZE; tab_size = HAK_DFL_SYSDIC_SIZE;
hak_setoption (hak, HAK_SYSDIC_SIZE, &tab_size); hak_setoption (hak, HAK_OPT_SYSDIC_SIZE, &tab_size);
tab_size = HAK_DFL_PROCSTK_SIZE; /* TODO: choose a better stack size or make this user specifiable */ tab_size = HAK_DFL_PROCSTK_SIZE; /* TODO: choose a better stack size or make this user specifiable */
hak_setoption (hak, HAK_PROCSTK_SIZE, &tab_size); hak_setoption (hak, HAK_OPT_PROCSTK_SIZE, &tab_size);
tab_size = HAK_DFL_EXSTK_SIZE; /* TODO: choose a better stack size or make this user specifiable */ tab_size = HAK_DFL_EXSTK_SIZE; /* TODO: choose a better stack size or make this user specifiable */
hak_setoption (hak, HAK_EXSTK_SIZE, &tab_size); hak_setoption (hak, HAK_OPT_EXSTK_SIZE, &tab_size);
tab_size = HAK_DFL_CLSTK_SIZE; /* TODO: choose a better stack size or make this user specifiable */ tab_size = HAK_DFL_CLSTK_SIZE; /* TODO: choose a better stack size or make this user specifiable */
hak_setoption (hak, HAK_CLSTK_SIZE, &tab_size); hak_setoption (hak, HAK_OPT_CLSTK_SIZE, &tab_size);
} }
{ {
@@ -997,34 +1004,29 @@ int main (int argc, char* argv[])
/*trait |= HAK_TRAIT_NOGC;*/ /*trait |= HAK_TRAIT_NOGC;*/
trait |= HAK_TRAIT_AWAIT_PROCS; trait |= HAK_TRAIT_AWAIT_PROCS;
trait |= HAK_TRAIT_LANG_ENABLE_EOL; trait |= HAK_TRAIT_LANG_ENABLE_EOL;
hak_setoption (hak, HAK_TRAIT, &trait); hak_setoption (hak, HAK_OPT_TRAIT, &trait);
}
if (incdirs)
{
/* the option is stored in both encodings, so the byte form from
* the command line goes in as is - no conversion needed here. */
if (hak_setoption(hak, HAK_OPT_INCDIRS_BCSTR, incdirs) <= -1)
{
hak_logbfmt(hak, HAK_LOG_STDERR,"ERROR: cannot set incdirs - [%d] %js\n", hak_geterrnum(hak), hak_geterrmsg(hak));
goto oops;
}
} }
if (modlibdirs) if (modlibdirs)
{ {
#if defined(HAK_OOCH_IS_UCH) /* the option is stored in both encodings, so the byte form from
hak_ooch_t* tmp; * the command line goes in as is - no conversion needed here. */
tmp = hak_dupbtoucstr(hak, modlibdirs, HAK_NULL); if (hak_setoption(hak, HAK_OPT_MODLIBDIRS_BCSTR, modlibdirs) <= -1)
if (HAK_UNLIKELY(!tmp))
{
hak_logbfmt(hak, HAK_LOG_STDERR,"ERROR: cannot duplicate modlibdirs - [%d] %js\n", hak_geterrnum(hak), hak_geterrmsg(hak));
goto oops;
}
if (hak_setoption(hak, HAK_MOD_LIBDIRS, tmp) <= -1)
{
hak_logbfmt(hak, HAK_LOG_STDERR,"ERROR: cannot set modlibdirs - [%d] %js\n", hak_geterrnum(hak), hak_geterrmsg(hak));
hak_freemem(hak, tmp);
goto oops;
}
hak_freemem(hak, tmp);
#else
if (hak_setoption(hak, HAK_MOD_LIBDIRS, modlibdirs) <= -1)
{ {
hak_logbfmt(hak, HAK_LOG_STDERR,"ERROR: cannot set modlibdirs - [%d] %js\n", hak_geterrnum(hak), hak_geterrmsg(hak)); hak_logbfmt(hak, HAK_LOG_STDERR,"ERROR: cannot set modlibdirs - [%d] %js\n", hak_geterrnum(hak), hak_geterrmsg(hak));
goto oops; goto oops;
} }
#endif
} }
memset (&hakcb, 0, HAK_SIZEOF(hakcb)); memset (&hakcb, 0, HAK_SIZEOF(hakcb));
@@ -1095,9 +1097,9 @@ int main (int argc, char* argv[])
// in the non-INTERACTIVE mode, the compiler generates MAKE_BLOCK for lambda functions. // in the non-INTERACTIVE mode, the compiler generates MAKE_BLOCK for lambda functions.
{ {
hak_bitmask_t trait; hak_bitmask_t trait;
hak_getoption(hak, HAK_TRAIT, &trait); hak_getoption(hak, HAK_OPT_TRAIT, &trait);
trait |= HAK_TRAIT_INTERACTIVE; trait |= HAK_TRAIT_INTERACTIVE;
hak_setoption(hak, HAK_TRAIT, &trait); hak_setoption(hak, HAK_OPT_TRAIT, &trait);
} }
#endif #endif
+169 -16
View File
@@ -4,8 +4,9 @@ import (
"flag" "flag"
"fmt" "fmt"
"hak" "hak"
"io"
"os" "os"
//"strings" "strings"
) )
/* /*
@@ -18,6 +19,9 @@ import (
`)) `))
*/ */
/* 0 means no pre-allocated heap, as in bin/hak.c */
const DEFAULT_HEAPSIZE uint = 0
/* to be set in build time */ /* to be set in build time */
var BINDIR = "." var BINDIR = "."
var SBINDIR = "." var SBINDIR = "."
@@ -25,10 +29,14 @@ var LIBDIR = "."
var SYSCONFDIR = "." var SYSCONFDIR = "."
type Param struct { type Param struct {
log_file string log_target string
log_mask hak.BitMask
input_file string input_file string
heapsize uint heapsize uint
modlibdirs string modlibdirs string
incdirs string
verbose bool
show_info bool
fs_usage func() fs_usage func()
} }
@@ -36,6 +44,93 @@ func empty_usage() {
} }
/* the filter names accepted after the comma in --log, mirroring the xtab
* table in handle_logopt() of bin/hak.c. 'and' marks the entries that clear
* bits instead of setting them. */
type log_filter struct {
name string
and bool
mask hak.BitMask
}
var log_filters = []log_filter{
{"", false, 0},
{"app", false, hak.LOG_APP},
{"compiler", false, hak.LOG_COMPILER},
{"vm", false, hak.LOG_VM},
{"mnemonic", false, hak.LOG_MNEMONIC},
{"gc", false, hak.LOG_GC},
{"ic", false, hak.LOG_IC},
{"primitive", false, hak.LOG_PRIMITIVE},
/* a specific level */
{"fatal", false, hak.LOG_FATAL},
{"error", false, hak.LOG_ERROR},
{"warn", false, hak.LOG_WARN},
{"info", false, hak.LOG_INFO},
{"debug", false, hak.LOG_DEBUG},
/* a specific level or higher */
{"fatal+", false, hak.LOG_FATAL},
{"error+", false, hak.LOG_FATAL | hak.LOG_ERROR},
{"warn+", false, hak.LOG_FATAL | hak.LOG_ERROR | hak.LOG_WARN},
{"info+", false, hak.LOG_FATAL | hak.LOG_ERROR | hak.LOG_WARN | hak.LOG_INFO},
{"debug+", false, hak.LOG_FATAL | hak.LOG_ERROR | hak.LOG_WARN | hak.LOG_INFO | hak.LOG_DEBUG},
/* a specific level or lower */
{"fatal-", false, hak.LOG_FATAL | hak.LOG_ERROR | hak.LOG_WARN | hak.LOG_INFO | hak.LOG_DEBUG},
{"error-", false, hak.LOG_ERROR | hak.LOG_WARN | hak.LOG_INFO | hak.LOG_DEBUG},
{"warn-", false, hak.LOG_WARN | hak.LOG_INFO | hak.LOG_DEBUG},
{"info-", false, hak.LOG_INFO | hak.LOG_DEBUG},
{"debug-", false, hak.LOG_DEBUG},
/* exclude a specific level */
{"-fatal", true, ^hak.LOG_FATAL},
{"-error", true, ^hak.LOG_ERROR},
{"-warn", true, ^hak.LOG_WARN},
{"-info", true, ^hak.LOG_INFO},
{"-debug", true, ^hak.LOG_DEBUG},
}
/* split "path,filter,filter" into a target and a log mask. with no comma the
* whole string is the target and every level and type is enabled. */
func parse_logopt(logstr string) (string, hak.BitMask, error) {
var comma int = strings.Index(logstr, ",")
var mask hak.BitMask
if comma < 0 {
return logstr, hak.LOG_ALL_LEVELS | hak.LOG_ALL_TYPES, nil
}
for _, f := range strings.Split(logstr[comma+1:], ",") {
var i int
for i = 0; i < len(log_filters); i++ {
if log_filters[i].name == f {
if log_filters[i].and {
mask &= log_filters[i].mask
} else {
mask |= log_filters[i].mask
}
break
}
}
if i >= len(log_filters) {
return "", 0, fmt.Errorf("unrecognized log filter - %s - in %s", f, logstr)
}
}
/* nothing selected in a category means everything in that category */
if (mask & hak.LOG_ALL_TYPES) == 0 {
mask |= hak.LOG_ALL_TYPES
}
if (mask & hak.LOG_ALL_LEVELS) == 0 {
mask |= hak.LOG_ALL_LEVELS
}
return logstr[0:comma], mask, nil
}
func handle_arguments(param *Param) error { func handle_arguments(param *Param) error {
/* /*
var nargs int = len(os.Args) var nargs int = len(os.Args)
@@ -64,34 +159,66 @@ func handle_arguments(param *Param) error {
var fs *flag.FlagSet var fs *flag.FlagSet
var heapsize *uint var heapsize *uint
var modlibdirs *string var modlibdirs *string
var incdirs *string
var log *string var log *string
var verbose *bool
var show_info *bool
var err error var err error
fs = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) fs = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
heapsize = fs.Uint("heapsize", 0, "specify heap size") /* the same set bin/hak.c accepts. the flag package treats -x and --x
modlibdirs = fs.String("modlibdirs", "", "specify module library directories") * alike, so registering both spellings of a short option is enough to
log = fs.String("log", "", "specify log file") * give -I and --incdirs the same destination. */
heapsize = fs.Uint("heapsize", DEFAULT_HEAPSIZE, "specify the heap size in bytes")
incdirs = fs.String("incdirs", "", "specify the list of include directories")
fs.StringVar(incdirs, "I", "", "specify the list of include directories")
log = fs.String("log", "", "specify the log file path and options")
fs.StringVar(log, "l", "", "specify the log file path and options")
modlibdirs = fs.String("modlibdirs", "", "specify directories to load modules from")
verbose = fs.Bool("v", false, "show verbose messages")
show_info = fs.Bool("info", false, "show build information")
param.fs_usage = fs.Usage param.fs_usage = fs.Usage
fs.Usage = empty_usage // i don't want fs.Parse() print the usage fs.Usage = empty_usage // i don't want fs.Parse() print the usage
fs.SetOutput(io.Discard) // nor its own copy of the error, which we report ourselves
err = fs.Parse(os.Args[1:]) err = fs.Parse(os.Args[1:])
fs.Usage = param.fs_usage // restore it fs.Usage = param.fs_usage // restore it
fs.SetOutput(os.Stderr) // so the restored usage still prints
if err != nil { if err != nil {
return fmt.Errorf("command line error - %s", err.Error()) return fmt.Errorf("command line error - %s", err.Error())
} }
param.heapsize = *heapsize
param.incdirs = *incdirs
param.modlibdirs = *modlibdirs
param.verbose = *verbose
param.show_info = *show_info
if *log != "" {
param.log_target, param.log_mask, err = parse_logopt(*log)
if err != nil {
return err
}
}
/* --info answers on its own and needs no script */
if param.show_info {
return nil
}
if fs.NArg() < 1 { if fs.NArg() < 1 {
return fmt.Errorf("no input file specified") return fmt.Errorf("no input file specified")
} else if fs.NArg() > 1 { } else if fs.NArg() > 1 {
/* bin/hak.c also takes an optional output file as the second
* argument, but the go binding attaches the user data streams
* through handler objects rather than a path, so there is nothing
* to pass it to yet. */
return fmt.Errorf("too many input files specified") return fmt.Errorf("too many input files specified")
} }
param.input_file = fs.Arg(0); param.input_file = fs.Arg(0)
param.log_file = *log // TODO: parse the option part (e.g. --log /dev/stderr,debug+) return nil
param.heapsize = *heapsize // TODO: set this to hak
param.modlibdirs = *modlibdirs // TODO: set this to hak
return nil;
} }
func main() { func main() {
@@ -111,20 +238,39 @@ func main() {
os.Exit(1) os.Exit(1)
} }
if param.show_info {
fmt.Println(hak.BuildInfo())
os.Exit(0)
}
x, err = hak.New() x, err = hak.New()
if err != nil { if err != nil {
fmt.Printf("ERROR: failed to instantiate hak - %s\n", err.Error()) fmt.Printf("ERROR: failed to instantiate hak - %s\n", err.Error())
os.Exit(1) os.Exit(1)
} }
if param.log_file != "" { if param.log_target != "" {
x.SetLogMask(^hak.BitMask(0)) /* honour both halves of --log. the previous code discarded the path
x.SetLogTarget("/dev/stderr") * and always logged everything to /dev/stderr. */
x.SetLogMask(param.log_mask)
err = x.SetLogTarget(param.log_target)
if err != nil {
fmt.Printf("ERROR: failed to set log target - %s\n", err.Error())
os.Exit(1)
}
}
if param.incdirs != "" {
x.SetIncDirs(param.incdirs)
}
if param.modlibdirs != "" {
x.SetModLibDirs(param.modlibdirs)
} }
x.SetTrait(x.GetTrait() | hak.TRAIT_LANG_ENABLE_EOL) x.SetTrait(x.GetTrait() | hak.TRAIT_LANG_ENABLE_EOL)
err = x.Ignite(1000000) err = x.Ignite(uintptr(param.heapsize))
if err != nil { if err != nil {
fmt.Printf("ERROR: failed to ignite - %s\n", err.Error()) fmt.Printf("ERROR: failed to ignite - %s\n", err.Error())
goto oops goto oops
@@ -169,8 +315,11 @@ func main() {
goto oops goto oops
} }
/* Decode() writes the bytecode mnemonics through the log, so it only
* produces anything when --log selects the mnemonic type. the log mask
* is no longer cleared afterwards - doing that silenced --log for the
* whole of Execute(). */
x.Decode() x.Decode()
x.SetLogMask(0)
err = x.Execute() err = x.Execute()
if err != nil { if err != nil {
@@ -179,6 +328,10 @@ func main() {
goto oops goto oops
} }
if param.verbose {
fmt.Printf("EXECUTION OK - %s\n", param.input_file)
}
x.Close() x.Close()
os.Exit(0) os.Exit(0)
+47 -13
View File
@@ -12,6 +12,7 @@ import (
"io" "io"
"os" "os"
"path" "path"
"strings"
"path/filepath" "path/filepath"
"reflect" "reflect"
"sync" "sync"
@@ -96,6 +97,8 @@ func hak_go_cci_handler(c *C.hak_t, cmd C.hak_io_cmd_t, arg unsafe.Pointer) C.in
var ( var (
ioarg *C.hak_io_cciarg_t ioarg *C.hak_io_cciarg_t
name string name string
raw string
try_incdirs bool
fd int fd int
tptr unsafe.Pointer tptr unsafe.Pointer
tlen C.size_t tlen C.size_t
@@ -110,33 +113,64 @@ func hak_go_cci_handler(c *C.hak_t, cmd C.hak_io_cmd_t, arg unsafe.Pointer) C.in
// actual included stream // actual included stream
var includer_name string var includer_name string
name = string(ucstr_to_rune_slice(ioarg.name)) raw = string(ucstr_to_rune_slice(ioarg.name))
tptr = ioarg.includer.handle tptr = ioarg.includer.handle
tlen = *(*C.size_t)(unsafe.Pointer(uintptr(tptr) + unsafe.Sizeof(fd))) tlen = *(*C.size_t)(unsafe.Pointer(uintptr(tptr) + unsafe.Sizeof(fd)))
includer_name = C.GoStringN((*C.char)(unsafe.Pointer(uintptr(tptr)+unsafe.Sizeof(fd)+unsafe.Sizeof(tlen))), C.int(tlen)) includer_name = C.GoStringN((*C.char)(unsafe.Pointer(uintptr(tptr)+unsafe.Sizeof(fd)+unsafe.Sizeof(tlen))), C.int(tlen))
name = filepath.Join(path.Dir(includer_name), name) name = filepath.Join(path.Dir(includer_name), raw)
// a name anchored by the author - absolute, or explicitly ./ or
// ../ - is meant to resolve against the includer alone. anything
// else may fall back to the include directories. this mirrors
// what open_cci_stream() does in lib/std.c.
try_incdirs = !filepath.IsAbs(raw) &&
!strings.HasPrefix(raw, "./") && !strings.HasPrefix(raw, "../")
}
// [NOTE] the open has to happen before the allocation below, because
// the include-directory search can settle on a different (and
// longer) path than the one first tried, and the block is
// sized from the name it ends up storing.
if ioarg.includer == nil {
fd = -1
} else {
fd, err = g.io.cci.Open(g, name)
if err != nil && try_incdirs {
// walk the colon-separated include directories, as the C
// reader does. an empty entry means the current directory.
for _, dir := range strings.Split(g.GetIncDirs(), ":") {
var cand string = filepath.Join(dir, raw)
var fd2 int
var err2 error
fd2, err2 = g.io.cci.Open(g, cand)
if err2 == nil {
// the stored name becomes the includer path for
// anything this file includes in turn, so it has to
// be the path that actually opened
fd, err, name = fd2, nil, cand
break
}
}
}
if err != nil {
g.set_errmsg(C.HAK_EIOERR, err.Error())
return -1
}
} }
tlen = C.size_t(len(name)) // number of bytes in the string tlen = C.size_t(len(name)) // number of bytes in the string
tptr = C.hak_allocmem(c, C.size_t(unsafe.Sizeof(fd)) + C.size_t(unsafe.Sizeof(tlen)) + tlen) tptr = C.hak_allocmem(c, C.size_t(unsafe.Sizeof(fd)) + C.size_t(unsafe.Sizeof(tlen)) + tlen)
if tptr == nil { if tptr == nil {
if ioarg.includer != nil {
g.io.cci.Close(fd)
}
g.set_errmsg(C.HAK_ESYSMEM, "cci name allocation failure") g.set_errmsg(C.HAK_ESYSMEM, "cci name allocation failure")
return -1 return -1
} }
if ioarg.includer == nil {
fd = -1
} else {
fd, err = g.io.cci.Open(g, name)
if err != nil {
g.set_errmsg(C.HAK_EIOERR, err.Error())
C.hak_freemem(c, tptr)
return -1
}
}
// | fd | length | name bytes of the length | // | fd | length | name bytes of the length |
*(*int)(tptr) = fd; *(*int)(tptr) = fd;
*(*C.size_t)(unsafe.Pointer(uintptr(tptr)+unsafe.Sizeof(fd))) = tlen; *(*C.size_t)(unsafe.Pointer(uintptr(tptr)+unsafe.Sizeof(fd))) = tlen;
+92 -9
View File
@@ -76,6 +76,38 @@ type BitMask C.hak_bitmask_t
const TRAIT_LANG_ENABLE_EOL BitMask = C.HAK_TRAIT_LANG_ENABLE_EOL const TRAIT_LANG_ENABLE_EOL BitMask = C.HAK_TRAIT_LANG_ENABLE_EOL
/* log levels */
const (
LOG_DEBUG BitMask = C.HAK_LOG_DEBUG
LOG_INFO BitMask = C.HAK_LOG_INFO
LOG_WARN BitMask = C.HAK_LOG_WARN
LOG_ERROR BitMask = C.HAK_LOG_ERROR
LOG_FATAL BitMask = C.HAK_LOG_FATAL
)
/* log types */
const (
LOG_UNTYPED BitMask = C.HAK_LOG_UNTYPED
LOG_COMPILER BitMask = C.HAK_LOG_COMPILER
LOG_VM BitMask = C.HAK_LOG_VM
LOG_MNEMONIC BitMask = C.HAK_LOG_MNEMONIC
LOG_GC BitMask = C.HAK_LOG_GC
LOG_IC BitMask = C.HAK_LOG_IC
LOG_PRIMITIVE BitMask = C.HAK_LOG_PRIMITIVE
LOG_APP BitMask = C.HAK_LOG_APP
)
const (
LOG_ALL_LEVELS BitMask = C.HAK_LOG_ALL_LEVELS
LOG_ALL_TYPES BitMask = C.HAK_LOG_ALL_TYPES
)
/* BuildInfo answers how the underlying C library was configured. it mirrors
* what bin/hak.c prints for --info. */
func BuildInfo() string {
return fmt.Sprintf("Configured with: %s %s", C.HAK_CONFIGURE_CMD, C.HAK_CONFIGURE_ARGS)
}
func deregister_instance(g *Hak) { func deregister_instance(g *Hak) {
if g.inst_no >= 0 { if g.inst_no >= 0 {
inst_table.delete_instance(g.inst_no) inst_table.delete_instance(g.inst_no)
@@ -142,7 +174,7 @@ func (hak *Hak) GetTrait() BitMask {
var x C.int var x C.int
var log_mask BitMask = 0 var log_mask BitMask = 0
x = C.hak_getoption(hak.c, C.HAK_TRAIT, unsafe.Pointer(&log_mask)) x = C.hak_getoption(hak.c, C.HAK_OPT_TRAIT, unsafe.Pointer(&log_mask))
if x <= -1 { if x <= -1 {
// this must not happen // this must not happen
panic(fmt.Errorf("unable to get log mask - %s", hak.get_errmsg())) panic(fmt.Errorf("unable to get log mask - %s", hak.get_errmsg()))
@@ -154,7 +186,7 @@ func (hak *Hak) GetTrait() BitMask {
func (hak *Hak) SetTrait(log_mask BitMask) { func (hak *Hak) SetTrait(log_mask BitMask) {
var x C.int var x C.int
x = C.hak_setoption(hak.c, C.HAK_TRAIT, unsafe.Pointer(&log_mask)) x = C.hak_setoption(hak.c, C.HAK_OPT_TRAIT, unsafe.Pointer(&log_mask))
if x <= -1 { if x <= -1 {
// this must not happen // this must not happen
panic(fmt.Errorf("unable to set log mask - %s", hak.get_errmsg())) panic(fmt.Errorf("unable to set log mask - %s", hak.get_errmsg()))
@@ -165,7 +197,7 @@ func (hak *Hak) GetLogMask() BitMask {
var x C.int var x C.int
var log_mask BitMask = 0 var log_mask BitMask = 0
x = C.hak_getoption(hak.c, C.HAK_LOG_MASK, unsafe.Pointer(&log_mask)) x = C.hak_getoption(hak.c, C.HAK_OPT_LOG_MASK, unsafe.Pointer(&log_mask))
if x <= -1 { if x <= -1 {
// this must not happen // this must not happen
panic(fmt.Errorf("unable to get log mask - %s", hak.get_errmsg())) panic(fmt.Errorf("unable to get log mask - %s", hak.get_errmsg()))
@@ -177,7 +209,7 @@ func (hak *Hak) GetLogMask() BitMask {
func (hak *Hak) SetLogMask(log_mask BitMask) { func (hak *Hak) SetLogMask(log_mask BitMask) {
var x C.int var x C.int
x = C.hak_setoption(hak.c, C.HAK_LOG_MASK, unsafe.Pointer(&log_mask)) x = C.hak_setoption(hak.c, C.HAK_OPT_LOG_MASK, unsafe.Pointer(&log_mask))
if x <= -1 { if x <= -1 {
// this must not happen // this must not happen
panic(fmt.Errorf("unable to set log mask - %s", hak.get_errmsg())) panic(fmt.Errorf("unable to set log mask - %s", hak.get_errmsg()))
@@ -188,27 +220,78 @@ func (hak *Hak) GetLogTarget() string {
var x C.int var x C.int
var tgt *C.char var tgt *C.char
x = C.hak_getoption(hak.c, C.HAK_LOG_TARGET_BCSTR, unsafe.Pointer(&tgt)) x = C.hak_getoption(hak.c, C.HAK_OPT_LOG_TARGET_BCSTR, unsafe.Pointer(&tgt))
if x <= -1 { if x <= -1 {
// this must not happen // this must not happen
panic(fmt.Errorf("unable to set log target - %s", hak.get_errmsg())) panic(fmt.Errorf("unable to get log target - %s", hak.get_errmsg()))
} }
return C.GoString(tgt) return C.GoString(tgt)
} }
func (hak *Hak) SetLogTarget(target string) { func (hak *Hak) SetLogTarget(target string) error {
var x C.int var x C.int
var tgt *C.char var tgt *C.char
tgt = C.CString(target) // TODO: need error check? tgt = C.CString(target) // TODO: need error check?
defer C.free(unsafe.Pointer(tgt)) defer C.free(unsafe.Pointer(tgt))
x = C.hak_setoption(hak.c, C.HAK_LOG_TARGET_BCSTR, unsafe.Pointer(tgt)) x = C.hak_setoption(hak.c, C.HAK_OPT_LOG_TARGET_BCSTR, unsafe.Pointer(tgt))
if x <= -1 { return hak.make_errinfo() }
return nil
}
func (hak *Hak) GetIncDirs() string {
var x C.int
var tgt *C.char
x = C.hak_getoption(hak.c, C.HAK_OPT_INCDIRS_BCSTR, unsafe.Pointer(&tgt))
if x <= -1 { if x <= -1 {
// this must not happen // this must not happen
panic(fmt.Errorf("unable to set log target - %s", hak.get_errmsg())) panic(fmt.Errorf("unable to get include directories - %s", hak.get_errmsg()))
} }
return C.GoString(tgt)
}
func (hak *Hak) SetIncDirs(target string) error {
var x C.int
var tgt *C.char
tgt = C.CString(target) // TODO: need error check?
defer C.free(unsafe.Pointer(tgt))
x = C.hak_setoption(hak.c, C.HAK_OPT_INCDIRS_BCSTR, unsafe.Pointer(tgt))
if x <= -1 { return hak.make_errinfo() }
return nil
}
func (hak *Hak) GetModLibDirs() string {
var x C.int
var tgt *C.char
x = C.hak_getoption(hak.c, C.HAK_OPT_MODLIBDIRS_BCSTR, unsafe.Pointer(&tgt))
if x <= -1 {
// this must not happen
panic(fmt.Errorf("unable to get module library directories - %s", hak.get_errmsg()))
}
return C.GoString(tgt)
}
func (hak *Hak) SetModLibDirs(target string) error {
var x C.int
var tgt *C.char
tgt = C.CString(target) // TODO: need error check?
defer C.free(unsafe.Pointer(tgt))
x = C.hak_setoption(hak.c, C.HAK_OPT_MODLIBDIRS_BCSTR, unsafe.Pointer(tgt))
if x <= -1 { return hak.make_errinfo() }
return nil
} }
func (hak *Hak) Ignite(memsize uintptr) error { func (hak *Hak) Ignite(memsize uintptr) error {
+127 -47
View File
@@ -380,11 +380,28 @@ void hak_fini (hak_t* hak)
} }
} }
if (hak->option.incdirs.ptr) if (hak->option.modlibdirs_b)
{ {
hak_freemem(hak, hak->option.incdirs.ptr); hak_freemem(hak, hak->option.modlibdirs_b);
hak->option.incdirs.ptr = HAK_NULL; hak->option.modlibdirs_b = HAK_NULL;
hak->option.incdirs.len = 0; }
if (hak->option.modlibdirs_u)
{
hak_freemem(hak, hak->option.modlibdirs_u);
hak->option.modlibdirs_u = HAK_NULL;
}
if (hak->option.incdirs_b)
{
hak_freemem(hak, hak->option.incdirs_b);
hak->option.incdirs_b = HAK_NULL;
}
if (hak->option.incdirs_u)
{
hak_freemem(hak, hak->option.incdirs_u);
hak->option.incdirs_u = HAK_NULL;
} }
if (hak->inttostr.xbuf.ptr) if (hak->inttostr.xbuf.ptr)
@@ -462,28 +479,74 @@ static int dup_str_opt (hak_t* hak, const hak_ooch_t* value, hak_oocs_t* tmp)
return 0; return 0;
} }
/* Store a string option in both representations at once.
*
* The consumers of these options are byte oriented - dlopen() and fopen() -
* so the bch form is what gets used, and converting once here saves a
* conversion on every module load and every include attempt. The uch form is
* kept so getoption can answer in either encoding without allocating.
*
* Both conversions are done before either slot is replaced, so a failure
* leaves the previous value in place rather than half-updating it. */
static int set_dual_str_opt (hak_t* hak, const void* value, int value_is_bch, hak_bch_t** bp, hak_uch_t** up)
{
hak_bch_t* v_b;
hak_uch_t* v_u;
if (value_is_bch)
{
v_b = hak_dupbcstr(hak, (const hak_bch_t*)value, HAK_NULL);
if (HAK_UNLIKELY(!v_b)) return -1;
v_u = hak_dupbtoucstr(hak, (const hak_bch_t*)value, HAK_NULL);
if (HAK_UNLIKELY(!v_u))
{
hak_freemem(hak, v_b);
return -1;
}
}
else
{
v_u = hak_dupucstr(hak, (const hak_uch_t*)value, HAK_NULL);
if (HAK_UNLIKELY(!v_u)) return -1;
v_b = hak_duputobcstr(hak, (const hak_uch_t*)value, HAK_NULL);
if (HAK_UNLIKELY(!v_b))
{
hak_freemem(hak, v_u);
return -1;
}
}
if (*bp) hak_freemem(hak, *bp);
if (*up) hak_freemem(hak, *up);
*bp = v_b;
*up = v_u;
return 0;
}
int hak_setoption (hak_t* hak, hak_option_t id, const void* value) int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
{ {
hak_cb_t* cb; hak_cb_t* cb;
switch (id) switch (id)
{ {
case HAK_TRAIT: case HAK_OPT_TRAIT:
hak->option.trait = *(const hak_bitmask_t*)value; hak->option.trait = *(const hak_bitmask_t*)value;
#if defined(HAK_BUILD_DEBUG) #if defined(HAK_BUILD_DEBUG)
hak->option.karatsuba_cutoff = ((hak->option.trait & HAK_TRAIT_DEBUG_BIGINT)? HAK_KARATSUBA_CUTOFF_DEBUG: HAK_KARATSUBA_CUTOFF); hak->option.karatsuba_cutoff = ((hak->option.trait & HAK_TRAIT_DEBUG_BIGINT)? HAK_KARATSUBA_CUTOFF_DEBUG: HAK_KARATSUBA_CUTOFF);
#endif #endif
break; break;
case HAK_LOG_MASK: case HAK_OPT_LOG_MASK:
hak->option.log_mask = *(const hak_bitmask_t*)value; hak->option.log_mask = *(const hak_bitmask_t*)value;
break; break;
case HAK_LOG_MAXCAPA: case HAK_OPT_LOG_MAXCAPA:
hak->option.log_maxcapa = *(hak_oow_t*)value; hak->option.log_maxcapa = *(hak_oow_t*)value;
break; break;
case HAK_LOG_TARGET_BCSTR: case HAK_OPT_LOG_TARGET_BCSTR:
{ {
hak_bch_t* v1; hak_bch_t* v1;
hak_uch_t* v2; hak_uch_t* v2;
@@ -503,7 +566,7 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_LOG_TARGET_UCSTR: case HAK_OPT_LOG_TARGET_UCSTR:
{ {
hak_uch_t* v1; hak_uch_t* v1;
hak_bch_t* v2; hak_bch_t* v2;
@@ -523,7 +586,7 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_LOG_TARGET_BCS: case HAK_OPT_LOG_TARGET_BCS:
{ {
hak_bch_t* v1; hak_bch_t* v1;
hak_uch_t* v2; hak_uch_t* v2;
@@ -544,7 +607,7 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_LOG_TARGET_UCS: case HAK_OPT_LOG_TARGET_UCS:
{ {
hak_uch_t* v1; hak_uch_t* v1;
hak_bch_t* v2; hak_bch_t* v2;
@@ -565,7 +628,7 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_SYMTAB_SIZE: case HAK_OPT_SYMTAB_SIZE:
{ {
hak_oow_t w; hak_oow_t w;
@@ -576,7 +639,7 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_SYSDIC_SIZE: case HAK_OPT_SYSDIC_SIZE:
{ {
hak_oow_t w; hak_oow_t w;
@@ -587,7 +650,7 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_PROCSTK_SIZE: case HAK_OPT_PROCSTK_SIZE:
{ {
hak_oow_t w; hak_oow_t w;
@@ -598,7 +661,7 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_EXSTK_SIZE: case HAK_OPT_EXSTK_SIZE:
{ {
hak_oow_t w; hak_oow_t w;
@@ -609,7 +672,7 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_CLSTK_SIZE: case HAK_OPT_CLSTK_SIZE:
{ {
hak_oow_t w; hak_oow_t w;
@@ -620,34 +683,40 @@ int hak_setoption (hak_t* hak, hak_option_t id, const void* value)
break; break;
} }
case HAK_MOD_LIBDIRS: case HAK_OPT_MODLIBDIRS_BCSTR:
case HAK_MOD_PREFIX: if (set_dual_str_opt(hak, value, 1, &hak->option.modlibdirs_b, &hak->option.modlibdirs_u) <= -1) return -1;
case HAK_MOD_POSTFIX: break;
case HAK_OPT_MODLIBDIRS_UCSTR:
if (set_dual_str_opt(hak, value, 0, &hak->option.modlibdirs_b, &hak->option.modlibdirs_u) <= -1) return -1;
break;
case HAK_OPT_MODPREFIX:
case HAK_OPT_MODPOSTFIX:
{ {
hak_oocs_t tmp; hak_oocs_t tmp;
int idx; int idx;
if (dup_str_opt(hak, (const hak_ooch_t*)value, &tmp) <= -1) return -1; if (dup_str_opt(hak, (const hak_ooch_t*)value, &tmp) <= -1) return -1;
idx = id - HAK_MOD_LIBDIRS; idx = id - HAK_OPT_MODPREFIX;
if (hak->option.mod[idx].ptr) hak_freemem(hak, hak->option.mod[idx].ptr); if (hak->option.mod[idx].ptr) hak_freemem(hak, hak->option.mod[idx].ptr);
hak->option.mod[idx] = tmp; hak->option.mod[idx] = tmp;
return 0; return 0;
} }
case HAK_MOD_INCTX: case HAK_OPT_MODINCTX:
hak->option.mod_inctx = *(void**)value; hak->option.mod_inctx = *(void**)value;
break; break;
case HAK_OPT_INCDIRS: case HAK_OPT_INCDIRS_BCSTR:
{ if (set_dual_str_opt(hak, value, 1, &hak->option.incdirs_b, &hak->option.incdirs_u) <= -1) return -1;
hak_oocs_t tmp; break;
if (dup_str_opt(hak, value, &tmp) <= -1) return -1;
if (hak->option.incdirs.ptr) hak_freemem(hak, hak->option.incdirs.ptr); case HAK_OPT_INCDIRS_UCSTR:
hak->option.incdirs = tmp; if (set_dual_str_opt(hak, value, 0, &hak->option.incdirs_b, &hak->option.incdirs_u) <= -1) return -1;
break; break;
}
default: default:
goto einval; goto einval;
@@ -669,68 +738,79 @@ int hak_getoption (hak_t* hak, hak_option_t id, void* value)
{ {
switch (id) switch (id)
{ {
case HAK_TRAIT: case HAK_OPT_TRAIT:
*(hak_bitmask_t*)value = hak->option.trait; *(hak_bitmask_t*)value = hak->option.trait;
return 0; return 0;
case HAK_LOG_MASK: case HAK_OPT_LOG_MASK:
*(hak_bitmask_t*)value = hak->option.log_mask; *(hak_bitmask_t*)value = hak->option.log_mask;
return 0; return 0;
case HAK_LOG_MAXCAPA: case HAK_OPT_LOG_MAXCAPA:
*(hak_oow_t*)value = hak->option.log_maxcapa; *(hak_oow_t*)value = hak->option.log_maxcapa;
return 0; return 0;
case HAK_LOG_TARGET_BCSTR: case HAK_OPT_LOG_TARGET_BCSTR:
*(hak_bch_t**)value = hak->option.log_target_b; *(hak_bch_t**)value = hak->option.log_target_b;
return 0; return 0;
case HAK_LOG_TARGET_UCSTR: case HAK_OPT_LOG_TARGET_UCSTR:
*(hak_uch_t**)value = hak->option.log_target_u; *(hak_uch_t**)value = hak->option.log_target_u;
return 0; return 0;
case HAK_LOG_TARGET_BCS: case HAK_OPT_LOG_TARGET_BCS:
((hak_bcs_t*)value)->ptr = hak->option.log_target_b; ((hak_bcs_t*)value)->ptr = hak->option.log_target_b;
((hak_bcs_t*)value)->len = hak_count_bcstr(hak->option.log_target_b); ((hak_bcs_t*)value)->len = hak_count_bcstr(hak->option.log_target_b);
return 0; return 0;
case HAK_LOG_TARGET_UCS: case HAK_OPT_LOG_TARGET_UCS:
((hak_ucs_t*)value)->ptr = hak->option.log_target_u; ((hak_ucs_t*)value)->ptr = hak->option.log_target_u;
((hak_ucs_t*)value)->len = hak_count_ucstr(hak->option.log_target_u); ((hak_ucs_t*)value)->len = hak_count_ucstr(hak->option.log_target_u);
return 0; return 0;
case HAK_SYMTAB_SIZE: case HAK_OPT_SYMTAB_SIZE:
*(hak_oow_t*)value = hak->option.dfl_symtab_size; *(hak_oow_t*)value = hak->option.dfl_symtab_size;
return 0; return 0;
case HAK_SYSDIC_SIZE: case HAK_OPT_SYSDIC_SIZE:
*(hak_oow_t*)value = hak->option.dfl_sysdic_size; *(hak_oow_t*)value = hak->option.dfl_sysdic_size;
return 0; return 0;
case HAK_PROCSTK_SIZE: case HAK_OPT_PROCSTK_SIZE:
*(hak_oow_t*)value = hak->option.dfl_procstk_size; *(hak_oow_t*)value = hak->option.dfl_procstk_size;
return 0; return 0;
case HAK_EXSTK_SIZE: case HAK_OPT_EXSTK_SIZE:
*(hak_oow_t*)value = hak->option.dfl_exstk_size; *(hak_oow_t*)value = hak->option.dfl_exstk_size;
return 0; return 0;
case HAK_CLSTK_SIZE: case HAK_OPT_CLSTK_SIZE:
*(hak_oow_t*)value = hak->option.dfl_clstk_size; *(hak_oow_t*)value = hak->option.dfl_clstk_size;
return 0; return 0;
case HAK_MOD_LIBDIRS: case HAK_OPT_MODLIBDIRS_BCSTR:
case HAK_MOD_PREFIX: *(const hak_bch_t**)value = hak->option.modlibdirs_b;
case HAK_MOD_POSTFIX:
*(const hak_ooch_t**)value = hak->option.mod[id - HAK_MOD_LIBDIRS].ptr;
return 0; return 0;
case HAK_MOD_INCTX: case HAK_OPT_MODLIBDIRS_UCSTR:
*(const hak_uch_t**)value = hak->option.modlibdirs_u;
return 0;
case HAK_OPT_MODPREFIX:
case HAK_OPT_MODPOSTFIX:
*(const hak_ooch_t**)value = hak->option.mod[id - HAK_OPT_MODPREFIX].ptr;
return 0;
case HAK_OPT_MODINCTX:
*(void**)value = hak->option.mod_inctx; *(void**)value = hak->option.mod_inctx;
return 0; return 0;
case HAK_OPT_INCDIRS: case HAK_OPT_INCDIRS_BCSTR:
*(const hak_ooch_t**)value = hak->option.incdirs.ptr; *(const hak_bch_t**)value = hak->option.incdirs_b;
return 0;
case HAK_OPT_INCDIRS_UCSTR:
*(const hak_uch_t**)value = hak->option.incdirs_u;
return 0; return 0;
}; };
+49 -25
View File
@@ -241,36 +241,50 @@ typedef hak_errbinf_t hak_errinf_t;
enum hak_option_t enum hak_option_t
{ {
HAK_TRAIT, HAK_OPT_TRAIT,
HAK_LOG_MASK, HAK_OPT_LOG_MASK,
HAK_LOG_MAXCAPA, HAK_OPT_LOG_MAXCAPA,
HAK_LOG_TARGET_BCSTR, HAK_OPT_LOG_TARGET_BCSTR,
HAK_LOG_TARGET_UCSTR, HAK_OPT_LOG_TARGET_UCSTR,
HAK_LOG_TARGET_BCS, HAK_OPT_LOG_TARGET_BCS,
HAK_LOG_TARGET_UCS, HAK_OPT_LOG_TARGET_UCS,
#if defined(HAK_OOCH_IS_UCH) #if defined(HAK_OOCH_IS_UCH)
# define HAK_LOG_TARGET HAK_LOG_TARGET_UCSTR # define HAK_OPT_LOG_TARGET HAK_OPT_LOG_TARGET_UCSTR
# define HAK_LOG_TARGET_OOCSTR HAK_LOG_TARGET_UCSTR # define HAK_OPT_LOG_TARGET_OOCSTR HAK_OPT_LOG_TARGET_UCSTR
# define HAK_LOG_TARGET_OOCS HAK_LOG_TARGET_UCS # define HAK_OPT_LOG_TARGET_OOCS HAK_OPT_LOG_TARGET_UCS
#else #else
# define HAK_LOG_TARGET HAK_LOG_TARGET_BCSTR # define HAK_OPT_LOG_TARGET HAK_OPT_LOG_TARGET_BCSTR
# define HAK_LOG_TARGET_OOCSTR HAK_LOG_TARGET_BCSTR # define HAK_OPT_LOG_TARGET_OOCSTR HAK_OPT_LOG_TARGET_BCSTR
# define HAK_LOG_TARGET_OOCS HAK_LOG_TARGET_BCS # define HAK_OPT_LOG_TARGET_OOCS HAK_OPT_LOG_TARGET_BCS
#endif #endif
HAK_SYMTAB_SIZE, /* default system table size */ HAK_OPT_SYMTAB_SIZE, /* default system table size */
HAK_SYSDIC_SIZE, /* default system dictionary size */ HAK_OPT_SYSDIC_SIZE, /* default system dictionary size */
HAK_PROCSTK_SIZE, /* default process stack size */ HAK_OPT_PROCSTK_SIZE, /* default process stack size */
HAK_EXSTK_SIZE, /* default exception stack size */ HAK_OPT_EXSTK_SIZE, /* default exception stack size */
HAK_CLSTK_SIZE, /* default class stack size */ HAK_OPT_CLSTK_SIZE, /* default class stack size */
HAK_MOD_LIBDIRS, HAK_OPT_MODLIBDIRS_BCSTR,
HAK_MOD_PREFIX, HAK_OPT_MODLIBDIRS_UCSTR,
HAK_MOD_POSTFIX, #if defined(HAK_OOCH_IS_UCH)
# define HAK_OPT_MODLIBDIRS HAK_OPT_MODLIBDIRS_UCSTR
#else
# define HAK_OPT_MODLIBDIRS HAK_OPT_MODLIBDIRS_BCSTR
#endif
HAK_MOD_INCTX, HAK_OPT_MODPREFIX,
HAK_OPT_INCDIRS HAK_OPT_MODPOSTFIX,
HAK_OPT_MODINCTX,
HAK_OPT_INCDIRS_BCSTR,
HAK_OPT_INCDIRS_UCSTR
#if defined(HAK_OOCH_IS_UCH)
# define HAK_OPT_INCDIRS HAK_OPT_INCDIRS_UCSTR
#else
# define HAK_OPT_INCDIRS HAK_OPT_INCDIRS_BCSTR
#endif
}; };
typedef enum hak_option_t hak_option_t; typedef enum hak_option_t hak_option_t;
@@ -1787,8 +1801,18 @@ struct hak_t
hak_oow_t dfl_clstk_size; hak_oow_t dfl_clstk_size;
void* mod_inctx; void* mod_inctx;
hak_oocs_t mod[3]; /* both representations are kept for the two options whose consumers
hak_oocs_t incdirs; * are byte oriented: dl_open() feeds dlopen() and open_cci_stream()
* feeds fopen(), so the bch form is what actually gets used, while the
* uch form serves getoption and %js. converting once at set time beats
* converting on every module load and every include attempt. */
hak_bch_t* modlibdirs_b;
hak_uch_t* modlibdirs_u;
hak_bch_t* incdirs_b;
hak_uch_t* incdirs_u;
/* prefix and postfix only - indexed by (id - HAK_OPT_MODPREFIX) */
hak_oocs_t mod[2];
#if defined(HAK_BUILD_DEBUG) #if defined(HAK_BUILD_DEBUG)
/* set automatically when trait is set */ /* set automatically when trait is set */
+2 -2
View File
@@ -952,7 +952,7 @@ hak_json_t* hak_json_open (hak_mmgr_t* mmgr, hak_oow_t xtnsize, hak_json_prim_t*
/* the dummy hak is used for this json to perform primitive operations /* the dummy hak is used for this json to perform primitive operations
* such as getting system time or logging. so the heap size doesn't * such as getting system time or logging. so the heap size doesn't
* need to be changed from the tiny value set above. */ * need to be changed from the tiny value set above. */
hak_setoption(json->dummy_hak, HAK_LOG_MASK, &json->cfg.logmask); hak_setoption(json->dummy_hak, HAK_OPT_LOG_MASK, &json->cfg.logmask);
hak_setcmgr(json->dummy_hak, json->cmgr); hak_setcmgr(json->dummy_hak, json->cmgr);
@@ -987,7 +987,7 @@ int hak_json_setoption (hak_json_t* json, hak_json_option_t id, const void* valu
* existing hak instances inside worker threads won't get * existing hak instances inside worker threads won't get
* affected. new hak instances to be created later * affected. new hak instances to be created later
* is supposed to use the new value */ * is supposed to use the new value */
hak_setoption(json->dummy_hak, HAK_LOG_MASK, value); hak_setoption(json->dummy_hak, HAK_OPT_LOG_MASK, value);
} }
return 0; return 0;
} }
+81 -32
View File
@@ -3712,11 +3712,17 @@ static void dl_cleanup (hak_t* hak)
#endif #endif
} }
static void* dlopen_pfmod (hak_t* hak, const hak_ooch_t* name, const hak_ooch_t* dirptr, const hak_oow_t dirlen, hak_bch_t* bufptr, hak_oow_t bufcapa) /* [NOTE] dirptr/dirlen is a byte string - it is a segment of the modlibdirs
* option, which is stored in the byte form precisely because it ends up
* here and in dlopen(). only 'name' still needs converting. */
static void* dlopen_pfmod (hak_t* hak, const hak_ooch_t* name, const hak_bch_t* dirptr, const hak_oow_t dirlen, hak_bch_t* bufptr, hak_oow_t bufcapa)
{ {
void* handle; void* handle;
hak_oow_t len, i, xlen, dlen; hak_oow_t len, i, xlen, dlen;
hak_oow_t ucslen, bcslen; hak_oow_t bcslen;
#if defined(HAK_OOCH_IS_UCH)
hak_oow_t ucslen;
#endif
/* opening a primitive function module - mostly libhak-xxxx. /* opening a primitive function module - mostly libhak-xxxx.
* if PFMODPREFIX is absolute, never use PFMODDIR */ * if PFMODPREFIX is absolute, never use PFMODDIR */
@@ -3727,13 +3733,7 @@ static void* dlopen_pfmod (hak_t* hak, const hak_ooch_t* name, const hak_ooch_t*
} }
else if (dirptr) else if (dirptr)
{ {
xlen = dirlen;
dlen = bufcapa;
#if defined(HAK_OOCH_IS_UCH)
if (hak_convootobchars(hak, dirptr, &xlen, bufptr, &dlen) <= -1) return HAK_NULL;
#else
dlen = hak_copy_bchars_to_bcstr(bufptr, bufcapa, dirptr, dirlen); dlen = hak_copy_bchars_to_bcstr(bufptr, bufcapa, dirptr, dirlen);
#endif
if (dlen > 0 && bufptr[dlen - 1] != HAK_DFL_PATH_SEP) if (dlen > 0 && bufptr[dlen - 1] != HAK_DFL_PATH_SEP)
{ {
@@ -3869,25 +3869,28 @@ static void* dl_open (hak_t* hak, const hak_ooch_t* name, int flags)
{ {
#if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD) #if defined(USE_LTDL) || defined(USE_DLFCN) || defined(USE_MACH_O_DYLD)
hak_bch_t stabuf[128], * bufptr; hak_bch_t stabuf[128], * bufptr;
hak_oow_t ucslen, bcslen, bufcapa;
void* handle = HAK_NULL; void* handle = HAK_NULL;
hak_oow_t bufcapa;
const hak_bch_t* modlibdirs;
#if defined(HAK_OOCH_IS_UCH)
hak_oow_t ucslen;
#endif
modlibdirs = hak->option.modlibdirs_b;
#if defined(HAK_OOCH_IS_UCH) #if defined(HAK_OOCH_IS_UCH)
if (hak_convootobcstr(hak, name, &ucslen, HAK_NULL, &bufcapa) <= -1) return HAK_NULL; if (hak_convootobcstr(hak, name, &ucslen, HAK_NULL, &bufcapa) <= -1) return HAK_NULL;
if (hak->option.mod[0].len > 0)
{
/* multiple directories separated by a colon can be specified for HAK_MOD_LIBDIRS
* however, use the total length to secure space just for simplicity */
ucslen = hak->option.mod[0].len;
if (hak_convootobchars(hak, hak->option.mod[0].ptr, &ucslen, HAK_NULL, &bcslen) <= -1) return HAK_NULL;
bufcapa += bcslen;
}
#else #else
bufcapa = hak_count_bcstr(name); bufcapa = hak_count_bcstr(name);
bufcapa += (hak->option.mod[0].len > 0)? hak->option.mod[0].len: HAK_COUNTOF(HAK_DEFAULT_PFMODDIR);
#endif #endif
/* modlibdirs is stored in the byte form too, so no conversion is needed
* here. multiple directories separated by a colon can be specified for
* HAK_OPT_MODLIBDIRS - use the total length to secure space, for
* simplicity. */
bufcapa += (modlibdirs && modlibdirs[0] != '\0')?
hak_count_bcstr(modlibdirs): HAK_COUNTOF(HAK_DEFAULT_PFMODDIR);
/* HAK_COUNTOF(HAK_DEFAULT_PFMODPREFIX) and HAK_COUNTOF(HAK_DEFAULT_PFMODPOSTIFX) /* HAK_COUNTOF(HAK_DEFAULT_PFMODPREFIX) and HAK_COUNTOF(HAK_DEFAULT_PFMODPOSTIFX)
* include the terminating nulls. Never mind about the extra 2 characters. */ * include the terminating nulls. Never mind about the extra 2 characters. */
bufcapa += HAK_COUNTOF(HAK_DEFAULT_PFMODPREFIX) + HAK_COUNTOF(HAK_DEFAULT_PFMODPOSTFIX) + 1; bufcapa += HAK_COUNTOF(HAK_DEFAULT_PFMODPREFIX) + HAK_COUNTOF(HAK_DEFAULT_PFMODPOSTFIX) + 1;
@@ -3901,12 +3904,12 @@ static void* dl_open (hak_t* hak, const hak_ooch_t* name, int flags)
if (flags & HAK_VMPRIM_DLOPEN_PFMOD) if (flags & HAK_VMPRIM_DLOPEN_PFMOD)
{ {
if (hak->option.mod[0].len > 0) if (modlibdirs && modlibdirs[0] != '\0')
{ {
const hak_ooch_t* ptr, * end, * seg; const hak_bch_t* ptr, * end, * seg;
ptr = hak->option.mod[0].ptr; ptr = modlibdirs;
end = hak->option.mod[0].ptr + hak->option.mod[0].len; end = modlibdirs + hak_count_bcstr(modlibdirs);
seg = ptr; seg = ptr;
while (ptr <= end) while (ptr <= end)
@@ -4109,8 +4112,8 @@ static void cb_on_option (hak_t* hak, hak_option_t id, const void* value)
xtn_t* xtn = GET_XTN(hak); xtn_t* xtn = GET_XTN(hak);
int fd; int fd;
if (id != HAK_LOG_TARGET_BCSTR && id != HAK_LOG_TARGET_UCSTR && if (id != HAK_OPT_LOG_TARGET_BCSTR && id != HAK_OPT_LOG_TARGET_UCSTR &&
id != HAK_LOG_TARGET_BCS && id != HAK_LOG_TARGET_UCS) return; /* return success. not interested */ id != HAK_OPT_LOG_TARGET_BCS && id != HAK_OPT_LOG_TARGET_UCS) return; /* return success. not interested */
#if defined(_WIN32) #if defined(_WIN32)
#if defined(HAK_OOCH_IS_UCH) && (HAK_SIZEOF_UCH_T == HAK_SIZEOF_WCHAR_T) #if defined(HAK_OOCH_IS_UCH) && (HAK_SIZEOF_UCH_T == HAK_SIZEOF_WCHAR_T)
@@ -4663,12 +4666,13 @@ static HAK_INLINE int open_cci_stream (hak_t* hak, hak_io_cciarg_t* arg)
xtn_t* xtn = GET_XTN(hak); xtn_t* xtn = GET_XTN(hak);
bb_t* bb = HAK_NULL; bb_t* bb = HAK_NULL;
/* TOOD: support predefined include directory as well */
if (arg->includer) if (arg->includer)
{ {
/* includee */ /* includee */
hak_oow_t ucslen, bcslen, parlen; hak_oow_t ucslen, bcslen, parlen;
const hak_bch_t* fn, * fb; const hak_bch_t* fn, * fb;
int attempt_incdirs;
const hak_bch_t* incdirs_ptr;
#if defined(HAK_OOCH_IS_UCH) #if defined(HAK_OOCH_IS_UCH)
if (hak_convootobcstr(hak, arg->name, &ucslen, HAK_NULL, &bcslen) <= -1) goto oops; if (hak_convootobcstr(hak, arg->name, &ucslen, HAK_NULL, &bcslen) <= -1) goto oops;
@@ -4682,27 +4686,63 @@ static HAK_INLINE int open_cci_stream (hak_t* hak, hak_io_cciarg_t* arg)
{ {
fb = ""; fb = "";
parlen = 0; parlen = 0;
attempt_incdirs = 0;
} }
else else
{ {
fb = hak_get_base_name_from_bcstr_path(fn); fb = hak_get_base_name_from_bcstr_path(fn);
parlen = fb - fn; parlen = fb - fn;
attempt_incdirs = !((arg->name[0] == '.' && arg->name[1] == '/') || (arg->name[0] == '.' && arg->name[1] == '.' && arg->name[2] == '/'));
} }
bb = (bb_t*)hak_callocmem(hak, HAK_SIZEOF(*bb) + (HAK_SIZEOF(hak_bch_t) * (parlen + bcslen + 1))); bb = (bb_t*)hak_callocmem(hak, HAK_SIZEOF(*bb) + (HAK_SIZEOF(hak_bch_t) * (parlen + bcslen + 1)));
if (!bb) goto oops; if (HAK_UNLIKELY(!bb)) goto oops;
bb->fn = (hak_bch_t*)(bb + 1); bb->fn = (hak_bch_t*)(bb + 1);
hak_copy_bchars (bb->fn, fn, parlen); hak_copy_bchars(bb->fn, fn, parlen);
#if defined(HAK_OOCH_IS_UCH) #if defined(HAK_OOCH_IS_UCH)
hak_convootobcstr(hak, arg->name, &ucslen, &bb->fn[parlen], &bcslen); hak_convootobcstr(hak, arg->name, &ucslen, &bb->fn[parlen], &bcslen);
#else #else
hak_copy_bcstr(&bb->fn[parlen], bcslen + 1, arg->name); hak_copy_bcstr(&bb->fn[parlen], bcslen + 1, arg->name);
#endif #endif
incdirs_ptr = hak->option.incdirs_b;
retry:
bb->fp = fopen(bb->fn, FOPEN_R_FLAGS); bb->fp = fopen(bb->fn, FOPEN_R_FLAGS);
if (!bb->fp) if (!bb->fp)
{ {
if ((errno == ENOENT || errno == ENOTDIR) && attempt_incdirs && incdirs_ptr && incdirs_ptr[0] != '\0')
{
hak_oow_t incdir_bcslen;
const hak_bch_t* colon;
hak_freemem(hak, bb); bb = HAK_NULL;
/* incdirs is kept in the byte form as well, so the directory part
* needs no conversion here - only the include name does. */
colon = hak_find_bchar_in_bcstr(incdirs_ptr, ':');
incdir_bcslen = colon? (hak_oow_t)(colon - incdirs_ptr): hak_count_bcstr(incdirs_ptr);
bb = (bb_t*)hak_callocmem(hak, HAK_SIZEOF(*bb) + (HAK_SIZEOF(hak_bch_t) * (incdir_bcslen + bcslen + 2)));
if (HAK_UNLIKELY(!bb)) goto oops;
bb->fn = (hak_bch_t*)(bb + 1);
/* TODO: i need to support different directory separator */
hak_copy_bchars(bb->fn, incdirs_ptr, incdir_bcslen);
if (incdir_bcslen > 0 && bb->fn[incdir_bcslen - 1] != '/') bb->fn[incdir_bcslen++] = '/';
#if defined(HAK_OOCH_IS_UCH)
hak_convootobcstr(hak, arg->name, &ucslen, &bb->fn[incdir_bcslen], &bcslen);
#else
hak_copy_bcstr(&bb->fn[incdir_bcslen], bcslen + 1, arg->name);
#endif
incdirs_ptr = colon? colon + 1: HAK_NULL;
/*printf("RETRYING bb->fn [%s]\n", bb->fn);*/
goto retry;
}
hak_seterrbfmt(hak, HAK_EIOERR, "unable to open %hs", bb->fn); hak_seterrbfmt(hak, HAK_EIOERR, "unable to open %hs", bb->fn);
goto oops; goto oops;
} }
@@ -4710,6 +4750,15 @@ static HAK_INLINE int open_cci_stream (hak_t* hak, hak_io_cciarg_t* arg)
else else
{ {
/* main stream */ /* main stream */
/* [NOTE]
* in the current implementation, the main stream is rarely used read
* because the input the the reader/compiler is fed via hak_feed() and its relatives.
* this part doesn't really open the specified file.
*/
/* TODO: make if hak_feed() is going to be used or not.
* if it's not used, it can open it as usual as xtn->cci_path point to the file name anyways */
hak_oow_t pathlen; hak_oow_t pathlen;
pathlen = xtn->cci_path? hak_count_bcstr(xtn->cci_path): 0; pathlen = xtn->cci_path? hak_count_bcstr(xtn->cci_path): 0;
@@ -4822,7 +4871,7 @@ static HAK_INLINE int read_cci_stream (hak_t* hak, hak_io_cciarg_t* arg)
#else #else
bcslen = (bb->len < HAK_COUNTOF(arg->buf.c))? bb->len: HAK_COUNTOF(arg->buf.c); bcslen = (bb->len < HAK_COUNTOF(arg->buf.c))? bb->len: HAK_COUNTOF(arg->buf.c);
ucslen = bcslen; ucslen = bcslen;
hak_copy_bchars (arg->buf.c, bb->buf, bcslen); hak_copy_bchars(arg->buf.c, bb->buf, bcslen);
#endif #endif
remlen = bb->len - bcslen; remlen = bb->len - bcslen;
@@ -4973,7 +5022,7 @@ static HAK_INLINE int read_udi_stream (hak_t* hak, hak_io_udiarg_t* arg)
#else #else
bcslen = (bb->len < HAK_COUNTOF(arg->buf.c))? bb->len: HAK_COUNTOF(arg->buf.c); bcslen = (bb->len < HAK_COUNTOF(arg->buf.c))? bb->len: HAK_COUNTOF(arg->buf.c);
ucslen = bcslen; ucslen = bcslen;
hak_copy_bchars (arg->buf.c, bb->buf, bcslen); hak_copy_bchars(arg->buf.c, bb->buf, bcslen);
#endif #endif
remlen = bb->len - bcslen; remlen = bb->len - bcslen;
@@ -5016,7 +5065,7 @@ static HAK_INLINE int read_udi_stream_bytes (hak_t* hak, hak_io_udiarg_t* arg)
bcslen = (bb->len < HAK_COUNTOF(arg->buf.b))? bb->len: HAK_COUNTOF(arg->buf.b); bcslen = (bb->len < HAK_COUNTOF(arg->buf.b))? bb->len: HAK_COUNTOF(arg->buf.b);
ucslen = bcslen; ucslen = bcslen;
hak_copy_bchars ((hak_bch_t*)arg->buf.b, bb->buf, bcslen); hak_copy_bchars((hak_bch_t*)arg->buf.b, bb->buf, bcslen);
remlen = bb->len - bcslen; remlen = bb->len - bcslen;
if (remlen > 0) HAK_MEMMOVE(bb->buf, &bb->buf[bcslen], remlen); if (remlen > 0) HAK_MEMMOVE(bb->buf, &bb->buf[bcslen], remlen);
@@ -5113,7 +5162,7 @@ static HAK_INLINE int write_udo_stream (hak_t* hak, hak_io_udoarg_t* arg)
ucslen = arg->len - donelen; ucslen = arg->len - donelen;
if (ucslen > bcslen) ucslen = bcslen; if (ucslen > bcslen) ucslen = bcslen;
else if (ucslen < bcslen) bcslen = ucslen; else if (ucslen < bcslen) bcslen = ucslen;
hak_copy_bchars (bcsbuf, &ptr[donelen], bcslen); hak_copy_bchars(bcsbuf, &ptr[donelen], bcslen);
#endif #endif
if (fwrite(bcsbuf, HAK_SIZEOF(bcsbuf[0]), bcslen, (FILE*)arg->handle) < bcslen) if (fwrite(bcsbuf, HAK_SIZEOF(bcsbuf[0]), bcslen, (FILE*)arg->handle) < bcslen)
+2 -2
View File
@@ -212,7 +212,7 @@ hak_client_t* hak_client_open (hak_mmgr_t* mmgr, hak_oow_t xtnsize, hak_client_p
/* the dummy hak is used for this client to perform primitive operations /* the dummy hak is used for this client to perform primitive operations
* such as getting system time or logging. so the heap size doesn't * such as getting system time or logging. so the heap size doesn't
* need to be changed from the tiny value set above. */ * need to be changed from the tiny value set above. */
hak_setoption (client->dummy_hak, HAK_LOG_MASK, &client->cfg.logmask); hak_setoption (client->dummy_hak, HAK_OPT_LOG_MASK, &client->cfg.logmask);
hak_setcmgr (client->dummy_hak, client->_cmgr); hak_setcmgr (client->dummy_hak, client->_cmgr);
return client; return client;
@@ -258,7 +258,7 @@ int hak_client_setoption (hak_client_t* client, hak_client_option_t id, const vo
* existing hak instances inside worker threads won't get * existing hak instances inside worker threads won't get
* affected. new hak instances to be created later * affected. new hak instances to be created later
* is supposed to use the new value */ * is supposed to use the new value */
hak_setoption (client->dummy_hak, HAK_LOG_MASK, value); hak_setoption (client->dummy_hak, HAK_OPT_LOG_MASK, value);
} }
return 0; return 0;
} }
+10 -10
View File
@@ -1177,14 +1177,14 @@ hak_server_t* hak_server_open (hak_mmgr_t* mmgr, hak_oow_t xtnsize, hak_server_p
/* the dummy hak is used for this server to perform primitive operations /* the dummy hak is used for this server to perform primitive operations
* such as getting system time or logging. so the heap size doesn't * such as getting system time or logging. so the heap size doesn't
* need to be changed from the tiny value set above. */ * need to be changed from the tiny value set above. */
hak_setoption (server->dummy_hak, HAK_LOG_MASK, &server->cfg.logmask); hak_setoption (server->dummy_hak, HAK_OPT_LOG_MASK, &server->cfg.logmask);
hak_setcmgr (server->dummy_hak, hak_server_getcmgr(server)); hak_setcmgr (server->dummy_hak, hak_server_getcmgr(server));
hak_getoption (server->dummy_hak, HAK_TRAIT, &trait); hak_getoption (server->dummy_hak, HAK_OPT_TRAIT, &trait);
#if defined(HAK_BUILD_DEBUG) #if defined(HAK_BUILD_DEBUG)
if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_GC) trait |= HAK_TRAIT_DEBUG_GC; if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_GC) trait |= HAK_TRAIT_DEBUG_GC;
if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_BIGINT) trait |= HAK_TRAIT_DEBUG_BIGINT; if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_BIGINT) trait |= HAK_TRAIT_DEBUG_BIGINT;
#endif #endif
hak_setoption (server->dummy_hak, HAK_TRAIT, &trait); hak_setoption (server->dummy_hak, HAK_OPT_TRAIT, &trait);
return server; return server;
@@ -1517,17 +1517,17 @@ static int init_worker_hak (hak_server_worker_t* worker)
xtn = (worker_hak_xtn_t*)hak_getxtn(hak); xtn = (worker_hak_xtn_t*)hak_getxtn(hak);
xtn->worker = worker; xtn->worker = worker;
hak_setoption(hak, HAK_MOD_INCTX, &server->cfg.module_inctx); hak_setoption(hak, HAK_OPT_MODINCTX, &server->cfg.module_inctx);
hak_setoption(hak, HAK_LOG_MASK, &server->cfg.logmask); hak_setoption(hak, HAK_OPT_LOG_MASK, &server->cfg.logmask);
hak_setcmgr(hak, hak_server_getcmgr(server)); hak_setcmgr(hak, hak_server_getcmgr(server));
hak_getoption(hak, HAK_TRAIT, &trait); hak_getoption(hak, HAK_OPT_TRAIT, &trait);
#if defined(HAK_BUILD_DEBUG) #if defined(HAK_BUILD_DEBUG)
if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_GC) trait |= HAK_TRAIT_DEBUG_GC; if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_GC) trait |= HAK_TRAIT_DEBUG_GC;
if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_BIGINT) trait |= HAK_TRAIT_DEBUG_BIGINT; if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_BIGINT) trait |= HAK_TRAIT_DEBUG_BIGINT;
#endif #endif
trait |= HAK_TRAIT_LANG_ENABLE_EOL; trait |= HAK_TRAIT_LANG_ENABLE_EOL;
hak_setoption(hak, HAK_TRAIT, &trait); hak_setoption(hak, HAK_OPT_TRAIT, &trait);
HAK_MEMSET(&hakcb, 0, HAK_SIZEOF(hakcb)); HAK_MEMSET(&hakcb, 0, HAK_SIZEOF(hakcb));
/*hakcb.fini = fini_hak; /*hakcb.fini = fini_hak;
@@ -2050,12 +2050,12 @@ int hak_server_setoption (hak_server_t* server, hak_server_option_t id, const vo
* is supposed to use the new value */ * is supposed to use the new value */
hak_bitmask_t trait; hak_bitmask_t trait;
hak_getoption (server->dummy_hak, HAK_TRAIT, &trait); hak_getoption (server->dummy_hak, HAK_OPT_TRAIT, &trait);
#if defined(HAK_BUILD_DEBUG) #if defined(HAK_BUILD_DEBUG)
if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_GC) trait |= HAK_TRAIT_DEBUG_GC; if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_GC) trait |= HAK_TRAIT_DEBUG_GC;
if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_BIGINT) trait |= HAK_TRAIT_DEBUG_BIGINT; if (server->cfg.trait & HAK_SERVER_TRAIT_DEBUG_BIGINT) trait |= HAK_TRAIT_DEBUG_BIGINT;
#endif #endif
hak_setoption (server->dummy_hak, HAK_TRAIT, &trait); hak_setoption (server->dummy_hak, HAK_OPT_TRAIT, &trait);
} }
return 0; return 0;
@@ -2067,7 +2067,7 @@ int hak_server_setoption (hak_server_t* server, hak_server_option_t id, const vo
* existing hak instances inside worker threads won't get * existing hak instances inside worker threads won't get
* affected. new hak instances to be created later * affected. new hak instances to be created later
* is supposed to use the new value */ * is supposed to use the new value */
hak_setoption (server->dummy_hak, HAK_LOG_MASK, value); hak_setoption (server->dummy_hak, HAK_OPT_LOG_MASK, value);
} }
return 0; return 0;
+3 -14
View File
@@ -115,18 +115,7 @@ static int on_cnode (hak_t* hak, hak_cnode_t* obj)
static int set_modlibdirs (hak_t* hak) static int set_modlibdirs (hak_t* hak)
{ {
#if defined(HAK_TEST_MODLIBDIRS) #if defined(HAK_TEST_MODLIBDIRS)
# if defined(HAK_OOCH_IS_UCH) return hak_setoption(hak, HAK_OPT_MODLIBDIRS_BCSTR, HAK_TEST_MODLIBDIRS);
hak_ooch_t* tmp;
int n;
tmp = hak_dupbtoucstr(hak, HAK_TEST_MODLIBDIRS, HAK_NULL);
if (HAK_UNLIKELY(!tmp)) return -1;
n = hak_setoption(hak, HAK_MOD_LIBDIRS, tmp);
hak_freemem(hak, tmp);
return n;
# else
return hak_setoption(hak, HAK_MOD_LIBDIRS, HAK_TEST_MODLIBDIRS);
# endif
#else #else
return 0; return 0;
#endif #endif
@@ -144,9 +133,9 @@ static void preempts_a_spinner (void)
OK (hak != HAK_NULL, "instantiation"); OK (hak != HAK_NULL, "instantiation");
if (!hak) return; if (!hak) return;
hak_getoption(hak, HAK_TRAIT, &trait); hak_getoption(hak, HAK_OPT_TRAIT, &trait);
trait |= HAK_TRAIT_AWAIT_PROCS | HAK_TRAIT_LANG_ENABLE_EOL; trait |= HAK_TRAIT_AWAIT_PROCS | HAK_TRAIT_LANG_ENABLE_EOL;
hak_setoption(hak, HAK_TRAIT, &trait); hak_setoption(hak, HAK_OPT_TRAIT, &trait);
OK (set_modlibdirs(hak) == 0, "module search path"); OK (set_modlibdirs(hak) == 0, "module search path");
+3 -3
View File
@@ -79,12 +79,12 @@ static int run_at_depth (int depth, int expect_overflow)
OK (hak != HAK_NULL, "instantiation"); OK (hak != HAK_NULL, "instantiation");
if (!hak) goto done; if (!hak) goto done;
hak_getoption(hak, HAK_TRAIT, &trait); hak_getoption(hak, HAK_OPT_TRAIT, &trait);
trait |= HAK_TRAIT_LANG_ENABLE_EOL; trait |= HAK_TRAIT_LANG_ENABLE_EOL;
hak_setoption(hak, HAK_TRAIT, &trait); hak_setoption(hak, HAK_OPT_TRAIT, &trait);
stksize = STK_SLOTS; stksize = STK_SLOTS;
OK (hak_setoption(hak, HAK_PROCSTK_SIZE, &stksize) == 0, "process stack size"); OK (hak_setoption(hak, HAK_OPT_PROCSTK_SIZE, &stksize) == 0, "process stack size");
OK (hak_ignite(hak, 0) == 0, "ignition"); OK (hak_ignite(hak, 0) == 0, "ignition");
OK (hak_addbuiltinprims(hak) == 0, "builtin primitives"); OK (hak_addbuiltinprims(hak) == 0, "builtin primitives");