#include #include #include #include #include #include #include #include #include #include #include "memory.h" #include "cpu.h" #include "loader.h" #include "assembler.h" #include "compiler.h" #include "pragmas.h" #include "keywords.h" #include "functions.h" #include "operators.h" #include "optimiser.h" #include "validater.h" #include "linker.h" #include "midi.h" size_t _heapTotalUsage = 0; size_t _heapAllocations = 0; void* operator new(size_t size) { _heapTotalUsage += size; _heapAllocations++; return malloc(size); } namespace Compiler { const std::vector _sysInitNames = {"InitEqOp", "InitNeOp", "InitLeOp", "InitGeOp", "InitLtOp", "InitGtOp", "Init8Array2d", "Init8Array3d", "Init16Array2d", "Init16Array3d", "InitRealTimeStub"}; enum VarResult {VarError=-1, VarNotFound, VarCreated, VarUpdated, VarExists, VarExistsAsConst}; enum StrResult {StrError=-1, StrNotFound, StrCreated}; enum FloatSize {Float16=2, Float32=4}; enum LabelResult {LabelError=-1, LabelNotFound, LabelFound}; uint16_t _vasmPC = USER_CODE_START; uint16_t _userCodeStart = USER_CODE_START; uint16_t _tempVarSize = TEMP_VAR_SIZE; uint16_t _tempVarStart = TEMP_VAR_START; uint16_t _userVarStart = USER_VAR_START; uint16_t _userVarsAddr = USER_VAR_START; uint16_t _runtimeEnd = RUN_TIME_START; uint16_t _runtimeStart = RUN_TIME_START; uint16_t _arraysStart = RUN_TIME_START; uint16_t _stringsStart = RUN_TIME_START; uint16_t _regWorkArea = 0x0000; uint16_t _gprintfVarsAddr = 0x0000; uint16_t _strWorkAreaIdx = 0; uint16_t _strWorkArea[NUM_STR_WORK_AREAS] = {0x0000, 0x0000}; uint16_t _spritesAddrLutAddress = 0x0000; uint16_t _spriteStripeChunks = 15; uint16_t _spriteStripeMinAddress = USER_CODE_START; Memory::FitType _spriteStripeFitType = Memory::FitDescending; CodeOptimiseType _codeOptimiseType = CodeSpeed; Cpu::RomType _codeRomType = Cpu::ROMv3; std::map _branchTypes = {{"BRA", 0}, {"BEQ", 1}, {"BNE", 2}, {"BLE", 3}, {"BGE", 4}, {"BLT", 5}, {"BGT", 6}}; bool _codeIsAsm = false; bool _arrayIndiciesOne = false; bool _createNumericLabelLut = false; bool _createTimeData = false; int _currentLabelIndex = -1; int _currentCodeLineIndex = 0; int _nonNumericLabelIndex = -1; int _jumpFalseUniqueId = 0; int _codeLineStart = 0; std::string _codeLineText; std::string _codeLineModule; std::string _runtimePath = "./runtime"; std::string _tempVarStartStr; std::string _nextInternalLabel; std::vector _input; std::vector _output; std::vector _runtime; std::vector