Browse Source

Sol Part 62: It's Going Places!

master
Graham Northup 5 years ago
parent
commit
1f061239c9
Signed by: grissess GPG Key ID: 5D000E6F539376FB
  1. 37
      Makefile
  2. 2
      sol.h
  3. 1
      sol_help.txt
  4. 4
      solrun.c
  5. 29
      state.c

37
Makefile

@ -2,6 +2,22 @@ CFLAGS= -g $(BUILD_DEFINES)
LDFLAGS= -lm -ldl -lreadline
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
ifndef CC
CC:= gcc
endif
ifndef OBJCOPY
OBJCOPY:= objcopy
endif
ifndef OBJDUMP
OBJDUMP:= objdump
endif
ifndef PREFIX
PREFIX:= /usr/local/
endif
include VERSION_INFO
include ARCH_INFO
@ -10,15 +26,26 @@ BUILD_DEFINES:= -DSOL_BUILD_HOST="\"$(shell uname -n)\"" -DSOL_BUILD_KERNEL="\"$
SOL_VER:=$(MAJOR).$(MINOR)$(RELEASE)$(PATCH)
LINKED_VERS:=sol sol$(MAJOR) sol$(MAJOR).$(MINOR)
.PHONY: all test
.PHONY: install install_bin all test clean docs
all: dsl $(LINKED_VERS)
install: install_bin
install_bin: sol$(SOL_VER) $(LINKED_VERS)
install $? $(PREFIX)/bin/
uninstall: uninstall_bin
uninstall_bin:
rm $(PREFIX)/bin/sol$(SOL_VER)
for fname in $(LINKED_VERS); do rm $(PREFIX)/bin/$$fname; done
$(LINKED_VERS): sol$(SOL_VER)
rm $@; ln -s $? $@
sol$(SOL_VER): $(OBJ)
gcc $(CFLAGS) $? $(LDFLAGS) -o $@
$(CC) $(CFLAGS) $? $(LDFLAGS) -o $@
test: all $(sort $(patsubst tests/%.sol,test_%,$(wildcard tests/*.sol))) $(sort $(patsubst tests/%.sol,testcomp_%,$(wildcard tests/*.sol)))
@ -36,13 +63,13 @@ VERSION_INFO: sol.h
perl -n -e '/#define SOL_VERSION "([[:digit:]]+)\.([[:digit:]]+)(.)([[:digit:]]+)"/ && print "MAJOR:=$$1\nMINOR:=$$2\nRELEASE:=$$3\nPATCH:=$$4\n"' $? > $@
ARCH_INFO: gc.o
objdump -f $? | perl -n -e '/file format ([^-]+-(.+))$$/ && print "HOST_ARCH:=$$2\nHOST_ELF:=$$1\n"' > $@
$(OBJDUMP) -f $? | perl -n -e '/file format ([^-]+-(.+))$$/ && print "HOST_ARCH:=$$2\nHOST_ELF:=$$1\n"' > $@
%.o: %.c
gcc -c -o $@ $? $(CFLAGS)
$(CC) -c -o $@ $? $(CFLAGS)
%.o: %.txt | ARCH_INFO
objcopy -B i386 -I binary -O $(HOST_ELF) $? $@
$(OBJCOPY) -B i386 -I binary -O $(HOST_ELF) $? $@
%.tab.c %.tab.h: %.y
bison -rall -fall -d $?

2
sol.h

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

1
sol_help.txt

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

4
solrun.c

@ -22,6 +22,10 @@ int main(int argc, char **argv) {
yydebug = 1;
break;
case 'D':
state.features |= SOL_FT_DEBUG;
break;
case 't':
printtree = 1;
break;

29
state.c

@ -474,26 +474,55 @@ int sol_state_init(sol_state_t *state) {
if(!(state->features & SOL_FT_NO_USR_INIT)) {
for(i = 0; i < LENGTH(sol_AbsInitPaths); i++) {
fp = fopen(sol_AbsInitPaths[i], "r");
if(state->features & SOL_FT_DEBUG) {
printf("state init: loading abs %s: ", sol_AbsInitPaths[i]);
}
if(fp) {
if(state->features & SOL_FT_DEBUG) {
printf("found");
}
stmt = sol_compile_file(fp);
sol_exec(state, stmt);
st_free(stmt);
fclose(fp);
} else {
if(state->features & SOL_FT_DEBUG) {
printf("not found");
}
}
if(state->features & SOL_FT_DEBUG) {
printf("\n");
}
}
suffix = getenv("HOME");
if(state->features & SOL_FT_DEBUG) {
printf("state init: loading relative to %s\n", suffix);
}
if(suffix) {
strncpy(sol_TempPath, suffix, TMP_PATH_SZ);
suffix = sol_TempPath + strlen(sol_TempPath);
for(i = 0; i < LENGTH(sol_HomeInitPaths); i++) {
strncpy(suffix, sol_HomeInitPaths[i], TMP_PATH_SZ - (suffix - sol_TempPath));
if(state->features & SOL_FT_DEBUG) {
printf("state init: loading rel %s: ", sol_TempPath);
}
fp = fopen(sol_TempPath, "r");
if(fp) {
if(state->features & SOL_FT_DEBUG) {
printf("found");
}
stmt = sol_compile_file(fp);
sol_exec(state, stmt);
st_free(stmt);
fclose(fp);
} else {
if(state->features & SOL_FT_DEBUG) {
printf("not found");
}
}
if(state->features & SOL_FT_DEBUG) {
printf("\n");
}
}
}

Loading…
Cancel
Save