-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathasm_error.m
More file actions
90 lines (74 loc) · 3.16 KB
/
asm_error.m
File metadata and controls
90 lines (74 loc) · 3.16 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
%-----------------------------------------------------------------------%
% vim: ts=4 sw=4 et
%-----------------------------------------------------------------------%
:- module asm_error.
%
% Copyright (C) Plasma Team
% Distributed under the terms of the MIT License see ../LICENSE.code
%
% Error type for the PZ assembler.
%
%-----------------------------------------------------------------------%
:- interface.
:- import_module parse_util.
:- import_module q_name.
:- import_module util.
:- import_module util.result.
%-----------------------------------------------------------------------%
:- type asm_error
---> e_read_src_error(read_src_error)
; e_name_already_defined(string)
; e_no_such_instruction(string)
; e_symbol_not_found(q_name)
; e_block_not_found(string)
; e_struct_not_found(string)
; e_import_not_found(q_name)
; e_stack_depth.
:- instance error(asm_error).
%-----------------------------------------------------------------------%
%-----------------------------------------------------------------------%
:- implementation.
:- import_module list.
:- import_module string.
:- import_module util.pretty.
%-----------------------------------------------------------------------%
:- instance error(asm_error) where [
pred(pretty/4) is asme_pretty,
func(error_or_warning/1) is asme_error_or_warning
].
:- pred asme_pretty(string::in, asm_error::in, list(pretty)::out, list(pretty)::out) is det.
asme_pretty(SrcPath, Error, Para, Extra) :-
( Error = e_read_src_error(ReadSrcError),
pretty(SrcPath, ReadSrcError, Para, Extra)
;
( Error = e_name_already_defined(Name),
Para = [p_quote("\"", p_str(Name))] ++ p_spc_nl ++
p_words("is already defined")
; Error = e_no_such_instruction(Name),
Para = [p_quote("\"", p_str(Name))] ++ p_spc_nl ++
p_words("is not a PZ instruction")
; Error = e_symbol_not_found(Symbol),
Para = p_words("The symbol") ++ p_spc_nl ++
[p_quote("\"", q_name_pretty(Symbol))] ++ p_spc_nl ++
p_words("is undefined")
; Error = e_block_not_found(Name),
Para = p_words("The block") ++ p_spc_nl ++
[p_quote("\"", p_str(Name))] ++ p_spc_nl ++
p_words("is undefined")
; Error = e_struct_not_found(Name),
Para = p_words("The structure") ++ p_spc_nl ++
[p_quote("\"", p_str(Name))] ++ p_spc_nl ++
p_words("is undefined")
; Error = e_stack_depth,
Para = p_words("Stack operations have a maximum depth of 255")
; Error = e_import_not_found(Symbol),
Para = p_words("The symbol") ++ p_spc_nl ++
[p_quote("\"", q_name_pretty(Symbol))] ++ p_spc_nl ++
p_words("cannot be found or is not an imported procedure")
),
Extra = []
).
:- func asme_error_or_warning(asm_error) = error_or_warning.
asme_error_or_warning(_) = error.
%-----------------------------------------------------------------------%
%-----------------------------------------------------------------------%