summaryrefslogtreecommitdiff
path: root/module/debug.m
blob: 4abfe58542fbe9dc3a2811fc7167df7c92318fe8 (plain)
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
Debug: module
{
	PATH:	con "/dis/lib/debug.dis";

	Terror, Tid, Tadt, Tadtpick, Tarray, Tbig, Tbyte, Tchan, Treal,
	Tfn, Targ, Tlocal, Tglobal, Tint, Tlist, Tmodule, Tnil, Tnone,
	Tref, Tstring, Ttuple, Tend, Targs, Tslice, Tpoly: con iota;

	Pos: adt
	{
		file:		string;
		line:		int;		# line number: origin 1
		pos:		int;		# character within the line: origin 0
	};
	Src: adt
	{
		start:		Pos;		# range within source files
		stop:		Pos;
	};
	Id: adt
	{
		src:		ref Src;
		name:		string;
		offset:		int;		# start of pc, offset in frame, etc
		stoppc:		int;		# limit pc of function
		t:		cyclic ref Type;
	};
	Type: adt
	{
		src:		ref Src;
		kind:		int;
		size:		int;
		name:		string;			# for adts, modules
		Of:		cyclic ref Type;	# for lists, arrays, etc.
		ids:		cyclic array of ref Id;	# for adts, etc. locals for fns
		tags:		cyclic array of ref Type;# for adts with pick tags

		text:		fn(t: self ref Type, sym: ref Sym): string;
		getkind:	fn(t: self ref Type, sym: ref Sym): int;
	};
	Sym: adt
	{
		path:		string;
		name:		string;		# implements name
		src:		array of ref Src;
		srcstmt:	array of int;
		adts:		array of ref Type;
		fns:		array of ref Id;
		vars:		array of ref Id;

		srctopc:	fn(s: self ref Sym, src: ref Src): int;
		pctosrc:	fn(s: self ref Sym, pc: int): ref Src;
	};

	Module: adt
	{
		path:	string;		# from whence loaded
		code:	int;		# address of code start
		data:	int;		# address of data
		comp:	int;		# compiled to native assembler?
		sym:	ref Sym;

		addsym:	fn(m: self ref Module, sym: ref Sym);
		stdsym:	fn(m: self ref Module);
		dis:	fn(m: self ref Module): string;
		sbl:	fn(m: self ref Module): string;
	};

	StepExp, StepStmt, StepOver, StepOut: con iota;
	Prog: adt
	{
		id:	int;
		heap:	ref Sys->FD;	# prog heap file
		ctl:	ref Sys->FD;	# prog control file
		dbgctl:	ref Sys->FD;	# debug file
		stk:	ref Sys->FD;	# stack file

		status:	fn(p: self ref Prog): (int, string, string, string);
		stack:	fn(p: self ref Prog): (array of ref Exp, string);
		step:	fn(p: self ref Prog, how: int): string;
		cont:	fn(p: self ref Prog): string;
		grab:	fn(p: self ref Prog): string;
		start:	fn(p: self ref Prog): string;
		stop:	fn(p: self ref Prog): string;
		unstop:	fn(p: self ref Prog): string;
		kill:	fn(p: self ref Prog): string;
		event:	fn(p: self ref Prog): string;
		setbpt:	fn(p: self ref Prog, dis: string, pc: int): string;
		delbpt:	fn(p: self ref Prog, dis: string, pc: int): string;
	};

	Exp: adt
	{
		name:	string;
		offset:	int;
		pc:	int;
		m:	ref Module;
		p:	ref Prog;

		# this is private
		id:	ref Id;

		expand:	fn(e: self ref Exp): array of ref Exp;
		val:	fn(e: self ref Exp): (string, int);
		typename:	fn(e: self ref Exp): string;
		kind: fn(e: self ref Exp): int;
		src:	fn(e: self ref Exp): ref Src;
		findsym:fn(e: self ref Exp): string;
		srcstr:	fn(e: self ref Exp): string;
	};

	init:		fn(): int;
	sym:		fn(sbl: string): (ref Sym, string);
	prog:	fn(pid: int): (ref Prog, string);
	startprog:	fn(dis, dir: string, ctxt: ref Draw->Context, argv: list of string): (ref Prog, string);
};