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

Ride vm and compiler. #438

Draft
wants to merge 61 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f7bff52
Stateful compiler.
Frozen Oct 23, 2020
393bea6
Context for func execution.
Frozen Oct 23, 2020
c32e887
Function definition passed tess.
Frozen Oct 23, 2020
1975cd8
Uncomment completed tests.
Frozen Oct 23, 2020
fb77419
Pass args as reference.
Frozen Oct 30, 2020
d20052b
Pass args as mem storage.
Frozen Nov 3, 2020
197130e
Global variables.
Frozen Nov 5, 2020
980f91f
Get attribute vm.
Frozen Nov 6, 2020
b11b59e
Odd byte codes.
Frozen Nov 6, 2020
3f70cd3
Stagenet tests.
Frozen Nov 10, 2020
03e9286
Cells for variables.
Frozen Nov 12, 2020
3165334
Fix bug with if stmt.
Frozen Nov 23, 2020
f4c6943
Cache function result as variable.
Frozen Dec 1, 2020
ae6f02a
Function arguments.
Frozen Dec 2, 2020
86f9281
Cache variable result.
Frozen Dec 3, 2020
f6a69e9
Clear cache.
Frozen Dec 3, 2020
0fd9f97
Fix clear cache.
Frozen Dec 7, 2020
219cf08
Reverse assigments.
Frozen Dec 7, 2020
2f51036
Deferred code.
Frozen Dec 9, 2020
9e7f14c
Property state.
Frozen Dec 10, 2020
0296798
Call function.
Frozen Dec 10, 2020
9c0d640
Property invocation changed.
Frozen Dec 13, 2020
8f7a32a
Property bytecode checked in tests.
Frozen Dec 13, 2020
f01939c
Reversed tree.
Frozen Dec 15, 2020
4bdddaa
Fix transitions.
Frozen Dec 22, 2020
d983007
Merge branch 'master' into ride_vm_fsm
Frozen Dec 22, 2020
415c5c1
Fix transitions.
Frozen Dec 23, 2020
b43481d
Fix functions.
Frozen Dec 23, 2020
f755658
Fix functions.
Frozen Dec 24, 2020
33f2f24
Save entrypoints into meta.
Frozen Dec 24, 2020
36be49d
Testnet random script.
Frozen Jan 24, 2021
1b6f2ff
Passed testnet.
Frozen Feb 1, 2021
8a2b1cd
Enabled cache.
Frozen Feb 4, 2021
598f0aa
Merge branch 'master' into ride_vm_fsm
Frozen Feb 4, 2021
78afd85
Merged master.
Frozen Feb 4, 2021
ff8c959
Switchable bloom filter.
Frozen Feb 5, 2021
60410b4
Fix tests.
Frozen Feb 5, 2021
cc3d021
Merge branch 'optional_bloom_filter' into ride_vm_fsm
Frozen Feb 5, 2021
b70c14b
Code clean up and returned back debug info.
Frozen Feb 9, 2021
3e16ec5
Fix panic.
Frozen Feb 9, 2021
73a8ce5
Remove caching duplicates.
Frozen Feb 12, 2021
349c863
Expanded tree.
Frozen Mar 10, 2021
9c1b500
Rewrite tree by using immutable context with variables.
Frozen Mar 16, 2021
74b8cf3
Fix problems with tree expand.
Frozen Mar 17, 2021
be99ac9
Fix naming.
Frozen Mar 18, 2021
5d035b3
Remove unused code.
Frozen Mar 18, 2021
8b64449
Fix vetcheck errors.
Frozen Mar 18, 2021
366b203
Fix vetcheck errors.
Frozen Mar 18, 2021
ba560d8
Set up go 1.16
Frozen Mar 18, 2021
6c06ca0
Merge branch 'master' into ride_vm_fsm
Frozen Mar 18, 2021
b50a0c7
Rewrite path.
Frozen Mar 19, 2021
15d0cb0
Removed fmtcheck.
Frozen Mar 19, 2021
2e6c584
Clean code in tree evaluator.
Frozen Mar 19, 2021
2c1c208
Fix small errors.
Frozen Mar 19, 2021
f86c981
Clean up compiler.
Frozen Mar 22, 2021
1d6f34a
Fix bug with var override in condition stste.
Frozen Mar 25, 2021
80bfd76
Merge remote-tracking branch 'origin/expand_tree_rewrite_path' into r…
Frozen Mar 25, 2021
a644a73
Fix bug with nil values and duplicate vars in conditional state.
Frozen Apr 2, 2021
cee2edc
Merge remote-tracking branch 'origin/master' into ride_vm_fsm
Frozen Apr 2, 2021
0c792d4
Updated mocks.
Frozen Apr 2, 2021
48d19f8
Added skip file compiler_heplers
esuwu Apr 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Get attribute vm.
Frozen committed Nov 6, 2020
commit 980f91f12dc4c0fe28cb2e71f02064ed2b75f826
20 changes: 6 additions & 14 deletions pkg/ride/compiler2.go
Original file line number Diff line number Diff line change
@@ -53,16 +53,11 @@ func ccc(f Fsm, node Node) (Fsm, error) {
}
return ccc(fsm.Return(), n.Block)
case *PropertyNode:
//f = f.Call("$property", 2)
//f, err := ccc(f, n.Object)
//if err != nil {
// return f, err
//}
//f.(params).b.writeByte(OpProperty)

