((1op #x02) get_child ez-op-get-child)
((1op #x03) get_parent ez-op-get-parent)
((2op #x0A) test_attr ez-op-test-attr)
- ((var #x03) put_prop ez-op-put-prop)))
+ ((var #x03) put_prop ez-op-put-prop)
+ ((0op #x02) print ez-op-print)))
(defun ez-op-ret (operands &optional operand-types)
(let ((retval (car operands)))
(ez-set-obj-prop obj prop a)
t))
-;; Main
+(defun ez-op-print (operands operand-types)
+ (ez-print (ez-get-zstring (ez-get-pc)))
+ t)
+
+
+;; Execution loop
(defun ez-run (filename)
(ez-load-file filename)
(while (ez-execute-instr)))
-;; Scratch
-
-;; (ez-load-file "zork1.z3")
-;; (ez-parse-header)
-;; (setq ez-call-stack (list (ez-make-call-stack-frame ez-start-pc)))
-;; (while (ez-execute-instr))
-(ez-run "zork1.z3")
+;;; Buffer and I/O
+;;
+
+(defun ez-render-prompt ()
+ (with-current-buffer "*ez*"
+ (let ((update-point (= ez-input-marker (point)))
+ (update-window-points (mapcar (lambda (w)
+ (list (= (window-point w) ez-input-marker)
+ w))
+ (get-buffer-window-list nil nil t))))
+ (save-excursion
+ (set-marker-insertion-type ez-prompt-marker nil)
+ (set-marker-insertion-type ez-input-marker t)
+ (let ((inhibit-read-only t))
+ (delete-region ez-prompt-marker ez-input-marker)
+ (goto-char ez-prompt-marker)
+ (insert
+ ">"
+ (propertize " " ; Need this to be separate to mark it as rear-nonsticky
+ 'read-only t
+ 'rear-nonsticky t)))
+ (set-marker-insertion-type ez-input-marker nil))
+ (goto-char ez-input-marker))))
+
+(defvar ez-prompt-marker nil
+ "Marker for prompt position in buffer.")
+
+(defvar ez-input-marker nil
+ "Marker for prompt position in buffer.")
+
+(defun ez-setup-buffer ()
+ (with-current-buffer (get-buffer-create "*ez*")
+ (let ((inhibit-read-only t))
+ (delete-region (point-min) (point-max)))
+ (setq-local scroll-conservatively 1)
+ (if (markerp ez-prompt-marker)
+ (set-marker ez-prompt-marker (point-max))
+ (setq ez-prompt-marker (point-max-marker)))
+ (if (markerp ez-input-marker)
+ (set-marker ez-input-marker (point-max))
+ (setq ez-input-marker (point-max-marker)))
+ (goto-char (point-max))
+ (ez-render-prompt)))
+
+
+(defun ez-print (string)
+ (with-current-buffer "*ez*"
+ (save-excursion
+ (goto-char ez-prompt-marker)
+ (insert-before-markers string))))
+
+;; Mode
+
+(defvar ez-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "RET") 'ez-enter)
+ map))
+
+(define-derived-mode ez-mode text-mode "ez"
+ "Major mode for EZ.")
+
+(when (fboundp 'evil-set-initial-state)
+ (evil-set-initial-state 'ez-mode 'insert))
+
+(defun ez (zfile)
+ (interactive "fEnter name of z3 story file: ")
+ (if (get-buffer "*ez*")
+ (switch-to-buffer "*ez*")
+ (switch-to-buffer "*ez*")
+ (ez-mode)
+ (ez-setup-buffer)
+ (ez-run zfile))
+ "Started EZ.")
+
+(defun ez-debug ()
+ (interactive)
+ (switch-to-buffer "*ez*")
+ (ez-mode)
+ (ez-setup-buffer)
+ (ez-run "zork1.z3"))
;;; ez.el ends here