commit 9a170384797d6caaf4d07637b7e7348ef479e674 Author: Moritz Gmeiner Date: Sat Sep 7 01:51:08 2024 +0200 init commit diff --git a/.vscode/alive/fasl/tmp.fasl b/.vscode/alive/fasl/tmp.fasl new file mode 100644 index 0000000..24fc7a0 Binary files /dev/null and b/.vscode/alive/fasl/tmp.fasl differ diff --git a/.vscode/alive/fasl/tmp.lisp b/.vscode/alive/fasl/tmp.lisp new file mode 100644 index 0000000..045ea3f --- /dev/null +++ b/.vscode/alive/fasl/tmp.lisp @@ -0,0 +1,11 @@ +(in-package :cl-lox) + +(defstruct code-pos + (line 1 :type integer) + (col 0 :type integer)) + + +(defstruct token + (code-pos (make-code-pos) :type code-pos) + token-type + (data nil)) diff --git a/.vscode/alive/repl-history.json b/.vscode/alive/repl-history.json new file mode 100644 index 0000000..b9e832f --- /dev/null +++ b/.vscode/alive/repl-history.json @@ -0,0 +1 @@ +[{"pkgName":"cl-user","text":"(describe token-type)"},{"pkgName":"cl-user","text":"(describe 'token-type)"},{"pkgName":"cl-user","text":"(make-code-pos)"},{"pkgName":"cl-user","text":"(cl-lox::code-pos)"},{"pkgName":"cl-user","text":"(code-pos)"},{"pkgName":"cl-user","text":"(code-pos"},{"pkgName":"cl-user","text":"(typep \"asdf\" 'string)"},{"pkgName":"cl-user","text":"(describe 'integer)"},{"pkgName":"cl-user","text":"(describe 'string)"},{"pkgName":"cl-user","text":"'string"},{"pkgName":"cl-user","text":"string"},{"pkgName":"cl-user","text":"(type-of xyz)"},{"pkgName":"cl-user","text":"(setf xyz \"asdf\")"},{"pkgName":"cl-user","text":"xyz"},{"pkgName":"cl-user","text":"(defvar xyz 123)"},{"pkgName":"cl-user","text":"(cl-lox::scan-tokens 3)"},{"pkgName":"cl-user","text":"(scan-tokens 3)"},{"pkgName":"cl-user","text":"(cl-lox::run-repl)"},{"pkgName":"cl-user","text":"(cl-lox::run-file :path nil)"},{"pkgName":"cl-user","text":"(cl-lox:run-repl)"},{"pkgName":"cl-user","text":"(run-repl)"},{"pkgName":"cl-user","text":"(length argv)"},{"pkgName":"cl-user","text":"argv"},{"pkgName":"cl-user","text":"4"},{"pkgName":"cl-user","text":"(argv)"},{"pkgName":"cl-user","text":"(defvar argv (uiop:command-line-arguments))"},{"pkgName":"cl-user","text":"(define argv (uiop:command-line-arguments))"},{"pkgName":"cl-user","text":"(uiop:command-line-arguments)"},{"pkgName":"cl-user","text":"(cl-lox:main)"},{"pkgName":"cl-user","text":"(asdf:make :cl-lox)"},{"pkgName":"cl-user","text":"(my-command-line)"},{"pkgName":"cl-user","text":"(cl-lox:my-command-line)"},{"pkgName":"cl-user","text":"(cl-lox:hello)"},{"pkgName":"cl-user","text":"(hello)"},{"pkgName":"cl-user","text":"(ql:quickload \"cl-ppcre\")"},{"pkgName":"cl-user","text":"(ql:quickload cl-ppcre)"}] \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..99c2a0b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.formatOnType": true, + "[commonlisp]": { + "editor.wordSeparators": "`|;:'\",()" + } +} diff --git a/cl-lox.asd b/cl-lox.asd new file mode 100644 index 0000000..96bf7c8 --- /dev/null +++ b/cl-lox.asd @@ -0,0 +1,8 @@ +(asdf:defsystem "cl-lox" + :description "Lox implementation in Common Lisp" + :serial t + :depends-on () + :components ((:file "package") + (:file "src/cl-lox") + (:file "src/token") + (:file "src/lexer"))) diff --git a/package.lisp b/package.lisp new file mode 100644 index 0000000..60ea194 --- /dev/null +++ b/package.lisp @@ -0,0 +1,4 @@ +(defpackage cl-lox + (:use cl) + (:export #:main) + (:export #:make-exe)) diff --git a/src/cl-lox.lisp b/src/cl-lox.lisp new file mode 100644 index 0000000..1fb351d --- /dev/null +++ b/src/cl-lox.lisp @@ -0,0 +1,11 @@ +(in-package :cl-lox) + + +(defun main () + (let* ((argv (uiop:command-line-arguments)) (argc (length argv))) + (cond ((= argc 0) (run-repl)) + ((= argc 1) (run-file :path (car argv)))))) + + +(defun make-exe () + (sb-ext:save-lisp-and-die "cl-lox" :toplevel #'main :executable t)) diff --git a/src/lexer.lisp b/src/lexer.lisp new file mode 100644 index 0000000..8d17266 --- /dev/null +++ b/src/lexer.lisp @@ -0,0 +1,6 @@ +(in-package :cl-lox) + + +(defun scan-tokens (source) + (declare (string source) + (ignore source))) diff --git a/src/run.lisp b/src/run.lisp new file mode 100644 index 0000000..8e4ada0 --- /dev/null +++ b/src/run.lisp @@ -0,0 +1,13 @@ +(in-package :cl-lox) + + +(defun run-file (&key path) + (let ((source (uiop:read-file-string path))) + (run source))) + + +(defun run-repl ()) + +(defun run (source) + (declare (string source) + (ignore source))) diff --git a/src/token.fasl b/src/token.fasl new file mode 100644 index 0000000..20755b5 Binary files /dev/null and b/src/token.fasl differ diff --git a/src/token.lisp b/src/token.lisp new file mode 100644 index 0000000..045ea3f --- /dev/null +++ b/src/token.lisp @@ -0,0 +1,11 @@ +(in-package :cl-lox) + +(defstruct code-pos + (line 1 :type integer) + (col 0 :type integer)) + + +(defstruct token + (code-pos (make-code-pos) :type code-pos) + token-type + (data nil))