Skip to content

Commit

Permalink
introduce executer.Run and ExecutionData and DLCI
Browse files Browse the repository at this point in the history
Notes: we reformulated the memory model s.t. everything is stored in
docker containers (including literals). This in order to bubble up
through the AST once we've treversed to its deepest depths, we only
need to return the DLCI which is a pointer to the docker
container (memory cell) which contains our data

Co-authored-by: Connor Walsh <[email protected]>
Co-authored-by: Mouse Reeve <[email protected]>

Git issue references:

Gamelan music currently playing: Gendhing Sumyar
  • Loading branch information
connorwalsh committed Mar 22, 2018
1 parent be65a2d commit 6c23c8b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
3 changes: 2 additions & 1 deletion evil.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ package dockerlang
// Local, Args, Global

func (c *Compterpreter) Evaluate() error {
return c.StackTree.Operands[0].Eval()
_, err := c.StackTree.Operands[0].Eval()
return err
}
12 changes: 12 additions & 0 deletions execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ type ExecutionEngine struct {
Network string
}

type ExecutionData struct {
Operands []DLCI
}

// constructs an ExecutionEngine and binds to the globally scoped executer.
func NewExecutionEngine() error {
// set the API version to use in an environment variable
Expand Down Expand Up @@ -70,3 +74,11 @@ func ShutdownExecutionEngine() error {

return nil
}

func (e *ExecutionEngine) Run(d *ExecutionData) (DLCI, error) {
// start container with network name

// pass data structure needed to compute

return "", nil
}
51 changes: 28 additions & 23 deletions forest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ package dockerlang
// AST map AST map empty AST map (AST of parsed code)

type AST interface {
Eval() error
Eval() (DLCI, error)
Execute() (DLCI, error)
GetChildren() []AST
}

// we should never actually instantiate this on its own
// it should *always* be an embedded structure (this is a mixin)
type BaseAST struct{}
type BaseAST struct {
ExecData *ExecutionData
}

func (b *BaseAST) GetChildren() []AST {
return []AST{}
}

func (b *BaseAST) Execute() error {
func (b *BaseAST) Execute() (DLCI, error) {
// actual docker

// but wait, what parts of the AST actually have their own containers?
// containers are like memory cells and DLIIs are like memory pointers,
// containers are like memory cells and DLCIs are like memory pointers,
// so anything we are storing in memory we will give its own docker container
// this means variables, expressions, and functions (which are basically just
// expressions) will have their own containers. Literals will not. The variable
Expand All @@ -37,17 +40,14 @@ func (b *BaseAST) Execute() error {
// in go and therefore we can just talk directly to docker through
// this code.

// before execution of anything, create a docker network
// when we run a docker container, we must give it the network name
// and the computation type (some data structure we haven't decided on yet)
// OK before execution of anything, create a docker network

// pass computation data (some data structure we haven't decided on yet)
// for it to execute
// each container will persist until that computation is no longer in scope
// within the source code.
// to that end, we can implement a very simple garbage collector or something.
return nil
return executer.Run(b.ExecData)
}

func (b *BaseAST) Eval() error {
func (b *BaseAST) Eval() (DLCI, error) {
var (
err error
)
Expand All @@ -56,26 +56,29 @@ func (b *BaseAST) Eval() error {
// to evaluate the current expression. So, evaluate
// all the child ASTs from left to right
for _, child := range b.GetChildren() {
err = child.Eval()
dlci, err := child.Eval()
if err != nil {
return err
return "", err
}

// construct operands for execution
b.ExecData.Operands = append(b.ExecData.Operands, dlci)
}

// we've computed all dependencies, now lets eval this thang
err = b.Execute()
literal, err := b.Execute()
if err != nil {
return err
return "", err
}

return nil
return literal, nil
}

type Expr struct {
BaseAST
Name string
Op string
DLII string
DLCI string
Arity int
Operands []AST
Args map[string]AST
Expand All @@ -91,11 +94,6 @@ func NewExpr(name string) *Expr {

type IfConditional struct{}

func (c *IfConditional) Eval() error {

return nil
}

type Variable struct {
BaseAST
Literal
Expand All @@ -108,3 +106,10 @@ type Literal struct {
Type string
Value interface{}
}

func (l *Literal) Eval() (DLCI, error) {

return l.Execute()
}

type DLCI string

0 comments on commit 6c23c8b

Please sign in to comment.