summaryrefslogtreecommitdiff
path: root/data/transactions/logic/assembler.go
diff options
context:
space:
mode:
Diffstat (limited to 'data/transactions/logic/assembler.go')
-rw-r--r--data/transactions/logic/assembler.go38
1 files changed, 26 insertions, 12 deletions
diff --git a/data/transactions/logic/assembler.go b/data/transactions/logic/assembler.go
index 58e597ecd..5b4d72b38 100644
--- a/data/transactions/logic/assembler.go
+++ b/data/transactions/logic/assembler.go
@@ -27,7 +27,6 @@ import (
"errors"
"fmt"
"io"
- "os"
"sort"
"strconv"
"strings"
@@ -472,13 +471,16 @@ func asmPushInt(ops *OpStream, spec *OpSpec, args []string) error {
return nil
}
func asmPushBytes(ops *OpStream, spec *OpSpec, args []string) error {
- if len(args) != 1 {
- return ops.errorf("%s needs one argument", spec.Name)
+ if len(args) == 0 {
+ return ops.errorf("%s operation needs byte literal argument", spec.Name)
}
- val, _, err := parseBinaryArgs(args)
+ val, consumed, err := parseBinaryArgs(args)
if err != nil {
return ops.error(err)
}
+ if len(args) != consumed {
+ return ops.errorf("%s operation with extraneous argument", spec.Name)
+ }
ops.pending.WriteByte(spec.Opcode)
var scratch [binary.MaxVarintLen64]byte
vlen := binary.PutUvarint(scratch[:], uint64(len(val)))
@@ -636,12 +638,15 @@ func parseStringLiteral(input string) (result []byte, err error) {
// byte "this is a string\n"
func assembleByte(ops *OpStream, spec *OpSpec, args []string) error {
if len(args) == 0 {
- return ops.error("byte operation needs byte literal argument")
+ return ops.errorf("%s operation needs byte literal argument", spec.Name)
}
- val, _, err := parseBinaryArgs(args)
+ val, consumed, err := parseBinaryArgs(args)
if err != nil {
return ops.error(err)
}
+ if len(args) != consumed {
+ return ops.errorf("%s operation with extraneous argument", spec.Name)
+ }
ops.ByteLiteral(val)
return nil
}
@@ -1290,8 +1295,8 @@ func typeDig(ops *OpStream, args []string) (StackTypes, StackTypes) {
idx := len(ops.typeStack) - depth
if idx >= 0 {
returns[len(returns)-1] = ops.typeStack[idx]
- for i := idx + 1; i < len(ops.typeStack); i++ {
- returns[i-idx-1] = ops.typeStack[i]
+ for i := idx; i < len(ops.typeStack); i++ {
+ returns[i-idx] = ops.typeStack[i]
}
}
return anys, returns
@@ -1588,6 +1593,7 @@ func (ops *OpStream) assemble(fin io.Reader) error {
for scanner.Scan() {
ops.sourceLine++
line := scanner.Text()
+ line = strings.TrimSpace(line)
if len(line) == 0 {
ops.trace("%d: 0 line\n", ops.sourceLine)
continue
@@ -2102,19 +2108,27 @@ func (ops *OpStream) warnf(format string, a ...interface{}) error {
return ops.warn(fmt.Errorf(format, a...))
}
-// ReportProblems issues accumulated warnings and errors to stderr.
-func (ops *OpStream) ReportProblems(fname string) {
+// ReportProblems issues accumulated warnings and outputs errors to an io.Writer.
+func (ops *OpStream) ReportProblems(fname string, writer io.Writer) {
for i, e := range ops.Errors {
if i > 9 {
break
}
- fmt.Fprintf(os.Stderr, "%s: %s\n", fname, e)
+ if fname == "" {
+ fmt.Fprintf(writer, "%s\n", e)
+ } else {
+ fmt.Fprintf(writer, "%s: %s\n", fname, e)
+ }
}
for i, w := range ops.Warnings {
if i > 9 {
break
}
- fmt.Fprintf(os.Stderr, "%s: %s\n", fname, w)
+ if fname == "" {
+ fmt.Fprintf(writer, "%s\n", w)
+ } else {
+ fmt.Fprintf(writer, "%s: %s\n", fname, w)
+ }
}
}