Skip to content

Commit 5ae3dfb

Browse files
committed
symtab: add symdef()
1 parent eada356 commit 5ae3dfb

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

symtab.c

+7
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ SOFTWARE.
2323
#include <stddef.h>
2424
#include <string.h>
2525

26+
#include "const.h"
2627
#include "symtab.h"
2728
#include "types.h"
2829

30+
void symdef(symtab_t *symtab, char *label, size_t lineno) {
31+
strncpy(symtab->symbols[symtab->sp].label, label, LBLLN);
32+
symtab->symbols[symtab->sp].lineno = lineno;
33+
symtab->sp++;
34+
}
35+
2936
size_t symfind(symtab_t *symtab, char *label) {
3037
size_t i;
3138

symtab.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SOFTWARE.
2626
#include <stddef.h>
2727
#include "types.h"
2828

29+
void symdef(symtab_t *symtab, char *label, size_t lineno);
2930
size_t symfind(symtab_t *symtab, char *label);
3031

3132
#endif

vm.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ void load(vm_t *vm) {
102102

103103
/* it's a label */
104104
if (line[0] != '#' && line[0] != ' ') {
105-
strncpy(vm->symtab.symbols[vm->symtab.sp].label, line, LBLLN);
106-
vm->symtab.symbols[vm->symtab.sp].lineno = vm->program.sp;
107-
vm->symtab.sp++;
105+
symdef(&vm->symtab, line, vm->program.sp);
108106
}
109107
/* record line for future reference */
110108
strncpy(vm->program.lines[vm->program.sp], line, LNLEN);

0 commit comments

Comments
 (0)