From 0f52c91f64be6fa3036e92fc3b75a21395c56ac1 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Fri, 25 Jun 2021 13:48:58 -0400 Subject: [PATCH] wip! Port the back end to Mes. See also . * gash/pattern.scm (): Use 'define-record-type' instead of 'define-immutable-record-type'. * mes/gash.mes: Add a bunch of shims; run 'guile --version'. --- gash/pattern.scm | 4 +-- mes/gash.mes | 78 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/gash/pattern.scm b/gash/pattern.scm index a9170d1..02610ec 100644 --- a/gash/pattern.scm +++ b/gash/pattern.scm @@ -20,7 +20,7 @@ #:use-module (ice-9 match) #:use-module (ice-9 receive) #:use-module (srfi srfi-1) - #:use-module (srfi srfi-9 gnu) + #:use-module (srfi srfi-9) #:use-module (srfi srfi-26) #:use-module (gash compat srfi-43) #:export (parse-pattern @@ -31,7 +31,7 @@ pattern-drop pattern-drop-right)) -(define-immutable-record-type +(define-record-type (make-pattern parts) pattern? (parts pattern-parts)) diff --git a/mes/gash.mes b/mes/gash.mes index ce60d63..868903a 100644 --- a/mes/gash.mes +++ b/mes/gash.mes @@ -8,10 +8,6 @@ (mes-use-module (srfi srfi-14)) (mes-use-module (srfi srfi-26)) - - -;; Stuff for the lexer. - ;; SRFI 14 extras @@ -113,29 +109,95 @@ (define (string-every pred str) (every pred (string->list str))) + +;; Prompts + +(define* (make-prompt-tag #:optional (stem "prompt")) + (list stem)) + ;; Misc. fixes (define-syntax-rule (define-inlinable stuff ...) (define stuff ...)) - - -;; Stuff for the parser - (define the-eof-object (integer->char -1)) (define (noop . args) #f) +(define (alist->hash-table alist) + (define ht (make-hash-table 100)) + (fold-right (lambda (kvp acc) + (hash-set! ht (car kvp) (cdr kvp))) + #f + alist) + ht) + +;; FIXME: Actually do somrething here. +(define (canonicalize-path path) path) + +;; Shadow these so that optional arguments work. +(define mes-make-hash-table make-hash-table) +(define mes-hash-ref hash-ref) +(define* (make-hash-table #:optional (size 0)) + (mes-make-hash-table size)) +(define* (hash-ref table key #:optional dflt) + (mes-hash-ref table key dflt)) + +(define X_OK 1) + +(define program-arguments command-line) + +(define (hash-fold proc init table) + (define (proc* kvp acc) + (proc (car kvp) (cdr kvp) acc)) + (define buckets (struct-ref table 4)) + (let loop ((k 0) (acc init)) + (if (>= k (vector-length buckets)) + acc + (let ((bucket (vector-ref buckets k))) + (loop (1+ k) + (if (pair? bucket) + (fold proc* acc bucket) + acc)))))) + +(define delete-duplicates! delete-duplicates) + +;; Mes does not have port buffers. +(define flush-all-ports noop) + +;; Mes uses raw file descriptors for file ports. +(define file-port? number?) + +;; This is probably OK.... +(define (input-port? port) #f) +(define (output-port? port) #f) + +;; More interface adjustments. +(define mes-dup dup) +(define* (dup fd #:optional new) + (if new (dup2 fd new) (dup fd))) + ;; Main show (include-from-path "gash/lexer.scm") (include-from-path "gash/parser.scm") +(include-from-path "gash/environment.scm") +(include-from-path "gash/pattern.scm") + +;; These should come from (gash built-ins), but that whole system needs +;; to be reworked. +(define (search-built-ins name) #f) +(define (search-special-built-ins name) #f) + +(include-from-path "gash/shell.scm") ;; XXX: Mes module loading seems to bork reading from stdin. (set-current-input-port (open-input-file "/home/samplet/code/gash/mes/test.sh")) +(sh:exec "guile" "--version") + (write (read-sh-all)) (newline)