summary refs log tree commit diff stats
path: root/lib/system/comparisons.nim
Commit message (Expand)AuthorAgeFilesLines
* implement RFCs/294 ; disallow enum <=> enum conversion (#16351)Timothee Cour2021-04-031-1/+1
* Added assertion to clamp (#17248)Jason Beetham2021-03-041-2/+5
* Replace double backticks with single backticks - Part 1 out of ~6 (#17205)Danil Yarantsev2021-02-281-11/+11
* remove all uses of condsyms symbols defined prior to bootstrap nim 0.20.0 (#1...Timothee Cour2021-02-171-10/+2
* cleanup docs and tests (#16235)flywind2020-12-031-1/+1
* Fix typo and improve grammar for clamps noteClyybber2020-12-021-1/+1
* small style changes and clarify clamp (#16228)flywind2020-12-021-6/+8
* [docs minor] better comparisons docs (#16201)flywind2020-12-021-90/+89
* fix operators containing percent for VM usage (#13536)Arne Döring2020-03-111-20/+25
* style fix: change 'JS' to 'js' to make it consistent (#13168)Miran2020-01-161-1/+1
* System cleanup, part 2 (#13155)Miran2020-01-151-0/+311
-19 18:25:25 -0800 796 - jump instructions done' href='/akkartik/mu/commit/cpp/015jump?h=main&id=201b2e6c7ce94c986fe7888a60f0e1ba24a05ce9'>201b2e6c ^
f7051fad ^
201b2e6c ^




















6f5d7864 ^
201b2e6c ^

6f5d7864 ^
201b2e6c ^






6f5d7864 ^
201b2e6c ^
6f5d7864 ^
201b2e6c ^





f7051fad ^
201b2e6c ^




















6f5d7864 ^
201b2e6c ^

6f5d7864 ^
201b2e6c ^






6f5d7864 ^
201b2e6c ^

6f5d7864 ^
201b2e6c ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118




                                        
                                   












                                                                             
                        
                       
                        



                           



                              


                        




                                        
                                      




















                                                                             
                        

                              
                        






                                 
                        
                          
                        





                                           
                                          




















                                                                             
                        

                              
                        






                                     
                        

                              
                        
                             
:(before "End Globals")
// Jump ops.
const int JUMP = 10;
:(before "End Primitive Recipe Numbers")
Recipe_number["jump"] = JUMP;
assert(Next_recipe_number == JUMP);
Next_recipe_number++;
:(before "End Primitive Recipe Implementations")
case JUMP: {
  trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name;
  pc += to_int(instructions[pc].ingredients[0].name);
  break;
}

:(scenario "jump_can_skip_instructions")
recipe main [
  jump 1:offset
  1:integer <- copy 1:literal
]
+run: instruction main/0
+run: ingredient 0 is 1
-run: instruction main/1
-mem: storing in location 1

:(scenario "jump_backward")
recipe main [
  jump 1:offset  // 0 -+
  jump 1:offset  //    | 1 +-+
  jump -2:offset //  2 +-->+ |
]                //       3 \/
+run: instruction main/0
+run: instruction main/2
+run: instruction main/1

:(before "End Globals")
const int JUMP_IF = 11;
:(before "End Primitive Recipe Numbers")
Recipe_number["jump-if"] = JUMP_IF;
assert(Next_recipe_number == JUMP_IF);
Next_recipe_number++;
:(before "End Primitive Recipe Implementations")
case JUMP_IF: {
  vector<int> arg0 = read_memory(instructions[pc].ingredients[0]);
  assert(arg0.size() == 1);
  trace("run") << "ingredient 0 is " << arg0[0];
  if (!arg0[0]) {
    trace("run") << "jump-if fell through";
    break;
  }
  trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
  pc += to_int(instructions[pc].ingredients[1].name);
  trace("run") << "jumping to instruction " << pc+1;
  break;
}

:(scenario "jump_if")
recipe main [
  jump-if 999:literal 1:offset
  1:integer <- copy 1:literal
]
+run: instruction main/0
+run: ingredient 1 is 1
+run: jumping to instruction 2
-run: instruction main/1
-mem: storing in location 1

:(scenario "jump_if_fallthrough")
recipe main [
  jump-if 0:literal 1:offset
  123:integer <- copy 1:literal
]
+run: instruction main/0
+run: jump-if fell through
+run: instruction main/1
+mem: storing in location 123

:(before "End Globals")
const int JUMP_UNLESS = 12;
:(before "End Primitive Recipe Numbers")
Recipe_number["jump-unless"] = JUMP_UNLESS;
assert(Next_recipe_number == JUMP_UNLESS);
Next_recipe_number++;
:(before "End Primitive Recipe Implementations")
case JUMP_UNLESS: {
  vector<int> arg0 = read_memory(instructions[pc].ingredients[0]);
  assert(arg0.size() == 1);
  trace("run") << "ingredient 0 is " << arg0[0];
  if (arg0[0]) {
    trace("run") << "jump-unless fell through";
    break;
  }
  trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name;
  pc += to_int(instructions[pc].ingredients[1].name);
  trace("run") << "jumping to instruction " << pc+1;
  break;
}

:(scenario "jump_unless")
recipe main [
  jump-unless 0:literal 1:offset
  1:integer <- copy 1:literal
]
+run: instruction main/0
+run: ingredient 1 is 1
+run: jumping to instruction 2
-run: instruction main/1
-mem: storing in location 1

:(scenario "jump_unless_fallthrough")
recipe main [
  jump-unless 999:literal 1:offset
  123:integer <- copy 1:literal
]
+run: instruction main/0
+run: ingredient 0 is 999
+run: jump-unless fell through
+run: instruction main/1
+mem: storing in location 123