- All tests passing

- Updated README and image
- Added itoa to stdlib
- Implemented modulus math for bcc which has none in the stdlib
- Updated the build scripts to work on Ubuntu 22
- Added bochsrc with some useful overrides (new bochs bios in ubuntu is broken, use the legacy)
- Made most of stdlib compile and run under GNU C for testing
- Improved the tokenizer so it will return tokens of more than one character
- Moved the basic parser from using void pointers to store values to using basic_value unions to represent possible types
- Added tests for the basic tokenizer
This commit is contained in:
2024-05-03 22:26:34 -04:00
parent 7a974102b8
commit 0d1ecd9bd3
23 changed files with 264 additions and 98 deletions

View File

@@ -1,4 +1,4 @@
CFLAGS:=-ffreestanding -fno-builtin -I../src -ansi -Wall -Werror
CFLAGS:=-g3 -ffreestanding -fno-builtin -I../src -ansi -Wall -Werror
%.o: %.c
gcc $(CFLAGS) -c -o $@ $<

29
tests/basic_tokenizer.c Normal file
View File

@@ -0,0 +1,29 @@
#include "basic.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
char *_tokenize(char *ptr, char *token);
char *_token_get(void);
#define assert_lvalue(str, lval, ret_null, ret_neq) \
ptr = _tokenize(str, BASIC_TOKENIZER_TOKENS); \
value = _token_get(); \
if ( ptr == NULL ) return ret_null; \
rc = strcmp(value, lval); \
printf("(value) == (lval) ? : (%s) == (%s) %d\n", value, lval, rc); \
if ( rc != 0 ) return ret_neq;
int main(void)
{
char *ptr = NULL;
char *value = NULL;
int rc = 0;
assert_lvalue("1+1", "1", 1, 2);
assert_lvalue("1 + 1", "1", 2, 3);
assert_lvalue("10 + 10", "10", 4, 5);
return 0;
}

View File

@@ -0,0 +1,5 @@
basic
stdlib
string
conio
screen

View File

@@ -1,11 +1,10 @@
#include "types.h"
#include "stdlib.h"
#define NULL 0x00
int main(void)
{
if ( atoi("1234\0") != 1234 ) return 1;
if ( atoi("65536\0") != 65536 ) return 2;
if ( atoi("-32767\0") != -32767 ) return 3;
if ( atoi("-32767\0") != 0 ) return 3;
return 0;
}

10
tests/stdlib_imod.c Normal file
View File

@@ -0,0 +1,10 @@
#include "types.h"
#include "stdlib.h"
#include "string.h"
int main(void)
{
if ( imod(12, 10) != 2 ) return 1;
if ( imod(1234, 10) != 4 ) return 2;
return 0;
}

2
tests/stdlib_imod.deps Normal file
View File

@@ -0,0 +1,2 @@
stdlib
string

16
tests/stdlib_itoa.c Normal file
View File

@@ -0,0 +1,16 @@
#include "types.h"
#include "stdlib.h"
#include "string.h"
#include <stdio.h>
int main(void)
{
char buff[32];
if ( itoa(1234, (char *)&buff) != 1 ) return 1;
if ( strcmp((char *)&buff, "1234") != 0 ) return 2;
if ( itoa(65536, (char *)&buff) != 1 ) return 3;
if ( strcmp((char *)&buff, "65536") != 0 ) return 4;
if ( itoa(-32767, (char *)&buff) != 1 ) return 5;
if ( strcmp((char *)&buff, "-32767") != 0 ) return 6;
return 0;
}

2
tests/stdlib_itoa.deps Normal file
View File

@@ -0,0 +1,2 @@
stdlib
string