Skip to content

Commit

Permalink
handle recursive values (due to references) in string function
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed May 17, 2021
1 parent 9281269 commit 711d294
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 75 deletions.
3 changes: 2 additions & 1 deletion runtime/cmd/execute/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ func printWelcome() {
}

func colorizeResult(value interpreter.Value) string {
return aurora.Colorize(fmt.Sprint(value), aurora.YellowFg|aurora.BrightFg).String()
str := value.String(interpreter.StringResults{})
return aurora.Colorize(str, aurora.YellowFg|aurora.BrightFg).String()
}

func colorizeError(message string) string {
Expand Down
7 changes: 5 additions & 2 deletions runtime/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ func TestRuntimeContract(t *testing.T) {

contractKey := []byte(formatContractKey("Test"))

codeArrayString := interpreter.ByteSliceToByteArrayValue([]byte(tc.code)).String()
code2ArrayString := interpreter.ByteSliceToByteArrayValue([]byte(tc.code2)).String()
codeArrayString := interpreter.ByteSliceToByteArrayValue([]byte(tc.code)).
String(interpreter.StringResults{})

code2ArrayString := interpreter.ByteSliceToByteArrayValue([]byte(tc.code2)).
String(interpreter.StringResults{})

t.Run("add", func(t *testing.T) {

Expand Down
2 changes: 1 addition & 1 deletion runtime/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) {
argumentCodes := make([]string, len(test.arguments))

for i, argument := range test.arguments {
argumentCodes[i] = argument.String()
argumentCodes[i] = argument.String(interpreter.StringResults{})
}

argumentCode := strings.Join(argumentCodes, ", ")
Expand Down
8 changes: 4 additions & 4 deletions runtime/interpreter/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ func (v BlockValue) IDAsByteArray() [sema.BlockIDSize]byte {
return byteArray
}

func (v BlockValue) String() string {
func (v BlockValue) String(results StringResults) string {
return fmt.Sprintf(
"Block(height: %s, view: %s, id: 0x%x, timestamp: %s)",
v.Height,
v.View,
v.Height.String(results),
v.View.String(results),
v.IDAsByteArray(),
v.Timestamp,
v.Timestamp.String(results),
)
}

Expand Down
8 changes: 4 additions & 4 deletions runtime/interpreter/deployed_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ func (v DeployedContractValue) Destroy(_ *Interpreter, _ func() LocationRange) {
// NO-OP
}

func (v DeployedContractValue) String() string {
func (v DeployedContractValue) String(results StringResults) string {
return fmt.Sprintf(
"DeployedContract(address: %s, name: %s, code: %s)",
v.Address.String(),
v.Name,
v.Code,
v.Address.String(results),
v.Name.String(results),
v.Code.String(results),
)
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/interpreter/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (e CyclicLinkError) Error() string {
if i > 0 {
builder.WriteString(" -> ")
}
builder.WriteString(path.String())
builder.WriteString(path.String(StringResults{}))
}
paths := builder.String()

Expand Down
8 changes: 4 additions & 4 deletions runtime/interpreter/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type InterpretedFunctionValue struct {
PostConditions ast.Conditions
}

func (f InterpretedFunctionValue) String() string {
func (f InterpretedFunctionValue) String(results StringResults) string {
return fmt.Sprintf("Function%s", f.Type.String())
}

Expand Down Expand Up @@ -135,7 +135,7 @@ type HostFunctionValue struct {
NestedVariables *StringVariableOrderedMap
}

func (f HostFunctionValue) String() string {
func (f HostFunctionValue) String(results StringResults) string {
// TODO: include type
return "Function(...)"
}
Expand Down Expand Up @@ -217,8 +217,8 @@ type BoundFunctionValue struct {
Self *CompositeValue
}

func (f BoundFunctionValue) String() string {
return fmt.Sprint(f.Function)
func (f BoundFunctionValue) String(results StringResults) string {
return f.Function.String(results)
}

func (BoundFunctionValue) IsValue() {}
Expand Down
Loading

0 comments on commit 711d294

Please sign in to comment.