Refactor our bits.h to help with asm.js version.

This commit is contained in:
Brad Nelson
2022-07-10 19:38:19 -07:00
parent 9a2555d884
commit 992f243c09
4 changed files with 51 additions and 1 deletions

View File

@ -232,6 +232,7 @@ $(GEN)/esp32_boot.h: tools/source_to_string.js $(ESP32_BOOT) | $(GEN)
$(GEN)/dump_web_opcodes: \
web/dump_web_opcodes.c \
common/opcodes.h \
common/bits.h \
common/floats.h | $(GEN)
$(CXX) $(CFLAGS) $< -o $@
@ -315,6 +316,7 @@ $(POSIX)/ueforth: \
common/calling.h \
common/floats.h \
common/interp.h \
common/bits.h \
common/core.h \
$(GEN)/posix_boot.h | $(POSIX)
$(CXX) $(CFLAGS) $< -o $@ $(LIBS)
@ -337,6 +339,7 @@ $(WINDOWS)/uEf32.obj: \
common/calls.h \
common/calling.h \
common/floats.h \
common/bits.h \
common/core.h \
windows/interp.h \
$(GEN)/windows_boot.h | $(WINDOWS)
@ -354,6 +357,7 @@ $(WINDOWS)/uEf64.obj: \
common/calls.h \
common/calling.h \
common/floats.h \
common/bits.h \
common/core.h \
windows/interp.h \
$(GEN)/windows_boot.h | $(WINDOWS)
@ -387,6 +391,7 @@ $(ESP32_SIM)/Esp32forth-sim: \
common/floats.h \
common/calling.h \
common/floats.h \
common/bits.h \
common/core.h \
common/interp.h \
$(GEN)/esp32_boot.h \
@ -408,6 +413,7 @@ ESP32_PARTS = tools/replace.js \
common/extra_opcodes.h \
common/floats.h \
common/calling.h \
common/bits.h \
common/core.h \
common/interp.h \
esp32/options.h \
@ -424,6 +430,7 @@ $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth
extra_opcodes=@common/extra_opcodes.h \
calling=@common/calling.h \
floats=@common/floats.h \
bits=@common/bits.h \
core=@common/core.h \
interp=@common/interp.h \
options=@esp32/options.h \

18
common/bits.h Normal file
View File

@ -0,0 +1,18 @@
// Copyright 2022 Bradley D. Nelson
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#define IMMEDIATE 1
#define SMUDGE 2
#define BUILTIN_FORK 4
#define BUILTIN_MARK 8

View File

@ -14,6 +14,7 @@
static char filename[PATH_MAX];
{{bits}}
{{core}}
{{interp}}
{{boot}}

View File

@ -17,6 +17,9 @@
#include "common/opcodes.h"
#include "common/floats.h"
#include "common/bits.h"
#define VOCABULARY_LIST V(forth) V(internals)
#define PLATFORM_OPCODE_LIST \
X("CALL", CALL, sp = Call(sp|0, tos|0) | 0; DROP) \
@ -29,6 +32,19 @@ enum {
#undef XV
};
enum {
#define V(name) VOC_ ## name,
VOCABULARY_LIST
#undef V
};
enum {
#define V(name) VOC_ ## name ## _immediate = VOC_ ## name + (IMMEDIATE << 8),
VOCABULARY_LIST
#undef V
};
int main(int argc, char *argv[]) {
if (argc == 2 && strcmp(argv[1], "cases") == 0) {
#define XV(flags, name, op, code) \
@ -37,7 +53,15 @@ int main(int argc, char *argv[]) {
OPCODE_LIST
#undef XV
} else if (argc == 2 && strcmp(argv[1], "dict") == 0) {
#define XV(flags, name, op, code) printf(" create(" #name ", %d);\n", OP_ ## op);
#define V(name) \
printf(" create(\"" #name "-builtins\", %d);\n", BUILTIN_FORK, OP_DOCREATE); \
printf(" COMMA(%d);\n", VOC_ ## name);
VOCABULARY_LIST
#undef V
#define XV(flags, name, op, code) \
printf(" builtin(" #name ", %d, %d, %d);\n", \
((VOC_ ## flags >> 8) & 0xff) | BUILTIN_MARK, \
(VOC_ ## flags & 0xff), OP_ ## op);
PLATFORM_OPCODE_LIST
OPCODE_LIST
#undef XV