Skip to content

Commit

Permalink
Checkin all changes related to fixing build-time issues
Browse files Browse the repository at this point in the history
The only build-time error encountered is the following, now:

/home/bryce/src/c/TIC-80/src/api/r.c:175:10: fatal error: ../build/assets/rdemo.tic.dat: No such file or directory
  175 | #include "../build/assets/rdemo.tic.dat"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/r.dir/build.make:76: CMakeFiles/r.dir/src/api/r.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:283: CMakeFiles/r.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
  • Loading branch information
bryce-carson committed Sep 26, 2024
1 parent 27642cf commit 0373b73
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 63 deletions.
15 changes: 13 additions & 2 deletions cmake/r.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if(BUILD_WITH_R AND NOT N3DS AND NOT BAREMETALAPI)
endif()

if(NOT DEFINED ENV{LD_LIBRARY_PATH} AND NOT LD_LIBRARY_PATH)
set(LD_LIBRARY_PATH "${R_HOME}/lib:${PREFIX}/lib/jvm/jre/lib/server")
set(LD_LIBRARY_PATH "/usr/include/R:${R_HOME}/lib:${PREFIX}/lib/jvm/jre/lib/server")
else()
# Add these entries to the this *PATH variable
set(LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:${PREFIX}/lib64/R/lib:${PREFIX}/lib/jvm/jre/lib/server")
Expand All @@ -34,7 +34,18 @@ if(BUILD_WITH_R AND NOT N3DS AND NOT BAREMETALAPI)
list(APPEND R_SRC "${PREFIX}/lib/jvm/jre/lib/server" R_SHARE_DIR R_DOC_DIR)
endif()

list(APPEND R_SRC ${CMAKE_SOURCE_DIR}/src/api/r.c)
set(R_LIB_DIR "/usr/include/R")
include_directories(SYSTEM "/usr/include/R")
list(
APPEND R_SRC
${CMAKE_SOURCE_DIR}/src/api/r.c
${R_LIB_DIR}/R.h
${R_LIB_DIR}/Rembedded.h
${R_LIB_DIR}/Rinterface.h
${R_LIB_DIR}/Rinternals.h
${R_LIB_DIR}/Rconfig.h
${R_LIB_DIR}/Rdefines.h
)

add_library(r ${TIC_RUNTIME} ${R_SRC})
set_target_properties(r PROPERTIES PREFIX "")
Expand Down
65 changes: 34 additions & 31 deletions src/api/r.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,52 @@
#include <stdlib.h>
#include <string.h>

tic_core *getTICCore(tic_mem* tic, const char* code) {
tic_core *core;
while (core == NULL && (!initR(tic, code))) {
core = (castTicMemory)->currentVM;
}
return core;
}

void evalR(tic_mem *memory, char *code) {
Rf_eval(Rf_mkString(code));
SEXP result = Rf_eval(Rf_mkString(code), R_GlobalEnv);
}

#define killer(x) \
if ((tic_core *core = (castTicMemory)->currentVM) != NULL) { \
Rf_endEmbeddedR(x); \
core->currentVM = NULL; \
#define killer \
tic_core *core; \
if ((core = (((tic_core *) tic))->currentVM) != NULL) { \
Rf_endEmbeddedR(0); \
core->currentVM = NULL; \
}

tic_core *getTICCore(tic_mem* tic, const char* code);

static bool initR(tic_mem *tic, const char *code) {
killer(0);
killer;

int tries = 1;
tic_core *core = getTicCore(tic, code);
core = getTICCore(tic, code);

tryOnceMoreOnly:
/* embdRAV: embedded R argument vector. */
char *embdRAV[]= { "REmbeddedInTIC80", "--silent" };
core = (tic_core *) Rf_initEmbeddedR(sizeof(embdRAV)/sizeof(embdRAV[0]), embdRAV);

bool rc = (bool) *core;
bool rc = (bool) Rf_initEmbeddedR(sizeof(embdRAV)/sizeof(embdRAV[0]), embdRAV);
if (rc) return rc;
else if (tries--) goto tryOnceMoreOnly;

return false;
}

static void closeR(tic_mem *tic) {
killer(0);
killer;
}
static void callRfn_TIC80() {
/* if (exists("TIC-80") && is.function(`TIC-80`)) `TIC-80`() */
Rf_eval(Rf_mkString("if (exists(\"TIC-80\") && is.function(`TIC-80`)) "\
"`TIC-80`()"));
/* if (exists("TIC-80") && is.function(`TIC-80`)) `TIC-80`() */
Rf_eval(Rf_mkString("if (exists(\"TIC-80\") && is.function(`TIC-80`)) "\
"`TIC-80`()"),
R_GlobalEnv);
}
#define defineCallRFn_(x) \
static void callRfn_##x(tic_mem *tic) { \
Rf_eval(Rf_mkString("if (exists(\""#x"\") && is.function("#x")) "#x"()")); \

tic_core *getTICCore(tic_mem* tic, const char* code) {
tic_core *core;
while (core == NULL && (!initR(tic, code))) {
core = (((tic_core *) tic))->currentVM;
}
/* if (exists("x") && is.function(x)) x() */
defineCallRFn_("MENU")
defineCallRFn_("BDR")
defineCallRFn_("BOOT")
defineCallRFn_("SCN")
#undef defineCallRFn_
return core;
}

static const char* const RKeywords [] =
{
Expand All @@ -99,6 +91,17 @@ static const char* const RKeywords [] =
"...", "..1", "..2", "..3", "..4", "..5", "..6", "..7", "..8", "..9",
};

/* A naive edit of the Python function to check if a character is a valid
* character within an identifier. */
static bool r_isalnum(char c) {
return (
(c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9')
|| (c == '_') || (c == '.')
);
}

static const tic_outline_item* getROutline(const char* code, s32* size)
{
enum{Size = sizeof(tic_outline_item)};
Expand Down
83 changes: 53 additions & 30 deletions src/api/r.org
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ can define it right now. For now the =memory= parameter can be ignored.
#+name: define evalR
#+begin_src C
void evalR(tic_mem *memory, char *code) {
Rf_eval(Rf_mkString(code));
SEXP result = Rf_eval(Rf_mkString(code), R_GlobalEnv);
}
#+end_src

Expand Down Expand Up @@ -249,7 +249,7 @@ definition of the function in either soure tree.
tic_core *getTICCore(tic_mem* tic, const char* code) {
tic_core *core;
while (core == NULL && (!initR(tic, code))) {
core = (castTicMemory)->currentVM;
core = (((tic_core *) tic))->currentVM;
}
return core;
}
Expand Down Expand Up @@ -448,12 +448,12 @@ changed so that no references to "Scheme" occur in the code.

<<INCLUDE>>

<<define a function to get a pointer to the tic_core>>

<<define evalR>>

<<cartridge commands>>

<<define a function to get a pointer to the tic_core>>

<<syntax highlighting and outline generation>>

<<TIC EXPORT>>
Expand Down Expand Up @@ -498,32 +498,33 @@ restarting R as necessary and tracking the current interpreter (there can be
only one).

#+begin_src C :noweb-ref cartridge commands
#define killer(x) \
if ((tic_core *core = (castTicMemory)->currentVM) != NULL) { \
Rf_endEmbeddedR(x); \
core->currentVM = NULL; \
#define killer \
tic_core *core; \
if ((core = (((tic_core *) tic))->currentVM) != NULL) { \
Rf_endEmbeddedR(0); \
core->currentVM = NULL; \
}

tic_core *getTICCore(tic_mem* tic, const char* code);

static bool initR(tic_mem *tic, const char *code) {
killer(0);
killer;

int tries = 1;
tic_core *core = getTicCore(tic, code);
core = getTICCore(tic, code);

tryOnceMoreOnly:
/* embdRAV: embedded R argument vector. */
char *embdRAV[]= { "REmbeddedInTIC80", "--silent" };
core = (tic_core *) Rf_initEmbeddedR(sizeof(embdRAV)/sizeof(embdRAV[0]), embdRAV);

bool rc = (bool) *core;
bool rc = (bool) Rf_initEmbeddedR(sizeof(embdRAV)/sizeof(embdRAV[0]), embdRAV);
if (rc) return rc;
else if (tries--) goto tryOnceMoreOnly;

return false;
}

static void closeR(tic_mem *tic) {
killer(0);
killer;
}
#+end_src

Expand All @@ -535,26 +536,26 @@ at least. The =exists= function doesn't use symbols, it uses strings to lookup
symbols so that is why that part differs in the chunk below.

#+begin_src C :noweb no-export :noweb-ref cartridge commands
static void callRfn_TIC80() {
/* if (exists("TIC-80") && is.function(`TIC-80`)) `TIC-80`() */
Rf_eval(Rf_mkString("if (exists(\"TIC-80\") && is.function(`TIC-80`)) "\
"`TIC-80`()"));
}
static void callRfn_TIC80() {
/* if (exists("TIC-80") && is.function(`TIC-80`)) `TIC-80`() */
Rf_eval(Rf_mkString("if (exists(\"TIC-80\") && is.function(`TIC-80`)) "\
"`TIC-80`()"),
R_GlobalEnv);
}
#+end_src

*** The menu, border, scanline, and system boot callback functions
These four TIC-80 API functions or commands are defined using a macro.

#+begin_src C :noweb no-export :noweb-ref cartridge commands
#define defineCallRFn_(x) \
static void callRfn_##x(tic_mem *tic) { \
Rf_eval(Rf_mkString("if (exists(\""#x"\") && is.function("#x")) "#x"()")); \
Rf_eval(Rf_mkString("if (exists(\""#x"\") && is.function("#x")) "#x"()"), \
R_GlobalEnv); \
}
/* if (exists("x") && is.function(x)) x() */
defineCallRFn_("MENU")
defineCallRFn_("BDR")
defineCallRFn_("BOOT")
defineCallRFn_("SCN")
defineCallRFn_(MENU)
defineCallRFn_(BDR)
defineCallRFn_(BOOT)
defineCallRFn_(SCN)
#undef defineCallRFn_
#+end_src

Expand Down Expand Up @@ -667,6 +668,17 @@ different areas of the script being written.

#+name: OUTLINE GENERATION
#+begin_src C
/* A naive edit of the Python function to check if a character is a valid
,* character within an identifier. */
static bool r_isalnum(char c) {
return (
(c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9')
|| (c == '_') || (c == '.')
);
}

static const tic_outline_item* getROutline(const char* code, s32* size)
{
enum{Size = sizeof(tic_outline_item)};
Expand Down Expand Up @@ -933,8 +945,8 @@ the R langauge embedding into TIC-80's build process using CMake now.

*** Tasks to complete related to this heading:
- [X] Patch =CMakeLists.txt=, if necessary.
- [ ] Write a CMake file for R, specifically.
- [ ] Test the build succeeds.
- [X] Write a CMake file for R, specifically.
- [X] Test the build succeeds: build fails with the message "R.h not found."
- [ ] Test ~eval~ on the TIC-80 command-line.

*** Patching =CMakeLists.txt=
Expand Down Expand Up @@ -962,7 +974,7 @@ chain (is there Fortran?) to ever work there. Baremetal? I won't bother.
endif()

if(NOT DEFINED ENV{LD_LIBRARY_PATH} AND NOT LD_LIBRARY_PATH)
set(LD_LIBRARY_PATH "${R_HOME}/lib:${PREFIX}/lib/jvm/jre/lib/server")
set(LD_LIBRARY_PATH "/usr/include/R:${R_HOME}/lib:${PREFIX}/lib/jvm/jre/lib/server")
else()
# Add these entries to the this *PATH variable
set(LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:${PREFIX}/lib64/R/lib:${PREFIX}/lib/jvm/jre/lib/server")
Expand All @@ -985,7 +997,18 @@ chain (is there Fortran?) to ever work there. Baremetal? I won't bother.
list(APPEND R_SRC "${PREFIX}/lib/jvm/jre/lib/server" R_SHARE_DIR R_DOC_DIR)
endif()

list(APPEND R_SRC ${CMAKE_SOURCE_DIR}/src/api/r.c)
set(R_LIB_DIR "/usr/include/R")
include_directories(SYSTEM "/usr/include/R")
list(
APPEND R_SRC
${CMAKE_SOURCE_DIR}/src/api/r.c
${R_LIB_DIR}/R.h
${R_LIB_DIR}/Rembedded.h
${R_LIB_DIR}/Rinterface.h
${R_LIB_DIR}/Rinternals.h
${R_LIB_DIR}/Rconfig.h
${R_LIB_DIR}/Rdefines.h
)

add_library(r ${TIC_RUNTIME} ${R_SRC})
set_target_properties(r PROPERTIES PREFIX "")
Expand Down

0 comments on commit 0373b73

Please sign in to comment.