Refactor our bits.h to help with asm.js version.
This commit is contained in:
7
Makefile
7
Makefile
@ -232,6 +232,7 @@ $(GEN)/esp32_boot.h: tools/source_to_string.js $(ESP32_BOOT) | $(GEN)
|
|||||||
$(GEN)/dump_web_opcodes: \
|
$(GEN)/dump_web_opcodes: \
|
||||||
web/dump_web_opcodes.c \
|
web/dump_web_opcodes.c \
|
||||||
common/opcodes.h \
|
common/opcodes.h \
|
||||||
|
common/bits.h \
|
||||||
common/floats.h | $(GEN)
|
common/floats.h | $(GEN)
|
||||||
$(CXX) $(CFLAGS) $< -o $@
|
$(CXX) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
@ -315,6 +316,7 @@ $(POSIX)/ueforth: \
|
|||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
common/interp.h \
|
common/interp.h \
|
||||||
|
common/bits.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
$(GEN)/posix_boot.h | $(POSIX)
|
$(GEN)/posix_boot.h | $(POSIX)
|
||||||
$(CXX) $(CFLAGS) $< -o $@ $(LIBS)
|
$(CXX) $(CFLAGS) $< -o $@ $(LIBS)
|
||||||
@ -337,6 +339,7 @@ $(WINDOWS)/uEf32.obj: \
|
|||||||
common/calls.h \
|
common/calls.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
|
common/bits.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
windows/interp.h \
|
windows/interp.h \
|
||||||
$(GEN)/windows_boot.h | $(WINDOWS)
|
$(GEN)/windows_boot.h | $(WINDOWS)
|
||||||
@ -354,6 +357,7 @@ $(WINDOWS)/uEf64.obj: \
|
|||||||
common/calls.h \
|
common/calls.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
|
common/bits.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
windows/interp.h \
|
windows/interp.h \
|
||||||
$(GEN)/windows_boot.h | $(WINDOWS)
|
$(GEN)/windows_boot.h | $(WINDOWS)
|
||||||
@ -387,6 +391,7 @@ $(ESP32_SIM)/Esp32forth-sim: \
|
|||||||
common/floats.h \
|
common/floats.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
|
common/bits.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
common/interp.h \
|
common/interp.h \
|
||||||
$(GEN)/esp32_boot.h \
|
$(GEN)/esp32_boot.h \
|
||||||
@ -408,6 +413,7 @@ ESP32_PARTS = tools/replace.js \
|
|||||||
common/extra_opcodes.h \
|
common/extra_opcodes.h \
|
||||||
common/floats.h \
|
common/floats.h \
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
|
common/bits.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
common/interp.h \
|
common/interp.h \
|
||||||
esp32/options.h \
|
esp32/options.h \
|
||||||
@ -424,6 +430,7 @@ $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth
|
|||||||
extra_opcodes=@common/extra_opcodes.h \
|
extra_opcodes=@common/extra_opcodes.h \
|
||||||
calling=@common/calling.h \
|
calling=@common/calling.h \
|
||||||
floats=@common/floats.h \
|
floats=@common/floats.h \
|
||||||
|
bits=@common/bits.h \
|
||||||
core=@common/core.h \
|
core=@common/core.h \
|
||||||
interp=@common/interp.h \
|
interp=@common/interp.h \
|
||||||
options=@esp32/options.h \
|
options=@esp32/options.h \
|
||||||
|
|||||||
18
common/bits.h
Normal file
18
common/bits.h
Normal 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
|
||||||
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
static char filename[PATH_MAX];
|
static char filename[PATH_MAX];
|
||||||
|
|
||||||
|
{{bits}}
|
||||||
{{core}}
|
{{core}}
|
||||||
{{interp}}
|
{{interp}}
|
||||||
{{boot}}
|
{{boot}}
|
||||||
|
|||||||
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
#include "common/opcodes.h"
|
#include "common/opcodes.h"
|
||||||
#include "common/floats.h"
|
#include "common/floats.h"
|
||||||
|
#include "common/bits.h"
|
||||||
|
|
||||||
|
#define VOCABULARY_LIST V(forth) V(internals)
|
||||||
|
|
||||||
#define PLATFORM_OPCODE_LIST \
|
#define PLATFORM_OPCODE_LIST \
|
||||||
X("CALL", CALL, sp = Call(sp|0, tos|0) | 0; DROP) \
|
X("CALL", CALL, sp = Call(sp|0, tos|0) | 0; DROP) \
|
||||||
@ -29,6 +32,19 @@ enum {
|
|||||||
#undef XV
|
#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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc == 2 && strcmp(argv[1], "cases") == 0) {
|
if (argc == 2 && strcmp(argv[1], "cases") == 0) {
|
||||||
#define XV(flags, name, op, code) \
|
#define XV(flags, name, op, code) \
|
||||||
@ -37,7 +53,15 @@ int main(int argc, char *argv[]) {
|
|||||||
OPCODE_LIST
|
OPCODE_LIST
|
||||||
#undef XV
|
#undef XV
|
||||||
} else if (argc == 2 && strcmp(argv[1], "dict") == 0) {
|
} 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
|
PLATFORM_OPCODE_LIST
|
||||||
OPCODE_LIST
|
OPCODE_LIST
|
||||||
#undef XV
|
#undef XV
|
||||||
|
|||||||
Reference in New Issue
Block a user