This commit is contained in:
xolatile
2024-07-26 18:51:15 -04:00
18 changed files with 149 additions and 93 deletions

@ -76,7 +76,7 @@ ${OBJECT.d}/%.pluglock: ${OBJECT.d}/%.pp
touch $@
test: ${OUT}
-ORIGIN="$$(realpath .)" PATH="$$(realpath .):${PATH}" cmdtest
-ORIGIN="$$(realpath .)" PATH="$$(realpath .):${PATH}" cmdtest --fast
-${WRAP} ./${OUT} test/nop.eax
bootstrap:

@ -6,6 +6,8 @@
* the storage of variables.
*/
// XXX: we dont *actually* have to store names, do we?
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
@ -33,9 +35,29 @@ static size_t anon_variable_counter = 0;
*/
static size_t unresolved_label_counter = 0;
/*
static int control_block_stack[12];
static size_t control_block_stack_top = 0;
*/
static unsigned symbol_id = 1;
tommy_hashtable symbol_table;
/*
void add_if(void) {
control_block_stack[control_block_stack_top++] = symbol_id++;
}
void fin_if(void) {
append_instructions(ASMDIRMEM, control_block_stack[control_block_stack_top--]);
}
void add_logic_equals(cpuregister_t * c1, cpuregister_t * c2) {
append_instructions(CMP, c1->size, REG, c1->number, REG, c2->number);
append_instructions(JNE, D32, REL, control_block_stack[control_block_stack_top]);
}
*/
static char * scope = NULL;
void empty_out_scope(void) {
free(scope);
@ -60,7 +82,6 @@ symbol_t * new_symbol(char * name) {
return r;
}
static
void free_symbol(void * data) {
symbol_t * variable = (symbol_t*)data;
@ -332,6 +353,7 @@ void add_fastcall(const char * const destination) {
append_instructions(CALL, REL, function->_id);
}
int type2size(const int type) {
switch (type) {
case U8:

@ -75,6 +75,12 @@ extern void add_procedure(const char * const name);
extern void add_fastcall(const char * const destination);
extern void fin_procedure(void);
extern void fin_hla(void);
/*
extern void add_if(void);
extern void fin_if(void);
extern void add_logic_equals();
extern void add_logic_equals(cpuregister_t * c1, cpuregister_t * c2);
*/
/* Not implemented
extern symbol_t * add_function(symbol_t function);
extern symbol_t * get_function(const char * const name);

@ -106,7 +106,6 @@ document: hla { fin_hla(); }
hla: %empty
// | library hla
| declaration hla // tmp
| program hla
| function hla
;
@ -234,12 +233,12 @@ stored_literal: ARRAY_LITERAL {
code: %empty
| error code { /*yyerrok;*/ }
| repeat code
| if code
/*| repeat code */
/*| if code */
| call code
| label code
| machine code
| BREAK code
/*| BREAK code*/
| exit code
| instruction code
;
@ -250,15 +249,26 @@ label: LABEL {
}
;
/*
repeat: REPEAT code END_REPEAT
| UNTIL logic REPEAT code END_REPEAT
;
if: IF logic THEN code END_IF
if_start: IF { add_if(); }
;
if_end: END_IF { fin_if(); }
;
if: if_start logic THEN code if_end
| IF logic THEN code ELSE code END_IF
;
logic: logical_operand ITAND logical_operand
logic: register '=' register {
add_logic_equals(&$1, &$3);
}
;
logical_operand ITAND logical_operand
| logical_operand ITOR logical_operand
| logical_operand ITXOR logical_operand
| logical_operand '=' logical_operand
@ -277,6 +287,7 @@ logical_operand: sublogic
sublogic: '(' logic ')'
;
*/
machine: MACHINE machine_code END_MACHINE
;

@ -1,127 +1,73 @@
$default_output_file = "test_me_please"
$default_output_file = "a.out"
class CMDTEST_error_batch < Cmdtest::Testcase
def test_unknown_instruction
create_file "input.eax", <<-HEREDOC
procedure a
nop
end procedure
import_file "test/unknown_instruction.eax", "./"
unix
program main
wigglecall a
end program
HEREDOC
cmd "eaxhla input.eax" do
cmd "eaxhla unknown_instruction.eax" do
stderr_equal /.+/
exit_status 1
end
end
def test_unclosed_comment
create_file "input.eax", <<-HEREDOC
/*
reeeeeeee
reeeeeeeee
reeeeee
HEREDOC
import_file "test/unclosed_comment.eax", "./"
cmd "eaxhla input.eax" do
cmd "eaxhla unclosed_comment.eax" do
stderr_equal /.+/
exit_status 1
end
end
def test_unclosed_artimetric
create_file "input.eax", <<-HEREDOC
program a
u8 var = [
HEREDOC
import_file "test/unclosed_artimetric.eax", "./"
cmd "eaxhla input.eax" do
cmd "eaxhla unclosed_artimetric.eax" do
stderr_equal /.+/
exit_status 1
end
end
def test_unclosed_program
create_file "input.eax", <<-HEREDOC
unix
program main
begin
exit 1
end rpogram
HEREDOC
import_file "test/unclosed_program.eax", "./"
cmd "eaxhla input.eax" do
cmd "eaxhla unclosed_program.eax" do
stderr_equal /.+/
exit_status 1
end
end
def test_double_declare
create_file "input.eax", <<-HEREDOC
program main
u8 a
u8 a
begin
end program
HEREDOC
import_file "test/double_declare.eax", "./"
cmd "eaxhla input.eax" do
cmd "eaxhla double_declare.eax" do
stderr_equal /.+/
exit_status 1
end
end
def test_double_program
create_file "input.eax", <<-HEREDOC
program a
begin
end program
import_file "test/double_program.eax", "./"
program b
begin
end program
HEREDOC
cmd "eaxhla input.eax" do
cmd "eaxhla double_program.eax" do
stderr_equal /.+/
exit_status 1
end
end
def test_cut_string
create_file "input.eax", <<-HEREDOC
program main
u8 <> kek = "asd
begin
end program
HEREDOC
import_file "test/cut_string.eax", "./"
cmd "eaxhla input.eax" do
cmd "eaxhla cut_string.eax" do
stderr_equal /.+\n(.|\n)+/m
exit_status 1
end
end
def test_multi_error
create_file "input.eax", <<-HEREDOC
program main
k8 kek
begin
wigglecall func
xor $rsp rsp
xor rsp rsp
poke rsp
xor rsp rsp
xor rsp rsp
xor rsp rsp
end program
HEREDOC
import_file "test/multi_error.eax", "./"
cmd "eaxhla input.eax" do
cmd "eaxhla multi_error.eax" do
stderr_equal /.+\n(.|\n)+/m
exit_status 1
end
@ -130,31 +76,31 @@ end
class CMDTEST_warning_batch < Cmdtest::Testcase
def test_overflows
create_file "input.eax", <<-HEREDOC
program main
u8 a = 10
u8 b = 10000
u8 c = -200
begin
end program
HEREDOC
import_file "test/overflows.eax", "./"
ignore_file $default_output_file
cmd "eaxhla input.eax" do
created_files "a.out"
cmd "eaxhla overflows.eax" do
stderr_equal /.+/
end
end
def test_very_empty
import_file "test/very_empty.eax", "./"
ignore_file $default_output_file
cmd "eaxhla very_empty.eax" do
stderr_equal /.+/
end
end
def test_empty
create_file "input.eax", <<-HEREDOC
HEREDOC
import_file "test/empty.eax", "./"
ignore_file $default_output_file
cmd "eaxhla input.eax" do
created_files "a.out"
cmd "eaxhla empty.eax" do
stderr_equal /.+/
end
end

9
test/basic_if.eax Normal file

@ -0,0 +1,9 @@
program basic_if
begin
mov rax 2
mov rbx 3
if rax = rbx then
exit 1
end if
exit 0
end program

4
test/cut_string.eax Normal file

@ -0,0 +1,4 @@
program main
u8 <> kek = "asd
begin
end program

5
test/double_declare.eax Normal file

@ -0,0 +1,5 @@
program main
u8 a
u8 a
begin
end program

7
test/double_program.eax Normal file

@ -0,0 +1,7 @@
program a
begin
end program
program b
begin
end program

5
test/hello_world.c Normal file

@ -0,0 +1,5 @@
// @BAKE gcc $@ -o $*.out -ggdb
signed main() {
puts("Hello World!");
return 0;
}

11
test/multi_error.eax Normal file

@ -0,0 +1,11 @@
program main
k8 kek
begin
wigglecall func
xor $rsp rsp
xor rsp rsp
poke rsp
xor rsp rsp
xor rsp rsp
xor rsp rsp
end program

6
test/overflows.eax Normal file

@ -0,0 +1,6 @@
program main
u8 a = 10
u8 b = 10000
u8 c = -200
begin
end program

5
test/sigint.eax Normal file

@ -0,0 +1,5 @@
program sigint
begin
my_loop:
jmp my_loop
end program

@ -0,0 +1,2 @@
program a
u8 var = [

@ -0,0 +1,4 @@
/*
reeeeeeee
reeeeeeeee
reeeeee

@ -0,0 +1,5 @@
unix
program main
begin
exit 1
end rpogram

@ -0,0 +1,8 @@
procedure a
nop
end procedure
unix
program main
wigglecall a
end program

0
test/very_empty.eax Normal file