Mercurial > hg-old > index.cgi
comparison lwasm/pass1.c @ 346:a82c55070624
Added expression parsing infrastructure and misc fixes
author | lost@starbug |
---|---|
date | Sat, 27 Mar 2010 19:04:03 -0600 |
parents | 7416c3f9c321 |
children | 1649bc7bda5a |
comparison
equal
deleted
inserted
replaced
345:7416c3f9c321 | 346:a82c55070624 |
---|---|
20 */ | 20 */ |
21 | 21 |
22 #include <config.h> | 22 #include <config.h> |
23 | 23 |
24 #include <stdio.h> | 24 #include <stdio.h> |
25 #include <string.h> | |
25 | 26 |
26 #include <lw_alloc.h> | 27 #include <lw_alloc.h> |
27 #include <lw_string.h> | 28 #include <lw_string.h> |
28 | 29 |
29 #include "lwasm.h" | 30 #include "lwasm.h" |
76 continue; | 77 continue; |
77 } | 78 } |
78 printf("%s\n", line); | 79 printf("%s\n", line); |
79 | 80 |
80 cl = lw_alloc(sizeof(line_t)); | 81 cl = lw_alloc(sizeof(line_t)); |
81 cl -> next = NULL; | 82 memset(cl, 0, sizeof(line_t)); |
82 cl -> prev = as -> line_tail; | 83 cl -> prev = as -> line_tail; |
83 cl -> len = -1; | |
84 cl -> insn = -1; | 84 cl -> insn = -1; |
85 cl -> err = NULL; | 85 cl -> as = as; |
86 if (!as -> line_tail) | 86 if (!as -> line_tail) |
87 { | 87 { |
88 as -> line_head = cl; | 88 as -> line_head = cl; |
89 cl -> addr = lw_expr_build(lw_expr_type_int, 0); | 89 cl -> addr = lw_expr_build(lw_expr_type_int, 0); |
90 } | 90 } |
93 lw_expr_t te; | 93 lw_expr_t te; |
94 as -> line_tail -> next = cl; | 94 as -> line_tail -> next = cl; |
95 te = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, cl -> prev); | 95 te = lw_expr_build(lw_expr_type_special, lwasm_expr_linelen, cl -> prev); |
96 cl -> addr = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, cl -> prev -> addr, te); | 96 cl -> addr = lw_expr_build(lw_expr_type_oper, lw_expr_oper_plus, cl -> prev -> addr, te); |
97 lw_expr_destroy(te); | 97 lw_expr_destroy(te); |
98 lw_expr_simplify(cl -> addr); | 98 lw_expr_simplify(cl -> addr, as); |
99 } | 99 } |
100 as -> line_tail = cl; | 100 as -> line_tail = cl; |
101 as -> cl = cl; | |
101 | 102 |
102 // blank lines don't count for anything | 103 // blank lines don't count for anything |
103 // except a local symbol context break | 104 // except a local symbol context break |
104 if (!*line) | 105 if (!*line) |
105 { | 106 { |
220 { | 221 { |
221 cl -> insn = opnum; | 222 cl -> insn = opnum; |
222 // no parse func means operand doesn't matter | 223 // no parse func means operand doesn't matter |
223 if (instab[opnum].parse) | 224 if (instab[opnum].parse) |
224 { | 225 { |
226 cl -> len = -1; | |
225 // call parse function | 227 // call parse function |
226 (instab[opnum].parse)(as, cl, &p1); | 228 (instab[opnum].parse)(as, cl, &p1); |
227 | 229 |
228 if (*p1 && !isspace(*p1)) | 230 if (*p1 && !isspace(*p1)) |
229 { | 231 { |