From 062f9eca335164b46dd869dc949efd5b35337d08 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Thu, 18 Jul 2024 09:09:19 +0800 Subject: [PATCH] [61_7] S7: rework in Scheme ## What New feature: ![img_v3_02ct_4d5b161e-8121-47db-ab94-a0a62f6e2c0g](https://github.com/user-attachments/assets/e23d14b1-1511-43ec-ada3-2d92a586d4f3) The other features remains the same with the cpp impl. ## Why To make it easier to maintain. ## How + Open `61_7.tm` + Open `Help -> Plugins -> S7 Scheme` --- TeXmacs/plugins/s7/doc/s7.en.tm | 235 ++++++++++----------- TeXmacs/plugins/s7/packages/code/s7.ts | 9 + TeXmacs/plugins/s7/progs/init-s7.scm | 3 +- TeXmacs/plugins/s7/s7/texmacs/protocol.scm | 47 +++++ TeXmacs/plugins/s7/s7/tm-s7.scm | 111 ++++++++++ TeXmacs/plugins/s7/src/{tm_s7.cpp => s7.c} | 151 +++---------- TeXmacs/tests/tmu/61_7.tmu | 100 +++++++++ bin/format | 2 +- xmake/tm_s7.lua | 2 +- 9 files changed, 418 insertions(+), 242 deletions(-) create mode 100644 TeXmacs/plugins/s7/s7/texmacs/protocol.scm create mode 100644 TeXmacs/plugins/s7/s7/tm-s7.scm rename TeXmacs/plugins/s7/src/{tm_s7.cpp => s7.c} (62%) create mode 100644 TeXmacs/tests/tmu/61_7.tmu diff --git a/TeXmacs/plugins/s7/doc/s7.en.tm b/TeXmacs/plugins/s7/doc/s7.en.tm index 25ced8ed4d..85464aad16 100644 --- a/TeXmacs/plugins/s7/doc/s7.en.tm +++ b/TeXmacs/plugins/s7/doc/s7.en.tm @@ -14,7 +14,7 @@ Here are snippets which only works in the S7 Scheme session: - + The string literal in S7 Scheme does not support Unicode. In the S7 Scheme session, we use the cork encoding as a workaround. @@ -35,7 +35,7 @@ <|unfolded-io> '\<#4E2D\>\<#6587\> <|unfolded-io> - \#4E2D\\#6587\ + \<#6587\>> <\unfolded-io> @@ -43,7 +43,7 @@ <|unfolded-io> '\#4E2D\\#6587\ <|unfolded-io> - \#4E2D\\#6587\ + \<#6587\>> <\unfolded-io> @@ -51,7 +51,7 @@ <|unfolded-io> (length "\<#4E2D\>\<#6587\>") <|unfolded-io> - 14 + <\unfolded-io> @@ -59,7 +59,7 @@ <|unfolded-io> (length "\#4E2D\\#6587\") <|unfolded-io> - 14 + <\input> @@ -69,7 +69,7 @@ - + For Scheme snippets starting with the markup \<#3001\>\<#3001\>\<#3001\>\<#3001\>\<#3001\>: @@ -106,6 +106,43 @@ + + + Eval result is rendered in green background. Side effect is in normal white + background. + + <\session|s7|default> + <\unfolded-io> + \\ + <|unfolded-io> + (begin (display "Hello") (newline) (+ 1 2)) + <|unfolded-io> + Hello + + + + + <\unfolded-io> + \\ + <|unfolded-io> + (for-each (lambda (x) (display x) (newline)) + + \ \ (list 1 2 3)) + <|unfolded-io> + 1 + + 2 + + 3 + + + <\input> + \\ + <|input> + \; + + + SRFI implementation for S7 Scheme will be built-in for the S7 Scheme @@ -163,7 +200,7 @@ <|unfolded-io> (import (srfi srfi-1)) <|unfolded-io> - (rootlet) + <\unfolded-io> @@ -171,7 +208,7 @@ <|unfolded-io> (reduce + 0 (list 1 2 3)) <|unfolded-io> - 6 + <\unfolded-io> @@ -179,7 +216,7 @@ <|unfolded-io> (import (srfi srfi-78)) <|unfolded-io> - (rootlet) + <\unfolded-io> @@ -191,7 +228,7 @@ (+ 1 2) =\ 3 ; correct - 1 + <\input> @@ -211,7 +248,7 @@ <|unfolded-io> (help 'equal?) <|unfolded-io> - "(equal? obj1 obj2) returns #t if obj1 is equal to obj2" + <\unfolded-io> @@ -219,7 +256,8 @@ <|unfolded-io> (help 'cdar) <|unfolded-io> - "(cdar lst) returns (cdr (car lst)): (cdar '((1 2 3))) -\ '(2 3)" + + '(2 3)"> <\input> @@ -237,7 +275,7 @@ <|unfolded-io> (eq? () ()) <|unfolded-io> - #t + <\unfolded-io> @@ -245,7 +283,7 @@ <|unfolded-io> (eq? 2 2.0) <|unfolded-io> - #f + <\unfolded-io> @@ -253,7 +291,7 @@ <|unfolded-io> (equal? 2 2.0) <|unfolded-io> - #f + <\unfolded-io> @@ -261,7 +299,7 @@ <|unfolded-io> (equivalent? 2 2.0) <|unfolded-io> - #t + <\unfolded-io> @@ -269,7 +307,7 @@ <|unfolded-io> (equivalent? .1 1/10) <|unfolded-io> - #t + <\input> @@ -291,7 +329,7 @@ <|unfolded-io> pi <|unfolded-io> - 3.141592653589793 + <\unfolded-io> @@ -299,7 +337,7 @@ <|unfolded-io> (*s7* 'bignum-precision) <|unfolded-io> - 128 + <\unfolded-io> @@ -307,7 +345,7 @@ <|unfolded-io> (set! (*s7* 'bignum-precision) 256) <|unfolded-io> - 256 + <\unfolded-io> @@ -315,7 +353,7 @@ <|unfolded-io> pi <|unfolded-io> - 3.141592653589793 + <\unfolded-io> @@ -323,7 +361,7 @@ <|unfolded-io> (bignum "123456789123456789") <|unfolded-io> - 123456789123456789 + <\unfolded-io> @@ -331,7 +369,7 @@ <|unfolded-io> (bignum "1.123123123123123123123123123") <|unfolded-io> - 1.1231231231231231 + <\input> @@ -349,7 +387,7 @@ <|unfolded-io> (exact? 1.0) <|unfolded-io> - #f + <\unfolded-io> @@ -357,7 +395,7 @@ <|unfolded-io> (rational? 1.5) <|unfolded-io> - #f + <\unfolded-io> @@ -365,7 +403,7 @@ <|unfolded-io> (floor 1.4) <|unfolded-io> - 1 + <\unfolded-io> @@ -373,7 +411,7 @@ <|unfolded-io> (remainder 2.4 1) <|unfolded-io> - 0.3999999999999999 + <\unfolded-io> @@ -381,7 +419,7 @@ <|unfolded-io> (modulo 1.4 1.0) <|unfolded-io> - 0.3999999999999999 + <\unfolded-io> @@ -389,7 +427,7 @@ <|unfolded-io> (lcm 3/4 1/6) <|unfolded-io> - 3/2 + <\unfolded-io> @@ -397,7 +435,7 @@ <|unfolded-io> (log 8 2) <|unfolded-io> - 3 + <\unfolded-io> @@ -405,7 +443,7 @@ <|unfolded-io> (number-\string 0.5 2) <|unfolded-io> - "0.1" + <\unfolded-io> @@ -413,7 +451,7 @@ <|unfolded-io> (string-\number "0.1" 2) <|unfolded-io> - 0.5 + <\unfolded-io> @@ -421,7 +459,7 @@ <|unfolded-io> (rationalize 1.5) <|unfolded-io> - 3/2 + <\unfolded-io> @@ -429,7 +467,7 @@ <|unfolded-io> (complex 1/2 0) <|unfolded-io> - 1/2 + <\unfolded-io> @@ -437,7 +475,7 @@ <|unfolded-io> (logbit? 6 1) <|unfolded-io> - #t + <\unfolded-io> @@ -445,7 +483,7 @@ <|unfolded-io> (random 0) <|unfolded-io> - 0 + <\unfolded-io> @@ -453,7 +491,7 @@ <|unfolded-io> (random 1.0) <|unfolded-io> - 0.27911546200969206 + <\unfolded-io> @@ -461,7 +499,7 @@ <|unfolded-io> (random 3/4) <|unfolded-io> - 208571/373317 + <\input> @@ -479,7 +517,7 @@ <|unfolded-io> (define v (make-vector '(2 3) 1.0)) <|unfolded-io> - #2d((1.0 1.0 1.0) (1.0 1.0 1.0)) + <\unfolded-io> @@ -487,7 +525,7 @@ <|unfolded-io> (set! (v 0 1) 2.0) <|unfolded-io> - 2.0 + <\unfolded-io> @@ -495,7 +533,7 @@ <|unfolded-io> (v 0 1) <|unfolded-io> - 2.0 + <\unfolded-io> @@ -503,7 +541,7 @@ <|unfolded-io> (vector-length v) <|unfolded-io> - 6 + <\input> @@ -525,7 +563,7 @@ \ \ (ht "hi")) <|unfolded-io> - 123 + <\unfolded-io> @@ -533,7 +571,7 @@ <|unfolded-io> (define test-tb (hash-table 'a 1 'b 2)) <|unfolded-io> - (hash-table 'a 1 'b 2) + <\unfolded-io> @@ -541,7 +579,7 @@ <|unfolded-io> (hash-table? test-tb) <|unfolded-io> - #t + <\unfolded-io> @@ -549,7 +587,7 @@ <|unfolded-io> (hash-table-ref test-tb 'a) <|unfolded-io> - 1 + <\unfolded-io> @@ -557,7 +595,7 @@ <|unfolded-io> (hash-table-entries test-tb) <|unfolded-io> - 2 + <\input> @@ -575,7 +613,7 @@ <|unfolded-io> (+ (values 1 2 3) 4) <|unfolded-io> - 10 + <\unfolded-io> @@ -583,7 +621,11 @@ <|unfolded-io> (values 1 2 3) <|unfolded-io> - (1 2 3) + <\errput> + wrong-number-of-args + + s7-print: too many arguments: 2 + <\unfolded-io> @@ -591,7 +633,7 @@ <|unfolded-io> ((lambda (a b) (+ a b)) 1 2) <|unfolded-io> - 3 + <\unfolded-io> @@ -599,7 +641,7 @@ <|unfolded-io> ((lambda (a b) (+ a b)) (values 1 2)) <|unfolded-io> - 3 + <\input> @@ -617,7 +659,7 @@ <|unfolded-io> (object-\string "hiho") <|unfolded-io> - "\\"hiho\\"" + <\unfolded-io> @@ -625,7 +667,7 @@ <|unfolded-io> (format #f "~S" "hiho") <|unfolded-io> - "\\"hiho\\"" + <\unfolded-io> @@ -633,7 +675,7 @@ <|unfolded-io> (format #f "~A ~D ~F" 'hi 123 3.14) <|unfolded-io> - "hi 123 3.140000" + <\input> @@ -651,7 +693,7 @@ <|unfolded-io> (eval '(+ 1 2)) <|unfolded-io> - 3 + <\unfolded-io> @@ -659,7 +701,7 @@ <|unfolded-io> (eval-string "(+ 1 2)") <|unfolded-io> - 3 + <\input> @@ -677,7 +719,7 @@ <|unfolded-io> (directory? "/tmp") <|unfolded-io> - #t + <\unfolded-io> @@ -685,7 +727,7 @@ <|unfolded-io> (file-exists? "/tmp") <|unfolded-io> - #t + <\unfolded-io> @@ -693,7 +735,7 @@ <|unfolded-io> (getenv "HOME") <|unfolded-io> - "/home/da" + <\input> @@ -715,16 +757,10 @@ <|unfolded-io> (abs 1 2) <|unfolded-io> - wrong-number-of-args - <\errput> - \; - - ;abs: too many arguments: (abs 1 2) - - ; (abs 1 2) + wrong-number-of-args - \; + abs: too many arguments: (abs 1 2) @@ -741,7 +777,8 @@ \ \ \ \ \ \ (apply format #t (cadr args)))) <|unfolded-io> - abs: too many arguments: (abs 1 2)"abs: too many arguments: (abs 1 2)" + abs: too many arguments: (abs 1 2) <\unfolded-io> @@ -753,7 +790,7 @@ \ \ \ \ (lambda args (string-\number "+inf.0"))) <|unfolded-io> - +inf.0 + <\input> @@ -771,16 +808,10 @@ <|unfolded-io> (load "test.scm") <|unfolded-io> - io-error - <\errput> - \; - - ;load: No such file or directory "test.scm" + io-error - ; (load "test.scm") - - \; + load: No such file or directory "test.scm" @@ -799,7 +830,7 @@ <|unfolded-io> (define v (immutable! (vector 1 2 3))) <|unfolded-io> - #(1 2 3) + <\unfolded-io> @@ -807,20 +838,10 @@ <|unfolded-io> (vector-set! v 0 23) <|unfolded-io> - immutable-error - <\errput> - \; + immutable-error - ;can't vector-set! #(1 2 3) (it is immutable) - - ; (vector-set! v 0 23) - - ; ((/ 1.0 0.0)) - - ; ((/ 1.0 0.0)) - - \; + can't vector-set! #(1 2 3) (it is immutable) @@ -829,7 +850,7 @@ <|unfolded-io> (immutable? v) <|unfolded-io> - #t + <\unfolded-io> @@ -837,7 +858,7 @@ <|unfolded-io> (define-constant var 32) <|unfolded-io> - 32 + <\unfolded-io> @@ -845,20 +866,10 @@ <|unfolded-io> (set! var 1) <|unfolded-io> - syntax-error - <\errput> - \; - - ;set!: can't alter constant's value: var in (set! var 1) - - ; (set! var 1) - - ; ((/ 1.0 0.0)) + immutable-error - ; ((/ 1.0 0.0)) - - \; + can't set! var (it is immutable) @@ -867,22 +878,10 @@ <|unfolded-io> (let ((var 1)) var) <|unfolded-io> - wrong-type-arg - <\errput> - \; - - ;let: can't bind an immutable object: ((var 1)) - - ; (let ((var 1)) var) - - ; (set! var 1) - - ; ((/ 1.0 0.0)) - - ; ((/ 1.0 0.0)) + wrong-type-arg - \; + let: can't bind an immutable object: ((var 1)) diff --git a/TeXmacs/plugins/s7/packages/code/s7.ts b/TeXmacs/plugins/s7/packages/code/s7.ts index 2a69b253ee..89aeb192f5 100644 --- a/TeXmacs/plugins/s7/packages/code/s7.ts +++ b/TeXmacs/plugins/s7/packages/code/s7.ts @@ -39,6 +39,15 @@ |> > + + \; + + + + + > + > diff --git a/TeXmacs/plugins/s7/progs/init-s7.scm b/TeXmacs/plugins/s7/progs/init-s7.scm index 5807ff1979..1b31bb2061 100644 --- a/TeXmacs/plugins/s7/progs/init-s7.scm +++ b/TeXmacs/plugins/s7/progs/init-s7.scm @@ -20,7 +20,8 @@ (string-append s "\n\n"))) (define (s7-launcher) - "tm_s7") + (string-append "tm_s7" " " (url->system (get-texmacs-path)) + "/plugins/s7/s7/tm-s7.scm")) (plugin-configure s7 (:require (url-exists-in-path? "tm_s7")) diff --git a/TeXmacs/plugins/s7/s7/texmacs/protocol.scm b/TeXmacs/plugins/s7/s7/texmacs/protocol.scm new file mode 100644 index 0000000000..4161291606 --- /dev/null +++ b/TeXmacs/plugins/s7/s7/texmacs/protocol.scm @@ -0,0 +1,47 @@ +; +; Copyright (C) 2024 The S7 SRFI Authors +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +; License for the specific language governing permissions and limitations +; under the License. +; + +(define-library (texmacs protocol) +(export data-begin data-end data-escape + flush-verbatim flush-prompt flush-scheme) +(begin + +(define (data-begin) + (display (integer->char 2))) + +(define (data-end) + (display (integer->char 5)) + (flush-output-port)) + +(define (data-escape) + (write (integer->char 27))) + +(define (flush-any msg) + (data-begin) + (display msg) + (data-end)) + +(define (flush-verbatim msg) + (flush-any (append "verbatim:" msg))) + +(define (flush-scheme msg) + (flush-any (append "scheme:" msg))) + +(define (flush-prompt msg) + (flush-any (append "prompt#" msg))) + +) ; end of begin +) ; end of define-library \ No newline at end of file diff --git a/TeXmacs/plugins/s7/s7/tm-s7.scm b/TeXmacs/plugins/s7/s7/tm-s7.scm new file mode 100644 index 0000000000..676b9c804e --- /dev/null +++ b/TeXmacs/plugins/s7/s7/tm-s7.scm @@ -0,0 +1,111 @@ +; +; Copyright (C) 2024 The S7 SRFI Authors +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +; License for the specific language governing permissions and limitations +; under the License. +; + +(set! *load-path* + (cons (append (getenv "TEXMACS_PATH") "/plugins/s7/s7") + *load-path*)) + +(import (texmacs protocol)) + + +(define (s7-welcome) + (flush-prompt "> ") + (flush-verbatim + (append "S7 Scheme: " (substring (*s7* 'version) 3)))) + +(define (s7-repl) + ; SRFI 1 + (define (find pred l) + (cond ((null? l) #f) + ((pred (car l)) (car l)) + (else (find pred (cdr l))))) + + ; SRFI 13 + (define (string-join l) + (cond ((null? l) "") + ((= (length l) 1) (car l)) + (else + (append + (car l) + (string-join (cdr l)))))) + + (define (string-prefix? prefix str) + (let* ((prefix-len (length prefix)) + (str-len (length str))) + (and (<= prefix-len str-len) + (let loop ((i 0)) + (or (= i prefix-len) + (and (char=? (string-ref prefix i) + (string-ref str i)) + (loop (+ i 1)))))))) + + (define (s7-read-code) + (define (read-code code) + (let ((line (read-line))) + (if (string=? line "\n") + code + (read-code (append code line))))) + + (read-code "")) + + (define (escape-string str) + (string-join + (map (lambda (char) + (if (char=? char #\") + (string #\\ #\") + (if (char=? char #\\) + (string #\\ #\\) + (string char)))) + (string->list str)))) + + (define (s7-quote s) + (append "\"" (escape-string s) "\"")) + + (define (build-s7-result obj) + (let ((output (object->string obj)) + (leadings (list "(document" "(math" "(equation*" "(align" "(with" "(graphics"))) + (if (find (lambda (x) (string-prefix? x output)) leadings) + output + (append "(s7-result " (s7-quote output) ")")))) + + (define (s7-print obj) + (if (eq? obj #) + (flush-scheme "") + (flush-scheme (build-s7-result obj)))) + + (define (eval-and-print code) + (catch #t + (lambda () + (s7-print (eval-string code (rootlet)))) + (lambda args + (begin + (flush-scheme + (append "(errput (document " + (s7-quote (symbol->string (car args))) + (s7-quote (apply format #f (cadr args))) + "))")))))) + + (define (read-eval-print) + (let ((code (s7-read-code))) + (if (string=? code "") + #t + (eval-and-print code)))) + + (begin (read-eval-print) + (s7-repl))) + +(s7-welcome) +(s7-repl) diff --git a/TeXmacs/plugins/s7/src/tm_s7.cpp b/TeXmacs/plugins/s7/src/s7.c similarity index 62% rename from TeXmacs/plugins/s7/src/tm_s7.cpp rename to TeXmacs/plugins/s7/src/s7.c index 7de855362a..7723bc6211 100644 --- a/TeXmacs/plugins/s7/src/tm_s7.cpp +++ b/TeXmacs/plugins/s7/src/s7.c @@ -1,19 +1,18 @@ /* 0-clause BSD */ -/* Adapted from repl.c in the s7 official repo */ +/* gcc -o repl repl.c s7.o -Wl,-export-dynamic -lm -I. -ldl */ -#include -#include -#include -#include - -using std::cout; -using std::flush; -using std::string; +#include +#include +#include +#ifndef _MSC_VER +#include +#include +#endif #include "s7.h" -string str_r7rs_define_library= +char* str_r7rs_define_library= "(define-macro (define-library libname . body) ; |(lib name)| -> " "environment\n" " `(define ,(symbol (object->string libname))\n" @@ -33,7 +32,7 @@ string str_r7rs_define_library= " (values)\n" " entry))\n" " (curlet))))))\n"; -string str_r7rs_library_filename= +char* str_r7rs_library_filename= "(unless (defined? 'r7rs-import-library-filename)\n" " (define (r7rs-import-library-filename libs)\n" " (when (pair? libs)\n" @@ -52,7 +51,7 @@ string str_r7rs_library_filename= " (unless (member lib-filename (*s7* 'file-names))\n" " (load lib-filename)))\n" " (r7rs-import-library-filename (cdr libs)))))\n"; -string str_r7rs_import= +char* str_r7rs_import= "(define-macro (import . libs)\n" " `(begin\n" " (r7rs-import-library-filename ',libs)\n" @@ -114,121 +113,31 @@ string str_r7rs_import= " (symbol->value sym))))))\n" " libs))))\n"; -#define DATA_BEGIN ((char) 2) -#define DATA_END ((char) 5) -#define DATA_ESCAPE ((char) 27) - -void -data_begin () { - cout << DATA_BEGIN; -} - -void -data_end () { - cout << DATA_END << flush; -} - -void -flush_scheme (string msg) { - data_begin (); - cout << "scheme:" << msg; - data_end (); -} - -void -flush_verbatim (string msg) { - data_begin (); - cout << "verbatim:" << msg; - data_end (); -} - -void -flush_prompt (string prompt) { - data_begin (); - cout << "prompt#" << prompt; - data_end (); -} - -string -getBeforeSpace (const string& str) { - size_t pos= str.find (' '); - if (pos == string::npos) { - return str; - } - return str.substr (0, pos); -} - -std::string::size_type -findBegin (const std::string& s) { - std::string::size_type pos= s.find_first_not_of (" \t\n\r\f\v"); - return (pos == std::string::npos) ? s.length () : pos; -} - -std::string::size_type -findEnd (const std::string& s) { - std::string::size_type pos= s.find_last_not_of (" \t\n\r\f\v"); - return (pos == std::string::npos) ? 0 : pos + 1; -} - -std::string -trim (const std::string& s) { - std::string::size_type left = findBegin (s); - std::string::size_type right= findEnd (s); - return s.substr (left, right - left); -} - int main (int argc, char** argv) { - std::unordered_set scheme_headers= { - "(document", "(math", "(equation*", "(align", "(with", "(graphics"}; - - std::stringstream welcome; - welcome << "S7 Scheme " << S7_VERSION << " (" << S7_DATE << ")\n"; - flush_verbatim (welcome.str ()); - flush_prompt ("> "); - - const char* env_key = "TEXMACS_PATH"; - const char* env_value= getenv (env_key); - std::stringstream load_path; - load_path << env_value << "/plugins/s7/s7"; - s7_scheme* sc; - sc= s7_init (); - s7_eval_c_string (sc, str_r7rs_define_library.c_str ()); - s7_eval_c_string (sc, str_r7rs_library_filename.c_str ()); - s7_eval_c_string (sc, str_r7rs_import.c_str ()); - s7_add_to_load_path (sc, load_path.str ().c_str ()); - - while (true) { - string first_line; - std::getline (std::cin, first_line); - std::vector lines; - lines.push_back (first_line); - std::stringstream ss; - string line= first_line; - while (line != "") { - ss << line << "\n"; - line= ""; - std::getline (std::cin, line); + sc= s7_init (); + s7_eval_c_string (sc, str_r7rs_define_library); + s7_eval_c_string (sc, str_r7rs_library_filename); + s7_eval_c_string (sc, str_r7rs_import); + if (argc >= 2) { + if (strcmp (argv[1], "-e") == 0) /* repl -e '(+ 1 2)' */ + { + s7_pointer x; + x= s7_eval_c_string (sc, argv[2]); + fprintf (stdout, "%s\n", s7_object_to_c_string (sc, x)); + return (0); } - s7_pointer x = s7_eval_c_string (sc, ss.str ().c_str ()); - string result= s7_object_to_c_string (sc, x); - if (result.size () == 0) { - flush_verbatim (""); + if (strcmp (argv[1], "--version") == 0) { + fprintf (stdout, "s7: %s, %s\n", S7_VERSION, S7_DATE); + return (0); } - else { - string trimmed= trim (result); - string head = getBeforeSpace (trimmed); - if (trimmed[trimmed.size () - 1] == ')' && - scheme_headers.find (head) != scheme_headers.end ()) { - flush_scheme (trimmed); - } - else { - flush_verbatim (result); - } + errno= 0; + if (!s7_load (sc, argv[1])) { + fprintf (stderr, "%s: %s\n", strerror (errno), argv[1]); + return (2); } } - - return 0; + return (0); } diff --git a/TeXmacs/tests/tmu/61_7.tmu b/TeXmacs/tests/tmu/61_7.tmu new file mode 100644 index 0000000000..218f661be0 --- /dev/null +++ b/TeXmacs/tests/tmu/61_7.tmu @@ -0,0 +1,100 @@ +> + +> + +<\body> + <\session|s7|default> + <\output> + S7 Scheme: 10.11, 2-July-2024 + + + <\unfolded-io> + \\ + <|unfolded-io> + #t + <|unfolded-io> + + + + <\unfolded-io> + \\ + <|unfolded-io> + #f + <|unfolded-io> + + + + <\unfolded-io> + \\ + <|unfolded-io> + 1 + <|unfolded-io> + + + + <\unfolded-io> + \\ + <|unfolded-io> + 1.2 + <|unfolded-io> + + + + <\unfolded-io> + \\ + <|unfolded-io> + "abc" + <|unfolded-io> + + + + <\unfolded-io> + \\ + <|unfolded-io> + #\\a + <|unfolded-io> + + + + <\unfolded-io> + \\ + <|unfolded-io> + (list 1 2 3) + <|unfolded-io> + + + + <\unfolded-io> + \\ + <|unfolded-io> + (list "A" "a") + <|unfolded-io> + + + + <\unfolded-io> + \\ + <|unfolded-io> + (string-join (list "a" "bc")) + <|unfolded-io> + <\errput> + unbound-variable + + unbound variable string-join in (string-join (list "a" "bc")) + + + + <\input> + \\ + <|input> + \; + + + + +<\initial> + <\collection> + + + + \ No newline at end of file diff --git a/bin/format b/bin/format index 716c6b4e41..9e9d6f94db 100755 --- a/bin/format +++ b/bin/format @@ -22,5 +22,5 @@ clang-format -i tests/**/*.cpp clang-format -i tests/**/*.hpp clang-format -i src/**/*.cpp clang-format -i src/**/*.hpp -clang-format -i TeXmacs/plugins/**/*.cpp +clang-format -i TeXmacs/plugins/**/*.c diff --git a/xmake/tm_s7.lua b/xmake/tm_s7.lua index 81aab83027..0a5f14d036 100644 --- a/xmake/tm_s7.lua +++ b/xmake/tm_s7.lua @@ -11,7 +11,7 @@ target ("tm_s7") do set_languages("c++17") set_targetdir("$(projectdir)/TeXmacs/plugins/s7/bin/") - add_files ("$(projectdir)/TeXmacs/plugins/s7/src/tm_s7.cpp") + add_files ("$(projectdir)/TeXmacs/plugins/s7/src/s7.c") add_packages("s7") on_install(function (target) end)