2021-12-30 22:29:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2023-10-28 07:53:37 +00:00
|
|
|
"code.betamike.com/mediocregopher/ginger/gg"
|
|
|
|
"code.betamike.com/mediocregopher/ginger/vm"
|
2021-12-30 22:29:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
if len(os.Args) < 3 {
|
|
|
|
fmt.Printf(`Usage: %s <operation source> "in = <value>"\n`, os.Args[0])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
opSrc := os.Args[1]
|
|
|
|
inSrc := os.Args[2]
|
|
|
|
|
2023-10-21 15:42:31 +00:00
|
|
|
inVal, err := gg.NewDecoder(bytes.NewBufferString(inSrc)).Next()
|
2021-12-30 22:29:38 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("decoding input: %v", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := vm.EvaluateSource(
|
|
|
|
bytes.NewBufferString(opSrc),
|
2023-10-27 14:14:37 +00:00
|
|
|
vm.Value{Value: inVal.Value},
|
2021-12-30 22:29:38 +00:00
|
|
|
vm.GlobalScope,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("evaluating: %v", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(res)
|
|
|
|
}
|