-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathselfboot-entry.scm
More file actions
129 lines (112 loc) · 4.47 KB
/
Copy pathselfboot-entry.scm
File metadata and controls
129 lines (112 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
;;
;; Selfboot entrypoint for gauche
;;
;; $ gosh /path/to/selfboot-entry.scm ....
;;
(define (%%extract-program-args args* entrypth)
(if (string=? (car args*) entrypth)
(cdr args*)
(%%extract-program-args (cdr args*) entrypth)))
(define (%%extract-entrypoint-path args*)
(define (checkone s)
(and (string? s)
(let ((len (string-length s)))
(and (< 4 len)
(string=? (substring s (- len 4) len) ".scm")
s))))
(and (pair? args*)
(or (checkone (car args*))
(%%extract-entrypoint-path (cdr args*)))))
(define (%%pathslashfy pth)
(let* ((l (string->list pth))
(x (map (lambda (c) (if (char=? #\\ c) #\/ c)) l)))
(list->string x)))
(define (%%pathsimplify pth)
(define (pathcompose acc l)
(if (pair? l)
(pathcompose (if (string=? (car l) "")
acc
(string-append acc "/" (car l)))
(cdr l))
acc))
(define (pathcompose-start acc l)
(pathcompose (car l) (cdr l)))
(define (pathcomponent acc cur strq)
(if (string=? strq "")
(if (null? acc)
(reverse cur)
(reverse (cons (list->string (reverse acc)) cur)))
(let ((c (string-ref strq 0))
(r (substring strq 1 (string-length strq))))
(if (char=? c #\/)
(pathcomponent '() (cons (list->string (reverse acc)) cur) r)
(pathcomponent (cons c acc) cur r)))))
(define (simple cur m q)
(if (null? q)
(if (null? cur)
(reverse (cons m cur))
(reverse (cdr cur)))
(let ((a (car q))
(d (cdr q)))
(if (string=? ".." a)
(let ((next-cur (if (null? cur)
(list "..")
(cdr cur))))
(if (null? d)
(reverse next-cur)
(simple next-cur (car d) (cdr d))))
(simple (cons m cur) a d)))))
(define (start-simple cur m q)
;; Protect relative ../../../ sequence at beginning
(if (string=? m "..")
(start-simple (cons m cur) (car q) (cdr q))
(simple cur m q)))
(let ((r (pathcomponent '() '() pth)))
(pathcompose-start "" (start-simple '() (car r) (cdr r)))))
(define (%%locate-yuniroot-fromscmpath scmpath)
(write %%selfboot-orig-command-line) (newline)
(write %%selfboot-mypath) (newline)
(let ((npth (%%pathslashfy scmpath)))
(%%pathsimplify (string-append npth "/../../../.."))))
(define %%selfboot-orig-command-line (command-line))
(define %%selfboot-mypath (%%extract-entrypoint-path %%selfboot-orig-command-line))
(define %%selfboot-yuniroot (%%locate-yuniroot-fromscmpath %%selfboot-mypath))
(define %%selfboot-program-args (%%extract-program-args
%%selfboot-orig-command-line
%%selfboot-mypath))
(define myenv
(let ((cur (current-module)))
(lambda () cur)))
(define (%%selfboot-loadlib pth libname imports exports)
(let ((code (%selfboot-file->sexp-list pth)))
(eval `(define-library ,libname
(export ,@exports)
(import (yuni-runtime r7rs) ,@imports)
(begin ,@code))
(myenv))))
(define (%%selfboot-load-aliaslib truename alias* export*)
(for-each (lambda (libname)
(let ((code `(define-library ,libname
(export ,@export*)
(import ,truename))))
(eval code (myenv))))
alias*))
(define %%selfboot-impl-type 'gauche)
(define %%selfboot-core-libs '((scheme base)
(scheme case-lambda)
(scheme cxr)
(scheme file)
(scheme inexact)
(scheme process-context)
(scheme read)
(scheme write)
(scheme eval)
))
(when (string=? %%selfboot-yuniroot "")
(set! %%selfboot-yuniroot "."))
;; Gauche doesn't include "." as default load path
(set! *load-path* (cons "." *load-path*))
(load (string-append %%selfboot-yuniroot "/lib-runtime/r7rs/yuni-runtime/r7rs.sld"))
(load (string-append %%selfboot-yuniroot "/lib-runtime/selfboot/chibi-scheme/selfboot-runtime.scm"))
(load (string-append %%selfboot-yuniroot "/lib-runtime/selfboot/common/common.scm"))
(load (string-append %%selfboot-yuniroot "/lib-runtime/selfboot/common/run-program.scm"))