Compare commits
3 Commits
a64caec5f8
...
a80b8d9acf
| Author | SHA1 | Date | |
|---|---|---|---|
| a80b8d9acf | |||
| d039fa0cb9 | |||
| 559ed9c7fa |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,4 @@
|
|||||||
*.o
|
*.o
|
||||||
*.import.scm
|
*.import.scm
|
||||||
*.link
|
|
||||||
sexc
|
sexc
|
||||||
sex-tests
|
sex-tests
|
||||||
|
|||||||
75
Makefile
75
Makefile
@@ -1,60 +1,53 @@
|
|||||||
CHICKEN_C = csc
|
CHICKEN_C = csc
|
||||||
CSC_FLAGS += -K prefix -static
|
CSC_FLAGS += -K prefix
|
||||||
# What and why:
|
|
||||||
# -emit-all-import-libraries: Emit import-libraries for all defined modules.
|
|
||||||
# Used to generate .import.scm files so compiler would know how to use the modules.
|
|
||||||
# Without it, csc fails with "cannot import from undefined module" error.
|
|
||||||
# -module-registration: Always generate module registration code, even when
|
|
||||||
# import libraries are emitted. Enables us to import from our modules at run time.
|
|
||||||
# Used in macros, where we inject `(import (only sex-macros cat))' before the macro body.
|
|
||||||
# Without it, sexc compiles scuccessfully, but is unable to process macros, failing with
|
|
||||||
# "during expansion of (import ...) - cannot import from undefined module: sex-macros"
|
|
||||||
# error.
|
|
||||||
# -c: Stop after compilation to object files. This one is obvious.
|
|
||||||
|
|
||||||
MODULE_FLAGS = -emit-all-import-libraries -module-registration -c
|
|
||||||
|
|
||||||
# Order matters, since module check correctness on compilation
|
# Order matters, since module check correctness on compilation
|
||||||
MODULES = utils sex-macros reader sex-modules semen sex-fmt-c fmt-c-writer sexc
|
MODULES = utils macros reader module-system semen sex-fmt-c fmt-c-writer sexc
|
||||||
OBJ = $(MODULES:%=%.o)
|
OBJ = $(MODULES:%=%.o)
|
||||||
|
IMPORTS = $(MODULES:%=%.import.scm)
|
||||||
|
LINK = $(MODULES:%=%.link)
|
||||||
|
|
||||||
sexc: $(OBJ) main.scm
|
sexc: $(OBJ) main.o
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) main.scm -o sexc-tmp -link sexc
|
$(CHICKEN_C) $(CSC_FLAGS) $^ -o $@
|
||||||
# otherwise csc hangs, probably because it tries to compile to sexc.o first
|
|
||||||
mv sexc-tmp sexc
|
main.o: main.scm
|
||||||
|
$(CHICKEN_C) $(CSC_FLAGS) $< -c -o $@ -link sexc
|
||||||
|
|
||||||
#------------------------------------------------------------------
|
#------------------------------------------------------------------
|
||||||
|
|
||||||
utils.o: utils.module.scm utils.scm
|
utils.o: utils.scm
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) utils.module.scm -o utils.o -unit utils
|
$(CHICKEN_C) $(CSC_FLAGS) utils.scm -e -c -J -o utils.o -unit utils
|
||||||
|
|
||||||
sex-macros.o: sex-macros.module.scm sex-macros.scm
|
macros.o: macros.scm
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-macros.module.scm -o sex-macros.o -unit sex-macros
|
$(CHICKEN_C) $(CSC_FLAGS) macros.scm -e -c -J -o macros.o -unit macros
|
||||||
|
|
||||||
reader.o: reader.module.scm reader.scm
|
reader.o:
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) reader.module.scm -o reader.o -unit reader
|
$(CHICKEN_C) $(CSC_FLAGS) reader.scm -e -c -J -o reader.o -unit reader
|
||||||
|
|
||||||
sex-modules.o: sex-modules.module.scm sex-modules.scm reader.o utils.o
|
module-system.o: module-system.scm reader.import.scm utils.import.scm
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-modules.module.scm -o sex-modules.o -unit sex-modules -link reader,utils
|
$(CHICKEN_C) $(CSC_FLAGS) module-system.scm -e -c -J -o module-system.o -unit module-system -link reader,utils
|
||||||
|
|
||||||
semen.o: semen.module.scm semen.scm sex-macros.o sex-modules.o utils.o
|
semen.o: semen.scm macros.import.scm module-system.import.scm utils.import.scm
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) semen.module.scm -o semen.o -unit semen -link sex-macros,sex-modules,utils
|
$(CHICKEN_C) $(CSC_FLAGS) semen.scm -e -c -J -o semen.o -unit semen -link macros,module-system,utils
|
||||||
|
|
||||||
sex-fmt-c.o: sex-fmt-c.scm
|
fmt-c-writer.o: fmt-c-writer.scm sex-fmt-c.import.scm utils.import.scm
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-fmt-c.scm -o sex-fmt-c.o -unit sex-fmt-c
|
$(CHICKEN_C) $(CSC_FLAGS) fmt-c-writer.scm -e -c -J -o fmt-c-writer.o -unit fmt-c-writer -link sex-fmt-c,utils
|
||||||
|
|
||||||
fmt-c-writer.o: fmt-c-writer.module.scm fmt-c-writer.scm sex-fmt-c.o utils.o
|
sexc.o: sexc.scm fmt-c-writer.import.scm macros.import.scm module-system.import.scm reader.import.scm semen.import.scm utils.import.scm
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) fmt-c-writer.module.scm -o fmt-c-writer.o -unit fmt-c-writer -link sex-fmt-c,utils
|
$(CHICKEN_C) $(CSC_FLAGS) sexc.scm -e -c -J -o sexc.o -unit sexc -link fmt-c-writer,macros,module-system,reader,semen,utils
|
||||||
|
|
||||||
sexc.o: sexc.module.scm sexc.scm fmt-c-writer.o sex-macros.o sex-modules.o reader.o semen.o utils.o
|
%.link: %.o
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sexc.module.scm -o sexc.o -unit sexc -link fmt-c-writer,sex-macros,sex-modules,reader,semen,utils
|
%.import.scm: %.o
|
||||||
|
%.o: %.scm
|
||||||
|
$(CHICKEN_C) $(CSC_FLAGS) $< -e -c -J -o $@ -unit $(@:%.o=%)
|
||||||
|
|
||||||
sex-tests:
|
|
||||||
$(MAKE) -C tests sex-tests
|
sex-tests: $(OBJ) tests/*.scm
|
||||||
cp ./tests/sex-tests ./
|
cd ./tests && $(CHICKEN_C) $(CSC_FLAGS) run.scm -c -o sex-tests.o
|
||||||
|
$(CHICKEN_C) $(CSC_FLAGS) $(OBJ) ./tests/sex-tests.o -o sex-tests
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJ) main.o
|
rm -f $(OBJ) main.o ./tests/sex-tests.o
|
||||||
rm -f *.import.scm
|
rm -f $(IMPORTS)
|
||||||
rm -f *.link
|
rm -f $(LINK) main.link
|
||||||
rm -f sexc sex-tests
|
rm -f sexc sex-tests
|
||||||
|
|||||||
2
example/mini-test.sex
Normal file
2
example/mini-test.sex
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
(pub fn main () int
|
||||||
|
(var l (* (struct list-int)) (make-list-int)))
|
||||||
25
example/our-reader.sex
Normal file
25
example/our-reader.sex
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
(include stdio.h)
|
||||||
|
|
||||||
|
(defmacro (plus . rest)
|
||||||
|
`(+ ,@rest))
|
||||||
|
|
||||||
|
(struct vertex
|
||||||
|
((pos (struct ((x u32) (y u32))))
|
||||||
|
(color (struct ((r float) (g float) (b float))))
|
||||||
|
(mask u32)))
|
||||||
|
|
||||||
|
(enum
|
||||||
|
(B A R))
|
||||||
|
|
||||||
|
;;; Main entry point
|
||||||
|
;;; Multi line comments should be packed
|
||||||
|
(pub fn main () int
|
||||||
|
;; the vertex
|
||||||
|
(var a (struct vertex) #(#(10 20)
|
||||||
|
#(0.3 0.5 0.7)
|
||||||
|
(c-bit-or B A R)))
|
||||||
|
(printf "%d %f %d\n" ; the printf
|
||||||
|
(plus a.pos.x a.pos.y)
|
||||||
|
(plus a.color.r a.color.g a.color.b)
|
||||||
|
a.mask)
|
||||||
|
(return 0))
|
||||||
6
example/structs.sex
Normal file
6
example/structs.sex
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
(struct settings
|
||||||
|
((b-x u32)
|
||||||
|
(l r t b x y w h u32)
|
||||||
|
(color (struct
|
||||||
|
((r g b a float))))
|
||||||
|
(colors [struct color ((r g b a float))])))
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module fmt-c-writer (emit-c
|
|
||||||
sex-fmt-current-file)
|
|
||||||
"fmt-c-writer.scm")
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
;;; Sex fmt-c output writer
|
;;; Sex fmt-c output writer
|
||||||
|
|
||||||
|
(module fmt-c-writer (emit-c
|
||||||
|
sex-fmt-current-file)
|
||||||
(import
|
(import
|
||||||
scheme
|
scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
@@ -280,4 +282,4 @@
|
|||||||
(sex-fmt-line-num start-line)
|
(sex-fmt-line-num start-line)
|
||||||
(fmt #t (line-directive-string) nl)))
|
(fmt #t (line-directive-string) nl)))
|
||||||
(fmt #t (c-expr (process-toplevel-form form)) nl))
|
(fmt #t (c-expr (process-toplevel-form form)) nl))
|
||||||
sex-forms))
|
sex-forms)))
|
||||||
|
|||||||
45
macros.scm
Normal file
45
macros.scm
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
(module macros
|
||||||
|
(register-macro
|
||||||
|
cat
|
||||||
|
get-macro
|
||||||
|
macro?
|
||||||
|
apply-macro
|
||||||
|
defmacro)
|
||||||
|
(import
|
||||||
|
scheme
|
||||||
|
(only fmt fmt)
|
||||||
|
(chicken base)
|
||||||
|
(chicken plist)
|
||||||
|
(chicken string))
|
||||||
|
|
||||||
|
(define (cat-syms s-1 s-2)
|
||||||
|
(fmt #f s-1 s-2))
|
||||||
|
|
||||||
|
(define (cat sym-1 sym-2)
|
||||||
|
(string->symbol (cat-syms sym-1 sym-2)))
|
||||||
|
|
||||||
|
(define (register-macro name arglist body)
|
||||||
|
(put! name 'sex-macro
|
||||||
|
`(lambda ,arglist
|
||||||
|
(import scheme
|
||||||
|
(only macros cat))
|
||||||
|
,@body)))
|
||||||
|
|
||||||
|
(define (get-macro name)
|
||||||
|
(eval (get name 'sex-macro)))
|
||||||
|
|
||||||
|
(define (macro? form)
|
||||||
|
(and (list? form)
|
||||||
|
(symbol? (car form))
|
||||||
|
(get (car form) 'sex-macro)))
|
||||||
|
|
||||||
|
(define (apply-macro form)
|
||||||
|
(assert (macro? form)
|
||||||
|
(fmt #f (car form) " is not a macro"))
|
||||||
|
(apply (get-macro (car form))
|
||||||
|
(cdr form)))
|
||||||
|
|
||||||
|
(define (defmacro form)
|
||||||
|
(let ((arglist (car form))
|
||||||
|
(body (cdr form)))
|
||||||
|
(register-macro (car arglist) (cdr arglist) body))))
|
||||||
92
module-system.scm
Normal file
92
module-system.scm
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
(module module-system
|
||||||
|
(get-modules-public-forms
|
||||||
|
load-persistent-module-paths
|
||||||
|
read-public-interface)
|
||||||
|
|
||||||
|
(import
|
||||||
|
scheme
|
||||||
|
brev-separate
|
||||||
|
(chicken base)
|
||||||
|
(chicken file)
|
||||||
|
(chicken load)
|
||||||
|
(chicken pathname)
|
||||||
|
(chicken process-context)
|
||||||
|
(chicken string)
|
||||||
|
fmt
|
||||||
|
reader
|
||||||
|
srfi-1
|
||||||
|
utils)
|
||||||
|
|
||||||
|
(define +persistent-module-paths+ (list))
|
||||||
|
|
||||||
|
(define (get-modules-public-forms module-list)
|
||||||
|
;; Module list is a list of symbols
|
||||||
|
;; How Sex handles modules:
|
||||||
|
;; For each module in a list, construct path, find module by path in
|
||||||
|
;; module path directories, extract public definitions from the
|
||||||
|
;; module, paste them in current one in emulation of C include
|
||||||
|
;; directives.
|
||||||
|
(fold-right append (list)
|
||||||
|
(map (fn (import-module (symbol->string x)))
|
||||||
|
module-list)))
|
||||||
|
|
||||||
|
(define (import-module name)
|
||||||
|
(let ((module-path (locate-module name)))
|
||||||
|
(assert module-path (fmt #f "Failed to find module " name " in "
|
||||||
|
(get-module-paths)))
|
||||||
|
(read-public-interface module-path)))
|
||||||
|
|
||||||
|
(define (get-module-paths)
|
||||||
|
(cons (current-directory)
|
||||||
|
+persistent-module-paths+))
|
||||||
|
|
||||||
|
(define (locate-module name)
|
||||||
|
;; Module locations: relative to file being compiled, or in what was
|
||||||
|
;; in SEX_MODULE_PATH env var at the start of the process (see
|
||||||
|
;; load-persistent-module-paths function)
|
||||||
|
|
||||||
|
(let ((search-paths (get-module-paths)))
|
||||||
|
(let loop ((paths search-paths))
|
||||||
|
(if (null? paths)
|
||||||
|
#f
|
||||||
|
(or (module-exists? name (car paths))
|
||||||
|
(loop (cdr paths)))))))
|
||||||
|
|
||||||
|
(define (module-exists? name module-dir)
|
||||||
|
;; returns absolute path to module, if it exists
|
||||||
|
(and (directory-exists? module-dir)
|
||||||
|
(let ((module-path (make-absolute-pathname module-dir name "sex")))
|
||||||
|
(and (file-exists? module-path)
|
||||||
|
(file-readable? module-path)
|
||||||
|
module-path))))
|
||||||
|
|
||||||
|
(define (read-public-interface module-path)
|
||||||
|
;; pub fns are reduced to prototypes, other pub forms are just pasted
|
||||||
|
(let ((raw-forms (read-from-file module-path)))
|
||||||
|
(fold
|
||||||
|
process-public-interface-form
|
||||||
|
(list)
|
||||||
|
raw-forms)))
|
||||||
|
|
||||||
|
;;; TODO: use semen facilities to analyze modules
|
||||||
|
(define (process-public-interface-form form acc)
|
||||||
|
(case (car form)
|
||||||
|
((pub)
|
||||||
|
(case (cadr form)
|
||||||
|
((fn) ; replace with prototype
|
||||||
|
;; fn type name (arg-list) (body)
|
||||||
|
;; 1 2 3 4 - we need first 4
|
||||||
|
(cons (take (cdr form) 4) acc))
|
||||||
|
((define defmacro import include struct typedef union var)
|
||||||
|
(cons (cdr form) acc))
|
||||||
|
(else (error "Pub what? " (cadr form)))))
|
||||||
|
(else acc)))
|
||||||
|
|
||||||
|
(define (load-persistent-module-paths)
|
||||||
|
(let ((sex-module-path-env-var
|
||||||
|
(get-env-var "SEX_MODULE_PATH")))
|
||||||
|
(when sex-module-path-env-var
|
||||||
|
(set! +persistent-module-paths+
|
||||||
|
(map (lambda (p)
|
||||||
|
(make-absolute-pathname p #f #f))
|
||||||
|
(string-split sex-module-path-env-var ":")))))))
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module reader (read-from-file
|
|
||||||
read-raw-forms)
|
|
||||||
"reader.scm")
|
|
||||||
17
reader.scm
17
reader.scm
@@ -1,3 +1,5 @@
|
|||||||
|
(module reader (read-from-file
|
||||||
|
read-raw-forms)
|
||||||
(import
|
(import
|
||||||
scheme
|
scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
@@ -22,6 +24,19 @@
|
|||||||
(with-input-from-file (pathname-strip-directory file)
|
(with-input-from-file (pathname-strip-directory file)
|
||||||
(fn (read-forms (list))))))
|
(fn (read-forms (list))))))
|
||||||
|
|
||||||
|
(define (read-bracket port)
|
||||||
|
(let loop ((c (read-char port))
|
||||||
|
(str (string)))
|
||||||
|
(cond ((char=? c #\])
|
||||||
|
(cons '¤
|
||||||
|
(with-input-from-string str
|
||||||
|
(fn (port-map identity read)))))
|
||||||
|
((char=? c #\[)
|
||||||
|
(loop port (conc )))
|
||||||
|
(else
|
||||||
|
(loop (read-char port)
|
||||||
|
(conc str c))))))
|
||||||
|
|
||||||
(define open-bracket-counter (make-parameter 0))
|
(define open-bracket-counter (make-parameter 0))
|
||||||
|
|
||||||
(define (read-raw-forms input-source)
|
(define (read-raw-forms input-source)
|
||||||
@@ -46,4 +61,4 @@
|
|||||||
(cons r acc)))))))
|
(cons r acc)))))))
|
||||||
(if (eq? input-source 'stdin)
|
(if (eq? input-source 'stdin)
|
||||||
(read-forms (list))
|
(read-forms (list))
|
||||||
(read-from-file input-source)))
|
(read-from-file input-source))))
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
(module semen ()
|
|
||||||
"semen.scm")
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
;;; Sex semantic engine
|
;;; Sex semantic engine
|
||||||
|
|
||||||
|
(module semen ()
|
||||||
(import
|
(import
|
||||||
scheme
|
scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
@@ -7,9 +8,9 @@
|
|||||||
(chicken string)
|
(chicken string)
|
||||||
(chicken module)
|
(chicken module)
|
||||||
fmt
|
fmt
|
||||||
sex-macros
|
macros
|
||||||
sex-modules
|
|
||||||
matchable ; pattern matching
|
matchable ; pattern matching
|
||||||
|
module-system
|
||||||
srfi-1 ; list routines
|
srfi-1 ; list routines
|
||||||
srfi-69 ; hash tables
|
srfi-69 ; hash tables
|
||||||
utils
|
utils
|
||||||
@@ -237,3 +238,4 @@ Returns #f if the form is not a function, returns the form otherwise"
|
|||||||
(if (sex-fn-public? fn-form)
|
(if (sex-fn-public? fn-form)
|
||||||
(drop fn-form 5)
|
(drop fn-form 5)
|
||||||
(drop fn-form 4)))
|
(drop fn-form 4)))
|
||||||
|
)
|
||||||
|
|||||||
@@ -105,6 +105,7 @@
|
|||||||
|
|
||||||
(define (c-op< x y) (< (c-op-precedence x) (c-op-precedence y)))
|
(define (c-op< x y) (< (c-op-precedence x) (c-op-precedence y)))
|
||||||
(define (c-op<= x y) (<= (c-op-precedence x) (c-op-precedence y)))
|
(define (c-op<= x y) (<= (c-op-precedence x) (c-op-precedence y)))
|
||||||
|
(define (c-op>= x y) (>= (c-op-precedence x) (c-op-precedence y)))
|
||||||
|
|
||||||
(define (c-paren x) (cat "(" (c-expr x) ")"))
|
(define (c-paren x) (cat "(" (c-expr x) ")"))
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
(module sex-macros
|
|
||||||
(register-macro
|
|
||||||
cat
|
|
||||||
get-macro
|
|
||||||
macro?
|
|
||||||
apply-macro
|
|
||||||
defmacro)
|
|
||||||
"sex-macros.scm")
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
(import
|
|
||||||
scheme
|
|
||||||
(only fmt fmt)
|
|
||||||
(chicken base)
|
|
||||||
(chicken plist)
|
|
||||||
(chicken string))
|
|
||||||
|
|
||||||
(define (cat-syms s-1 s-2)
|
|
||||||
(fmt #f s-1 s-2))
|
|
||||||
|
|
||||||
(define (cat sym-1 sym-2)
|
|
||||||
(string->symbol (cat-syms sym-1 sym-2)))
|
|
||||||
|
|
||||||
(define (register-macro name arglist body)
|
|
||||||
(put! name 'sex-macro
|
|
||||||
`(lambda ,arglist
|
|
||||||
(import scheme
|
|
||||||
(only sex-macros cat))
|
|
||||||
,@body)))
|
|
||||||
|
|
||||||
(define (get-macro name)
|
|
||||||
(eval (get name 'sex-macro)))
|
|
||||||
|
|
||||||
(define (macro? form)
|
|
||||||
(and (list? form)
|
|
||||||
(symbol? (car form))
|
|
||||||
(get (car form) 'sex-macro)))
|
|
||||||
|
|
||||||
(define (apply-macro form)
|
|
||||||
(assert (macro? form)
|
|
||||||
(fmt #f (car form) " is not a macro"))
|
|
||||||
(apply (get-macro (car form))
|
|
||||||
(cdr form)))
|
|
||||||
|
|
||||||
(define (defmacro form)
|
|
||||||
(let ((arglist (car form))
|
|
||||||
(body (cdr form)))
|
|
||||||
(register-macro (car arglist) (cdr arglist) body)))
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
(module sex-modules
|
|
||||||
(get-modules-public-forms
|
|
||||||
load-persistent-module-paths
|
|
||||||
read-public-interface)
|
|
||||||
"sex-modules.scm")
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
(import
|
|
||||||
scheme
|
|
||||||
brev-separate
|
|
||||||
(chicken base)
|
|
||||||
(chicken file)
|
|
||||||
(chicken load)
|
|
||||||
(chicken pathname)
|
|
||||||
(chicken process-context)
|
|
||||||
(chicken string)
|
|
||||||
fmt
|
|
||||||
reader
|
|
||||||
srfi-1
|
|
||||||
utils)
|
|
||||||
|
|
||||||
(define +persistent-module-paths+ (list))
|
|
||||||
|
|
||||||
(define (get-modules-public-forms module-list)
|
|
||||||
;; Module list is a list of symbols
|
|
||||||
;; How Sex handles modules:
|
|
||||||
;; For each module in a list, construct path, find module by path in
|
|
||||||
;; module path directories, extract public definitions from the
|
|
||||||
;; module, paste them in current one in emulation of C include
|
|
||||||
;; directives.
|
|
||||||
(fold-right append (list)
|
|
||||||
(map (fn (import-module (symbol->string x)))
|
|
||||||
module-list)))
|
|
||||||
|
|
||||||
(define (import-module name)
|
|
||||||
(let ((module-path (locate-module name)))
|
|
||||||
(assert module-path (fmt #f "Failed to find module " name " in "
|
|
||||||
(get-module-paths)))
|
|
||||||
(read-public-interface module-path)))
|
|
||||||
|
|
||||||
(define (get-module-paths)
|
|
||||||
(cons (current-directory)
|
|
||||||
+persistent-module-paths+))
|
|
||||||
|
|
||||||
(define (locate-module name)
|
|
||||||
;; Module locations: relative to file being compiled, or in what was
|
|
||||||
;; in SEX_MODULE_PATH env var at the start of the process (see
|
|
||||||
;; load-persistent-module-paths function)
|
|
||||||
|
|
||||||
(let ((search-paths (get-module-paths)))
|
|
||||||
(let loop ((paths search-paths))
|
|
||||||
(if (null? paths)
|
|
||||||
#f
|
|
||||||
(or (module-exists? name (car paths))
|
|
||||||
(loop (cdr paths)))))))
|
|
||||||
|
|
||||||
(define (module-exists? name module-dir)
|
|
||||||
;; returns absolute path to module, if it exists
|
|
||||||
(and (directory-exists? module-dir)
|
|
||||||
(let ((module-path (make-absolute-pathname module-dir name "sex")))
|
|
||||||
(and (file-exists? module-path)
|
|
||||||
(file-readable? module-path)
|
|
||||||
module-path))))
|
|
||||||
|
|
||||||
(define (read-public-interface module-path)
|
|
||||||
;; pub fns are reduced to prototypes, other pub forms are just pasted
|
|
||||||
(let ((raw-forms (read-from-file module-path)))
|
|
||||||
(fold
|
|
||||||
process-public-interface-form
|
|
||||||
(list)
|
|
||||||
raw-forms)))
|
|
||||||
|
|
||||||
;;; TODO: use semen facilities to analyze modules
|
|
||||||
(define (process-public-interface-form form acc)
|
|
||||||
(case (car form)
|
|
||||||
((pub)
|
|
||||||
(case (cadr form)
|
|
||||||
((fn) ; replace with prototype
|
|
||||||
;; fn type name (arg-list) (body)
|
|
||||||
;; 1 2 3 4 - we need first 4
|
|
||||||
(cons (take (cdr form) 4) acc))
|
|
||||||
((define defmacro import include struct typedef union var)
|
|
||||||
(cons (cdr form) acc))
|
|
||||||
(else (error "Pub what? " (cadr form)))))
|
|
||||||
(else acc)))
|
|
||||||
|
|
||||||
(define (load-persistent-module-paths)
|
|
||||||
(let ((sex-module-path-env-var
|
|
||||||
(get-env-var "SEX_MODULE_PATH")))
|
|
||||||
(when sex-module-path-env-var
|
|
||||||
(set! +persistent-module-paths+
|
|
||||||
(map (lambda (p)
|
|
||||||
(make-absolute-pathname p #f #f))
|
|
||||||
(string-split sex-module-path-env-var ":"))))))
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
(module sexc (main) "sexc.scm")
|
|
||||||
11
sexc.scm
11
sexc.scm
@@ -1,3 +1,4 @@
|
|||||||
|
(module sexc (main)
|
||||||
(import scheme
|
(import scheme
|
||||||
brev-separate
|
brev-separate
|
||||||
(chicken base)
|
(chicken base)
|
||||||
@@ -10,8 +11,8 @@
|
|||||||
fmt
|
fmt
|
||||||
fmt-c-writer
|
fmt-c-writer
|
||||||
getopt-long
|
getopt-long
|
||||||
sex-macros
|
macros
|
||||||
sex-modules
|
module-system
|
||||||
reader
|
reader
|
||||||
semen
|
semen
|
||||||
srfi-1 ; list routines
|
srfi-1 ; list routines
|
||||||
@@ -155,9 +156,7 @@
|
|||||||
(return #f))
|
(return #f))
|
||||||
(load-persistent-module-paths)
|
(load-persistent-module-paths)
|
||||||
|
|
||||||
(if (eq? input 'stdin)
|
(sex-fmt-current-file (to-absolute-pathname input))
|
||||||
(sex-fmt-current-file "stdin")
|
|
||||||
(sex-fmt-current-file (to-absolute-pathname input)))
|
|
||||||
(let* ((raw-forms (append prelude (read-raw-forms input)))
|
(let* ((raw-forms (append prelude (read-raw-forms input)))
|
||||||
(sex-forms (semantic-process-forms raw-forms input)))
|
(sex-forms (semantic-process-forms raw-forms input)))
|
||||||
(if (or (get-arg args 'macro-expand #f)
|
(if (or (get-arg args 'macro-expand #f)
|
||||||
@@ -165,4 +164,4 @@
|
|||||||
;; Emit processed and macro-expanded sex code, or emit C code
|
;; Emit processed and macro-expanded sex code, or emit C code
|
||||||
(emit-c-or-sex sex-forms output args)
|
(emit-c-or-sex sex-forms output args)
|
||||||
;; Compile file!
|
;; Compile file!
|
||||||
(compile-to-file sex-forms output args)))))))
|
(compile-to-file sex-forms output args))))))))
|
||||||
|
|||||||
@@ -1,45 +1 @@
|
|||||||
CHICKEN_C = csc
|
|
||||||
|
|
||||||
CSC_FLAGS += -K prefix -static
|
|
||||||
MODULE_FLAGS = -emit-all-import-libraries -module-registration -c
|
|
||||||
|
|
||||||
MODULES = utils sex-macros reader sex-modules semen sex-fmt-c fmt-c-writer sexc
|
|
||||||
SEX_OBJ = $(MODULES:%=%.o)
|
|
||||||
|
|
||||||
TESTS = basic semen reader fmt-c-writer utils
|
|
||||||
TEST_SRCS = $(TESTS:%=%.scm)
|
|
||||||
|
|
||||||
sex-tests: run.scm $(TEST_SRCS) $(SEX_OBJ)
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) run.scm -o sex-tests -link sexc
|
|
||||||
|
|
||||||
#------------------------------------------------------------------
|
|
||||||
|
|
||||||
utils.o: utils.module.scm ../utils.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) utils.module.scm -o utils.o -unit utils
|
|
||||||
|
|
||||||
sex-macros.o: sex-macros.module.scm ../sex-macros.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-macros.module.scm -o sex-macros.o -unit sex-macros
|
|
||||||
|
|
||||||
reader.o: reader.module.scm ../reader.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) reader.module.scm -o reader.o -unit reader
|
|
||||||
|
|
||||||
sex-modules.o: sex-modules.module.scm ../sex-modules.scm reader.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sex-modules.module.scm -o sex-modules.o -unit sex-modules -link reader,utils
|
|
||||||
|
|
||||||
semen.o: semen.module.scm ../semen.scm sex-macros.o sex-modules.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) semen.module.scm -o semen.o -unit semen -link sex-macros,sex-modules,utils
|
|
||||||
|
|
||||||
sex-fmt-c.o: ../sex-fmt-c.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) ../sex-fmt-c.scm -o sex-fmt-c.o -unit sex-fmt-c
|
|
||||||
|
|
||||||
fmt-c-writer.o: fmt-c-writer.module.scm ../fmt-c-writer.scm sex-fmt-c.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) fmt-c-writer.module.scm -o fmt-c-writer.o -unit fmt-c-writer -link sex-fmt-c,utils
|
|
||||||
|
|
||||||
sexc.o: sexc.module.scm ../sexc.scm fmt-c-writer.o sex-macros.o sex-modules.o reader.o semen.o utils.o
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) $(MODULE_FLAGS) sexc.module.scm -o sexc.o -unit sexc -link fmt-c-writer,sex-macros,sex-modules,reader,semen,utils
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f $(OBJ)
|
|
||||||
rm -f *.import.scm
|
|
||||||
rm -f *.link
|
|
||||||
rm -f sex-tests
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
(import fmt-c-writer)
|
|
||||||
|
|
||||||
(test-group "basic"
|
(test-group "basic"
|
||||||
|
|
||||||
;; unkebabify
|
;; unkebabify
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
(module fmt-c-writer
|
|
||||||
*
|
|
||||||
"../fmt-c-writer.scm")
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module reader
|
|
||||||
*
|
|
||||||
"../reader.scm")
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
(import (chicken port)
|
(import (chicken port))
|
||||||
reader)
|
|
||||||
|
|
||||||
(define-syntax reader-test
|
(define-syntax reader-test
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
(declare (uses fmt-c-writer
|
||||||
|
semen))
|
||||||
|
|
||||||
(import
|
(import
|
||||||
|
(chicken process)
|
||||||
|
(chicken process-context)
|
||||||
|
srfi-1
|
||||||
test)
|
test)
|
||||||
|
|
||||||
(include "basic.scm")
|
(include "basic.scm")
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
(module semen *
|
|
||||||
"../semen.scm")
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
(import srfi-69
|
(import srfi-69)
|
||||||
semen)
|
|
||||||
|
|
||||||
(define print-str-fn
|
(define print-str-fn
|
||||||
'(fn void print-str ((string s))
|
'(fn void print-str ((string s))
|
||||||
@@ -39,11 +38,11 @@
|
|||||||
(define (form-identity form env)
|
(define (form-identity form env)
|
||||||
form)
|
form)
|
||||||
|
|
||||||
(test 'a (walk-form 'a form-identity (make-hash-table)))
|
(test 'a (semen-walk-form 'a form-identity (make-hash-table)))
|
||||||
(test '(a b c) (walk-form '(a b c) form-identity (make-hash-table)))
|
(test '(a b c) (semen-walk-form '(a b c) form-identity (make-hash-table)))
|
||||||
|
|
||||||
(test 'a (macro-expand 'a))
|
(test 'a (semen-macro-expand 'a))
|
||||||
(test '(a b c) (macro-expand '(a b c)))
|
(test '(a b c) (semen-macro-expand '(a b c)))
|
||||||
|
|
||||||
(let ((sex-code-macro
|
(let ((sex-code-macro
|
||||||
'((defmacro (x10 a)
|
'((defmacro (x10 a)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
(module sex-macros
|
|
||||||
*
|
|
||||||
"../sex-macros.scm")
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module sex-modules
|
|
||||||
*
|
|
||||||
"../sex-modules.scm")
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
(module sexc (main) "../sexc.scm")
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
(module utils
|
|
||||||
*
|
|
||||||
"../utils.scm")
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
(import utils)
|
|
||||||
|
|
||||||
(test-group "utils"
|
(test-group "utils"
|
||||||
|
|
||||||
(test
|
(test
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
CHICKEN_C = csc
|
|
||||||
CSC_FLAGS += -K prefix -static
|
|
||||||
|
|
||||||
sextest: sextest.scm
|
|
||||||
$(CHICKEN_C) $(CSC_FLAGS) sextest.scm -o sextest
|
|
||||||
@@ -1,26 +1,34 @@
|
|||||||
* Sextest
|
* Sextest
|
||||||
A tool for testing Sex compiler by using test programs.
|
|
||||||
The tools compiles test programs, then runs with provided
|
A tool for testing sex compilator by using test programs.
|
||||||
input, checking the output and return code.
|
The tools compiles them using the compiler, then runs with provided
|
||||||
|
input, then checks that the output and return code matches the test
|
||||||
|
specification.
|
||||||
|
|
||||||
* Test format
|
* Test format
|
||||||
The test program is just a regular Sex program, which may contain
|
The test program consists of two sections: prelude and the test
|
||||||
additional toplevel forms, to define compilation parameters, input to
|
program itself. Prelude contains four sections: compilation
|
||||||
the program, and expected output and return code. Default value for
|
parameters, such as flags to compiler; string to be
|
||||||
compilation, input and output is an empty strings. For the return code
|
passed to program's stdin; output to match against
|
||||||
it is 0.
|
program's stdout; return code to match against what
|
||||||
|
program returns.
|
||||||
|
All sections start with respective name: :compilation, :stdout,
|
||||||
|
:stdin, :return.
|
||||||
|
Section names must be present, but all can be empty. Return code
|
||||||
|
defaults to 0 in such case.
|
||||||
|
|
||||||
* Example
|
* Example
|
||||||
some-test.sex:
|
some-test.sex:
|
||||||
#+begin_src
|
#+begin_src
|
||||||
(compilation "-- -O2")
|
; :compilation
|
||||||
(input "")
|
; :stdin
|
||||||
(output "Hello world!")
|
; :stdout Hello world!
|
||||||
(return 123)
|
; :return
|
||||||
|
|
||||||
(include stdio.h)
|
(include stdio.h)
|
||||||
|
|
||||||
(pub fn main () int
|
(pub fn main () int
|
||||||
(puts "Hello World!")
|
(puts "Hello World!")
|
||||||
(return 123))
|
(printf "Hello, %s!\n" name)
|
||||||
|
(return 0))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
(input "Sextest")
|
|
||||||
(output "Hello from Sex!" "What is your name?" "Hello, Sextest!")
|
|
||||||
(return 0)
|
|
||||||
|
|
||||||
(include stdio.h)
|
|
||||||
|
|
||||||
(pub fn main s ((argc int) (argv [* const char])) int
|
|
||||||
(puts "Hello from Sex!")
|
|
||||||
(var name [char 512])
|
|
||||||
(puts "What is your name?")
|
|
||||||
(scanf "%s" (cast (& name) (* char)))
|
|
||||||
(printf "Hello, %s!\n" name)
|
|
||||||
(return 255))
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
(import scheme
|
|
||||||
brev-separate
|
|
||||||
(chicken base)
|
|
||||||
(chicken file)
|
|
||||||
(chicken io)
|
|
||||||
(chicken pathname)
|
|
||||||
(chicken port)
|
|
||||||
(chicken process)
|
|
||||||
(chicken process-context)
|
|
||||||
(chicken read-syntax)
|
|
||||||
(chicken syntax)
|
|
||||||
fmt
|
|
||||||
srfi-1)
|
|
||||||
|
|
||||||
(define-syntax prog1
|
|
||||||
(syntax-rules ()
|
|
||||||
((prog1 form . forms)
|
|
||||||
(let ((res form))
|
|
||||||
(begin . forms)
|
|
||||||
res))))
|
|
||||||
|
|
||||||
(define-syntax with-directory
|
|
||||||
(syntax-rules ()
|
|
||||||
((with-directory path form . forms)
|
|
||||||
(let ((current-dir (current-directory)))
|
|
||||||
(set-working-directory path)
|
|
||||||
(prog1
|
|
||||||
(begin form . forms)
|
|
||||||
(change-directory current-dir))))))
|
|
||||||
|
|
||||||
(define (set-working-directory file)
|
|
||||||
(change-directory
|
|
||||||
(normalize-pathname
|
|
||||||
(if (absolute-pathname? file)
|
|
||||||
(pathname-directory file)
|
|
||||||
(make-absolute-pathname
|
|
||||||
(current-directory)
|
|
||||||
(pathname-directory file))))))
|
|
||||||
|
|
||||||
;;; TODO: use sexc reader code i.e. link with sex reader
|
|
||||||
(define open-bracket-counter (make-parameter 0))
|
|
||||||
|
|
||||||
(define (read-raw-forms input-source)
|
|
||||||
(let ((bracket-end (gensym)))
|
|
||||||
(set-read-syntax!
|
|
||||||
#\]
|
|
||||||
(lambda (port)
|
|
||||||
(when (= 0 (open-bracket-counter))
|
|
||||||
(error "Unmatched closing bracket"))
|
|
||||||
(open-bracket-counter (- (open-bracket-counter) 1))
|
|
||||||
bracket-end))
|
|
||||||
|
|
||||||
(set-read-syntax!
|
|
||||||
#\[
|
|
||||||
(lambda (port)
|
|
||||||
(open-bracket-counter (+ (open-bracket-counter) 1))
|
|
||||||
(let loop ((r (read port))
|
|
||||||
(acc (list)))
|
|
||||||
(if (eq? r bracket-end)
|
|
||||||
(cons '¤ (reverse acc))
|
|
||||||
(loop (read port)
|
|
||||||
(cons r acc)))))))
|
|
||||||
(read-from-file input-source))
|
|
||||||
|
|
||||||
(define (read-from-file file)
|
|
||||||
(with-directory file
|
|
||||||
(with-input-from-file (pathname-strip-directory file)
|
|
||||||
(fn (read-forms (list))))))
|
|
||||||
|
|
||||||
(define (read-forms acc)
|
|
||||||
(let ((r (read-with-source-info (current-input-port))))
|
|
||||||
(if (eof-object? r) (reverse acc)
|
|
||||||
(read-forms (cons r acc)))))
|
|
||||||
|
|
||||||
(define (print-help)
|
|
||||||
(fmt #t "Usage: sextest ./path/to/test-file.sex\n"))
|
|
||||||
|
|
||||||
(define (process-file target-path)
|
|
||||||
(let ((contents (read-raw-forms target-path)))
|
|
||||||
(foldl (lambda (acc elt)
|
|
||||||
(case (car elt)
|
|
||||||
((compilation input output return)
|
|
||||||
(cons
|
|
||||||
(append (car acc) (list elt))
|
|
||||||
(cdr acc)))
|
|
||||||
(else
|
|
||||||
(cons
|
|
||||||
(car acc)
|
|
||||||
(append (cdr acc) (list elt))))))
|
|
||||||
(cons (list) (list))
|
|
||||||
contents)))
|
|
||||||
|
|
||||||
(define (compile src flags)
|
|
||||||
(let ((compiler (or (get-environment-variable "SEXC")
|
|
||||||
;; TODO: pass compiler in args
|
|
||||||
;; (get-arg args 'sex-compiler #f)
|
|
||||||
"sexc"))
|
|
||||||
(compiled-file (create-temporary-file)))
|
|
||||||
(call-with-values
|
|
||||||
(fn
|
|
||||||
(process compiler
|
|
||||||
(append (list "-o" compiled-file)
|
|
||||||
flags)))
|
|
||||||
(lambda (out-port in-port pid)
|
|
||||||
(with-output-to-port in-port
|
|
||||||
(fn (map print src)))
|
|
||||||
(close-output-port in-port)
|
|
||||||
(call-with-values
|
|
||||||
(fn (process-wait pid))
|
|
||||||
(lambda (pid exited retcode)
|
|
||||||
(if (= 0 retcode)
|
|
||||||
compiled-file
|
|
||||||
#f)))))))
|
|
||||||
|
|
||||||
(define (run-and-check file in out ret)
|
|
||||||
(call-with-values
|
|
||||||
(fn (process file))
|
|
||||||
(lambda (out-port in-port pid)
|
|
||||||
(when in
|
|
||||||
(with-output-to-port in-port
|
|
||||||
(fn (map print (cdr in))))
|
|
||||||
(close-output-port in-port))
|
|
||||||
(with-input-from-port out-port
|
|
||||||
(fn
|
|
||||||
(let loop ((line (read-line))
|
|
||||||
(lines (list)))
|
|
||||||
(if (eof-object? line)
|
|
||||||
(reverse lines)
|
|
||||||
(loop (read-line)
|
|
||||||
(cons line lines))))))
|
|
||||||
(call-with-values
|
|
||||||
(fn (process-wait pid))
|
|
||||||
(lambda (pid exited retcode)
|
|
||||||
(fmt #t "Ret code: " retcode nl))))))
|
|
||||||
|
|
||||||
(define (main)
|
|
||||||
(let ((args (command-line-arguments)))
|
|
||||||
(if (not (= 1 (length args)))
|
|
||||||
(print-help)
|
|
||||||
(let ((settings-and-src
|
|
||||||
(process-file (first args))))
|
|
||||||
(let ((settings (car settings-and-src))
|
|
||||||
(src (cdr settings-and-src)))
|
|
||||||
(let ((compiled-file (compile src (assoc 'compile settings))))
|
|
||||||
(unless compiled-file
|
|
||||||
(fmt #t "Compilation failed." nl)
|
|
||||||
(exit 1))
|
|
||||||
(run-and-check
|
|
||||||
compiled-file
|
|
||||||
(assoc 'input settings)
|
|
||||||
(assoc 'output settings)
|
|
||||||
(assoc 'return settings))))))))
|
|
||||||
|
|
||||||
(main)
|
|
||||||
73
tools/sextest/sextest.sex
Normal file
73
tools/sextest/sextest.sex
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
(include stdio.h)
|
||||||
|
(include unistd.h)
|
||||||
|
(include string.h)
|
||||||
|
|
||||||
|
(var COMP (* const char) ":compilation")
|
||||||
|
(var STDIN (* const char) ":stdin")
|
||||||
|
(var STDOUT (* const char) ":stdout")
|
||||||
|
(var RET (* const char) ":return")
|
||||||
|
|
||||||
|
(var test-file-path (* const char) NULL)
|
||||||
|
|
||||||
|
(var prelude-comp [const char 1024])
|
||||||
|
(var prelude-stdin [const char 1024])
|
||||||
|
(var prelude-stdout [const char 1024])
|
||||||
|
(var prelude-ret [const char 1024])
|
||||||
|
|
||||||
|
(fn print-usage () void
|
||||||
|
(printf "Usage: sextest ./path/to/test-file.sex\n"))
|
||||||
|
|
||||||
|
(fn read-file ((file-path (* const char))) void
|
||||||
|
(var f (* FILE) (fopen file-path "r"))
|
||||||
|
(if (== f NULL)
|
||||||
|
(begin
|
||||||
|
(printf "Failed to read file %s\n" file-path)
|
||||||
|
(return)))
|
||||||
|
;; should be more than enough
|
||||||
|
(var buffer [const char 1024])
|
||||||
|
(var i int 0)
|
||||||
|
|
||||||
|
(var c char)
|
||||||
|
|
||||||
|
(var section (* const char))
|
||||||
|
(while (!= EOF (= c (getc f)))
|
||||||
|
(switch c
|
||||||
|
(case (#\space #\newline #\tab #\return)
|
||||||
|
(= [buffer i] #\null)
|
||||||
|
|
||||||
|
(if (!= NULL section)
|
||||||
|
(begin
|
||||||
|
(memcpy i section buffer)))
|
||||||
|
|
||||||
|
|
||||||
|
(if (== 0 (strncmp buffer COMP 8ul)))
|
||||||
|
(= i 0))
|
||||||
|
(default
|
||||||
|
(if (== i (sizeof buffer))
|
||||||
|
(printf "Blast! The section is longer than %d, not going to work with this" (++/post i)))
|
||||||
|
|
||||||
|
(if (< i (sizeof buffer))
|
||||||
|
(= [buffer (++/post i)] c))))))
|
||||||
|
|
||||||
|
(fn get-section ((section-name (* const char))) (* const char)
|
||||||
|
;; Get section from test file by name.
|
||||||
|
;; Name must be one of: :compilation, :stdin, :stdout, :return
|
||||||
|
(if (== 0 (strncmp section-name COMP 8ul))
|
||||||
|
(return prelude-comp))
|
||||||
|
(if (== 0 (strncmp section-name STDIN 6ul))
|
||||||
|
(return prelude-stdin))
|
||||||
|
(if (== 0 (strncmp section-name STDOUT 7ul))
|
||||||
|
(return prelude-stdout))
|
||||||
|
(if (== 0 (strncmp section-name RET 7ul))
|
||||||
|
(return prelude-ret))
|
||||||
|
(printf "Expected section name, got %s\n" section-name)
|
||||||
|
(return NULL))
|
||||||
|
|
||||||
|
(pub fn main ((argc int) (argv [* const char])) int
|
||||||
|
(if (!= argc 2)
|
||||||
|
(begin
|
||||||
|
(print-usage)
|
||||||
|
(return 1)))
|
||||||
|
(var test-file-path (* const char) [argv 1])
|
||||||
|
(read-file test-file-path)
|
||||||
|
(return 0))
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
(module utils
|
|
||||||
(get-env-var
|
|
||||||
set-working-directory
|
|
||||||
to-absolute-pathname
|
|
||||||
list-split
|
|
||||||
list-join
|
|
||||||
recons
|
|
||||||
with-directory
|
|
||||||
)
|
|
||||||
"utils.scm")
|
|
||||||
11
utils.scm
11
utils.scm
@@ -1,3 +1,13 @@
|
|||||||
|
(module utils
|
||||||
|
(get-env-var
|
||||||
|
set-working-directory
|
||||||
|
to-absolute-pathname
|
||||||
|
list-split
|
||||||
|
list-join
|
||||||
|
recons
|
||||||
|
with-directory
|
||||||
|
)
|
||||||
|
|
||||||
(import
|
(import
|
||||||
scheme
|
scheme
|
||||||
(chicken base)
|
(chicken base)
|
||||||
@@ -64,3 +74,4 @@
|
|||||||
(eq? new-cdr (cdr old-cons)))
|
(eq? new-cdr (cdr old-cons)))
|
||||||
old-cons
|
old-cons
|
||||||
(cons new-car new-cdr)))
|
(cons new-car new-cdr)))
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user