Browse Source

Sol Part 61: It's Almost a Language Edition!

Happy 101st commit, Sol!
Graham Northup 3 years ago
parent
commit
2487f8762c
Signed by: Graham Northup <grissess@nexusg.org> GPG Key ID: 5D000E6F539376FB
7 changed files with 108 additions and 8 deletions
  1. 3
    2
      .gitignore
  2. 7
    0
      LICENSE
  3. 25
    5
      Makefile
  4. 18
    0
      sol.h
  5. 41
    0
      sol_help.txt
  6. 14
    0
      solrun.c
  7. 0
    1
      state.c

+ 3
- 2
.gitignore View File

@@ -1,5 +1,5 @@
1
-sol
2
-solace
1
+sol*
2
+!sol_help.txt
3 3
 *.o
4 4
 stdout
5 5
 .submodule_stamp
@@ -13,3 +13,4 @@ iss*
13 13
 _build
14 14
 doxyxml
15 15
 valgrind.log
16
+*_INFO

+ 7
- 0
LICENSE View File

@@ -21,3 +21,10 @@ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21 21
 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22 22
 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 23
 DEALINGS IN THE SOFTWARE.
24
+
25
+The following exception is granted: these shall not be considered "derivative
26
+works":
27
+- source programs written in the Sol language;
28
+- compiled programs encoded in the Sol bytecode, including those generated by
29
+  this program;
30
+- the output generated as a direct result of executing a Sol program.

+ 25
- 5
Makefile View File

@@ -1,13 +1,24 @@
1
-CFLAGS= -g 
1
+CFLAGS= -g $(BUILD_DEFINES)
2 2
 LDFLAGS= -lm -ldl -lreadline
3
-OBJ= lex.yy.o parser.tab.o dsl/seq.o dsl/list.o dsl/array.o dsl/generic.o astprint.o runtime.o gc.o object.o state.o builtins.o solrun.o ser.o
3
+OBJ= lex.yy.o parser.tab.o dsl/seq.o dsl/list.o dsl/array.o dsl/generic.o astprint.o runtime.o gc.o object.o state.o builtins.o solrun.o ser.o sol_help.o
4
+
5
+include VERSION_INFO
6
+include ARCH_INFO
7
+
8
+BUILD_DEFINES:= -DSOL_BUILD_HOST="\"$(shell uname -n)\"" -DSOL_BUILD_KERNEL="\"$(shell uname -s)\"" -DSOL_BUILD_ARCH="\"$(shell uname -m)\"" -DSOL_BUILD_REV="\"$(shell git rev-parse --short HEAD)$(shell git diff-index --quiet HEAD || echo '-dirty')\""
9
+
10
+SOL_VER:=$(MAJOR).$(MINOR)$(RELEASE)$(PATCH)
11
+LINKED_VERS:=sol sol$(MAJOR) sol$(MAJOR).$(MINOR)
4 12
 
5 13
 .PHONY: all test
6 14
 
7
-all: dsl sol
15
+all: dsl $(LINKED_VERS)
16
+
17
+$(LINKED_VERS): sol$(SOL_VER)
18
+	rm $@; ln -s $? $@
8 19
 	
9
-sol: $(OBJ)
10
-	gcc $(CFLAGS) $? $(LDFLAGS) -o sol
20
+sol$(SOL_VER): $(OBJ)
21
+	gcc $(CFLAGS) $? $(LDFLAGS) -o $@
11 22
 
