Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Logic Programming and Compiler Writing (1980) [pdf]. Parent comment
(defun run (&optional (stream *standard-input*)) (let ((pc 0) (mem (make-array 32 :element-type 'bit :initial-element 0)) (halted nil)) (labels ((execute (code &optional a b) (macrolet ((mref (idx) `(sbit mem ,idx))) (ecase code (and (setf (mref a) (logand (mref a) (mref b)))) (or (setf (mref a) (logior (mref a) (mref b)))) (xor (setf (mref a) (logxor (mref a) (mref b)))) (not (setf (mref a) (if (zerop (mref a)) 1 0))) (mov (setf (mref a) (mref b))) (set (setf (mref a) b)) (random (setf (mref a) (random 2))) (jmp (setf pc (1- a))) (jz (when (zerop (mref b)) (setf pc (1- a)))) (halt (setf halted t))))) (interpret (codes) (loop for nil = (apply #'execute (aref codes pc)) and cycles from 1 do (incf pc) until (or halted (>= cycles 100000)) finally (if halted (format t "Program halts! ~a instructions executed.~%" cycles) (format t "Unable to determine if program halts.~%")))) (read-program () (coerce (loop for pc below (parse-integer (read-line stream)) collect (read-from-string (concatenate 'string "(" (read-line stream) ")"))) 'vector))) (interpret (read-program)))))
The rest in the example is an actual compiler.
There are no comments on this comment yet.
The rest in the example is an actual compiler.