1
1
import type { AvmContext } from '../avm_context.js' ;
2
- import { type Field , type MemoryValue } from '../avm_memory_types.js' ;
2
+ import {
3
+ type Field ,
4
+ type MemoryValue ,
5
+ TaggedMemory ,
6
+ type TaggedMemoryInterface ,
7
+ TypeTag ,
8
+ } from '../avm_memory_types.js' ;
3
9
import { ArithmeticError } from '../errors.js' ;
4
10
import { Opcode } from '../serialization/instruction_serialization.js' ;
5
11
import { Addressing } from './addressing_mode.js' ;
@@ -13,7 +19,7 @@ export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInst
13
19
const operands = [ this . aOffset , this . bOffset , this . dstOffset ] ;
14
20
const addressing = Addressing . fromWire ( this . indirect , operands . length ) ;
15
21
const [ aOffset , bOffset , dstOffset ] = addressing . resolve ( operands , memory ) ;
16
- memory . checkTagsAreSame ( aOffset , bOffset ) ;
22
+ this . checkTags ( memory , aOffset , bOffset ) ;
17
23
18
24
const a = memory . get ( aOffset ) ;
19
25
const b = memory . get ( bOffset ) ;
@@ -25,6 +31,9 @@ export abstract class ThreeOperandArithmeticInstruction extends ThreeOperandInst
25
31
}
26
32
27
33
protected abstract compute ( a : MemoryValue , b : MemoryValue ) : MemoryValue ;
34
+ protected checkTags ( memory : TaggedMemoryInterface , aOffset : number , bOffset : number ) {
35
+ memory . checkTagsAreSame ( aOffset , bOffset ) ;
36
+ }
28
37
}
29
38
30
39
export class Add extends ThreeOperandArithmeticInstruction {
@@ -65,6 +74,11 @@ export class Div extends ThreeOperandArithmeticInstruction {
65
74
66
75
return a . div ( b ) ;
67
76
}
77
+
78
+ protected override checkTags ( memory : TaggedMemoryInterface , aOffset : number , bOffset : number ) {
79
+ memory . checkTagsAreSame ( aOffset , bOffset ) ;
80
+ TaggedMemory . checkIsIntegralTag ( memory . getTag ( aOffset ) ) ; // Follows that bOffset tag is also of integral type
81
+ }
68
82
}
69
83
70
84
export class FieldDiv extends ThreeOperandArithmeticInstruction {
@@ -75,4 +89,9 @@ export class FieldDiv extends ThreeOperandArithmeticInstruction {
75
89
// return (a as Field).fdiv(b as Field);
76
90
return a . fdiv ( b ) ;
77
91
}
92
+
93
+ protected override checkTags ( memory : TaggedMemoryInterface , aOffset : number , bOffset : number ) {
94
+ memory . checkTagsAreSame ( aOffset , bOffset ) ;
95
+ memory . checkTag ( TypeTag . FIELD , aOffset ) ; // Follows that bOffset has also tag of type Field
96
+ }
78
97
}
0 commit comments