12 23
 test: all $(sort $(patsubst tests/%.sol,test_%,$(wildcard tests/*.sol))) $(sort $(patsubst tests/%.sol,testcomp_%,$(wildcard tests/*.sol)))
13 24
 
@@ -21,9 +32,18 @@ testcomp_%: tests/%.sol
21 32
 dsl:
22 33
 	git submodule init && git submodule sync && git submodule update
23 34
 
35
+VERSION_INFO: sol.h
36
+	perl -n -e '/#define SOL_VERSION "([[:digit:]]+)\.([[:digit:]]+)(.)([[:digit:]]+)"/ && print "MAJOR:=$$1\nMINOR:=$$2\nRELEASE:=$$3\nPATCH:=$$4\n"' $? > $@
37
+
38
+ARCH_INFO: gc.o
39
+	objdump -f $? | perl -n -e '/file format ([^-]+-(.+))$$/ && print "HOST_ARCH:=$$2\nHOST_ELF:=$$1\n"' > $@
40
+
24 41
 %.o: %.c
25 42
 	gcc -c -o $@ $? $(CFLAGS)
26 43
 
44
+%.o: %.txt | ARCH_INFO
45
+	objcopy -B i386 -I binary -O $(HOST_ELF) $? $@
46
+
27 47
 %.tab.c %.tab.h: %.y
28 48
 	bison -rall -fall -d $?
29 49
 

+ 18
- 0
sol.h View File

@@ -25,6 +25,24 @@
25 25
  */
26 26
 #define SOL_HEXVER 0x0003A02
27 27
 
28
+#ifndef SOL_BUILD_HOST
29
+#define SOL_BUILD_HOST "(unknown host)"
30
+#endif
31
+
32
+#ifndef SOL_BUILD_KERNEL
33
+#define SOL_BUILD_KERNEL "(unknown kernel)"
34
+#endif
35
+
36
+#ifndef SOL_BUILD_ARCH
37
+#define SOL_BUILD_ARCH "(unknown arch)"
38
+#endif
39
+
40
+#ifndef SOL_BUILD_REV
41
+#define SOL_BUILD_REV "(unknown rev)"
42
+#endif
43
+
44
+#define SOL_BUILD_ID "sol-" SOL_BUILD_REV " " __DATE__ " " __TIME__ " on " SOL_BUILD_HOST " " SOL_BUILD_KERNEL " " SOL_BUILD_ARCH
45
+
28 46
 #ifndef SOL_ICACHE_MIN
29 47
 /** The smallest integer to cache. */
30 48
 #define SOL_ICACHE_MIN -128

+ 41
- 0
sol_help.txt View File

@@ -0,0 +1,41 @@
1
+./sol [<options> [<arg> [<arg> ...]]]
2
+
3
+Sol Executive - compiles and/or runs a Sol program.
4
+
5
+Options given to Sol are given via the first argument. For options that take
6
+parameters, they are read in the order specified in the option argument; e.g.,
7
+"./sol ab a.foo b.bar" and "./sol ba b.bar a.foo" are equivalent, assuming
8
+options "a" and "b" take arguments.
9
+
10
+Sol currently recognizes the following options:
11
+
12
+-d: Sets yydebug=1, which enables debug tracing of the parser/lexer.
13
+-t: Prints the Sol syntax tree after program loading.
14
+-i: Ignore any initialization files. By default, Sol executes any of these
15
+ files, if they exist and are readable, in the initial environment in this
16
+ order:
17
+ - /etc/sol/init.sol
18
+ - /opt/sol/init.sol
19
+ - $HOME/.config/sol/init.sol
20
+ These may be overridden during compilation.
21
+-r <file>: Read the program from the file, instead of the default (stdin).
22
+ Programs run this way have access to stdin via `io.stdin` in the global
23
+ environment.
24
+-c <file>: After loading the program, write bytecode to the file, instead of
25
+ running the program. Such files can be later loaded using the C option.
26
+-C: Assume that the program file is a compiled bytecode stream instead of Sol
27
+ source text.
28
+
29
+Sol's exit status is determined by the following, in this order:
30
+- 0, on printing this help;
31
+- 2, if an argument, parsing, or initialization error occurred;
32
+- 0, if the file was to be compiled and was written successfully;
33
+- 1, if the program in the file encountered an error at the top level;
34
+- the integer value if an integer was returned at the top level;
35
+- 0 otherwise.
36
+
37
+For more information about the language itself, please refer to the source
38
+repository and/or `make docs` therein.
39
+
40
+Sol is Free Software under the Boost Software License, version 1.0; see LICENSE
41
+in the source repository for more details.

+ 14
- 0
solrun.c View File

@@ -2,6 +2,8 @@
2 2
 #include "ast.h"
3 3
 #include "parser.tab.h"
4 4
 
5
+extern char _binary_sol_help_txt_start, _binary_sol_help_txt_end;
6
+
5 7
 int main(int argc, char **argv) {
6 8
 	stmt_node *program;
7 9
 	sol_state_t state;
@@ -48,6 +50,18 @@ int main(int argc, char **argv) {
48 50
 				case 'C':
49 51
 					compiled = 1;
50 52
 					break;
53
+
54
+				case 'V':
55
+					printf(SOL_BUILD_ID "\n");
56
+				case 'h':
57
+					fwrite(
58
+						&_binary_sol_help_txt_start,
59
+						1,
60
+						&_binary_sol_help_txt_end - &_binary_sol_help_txt_start,
61
+						stdout
62
+					);
63
+					return 0;
64
+					break;
51 65
 			}
52 66
 			c++;
53 67
 		}

+ 0
- 1
state.c View File

@@ -470,7 +470,6 @@ int sol_state_init(sol_state_t *state) {
470 470
 	}
471 471
 
472 472
 	// Perform initialization based on the user profile, if so requested.
473
-	// TODO: Make this switchable at runtime.
474 473
 	
475 474
 	if(!(state->features & SOL_FT_NO_USR_INIT)) {
476 475
 		for(i = 0; i < LENGTH(sol_AbsInitPaths); i++) {

Loading…
Cancel
Save