This commit is contained in:
xolatile 2024-07-08 19:38:03 -04:00
commit 35f3597a10
8 changed files with 44 additions and 19 deletions

View File

@ -296,7 +296,7 @@ static void build_move (size_index size,
next token_count = 0;
byte * token_array = NULL;
int error_empty_array = 0;
int was_instruction_array_empty = 0;
void assemble (next count,
next * array) {
@ -304,7 +304,7 @@ void assemble (next count,
next index;
if ((count == 0) || (array == NULL)) {
error_empty_array = 1;
was_instruction_array_empty = 1;
return;
}

View File

@ -65,7 +65,7 @@ typedef enum {
extern next token_count;
extern byte * token_array;
extern int error_empty_array;
extern int was_instruction_array_empty;
extern void assemble (next count, next * array);

View File

@ -22,10 +22,10 @@ int is_program_found = 0;
static
void dump_variable(void * data) {
variable_t * variable = (variable_t*)data;
printf("{ .name = '%s', .value = '%ld', .size = %d }\n",
printf("{ .name = '%s', .value = '%ld', .elements = %d }\n",
variable->name,
variable->value,
variable->size
variable->elements
);
}

View File

@ -5,8 +5,11 @@
#define WORD_SIZE_IN_BYTES (64/8)
typedef struct {
int size;
long value;
union {
long value;
void * array_value;
};
int elements;
char * name;
unsigned _hash;
tommy_node _node;

View File

@ -33,7 +33,7 @@ begin { return MYBEGIN; }
program { return PROGRAM; }
procedure { return PROCEDURE; }
loop { return TLOOP; }
repeat { return REPEAT; }
if { return IF; }
then { return THEN; }
machine { return MACHINE; }
@ -109,7 +109,7 @@ u64 { return U64; }
\/\/ { BEGIN IN_COMMENT; }
\/\* { BEGIN IN_MULTILINE_COMMENT; }
\[|\]|\{|\}|\+|\-|\*|\/|\%|\^|\: {
\[|\]|\{|\}|\+|\-|\*|\/|\%|\^|\:|\<|\> {
return yytext[0];
}
@ -129,7 +129,7 @@ xor { return IXOR; }
<IN_END>{
program { BEGIN INITIAL; free(scope); scope = NULL; return END_PROGRAM; }
procedure { BEGIN INITIAL; free(scope); scope = NULL; return END_PROCEDURE; }
loop { BEGIN INITIAL; return END_LOOP; }
repeat { BEGIN INITIAL; return END_REPEAT; }
if { BEGIN INITIAL; return END_IF; }
machine { BEGIN INITIAL; return END_MACHINE; }
{wsnl} { ; }

View File

@ -15,11 +15,6 @@
void yyerror(const char * errmsg) {
issue_error("%s near \033[1m'%s'\033[0m", errmsg, yytext);
}
long new_static(int size) { // XXX might not be required
(void)size;
return 0;
}
%}
%union{
@ -39,7 +34,7 @@
%token PROGRAM END_PROGRAM
%token PROCEDURE END_PROCEDURE
%token TLOOP END_LOOP
%token REPEAT END_REPEAT
%token IF THEN ELSE END_IF
%token MACHINE END_MACHINE
@ -48,6 +43,7 @@
%type<intval> immediate
%type<intval> memory dereference
%type<intval> artimetric_block artimetric_expression artimetric_operand
%type<intval> value
%token<intval> LITERAL
%token<strval> ARRAY_LITERAL
@ -138,6 +134,7 @@ declaration_section: %empty
declaration:
variable_specifier type IDENTIFIER {
$$.name = make_scoped_name(scope, $3);
$$.elements = 1;
add_variable($$);
}
| variable_specifier type IDENTIFIER '=' LITERAL {
@ -145,9 +142,21 @@ declaration:
if (!can_fit($2, $5)) {
issue_warning("the value \033[1m'%lld'\033[0m will overflow in assignement", $5);
}
$$.elements = 1;
$$.value = $5;
add_variable($$);
}
| variable_specifier type '<' value '>' IDENTIFIER {
$$.name = make_scoped_name(scope, $6);
$$.elements = $4;
add_variable($$);
}
| variable_specifier type '<' value '>' IDENTIFIER '=' ARRAY_LITERAL {
$$.name = make_scoped_name(scope, $6);
$$.elements = $4;
$$.array_value = $8;
add_variable($$);
}
;
variable_specifier: %empty
@ -178,12 +187,17 @@ dereference: '[' IDENTIFIER '+' value ']' { $$ = 0; /* XXX: how the fuck do i d
value: artimetric_block
| LITERAL
| IDENTIFIER
| IDENTIFIER {
char * varname = make_scoped_name(scope, $1);
variable_t * var = get_variable(varname);
$$ = var->value;
free(var);
}
;
code: %empty
| error code { yyerrok; }
| loop code
| repeat code
| if code
| call code
| LABEL code { free($1); }
@ -214,7 +228,7 @@ instruction: INOP { ; }
| IXOR register memory
;
loop: TLOOP code END_LOOP
repeat: REPEAT code END_REPEAT
;
if: IF logic THEN code END_IF

View File

@ -48,6 +48,10 @@ signed main(int argc, char * argv[]) {
dump ("test_me_please");
}
if (was_instruction_array_empty) {
issue_warning("the input did not contain any instructions");
}
yyfree_leftovers();
eaxhla_destroy();

4
test/array.eax Normal file
View File

@ -0,0 +1,4 @@
program main
u8<10> myarray
begin
end program