Skip to content

Commit cc44e07

Browse files
author
nathanielCherian
committed
Native Introspection Opcodes grammar
1 parent b6de308 commit cc44e07

10 files changed

Lines changed: 902 additions & 631 deletions

examples/next.cash

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ pragma cashscript 0.7.0;
22

33
contract P2PKH() {
44
function spend() {
5-
bytes2 left, bytes2 right = 0x123456.split(2);
6-
require(left == right);
5+
// bytes2 left, bytes2 right = 0x123456.split(2);
6+
// require(left == right);
7+
require(tx.outputs[0].value == tx.inputs[this.activeInputIndex].value - 1000);
78
}
89
}

src/CashscriptLinter/grammar/CashScript.g4

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ expression
9292
| functionCall # FunctionCallExpression
9393
| 'new' Identifier expressionList #Instantiation
9494
| expression '[' index=NumberLiteral ']' # TupleIndexOp
95+
| scope='tx.outputs' '[' expression ']' op=('.value' | '.lockingBytecode') # UnaryIntrospectionOp
96+
| scope='tx.inputs' '[' expression ']' op=('.value' | '.lockingBytecode' | '.outpointTransactionHash' | '.outpointIndex' | '.unlockingBytecode' | '.sequenceNumber') # UnaryIntrospectionOp
9597
| expression op=('.reverse()' | '.length') # UnaryOp
96-
| op=('!' | '-') expression # UnaryOp
97-
// | expression '**' expression --- OP_POW does not exist in BCH Script
98-
// | expression ('*' | '/' | '%') expression --- OP_MUL is disabled in BCH Script
9998
| left=expression op='.split' '(' right=expression ')' # BinaryOp
100-
| left=expression op=('/' | '%') right=expression # BinaryOp
99+
| op=('!' | '-') expression # UnaryOp
100+
| left=expression op=('*' | '/' | '%') right=expression # BinaryOp
101101
| left=expression op=('+' | '-') right=expression # BinaryOp
102102
// | expression ('>>' | '<<') expression --- OP_LSHIFT & RSHIFT are disabled in BCH Script
103103
| left=expression op=('<' | '<=' | '>' | '>=') right=expression # BinaryOp
@@ -108,7 +108,7 @@ expression
108108
| left=expression op='&&' right=expression # BinaryOp
109109
| left=expression op='||' right=expression # BinaryOp
110110
| '[' (expression (',' expression)* ','?)? ']' # Array
111-
| PreimageField # PreimageField
111+
| NullaryOp # NullaryOp
112112
| Identifier # Identifier
113113
| literal # LiteralExpression
114114
;
@@ -172,18 +172,13 @@ TxVar
172172
| 'tx.time'
173173
;
174174

175-
PreimageField
176-
: 'tx.version'
177-
| 'tx.hashPrevouts'
178-
| 'tx.hashSequence'
179-
| 'tx.outpoint'
180-
| 'tx.bytecode'
181-
| 'tx.value'
182-
| 'tx.sequence'
183-
| 'tx.hashOutputs'
175+
NullaryOp
176+
: 'this.activeInputIndex'
177+
| 'this.activeBytecode'
178+
| 'tx.inputs.length'
179+
| 'tx.outputs.length'
180+
| 'tx.version'
184181
| 'tx.locktime'
185-
| 'tx.hashtype'
186-
| 'tx.preimage'
187182
;
188183

189184
Identifier

src/CashscriptLinter/grammar/CashScript.interp

Lines changed: 21 additions & 3 deletions
Large diffs are not rendered by default.

