File tree 3 files changed +17
-2
lines changed
3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ Myst bytecode is a binary stream of instructions for the Myst Virtual Machine to
12
12
| | setlocal | 0x02 | name | value | |
13
13
| stack | push | 0x10 | value | | value |
14
14
| | pop | 0x11 | | value | |
15
+ | | dup | 0x12 | | val | val,val |
16
+ | | dupn | 0x13 | n | * n | * n,* n |
15
17
| math | add | 0x20 | | b,a | a+b |
16
18
| | subtract | 0x21 | | b,a | a-b |
17
19
| | multiply | 0x22 | | b,a | a* b |
Original file line number Diff line number Diff line change @@ -3,10 +3,20 @@ require "./myst/vm"
3
3
include Myst ::VM
4
4
5
5
iseq = InstructionSequence .new
6
- iseq.add_instruction(Instruction ::Push .new(MTValue .new(" Hello," )))
7
- iseq.add_instruction(Instruction ::Push .new(MTValue .new(" world!" )))
6
+ iseq.add_instruction(Instruction ::Push .new(MTValue .new(1 _i64 )))
7
+ iseq.add_instruction(Instruction ::SetLocal .new(MTValue .new(" n_2" )))
8
+ iseq.add_instruction(Instruction ::Push .new(MTValue .new(1 _i64 )))
9
+ iseq.add_instruction(Instruction ::SetLocal .new(MTValue .new(" n_1" )))
10
+ iseq.add_instruction(Instruction ::Label .new(MTValue .new(" loop" )))
11
+ iseq.add_instruction(Instruction ::GetLocal .new(MTValue .new(" n_1" )))
12
+ iseq.add_instruction(Instruction ::GetLocal .new(MTValue .new(" n_2" )))
8
13
iseq.add_instruction(Instruction ::Add .new)
14
+ iseq.add_instruction(Instruction ::Dup .new)
9
15
iseq.add_instruction(Instruction ::Write .new)
16
+ iseq.add_instruction(Instruction ::GetLocal .new(MTValue .new(" n_1" )))
17
+ iseq.add_instruction(Instruction ::SetLocal .new(MTValue .new(" n_2" )))
18
+ iseq.add_instruction(Instruction ::SetLocal .new(MTValue .new(" n_1" )))
19
+ iseq.add_instruction(Instruction ::Jump .new(MTValue .new(" loop" )))
10
20
11
21
File .open(" ./generated_bytecode.mtc" , " w" ) do |io |
12
22
iseq.to_bytecode(io)
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ module Myst
15
15
def_instruction Push , 0x10 ,
16
16
value : MTValue
17
17
def_instruction Pop , 0x11
18
+ def_instruction Dup , 0x12
19
+ def_instruction DupN , 0x13 ,
20
+ size : MTValue
18
21
19
22
# Math
20
23
def_instruction Add , 0x20
You can’t perform that action at this time.
0 commit comments