-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcf.h
More file actions
82 lines (70 loc) · 2.28 KB
/
cf.h
File metadata and controls
82 lines (70 loc) · 2.28 KB
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
// A ColorForth and Tachyon inspired system, MIT license.
#ifndef __CF_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#define VERSION 20260118
#define BOOT_FN1 "cf-boot.fth"
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable : 4996) // stupid deprecated warnings
#define IS_WINDOWS 1
#define BOOT_FN2 "\\bin\\cf-boot.fth"
#define strEqI(s, d) (_strcmpi(s, d) == 0)
#else
#include <strings.h>
#define BOOT_FN2 "/home/chris/bin/cf-boot.fth"
#define strEqI(s, d) (strcasecmp(s, d) == 0)
#endif
#define MEM_SZ 16*(1024*1024)
#define STK_SZ 63
#define LSTK_SZ 60
#define TSTK_SZ 63
#define btwi(n,l,h) ((l<=n) && (n<=h))
#define NCASE goto next; case
#define BCASE break; case
#if INTPTR_MAX > INT32_MAX
#define CELL_T int64_t
#define UCELL_T uint64_t
#define CELL_SZ 8
#define NUM_BITS 0xE000000000000000
#define NUM_MASK 0x1FFFFFFFFFFFFFFF
#define NAME_MAX 21
#else
#define CELL_T int32_t
#define UCELL_T uint32_t
#define CELL_SZ 4
#define NUM_BITS 0xE0000000
#define NUM_MASK 0x1FFFFFFF
#define NAME_MAX 25
#endif
enum { DEFINE=1, COMPILE, INTERP, COMMENT };
enum { _IMMED=1, _INLINE=2 };
typedef CELL_T cell;
typedef UCELL_T ucell;
typedef unsigned short ushort;
typedef unsigned char byte;
typedef struct { cell xt; byte flags, len; char name[NAME_MAX+1]; } DE_T;
typedef struct { cell op; const char *name; byte fl; } PRIM_T;
// These are defined by cf.c
extern void cfInit();
extern void cfOuter(const char *src);
extern void addLit(char *nm, cell val);
extern cell state, outputFp;
extern byte mem[];
// cf.c needs these to be defined
extern void zType(const char *str);
extern void emit(const char ch);
extern void ttyMode(int isRaw);
extern int key();
extern int qKey();
extern cell timer();
extern void ms(cell sleepForMS);
extern cell fOpen(cell name, cell mode);
extern void fClose(cell fh);
extern cell fRead(cell buf, cell sz, cell fh);
extern cell fWrite(cell buf, cell sz, cell fh);
extern cell fSeek(cell fh, cell offset);
#endif // __CF_H__