summaryrefslogtreecommitdiff
path: root/minie
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-01-17 21:23:04 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2019-01-17 21:23:04 +0100
commit73c17bbef59ebe9860195fb8de6b24915a538d98 (patch)
tree5555a1a74412d080ca905719af081dd97ec79e90 /minie
parentcab9a1bc807f4f119292a5d797dda471c668942d (diff)
downloadcompilertests-73c17bbef59ebe9860195fb8de6b24915a538d98.tar.gz
compilertests-73c17bbef59ebe9860195fb8de6b24915a538d98.tar.bz2
tackled the in-situ allocation of symbols (for internal functions)
Diffstat (limited to 'minie')
-rw-r--r--minie/README1
-rwxr-xr-xminie/build.sh4
-rw-r--r--minie/e2c.c16
-rw-r--r--minie/test6.e4
-rw-r--r--minie/test9.e19
5 files changed, 40 insertions, 4 deletions
diff --git a/minie/README b/minie/README
index 9775777..2e2af82 100644
--- a/minie/README
+++ b/minie/README
@@ -23,3 +23,4 @@ test6: internal function 'length', system functions for stdio and stdin
test7: a proper string length function using 'length' and introducing
a function taking array of arbitrary length
test8: loops
+test9: read characters as in a lexer
diff --git a/minie/build.sh b/minie/build.sh
index b039017..46565ff 100755
--- a/minie/build.sh
+++ b/minie/build.sh
@@ -2,7 +2,7 @@
set -e
-gcc -m32 -g -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c
+gcc -m32 --stack-usage -g -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c
tcc -o e2c e2c.c
pcc -Wall -O0 -g -D__float128="long double" -o e2c e2c.c
clang -O0 -Wall -pedantic -std=c89 -Wno-return-type -o e2c e2c.c
@@ -16,11 +16,13 @@ set -e
./e2c < test6.e
./e2c < test7.e
./e2c < test8.e
+./e2c < test9.e
./e2c < test5.e > test5.c && gcc -g -o test5 test5.c && ./test5
./e2c < test6.e > test6.c && gcc -g -o test6 test6.c && ( echo 'Hello' | ./test6 )
./e2c < test7.e > test7.c && gcc -g -o test7 test7.c && ( echo 'Hello' | ./test7 )
./e2c < test8.e > test8.c && gcc -g -o test8 test8.c && ./test8
+./e2c < test9.e > test9.c && gcc -g -o test9 test9.c && ./test9 < test9.e
./e2c < ec.e
./e2c < ec.e > ec.c && gcc -o ec ec.c
diff --git a/minie/e2c.c b/minie/e2c.c
index 3a24f81..c6c4bfa 100644
--- a/minie/e2c.c
+++ b/minie/e2c.c
@@ -14,7 +14,7 @@ enum {
MAX_SYMBOLS = 32,
MAX_RECORD_MEMBERS = 8,
MAX_PARAMETERS = 4,
- MAX_TYPE_DATA_SIZE = 128
+ MAX_TYPE_DATA_SIZE = 2048
};
/* SCANNER */
@@ -683,15 +683,27 @@ static void register_internal_functions( void )
type.details.function.len = 1;
type.details.function.params[0] = (Type *)&type.details.function.data;
type.details.function.params[0]->type = TYPE_ARRAY;
+ type.details.function.return_value = (Type *)( type.details.function.data + sizeof( Type ) );
+ type.details.function.return_value->type = TYPE_INTEGER;
+ printf( "%p %p %p %x\n", (void *)&type.details.function.data, (void *)type.details.function.params[0],
+ (void *)type.details.function.return_value, sizeof( Type ) );
type.details.function.internal = 1;
insert_symbol( type, "length" );
type.type = TYPE_FUNCTION;
type.details.function.len = 1;
type.details.function.params[0] = (Type *)&type.details.function.data;
- type.details.function.params[0]->type = TYPE_CHAR;
+ type.details.function.params[0]->type = TYPE_INTEGER;
+ type.details.function.return_value = (Type *)( type.details.function.data + sizeof( Type ) );
+ type.details.function.return_value->type = TYPE_CHAR;
type.details.function.internal = 1;
insert_symbol( type, "char" );
+
+ /* register functions in module system, should be outside in the stage-1 compiler */
+ type.type = TYPE_FUNCTION;
+ type.details.function.len = 0;
+ type.details.function.internal = 1;
+ insert_symbol( type, "system.readchar" );
}
static void register_internal_constants( void )
diff --git a/minie/test6.e b/minie/test6.e
index 42838ef..09833f2 100644
--- a/minie/test6.e
+++ b/minie/test6.e
@@ -5,6 +5,8 @@ import system;
var
s : array[64] of char;
len : integer;
+ c : char;
+ i : integer;
begin
system.readline( s );
@@ -13,5 +15,5 @@ begin
system.writeline( s );
system.writestring( "Length: " );
system.writeinteger( len );
- system.writeline( "" )
+ system.writeline( "" );
end
diff --git a/minie/test9.e b/minie/test9.e
new file mode 100644
index 0000000..c72ff17
--- /dev/null
+++ b/minie/test9.e
@@ -0,0 +1,19 @@
+module test9;
+
+import system;
+
+var
+ len : integer;
+ i : integer;
+ s : array[64] of char;
+ c : char;
+
+begin
+ i := 0;
+ len := length( s );
+ while ( i < len ) and ( c <> char( 0 ) ) do
+ c := system.readchar( );
+ s[i] := c;
+ i := i + 1
+ end
+end