climp

Dirty interpreter for the limp programming language in C

git clone https://git.8pit.net/climp.git

 1define(`IFEQ', `
 2$2 := $2 - $1;
 3if $2 then
 4	$4
 5else
 6	$3
 7end
 8')
 9
10define(`AND', `
11IFEQ(1, $1, IFEQ(1, $2, rs := 1, rs := 0), rs := 0)
12')
13
14define(`OR', `
15IFEQ(1, $1, rs := 1, IFEQ(1, $2, rs := 1, rs := 0))
16')
17
18define(`NOT',
19IFEQ(1, $1, rs := 0, rs := 1)
20)
21
22# Valid boolean values are 0 and 1, however, user input is not verified.
23# 0 means false in this case and 1 means true. E.g. AND(1, 1) sets rs to 1.
24
25let af := 0; # First boolean value.
26let as := 0; # Second boolean value only read for binary operations.
27
28# Boolean operator:
29# 0 -> NOT (unarry operator)
30# 1 -> AND (binary operator)
31# 2 -> OR  (binary operator)
32let op := 0;
33
34# Result as a boolean value.
35let rs := 0;
36
37? af;
38? op;
39
40let opcopy := op;
41IFEQ(0, op,
42	NOT(af),
43	rs := 0 - 1);
44op := opcopy;
45
46if rs + 1 then
47	! rs
48else
49	? as;
50
51	IFEQ(1, op,
52		AND(af, as),
53		rs := 0 - 1);
54	op := opcopy;
55
56	if rs + 1 then
57		! rs
58	else
59		IFEQ(2, op,
60			OR(af, as),
61			rs := 0 - 1);
62		op := opcopy;
63
64		! rs
65	end
66end