Skip to content

Commit

Permalink
Refactor and fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Nov 7, 2024
1 parent ad3620e commit b2dab64
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 95 deletions.
27 changes: 15 additions & 12 deletions bbq/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,7 @@ func (c *Compiler) exportConstants() []*bbq.Constant {
}

func (c *Compiler) exportTypes() [][]byte {
types := make([][]byte, len(c.staticTypes))
for index, typeBytes := range c.staticTypes {
types[index] = typeBytes
}
return types
return c.staticTypes
}

func (c *Compiler) exportImports() []*bbq.Import {
Expand Down Expand Up @@ -645,8 +641,15 @@ func (c *Compiler) VisitSwapStatement(_ *ast.SwapStatement) (_ struct{}) {

func (c *Compiler) VisitExpressionStatement(statement *ast.ExpressionStatement) (_ struct{}) {
c.compileExpression(statement.Expression)
// Drop the expression evaluation result
c.emit(opcode.Drop)

switch statement.Expression.(type) {
case *ast.DestroyExpression:
// Do nothing. Destroy operation will not produce any result.
default:
// Otherwise, drop the expression evaluation result.
c.emit(opcode.Drop)
}

return
}

Expand Down Expand Up @@ -748,11 +751,11 @@ func (c *Compiler) VisitInvocationExpression(expression *ast.InvocationExpressio

switch invokedExpr := expression.InvokedExpression.(type) {
case *ast.IdentifierExpression:
typ := c.Elaboration.IdentifierInInvocationType(invokedExpr)
invocationType := typ.(*sema.FunctionType)
if invocationType.IsConstructor {
// TODO:
}
// TODO: Does constructors need any special handling?
//typ := c.Elaboration.IdentifierInInvocationType(invokedExpr)
//invocationType := typ.(*sema.FunctionType)
//if invocationType.IsConstructor {
//}

// Load arguments
c.loadArguments(expression)
Expand Down
12 changes: 6 additions & 6 deletions bbq/vm/test/ft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestFTTransfer(t *testing.T) {

mintTxArgs := []vm.Value{
vm.AddressValue(senderAddress),
vm.IntValue{total},
vm.NewIntValue(total),
}

mintTxAuthorizer := vm.NewAuthAccountReferenceValue(vmConfig, contractsAddress)
Expand All @@ -158,7 +158,7 @@ func TestFTTransfer(t *testing.T) {
transferAmount := int64(1)

tokenTransferTxArgs := []vm.Value{
vm.IntValue{transferAmount},
vm.NewIntValue(transferAmount),
vm.AddressValue(receiverAddress),
}

Expand All @@ -183,9 +183,9 @@ func TestFTTransfer(t *testing.T) {
require.Equal(t, 0, validationScriptVM.StackSize())

if address == senderAddress {
assert.Equal(t, vm.IntValue{total - transferAmount}, result)
assert.Equal(t, vm.NewIntValue(total-transferAmount), result)
} else {
assert.Equal(t, vm.IntValue{transferAmount}, result)
assert.Equal(t, vm.NewIntValue(transferAmount), result)
}
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ func BenchmarkFTTransfer(b *testing.B) {

mintTxArgs := []vm.Value{
vm.AddressValue(senderAddress),
vm.IntValue{total},
vm.NewIntValue(total),
}

mintTxAuthorizer := vm.NewAuthAccountReferenceValue(vmConfig, contractsAddress)
Expand All @@ -305,7 +305,7 @@ func BenchmarkFTTransfer(b *testing.B) {
transferAmount := int64(1)

tokenTransferTxArgs := []vm.Value{
vm.IntValue{transferAmount},
vm.NewIntValue(transferAmount),
vm.AddressValue(receiverAddress),
}

Expand Down
18 changes: 9 additions & 9 deletions bbq/vm/test/vm_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func BenchmarkRecursionFib(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

expected := vm.IntValue{SmallInt: 377}
expected := vm.NewIntValue(377)

for i := 0; i < b.N; i++ {

result, err := vmInstance.Invoke(
"fib",
vm.IntValue{SmallInt: 14},
vm.NewIntValue(14),
)
require.NoError(b, err)
require.Equal(b, expected, result)
Expand All @@ -64,7 +64,7 @@ func BenchmarkImperativeFib(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

var value vm.Value = vm.IntValue{SmallInt: 14}
var value vm.Value = vm.NewIntValue(14)

for i := 0; i < b.N; i++ {
_, err := vmInstance.Invoke("fib", value)
Expand Down Expand Up @@ -97,7 +97,7 @@ func BenchmarkNewStruct(b *testing.B) {
`)
require.NoError(b, err)

value := vm.IntValue{SmallInt: 1}
value := vm.NewIntValue(1)

b.ReportAllocs()
b.ResetTimer()
Expand Down Expand Up @@ -140,7 +140,7 @@ func BenchmarkNewResource(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

value := vm.IntValue{SmallInt: 9}
value := vm.NewIntValue(9)

scriptLocation := runtime_utils.NewScriptLocationGenerator()

Expand All @@ -162,7 +162,7 @@ func BenchmarkNewStructRaw(b *testing.B) {
Storage: storage,
}

fieldValue := vm.IntValue{SmallInt: 7}
fieldValue := vm.NewIntValue(7)

b.ReportAllocs()
b.ResetTimer()
Expand Down Expand Up @@ -239,7 +239,7 @@ func BenchmarkContractImport(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()

value := vm.IntValue{SmallInt: 7}
value := vm.NewIntValue(7)

for i := 0; i < b.N; i++ {
checker, err := ParseAndCheckWithOptions(b, `
Expand Down Expand Up @@ -367,7 +367,7 @@ func BenchmarkMethodCall(b *testing.B) {

vmInstance = vm.NewVM(scriptLocation(), program, vmConfig)

value := vm.IntValue{SmallInt: 10}
value := vm.NewIntValue(10)

b.ResetTimer()
b.ReportAllocs()
Expand Down Expand Up @@ -461,7 +461,7 @@ func BenchmarkMethodCall(b *testing.B) {

vmInstance = vm.NewVM(scriptLocation(), program, vmConfig)

value := vm.IntValue{SmallInt: 10}
value := vm.NewIntValue(10)

b.ResetTimer()
b.ReportAllocs()
Expand Down
Loading

0 comments on commit b2dab64

Please sign in to comment.