Giter Club home page Giter Club logo

tengo's People

Contributors

bbuck avatar bfreis avatar chyroc avatar d5 avatar deckarep avatar diamondo25 avatar endink avatar ganehag avatar geseq avatar graphman65 avatar gufeijun avatar ipsusila avatar keenskelly avatar keinos avatar kkty avatar lack30 avatar ma124 avatar maslino avatar mccolljr avatar misiek08 avatar mkuznets avatar naicolas avatar qzb avatar ripienaar avatar saromanov avatar sean- avatar shikbupt avatar shiyuge avatar vereecw avatar wlxwlxwlx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tengo's Issues

Fix local function recursion issue

// global recursive function: works perfectly
sum_g := func(a) {
    return a == 0 ? 0 : a + sum_g(a-1)
}
print(sum_g(10)) // 55

// local recursive function: causes an error
func() {
    sum := func(a) {
        return a == 0 ? 0 : a + sum(a-1)  // error
    }

    return sum(10)
}()

// workaround
func() {
    sum := undefined
    sum = func(a) {
        return a == 0 ? 0 : a + sum(a-1)  // ok
    }

    return sum(10)
}()

Playground

Instructions:
  0000 CONST   5    
  0003 CALL    0    
  0005 SETG    0    


Constants:
  [0] 0 (int)
  [1] 0 (int)
  [2] 1 (int)
  [3] (function)
    0000 GETL    0    
    0002 CONST   0    
    0005 EQL    
    0006 JMPF    15   
    0009 CONST   1    
    0012 JMP     28   
    0015 GETL    0    
    0017 GETF    0    
    0019 GETL    0    
    0021 CONST   2    
    0024 SUB    
    0025 CALL    1    
    0027 ADD    
    0028 RETVAL  1    
  [4] 10 (int)
  [5] (function)
    0000 GETL    0    
    0002 CLOSURE 3     1    
    0006 DEFL    0    
    0008 GETL    0    
    0010 CONST   4    
    0013 CALL    1    
    0015 RETVAL  1    

FFI?

Been observing new issues like #44 #45 and #46

Instead of duplicating the Go standard library in Tengo; Why not crate an FFI? This has the added advantage of allowing users to build new modules of anything they need that isn't already part of the Tengo standard library (exposing Go standard library modules/functions).

Question: Hide helpers in modules?

I found the module documentation in https://github.com/d5/tengo/blob/master/docs/tutorial.md (not sure if there is another document). I was wondering, if and how I can "hide" module-internal stuff, like helper functions etc.

Basically, import expression returns all the global variables defined in the module as a Map-like value.

If all "global defined" variables in a module are exported, there is currently no way to hide module internals, correct?

I was also wondering, what your thought process was for doing it that way, compared e.g. to mark variables as exported.

btw: Thank you a lot for tengo. I'm not using it for anything else then playing around, but I'm learning a lot by trying to understand how you build it! 💕

os.exec

I don't see any references in your code to os.exec can this execute any external commands?

Proposal to Add Value() to objects.Object

I was looking into how easy it would be to add an encoding/json module.
However when i put a tengo map, like:
testMap := {foo: "bar"}
the output result will be:

{"foo":{"Value": "bar"}}

Since the Tengo string object contains the Value field, the result would be like the above.

The proposal would be to add another method signature to the objects.Object interface:

type Object interface{
  Value() interface{}
}

which would in the case of the Tengo objects return the value as it is saved in the struct

Do you think something like that would be useful or that it would only make the interface to complicated for simple use?

Unless there are other plans for making a Map Object more accessible in Go?
In the mean time it should also be possible to just do type conversion and work with that, i'll give that a shot too

Line Number Info when compiled.Run() has error

Would be nice if the error returned by c.Run() would at least give the line number of the script where the error occurred. A stack-trace would even be nicer in case there was some recursion, or user defined function call.

if c, err := s.Compile(); err != nil {
	t.Errorf("compile error=%s",err )
} else {
	if err := c.Run(); err != nil {
		t.Errorf("error %s",err)
	}
}

IndexGet() of Array/ImmutableArray/Undefined types

Currently index-get behavior of array is to raise a run-time error. Maybe it can simplify things if array returns undefined instead.

Also, if this array retuning undefined makes sense, we may also want to implement IndexGet of Undefined type to return undefined: undefined[index] => undefined

a := []
b := a[1][2][3]      // b == undefined

c := {}
d := c.foo["bar"][1] // d == undefined

Other things to think about (for consistency):

  • IndexSet behavior of array: likely we'd like to keep the current behavior of raising a run-time error?
  • Slicing operator of array arr[low:high]: currently it raises error if out-of-bounds. should we keep it?

/cc @earncef

ponies: performance, portability, and security

Just a thought on architecting for speed, portability, security:

Given that Google has put hundreds of engineer-years into optimizing the v8 Just-in-time compiler, it is not surprising that it can run the recursive fib(35) in about 2x that of Go.

