@@ -372,6 +372,17 @@ case class EventuallyProgram(
372
372
def cloneable = this .copy(mainProcedure = mainProcedure.cloneable, otherProcedures = otherProcedures.map(_.cloneable))
373
373
}
374
374
375
+ /**
376
+ * Construction of basil IR programs from high level while langauge.
377
+ *
378
+ * These functions uniformly return a list of eventually block, where the first block
379
+ * is the entry point and the last block is the exit point.
380
+ * These lists are then concatenated by the functions [[sequence ]] and [[blocks ]].
381
+ * The function [[blocks ]] is essentially list.concat, but it connects each sublist
382
+ * with jumps.
383
+ *
384
+ */
385
+
375
386
object Counter {
376
387
var count = 1
377
388
def next () = {
@@ -421,11 +432,16 @@ def setSuccIfUndef(first: List[EventuallyBlock], rest: EventuallyBlock*) = {
421
432
first
422
433
}
423
434
424
- // def While(cond: Expr, body: EventuallyBlock*): List[EventuallyBlock] = {
425
- // While(cond, body.toList)
426
- // }
435
+ case class For (init : List [EventuallyBlock ], cond : Expr , after : List [EventuallyBlock ]) {
436
+ def Do (body : Iterable [EventuallyBlock ]) = mkFor(init, cond, after, (body.toList))
437
+ @ targetName(" doBlocks" )
438
+ def Do (body : EventuallyBlock * ) = mkFor(init, cond, after, (body.toList))
439
+ @ targetName(" doStatements" )
440
+ def Do (sl : (EventuallyCall | NonCallStatement | EventuallyStatement | EventuallyJump )* ) =
441
+ mkFor(init, cond, after, (List (stmts(sl : _* ))))
442
+ }
427
443
428
- def For (
444
+ private def mkFor (
429
445
init : List [EventuallyBlock ],
430
446
cond : Expr ,
431
447
after : List [EventuallyBlock ],
@@ -438,23 +454,6 @@ def For(
438
454
sequence(init, loop)
439
455
}
440
456
441
- // def For(init: EventuallyBlock, cond: Expr, after: EventuallyBlock, body: EventuallyBlock*): List[EventuallyBlock] = {
442
- // For(List(init), cond, List(after), body.toList)
443
- // }
444
- //
445
- // def For(init: NonCallStatement, cond: Expr, after: NonCallStatement, body: EventuallyBlock*): List[EventuallyBlock] = {
446
- // require(body.nonEmpty)
447
- // For(List(stmts(init)), cond, List(stmts(after)), body.toList)
448
- // }
449
- // def For(
450
- // init: NonCallStatement,
451
- // cond: Expr,
452
- // after: NonCallStatement,
453
- // body: List[EventuallyBlock]
454
- // ): List[EventuallyBlock] = {
455
- // For(List(stmts(init)), cond, List(stmts(after)), body.toList)
456
- // }
457
-
458
457
case class WhileDo (cond : Expr ) {
459
458
def Do (body : Iterable [EventuallyBlock ]) = While (cond, (body.toList))
460
459
@ targetName(" doBlocks" )
@@ -555,9 +554,12 @@ def progUnresolved(
555
554
): EventuallyProgram =
556
555
EventuallyProgram (mainProc, procedures, initialMemory)
557
556
558
- /**
559
- * Expr construction
560
- */
557
+ /**
558
+ * Expr and statement construction; this defined infix operators which construct
559
+ * BASIL IR statements and expressions.
560
+ *
561
+ * Typically with binops we default to signed ops, and provide named unsigned alternatives.
562
+ */
561
563
562
564
extension (lvar : Variable )
563
565
infix def := (j : Expr ) = LocalAssign (lvar, j)
0 commit comments