-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfalse.h
More file actions
135 lines (106 loc) · 5.75 KB
/
false.h
File metadata and controls
135 lines (106 loc) · 5.75 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
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
#pragma once
#include <stdbool.h>
#include <wchar.h>
/*
https://strlen.com/files/lang/false/false.txt
A Forth type language.
https://forth-standard.org/standard/core
Extensions (marked "Ext" below) are inspired by:
https://esolangs.org/wiki/DUP
https://esolangs.org/wiki/Falsish
https://wiki.laptop.org/go/Forth_stack_operators
Stack Diagram Token Description
===================================== ===== ===========
( num -- ) . print-number
"STR" print string
( ch -- ) , print-character
( -- ch ) ^ character from stdin
( -- ) ß flush (nop) (macOS Option-ß)
( -- ) B flush (nop)
( -- ) {..} comment
( -- func ) [..] lambda
( -- num ) 0-9 number
( -- var ) a-z variable
( -- ch ) 'C character
Ext ( bool -- ) ∫ assert true (macOS Option-B)
( x var -- ) : assign
( var -- x ) ; dereference
( func -- ) ! call
( x -- -x) _ negate
( term term -- sum ) + add
( term term -- diff ) - subtract
( factor factor -- product ) * multiply
( numer demon -- quot ) / divide
Ext ( numer denom -- rem quot ) ÷ (Forth) /MOD (macOS Option-/)
( x y -- bool ) = equal-to
Ext ( x y -- bool ) ≠ not-equal-to (macOS Option-=)
Ext ( x y -- bool ) < less-than
( x y -- bool ) > greater-than
Ext ( x y -- bool ) ≤ less-than-or-equal-to (macOS Option-<)
Ext ( x y -- bool ) ≥ greater-than-or-equal-to (macOS Option->)
( x y -- num ) & and (bitwise)
( x y -- num ) | or (bitwise)
( x -- num ) ~ invert (bitwise)
Ext ( x y -- num ) ⊻ xor (bitwise) (U+22BB)
Ext ( x y -- num ) « lshift (macOS Option-\)
Ext ( x y -- num ) » rshift (macOS Shift-Option-\)
Ext ( -- num ) § stack depth
( a -- a a ) $ dup
( a -- ) % drop
( a b -- b a ) \ swap
( a b c -- b c a ) @ rot
Ext ( a b -- a b a ) £ over (macOS Option-3)
Ext ( a b -- b ) ‰ nip (macOS Shift-Option-r)
Ext ( a b -- b a b ) € tuck (macOS Shift-Option-2)
Ext ( a b -- a b a b ) Ø 2dup (macOS Shift-Option-o)
Ext ( a b c -- c b a ) ® reverse (macOS Option-r)
( xu ... x1 x0 u -- xu ... x1 x0 xu ) ø pick (macOS Option-o)
( xu ... x1 x0 u -- xu ... x1 x0 xu ) O pick
Ext ( xu xu-1...x0 u -- xu-1...x0 xu ) ™ roll (macOS Option-2)
( bool func -- ) ? if-then
Ext ( bool func func -- ) ¿ if-then-else (macOS Option-?)
( func func -- ) # while
Unused ASCII characters
` unused (Amiga emitword)
A unused
C-N unused
P-Z unused
( unused
) unused
*/
struct config {
/// Command line argument count.
/// @note: Minimum one, since file name is the first element.
int argc;
/// Command line arguments.
/// @note: The first element is the source file name.
char **argv;
/// Source file contents.
const char *str;
/// Enable extensions.
bool extensions;
/// Report fatal error.
/// @param arg Points to the current symbol in the source file contents @c str.
void (*fatal)(const struct config config, const char *pos, const char *msg);
/// Trace execution.
/// @param arg Points to the current symbol in the source file contents @c str.
void (*log_trace)(const struct config config, wchar_t wc, const char *pos);
/// Log stack operations.
/// @param op Describes the stack operation, for example @c "push".
/// @param dump Contains a stack dump.
void (*log_stack)(const struct config config, const char *op, const char *dump);
/// Emit number.
void (*emit_number)(int);
/// Emit wide character.
/// @note Strings are emitted according to the source encoding.
void (*emit_wchar)(wchar_t);
/// Emit character.
/// @note Octets read from stdin are emitted as-is.
void (*emit_char)(char c);
/// Get input.
int (*input)(void);
/// Read until newline.
void (*flush)(void);
};
/// @return int Zero on success, one otherwise.
int interpret(struct config config);