}
var binaryOps = []binaryOp{
- // disjunctions disallowed (for now?)
- // {"||", 1, "BOOLOR", "Boolean", "Boolean", "Boolean"},
-
- // and disallow this too
- // {"&&", 2, "BOOLAND", "Boolean", "Boolean", "Boolean"},
+ {"||", 1, "BOOLOR", "Boolean", "Boolean", "Boolean"},
+ {"&&", 2, "BOOLAND", "Boolean", "Boolean", "Boolean"},
{">", 3, "GREATERTHAN", "Integer", "Integer", "Boolean"},
{"<", 3, "LESSTHAN", "Integer", "Integer", "Boolean"},
var unaryOps = []unaryOp{
{"-", "NEGATE", "Integer", "Integer"},
- // not not allowed (for now?)
- // {"!", "NOT", "Boolean", "Boolean"},
+ {"!", "NOT", "Boolean", "Boolean"},
{"~", "INVERT", "", ""},
}
{
"TestConstantMath",
equitytest.TestConstantMath,
- "547a547a935a93880431323330aa8806737472696e67aa87",
+ "765779577a935a93887c0431323330aa887c06737472696e67aa887c91697b011493879a",
},
}
for _, c := range cases {
}
`
const TestConstantMath = `
-contract TestConstantMath(result: Integer, hashByte: Hash, hashStr: Hash) locks valueAmount of valueAsset {
- clause calculation(left: Integer, right: Integer) {
+contract TestConstantMath(result: Integer, hashByte: Hash, hashStr: Hash, outcome: Boolean) locks valueAmount of valueAsset {
+ clause calculation(left: Integer, right: Integer, boolResult: Boolean) {
verify result == left + right + 10
verify hashByte == sha3(0x31323330)
verify hashStr == sha3('string')
+ verify !outcome
+ verify boolResult && (result == left + 20)
unlock valueAmount of valueAsset
}
}
// consume functions
var keywords = []string{
- "contract", "clause", "verify", "output", "return",
- "locks", "requires", "of", "lock", "with", "unlock",
+ "contract", "clause", "verify", "locks", "of",
+ "lock", "with", "unlock", "if", "else",
+ "define", "assign", "true", "false",
}
func consumeKeyword(p *parser, keyword string) {
if newOffset >= 0 {
return bytesliteral, newOffset
}
+ booleanLiteral, newOffset := scanBoolLiteral(buf, offset) // true or false
+ if newOffset >= 0 {
+ return booleanLiteral, newOffset
+ }
return nil, -1
}
return bytesLiteral(decoded), i
}
+func scanBoolLiteral(buf []byte, offset int) (booleanLiteral, int) {
+ offset = skipWsAndComments(buf, offset)
+ if offset >= len(buf) {
+ return false, -1
+ }
+
+ newOffset := scanKeyword(buf, offset, "true")
+ if newOffset < 0 {
+ if newOffset = scanKeyword(buf, offset, "false"); newOffset < 0 {
+ return false, -1
+ }
+ return false, newOffset
+ }
+ return true, newOffset
+}
+
func skipWsAndComments(buf []byte, offset int) int {
var inComment bool
for ; offset < len(buf); offset++ {