Skip to content

Instantly share code, notes, and snippets.

@SHoltzen
Last active April 5, 2025 23:14
Show Gist options
  • Select an option

  • Save SHoltzen/da29ef5d8a04240430a9ff37efa072f0 to your computer and use it in GitHub Desktop.

Select an option

Save SHoltzen/da29ef5d8a04240430a9ff37efa072f0 to your computer and use it in GitHub Desktop.
#lang plait
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; starter code: do not modify
(define-type IfLang
(boolE [b : Boolean])
(ifE [g : IfLang] [thn : IfLang] [els : IfLang])
(tryE [e : IfLang] [handle-id : Symbol] [handler : IfLang])
(raiseE [id : Symbol]))
(define-type Frame
(handleF [id : Symbol] [h : IfLang])
(ifF [thn : IfLang] [els : IfLang]))
(define-type State
(state [C : IfLang]
[K : (Listof Frame)]))
;;; push f onto the frame stack
(define (push-frame f stack)
(append (list f) stack))
(define (pop-frame stack)
(type-case (Listof Frame) stack
[(cons hd tl)
(pair hd tl)]
[empty (error 'invalid "popping empty stack frame")]))
;;; runs the machine beginning from `state` until a fixed point is reached
(define (run-machine s)
(begin
; uncomment these lines to see the state of your machine progress
; (display s)
; (display "\n")
(let [(next-state (transition s))]
(if (equal? next-state s)
s
(run-machine next-state)))))
;;; run the machine starting in control register e with
;;; store size store-size
(run-machine-init : (IfLang -> IfLang))
(define (run-machine-init e)
(let [(r (run-machine (state e empty)))]
(state-C r)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; problem 1
;;; your solution goes here
(transition : (State -> State))
(define (transition s)
(error 'implementme ""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment