Skip to content
This repository
Browse code

removing the last bits of the Range class that have integer instead o…

…f True and False. Also contains a bunch of my debugging code.
  • Loading branch information...
commit 5a9784f86a6191b975321ff5bbbffc7caa3bd9ac 1 parent 67d02cf
Bob Kuo authored

Showing 1 changed file with 56 additions and 56 deletions. Show diff stats Hide diff stats

  1. 112  src/classes/Range.pir
112  src/classes/Range.pir
@@ -74,10 +74,10 @@ Determines if topic is within the range or equal to the range.
74 74
     goto true
75 75
 
76 76
   value_in_range_check:
77  
-    $I0 = self.'!from_test'(topic)
78  
-    unless $I0 goto false
79  
-    $I0 = self.'!to_test'(topic)
80  
-    unless $I0 goto false
  77
+    $P3 = self.'!from_test'(topic)
  78
+    unless $P3, false
  79
+    $P3 = self.'!to_test'(topic)
  80
+    unless $P3, false
81 81
 
82 82
   true:
83 83
     $P0 = get_hll_global 'true'
@@ -129,6 +129,7 @@ Gets the beginning or end of the range.
129 129
 =cut
130 130
 
131 131
 .sub 'to_a' :method
  132
+    print "to_a\n"
132 133
     $P0 = self.'list'()
133 134
     .return ($P0)
134 135
 .end
@@ -137,7 +138,7 @@ Gets the beginning or end of the range.
137 138
    $P0 = getattribute self, '$!from_exclusive'
138 139
    $P1 = getattribute self, '$!to_exclusive'
139 140
    $P2 = $P0 && $P1
140  
-   if $P2 > 0 goto build_exclusive
  141
+   if $P2, build_exclusive
141 142
    $S0 = '..'
142 143
    goto build_return
143 144
    build_exclusive:
@@ -161,6 +162,7 @@ iterators, we can just return a clone.
161 162
 =cut
162 163
 
163 164
 .sub 'iterator' :method :vtable('get_iter')
  165
+    print "iterator\n"
164 166
     $P0 = clone self
165 167
     .return ($P0)
166 168
 .end
@@ -176,14 +178,21 @@ just return a clone of the CardinalRange.
176 178
 
177 179
 .sub 'list' :method
178 180
     .local pmc range_it, result
  181
+    say "list"
179 182
     range_it = self.'iterator'()
  183
+    say "after iterator"
180 184
     result = new 'CardinalArray'
181 185
   range_loop:
  186
+    say "start loop"
182 187
     unless range_it goto range_end
  188
+    say "true here"
183 189
     $P0 = shift range_it
  190
+    say "P0"
  191
+    say $P0
184 192
     push result, $P0
185 193
     goto range_loop
186 194
   range_end:
  195
+    say "end loop"
187 196
     .return (result)
188 197
 .end
189 198
 
@@ -265,18 +274,14 @@ Return true if the parameter is located with this CardinalRange
265 274
   $P0 = self.'from'()
266 275
   $P1 = self.'to'()
267 276
 
268  
-  $I0 = self.'!from_test'(test)
269  
-  if $I0 == 0 goto out_of_bounds
270  
-  $I0 = self.'!to_test'(test)
271  
-  if $I0 == 0 goto out_of_bounds
272  
-  #if test <= $P0 goto out_of_bounds
273  
-  #if test >= $P1 goto out_of_bounds
  277
+  $P2 = self.'!from_test'(test)
  278
+  unless $P2, out_of_bounds
  279
+  $P2 = self.'!to_test'(test)
  280
+  unless $P2, out_of_bounds
274 281
   $P3 = get_hll_global 'true'
275 282
   .return ($P3)
276 283
   out_of_bounds:
277 284
       $P3 = get_hll_global 'false'
278  
-      #say 'out of bounds'
279  
-      #throw 'out of bounds!'
280 285
       .return ($P3)
281 286
 .end
282 287
 
@@ -307,8 +312,8 @@ Generate the next element at the end of the CardinalRange.
307 312
     unless toexc goto have_value
308 313
     value = clone to
309 314
   have_value:
310  
-    $I0 = self.'!from_test'(value)
311  
-    if $I0 goto success
  315
+    $P0 = self.'!from_test'(value)
  316
+    if $P0, success
312 317
     #value = '!FAIL'('Undefined value popped from empty range')
313 318
     value = new 'Undef'
314 319
   success:
@@ -324,15 +329,16 @@ Generate the next element at the front of the CardinalRange.
324 329
 
325 330
 .sub 'shift' :method :vtable('shift_pmc')
326 331
     .local pmc from, fromexc, value
  332
+    print "shift\n"
327 333
     from = getattribute self, '$!from'
328 334
     fromexc = getattribute self, '$!from_exclusive'
329 335
     value = clone from
330 336
     inc from
331  
-    unless fromexc > 0 goto have_value
  337
+    unless fromexc, have_value
332 338
     value = clone from
333 339
   have_value:
334  
-    $I0 = self.'!to_test'(value)
335  
-    if $I0 goto success
  340
+    $P0 = self.'!to_test'(value)
  341
+    if $P0, success
336 342
     #value = '!FAIL'('Undefined value shifted from empty range')
337 343
     value = new 'Undef'
