whalesong/expression-structs.rkt

36 lines
1.3 KiB
Racket

#lang typed/racket/base
(require "lexical-structs.rkt")
(provide (all-defined-out))
;; Expressions
(define-type ExpressionCore (U Top Constant Var Branch Def Lam Seq #;App))
(define-type Expression (U ExpressionCore #;Assign))
(define-struct: Top ([prefix : Prefix]
[code : ExpressionCore]) #:transparent)
(define-struct: Constant ([v : Any]) #:transparent)
(define-struct: Var ([id : Symbol]) #:transparent)
(define-struct: Assign ([variable : Symbol]
[value : Expression]) #:transparent)
(define-struct: Branch ([predicate : Expression]
[consequent : Expression]
[alternative : Expression]) #:transparent)
(define-struct: Def ([variable : Symbol]
[value : Expression]) #:transparent)
(define-struct: Lam ([parameters : (Listof Symbol)]
[body : Expression]) #:transparent)
(define-struct: Seq ([actions : (Listof Expression)]) #:transparent)
(define-struct: App ([operator : Expression]
[operands : (Listof Expression)]) #:transparent)
(: last-exp? ((Listof Expression) -> Boolean))
(define (last-exp? seq)
(null? (cdr seq)))
(: first-exp ((Listof Expression) -> Expression))
(define (first-exp seq) (car seq))
(: rest-exps ((Listof Expression) -> (Listof Expression)))
(define (rest-exps seq) (cdr seq))