-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.dlr
97 lines (87 loc) · 2.25 KB
/
a.dlr
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
include "def.dlr";
defun print (((funptr () str) getter)) void {
puts (call-funptr getter);
};
defmacro try-lambdas {
print (freestanding-lambda () str "hallo");
empty-rtv;
};
try-lambdas;
defmacro debug-sizeof {
var (array 255 char) dummy;
var (ptr char) dummy2;
printf "%i\n" (sizeof-expr (ptr-deref dummy2));
printf "%i\n" (sizeof-expr dummy);
printf "%i\n" (sizeof-expr dummy:0);
empty-rtv;
};
debug-sizeof;
defstruct myval (
union (
u8 T; # Found in list.h:22:17
u8 A; # Found in list.h:22:17
u8 B; # Found in list.h:22:17
u8 C; # Found in list.h:22:17
u32 D; # Found in list.h:22:17
float E;
);
u8 Reserved; # Found in list.h:24:17
u32 CharIdx; # Found in list.h:26:16
u16 FileIdx; # Found in list.h:27:18
); # Found in list.h:18:8
defun main2 () void {
#printf "sizeof int: %i\n" (sizeof-type (eval-type (quote i32)));
#printf "sizeof int: %i\n" (sizeof i32);
#printf "sizeof long: %i\n" (sizeof-type (eval-type (quote i64)));
#printf "sizeof long: %i\n" (sizeof i64);
var myval b;
#assign (ptr-deref (ptr-to c)) 2;
assign b:Reserved 0;
assign b:D 300;
printf "hello %i\n" (convert i32 b:T);
printf "hello %i\n" b:Reserved;
var (array 10 char) name;
fgets (ptr-to name) (sizeof-expr name) stdin;
assign name:4 '\n';
assign (ptr-deref (strchr (ptr-to name) 10)) 0;
printf "Hello, %s!\n" (ptr-to name);
};
defmacro run {
main2;
empty-rtv;
};
#run;
defmacro compile {
:= mod (LLVMModuleCreateWithName "test");
copy_symbol_to_module "main" mod;
LLVMWriteBitcodeToFile mod "tmp.bc";
var (array 255 char) cmd;
snprintf (ptr-to cmd) 255 "clang %s -o test -O3" "tmp.bc";
system (ptr-to cmd);
empty-rtv;
};
#compile;
defun repl () void {
var (array 255 char) buf;
var (array 128 char) filename;
:= done 0;
:= n 0;
while (not done) {
printf "> ";
assign buf:0 0;
fgets (ptr-to buf) 255 stdin;
cond (= buf:1 0) {
puts "";
break;
};
snprintf (ptr-to filename) 128 "<repl-%i>" n;
:= list (read-string (ptr-to buf) (ptr-to filename));
:= fun (lower-macroproto (ptr-to filename));
funbody fun (car list) 0;
call-fun-macro fun list;
assign n (+ n 1);
};
};
defun main () void { repl; };
defmacro run-repl { repl; empty-rtv; };
run-repl;