> function fib(n) { if (n<2) { return n; } else { return fib(n-1)+fib(n-2); }
> console.time("hi"); fib(35) ;console.timeEnd("hi")
hi: 128.559ms

So for crazy good performance, it would be great to target wasm bytecode and let v8 run it.

The other nice aspect of targeting wasm would be that for those times when you need portability, there are at least two wasm bytecode interpreters written in pure Go. e.g. https://github.com/perlin-network/life and https://github.com/go-interpreter/wagon

Finally, a third benefit would be high security. V8 offers Isolates and Contexts, which Cloudflare has exploited for the ultimate in scalable-yet-secure "run someone else's untrusted code". See https://blog.cloudflare.com/cloud-computing-without-containers/ for example.

Consider, even just for a moment in a flight of imagination, how hard would it be for tengo to output wasm bytecode? I realize this is ambitious.

p.s. https://github.com/augustoroman/v8 is available for experiment.

Ability to call CompiledFunction from Callable

I want to supply a Callable to my script via Indexable. But I want the arg to my Callable to be a func() declared in the script. The func() comes to the script as "*CompiledFunction". But I have no way to call the compiled function. My use case is to implement things like map/reduce, where the script is declaring lambda's.

`

`

use strings.Builder to speed up string join

I notice that,some code use fmt.Sprintf("[%s]", strings.join(",", some array)) to join string

For example ,in some Object String

May be,we can use strings.Builder(go1.10) to speed up it

If you think so,i well push some merge request(1 for use go 1.10, 2 for refactor to use strings.Builder)

Thank you

sandbox environment support

  • Custom user module loader
  • Whitelist/blacklist standard library modules
  • Whitelist/blacklist builtin functions

REPL constants not transferred between commands

REPL shares the symbol table and the globals between each line of commands so it keeps the global variables between the lines. It also needs to keep the constants because some values (e.g. closures) and references to those constants need to be shared too.

Call a CompiledFunction from host

I'm trying to call a function defined inside the script from the embedning host. Is this possible? I can't seam to find any type of run or call like feature on them.

s := script.New([]byte(`
	out := func(state, keyboard, b) {
		
	}
`))
c, _ := s.Compile()
c.Run()

f := c.Get("out").Value().(objects.CompiledFunction)
// ??? f(&objects.String{Value: "a"}, &objects.String{Value: "b"}, &objects.String{Value: "c"})

Time module

We can add time module in a similar way as os module: Time as an immutable map object with some method -like functions.

reflection / host communication

First off, tengo looks really great. Thanks for making it!

For using tengo as a scripting language, is it possible to have the host program inject variables or functions into the script namespace for the script to use?

Along these lines, Alan Donovan on the Go team has done some nice reflection work for starlark-go on the wip-stargo branch. Any Go library can be called from script in this manner, as long as bindings have been compiled in.

https://github.com/google/starlark-go/tree/wip-stargo

Since it is 3-clause BSD licensed, good ideas there could be borrowed.

allow execution to be interrupted

This looks great, been looking for something to do some embedded scripting with and this appears to be the best so far - outside of the lua's which i am not a fan of - well done, cannot believe this is a few weeks of work!

When running embedded scripts there's a real risk that they would get stuck forever - maybe someone exec's something that is blocking.

So would be great if there was a Run() or Script() that had context support to set deadlines for example. Be interesting to see how we handle spawned things to avoid zombies in that case though.

more docs

hey!

i liked the idea of being able to easily use closures in a close-to-go syntax with dynamic checks

however, I cant seem to find some docs about the lang implementation/definition.

Maybe something about the vm: does it do JIT compilation? Can it?

Idk i'd to read some material about the lang itself

A couple of questions if I may...

First of all, congrats for this amazing project. Well done @d5.

I hope my HN post to bring more people in because this project looks promising.

I have a couple of questions:

  • What about concurrency?
  • More examples around standalone language please? I have tried to use a simple print('hello world') and couldn't make it work.
  • Is each file considered a module that gets namespaced by default?
  • Can Tengo use Go's existing modules? That is, is there any interoperability between the two?
  • When compiling to a binary file, do we have the same concept as Go's, such as choosing the system we want to build a binary for or an architecture of our choice?
  • Benchmarks in the nearest future please...
  • Maybe standard Tengo libraries?

That's it for now, I cannot think of anything else.

As soon as you provide more examples, I will start playing with it to see how I could use it and see whether I could replace some ancient shell scripting projects of mine or not.

Let me know.

Cheers.

Language level support for immutable values

Everyone knows that immutability can be useful in many ways.

A couple of questions to answer:

  1. How to implement? Could be builtin function(s). Could be Immutable object that wraps another object.
  2. What to do if immutable value is mutated? Should that cause runtime error? (Definitely compile-time error is not trivial unfortunately) Or should it be simply ignored? OR.... can it even be copy-on-write?
  3. Immutability of composite types (like map or array): should enforce immutability to its elements?
  4. Immutability of user types: should user type (Object implementation) given a chance to determine the meaning of immutability for their types? If so, how?

Other criteria includes:

  • Minimize performance overhead of immutable values
  • Immutability should be optional and it should not affect performance of non-immutable values.

support os.Stat()

It seems almost impossible to read a file, read takes a count of how many bytes to read but there is no way to get the size of a file to make the buffer, stat will help

reuse constants

Compiler.addConstant should re-use constant if the same value already exists.

v1 release review

  • review and finalize documentation for v1.0 release
  • setup CI for versioned release process

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.