Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce builtin function govm and makechan #330

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Commits on Mar 27, 2021

  1. Introduce builtin function go and makechan

    Builtin go(fn, arg1, arg2, ...) starts a goroutine which run
    fn(arg1, arg2, ...) in a new VM cloned from the current running VM,
    and returns a job object that has wait, result, abort methods.
    
    Builtin makechan(size) accepts an optional size parameter, makes a
    channel to send/receive object, and returns a chan object that has
    send, recv, close methods.
    
    To be able to access *VM instance that it is running in for go()
    and makechan(), now VM will always pass VMObj to and only to
    BuiltinFunction as arg[0].
    Bai-Yingjie committed Mar 27, 2021
    Configuration menu
    Copy the full SHA
    0f02c83 View commit details
    Browse the repository at this point in the history
  2. Rename job to goroutineVM for better understanding

    A goroutineVM is a VM cloned from the current VM in a shared way
    that the cloned VM(the child) can access globals and constants of
    the parent VM, but with its own stack and frames.
    
    The cloned VM will be running with a specified compiled function
    as the entrypoint in a new goroutine created by the parent VM.
    Bai-Yingjie committed Mar 27, 2021
    Configuration menu
    Copy the full SHA
    67ce595 View commit details
    Browse the repository at this point in the history

Commits on Mar 29, 2021

  1. Rename builtin go to govm

    In golang spec, "go" statement has no return value, which is not the
    semantic here: we want "govm" returns a goroutineVM object which can
    be used to wait, abort, or get result of the goroutineVM.
    Bai-Yingjie committed Mar 29, 2021
    Configuration menu
    Copy the full SHA
    d67644e View commit details
    Browse the repository at this point in the history
  2. Add docs for builtin "govm" and "makechan"

    fix typo
    Bai-Yingjie committed Mar 29, 2021
    Configuration menu
    Copy the full SHA
    e4ca97e View commit details
    Browse the repository at this point in the history
  3. Use unexported vmObj

    Bai-Yingjie committed Mar 29, 2021
    Configuration menu
    Copy the full SHA
    ee08782 View commit details
    Browse the repository at this point in the history

Commits on Mar 30, 2021

  1. Use needvmObj flag in BuiltinFunction

    VM will only pass its vmObj to builtin function that has needvmObj
    equals true, so that normal builtin functions do not need to notice
    the change.
    Bai-Yingjie committed Mar 30, 2021
    Configuration menu
    Copy the full SHA
    9e5fbbc View commit details
    Browse the repository at this point in the history

Commits on Apr 1, 2021

  1. goroutineVM: block parent VM untill all descendant VMs exit

    The goroutineVM will not exit unless:
    1. All its descendant VMs exit
    2. It calls abort()
    3. Its goroutineVM object abort() is called on behalf of its parent VM
    
    The latter 2 cases will trigger aborting procedure of all the descendant
    VMs, which will further result in d5#1 above.
    Bai-Yingjie committed Apr 1, 2021
    Configuration menu
    Copy the full SHA
    cc984e8 View commit details
    Browse the repository at this point in the history

Commits on Apr 14, 2021

  1. correct source position for closure function in call stack

    Take below snipet as an example:
    
    $ cat cmd/tengo/test.tengo
    test1 := func() {
    	v := 1
    	test2 := func() {
    		len(1,1,1,1)
    		v++
    	}
    	test2()
    }
    
    test1()
    
    ----
    before the fix:
    $ ./tengo test.tengo
    Runtime Error: wrong number of arguments in call to 'builtin-function:len'
            at -
            at test.tengo:7:2
            at test.tengo:10:1
    ----
    after the fix:
    $ ./tengo test.tengo
    Runtime Error: wrong number of arguments in call to 'builtin-function:len'
            at test.tengo:4:3
            at test.tengo:7:2
            at test.tengo:10:1
    Bai-Yingjie committed Apr 14, 2021
    Configuration menu
    Copy the full SHA
    5047ab7 View commit details
    Browse the repository at this point in the history
  2. govm now supports calling both script functions and native functions

    with this commit:
    
    1. builtinGovm() now accepts native golang function, but unlike
    compiled functions which run in a cloned VM, native golang functions
    do not need VM, they just run in a goroutine.
    
    2. Parent VMs now have records of errors of all its descendent VMs.
    A VM's error is a combination of the error of itself and all errors
    of the descendent VMs, in another word, parent VM's error includes
    all errors of the child VMs.
    
    3. ErrVMAborted is no longer treated as runtime error.
    Bai-Yingjie committed Apr 14, 2021
    Configuration menu
    Copy the full SHA
    c4aa6ae View commit details
    Browse the repository at this point in the history
  3. rename builtin govm back to go

    now that "govm" does not always run function in VM, so "go" is better.
    
    update docs to reflect the usage changes.
    Bai-Yingjie committed Apr 14, 2021
    Configuration menu
    Copy the full SHA
    c81780b View commit details
    Browse the repository at this point in the history

Commits on Apr 15, 2021

  1. Wrap main VM's error to make TestVMErrorUnwrap test pass

    And now abort() on the same VM twice will not panic.
    Bai-Yingjie committed Apr 15, 2021
    Configuration menu
    Copy the full SHA
    cf3fef9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4462ad9 View commit details
    Browse the repository at this point in the history

Commits on Apr 17, 2021

  1. improve panic handling

    On a panic happens in a VM:
    * the panic value along with both its script level and native level callstack
    are recorded as run time error, its parent VM should examine this error.
    * the panic will not cause whole program exits, but it does trigger the abort
    chain, so that the VM in which the panic happens and all its descendent VMs
    will terminate.
    
    So panic only causes the descendent group of VMs to exit.
    Other VM groups are not affected.
    Bai-Yingjie committed Apr 17, 2021
    Configuration menu
    Copy the full SHA
    a6205f4 View commit details
    Browse the repository at this point in the history

Commits on May 3, 2021

  1. Make VM's input/output redirectable

    Export VMObj to std.fmt, so that fmtPrintln can get vm.Out to output
    to a io.Writer per VM.
    Bai-Yingjie committed May 3, 2021
    Configuration menu
    Copy the full SHA
    496574d View commit details
    Browse the repository at this point in the history

Commits on May 6, 2021

  1. Configuration menu
    Copy the full SHA
    b6d2aba View commit details
    Browse the repository at this point in the history

Commits on May 20, 2021

  1. make times.sleep abortable

    and nolonger hide ErrVMAborted
    Bai-Yingjie committed May 20, 2021
    Configuration menu
    Copy the full SHA
    a14d22e View commit details
    Browse the repository at this point in the history

Commits on May 27, 2021

  1. Configuration menu
    Copy the full SHA
    367afb1 View commit details
    Browse the repository at this point in the history

Commits on May 29, 2021

  1. Configuration menu
    Copy the full SHA
    b979ae1 View commit details
    Browse the repository at this point in the history

Commits on May 31, 2021

  1. check aborting status before starting child VM

    and nil child VM to gc after it is done
    Bai-Yingjie committed May 31, 2021
    Configuration menu
    Copy the full SHA
    3a929e2 View commit details
    Browse the repository at this point in the history
  2. Start from small stack and frame space and grow on demand

    This reduce memory foot print significantly when there are large
    number of small VMs running.
    Bai-Yingjie committed May 31, 2021
    Configuration menu
    Copy the full SHA
    4cfaeeb View commit details
    Browse the repository at this point in the history