338 344
   success:
@@ -347,46 +353,39 @@ Return true if there are any more values to iterate over.
347 353
 =cut
348 354
 
349 355
 .sub 'true' :method :vtable('get_bool')
350  
-    .local pmc from, fromexc
351  
-    from = getattribute self, '$!from'
352  
-    fromexc = getattribute self, '$!from_exclusive'
353  
-    unless fromexc > 0 goto have_value
354  
-    from = clone from
355  
-    inc from
356  
-  have_value:
357  
-    $I0 = self.'!to_test'(from)
358  
-    .return ($I0)
  356
+    say "true method"
  357
+    $P0 = getattribute self, '$!from'
  358
+    $P1 = self.'!to_test'($P0)
  359
+    say "P1"
  360
+    say $P1
  361
+    .return ($P1)
359 362
 .end
360 363
 
361 364
 
362 365
 .sub 'initialize' :method :multi(_)
363 366
     .param pmc hash :named :slurpy
364  
-    $P1 = hash["$!from_exclusive"]
365  
-    defined $I0, $P1
366  
-    $I0 = !$I0
367  
-    if $I0 goto default
368  
-    setattribute self, '$!from_exclusive', $P1
369  
-    $P2 = hash["$!to_exclusive"]
370  
-    setattribute self, '$!to_exclusive', $P2
  367
+    $P0 = get_hll_global 'false'
  368
+    $P1 = get_hll_global 'true'
  369
+    $P2 = hash["$!from_exclusive"]
  370
+    unless $P2, default
  371
+    setattribute self, '$!from_exclusive', $P0
  372
+    setattribute self, '$!to_exclusive', $P1
371 373
     goto finish
372  
-    default:
373  
-        $P0 = new 'CardinalInteger'
374  
-        $P0 = 0
375  
-        setattribute self, '$!from_exclusive', $P0
376  
-        setattribute self, '$!to_exclusive', $P0
377  
-        goto finish
378  
-    finish:
379  
-        $P3 = hash["$!from"]
380  
-        setattribute self, '$!from', $P3
381  
-        $P4 = hash["$!to"]
382  
-        setattribute self, '$!to', $P4
  374
+  default:
  375
+    setattribute self, '$!from_exclusive', $P0
  376
+    setattribute self, '$!to_exclusive', $P0
  377
+    goto finish
  378
+  finish:
  379
+    $P3 = hash["$!from"]
  380
+    setattribute self, '$!from', $P3
  381
+    $P4 = hash["$!to"]
  382
+    setattribute self, '$!to', $P4
383 383
 .end
384 384
 
385 385
 .sub 'initialize' :method :multi(_,_,_)
386 386
     .param pmc from
387 387
     .param pmc to
388  
-    $P0 = new 'CardinalInteger'
389  
-    $P0 = 0
  388
+    $P0 = get_hll_global 'false'
390 389
     setattribute self, '$!from_exclusive', $P0
391 390
     setattribute self, '$!to_exclusive', $P0
392 391
     setattribute self, '$!from', from
@@ -442,9 +441,10 @@ Construct a range from the endpoints.
442 441
 .sub 'infix:..'
443 442
     .param pmc from
444 443
     .param pmc to
445  
-    .local pmc proto
  444
+    .local pmc proto, false
446 445
     proto = get_hll_global 'CardinalRange'
447  
-    $P1 = proto.'new'('$!from'=>from, '$!to'=>to)
  446
+    false = get_hll_global 'false'
  447
+    $P1 = proto.'new'('$!from'=>from, '$!to'=>to, '$!from_exclusive'=>false, '$!to_exclusive'=>false)
448 448
     .return ($P1)
449 449
 .end
450 450
 
@@ -480,12 +480,12 @@ honoring exclusive flags.
480 480
     .local pmc from, fromexc
481 481
     from = getattribute self, '$!from'
482 482
     fromexc = getattribute self, '$!from_exclusive'
483  
-    if fromexc > 0 goto exclusive_test
  483
+    if fromexc, exclusive_test
484 484
     $I0 = isge topic, from
485  
-    .return ($I0)
  485
+    .tailcall 'bool'($I0)
486 486
   exclusive_test:
487 487
     $I0 = isgt topic, from
488  
-    .return ($I0)
  488
+    .tailcall 'bool'($I0)
489 489
 .end
490 490
 
491 491
 .sub '!to_test' :method
@@ -500,15 +500,15 @@ honoring exclusive flags.
500 500
     $I1 = length $S1
501 501
     eq $I0, $I1, test_value
502 502
     $I0 = islt $I0, $I1
503  
-    .return ($I0)
  503
+    .tailcall 'bool'($I0)
504 504
   test_value:
505 505
     toexc = getattribute self, '$!to_exclusive'
506  
-    if toexc > 0 goto exclusive_test
  506
+    if toexc, exclusive_test
507 507
     $I0 = isle topic, to
508  
-    .return ($I0)
  508
+    .tailcall 'bool'($I0)
509 509
   exclusive_test:
510 510
     $I0 = islt topic, to
511  
-    .return ($I0)
  511
+    .tailcall 'bool'($I0)
512 512
 .end
513 513
 
514 514
 =back

0 notes on commit 5a9784f

Please sign in to comment.
Something went wrong with that request. Please try again.