-
Notifications
You must be signed in to change notification settings - Fork 5
/
c3.h
160 lines (142 loc) · 4.54 KB
/
c3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef __C3_H__
#define __C3_H__
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
enum { STOP_LOAD = 99, ALL_DONE = 999, VERSION = 20241110 };
#if (defined __x86_64 || defined _WIN64)
#define CELL_T int64_t
#define UCELL_T uint64_t
#define FLOAT_T double
#define CELL_SZ 8
#define addrFMT ": %s $%llx ;"
#else
#define CELL_T int32_t
#define UCELL_T uint32_t
#define FLOAT_T float
#define CELL_SZ 4
#define addrFMT ": %s $%lx ;"
#endif
typedef CELL_T cell_t;
typedef UCELL_T ucell_t;
typedef FLOAT_T flt_t;
typedef uint8_t byte;
#define ToCP(x) (char*)(x)
#define BTW(x,l,h) ((l<=x) && (x<=h))
#define PC(c) printChar(c)
#define BCASE break; case
#define NCASE goto next; case
#define RCASE return pc; case
#ifndef MIN
#define MIN(a,b) ((a)<(b))?(a):(b)
#define MAX(a,b) ((a)>(b))?(a):(b)
#endif
#if (defined _WIN32 || defined _WIN64)
#define isPC
#define IS_WINDOWS
#define __EDITOR__
// #define _SYS_LOAD_
#elif (defined __i386 || defined __x86_64 || defined IS_LINUX)
#define isPC
#ifndef IS_LINUX
#define IS_LINUX
#endif
#define __EDITOR__
// #define _SYS_LOAD_
#else
// Not a PC, must be a development board
// NOTE: Change these values for a specific board
// For the Pico, I use: https://github.com/earlephilhower/arduino-pico
// I use these for the Teensy-4 and the Pico
#define isBOARD 1
#define MAX_LINES 100
#define CODE_SZ 64*1024
#define VARS_SZ 96*1024
#define STK_SZ 128
#define LSTK_SZ 3*25 // 25 nested loops
#define REGS_SZ 10*25 // 25 nested +REGS
#define TIB_SZ 256
#define NAME_LEN 16
#define NEEDS_ALIGN
#define __EDITOR__
#define _SYS_LOAD_
// #define _TeensyFS_ // LittleFS for Teensy
#define _PicoFS_ // LittleFS for Pico
// #define _NoFS_ // No FS
#endif
#ifndef CODE_SZ
// Default for PCs
#define MAX_LINES 250
#define CODE_SZ 96*1024
#define VARS_SZ 4*1024*1024
#define STK_SZ 256
#define LSTK_SZ 50*3 // 50 nested loops
#define REGS_SZ 50*10 // 50 nested +REGS
#define TIB_SZ 1024
#define NAME_LEN 20
// #define _SYS_LOAD_
#endif
typedef union { cell_t i; flt_t f; char *c; } se_t;
typedef struct { cell_t sp; se_t stk[STK_SZ+1]; } stk_t;
typedef struct { cell_t xt; byte f, lex, len; char name[NAME_LEN+1]; } dict_t;
// These are defined in the VM
extern cell_t lstk[LSTK_SZ+1], lsp, output_fp;
extern cell_t state, base, reg[REGS_SZ], reg_base, t1, n1, lexicon;
extern char tib[TIB_SZ], *in, *y, *here;
extern char vars[VARS_SZ];
extern void push(cell_t x);
extern cell_t pop();
extern char *cpop();
extern void fpush(flt_t x);
extern flt_t fpop();
extern void rpush(char *x);
extern char *rpop();
extern void CComma(cell_t x);
extern void Comma(cell_t x);
extern void fill(char *d, char val, int num);
extern char *strEnd(char *s);
extern void strCat(char *d, const char *s);
extern void strCatC(char *d, const char c);
extern void strCpy(char *d, const char *s);
extern int strLen(const char *d);
extern char *lTrim(char *d);
extern char *rTrim(char *d);
extern int lower(int x);
extern int upper(int x);
extern void ParseLine(const char *x);
extern void parseF(const char *fmt, ...);
extern int strEqI(const char *s, const char *d);
extern int strEq(const char *d, const char *s);
extern void printStringF(const char *fmt, ...);
extern char *iToA(cell_t N, int b);
extern int isTempWord(const char *w);
extern char isRegOp(const char *w);
extern int nextWord();
extern void doDefine(char *wd);
extern int doFind(const char *n);
extern int isBase10(const char *wd);
extern int isNum(const char *wd);
extern void doType(const char *str);
extern char *doStringOp(char *pc);
extern char *doSysOp(char *pc);
extern char *doFloatOp(char *pc);
extern void Run(char *pc);
extern int doReg(const char *w);
extern void c3Init();
// These are functions the VM calls
extern void Store(char *addr, cell_t val);
extern cell_t Fetch(const char *addr);
extern void printString(const char *str);
extern void printChar(char c);
extern char *doUser(char *pc, int ir);
extern int key();
extern int qKey();
extern cell_t sysTime();
extern void sysLoad();
extern void loadUserWords();
// Files support
#include "file.h"
// Editor
extern void editBlock(cell_t blkNum);
extern cell_t edScrH;
#endif // __C3_H__