Sim works.
This commit is contained in:
@ -89,7 +89,7 @@ LINK64 = "$(shell $(LSQ) ${MSVS}/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/link.exe |
|
|||||||
RC32 = "$(shell $(LSQ) ${MSKITS}/*/bin/*/x86/rc.exe | head -n 1)"
|
RC32 = "$(shell $(LSQ) ${MSKITS}/*/bin/*/x86/rc.exe | head -n 1)"
|
||||||
RC64 = "$(shell $(LSQ) ${MSKITS}/*/bin/*/x64/rc.exe | head -n 1)"
|
RC64 = "$(shell $(LSQ) ${MSKITS}/*/bin/*/x64/rc.exe | head -n 1)"
|
||||||
|
|
||||||
UNIT_TESTS = unit_tests_posix
|
UNIT_TESTS = unit_tests_posix unit_tests_esp32_sim
|
||||||
|
|
||||||
# Selectively enable windows if tools available
|
# Selectively enable windows if tools available
|
||||||
DEPLOYABLE := 1
|
DEPLOYABLE := 1
|
||||||
@ -140,6 +140,12 @@ unit_tests: $(UNIT_TESTS)
|
|||||||
unit_tests_posix: $(POSIX)/ueforth common/all_tests.fs
|
unit_tests_posix: $(POSIX)/ueforth common/all_tests.fs
|
||||||
$^
|
$^
|
||||||
|
|
||||||
|
unit_tests_esp32_sim: \
|
||||||
|
$(ESP32_SIM)/Esp32forth-sim \
|
||||||
|
common/ansi.fs \
|
||||||
|
common/all_tests.fs
|
||||||
|
echo "include $(word 2,$^) include $(word 3,$^) \n1 terminate" | $<
|
||||||
|
|
||||||
unit_tests_win32: $(WINDOWS)/uEf32.exe common/all_tests.fs
|
unit_tests_win32: $(WINDOWS)/uEf32.exe common/all_tests.fs
|
||||||
wine $^
|
wine $^
|
||||||
|
|
||||||
@ -340,8 +346,8 @@ $(ESP32)/ESP32forth:
|
|||||||
ESP32_PARTS = common/replace.js \
|
ESP32_PARTS = common/replace.js \
|
||||||
esp32/template.ino \
|
esp32/template.ino \
|
||||||
common/opcodes.h \
|
common/opcodes.h \
|
||||||
common/calling.h \
|
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
|
common/calling.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
common/interp.h \
|
common/interp.h \
|
||||||
esp32/options.h \
|
esp32/options.h \
|
||||||
|
|||||||
@ -435,7 +435,7 @@ e: test-forth-namespace
|
|||||||
out: GETPROCADDRESS
|
out: GETPROCADDRESS
|
||||||
;e
|
;e
|
||||||
|
|
||||||
[ELSE]
|
[ELSE] DEFINED? posix [IF]
|
||||||
|
|
||||||
e: test-forth-namespace
|
e: test-forth-namespace
|
||||||
internals voclist
|
internals voclist
|
||||||
@ -477,4 +477,4 @@ e: test-forth-namespace
|
|||||||
out: DLSYM
|
out: DLSYM
|
||||||
;e
|
;e
|
||||||
|
|
||||||
[THEN]
|
[THEN] [THEN]
|
||||||
|
|||||||
@ -18,7 +18,11 @@ DEFINED? windows [IF]
|
|||||||
also windows
|
also windows
|
||||||
: sysexit ( n -- ) ExitProcess ;
|
: sysexit ( n -- ) ExitProcess ;
|
||||||
[ELSE]
|
[ELSE]
|
||||||
also posix
|
DEFINED? posix [IF]
|
||||||
|
also posix
|
||||||
|
[ELSE]
|
||||||
|
: sysexit ( n -- ) terminate ;
|
||||||
|
[THEN]
|
||||||
[THEN]
|
[THEN]
|
||||||
|
|
||||||
( Support for eval tests )
|
( Support for eval tests )
|
||||||
|
|||||||
@ -14,6 +14,6 @@
|
|||||||
|
|
||||||
( Words with OS assist )
|
( Words with OS assist )
|
||||||
: allocate ( n -- a ior ) malloc dup 0= ;
|
: allocate ( n -- a ior ) malloc dup 0= ;
|
||||||
: free ( a -- ior ) sysfree drop 0 ;
|
: free ( a -- ior ) sysfree 0 ;
|
||||||
: resize ( a n -- a ior ) realloc dup 0= ;
|
: resize ( a n -- a ior ) realloc dup 0= ;
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,9 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "esp32/config.h"
|
#define HEAP_SIZE (100 * 1024 + 1024 * 1024)
|
||||||
|
#define STACK_CELLS 512
|
||||||
|
|
||||||
#include "esp32/options.h"
|
#include "esp32/options.h"
|
||||||
#include "common/opcodes.h"
|
#include "common/opcodes.h"
|
||||||
#include "common/floats.h"
|
#include "common/floats.h"
|
||||||
@ -34,9 +36,13 @@ PLATFORM_SIMULATED_OPCODE_LIST
|
|||||||
#include "common/interp.h"
|
#include "common/interp.h"
|
||||||
#include "gen/esp32_boot.h"
|
#include "gen/esp32_boot.h"
|
||||||
#include "esp32/main.cpp"
|
#include "esp32/main.cpp"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
static cell_t *simulated(cell_t *sp, const char *op) {
|
static cell_t *simulated(cell_t *sp, const char *op) {
|
||||||
if (op == STR_MALLOC) {
|
if (op == STR_MALLOC) {
|
||||||
@ -49,10 +55,12 @@ static cell_t *simulated(cell_t *sp, const char *op) {
|
|||||||
--sp;
|
--sp;
|
||||||
return sp;
|
return sp;
|
||||||
} else if (op == STR_SERIAL_READ_BYTES) {
|
} else if (op == STR_SERIAL_READ_BYTES) {
|
||||||
sp[-1] = read(0, (void *) sp[-1], sp[0]); --sp;
|
cell_t len = *sp--;
|
||||||
|
*sp = read(0, (void *) *sp, len);
|
||||||
return sp;
|
return sp;
|
||||||
} else if (op == STR_SERIAL_WRITE) {
|
} else if (op == STR_SERIAL_WRITE) {
|
||||||
sp[-1] = write(1, (void *) sp[-1], sp[0]); --sp;
|
cell_t len = *sp--;
|
||||||
|
*sp = write(1, (void *) *sp, len);
|
||||||
return sp;
|
return sp;
|
||||||
} else if (op == STR_MS_TICKS) {
|
} else if (op == STR_MS_TICKS) {
|
||||||
struct timespec tm;
|
struct timespec tm;
|
||||||
@ -62,7 +70,8 @@ static cell_t *simulated(cell_t *sp, const char *op) {
|
|||||||
} else if (op == STR_RAW_YIELD) {
|
} else if (op == STR_RAW_YIELD) {
|
||||||
return sp;
|
return sp;
|
||||||
} else if (op == STR_SPIFFS_BEGIN) {
|
} else if (op == STR_SPIFFS_BEGIN) {
|
||||||
sp -= 2; *sp = 0;
|
sp -= 2;
|
||||||
|
*sp = 0;
|
||||||
return sp;
|
return sp;
|
||||||
} else if (op == STR_pinMode) {
|
} else if (op == STR_pinMode) {
|
||||||
sp -= 2;
|
sp -= 2;
|
||||||
@ -71,17 +80,46 @@ static cell_t *simulated(cell_t *sp, const char *op) {
|
|||||||
sp -= 2;
|
sp -= 2;
|
||||||
return sp;
|
return sp;
|
||||||
} else if (op == STR_gpio_install_isr_service) {
|
} else if (op == STR_gpio_install_isr_service) {
|
||||||
--sp;
|
|
||||||
*sp = 0;
|
*sp = 0;
|
||||||
return sp;
|
return sp;
|
||||||
} else if (op == STR_SERIAL_AVAILABLE) {
|
} else if (op == STR_SERIAL_AVAILABLE) {
|
||||||
*++sp = 1;
|
*++sp = 1;
|
||||||
return sp;
|
return sp;
|
||||||
} else if (op == STR_TERMINATE) {
|
} else if (op == STR_TERMINATE) {
|
||||||
exit(*sp);
|
exit(*sp--);
|
||||||
|
return sp;
|
||||||
|
} else if (op == STR_R_O) {
|
||||||
|
*++sp = O_RDONLY;
|
||||||
|
return sp;
|
||||||
|
} else if (op == STR_OPEN_FILE) {
|
||||||
|
cell_t mode = *sp--;
|
||||||
|
cell_t len = *sp--;
|
||||||
|
char filename[1024];
|
||||||
|
memcpy(filename, (void *) *sp, len); filename[len] = 0;
|
||||||
|
cell_t ret = open(filename, mode, 0777);
|
||||||
|
*sp = ret;
|
||||||
|
*++sp = ret < 0 ? errno : 0;
|
||||||
|
return sp;
|
||||||
|
} else if (op == STR_FILE_SIZE) {
|
||||||
|
struct stat st;
|
||||||
|
cell_t w = fstat(*sp, &st);
|
||||||
|
*sp = (cell_t) st.st_size;
|
||||||
|
*++sp = w < 0 ? errno : 0;
|
||||||
|
return sp;
|
||||||
|
} else if (op == STR_READ_FILE) {
|
||||||
|
cell_t fd = *sp--;
|
||||||
|
cell_t len = *sp--;
|
||||||
|
cell_t ret = read(fd, (void *) *sp, len);
|
||||||
|
*sp = ret;
|
||||||
|
*++sp = ret < 0 ? errno : 0;
|
||||||
|
return sp;
|
||||||
|
} else if (op == STR_CLOSE_FILE) {
|
||||||
|
cell_t ret = close(*sp);
|
||||||
|
*sp = ret ? errno : 0;
|
||||||
return sp;
|
return sp;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "MISSING SIM OPCODE: %s\n", op);
|
fprintf(stderr, "MISSING SIM OPCODE: %s\n", op);
|
||||||
|
exit(1);
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,4 +18,3 @@ posix
|
|||||||
: free ( a -- ior ) sysfree drop 0 ;
|
: free ( a -- ior ) sysfree drop 0 ;
|
||||||
: resize ( a n -- a ior ) realloc dup 0= ;
|
: resize ( a n -- a ior ) realloc dup 0= ;
|
||||||
forth
|
forth
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user