diff --git a/examples/benchmarks.results.text b/examples/benchmarks.results.text index 5c67cd9..23da7c0 100644 --- a/examples/benchmarks.results.text +++ b/examples/benchmarks.results.text @@ -68,5 +68,27 @@ Running benchmarks.prog exp() 10K 00:00:32 cos() 10K 00:00:06 -Running benchmarks.prog + +Arty-A7-35T +76.92MHz, 64KB SRAM, 256MB DRAM, 16B instruction cache +running in DRAM (except corelib, stdlib, runtime) + +Running benchmarks.prog + empty loop 10M 00:00:16 + write variable 10M 00:00:17 + read variable 10M 00:00:19 + integer addition 10M 00:00:24 + real addition 1M 00:00:30 + integer multiplication 1M 00:01:14 + real multiplication 1M 00:01:05 + integer division 1M 00:01:53 + real division 1M 00:01:13 + string indexing 1M 00:00:41 + string iteration 1M 00:00:21 + new/dispose 1k 1M 00:00:25 + new/dispose 128k 1M 00:00:26 + array copy 1k 10K 00:00:03 + array copy 128k 1K 00:00:48 + exp() 10K 00:00:32 + cos() 10K 00:00:06 diff --git a/pcomp/emit.pas b/pcomp/emit.pas index 2ede4f0..a201714 100644 --- a/pcomp/emit.pas +++ b/pcomp/emit.pas @@ -111,7 +111,7 @@ begin emitIns2('BRANCH','@+2'); (* NOP, to make alignment explicit *) emitIns('.CPOOL'); (* header/prologue + 2 constants is 32 bytes *) - if useStdlib then + if useStdlib and not useStandalone then begin writeln(outfile, '%include "stdlib.lsym"'); writeln(outfile, '%incbin "stdlib.lib"'); @@ -312,7 +312,12 @@ begin emitArrayConsts; if useStandalone then - emitInclude('corelib.s') + begin + emitInclude('corelib.s'); + emitInclude('runtime.s'); + emitInclude('float32.s'); + emitInclude('stdlib.s'); + end else emitInclude('coreloader.lsym'); @@ -1059,6 +1064,7 @@ end; *) procedure emitProcedureCall(aProc: ProcRef); var procLabel: IdentString; + i:integer; begin (* pass pointer to stackframe of caller for nested procedures *) if aProc^.isNested then @@ -1069,9 +1075,17 @@ begin if aProc^.level > curProcedure^.level then emitIns2('LOADREG','FP') else - (* TODO: calling nested aProc with a lower nesting level. - need to chase a chain of old BP pointers. *) - errorExit2('internal error: outward call of nested aProc not implemented', ''); + begin + (* Calling nested aProc with a lower nesting level. + Need to chase a chain of old BP pointers. *) + emitIns2('LOADREG', 'BP'); + (* BP points to the stackframe of the outer procedure, + @BP contains the stackframe of the procedure one step further + outwards, and so on. + *) + for i := aProc^.level + 1 to curProcedure^.level do + emitIns('LOADI'); + end; end; emitFpAdjust(-curProcedure^.tempsSize); @@ -1250,7 +1264,7 @@ begin (* nothing to do *) end else - if amount <= MaxTinyOffset then + if (amount > 0) and (amount <= MaxTinyOffset) then emitIns2Int('INC', amount) else begin @@ -1266,7 +1280,7 @@ begin (* nothing to do *) end else - if amount <= MaxTinyOffset then + if (amount > 0) and (amount <= MaxTinyOffset) then emitIns2Int('DEC', amount) else begin diff --git a/pcomp/pcomp.pas b/pcomp/pcomp.pas index 0eca89d..d7be8a5 100644 --- a/pcomp/pcomp.pas +++ b/pcomp/pcomp.pas @@ -2186,7 +2186,7 @@ begin if ch = '!' then (* special comment till end of line *) begin - while not (nextChar = #13) do (* nothing *); + while not (nextChar in [#13, #10]) do (* nothing *); readNextToken; end else @@ -2456,10 +2456,7 @@ begin begin digits := curToken.tokenText; if matchTokenOrNot(MinusToken) then - begin - readNextToken; digits := digits + curToken.tokenText; - end; parseInteger := integerFromString(digits); end; readNextToken; @@ -2812,6 +2809,8 @@ begin if checkToken(CommaToken) then begin + (* TODO: handle comma syntax for indexing a char + from an array of strings *) if elType.baseType <> ArrayType then errorExit2('invalid array subscript for', name) end; @@ -3231,10 +3230,22 @@ begin readNextToken; end; +(* Handle an array range part. Very similar to parseInteger + but additionally handles Boolean, Enum and Char types which + can be used for array indices *) procedure getRangePart(var value:integer; var typeReturn: TypeSpec); var cnst: ConstRef; + negate:boolean; + digits: string[12]; begin setBaseType(typeReturn, NoType); + negate := false; + + if checkToken(MinusToken) then + begin + negate := true; + readNextToken; + end; if checkToken(IdentToken) then begin @@ -3268,7 +3279,11 @@ begin else begin setBaseType(typeReturn, IntegerType); - value := parseInteger; + digits := curToken.tokenText; + if negate then + insert('-', digits, 1); + value := integerFromString(digits); + readNextToken; end; end; @@ -3433,9 +3448,9 @@ begin if savedType.baseType = NoType then savedType := elementType; emitLoadConstantInt(cnst^.intValue); + readNextToken; end; emitAddToSet; - readNextToken; end else if checkToken(NumberToken) then begin @@ -3999,6 +4014,8 @@ begin begin readNextToken; length := parseInteger; + if length < 1 then + errorExit2('invalid string length', ''); matchToken(RBracketToken); end; typSpec.size := getStringMemSize(length);