From c74408098407e372e0dcac00ac3a4f0bb2a38094 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 17 Jul 2015 21:39:57 -0400 Subject: [PATCH] Added (Cyc-installation-dir) --- Makefile | 2 +- TODO | 2 ++ cgen.scm | 7 ++++++- eval.scm | 1 + runtime.c | 14 ++++++++++++++ runtime.h | 2 ++ transforms.scm | 2 ++ 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a8b4041c..d5d1abc5 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ libcyclone.so.1: runtime.c runtime.h gcc -shared -Wl,-soname,libcyclone.so.1 -o libcyclone.so.1.0.1 runtime.o libcyclone.a: runtime.c runtime.h dispatch.c $(CC) -g -c dispatch.c -o dispatch.o - $(CC) -g -c runtime.c -o runtime.o + $(CC) -g -c -DCYC_INSTALL_DIR=\"$(PREFIX)\" runtime.c -o runtime.o $(AR) rcs libcyclone.a runtime.o dispatch.o # Instructions from: http://www.adp-gmbh.ch/cpp/gcc/create_lib.html # Note compiler will have to link to this, eg: diff --git a/TODO b/TODO index 45c15923..f3c00889 100644 --- a/TODO +++ b/TODO @@ -22,6 +22,8 @@ how about we add installation-dir (AKA PREFIX) as a libcyclone.a function? the code can assume a cyc:get function for install dir and act accordingly. in addition, the chicken code can just hardwire it to the current directory or a home dir (maybe ideal, that is just debug anyway) +1) makefile needs to pass PREFIX when building the runtime lib + * purge (cyc:get-*-dir) functions should only need these maybe for the chicken install. * figure out how a build will go now. is it possible to build locally diff --git a/cgen.scm b/cgen.scm index 26142206..11c77672 100644 --- a/cgen.scm +++ b/cgen.scm @@ -495,6 +495,7 @@ ((eq? p 'string-length) "Cyc_string_length") ((eq? p 'string-ref) "Cyc_string_ref") ((eq? p 'substring) "Cyc_substring") + ((eq? p 'Cyc-installation-dir) "Cyc_installation_dir") ((eq? p 'command-line-arguments) "Cyc_command_line_arguments") ((eq? p 'system) "Cyc_system") ((eq? p 'assq) "assq") @@ -542,6 +543,7 @@ ((eq? p 'length) "integer_type") ((eq? p 'vector-length) "integer_type") ((eq? p 'char->integer) "integer_type") + ((eq? p 'Cyc-installation-dir) "string_type") ((eq? p 'system) "integer_type") ((eq? p '+) "common_type") ((eq? p '-) "common_type") @@ -569,7 +571,10 @@ Cyc-stderr open-input-file open-output-file - char->integer system string->number + char->integer + system + Cyc-installation-dir + string->number string-append string-cmp list->string string->list make-vector list->vector symbol->string number->string diff --git a/eval.scm b/eval.scm index c8730efd..c6869f54 100644 --- a/eval.scm +++ b/eval.scm @@ -201,6 +201,7 @@ (list 'apply apply) (list '%halt %halt) (list 'exit exit) + (list 'Cyc-installation-dir Cyc-installation-dir) (list 'system system) (list 'command-line-arguments command-line-arguments) (list 'error error) diff --git a/runtime.c b/runtime.c index 6331cb0b..93dcfcc6 100644 --- a/runtime.c +++ b/runtime.c @@ -938,6 +938,15 @@ string_type Cyc_substring(object str, object start, object end) { } } +/** + * Return directory where cyclone is installed. + * This is configured via the makefile during a build. + */ +string_type Cyc_installation_dir() { + make_string(str, CYC_INSTALL_DIR); + return str; +} + /** * Perform same role as the CHICKEN function: * @@ -1459,6 +1468,9 @@ void _cyc_string_91ref(object cont, object args) { Cyc_check_num_args("string-ref", 2, args); { object c = Cyc_string_ref(car(args), cadr(args)); return_funcall1(cont, c); }} +void _Cyc_91installation_91dir(object cont, object args) { + string_type dir = Cyc_installation_dir(); + return_funcall1(cont, &dir);} void _command_91line_91arguments(object cont, object args) { object cmdline = Cyc_command_line_arguments(cont); return_funcall1(cont, cmdline); } @@ -2151,6 +2163,7 @@ static primitive_type string_91_125number_primitive = {primitive_tag, "string->n static primitive_type string_91length_primitive = {primitive_tag, "string-length", &_string_91length}; static primitive_type substring_primitive = {primitive_tag, "substring", &_cyc_substring}; static primitive_type string_91ref_primitive = {primitive_tag, "string-ref", &_cyc_string_91ref}; +static primitive_type Cyc_91installation_91dir_primitive = {primitive_tag, "Cyc-installation-dir", &_Cyc_91installation_91dir}; static primitive_type command_91line_91arguments_primitive = {primitive_tag, "command-line-arguments", &_command_91line_91arguments}; static primitive_type system_primitive = {primitive_tag, "system", &_cyc_system}; static primitive_type string_91cmp_primitive = {primitive_tag, "string-cmp", &_string_91cmp}; @@ -2266,6 +2279,7 @@ const object primitive_string_91_125number = &string_91_125number_primitive; const object primitive_string_91length = &string_91length_primitive; const object primitive_substring = &substring_primitive; const object primitive_string_91ref = &string_91ref_primitive; +const object primitive_Cyc_91installation_91dir = &Cyc_91installation_91dir_primitive; const object primitive_command_91line_91arguments = &command_91line_91arguments_primitive; const object primitive_system = &system_primitive; const object primitive_string_91cmp = &string_91cmp_primitive; diff --git a/runtime.h b/runtime.h index bd772ee3..58c36362 100644 --- a/runtime.h +++ b/runtime.h @@ -105,6 +105,7 @@ string_type Cyc_string_append_va_list(int argc, object str1, va_list ap); integer_type Cyc_string_length(object str); string_type Cyc_substring(object str, object start, object end); object Cyc_string_ref(object str, object k); +string_type Cyc_installation_dir(); object Cyc_command_line_arguments(object cont); integer_type Cyc_system(object cmd); integer_type Cyc_char2integer(object chr); @@ -327,6 +328,7 @@ extern const object primitive_list_91_125vector; extern const object primitive_vector_91ref; extern const object primitive_vector_91set_67; extern const object primitive_string_91ref; +extern const object primitive_Cyc_91installation_91dir; extern const object primitive_command_91line_91arguments; extern const object primitive_system; extern const object primitive_boolean_127; diff --git a/transforms.scm b/transforms.scm index bf607df0..381f4a26 100644 --- a/transforms.scm +++ b/transforms.scm @@ -541,6 +541,7 @@ exit system command-line-arguments + Cyc-installation-dir Cyc-default-exception-handler Cyc-current-exception-handler cons @@ -628,6 +629,7 @@ exit system command-line-arguments + Cyc-installation-dir Cyc-default-exception-handler Cyc-current-exception-handler cell-get