added hsargs, hsexit and bundler mode

This commit is contained in:
Luxferre
2026-07-04 08:52:56 +03:00
parent 10f0b39d8e
commit 4fc3ee518a
7 changed files with 116 additions and 1 deletions
+8
View File
@@ -313,6 +313,12 @@ func (c *Clyx) Eval(q any) {
}
}
func (c *Clyx) HasWord(name string) bool {
_, ok := c.words[name]
return ok
}
func printVal(v any) {
switch val := v.(type) {
case int64: fmt.Printf("%d\n", val)
@@ -420,6 +426,8 @@ func NewClyx(libfname string, libCode string) *Clyx {
c.words[".s"] = func() { printVal(c.reprStack()) }
c.words["dip"] = func() { q, y := c.pop().([]any), c.pop(); c.execQuot(q); c.stack = append(c.stack, y) }
c.words["loop"] = func() { body, cond := c.pop().([]any), c.pop().([]any); for { c.execQuot(cond); if !isTruthy(c.pop()) { break }; c.execQuot(body) } }
c.words["hsargs"] = func() { c.stack = append(c.stack, toAnySlice(os.Args)) }
c.words["hsexit"] = func() { os.Exit(int(toInt(c.pop()))) }
c.words["hseval"] = func() { fmt.Fprintln(os.Stderr, "Error: unsupported word"); os.Exit(1) }
c.words["chr"] = func() { c.stack = append(c.stack, string(rune(toInt(c.pop())))) }
c.words["asc"] = func() { s := c.pop().(string); r, _ := utf8.DecodeRuneInString(s); c.stack = append(c.stack, int64(r)) }