return ccc(f.Property(n.Name), n.Object)
//n.Object
//n.Name
f, err := ccc(f.Property(n.Name), n.Object)
if err != nil {
return f, err
}
return f.Return(), nil
default:
return f, errors.Errorf("unknown type %T", node)
}
@@ -82,9 +77,6 @@ func compileSimpleScript(libVersion int, node Node) (*Executable, error) {
r := newReferences(nil)
u := &uniqid{}

//predefs := newPredef()
//predefs.set("tx", math.MaxUint16, tx)

params := params{
b: b,
c: c,
@@ -94,7 +86,7 @@ func compileSimpleScript(libVersion int, node Node) (*Executable, error) {
predef: predefined,
}

f := NewDefinitionsFsm(params)
f := NewMain(params)
f, err = ccc(f, node)
if err != nil {
return nil, err
14 changes: 7 additions & 7 deletions pkg/ride/compiler2_test.go
Original file line number Diff line number Diff line change
@@ -95,16 +95,16 @@ func Test22(t *testing.T) {
//{`let x = throw(); true || x`, `AQQAAAABeAkBAAAABXRocm93AAAAAAMGBgUAAAABeKRnLds=`, env, true},
// Global variables
//{`tx == tx`, "BAkAAAAAAAACBQAAAAJ0eAUAAAACdHhnqgP4", env, true},
{`tx.id == base58''`, `AQkAAAAAAAACCAUAAAACdHgAAAACaWQBAAAAAJBtD70=`, env, false},
//{`tx.id == base58''`, `AQkAAAAAAAACCAUAAAACdHgAAAACaWQBAAAAAJBtD70=`, env, false},
//{`tx.id == base58'H5C8bRzbUTMePSDVVxjiNKDUwk6CKzfZGTP2Rs7aCjsV'`, `BAkAAAAAAAACCAUAAAACdHgAAAACaWQBAAAAIO7N5luRDUgN1SJ4kFmy/Ni8U2H6k7bpszok5tlLlRVgHwSHyg==`, env, true},
//{`let x = tx.id == base58'a';true`, `AQQAAAABeAkAAAAAAAACCAUAAAACdHgAAAACaWQBAAAAASEGjR0kcA==`, env, true},
//{`tx.proofs[0] != base58'' && tx.proofs[1] == base58''`, `BAMJAQAAAAIhPQAAAAIJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAAEAAAAACQAAAAAAAAIJAAGRAAAAAggFAAAAAnR4AAAABnByb29mcwAAAAAAAAAAAQEAAAAAB106gzM=`, env, true},
//{`match tx {case t : TransferTransaction | MassTransferTransaction | ExchangeTransaction => true; case _ => false}`, `AQQAAAAHJG1hdGNoMAUAAAACdHgDAwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAABNFeGNoYW5nZVRyYW5zYWN0aW9uBgMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAXTWFzc1RyYW5zZmVyVHJhbnNhY3Rpb24GCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAE1RyYW5zZmVyVHJhbnNhY3Rpb24EAAAAAXQFAAAAByRtYXRjaDAGB6Ilvok=`, env, true},
//{`V2: match transactionById(tx.id) {case t: Unit => false case _ => true}`, `AgQAAAAHJG1hdGNoMAkAA+gAAAABCAUAAAACdHgAAAACaWQDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABFVuaXQEAAAAAXQFAAAAByRtYXRjaDAHBp9TFcQ=`, env, true},
//{`Up() == UP`, `AwkAAAAAAAACCQEAAAACVXAAAAAABQAAAAJVUPGUxeg=`, nil, true},
{`Up() == UP`, `AwkAAAAAAAACCQEAAAACVXAAAAAABQAAAAJVUPGUxeg=`, env, true},
//{`HalfUp() == HALFUP`, `AwkAAAAAAAACCQEAAAAGSGFsZlVwAAAAAAUAAAAGSEFMRlVQbUfpTQ==`, nil, true},
//{`let a0 = NoAlg() == NOALG; let a1 = Md5() == MD5; let a2 = Sha1() == SHA1; let a3 = Sha224() == SHA224; let a4 = Sha256() == SHA256; let a5 = Sha384() == SHA384; let a6 = Sha512() == SHA512; let a7 = Sha3224() == SHA3224; let a8 = Sha3256() == SHA3256; let a9 = Sha3384() == SHA3384; let a10 = Sha3512() == SHA3512; a0 && a1 && a2 && a3 && a4 && a5 && a6 && a7 && a8 && a9 && a10`, `AwQAAAACYTAJAAAAAAAAAgkBAAAABU5vQWxnAAAAAAUAAAAFTk9BTEcEAAAAAmExCQAAAAAAAAIJAQAAAANNZDUAAAAABQAAAANNRDUEAAAAAmEyCQAAAAAAAAIJAQAAAARTaGExAAAAAAUAAAAEU0hBMQQAAAACYTMJAAAAAAAAAgkBAAAABlNoYTIyNAAAAAAFAAAABlNIQTIyNAQAAAACYTQJAAAAAAAAAgkBAAAABlNoYTI1NgAAAAAFAAAABlNIQTI1NgQAAAACYTUJAAAAAAAAAgkBAAAABlNoYTM4NAAAAAAFAAAABlNIQTM4NAQAAAACYTYJAAAAAAAAAgkBAAAABlNoYTUxMgAAAAAFAAAABlNIQTUxMgQAAAACYTcJAAAAAAAAAgkBAAAAB1NoYTMyMjQAAAAABQAAAAdTSEEzMjI0BAAAAAJhOAkAAAAAAAACCQEAAAAHU2hhMzI1NgAAAAAFAAAAB1NIQTMyNTYEAAAAAmE5CQAAAAAAAAIJAQAAAAdTaGEzMzg0AAAAAAUAAAAHU0hBMzM4NAQAAAADYTEwCQAAAAAAAAIJAQAAAAdTaGEzNTEyAAAAAAUAAAAHU0hBMzUxMgMDAwMDAwMDAwMFAAAAAmEwBQAAAAJhMQcFAAAAAmEyBwUAAAACYTMHBQAAAAJhNAcFAAAAAmE1BwUAAAACYTYHBQAAAAJhNwcFAAAAAmE4BwUAAAACYTkHBQAAAANhMTAHRc/wAA==`, nil, true},
//{`Unit() == unit`, `AwkAAAAAAAACCQEAAAAEVW5pdAAAAAAFAAAABHVuaXTstg1G`, nil, true},
//{`let a0 = NoAlg() == NOALG; let a1 = Md5() == MD5; let a2 = Sha1() == SHA1; let a3 = Sha224() == SHA224; let a4 = Sha256() == SHA256; let a5 = Sha384() == SHA384; let a6 = Sha512() == SHA512; let a7 = Sha3224() == SHA3224; let a8 = Sha3256() == SHA3256; let a9 = Sha3384() == SHA3384; let a10 = Sha3512() == SHA3512; a0 && a1 && a2 && a3 && a4 && a5 && a6 && a7 && a8 && a9 && a10`, `AwQAAAACYTAJAAAAAAAAAgkBAAAABU5vQWxnAAAAAAUAAAAFTk9BTEcEAAAAAmExCQAAAAAAAAIJAQAAAANNZDUAAAAABQAAAANNRDUEAAAAAmEyCQAAAAAAAAIJAQAAAARTaGExAAAAAAUAAAAEU0hBMQQAAAACYTMJAAAAAAAAAgkBAAAABlNoYTIyNAAAAAAFAAAABlNIQTIyNAQAAAACYTQJAAAAAAAAAgkBAAAABlNoYTI1NgAAAAAFAAAABlNIQTI1NgQAAAACYTUJAAAAAAAAAgkBAAAABlNoYTM4NAAAAAAFAAAABlNIQTM4NAQAAAACYTYJAAAAAAAAAgkBAAAABlNoYTUxMgAAAAAFAAAABlNIQTUxMgQAAAACYTcJAAAAAAAAAgkBAAAAB1NoYTMyMjQAAAAABQAAAAdTSEEzMjI0BAAAAAJhOAkAAAAAAAACCQEAAAAHU2hhMzI1NgAAAAAFAAAAB1NIQTMyNTYEAAAAAmE5CQAAAAAAAAIJAQAAAAdTaGEzMzg0AAAAAAUAAAAHU0hBMzM4NAQAAAADYTEwCQAAAAAAAAIJAQAAAAdTaGEzNTEyAAAAAAUAAAAHU0hBMzUxMgMDAwMDAwMDAwMFAAAAAmEwBQAAAAJhMQcFAAAAAmEyBwUAAAACYTMHBQAAAAJhNAcFAAAAAmE1BwUAAAACYTYHBQAAAAJhNwcFAAAAAmE4BwUAAAACYTkHBQAAAANhMTAHRc/wAA==`, env, true},
//{`Unit() == unit`, `AwkAAAAAAAACCQEAAAAEVW5pdAAAAAAFAAAABHVuaXTstg1G`, env, true},
} {
src, err := base64.StdEncoding.DecodeString(test.source)
require.NoError(t, err, test.comment)
@@ -144,8 +144,8 @@ func Test33(t *testing.T) {
OpReturn,
// ENTRYPOINT
at(0),
OpPushArg, to(1), // jump to the beginning, first variable
OpPushArg, to(2), // jump to the second variable
OpSetArg, to(1), // jump to the beginning, first variable
OpSetArg, to(2), // jump to the second variable
OpCall, 0, 8, // вызов пользовательской функции add
OpReturn,
)
@@ -304,7 +304,7 @@ func TestCallWithConstArg(t *testing.T) {
OpReturn,

OpTrue, OpReturn,
OpPushArg, 0, 1, 0, 9,
OpSetArg, 0, 1, 0, 9,
OpCall, 0, 4,

OpReturn,
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package ride

// Assigment: let x = 5
type AssigmentFsm struct {
type AssigmentState struct {
params
prev Fsm
name string
offset uint16
}

func (a AssigmentFsm) Property(name string) Fsm {
panic("AssigmentFsm Property")
func (a AssigmentState) Property(name string) Fsm {
panic("AssigmentState Property")
}

func (a AssigmentFsm) FuncDeclaration(name string, args []string) Fsm {
func (a AssigmentState) FuncDeclaration(name string, args []string) Fsm {
return funcDeclarationFsmTransition(a, a.params, name, args)
}

func (a AssigmentFsm) Bytes(b []byte) Fsm {
func (a AssigmentState) Bytes(b []byte) Fsm {
return constant(a, a.params, rideBytes(b))
}

func (a AssigmentFsm) Condition() Fsm {
func (a AssigmentState) Condition() Fsm {
return conditionalTransition(a, a.params)
}

func (a AssigmentFsm) TrueBranch() Fsm {
panic("Illegal call `TrueBranch` on AssigmentFsm")
func (a AssigmentState) TrueBranch() Fsm {
panic("Illegal call `TrueBranch` on AssigmentState")
}

func (a AssigmentFsm) FalseBranch() Fsm {
panic("Illegal call `FalseBranch` on AssigmentFsm")
func (a AssigmentState) FalseBranch() Fsm {
panic("Illegal call `FalseBranch` on AssigmentState")
}

func (a AssigmentFsm) String(s string) Fsm {
func (a AssigmentState) String(s string) Fsm {
return constant(a, a.params, rideString(s))
}

func (a AssigmentFsm) Boolean(v bool) Fsm {
func (a AssigmentState) Boolean(v bool) Fsm {
return boolean(a, a.params, v)
}

@@ -45,41 +45,36 @@ func assigmentFsmTransition(prev Fsm, params params, name string) Fsm {
}

func newAssigmentFsm(prev Fsm, p params, name string) Fsm {
return AssigmentFsm{
prev: prev,
params: params{
b: p.b,
c: p.c,
f: p.f,
r: p.r,
},
return AssigmentState{
prev: prev,
params: p,
name: name,
offset: p.b.len(),
}
}

// Create new scope, so assigment in assigment can't affect global state.
func (a AssigmentFsm) Assigment(name string) Fsm {
func (a AssigmentState) Assigment(name string) Fsm {
params := a.params
params.r = newReferences(params.r)
return assigmentFsmTransition(a, params, name)
}

func (a AssigmentFsm) Return() Fsm {
func (a AssigmentState) Return() Fsm {
a.b.ret()
// store reference on variable and it's offset.
a.r.set(a.name, a.offset)
return a.prev
}

func (a AssigmentFsm) Long(value int64) Fsm {
func (a AssigmentState) Long(value int64) Fsm {
return long(a, a.params, value)
}

func (a AssigmentFsm) Call(name string, argc uint16) Fsm {
func (a AssigmentState) Call(name string, argc uint16) Fsm {
return callTransition(a, a.params, name, argc)
}

func (a AssigmentFsm) Reference(name string) Fsm {
func (a AssigmentState) Reference(name string) Fsm {
return reference(a, a.params, name)
}
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package ride
import "fmt"

// Function call
type CallSystemFsm struct {
type CallSystemState struct {
prev Fsm
params
name string
@@ -12,42 +12,35 @@ type CallSystemFsm struct {
argn []uint16
}

func property(f Fsm, p params, name string) Fsm {
p.b.writeByte(OpProperty)
index := p.c.put(rideString(name))
p.b.push(index)
return f
func (a CallSystemState) Property(name string) Fsm {
return propertyTransition(a, a.params, name)
}

func (a CallSystemFsm) Property(name string) Fsm {
return property(a, a.params, name)
}

func (a CallSystemFsm) FuncDeclaration(name string, args []string) Fsm {
func (a CallSystemState) FuncDeclaration(name string, args []string) Fsm {
return funcDeclarationFsmTransition(a, a.params, name, args)
}

func (a CallSystemFsm) Bytes(b []byte) Fsm {
func (a CallSystemState) Bytes(b []byte) Fsm {
return constant(a, a.params, rideBytes(b))
}

func (a CallSystemFsm) Condition() Fsm {
func (a CallSystemState) Condition() Fsm {
return conditionalTransition(a, a.params)
}

func (a CallSystemFsm) TrueBranch() Fsm {
func (a CallSystemState) TrueBranch() Fsm {
panic("Illegal call `TrueBranch` on CallFsm")
}

func (a CallSystemFsm) FalseBranch() Fsm {
func (a CallSystemState) FalseBranch() Fsm {
panic("Illegal call `FalseBranch` on CallFsm")
}

func (a CallSystemFsm) String(s string) Fsm {
func (a CallSystemState) String(s string) Fsm {
return str(a, a.params, s)
}

func (a CallSystemFsm) Boolean(v bool) Fsm {
func (a CallSystemState) Boolean(v bool) Fsm {
return boolean(a, a.params, v)
}

@@ -59,32 +52,32 @@ func callTransition(prev Fsm, params params, name string, argc uint16) Fsm {
}

func newCallSystemFsm(prev Fsm, params params, name string, argc uint16) Fsm {
return &CallSystemFsm{
return &CallSystemState{
prev: prev,
params: params,
name: name,
argc: argc,
}
}

func (a CallSystemFsm) Assigment(name string) Fsm {
func (a CallSystemState) Assigment(name string) Fsm {
return assigmentFsmTransition(a, a.params, name)
}

func (a CallSystemFsm) Long(value int64) Fsm {
func (a CallSystemState) Long(value int64) Fsm {
index := a.params.c.put(rideInt(value))
a.params.b.push(index)
return a
}

func (a CallSystemFsm) Return() Fsm {
func (a CallSystemState) Return() Fsm {

//// check user functions
//n, ok := a.r.get(a.name)
//if ok {
// a.b.startPos()
// for _, pos := range a.argn {
// a.b.writeByte(OpPushArg)
// a.b.writeByte(OpSetArg)
// a.b.write(encode(pos))
// //a.b.writeByte(OpReturn)
// }
@@ -110,10 +103,10 @@ func (a CallSystemFsm) Return() Fsm {
return a.prev
}

func (a CallSystemFsm) Call(name string, argc uint16) Fsm {
func (a CallSystemState) Call(name string, argc uint16) Fsm {
return callTransition(a, a.params, name, argc)
}

func (a CallSystemFsm) Reference(name string) Fsm {
func (a CallSystemState) Reference(name string) Fsm {
return reference(a, a.params, name)
}
Loading