annotate lwasm/lwasm.c @ 345:7416c3f9c321

Basic macro processor ported forward; added context break handling for local symbols
author lost@starbug
date Thu, 25 Mar 2010 23:17:54 -0600
parents 0215a0fbf61b
children a82c55070624
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
337
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
1 /*
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
2 lwasm.c
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
3
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
4 Copyright © 2010 William Astle
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
5
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
6 This file is part of LWTOOLS.
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
7
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
11 version.
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
12
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
16 more details.
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
17
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
20 */
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
21
344
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
22 #define ___lwasm_c_seen___
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
23
337
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
24 #include <config.h>
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
25
344
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
26 #include <stdio.h>
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
27 #include <stdarg.h>
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
28
337
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
29 #include <lw_expr.h>
344
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
30 #include <lw_alloc.h>
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
31 #include <lw_string.h>
337
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
32
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
33 #include "lwasm.h"
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
34
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
35 lw_expr_t lwasm_evaluate_var(char *var)
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
36 {
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
37 return NULL;
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
38 }
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
39
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
40 lw_expr_t lwasm_evaluate_special(int t, void *ptr)
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
41 {
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
42 switch (t)
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
43 {
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
44 case lwasm_expr_linelen:
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
45 {
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
46 line_t *cl = ptr;
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
47 if (cl -> len == -1)
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
48 return NULL;
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
49 return lw_expr_build(lw_expr_type_int, cl -> len);
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
50 }
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
51 break;
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
52 }
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
53 return NULL;
04c80c51b16a Checkpoint development
lost
parents:
diff changeset
54 }
344
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
55
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
56 void lwasm_register_error(asmstate_t *as, line_t *l, const char *msg, ...)
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
57 {
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
58 lwasm_error_t *e;
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
59 va_list args;
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
60 char errbuff[1024];
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
61 int r;
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
62
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
63 if (!l)
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
64 return;
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
65
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
66 va_start(args, msg);
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
67
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
68 e = lw_alloc(sizeof(lwasm_error_t));
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
69
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
70 e -> next = l -> err;
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
71 l -> err = e;
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
72
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
73 as -> errorcount++;
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
74
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
75 r = vsnprintf(errbuff, 1024, msg, args);
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
76 e -> mess = lw_strdup(errbuff);
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
77
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
78 va_end(args);
0215a0fbf61b Added assembly error system and additional checks for symbol syntax
lost@starbug
parents: 337
diff changeset
79 }
345
7416c3f9c321 Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents: 344
diff changeset
80
7416c3f9c321 Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents: 344
diff changeset
81 int lwasm_next_context(asmstate_t *as)
7416c3f9c321 Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents: 344
diff changeset
82 {
7416c3f9c321 Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents: 344
diff changeset
83 int r;
7416c3f9c321 Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents: 344
diff changeset
84 r = as -> nextcontext;
7416c3f9c321 Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents: 344
diff changeset
85 as -> nextcontext++;
7416c3f9c321 Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents: 344
diff changeset
86 return r;
7416c3f9c321 Basic macro processor ported forward; added context break handling for local symbols
lost@starbug
parents: 344
diff changeset
87 }