This commit is contained in:
2024-05-14 12:10:58 +02:00
parent a9bb79b01c
commit 59911aebb9
645 changed files with 263320 additions and 0 deletions

43
vendor/github.com/glycerine/zygomys/zygo/msgpackmap.go generated vendored Normal file
View File

@@ -0,0 +1,43 @@
package zygo
import (
"errors"
"fmt"
)
func (env *Zlisp) ImportMsgpackMap() {
env.AddMacro("msgpack-map", MsgpackMapMacro)
env.AddFunction("declare-msgpack-map", DeclareMsgpackMapFunction)
}
// declare a new record type
func MsgpackMapMacro(env *Zlisp, name string,
args []Sexp) (Sexp, error) {
if len(args) < 1 {
return SexpNull, fmt.Errorf("struct-name is missing. use: " +
"(msgpack-map struct-name)\n")
}
return MakeList([]Sexp{
env.MakeSymbol("def"),
args[0],
MakeList([]Sexp{
env.MakeSymbol("quote"),
env.MakeSymbol("msgmap"),
&SexpStr{S: args[0].(*SexpSymbol).name},
}),
}), nil
}
func DeclareMsgpackMapFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) {
if len(args) != 1 {
return SexpNull, WrongNargs
}
switch t := args[0].(type) {
case *SexpStr:
return t, nil
}
return SexpNull, errors.New("argument must be string: the name of the new msgpack-map constructor function to create")
}