shark-compiler/demo.rkt

51 lines
897 B
Racket
Executable File

#!/usr/bin/env racket
#lang shark/llir
(global count)
(global one)
(global zero)
(global j)
(global largest-j)
(global largest-value)
(global tmp)
(label main)
(set! zero 0)
(set! one 1)
(set! j 0)
(set! largest-j 0)
(set! largest-value -999999)
;; get size of input stack
(asm! "DDDcsUsUsU" "r" "w" count)
(ifeq count zero exit sort-step)
(label sort-step)
;; get value from input stack
(asm! "DDDrsuUsUsU" "r" "w" tmp)
(iflt tmp largest-value sort-step-cont sort-step-update)
(label sort-step-update)
(set! largest-j j)
(set! largest-value tmp)
(label sort-step-cont)
(add! j one)
(ifeq j count move-val sort-step)
(label move-val)
(set! j 0)
(label shift-loop)
(ifeq j largest-j shift-done shift-cont)
(label shift-cont)
(asm! "DDDuUUU" "r" "w" #f)
(add! j one)
(goto shift-loop)
(label shift-done)
;; move input->output
(asm! "DDDsUUU" "r" "w" #f)
(goto main)
(label exit)
(terminate)