| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
// Copyright (c) 2023 Yuki Kimoto |
|
2
|
|
|
|
|
|
|
// MIT License |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include |
|
5
|
|
|
|
|
|
|
#include |
|
6
|
|
|
|
|
|
|
#include |
|
7
|
|
|
|
|
|
|
#include |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "spvm_compiler.h" |
|
11
|
|
|
|
|
|
|
#include "spvm_yacc_util.h" |
|
12
|
|
|
|
|
|
|
#include "spvm_allocator.h" |
|
13
|
|
|
|
|
|
|
#include "spvm_yacc.h" |
|
14
|
|
|
|
|
|
|
#include "spvm_constant.h" |
|
15
|
|
|
|
|
|
|
#include "spvm_var.h" |
|
16
|
|
|
|
|
|
|
#include "spvm_op.h" |
|
17
|
|
|
|
|
|
|
#include "spvm_type.h" |
|
18
|
|
|
|
|
|
|
#include "spvm_basic_type.h" |
|
19
|
|
|
|
|
|
|
#include "spvm_list.h" |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
// Print error |
|
22
|
63
|
|
|
|
|
|
void SPVM_yyerror(SPVM_COMPILER* compiler, const char* message_not_used) { |
|
23
|
|
|
|
|
|
|
(void)compiler; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
// Current token |
|
26
|
63
|
|
|
|
|
|
int32_t length = 0; |
|
27
|
63
|
|
|
|
|
|
int32_t empty_count = 0; |
|
28
|
63
|
|
|
|
|
|
const char* ptr = compiler->token_begin_ch_ptr; |
|
29
|
215
|
100
|
|
|
|
|
while (ptr != compiler->ch_ptr) { |
|
30
|
152
|
100
|
|
|
|
|
if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
|
empty_count++; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
else { |
|
34
|
150
|
|
|
|
|
|
length++; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
152
|
|
|
|
|
|
ptr++; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
63
|
|
|
|
|
|
char* token = (char*) SPVM_ALLOCATOR_alloc_memory_block_tmp(compiler->current_each_compile_allocator, length + 1); |
|
40
|
63
|
|
|
|
|
|
memcpy(token, compiler->token_begin_ch_ptr + empty_count, length); |
|
41
|
63
|
|
|
|
|
|
token[length] = '\0'; |
|
42
|
|
|
|
|
|
|
|
|
43
|
63
|
|
|
|
|
|
int32_t char_pos = (int32_t)(compiler->token_begin_ch_ptr + empty_count + 1 - compiler->line_begin_ch_ptr); |
|
44
|
|
|
|
|
|
|
|
|
45
|
63
|
|
|
|
|
|
SPVM_COMPILER_error(compiler, "Unexpected token \"%s\"\n at %s line %d:%d", token, compiler->current_file, compiler->current_line, char_pos); |
|
46
|
|
|
|
|
|
|
|
|
47
|
63
|
|
|
|
|
|
SPVM_ALLOCATOR_free_memory_block_tmp(compiler->current_each_compile_allocator, token); |
|
48
|
63
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
// Print the token value in yacc/bison debug mode |
|
51
|
0
|
|
|
|
|
|
void SPVM_yyprint (FILE *file, int type, YYSTYPE yylval) { |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
switch(type) { |
|
54
|
|
|
|
|
|
|
case SYMBOL_NAME: |
|
55
|
|
|
|
|
|
|
case VAR_NAME: |
|
56
|
|
|
|
|
|
|
{ |
|
57
|
0
|
|
|
|
|
|
const char* name = yylval.opval->uv.name; |
|
58
|
0
|
|
|
|
|
|
fprintf(file, "%s", name); |
|
59
|
0
|
|
|
|
|
|
break; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
|
} |