src/CashscriptLinter/grammar/CashScript.tokens

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,30 @@ T__39=40
4141
T__40=41
4242
T__41=42
4343
T__42=43
44-
VersionLiteral=44
45-
BooleanLiteral=45
46-
NumberUnit=46
47-
NumberLiteral=47
48-
Bytes=48
49-
Bound=49
50-
StringLiteral=50
51-
DateLiteral=51
52-
HexLiteral=52
53-
TxVar=53
54-
PreimageField=54
55-
Identifier=55
56-
WHITESPACE=56
57-
COMMENT=57
58-
LINE_COMMENT=58
44+
T__43=44
45+
T__44=45
46+
T__45=46
47+
T__46=47
48+
T__47=48
49+
T__48=49
50+
T__49=50
51+
T__50=51
52+
T__51=52
53+
VersionLiteral=53
54+
BooleanLiteral=54
55+
NumberUnit=55
56+
NumberLiteral=56
57+
Bytes=57
58+
Bound=58
59+
StringLiteral=59
60+
DateLiteral=60
61+
HexLiteral=61
62+
TxVar=62
63+
NullaryOp=63
64+
Identifier=64
65+
WHITESPACE=65
66+
COMMENT=66
67+
LINE_COMMENT=67
5968
'pragma'=1
6069
';'=2
6170
'cashscript'=3
@@ -79,23 +88,32 @@ LINE_COMMENT=58
7988
'new'=21
8089
'['=22
8190
']'=23
82-
'.reverse()'=24
83-
'.length'=25
84-
'!'=26
85-
'-'=27
86-
'.split'=28
87-
'/'=29
88-
'%'=30
89-
'+'=31
90-
'=='=32
91-
'!='=33
92-
'&'=34
93-
'|'=35
94-
'&&'=36
95-
'||'=37
96-
'int'=38
97-
'bool'=39
98-
'string'=40
99-
'pubkey'=41
100-
'sig'=42
101-
'datasig'=43
91+
'tx.outputs'=24
92+
'.value'=25
93+
'.lockingBytecode'=26
94+
'tx.inputs'=27
95+
'.outpointTransactionHash'=28
96+
'.outpointIndex'=29
97+
'.unlockingBytecode'=30
98+
'.sequenceNumber'=31
99+
'.reverse()'=32
100+
'.length'=33
101+
'.split'=34
102+
'!'=35
103+
'-'=36
104+
'*'=37
105+
'/'=38
106+
'%'=39
107+
'+'=40
108+
'=='=41
109+
'!='=42
110+
'&'=43
111+
'|'=44
112+
'&&'=45
113+
'||'=46
114+
'int'=47
115+
'bool'=48
116+
'string'=49
117+
'pubkey'=50
118+
'sig'=51
119+
'datasig'=52

src/CashscriptLinter/grammar/CashScriptLexer.interp

Lines changed: 31 additions & 4 deletions
Large diffs are not rendered by default.

src/CashscriptLinter/grammar/CashScriptLexer.tokens

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,30 @@ T__39=40
4141
T__40=41
4242
T__41=42
4343
T__42=43
44-
VersionLiteral=44
45-
BooleanLiteral=45
46-
NumberUnit=46
47-
NumberLiteral=47
48-
Bytes=48
49-
Bound=49
50-
StringLiteral=50
51-
DateLiteral=51
52-
HexLiteral=52
53-
TxVar=53
54-
PreimageField=54
55-
Identifier=55
56-
WHITESPACE=56
57-
COMMENT=57
58-
LINE_COMMENT=58
44+
T__43=44
45+
T__44=45
46+
T__45=46
47+
T__46=47
48+
T__47=48
49+
T__48=49
50+
T__49=50
51+
T__50=51
52+
T__51=52
53+
VersionLiteral=53
54+
BooleanLiteral=54
55+
NumberUnit=55
56+
NumberLiteral=56
57+
Bytes=57
58+
Bound=58
59+
StringLiteral=59
60+
DateLiteral=60
61+
HexLiteral=61
62+
TxVar=62
63+
NullaryOp=63
64+
Identifier=64
65+
WHITESPACE=65
66+
COMMENT=66
67+
LINE_COMMENT=67
5968
'pragma'=1
6069
';'=2
6170
'cashscript'=3
@@ -79,23 +88,32 @@ LINE_COMMENT=58
7988
'new'=21
8089
'['=22
8190
']'=23
82-
'.reverse()'=24
83-
'.length'=25
84-
'!'=26
85-
'-'=27
86-
'.split'=28
87-
'/'=29
88-
'%'=30
89-
'+'=31
90-
'=='=32
91-
'!='=33
92-
'&'=34
93-
'|'=35
94-
'&&'=36
95-
'||'=37
96-
'int'=38
97-
'bool'=39
98-
'string'=40
99-
'pubkey'=41
100-
'sig'=42
101-
'datasig'=43
91+
'tx.outputs'=24
92+
'.value'=25
93+
'.lockingBytecode'=26
94+
'tx.inputs'=27
95+
'.outpointTransactionHash'=28
96+
'.outpointIndex'=29
97+
'.unlockingBytecode'=30
98+
'.sequenceNumber'=31
99+
'.reverse()'=32
100+
'.length'=33
101+
'.split'=34
102+
'!'=35
103+
'-'=36
104+
'*'=37
105+
'/'=38
106+
'%'=39
107+
'+'=40
108+
'=='=41
109+
'!='=42
110+
'&'=43
111+
'|'=44
112+
'&&'=45
113+
'||'=46
114+
'int'=47
115+
'bool'=48
116+
'string'=49
117+
'pubkey'=50
118+
'sig'=51
119+
'datasig'=52

0 commit comments

Comments
 (0)