forked from jmesyou/erasure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bring work up to date, added sample program, create runtime, used key…
…words for enums
- Loading branch information
Jack You
authored and
Jack You
committed
Apr 2, 2018
1 parent
493199b
commit 3004353
Showing
5 changed files
with
72 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(ns clj-whitespace.programs | ||
(:gen-class)) | ||
|
||
(def hello-world " \t \t \n \t\t\t \t\t \t\t \t \n \n\t\t \t \t \n\t\n \t\t \t \t\n\t\n \t\t \t\t \n \n \t\n \t\n \t\t \t\t\t\t\n\t\n \t \n\t\n \t \t \t\t\t\n\t\n \t\t \t\t\t\t\n\t\n \t\t\t \t \n\t\n \t\t \t\t \n\t\n \t\t \t \n\t\n \t \t\n\t\n \t \t \n\t\n \n\n\n\n ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns clj-whitespace.runtime | ||
(:require [clojure.core.match :refer [match]]) | ||
(:gen-class)) | ||
|
||
(defn routine [prgm stack table labels call-stack] | ||
(if (empty? prgm) | ||
(do ()) | ||
(match [prgm] | ||
[([[:push v] & xs] :seq)] (routine xs (conj stack v) table labels call-stack) | ||
[([:dup & xs] :seq)] (let [x (peek stack)] (routine xs (conj stack x) table labels call-stack)) | ||
[([:swap & xs] :seq)] (let [a (first stack) b (second stack)] (routine xs (concat [b a] (nnext stack)) table labels call-stack)) | ||
[([:pop & xs] :seq)] (routine xs (pop stack) table labels call-stack) | ||
[([:add & xs] :seq)] (let [a (first stack) b (second stack)] (routine xs (conj (nnext stack) (+ b a)) table labels call-stack)) | ||
[([:sub & xs] :seq)] (let [a (first stack) b (second stack)] (routine xs (conj (nnext stack) (- b a)) table labels call-stack)) | ||
[([:mul & xs] :seq)] (let [a (first stack) b (second stack)] (routine xs (conj (nnext stack) (* b a)) table labels call-stack)) | ||
[([:div & xs] :seq)] (let [a (first stack) b (second stack)] (routine xs (conj (nnext stack) (/ b a)) table labels call-stack)) | ||
[([:mod & xs] :seq)] (let [a (first stack) b (second stack)] (routine xs (conj (nnext stack) (mod b a)) table labels call-stack)) | ||
[([:print-char & xs] :seq)] (do (print (char (first stack))) (routine xs stack table labels call-stack)) | ||
[([:print-int & xs] :seq)] (do (print (first stack)) (routine xs stack table labels call-stack)) | ||
:else (throw (Exception. "[runtime/routine] unexpected or malformed op!"))))) | ||
|
||
(defn exec [prgm labels] (routine prgm '() {} labels nil)) |