Browse Source

Sol Part 62: It's Going Places!

Graham Northup 4 years ago
parent
commit
1f061239c9
Signed by: Graham Northup <grissess@nexusg.org> GPG Key ID: 5D000E6F539376FB
5 changed files with 68 additions and 5 deletions
  1. 32
    5
      Makefile
  2. 2
    0
      sol.h
  3. 1
    0
      sol_help.txt
  4. 4
    0
      solrun.c
  5. 29
    0
      state.c

+ 32
- 5
Makefile View File

@@ -2,6 +2,22 @@ CFLAGS= -g $(BUILD_DEFINES)
2 2
 LDFLAGS= -lm -ldl -lreadline
3 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 4
 
5
+ifndef CC
6
+	CC:= gcc
7
+endif
8
+
9
+ifndef OBJCOPY
10
+	OBJCOPY:= objcopy
11
+endif
12
+
13
+ifndef OBJDUMP
14
+	OBJDUMP:= objdump
15
+endif
16
+
17
+ifndef PREFIX
18
+	PREFIX:= /usr/local/
19
+endif
20
+
5 21
 include VERSION_INFO
6 22
 include ARCH_INFO
7 23
 
@@ -10,15 +26,26 @@ BUILD_DEFINES:= -DSOL_BUILD_HOST="\"$(shell uname -n)\"" -DSOL_BUILD_KERNEL="\"$
10 26
 SOL_VER:=$(MAJOR).$(MINOR)$(RELEASE)$(PATCH)
11 27
 LINKED_VERS:=sol sol$(MAJOR) sol$(MAJOR).$(MINOR)
12 28
 
13
-.PHONY: all test
29
+.PHONY: install install_bin all test clean docs
14 30
 
15 31
 all: dsl $(LINKED_VERS)
16 32
 
33
+install: install_bin
34
+
35
+install_bin: sol$(SOL_VER) $(LINKED_VERS)
36
+	install $? $(PREFIX)/bin/
37
+
38
+uninstall: uninstall_bin
39
+
40
+uninstall_bin:
41
+	rm $(PREFIX)/bin/sol$(SOL_VER)
42
+	for fname in $(LINKED_VERS); do rm $(PREFIX)/bin/$$fname; done
43
+
17 44
 $(LINKED_VERS): sol$(SOL_VER)
18 45
 	rm $@; ln -s $? $@
19 46
 	
20 47
 sol$(SOL_VER): $(OBJ)
21
-	gcc $(CFLAGS) $? $(LDFLAGS) -o $@
48
+	$(CC) $(CFLAGS) $? $(LDFLAGS) -o $@
22 49
 
