38 lines
646 B
Go
38 lines
646 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
|
|
"code.betamike.com/mediocregopher/ginger/gg"
|
|
"code.betamike.com/mediocregopher/ginger/vm"
|
|
)
|
|
|
|
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]
|
|
|
|
inVal, err := gg.NewDecoder(bytes.NewBufferString(inSrc)).Next()
|
|
if err != nil {
|
|
panic(fmt.Sprintf("decoding input: %v", err))
|
|
}
|
|
|
|
res, err := vm.EvaluateSource(
|
|
bytes.NewBufferString(opSrc),
|
|
vm.Value{Value: inVal.Value},
|
|
vm.GlobalScope,
|
|
)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("evaluating: %v", err))
|
|
}
|
|
|
|
fmt.Println(res)
|
|
}
|