Skip to content

Instantly share code, notes, and snippets.

@kingcons
Created March 25, 2013 16:42
Show Gist options
  • Save kingcons/5238551 to your computer and use it in GitHub Desktop.
Save kingcons/5238551 to your computer and use it in GitHub Desktop.
(ql:quickload '(cl-fad cl-ppcre))
(defpackage :sloc
(:use :cl)
(:import-from :cl-fad #:walk-directory))
(in-package :sloc)
(defvar *ext->syntax*
'(("factor" "^!.*"))
"A mapping from pathname-types to regexes to ignore.")
(defun count-file-lines (file regex)
"Count the lines in FILE not matching REGEX."
(with-open-file (in file)
(loop for line = (read-line in nil) while line
unless (or (cl-ppcre:scan regex line)
(string= "" line))
count line)))
(defun count-lines (filetype dir &optional constraints)
"Count all the valid lines under DIR for the given FILETYPE."
(let ((regex (second (assoc filetype *ext->syntax* :test #'equal)))
(count 0))
(unless regex
(error "No such filetype in ~A" *ext->syntax*))
(walk-directory dir (lambda (f) (incf count (count-file-lines f regex)))
:test (lambda (f)
(and (string= (pathname-type f) filetype)
(not (search "-docs" (pathname-name f))))))
count))
;; A few interesting stats:
;; Factor Compiler -> 25,505 lines Factor
;; Factor CPU -> 8,286 lines Factor
;; Factor Bootstrap -> 841 lines Factor
;; Factor Tools -> 4,404 lines Factor
;; Factor Help -> 2,651 lines Factor
;; Factor Classes -> 2,470 lines Factor
;; Factor Generics -> 968 lines Factor
;; Factor Stack-xer -> 1,913 lines Factor
;; Factor Alien/FFI -> 1,710 lines Factor
;; Factor PEG Parser -> 1,775 lines Factor
;; Factor Prettyprinter -> 1,048 lines Factor
;; Factor Vocabs -> 658 lines Factor
;; Factor Kernel -> 343 lines Factor
;; Factor Debugger -> 354 lines Factor
;; Factor Listener -> 225 lines Factor
;; Factor Inspector -> 110 lines Factor
;; Factor Macros -> 118 lines Factor
;; TOTAL -> 53,379 lines Factor
;; Other stats:
;; Factor VM -> ~14,500 lines C/C++ (via CLOC)
;; Factor Basis -> 151,446 lines Factor
;; Factor Core -> 14,435 lines Factor
;; Factor Extra -> 73,884 lines Factor
;; Unmaintained Code -> 16,360 lines Factor
;; TODO: Rough comparisons to CCL, LuaJIT?
;; and some interesting posts by littledan:
;; http://useless-factor.blogspot.com/2010/01/type-feedback-in-factor.html
;; http://useless-factor.blogspot.com/2010/04/couple-language-design-ideas.html
;; http://useless-factor.blogspot.com/2010/04/guarded-method-inlining-for-factor.html
;; and the DLS paper:
;; http://factorcode.org/littledan/dls.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment