Advertisement
Guest User

Untitled

a guest
Nov 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.46 KB | None | 0 0
  1. #lang turnstile
  2. (require (prefix-in SM/ "sm.rkt"))
  3.  
  4. (provide (rename-out [@%module-begin #%module-begin]
  5.                      [@%datum #%datum]
  6.                      [@%app #%app]
  7.                      [@if if]))
  8.  
  9. (define-base-type Int)
  10. (define-base-type Bool)
  11. (define-type-constructor -> #:arity > 0)
  12.  
  13. (provide (typed-out [[SM/+ : (-> Int Int Int)] +]
  14.                     [[SM/- : (-> Int Int Int)] -]
  15.                     [[SM/* : (-> Int Int Int)] *]
  16.                     [[SM// : (-> Int Int Bool)] /]
  17.                     [[SM/< : (-> Int Int Bool)] <]
  18.                     [[SM/> : (-> Int Int Bool)] >]
  19.                     [[SM/= : (-> Int Int Bool)] =]))
  20.  
  21. (define-syntax @%module-begin
  22.   (syntax-parser
  23.     [(_ toplvl ...)
  24.      ; TODO: parse defines using syntax-local-lift-...
  25.      #'(SM/#%module-begin
  26.         (SM/do toplvl SM/.d) ...)]))
  27.  
  28. (define-typed-syntax @%datum
  29.   [(_ . n:exact-integer)
  30.    --------
  31.    [(#%no-expand (SM/#%datum . n)) ⇒ Int]]
  32.   [(_ . b:boolean)
  33.    --------
  34.    [(#%no-expand (SM/#%datum . b)) ⇒ Bool]])
  35.  
  36. (define-typed-syntax @%app
  37.   [(_ f e ...)
  38.    [⊢ f ≫ f-(~-> τ ... τ_out)]
  39.    [[e ≫ e- ⇐ τ] ...]
  40.    --------
  41.    [(#%no-expand (SM/do e- ... f-)) ⇒ τ_out]])
  42.  
  43. (define-typed-syntax @if
  44.   [(_ c e_1 e_2)
  45.    [⊢ c ≫ c- ⇐ Bool]
  46.    [⊢ e_1 ≫ e_1- ⇒ τ]
  47.    [⊢ e_2 ≫ e_2- ⇐ τ]
  48.    --------
  49.    [(#%no-expand (SM/do c- (SM/if [e_1-] [e_2-]))) ⇒ τ]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement