@@ -40,55 +40,55 @@ pub enum OpCode {
4040 LessEqual ( usize , usize , usize ) ,
4141 NotEqual ( usize , usize , usize ) ,
4242 Call ( usize , usize , usize ) ,
43- NewArray ( usize , usize ) , // dest, length-reg
44- GetIndex ( usize , usize , usize ) , // dest, array-reg, index-reg
45- SetIndex ( usize , usize , usize ) , // array-reg, index-reg, value-reg
43+ NewArray ( usize , usize ) , // dest, length-reg
44+ GetIndex ( usize , usize , usize ) , // dest, array-reg, index-reg
45+ SetIndex ( usize , usize , usize ) , // array-reg, index-reg, value-reg
4646 IncLoopIfLess ( usize , usize , usize ) , // idx_reg, limit_reg, target_pc
4747}
4848
4949impl OpCode {
5050 /// A compact numeric tag for each variant (useful for a real byte-buffer backend)
5151 pub fn tag ( & self ) -> u8 {
5252 match self {
53- OpCode :: LoadConstant ( _, _) => 0x01 ,
54- OpCode :: DefineGlobal ( _, _) => 0x02 ,
55- OpCode :: GetGlobal ( _, _) => 0x03 ,
56- OpCode :: SetGlobal ( _, _) => 0x04 ,
57- OpCode :: GetLocal ( _, _) => 0x05 ,
58- OpCode :: SetLocal ( _, _) => 0x06 ,
59- OpCode :: JumpIfFalse ( _, _) => 0x07 ,
60- OpCode :: Jump ( _) => 0x08 ,
61- OpCode :: Loop ( _) => 0x09 ,
62- OpCode :: Move ( _, _) => 0x0A ,
63- OpCode :: True ( _) => 0x0B ,
64- OpCode :: False ( _) => 0x0C ,
65- OpCode :: Pop ( _) => 0x0D ,
66- OpCode :: None ( _) => 0x0E ,
67- OpCode :: Add ( _, _, _) => 0x0F ,
68- OpCode :: Subtract ( _, _, _) => 0x10 ,
69- OpCode :: Multiply ( _, _, _) => 0x11 ,
70- OpCode :: Divide ( _, _, _) => 0x12 ,
71- OpCode :: Exponentiate ( _, _, _) => 0x13 ,
72- OpCode :: IntDivide ( _, _, _) => 0x14 ,
73- OpCode :: Return ( _) => 0x15 ,
74- OpCode :: BitwiseNot ( _, _) => 0x16 ,
75- OpCode :: Negate ( _, _) => 0x17 ,
76- OpCode :: Print ( _) => 0x18 ,
77- OpCode :: Equal ( _, _, _) => 0x19 ,
78- OpCode :: Greater ( _, _, _) => 0x1A ,
79- OpCode :: Less ( _, _, _) => 0x1B ,
80- OpCode :: BitwiseAnd ( _, _, _) => 0x1C ,
81- OpCode :: BitwiseOr ( _, _, _) => 0x1D ,
82- OpCode :: BitwiseXor ( _, _, _) => 0x1E ,
83- OpCode :: GreaterEqual ( _, _, _) => 0x1F ,
84- OpCode :: LessEqual ( _, _, _) => 0x20 ,
85- OpCode :: NotEqual ( _, _, _) => 0x21 ,
86- OpCode :: Call ( _, _, _) => 0x22 ,
87- OpCode :: Mod ( _, _, _) => 0x23 ,
88- OpCode :: NewArray ( _, _) => 0x24 ,
89- OpCode :: GetIndex ( _, _, _) => 0x25 ,
90- OpCode :: SetIndex ( _, _, _) => 0x26 ,
91- OpCode :: IncLoopIfLess ( _, _ , _) => 0x27 ,
53+ OpCode :: LoadConstant ( _, _) => 0x01 ,
54+ OpCode :: DefineGlobal ( _, _) => 0x02 ,
55+ OpCode :: GetGlobal ( _, _) => 0x03 ,
56+ OpCode :: SetGlobal ( _, _) => 0x04 ,
57+ OpCode :: GetLocal ( _, _) => 0x05 ,
58+ OpCode :: SetLocal ( _, _) => 0x06 ,
59+ OpCode :: JumpIfFalse ( _, _) => 0x07 ,
60+ OpCode :: Jump ( _) => 0x08 ,
61+ OpCode :: Loop ( _) => 0x09 ,
62+ OpCode :: Move ( _, _) => 0x0A ,
63+ OpCode :: True ( _) => 0x0B ,
64+ OpCode :: False ( _) => 0x0C ,
65+ OpCode :: Pop ( _) => 0x0D ,
66+ OpCode :: None ( _) => 0x0E ,
67+ OpCode :: Add ( _, _, _) => 0x0F ,
68+ OpCode :: Subtract ( _, _, _) => 0x10 ,
69+ OpCode :: Multiply ( _, _, _) => 0x11 ,
70+ OpCode :: Divide ( _, _, _) => 0x12 ,
71+ OpCode :: Exponentiate ( _, _, _) => 0x13 ,
72+ OpCode :: IntDivide ( _, _, _) => 0x14 ,
73+ OpCode :: Return ( _) => 0x15 ,
74+ OpCode :: BitwiseNot ( _, _) => 0x16 ,
75+ OpCode :: Negate ( _, _) => 0x17 ,
76+ OpCode :: Print ( _) => 0x18 ,
77+ OpCode :: Equal ( _, _, _) => 0x19 ,
78+ OpCode :: Greater ( _, _, _) => 0x1A ,
79+ OpCode :: Less ( _, _, _) => 0x1B ,
80+ OpCode :: BitwiseAnd ( _, _, _) => 0x1C ,
81+ OpCode :: BitwiseOr ( _, _, _) => 0x1D ,
82+ OpCode :: BitwiseXor ( _, _, _) => 0x1E ,
83+ OpCode :: GreaterEqual ( _, _, _) => 0x1F ,
84+ OpCode :: LessEqual ( _, _, _) => 0x20 ,
85+ OpCode :: NotEqual ( _, _, _) => 0x21 ,
86+ OpCode :: Call ( _, _, _) => 0x22 ,
87+ OpCode :: Mod ( _, _, _) => 0x23 ,
88+ OpCode :: NewArray ( _, _) => 0x24 ,
89+ OpCode :: GetIndex ( _, _, _) => 0x25 ,
90+ OpCode :: SetIndex ( _, _, _) => 0x26 ,
91+ OpCode :: IncLoopIfLess ( _, _ , _) => 0x27 ,
9292 }
9393 }
9494 ///Convert to bytes (For Debugging)
@@ -119,8 +119,7 @@ impl OpCode {
119119 buf. extend ( & ( * r as u32 ) . to_le_bytes ( ) ) ;
120120 buf. extend ( & ( * idx as u32 ) . to_le_bytes ( ) ) ;
121121 }
122- OpCode :: Jump ( idx)
123- | OpCode :: Loop ( idx) => {
122+ OpCode :: Jump ( idx) | OpCode :: Loop ( idx) => {
124123 buf. extend ( & ( * idx as u32 ) . to_le_bytes ( ) ) ;
125124 }
126125 OpCode :: True ( r)
@@ -131,27 +130,27 @@ impl OpCode {
131130 | OpCode :: Print ( r) => {
132131 buf. extend ( & ( * r as u32 ) . to_le_bytes ( ) ) ;
133132 }
134- OpCode :: Add ( d, a , b)
135- | OpCode :: Subtract ( d, a , b)
136- | OpCode :: Multiply ( d, a , b)
137- | OpCode :: Divide ( d, a , b)
138- | OpCode :: Exponentiate ( d, a , b)
139- | OpCode :: IntDivide ( d, a , b)
140- | OpCode :: Mod ( d, a , b)
141- | OpCode :: Equal ( d, a , b)
142- | OpCode :: Greater ( d, a , b)
143- | OpCode :: Less ( d, a , b)
144- | OpCode :: BitwiseAnd ( d, a , b)
145- | OpCode :: BitwiseOr ( d, a , b)
146- | OpCode :: BitwiseXor ( d, a , b)
147- | OpCode :: GreaterEqual ( d, a , b)
148- | OpCode :: LessEqual ( d, a , b)
149- | OpCode :: NotEqual ( d, a , b) => {
133+ OpCode :: Add ( d, a , b)
134+ | OpCode :: Subtract ( d, a , b)
135+ | OpCode :: Multiply ( d, a , b)
136+ | OpCode :: Divide ( d, a , b)
137+ | OpCode :: Exponentiate ( d, a , b)
138+ | OpCode :: IntDivide ( d, a , b)
139+ | OpCode :: Mod ( d, a , b)
140+ | OpCode :: Equal ( d, a , b)
141+ | OpCode :: Greater ( d, a , b)
142+ | OpCode :: Less ( d, a , b)
143+ | OpCode :: BitwiseAnd ( d, a , b)
144+ | OpCode :: BitwiseOr ( d, a , b)
145+ | OpCode :: BitwiseXor ( d, a , b)
146+ | OpCode :: GreaterEqual ( d, a , b)
147+ | OpCode :: LessEqual ( d, a , b)
148+ | OpCode :: NotEqual ( d, a , b) => {
150149 buf. extend ( & ( * d as u32 ) . to_le_bytes ( ) ) ;
151150 buf. extend ( & ( * a as u32 ) . to_le_bytes ( ) ) ;
152151 buf. extend ( & ( * b as u32 ) . to_le_bytes ( ) ) ;
153152 }
154- OpCode :: Call ( d, c , a) => {
153+ OpCode :: Call ( d, c , a) => {
155154 buf. extend ( & ( * d as u32 ) . to_le_bytes ( ) ) ;
156155 buf. extend ( & ( * c as u32 ) . to_le_bytes ( ) ) ;
157156 buf. extend ( & ( * a as u32 ) . to_le_bytes ( ) ) ;
@@ -160,8 +159,7 @@ impl OpCode {
160159 buf. extend ( & ( * dest as u32 ) . to_le_bytes ( ) ) ;
161160 buf. extend ( & ( * len as u32 ) . to_le_bytes ( ) ) ;
162161 }
163- OpCode :: GetIndex ( d, arr, idx)
164- | OpCode :: SetIndex ( d, arr, idx) => {
162+ OpCode :: GetIndex ( d, arr, idx) | OpCode :: SetIndex ( d, arr, idx) => {
165163 buf. extend ( & ( * d as u32 ) . to_le_bytes ( ) ) ;
166164 buf. extend ( & ( * arr as u32 ) . to_le_bytes ( ) ) ;
167165 buf. extend ( & ( * idx as u32 ) . to_le_bytes ( ) ) ;
@@ -185,12 +183,11 @@ impl OpCode {
185183 | True ( d)
186184 | False ( d)
187185 | Pop ( d)
188- | None ( d) => vec ! [ * d] ,
186+ | None ( d) => vec ! [ * d] ,
189187
190- GetLocal ( d, _)
191- | SetLocal ( d, _) => vec ! [ * d] ,
188+ GetLocal ( d, _) | SetLocal ( d, _) => vec ! [ * d] ,
192189
193- SetGlobal ( r, _ ) => vec ! [ * r] ,
190+ SetGlobal ( r, _ ) => vec ! [ * r] ,
194191
195192 Add ( d, a, b)
196193 | Subtract ( d, a, b)
@@ -207,17 +204,17 @@ impl OpCode {
207204 | Greater ( d, a, b)
208205 | GreaterEqual ( d, a, b)
209206 | Less ( d, a, b)
210- | LessEqual ( d, a, b) => vec ! [ * d, * a, * b] ,
207+ | LessEqual ( d, a, b) => vec ! [ * d, * a, * b] ,
211208
212- Move ( d, s) => vec ! [ * d, * s] ,
213- Call ( d, c, _) => vec ! [ * d, * c] ,
214- NewArray ( d, l) => vec ! [ * d, * l] ,
215- GetIndex ( d, a, i) => vec ! [ * d, * a, * i] ,
216- SetIndex ( a, i, v) => vec ! [ * a, * i, * v] ,
209+ Move ( d, s) => vec ! [ * d, * s] ,
210+ Call ( d, c, _) => vec ! [ * d, * c] ,
211+ NewArray ( d, l) => vec ! [ * d, * l] ,
212+ GetIndex ( d, a, i) => vec ! [ * d, * a, * i] ,
213+ SetIndex ( a, i, v) => vec ! [ * a, * i, * v] ,
217214
218- JumpIfFalse ( r, _) => vec ! [ * r] ,
219- Loop ( _) | Jump ( _) => vec ! [ ] ,
220- _ => vec ! [ ] ,
215+ JumpIfFalse ( r, _) => vec ! [ * r] ,
216+ Loop ( _) | Jump ( _) => vec ! [ ] ,
217+ _ => vec ! [ ] ,
221218 }
222219 }
223220}
0 commit comments