Skip to content

Commit

Permalink
Merge branch 'master' into integrate-cacheless-core
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau authored Oct 24, 2023
2 parents 21dc7c5 + 2a86c45 commit cea7781
Show file tree
Hide file tree
Showing 19 changed files with 307 additions and 48 deletions.
8 changes: 5 additions & 3 deletions test/contracts/answer-locals/answer-locals.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
(type (;0;) (func (param i64)))
(type (;1;) (func))
(import "env" "int64finish" (func (;0;) (type 0)))
(func (;1;) (type 1)
(local i64 i64 i64 i64 i64)
(func (;1;) (type 1))
(func (;2;) (type 1)
(local i64 i64 i64 i64)
i64.const 42
call 0)
(table (;0;) 1 1 funcref)
(memory (;0;) 2)
(global (;0;) (mut i32) (i32.const 66560))
(export "memory" (memory 0))
(export "answer" (func 1)))
(export "init" (func 1))
(export "answer" (func 2)))
Binary file modified test/contracts/answer-locals/output/answer-locals.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions test/contracts/answer/answer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "../mxvm/context.h"

void init() {}

void answer() {
int64finish(42);
}
1 change: 1 addition & 0 deletions test/contracts/answer/answer.export
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
answer
init
Binary file added test/contracts/bad-extra/output/bad-extra.wasm
Binary file not shown.
30 changes: 30 additions & 0 deletions test/contracts/bad-recursive/bad-recursive.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
typedef unsigned char byte;
typedef unsigned int i32;
typedef unsigned long long i64;
typedef unsigned int bigInt;

bigInt bigIntNew(long long value);
void bigIntFinishUnsigned(bigInt reference);

void init()
{
}

i64 doStackoverflow(i64 a)
{
if (a % 2 == 0)
{
return 42;
}

i64 x = doStackoverflow(a * 8 + 1);
i64 y = doStackoverflow(a * 2 + 1);
return x + y + a;
}

void badRecursive()
{
i64 result = doStackoverflow(1);
bigInt resultBig = bigIntNew(result);
bigIntFinishUnsigned(resultBig);
}
2 changes: 2 additions & 0 deletions test/contracts/bad-recursive/bad-recursive.export
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
init
badRecursive
Binary file not shown.
4 changes: 4 additions & 0 deletions test/contracts/counter/counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ void init() {
int64storageStore(COUNTER_KEY, COUNTER_KEY_LEN, 1);
}

void upgrade() {
int64storageStore(COUNTER_KEY, COUNTER_KEY_LEN, 1);
}

