Skip to content

Commit

Permalink
Direct variable assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Dec 25, 2020
1 parent e168aa8 commit e0ffc84
Show file tree
Hide file tree
Showing 19 changed files with 414 additions and 224 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Warm up pkg.go.dev
uses: andrewslotin/go-proxy-pull-action@master

pages:
name: Pages
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![codecov](https://codecov.io/gh/Vilsol/go-mlog/branch/master/graph/badge.svg?token=LFNKYWS0N2)](https://codecov.io/gh/Vilsol/go-mlog)
[![CodeFactor](https://www.codefactor.io/repository/github/vilsol/go-mlog/badge)](https://www.codefactor.io/repository/github/vilsol/go-mlog)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/vilsol/go-mlog)
[![godoc reference](https://img.shields.io/badge/godoc-reference-5272B4)](https://pkg.go.dev/github.com/Vilsol/go-mlog)

Go to MLOG transpiler.

Expand Down Expand Up @@ -34,6 +35,7 @@ A Web IDE is available [here](https://vilsol.github.io/go-mlog-web/?1)
* Variable argument count functions
* Multiple function return values
* Optimize simple jump instructions
* Multi-pass post-processing

## Design Limitations

Expand Down
49 changes: 27 additions & 22 deletions m/base.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
package m

import (
"errors"
"github.com/Vilsol/go-mlog/transpiler"
"strings"
)

func init() {
transpiler.RegisterFuncTranslation("m.Read", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Count: 1,
Variables: 1,
Translate: func(args []transpiler.Resolvable, vars []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
memoryName := strings.Trim(args[0].GetValue(), "\"")

if memoryName == transpiler.StackCellName {
panic("can't read/write to memory cell that is used for the stack: " + transpiler.StackCellName)
return nil, errors.New("can't read/write to memory cell that is used for the stack: " + transpiler.StackCellName)
}

return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
{
&transpiler.Value{Value: "read"},
&transpiler.Value{Value: transpiler.FunctionReturnVariable},
vars[0],
&transpiler.Value{Value: memoryName},
&transpiler.Value{Value: args[1].GetValue()},
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.Write", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
memoryName := strings.Trim(args[1].GetValue(), "\"")

if memoryName == transpiler.StackCellName {
panic("can't read/write to memory cell that is used for the stack: " + transpiler.StackCellName)
return nil, errors.New("can't read/write to memory cell that is used for the stack: " + transpiler.StackCellName)
}

return []transpiler.MLOGStatement{
Expand All @@ -49,12 +51,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.PrintFlush", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -64,28 +66,30 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.GetLink", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Count: 1,
Variables: 1,
Translate: func(args []transpiler.Resolvable, vars []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
{
&transpiler.Value{Value: "getlink"},
&transpiler.Value{Value: transpiler.FunctionReturnVariable},
vars[0],
&transpiler.Value{Value: args[0].GetValue()},
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.Radar", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Count: 1,
Variables: 1,
Translate: func(args []transpiler.Resolvable, vars []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -97,28 +101,29 @@ func init() {
&transpiler.Value{Value: args[5].GetValue()},
&transpiler.Value{Value: args[0].GetValue()},
&transpiler.Value{Value: args[4].GetValue()},
&transpiler.Value{Value: transpiler.FunctionReturnVariable},
vars[0],
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.Sensor", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Count: 1,
Variables: 1,
Translate: func(args []transpiler.Resolvable, vars []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
{
&transpiler.Value{Value: "sensor"},
&transpiler.Value{Value: transpiler.FunctionReturnVariable},
vars[0],
&transpiler.Value{Value: args[0].GetValue()},
&transpiler.Value{Value: args[1].GetValue()},
},
},
},
}
}, nil
},
})
}
Expand Down
16 changes: 8 additions & 8 deletions m/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/Vilsol/go-mlog/transpiler"
func init() {
transpiler.RegisterFuncTranslation("m.ControlEnabled", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -17,12 +17,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.ControlShoot", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -36,12 +36,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.ControlShootP", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -54,12 +54,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.ControlConfigure", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -71,7 +71,7 @@ func init() {
},
},
},
}
}, nil
},
})
}
Expand Down
44 changes: 22 additions & 22 deletions m/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func init() {
transpiler.RegisterFuncTranslation("m.DrawClear", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -21,12 +21,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawColor", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -40,12 +40,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawStroke", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -56,12 +56,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawLine", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -75,12 +75,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawRect", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -94,12 +94,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawLineRect", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -113,12 +113,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawPoly", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -133,12 +133,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawLinePoly", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -153,12 +153,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawTriangle", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -174,12 +174,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawImage", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -194,12 +194,12 @@ func init() {
},
},
},
}
}, nil
},
})
transpiler.RegisterFuncTranslation("m.DrawFlush", transpiler.Translator{
Count: 1,
Translate: func(args []transpiler.Resolvable) []transpiler.MLOGStatement {
Translate: func(args []transpiler.Resolvable, _ []transpiler.Resolvable) ([]transpiler.MLOGStatement, error) {
return []transpiler.MLOGStatement{
&transpiler.MLOG{
Statement: [][]transpiler.Resolvable{
Expand All @@ -209,7 +209,7 @@ func init() {
},
},
},
}
}, nil
},
})
}
Expand Down
Loading

0 comments on commit e0ffc84

Please sign in to comment.