command line with clingon (how to use it i dont get it???)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
:version "0.1"
|
:version "0.1"
|
||||||
:author "Emre Akan"
|
:author "Emre Akan"
|
||||||
:licence "MIT"
|
:licence "MIT"
|
||||||
:depends-on ("iterate" "cl-fad")
|
:depends-on ("iterate" "cl-fad" "clingon")
|
||||||
:serial t
|
:serial t
|
||||||
:components ((:file "package")
|
:components ((:file "package")
|
||||||
(:file "util")
|
(:file "util")
|
||||||
|
|||||||
131
main.lisp
131
main.lisp
@@ -1,25 +1,30 @@
|
|||||||
(in-package :cl-forth)
|
(in-package :cl-forth)
|
||||||
|
|
||||||
(defun main ()
|
;; (defun main ()
|
||||||
(let ((args (rest sb-ext:*posix-argv*)))
|
;; (let ((args (rest sb-ext:*posix-argv*)))
|
||||||
(let ((flag (first args)))
|
;; (let ((flag (first args)))
|
||||||
(cond ((string= flag "-c")
|
;; (cond ((string= flag "-c")
|
||||||
;; (iter (for (k v) in-hashtable *operations*)
|
;; ;; (iter (for (k v) in-hashtable *operations*)
|
||||||
;; (for i from 0)
|
;; ;; (for i from 0)
|
||||||
;; (format t "~s: ~s~%" i k))
|
;; ;; (format t "~s: ~s~%" i k))
|
||||||
;; (let ((tokens (lex-file (second args))))
|
;; ;; (let ((tokens (lex-file (second args))))
|
||||||
;; (format t "~s~%" tokens)
|
;; ;; (format t "~s~%" tokens)
|
||||||
;; (let ((program (prog-from-tokens tokens)))
|
;; ;; (let ((program (prog-from-tokens tokens)))
|
||||||
;; (format t "~s~%" program)
|
;; ;; (format t "~s~%" program)
|
||||||
;; (generate-program program :compile t)))
|
;; ;; (generate-program program :compile t)))
|
||||||
(generate-program (make-program (second args)) :compile t))
|
;; (generate-program (make-program (second args)) :compile t))
|
||||||
((string= flag "-p")
|
;; ((string= flag "-p")
|
||||||
(format t "~a" (make-program (second args))))
|
;; (format t "~a" (make-program (second args))))
|
||||||
((string= flag "-t")
|
;; ((string= flag "-t")
|
||||||
(run-tests))
|
;; (run-tests))
|
||||||
((string= flag "-s")
|
;; ((string= flag "-s")
|
||||||
(simulate-program (make-program (second args))))
|
;; (simulate-program (make-program (second args))))
|
||||||
(t (format t "~a is not a valid flag~%" flag))))))
|
;; ((string= flag "-i")
|
||||||
|
;; (simulate-program (with-open-file (str (second args))
|
||||||
|
;; (read str))))
|
||||||
|
;; ((string= flag "-e")
|
||||||
|
;; (print 5))
|
||||||
|
;; (t (format t "~a is not a valid flag~%" flag))))))
|
||||||
|
|
||||||
;; (defun make-exe ()
|
;; (defun make-exe ()
|
||||||
;; (sb-ext:save-lisp-and-die #P"cl-forth"
|
;; (sb-ext:save-lisp-and-die #P"cl-forth"
|
||||||
@@ -38,8 +43,8 @@
|
|||||||
(generate-program (make-program *example-path*) :path "test/output.asm"
|
(generate-program (make-program *example-path*) :path "test/output.asm"
|
||||||
:compile t))
|
:compile t))
|
||||||
|
|
||||||
(defun example-interpret ()
|
;; (defun example-interpret ()
|
||||||
(interpret-program (make-program *example-path*)))
|
;; (interpret-program (make-program *example-path*)))
|
||||||
|
|
||||||
(defun example-run ()
|
(defun example-run ()
|
||||||
(example-compile)
|
(example-compile)
|
||||||
@@ -49,4 +54,84 @@
|
|||||||
(iter (for line = (progn (format t "~&> ") (read-line)))
|
(iter (for line = (progn (format t "~&> ") (read-line)))
|
||||||
(when (string= line "bye")
|
(when (string= line "bye")
|
||||||
(finish))
|
(finish))
|
||||||
(interpret-program (parse-tokens (lex-line line 0)))))
|
(simulate-program (parse-tokens (lex-line line 0)))))
|
||||||
|
|
||||||
|
(defun subcommands ()
|
||||||
|
(list (clingon:make-command
|
||||||
|
:name "derle"
|
||||||
|
:description "Dosyadaki programı derle"
|
||||||
|
:usage "<dosya-ismi>"
|
||||||
|
:handler (lambda (cmd) (generate-program
|
||||||
|
(make-program
|
||||||
|
(car (clingon:command-arguments cmd)))
|
||||||
|
:compile t)))
|
||||||
|
(clingon:make-command
|
||||||
|
:name "test"
|
||||||
|
:description "Testleri çalıştır."
|
||||||
|
:handler (lambda (cmd) (declare (ignore cmd)) (run-tests)))
|
||||||
|
(clingon:make-command
|
||||||
|
:name "sim"
|
||||||
|
:description "Dosyadaki programı simüle et."
|
||||||
|
:usage "<dosya-ismi>"
|
||||||
|
:handler (lambda (cmd) (simulate-program
|
||||||
|
(make-program
|
||||||
|
(car (clingon:command-arguments cmd))))))))
|
||||||
|
|
||||||
|
(defun top-level-options ()
|
||||||
|
(list (clingon:make-option
|
||||||
|
:flag
|
||||||
|
:description "Programın seçeneklerini göster."
|
||||||
|
:short-name #\h
|
||||||
|
:key :help)))
|
||||||
|
|
||||||
|
(defun top-level-handler (cmd)
|
||||||
|
(clingon:print-usage-and-exit cmd t))
|
||||||
|
|
||||||
|
(defun top-level-command ()
|
||||||
|
(clingon:make-command
|
||||||
|
:name "cl-forth"
|
||||||
|
:description "cl-forth derleyicisi"
|
||||||
|
:version "0.1.0"
|
||||||
|
:authors '("Emre Akan <akannemre@gmail.com>")
|
||||||
|
:options (top-level-options)
|
||||||
|
:handler #'top-level-handler
|
||||||
|
:sub-commands (subcommands)))
|
||||||
|
|
||||||
|
(defun main ()
|
||||||
|
(let ((app (top-level-command)))
|
||||||
|
(clingon:run app)))
|
||||||
|
|
||||||
|
;; (defun handler (cmd)
|
||||||
|
;; (let ((help (clingon:getopt cmd :help))
|
||||||
|
;; (comp (clingon:getopt cmd :compile))
|
||||||
|
;; (sim (clingon:getopt cmd :simulate))
|
||||||
|
;; (test (clingon:getopt cmd :test)))
|
||||||
|
;; (cond ((or (not (null help)) (= 0 (length cmd (clingon:command-arguments cmd))))
|
||||||
|
;; (clingon:print-usage (cli-command) t))
|
||||||
|
;; ((not (null compile))
|
||||||
|
;; (generate-program (make-program (second args)) :compile t))
|
||||||
|
;; ((not null sim)
|
||||||
|
;; (simulate-program (make-program (second args))))
|
||||||
|
;; ((not null test)
|
||||||
|
;; (run-tests)))))
|
||||||
|
|
||||||
|
;; (defun sim-options ()
|
||||||
|
;; (list (clingon:make-option
|
||||||
|
;; :filepath
|
||||||
|
;; :description "Dosyadaki programı simüle et."
|
||||||
|
;; :short-name #\s
|
||||||
|
;; :key :simulate)))
|
||||||
|
|
||||||
|
;; (defun comp-options ()
|
||||||
|
;; (list (clingon:make-option
|
||||||
|
;; :filepath
|
||||||
|
;; :description "Dosyadaki programı derle."
|
||||||
|
;; :short-name #\c
|
||||||
|
;; :key :compile)))
|
||||||
|
|
||||||
|
;; (defun test-options ()
|
||||||
|
;; (list (clingon:make-option
|
||||||
|
;; :flag
|
||||||
|
;; :description "Testleri çalıştır."
|
||||||
|
;; :short-name #\t
|
||||||
|
;; :key :test)))
|
||||||
|
|||||||
Reference in New Issue
Block a user