about summary refs log tree commit diff stats
path: root/shell/data.limg
Commit message (Expand)AuthorAgeFilesLines
* shell: roll back a change to the 'when' macroKartik K. Agaram2021-05-151-2/+2
* A 'bowboard', a chessboard of rainbow circlesKartik K. Agaram2021-05-081-23/+31
* a full-circle rainbowKartik K. Agaram2021-05-081-2/+29
* new shell macro: doKartik K. Agaram2021-05-071-2/+3
* .Kartik K. Agaram2021-05-071-3/+5
* .Kartik K. Agaram2021-05-071-19/+19
* clean up all definitionsKartik K. Agaram2021-05-071-21/+20
* clean up chessboardKartik K. Agaram2021-05-071-10/+12
* clean up read_lineKartik K. Agaram2021-05-071-9/+6
* clean up Bresenham line-drawingKartik K. Agaram2021-05-071-26/+22
* no, we need hline1 for fill_rectKartik K. Agaram2021-05-071-8/+10
* clean up hline and vlineKartik K. Agaram2021-05-071-10/+10
* starting to implement first macrosKartik K. Agaram2021-05-071-0/+4
* belatedly migrate stale example definitionsKartik K. Agaram2021-05-061-91/+91
* bresenham circlesKartik K. Agaram2021-04-251-1/+22
* bug in bresenham linesKartik K. Agaram2021-04-251-2/+2
* shell: primitives 'and' and 'or'Kartik K. Agaram2021-04-251-11/+1
* .Kartik K. Agaram2021-04-251-0/+84
n> ^
f1e953d0 ^
ec926027 ^




363be37f ^
ac0e9db5 ^
ca01193d ^
363be37f ^
50eab110 ^



ec926027 ^
31401373 ^
ec926027 ^



ca01193d ^
363be37f ^
69e14325 ^
5eb49929 ^
e2240eb4 ^

363be37f ^
31401373 ^
d72f3799 ^
0b0cfb6f ^
7284d503 ^


ac0e9db5 ^

31401373 ^

ec926027 ^
7c8493b3 ^

31401373 ^

ec926027 ^
dcfca05e ^

31401373 ^

dcfca05e ^
f89378d5 ^
f1a6f323 ^
9cf71627 ^
2199940a ^
dcfca05e ^
768bdb4d ^
9cf71627 ^

012d2ee1 ^

7feea75b ^

a767dbd3 ^
9cf71627 ^

7284d503 ^
64cf0a59 ^
69e14325 ^


df8bb4c3 ^
f6d47435 ^
5eb49929 ^
31401373 ^

5eb49929 ^

f1e953d0 ^
ec926027 ^

ac0e9db5 ^
7feea75b ^
87fbfc2d ^
31401373 ^
b75e94b3 ^
ec926027 ^
8eff7919 ^
f6d47435 ^
f278a15d ^



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
119
120

                                                                      
                          



             
                                      
 
                             
 
                                 

             


                            

          

                            
 







                                
 




                                                                             
                                
                                   
                    
                          



                           
  
                              



                             
                       
                            
                         
                                           

       
                                    
                            
                            
 


                                 

                                                         

                                                           
 

                                                         

                                                                    
 

                                                              

                                                                                                                           
 
 
                                                                        
          
                                                        
                                                                     
                                                                                                                            

          

                                                                           

                                                           
                                                                          

 
                                                                        
 


                                                     
 
 
                                                          

                                                    

 
                                   

                                                                           
                                                                
                    
                                                                      
                                     
                                             
                                      
                         
 



                        
//: So far the recipes we define can't run each other. Let's fix that.

:(scenario calling_recipe)
recipe main [
  f
]
recipe f [
  3:number <- add 2:literal, 2:literal
]
+mem: storing 4 in location 3

:(scenario return_on_fallthrough)
recipe main [
  f
  1:number <- copy 0:literal
  2:number <- copy 0:literal
  3:number <- copy 0:literal
]
recipe f [
  4:number <- copy 0:literal
  5:number <- copy 0:literal
]
+run: f
# running f
+run: 4:number <- copy 0:literal
+run: 5:number <- copy 0:literal
# back out to main
+run: 1:number <- copy 0:literal
+run: 2:number <- copy 0:literal
+run: 3:number <- copy 0:literal

:(before "struct routine {")
// Everytime a recipe runs another, we interrupt it and start running the new
// recipe. When that finishes, we continue this one where we left off.
// This requires maintaining a 'stack' of interrupted recipes or 'calls'.
struct call {
  recipe_ordinal running_recipe;
  long long int running_step_index;
  // End call Fields
  call(recipe_ordinal r) {
    running_recipe = r;
    running_step_index = 0;
    // End call Constructor
  }
};
typedef list<call> call_stack;

:(replace{} "struct routine")
struct routine {
  call_stack calls;
  // End routine Fields
  routine(recipe_ordinal r);
  bool completed() const;
  const vector<instruction>& steps() const;
};
:(code)
routine::routine(recipe_ordinal r) {
  calls.push_front(call(r));
  // End routine Constructor
}

//:: now update routine's helpers

:(replace{} "inline long long int& current_step_index()")
inline long long int& current_step_index() {
  assert(!Current_routine->calls.empty());
  return Current_routine->calls.front().running_step_index;
}
:(replace{} "inline const string& current_recipe_name()")
inline const string& current_recipe_name() {
  assert(!Current_routine->calls.empty());
  return Recipe[Current_routine->calls.front().running_recipe].name;
}
:(replace{} "inline const instruction& current_instruction()")
inline const instruction& current_instruction() {
  assert(!Current_routine->calls.empty());
  return Recipe[Current_routine->calls.front().running_recipe].steps.at(Current_routine->calls.front().running_step_index);
}

:(replace{} "default:" following "End Primitive Recipe Implementations")
default: {
  // not a primitive; try to look up the book of recipes
  if (Recipe.find(current_instruction().operation) == Recipe.end()) {
    raise << "undefined operation " << current_instruction().operation << ": " << current_instruction().to_string() << '\n';
    break;
  }
  Current_routine->calls.push_front(call(current_instruction().operation));
complete_call:
  ++Callstack_depth;
  assert(Callstack_depth < 9000);  // 9998-101 plus cushion
  continue;  // not done with caller; don't increment current_step_index()
}

//:: finally, we need to fix the termination conditions for the run loop

:(replace{} "inline bool routine::completed() const")
inline bool routine::completed() const {
  return calls.empty();
}

inline const vector<instruction>& routine::steps() const {
  assert(!calls.empty());
  return Recipe[calls.front().running_recipe].steps;
}

:(before "Running One Instruction")
// when we reach the end of one call, we may reach the end of the one below
// it, and the one below that, and so on
while (current_step_index() >= SIZE(Current_routine->steps())) {
  --Callstack_depth;
//?   cerr << "reply " << Current_routine->calls.size() << '\n'; //? 1
  Current_routine->calls.pop_front();
  if (Current_routine->calls.empty()) return;
  // todo: no results returned warning
  ++current_step_index();
}

:(before "End Includes")
#include <stack>
using std::stack;