void increment() {
i64 counter = int64storageLoad(COUNTER_KEY, COUNTER_KEY_LEN);
counter++;
Expand Down
1 change: 1 addition & 0 deletions test/contracts/counter/counter.export
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
init
upgrade
increment
decrement
get
Binary file modified test/contracts/counter/output/counter.wasm
100755 → 100644
Binary file not shown.
215 changes: 178 additions & 37 deletions test/contracts/counter/output/counter.wat
Original file line number Diff line number Diff line change
@@ -1,56 +1,197 @@
(module
(type $t0 (func (param i32 i32 i64) (result i32)))
(type $t1 (func (param i32 i32) (result i64)))
(type $t2 (func (param i64)))
(type $t3 (func))
(import "env" "int64storageStore" (func $env.int64storageStore (type $t0)))
(import "env" "int64storageLoad" (func $env.int64storageLoad (type $t1)))
(import "env" "int64finish" (func $env.int64finish (type $t2)))
(func $init (type $t3)
(type (;0;) (func (param i32 i32 i64) (result i32)))
(type (;1;) (func (param i32 i32) (result i64)))
(type (;2;) (func (param i64)))
(type (;3;) (func))
(import "env" "int64storageStore" (func (;0;) (type 0)))
(import "env" "int64storageLoad" (func (;1;) (type 1)))
(import "env" "int64finish" (func (;2;) (type 2)))
(func (;3;) (type 3)
(local i32 i32 i64)
i32.const 1024
local.set 0
i32.const 7
local.set 1
i64.const 1
call $env.int64storageStore
drop)
(func $increment (type $t3)
(local $l0 i64)
local.set 2
local.get 0
local.get 1
local.get 2
call 0
drop
return)
(func (;4;) (type 3)
(local i32 i32 i64)
i32.const 1024
local.set 0
i32.const 7
local.set 1
i64.const 1
local.set 2
local.get 0
local.get 1
local.get 2
call 0
drop
return)
(func (;5;) (type 3)
(local i32 i32 i32 i32 i32 i64 i64 i64 i64 i64 i64 i32 i32)
global.get 0
local.set 0
i32.const 16
local.set 1
local.get 0
local.get 1
i32.sub
local.set 2
local.get 2
global.set 0
i32.const 1024
local.set 3
i32.const 7
call $env.int64storageLoad
local.set 4
local.get 3
local.get 4
call 1
local.set 5
local.get 2
local.get 5
i64.store offset=8
local.get 2
i64.load offset=8
local.set 6
i64.const 1
local.set 7
local.get 6
local.get 7
i64.add
local.tee $l0
call $env.int64storageStore
local.set 8
local.get 2
local.get 8
i64.store offset=8
local.get 2
i64.load offset=8
local.set 9
local.get 3
local.get 4
local.get 9
call 0
drop
local.get $l0
call $env.int64finish)
(func $decrement (type $t3)
(local $l0 i64)
i32.const 1024
i32.const 7
local.get 2
i64.load offset=8
local.set 10
local.get 10
call 2
i32.const 16
local.set 11
local.get 2
local.get 11
i32.add
local.set 12
local.get 12
global.set 0
return)
(func (;6;) (type 3)
(local i32 i32 i32 i32 i32 i64 i64 i64 i64 i64 i64 i32 i32)
global.get 0
local.set 0
i32.const 16
local.set 1
local.get 0
local.get 1
i32.sub
local.set 2
local.get 2
global.set 0
i32.const 1024
local.set 3
i32.const 7
call $env.int64storageLoad
local.set 4
local.get 3
local.get 4
call 1
local.set 5
local.get 2
local.get 5
i64.store offset=8
local.get 2
i64.load offset=8
local.set 6
i64.const -1
local.set 7
local.get 6
local.get 7
i64.add
local.tee $l0
call $env.int64storageStore
local.set 8
local.get 2
local.get 8
i64.store offset=8
local.get 2
i64.load offset=8
local.set 9
local.get 3
local.get 4
local.get 9
call 0
drop
local.get $l0
call $env.int64finish)
(func $get (type $t3)
local.get 2
i64.load offset=8
local.set 10
local.get 10
call 2
i32.const 16
local.set 11
local.get 2
local.get 11
i32.add
local.set 12
local.get 12
global.set 0
return)
(func (;7;) (type 3)
(local i32 i32 i32 i32 i32 i64 i64 i32 i32)
global.get 0
local.set 0
i32.const 16
local.set 1
local.get 0
local.get 1
i32.sub
local.set 2
local.get 2
global.set 0
i32.const 1024
local.set 3
i32.const 7
call $env.int64storageLoad
call $env.int64finish)
(table $T0 1 1 funcref)
(memory $memory 2)
(global $g0 (mut i32) (i32.const 66576))
local.set 4
local.get 3
local.get 4
call 1
local.set 5
local.get 2
local.get 5
i64.store offset=8
local.get 2
i64.load offset=8
local.set 6
local.get 6
call 2
i32.const 16
local.set 7
local.get 2
local.get 7
i32.add
local.set 8
local.get 8
global.set 0
return)
(table (;0;) 1 1 funcref)
(memory (;0;) 2)
(global (;0;) (mut i32) (i32.const 66576))
(export "memory" (memory 0))
(export "init" (func $init))
(export "increment" (func $increment))
(export "decrement" (func $decrement))
(export "get" (func $get))
(data $d0 (i32.const 1024) "COUNTER\00"))
(export "init" (func 3))
(export "upgrade" (func 4))
(export "increment" (func 5))
(export "decrement" (func 6))
(export "get" (func 7))
(data (;0;) (i32.const 1024) "COUNTER\00"))
2 changes: 1 addition & 1 deletion vmhost/hostCore/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ func (host *vmHost) callUpgradeFunction() error {
func (host *vmHost) callSCFunction(functionName string) error {
runtime := host.Runtime()
if !runtime.HasFunction(functionName) {
return nil
return executor.ErrFuncNotFound
}

err := runtime.CallSCFunction(functionName)
Expand Down
Loading

0 comments on commit cea7781

Please sign in to comment.