23 50
 test: all $(sort $(patsubst tests/%.sol,test_%,$(wildcard tests/*.sol))) $(sort $(patsubst tests/%.sol,testcomp_%,$(wildcard tests/*.sol)))
24 51
 
@@ -36,13 +63,13 @@ VERSION_INFO: sol.h
36 63
 	perl -n -e '/#define SOL_VERSION "([[:digit:]]+)\.([[:digit:]]+)(.)([[:digit:]]+)"/ && print "MAJOR:=$$1\nMINOR:=$$2\nRELEASE:=$$3\nPATCH:=$$4\n"' $? > $@
37 64
 
38 65
 ARCH_INFO: gc.o
39
-	objdump -f $? | perl -n -e '/file format ([^-]+-(.+))$$/ && print "HOST_ARCH:=$$2\nHOST_ELF:=$$1\n"' > $@
66
+	$(OBJDUMP) -f $? | perl -n -e '/file format ([^-]+-(.+))$$/ && print "HOST_ARCH:=$$2\nHOST_ELF:=$$1\n"' > $@
40 67
 
41 68
 %.o: %.c
42
-	gcc -c -o $@ $? $(CFLAGS)
69
+	$(CC) -c -o $@ $? $(CFLAGS)
43 70
 
44 71
 %.o: %.txt | ARCH_INFO
45
-	objcopy -B i386 -I binary -O $(HOST_ELF) $? $@
72
+	$(OBJCOPY) -B i386 -I binary -O $(HOST_ELF) $? $@
46 73
 
47 74
 %.tab.c %.tab.h: %.y
48 75
 	bison -rall -fall -d $?

+ 2
- 0
sol.h View File

@@ -450,6 +450,8 @@ typedef struct sol_tag_state_t {
450 450
 
451 451
 /** Don't run user initialization files. */
452 452
 #define SOL_FT_NO_USR_INIT 0x0001
453
+/** Be noisy in the language runtime. */
454
+#define SOL_FT_DEBUG       0x0002
453 455
 
454 456
 // state.c
455 457
 

+ 1
- 0
sol_help.txt View File

@@ -10,6 +10,7 @@ options "a" and "b" take arguments.
10 10
 Sol currently recognizes the following options:
11 11
 
12 12
 -d: Sets yydebug=1, which enables debug tracing of the parser/lexer.
13
+-D: Sets debugging within the language runtime itself.
13 14
 -t: Prints the Sol syntax tree after program loading.
14 15
 -i: Ignore any initialization files. By default, Sol executes any of these
15 16
  files, if they exist and are readable, in the initial environment in this

+ 4
- 0
solrun.c View File

@@ -22,6 +22,10 @@ int main(int argc, char **argv) {
22 22
 					yydebug = 1;
23 23
 					break;
24 24
 
25
+				case 'D':
26
+					state.features |= SOL_FT_DEBUG;
27
+					break;
28
+
25 29
 				case 't':
26 30
 					printtree = 1;
27 31
 					break;

+ 29
- 0
state.c View File

@@ -474,26 +474,55 @@ int sol_state_init(sol_state_t *state) {
474 474
 	if(!(state->features & SOL_FT_NO_USR_INIT)) {
475 475
 		for(i = 0; i < LENGTH(sol_AbsInitPaths); i++) {
476 476
 			fp = fopen(sol_AbsInitPaths[i], "r");
477
+			if(state->features & SOL_FT_DEBUG) {
478
+				printf("state init: loading abs %s: ", sol_AbsInitPaths[i]);
479
+			}
477 480
 			if(fp) {
481
+				if(state->features & SOL_FT_DEBUG) {
482
+					printf("found");
483
+				}
478 484
 				stmt = sol_compile_file(fp);
479 485
 				sol_exec(state, stmt);
480 486
 				st_free(stmt);
481 487
 				fclose(fp);
488
+			} else {
489
+				if(state->features & SOL_FT_DEBUG) {
490
+					printf("not found");
491
+				}
492
+			}
493
+			if(state->features & SOL_FT_DEBUG) {
494
+				printf("\n");
482 495
 			}
483 496
 		}
484 497
 
485 498
 		suffix = getenv("HOME");
499
+		if(state->features & SOL_FT_DEBUG) {
500
+			printf("state init: loading relative to %s\n", suffix);
501
+		}
486 502
 		if(suffix) {
487 503
 			strncpy(sol_TempPath, suffix, TMP_PATH_SZ);
488 504
 			suffix = sol_TempPath + strlen(sol_TempPath);
489 505
 			for(i = 0; i < LENGTH(sol_HomeInitPaths); i++) {
490 506
 				strncpy(suffix, sol_HomeInitPaths[i], TMP_PATH_SZ - (suffix - sol_TempPath));
507
+				if(state->features & SOL_FT_DEBUG) {
508
+					printf("state init: loading rel %s: ", sol_TempPath);
509
+				}
491 510
 				fp = fopen(sol_TempPath, "r");
492 511
 				if(fp) {
512
+					if(state->features & SOL_FT_DEBUG) {
513
+						printf("found");
514
+					}
493 515
 					stmt = sol_compile_file(fp);
494 516
 					sol_exec(state, stmt);
495 517
 					st_free(stmt);
496 518
 					fclose(fp);
519
+				} else {
520
+					if(state->features & SOL_FT_DEBUG) {
521
+						printf("not found");
522
+					}
523
+				}
524
+				if(state->features & SOL_FT_DEBUG) {
525
+					printf("\n");
497 526
 				}
498 527
 			}
499 528
 		}

Loading…
Cancel
Save