commit
47418fddac
4 changed files with 75 additions and 88 deletions
10
.travis.yml
Normal file
10
.travis.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
language: go
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.9
|
||||||
|
|
||||||
|
install:
|
||||||
|
- go get -u golang.org/x/lint/golint
|
||||||
|
|
||||||
|
script:
|
||||||
|
- make test
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
[![GoDoc](https://godoc.org/github.com/d5/tengo?status.svg)](https://godoc.org/github.com/d5/tengo/script)
|
[![GoDoc](https://godoc.org/github.com/d5/tengo?status.svg)](https://godoc.org/github.com/d5/tengo/script)
|
||||||
[![Go Report Card](https://goreportcard.com/badge/github.com/d5/tengo)](https://goreportcard.com/report/github.com/d5/tengo)
|
[![Go Report Card](https://goreportcard.com/badge/github.com/d5/tengo)](https://goreportcard.com/report/github.com/d5/tengo)
|
||||||
|
[![Build Status](https://travis-ci.org/d5/tengo.svg?branch=master)](https://travis-ci.org/d5/tengo)
|
||||||
|
|
||||||
Tengo is an embeddable script language for Go.
|
Tengo is an embeddable script language for Go.
|
||||||
|
|
||||||
|
|
|
@ -7,74 +7,70 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var mathModule = map[string]objects.Object{
|
var mathModule = map[string]objects.Object{
|
||||||
"e": &objects.Float{Value: math.E},
|
"e": &objects.Float{Value: math.E},
|
||||||
"pi": &objects.Float{Value: math.Pi},
|
"pi": &objects.Float{Value: math.Pi},
|
||||||
"phi": &objects.Float{Value: math.Phi},
|
"phi": &objects.Float{Value: math.Phi},
|
||||||
"sqrt2": &objects.Float{Value: math.Sqrt2},
|
"sqrt2": &objects.Float{Value: math.Sqrt2},
|
||||||
"sqrtE": &objects.Float{Value: math.SqrtE},
|
"sqrtE": &objects.Float{Value: math.SqrtE},
|
||||||
"sqrtPi": &objects.Float{Value: math.SqrtPi},
|
"sqrtPi": &objects.Float{Value: math.SqrtPi},
|
||||||
"sqrtPhi": &objects.Float{Value: math.SqrtPhi},
|
"sqrtPhi": &objects.Float{Value: math.SqrtPhi},
|
||||||
"ln2": &objects.Float{Value: math.Ln2},
|
"ln2": &objects.Float{Value: math.Ln2},
|
||||||
"log2E": &objects.Float{Value: math.Log2E},
|
"log2E": &objects.Float{Value: math.Log2E},
|
||||||
"ln10": &objects.Float{Value: math.Ln10},
|
"ln10": &objects.Float{Value: math.Ln10},
|
||||||
"log10E": &objects.Float{Value: math.Log10E},
|
"log10E": &objects.Float{Value: math.Log10E},
|
||||||
"abs": FuncAFRF(math.Abs),
|
"abs": FuncAFRF(math.Abs),
|
||||||
"acos": FuncAFRF(math.Acos),
|
"acos": FuncAFRF(math.Acos),
|
||||||
"acosh": FuncAFRF(math.Acosh),
|
"acosh": FuncAFRF(math.Acosh),
|
||||||
"asin": FuncAFRF(math.Asin),
|
"asin": FuncAFRF(math.Asin),
|
||||||
"asinh": FuncAFRF(math.Asinh),
|
"asinh": FuncAFRF(math.Asinh),
|
||||||
"atan": FuncAFRF(math.Atan),
|
"atan": FuncAFRF(math.Atan),
|
||||||
"atan2": FuncAFFRF(math.Atan2),
|
"atan2": FuncAFFRF(math.Atan2),
|
||||||
"atanh": FuncAFRF(math.Atanh),
|
"atanh": FuncAFRF(math.Atanh),
|
||||||
"cbrt": FuncAFRF(math.Cbrt),
|
"cbrt": FuncAFRF(math.Cbrt),
|
||||||
"ceil": FuncAFRF(math.Ceil),
|
"ceil": FuncAFRF(math.Ceil),
|
||||||
"copysign": FuncAFFRF(math.Copysign),
|
"copysign": FuncAFFRF(math.Copysign),
|
||||||
"cos": FuncAFRF(math.Cos),
|
"cos": FuncAFRF(math.Cos),
|
||||||
"cosh": FuncAFRF(math.Cosh),
|
"cosh": FuncAFRF(math.Cosh),
|
||||||
"dim": FuncAFFRF(math.Dim),
|
"dim": FuncAFFRF(math.Dim),
|
||||||
"erf": FuncAFRF(math.Erf),
|
"erf": FuncAFRF(math.Erf),
|
||||||
"erfc": FuncAFRF(math.Erfc),
|
"erfc": FuncAFRF(math.Erfc),
|
||||||
"erfcinv": FuncAFRF(math.Erfcinv),
|
"exp": FuncAFRF(math.Exp),
|
||||||
"erfinv": FuncAFRF(math.Erfinv),
|
"exp2": FuncAFRF(math.Exp2),
|
||||||
"exp": FuncAFRF(math.Exp),
|
"expm1": FuncAFRF(math.Expm1),
|
||||||
"exp2": FuncAFRF(math.Exp2),
|
"floor": FuncAFRF(math.Floor),
|
||||||
"expm1": FuncAFRF(math.Expm1),
|
"gamma": FuncAFRF(math.Gamma),
|
||||||
"floor": FuncAFRF(math.Floor),
|
"hypot": FuncAFFRF(math.Hypot),
|
||||||
"gamma": FuncAFRF(math.Gamma),
|
"ilogb": FuncAFRI(math.Ilogb),
|
||||||
"hypot": FuncAFFRF(math.Hypot),
|
"inf": FuncAIRF(math.Inf),
|
||||||
"ilogb": FuncAFRI(math.Ilogb),
|
"is_inf": FuncAFIRB(math.IsInf),
|
||||||
"inf": FuncAIRF(math.Inf),
|
"is_nan": FuncAFRB(math.IsNaN),
|
||||||
"is_inf": FuncAFIRB(math.IsInf),
|
"j0": FuncAFRF(math.J0),
|
||||||
"is_nan": FuncAFRB(math.IsNaN),
|
"j1": FuncAFRF(math.J1),
|
||||||
"j0": FuncAFRF(math.J0),
|
"jn": FuncAIFRF(math.Jn),
|
||||||
"j1": FuncAFRF(math.J1),
|
"ldexp": FuncAFIRF(math.Ldexp),
|
||||||
"jn": FuncAIFRF(math.Jn),
|
"log": FuncAFRF(math.Log),
|
||||||
"ldexp": FuncAFIRF(math.Ldexp),
|
"log10": FuncAFRF(math.Log10),
|
||||||
"log": FuncAFRF(math.Log),
|
"log1p": FuncAFRF(math.Log1p),
|
||||||
"log10": FuncAFRF(math.Log10),
|
"log2": FuncAFRF(math.Log2),
|
||||||
"log1p": FuncAFRF(math.Log1p),
|
"logb": FuncAFRF(math.Logb),
|
||||||
"log2": FuncAFRF(math.Log2),
|
"max": FuncAFFRF(math.Max),
|
||||||
"logb": FuncAFRF(math.Logb),
|
"min": FuncAFFRF(math.Min),
|
||||||
"max": FuncAFFRF(math.Max),
|
"mod": FuncAFFRF(math.Mod),
|
||||||
"min": FuncAFFRF(math.Min),
|
"nan": FuncARF(math.NaN),
|
||||||
"mod": FuncAFFRF(math.Mod),
|
"nextafter": FuncAFFRF(math.Nextafter),
|
||||||
"nan": FuncARF(math.NaN),
|
"pow": FuncAFFRF(math.Pow),
|
||||||
"nextafter": FuncAFFRF(math.Nextafter),
|
"pow10": FuncAIRF(math.Pow10),
|
||||||
"pow": FuncAFFRF(math.Pow),
|
"remainder": FuncAFFRF(math.Remainder),
|
||||||
"pow10": FuncAIRF(math.Pow10),
|
"signbit": FuncAFRB(math.Signbit),
|
||||||
"remainder": FuncAFFRF(math.Remainder),
|
"sin": FuncAFRF(math.Sin),
|
||||||
"round": FuncAFRF(math.Round),
|
"sinh": FuncAFRF(math.Sinh),
|
||||||
"round_to_even": FuncAFRF(math.RoundToEven),
|
"sqrt": FuncAFRF(math.Sqrt),
|
||||||
"signbit": FuncAFRB(math.Signbit),
|
"tan": FuncAFRF(math.Tan),
|
||||||
"sin": FuncAFRF(math.Sin),
|
"tanh": FuncAFRF(math.Tanh),
|
||||||
"sinh": FuncAFRF(math.Sinh),
|
"runct": FuncAFRF(math.Trunc),
|
||||||
"sqrt": FuncAFRF(math.Sqrt),
|
"y0": FuncAFRF(math.Y0),
|
||||||
"tan": FuncAFRF(math.Tan),
|
"y1": FuncAFRF(math.Y1),
|
||||||
"tanh": FuncAFRF(math.Tanh),
|
"yn": FuncAIFRF(math.Yn),
|
||||||
"runct": FuncAFRF(math.Trunc),
|
|
||||||
"y0": FuncAFRF(math.Y0),
|
|
||||||
"y1": FuncAFRF(math.Y1),
|
|
||||||
"yn": FuncAIFRF(math.Yn),
|
|
||||||
// TODO: functions that have multiple returns
|
// TODO: functions that have multiple returns
|
||||||
// Should these be tuple assignment? Or Map return?
|
// Should these be tuple assignment? Or Map return?
|
||||||
//"frexp": nil,
|
//"frexp": nil,
|
||||||
|
|
|
@ -27,7 +27,6 @@ var osModule = map[string]objects.Object{
|
||||||
"mode_setgui": &objects.Int{Value: int64(os.ModeSetgid)},
|
"mode_setgui": &objects.Int{Value: int64(os.ModeSetgid)},
|
||||||
"mode_char_device": &objects.Int{Value: int64(os.ModeCharDevice)},
|
"mode_char_device": &objects.Int{Value: int64(os.ModeCharDevice)},
|
||||||
"mode_sticky": &objects.Int{Value: int64(os.ModeSticky)},
|
"mode_sticky": &objects.Int{Value: int64(os.ModeSticky)},
|
||||||
"mode_irregular": &objects.Int{Value: int64(os.ModeIrregular)},
|
|
||||||
"mode_type": &objects.Int{Value: int64(os.ModeType)},
|
"mode_type": &objects.Int{Value: int64(os.ModeType)},
|
||||||
"mode_perm": &objects.Int{Value: int64(os.ModePerm)},
|
"mode_perm": &objects.Int{Value: int64(os.ModePerm)},
|
||||||
"path_separator": &objects.Char{Value: os.PathSeparator},
|
"path_separator": &objects.Char{Value: os.PathSeparator},
|
||||||
|
@ -48,8 +47,6 @@ var osModule = map[string]objects.Object{
|
||||||
"clearenv": FuncAR(os.Clearenv),
|
"clearenv": FuncAR(os.Clearenv),
|
||||||
// environ() => array(string)
|
// environ() => array(string)
|
||||||
"environ": FuncARSs(os.Environ),
|
"environ": FuncARSs(os.Environ),
|
||||||
// executable() => string/error
|
|
||||||
"executable": &objects.UserFunction{Value: osExecutable},
|
|
||||||
// exit(code int)
|
// exit(code int)
|
||||||
"exit": FuncAIR(os.Exit),
|
"exit": FuncAIR(os.Exit),
|
||||||
// expand_env(s string) => string
|
// expand_env(s string) => string
|
||||||
|
@ -104,8 +101,6 @@ var osModule = map[string]objects.Object{
|
||||||
"truncate": FuncASI64RE(os.Truncate),
|
"truncate": FuncASI64RE(os.Truncate),
|
||||||
// unsetenv(key string) => error
|
// unsetenv(key string) => error
|
||||||
"unsetenv": FuncASRE(os.Unsetenv),
|
"unsetenv": FuncASRE(os.Unsetenv),
|
||||||
// user_cache_dir() => string/error
|
|
||||||
"user_cache_dir": FuncARSE(os.UserCacheDir),
|
|
||||||
// create(name string) => imap(file)/error
|
// create(name string) => imap(file)/error
|
||||||
"create": &objects.UserFunction{Value: osCreate},
|
"create": &objects.UserFunction{Value: osCreate},
|
||||||
// open(name string) => imap(file)/error
|
// open(name string) => imap(file)/error
|
||||||
|
@ -116,21 +111,6 @@ var osModule = map[string]objects.Object{
|
||||||
"find_process": &objects.UserFunction{Value: osFindProcess},
|
"find_process": &objects.UserFunction{Value: osFindProcess},
|
||||||
// start_process(name string, argv array(string), dir string, env array(string)) => imap(process)/error
|
// start_process(name string, argv array(string), dir string, env array(string)) => imap(process)/error
|
||||||
"start_process": &objects.UserFunction{Value: osStartProcess},
|
"start_process": &objects.UserFunction{Value: osStartProcess},
|
||||||
|
|
||||||
// TODO: implemented more functions
|
|
||||||
//"stdin": nil,
|
|
||||||
//"stdout": nil,
|
|
||||||
//"stderr": nil,
|
|
||||||
//"chtimes": nil,
|
|
||||||
//"expand": nil,
|
|
||||||
//"is_exists": nil,
|
|
||||||
//"is_not_exist": nil,
|
|
||||||
//"is_path_separator": nil,
|
|
||||||
//"is_permission": nil,
|
|
||||||
//"is_timeout": nil,
|
|
||||||
//"new_syscall_error": nil,
|
|
||||||
//"pipe": nil,
|
|
||||||
//"same_file": nil,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func osArgs(args ...objects.Object) (objects.Object, error) {
|
func osArgs(args ...objects.Object) (objects.Object, error) {
|
||||||
|
|
Loading…
Reference in a new issue