From 46ceddde370d03a09d3312a28cb3f3ba86e2c3a6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Feb 2026 15:57:11 +0000 Subject: [PATCH 1/3] Initial plan From 37da1a5b6f86330d591db695b6d33c2944f094db Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:00:00 +0000 Subject: [PATCH 2/3] Add AVR type checking for class field declarations and tests Co-authored-by: ycharfi09 <203522567+ycharfi09@users.noreply.github.com> --- src/semantic-analyzer.js | 13 +++++ tests/semantic-analyzer.test.js | 93 +++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/src/semantic-analyzer.js b/src/semantic-analyzer.js index 21f4e7a..e785d4a 100644 --- a/src/semantic-analyzer.js +++ b/src/semantic-analyzer.js @@ -339,6 +339,19 @@ class SemanticAnalyzer { // Declare all properties if (stmt.properties) { stmt.properties.forEach(prop => { + // Check for List/Map usage on AVR boards + if (this.config && this.config.isAVRBoard()) { + if (prop.propertyType && RESTRICTED_COLLECTION_TYPES.includes(prop.propertyType)) { + const board = this.config.options.board; + this.addError( + `Collection type '${prop.propertyType}' is not supported on AVR targets (${board}) due to insufficient RAM.\n` + + ` AVR boards have very limited memory and cannot support std::vector and std::map.\n` + + ` Consider using arrays or simpler data structures, or target a board with more RAM (e.g., ESP32).`, + stmt.line + ); + } + } + this.declare(prop.name); if (prop.init) { this.analyzeExpression(prop.init); diff --git a/tests/semantic-analyzer.test.js b/tests/semantic-analyzer.test.js index 3011d63..db1f437 100644 --- a/tests/semantic-analyzer.test.js +++ b/tests/semantic-analyzer.test.js @@ -455,4 +455,97 @@ describe('Semantic Analyzer - AVR Board Restrictions', () => { expect(result.error).toContain('Collection type \'List\' is not supported on AVR targets'); expect(result.error).toContain('Collection type \'Map\' is not supported on AVR targets'); }); + + test('should reject List type in class field on arduino_uno', () => { + const source = ` + @main + config { + board: arduino_uno, + clock: 16MHz + } + + class DataLogger { + mut List data + + constructor() { + self.data = new List() + } + + fn addReading(int value) { + self.data.push(value) + } + } + + on start { + mut DataLogger logger = new DataLogger() + } + `; + + const result = compile(source); + expect(result.success).toBe(false); + expect(result.error).toContain('Collection type \'List\' is not supported on AVR targets'); + expect(result.error).toContain('arduino_uno'); + expect(result.error).toContain('insufficient RAM'); + }); + + test('should reject Map type in class field on arduino_uno', () => { + const source = ` + @main + config { + board: arduino_uno, + clock: 16MHz + } + + class Configuration { + mut Map settings + + constructor() { + self.settings = new Map() + } + + fn setSetting(int key, int value) { + self.settings.set(key, value) + } + } + + on start { + mut Configuration cfg = new Configuration() + } + `; + + const result = compile(source); + expect(result.success).toBe(false); + expect(result.error).toContain('Collection type \'Map\' is not supported on AVR targets'); + expect(result.error).toContain('arduino_uno'); + expect(result.error).toContain('insufficient RAM'); + }); + + test('should allow List type in class field on esp32', () => { + const source = ` + @main + config { + board: esp32, + clock: 16MHz + } + + class DataLogger { + mut List data + + constructor() { + self.data = new List() + } + + fn addReading(int value) { + self.data.push(value) + } + } + + on start { + mut DataLogger logger = new DataLogger() + } + `; + + const result = compile(source); + expect(result.success).toBe(true); + }); }); From dd79086bcaa3641f79ee9799072d5af2c13628ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:01:45 +0000 Subject: [PATCH 3/3] Add AVR type checking for struct field declarations and tests Co-authored-by: ycharfi09 <203522567+ycharfi09@users.noreply.github.com> --- src/semantic-analyzer.js | 16 ++++++++ tests/semantic-analyzer.test.js | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/src/semantic-analyzer.js b/src/semantic-analyzer.js index e785d4a..12a1fb3 100644 --- a/src/semantic-analyzer.js +++ b/src/semantic-analyzer.js @@ -212,6 +212,22 @@ class SemanticAnalyzer { case 'StructDeclaration': // Declare struct name this.declare(stmt.name); + // Check struct fields for List/Map usage on AVR boards + if (this.config && this.config.isAVRBoard()) { + if (stmt.fields) { + stmt.fields.forEach(field => { + if (field.type && RESTRICTED_COLLECTION_TYPES.includes(field.type)) { + const board = this.config.options.board; + this.addError( + `Collection type '${field.type}' is not supported on AVR targets (${board}) due to insufficient RAM.\n` + + ` AVR boards have very limited memory and cannot support std::vector and std::map.\n` + + ` Consider using arrays or simpler data structures, or target a board with more RAM (e.g., ESP32).`, + stmt.line + ); + } + }); + } + } break; case 'FunctionDeclaration': diff --git a/tests/semantic-analyzer.test.js b/tests/semantic-analyzer.test.js index db1f437..42699b4 100644 --- a/tests/semantic-analyzer.test.js +++ b/tests/semantic-analyzer.test.js @@ -548,4 +548,76 @@ describe('Semantic Analyzer - AVR Board Restrictions', () => { const result = compile(source); expect(result.success).toBe(true); }); + + test('should reject List type in struct field on arduino_uno', () => { + const source = ` + @main + config { + board: arduino_uno, + clock: 16MHz + } + + struct DataPoint { + List values + int timestamp + } + + on start { + print("test") + } + `; + + const result = compile(source); + expect(result.success).toBe(false); + expect(result.error).toContain('Collection type \'List\' is not supported on AVR targets'); + expect(result.error).toContain('arduino_uno'); + expect(result.error).toContain('insufficient RAM'); + }); + + test('should reject Map type in struct field on arduino_uno', () => { + const source = ` + @main + config { + board: arduino_uno, + clock: 16MHz + } + + struct Config { + Map settings + int version + } + + on start { + print("test") + } + `; + + const result = compile(source); + expect(result.success).toBe(false); + expect(result.error).toContain('Collection type \'Map\' is not supported on AVR targets'); + expect(result.error).toContain('arduino_uno'); + expect(result.error).toContain('insufficient RAM'); + }); + + test('should allow List type in struct field on esp32', () => { + const source = ` + @main + config { + board: esp32, + clock: 16MHz + } + + struct DataPoint { + List values + int timestamp + } + + on start { + print("test") + } + `; + + const result = compile(source); + expect(result.success).toBe(true); + }); });