diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2019-02-13 19:45:08 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2019-02-13 19:45:08 +0100 |
commit | 9da8bae31a26de04d664abe1f89cdb54170498c9 (patch) | |
tree | dbef088e88d9e179b6a39de5112661250d2b57b6 /minie | |
parent | 8c2cd8a7e94a310cf5f9e2beb55ffe36f4f4fa13 (diff) | |
download | compilertests-9da8bae31a26de04d664abe1f89cdb54170498c9.tar.gz compilertests-9da8bae31a26de04d664abe1f89cdb54170498c9.tar.bz2 |
fixed handling of no paramlist for 0-value procedure calls
Diffstat (limited to 'minie')
-rw-r--r-- | minie/DESIGN | 24 | ||||
-rw-r--r-- | minie/TODOS | 27 | ||||
-rw-r--r-- | minie/e2c.c | 11 | ||||
-rw-r--r-- | minie/ec.e | 6 |
4 files changed, 58 insertions, 10 deletions
diff --git a/minie/DESIGN b/minie/DESIGN index 5c1116b..7c6a4ce 100644 --- a/minie/DESIGN +++ b/minie/DESIGN @@ -36,22 +36,36 @@ Options: - Language O is just a special backend for the code generator. So it's the first one we implement. -Steps: +Glossary - O: old language, well-established, can be ported, can build native code - O', O'': subset languages of language O with reduced features, O' has most features in common with O, O''''' has least features in common with O - N: new language we want to have a compiler for - N', N'': subset languages of language N with reduced features +- S: a system being able to run all tools of O and N. This is an operating + system with some tools for building software. +- H: a system S used as host system +- H', H'': reduced host system of H +- T: a system S used as target system +- T', T'': reduced target system +- E(S): emulator able to act as system S Step 1: Build a translator (a transpiler) from N'' -> O'' written in O, O', O'' We also use the O-toolchain for building all artifacts (compiler, assembler, linker). Try to build minimal subsets of N and use as little features of O for -the generated code. As this is a throw-away piece of code, it doesn't -matter so much how many features of O we use to implement it. +the generated code. This first compiler allows to port N to new platforms, +given they have a compiler in O. The less features of O we are using, the +better. Step 2: Write compiler in N, with a backend for O'' -Do all the steps in language N as nicely as possible. Introduce new -elements to N (and thus to the N to O translator as needed). +Do all the steps of step 1 again in language N as nicely as possible. +Introduce new elements to N (and thus to the N to O translator as needed). +The question remains whether this is a full N language or only a sublanguage N'. +We produce code for a small subset of O, so also this code can be +built on as many systems as possible. The goal is that N is self-hosting +using the toolchain of O. + +Step 3: diff --git a/minie/TODOS b/minie/TODOS index 95c8423..d2ccd26 100644 --- a/minie/TODOS +++ b/minie/TODOS @@ -157,6 +157,33 @@ to be adapted and the compiler has to be recompiled. But the benefits are that you are not using any dynamic memory allocation which can go wrong in some ways. +procedure/function declarations and calls + +Pascalish: +procedure f : char; +procedure f; + +C-ish: +procedure f( ) : char; +procedure f( ); +=> matter of definition of ParameterList in ProcedureDeclaration + +procedure f( var a : integer ); +function sin( x : float ) : float; +=> function seems more mathematical, but otherwise we don't gain anything + to have a keyword more for detecting anything we couldn't detect already + +procedure call: +init; +proc( a, b ); + +function call in expression: +a+sin( b ) +a+rand( ) +=> even here it might feel more logical and actually the syntax element '(' +helps us to detect it is actually a function, otoh we can get the same +information from the symbol table. + links ----- diff --git a/minie/e2c.c b/minie/e2c.c index 759e23b..9d46f52 100644 --- a/minie/e2c.c +++ b/minie/e2c.c @@ -1153,12 +1153,19 @@ static void statement( void ) return; } else if( sym == S_ident ) { qualident( ); - /* procedure call with parameter */ if( sym == S_lparen ) { + /* procedure call with parameter */ parameterList( ); emitLn( ";" ); } else { - assignment( ); + Type type = get_symbol_type( varName ); + if( type.type == TYPE_FUNCTION ) { + /* procedure call without parameter */ + /* TODO: check number of parameter and return value to be 0 */ + emitLn( "%s( );", varName ); + } else { + assignment( ); + } } } else { Abort( "Illegal statement" ); @@ -43,9 +43,9 @@ begin end begin - init( ); - prologue( ); - epilogue( ); + init; + prologue; + epilogue; look := getChar( ); while ( look <> char( 0 ) ) do |