Skip to content

Commit

Permalink
Fix the BSD build and test tool
Browse files Browse the repository at this point in the history
  • Loading branch information
malyn committed Jun 28, 2014
1 parent 54919d3 commit 3d3e60c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 62 deletions.
20 changes: 16 additions & 4 deletions Makefile.bsd
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
all: test/enforth test/enforthsimple

test/enforth: enforth.h enforth.cpp test/enforth.cpp
c++ -g -I. -lcurses -o $@ -DENABLE_STACK_CHECKING=1 enforth.cpp test/enforth.cpp
utility/enforth_definitions.h: primitives/core.edn primitives/core-ext.edn primitives/enforth.edn primitives/tools.edn
cd DefGen && lein run ../utility $(addprefix ../, $+)

test/enforthsimple: enforth.h enforth.cpp test/enforthsimple.cpp
c++ -g -I. -o $@ -DENABLE_STACK_CHECKING=1 enforth.cpp test/enforthsimple.cpp
utility/enforth_jumptable.h: primitives/core.edn primitives/core-ext.edn primitives/enforth.edn primitives/tools.edn
cd DefGen && lein run ../utility $(addprefix ../, $+)

utility/enforth_names.h: primitives/core.edn primitives/core-ext.edn primitives/enforth.edn primitives/tools.edn
cd DefGen && lein run ../utility $(addprefix ../, $+)

utility/enforth_tokens.h: primitives/core.edn primitives/core-ext.edn primitives/enforth.edn primitives/tools.edn
cd DefGen && lein run ../utility $(addprefix ../, $+)

test/enforth: enforth.h enforth.c utility/enforth_definitions.h utility/enforth_jumptable.h utility/enforth_names.h utility/enforth_tokens.h test/enforth.c
cc -g -I. -I./utility -lcurses -o $@ -DENABLE_STACK_CHECKING=1 enforth.c test/enforth.c

test/enforthsimple: enforth.h enforth.c utility/enforth_definitions.h utility/enforth_jumptable.h utility/enforth_names.h utility/enforth_tokens.h test/enforthsimple.c
cc -g -I. -I./utility -o $@ -DENABLE_STACK_CHECKING=1 enforth.c test/enforthsimple.c
77 changes: 19 additions & 58 deletions test/enforth.cpp → test/enforth.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@

/* ANSI C includes. */
#include <stdio.h>
#include <stdlib.h>

/* Curses includes. */
#include <curses.h>

/* enforth includes. */
/* Enforth includes. */
#include "enforth.h"


Expand All @@ -51,7 +50,7 @@
* Sample FFI definitions.
*/

// Externs
/* Externs */
ENFORTH_EXTERN(clear, clear, 0)
#undef LAST_FFI
#define LAST_FFI GET_LAST_FFI(clear)
Expand All @@ -67,12 +66,12 @@ ENFORTH_EXTERN(srand, srand, 1)


/* -------------------------------------
* enforth I/O primitives.
* Enforth I/O primitives.
*/

static bool enforthCursesKeyQuestion(void)
static int enforthCursesKeyQuestion(void)
{
return true;
return -1;
}

/* 6.1.1750 KEY
Expand Down Expand Up @@ -112,11 +111,9 @@ static void enforthCursesEmit(char ch)
* Globals.
*/

static EnforthVM enforthVM;
static unsigned char enforthDict[512];
static ENFORTH enforth(
enforthDict, sizeof(enforthDict),
LAST_FFI,
enforthCursesKeyQuestion, enforthCursesKey, enforthCursesEmit);



/* -------------------------------------
Expand All @@ -125,53 +122,6 @@ static ENFORTH enforth(

int main(int argc, char **argv)
{
/* Add a couple of hand-coded definitions. */
const uint8_t favnumDef[] = {
0x00, // DOCOLON
'F',
'A',
'V',
'N',
'U',
0x80 | 'M',
0x0b, // CHARLIT
27,
0x7f }; // EXIT
enforth.addDefinition(favnumDef, sizeof(favnumDef));

const uint8_t twoxDef[] = {
0x00, // DOCOLON
'2',
0x80 | 'X',
0x02, // DUP
0x04, // +
0x7f }; // EXIT
enforth.addDefinition(twoxDef, sizeof(twoxDef));

const uint8_t randDef[] = {
0x06, // DOFFI0
((uint32_t)&FFIDEF_rand ) & 0xff, // FFIdef LSB
((uint32_t)&FFIDEF_rand >> 8) & 0xff, // FFIdef
((uint32_t)&FFIDEF_rand >> 16) & 0xff, // FFIdef
((uint32_t)&FFIDEF_rand >> 24) & 0xff}; // FFIdef MSB
enforth.addDefinition(randDef, sizeof(randDef));

const uint8_t srandDef[] = {
0x07, // DOFFI1
((uint32_t)&FFIDEF_srand ) & 0xff, // FFIdef LSB
((uint32_t)&FFIDEF_srand >> 8) & 0xff, // FFIdef
((uint32_t)&FFIDEF_srand >> 16) & 0xff, // FFIdef
((uint32_t)&FFIDEF_srand >> 24) & 0xff}; // FFIdef MSB
enforth.addDefinition(srandDef, sizeof(srandDef));

const uint8_t clearDef[] = {
0x06, // DOFFI0
((uint32_t)&FFIDEF_clear ) & 0xff, // FFIdef LSB
((uint32_t)&FFIDEF_clear >> 8) & 0xff, // FFIdef
((uint32_t)&FFIDEF_clear >> 16) & 0xff, // FFIdef
((uint32_t)&FFIDEF_clear >> 24) & 0xff}; // FFIdef MSB
enforth.addDefinition(clearDef, sizeof(clearDef));

/* Initialize curses: disable line buffering and local echo, enable
* line-oriented scrolling. */
initscr();
Expand All @@ -180,8 +130,19 @@ int main(int argc, char **argv)
idlok(stdscr, TRUE);
scrollok(stdscr, TRUE);

/* Initialize Enforth. */
enforth_init(
&enforthVM,
enforthDict, sizeof(enforthDict),
LAST_FFI,
enforthCursesKeyQuestion, enforthCursesKey, enforthCursesEmit);

/* Add a couple of definitions. */
enforth_evaluate(&enforthVM, ": favnum 27 ;");
enforth_evaluate(&enforthVM, ": 2x dup + ;");

/* Launch the enforth interpreter. */
enforth.go();
enforth_go(&enforthVM);

/* Destroy curses. */
endwin();
Expand Down

0 comments on commit 3d3e60c

Please sign in to comment.