c-next 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c-next",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A safer C for embedded systems development. Transpiles to clean, readable C.",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -898,6 +898,10 @@ export default class CodeGenerator {
898
898
  const scopeDecl = decl.scopeDeclaration()!;
899
899
  const scopeName = scopeDecl.IDENTIFIER().getText();
900
900
 
901
+ // Set currentScope so that this.Type references resolve correctly
902
+ const savedScope = this.context.currentScope;
903
+ this.context.currentScope = scopeName;
904
+
901
905
  for (const member of scopeDecl.scopeMember()) {
902
906
  if (member.variableDeclaration()) {
903
907
  const varDecl = member.variableDeclaration()!;
@@ -907,6 +911,9 @@ export default class CodeGenerator {
907
911
  this.trackVariableTypeWithName(varDecl, fullName);
908
912
  }
909
913
  }
914
+
915
+ // Restore previous scope
916
+ this.context.currentScope = savedScope;
910
917
  }
911
918
 
912
919
  // Note: Function parameters are registered per-function during generation
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Callback type info for Function-as-Type pattern
3
+ * Each function definition creates both a callable function AND a type
4
+ */
5
+
6
+ interface ICallbackTypeInfo {
7
+ functionName: string; // The original function name (also the type name)
8
+ returnType: string; // Return type for typedef (C type)
9
+ parameters: Array<{
10
+ name: string;
11
+ type: string; // C type
12
+ isConst: boolean;
13
+ isPointer: boolean; // Non-array params become pointers
14
+ isArray: boolean; // Array parameters pass naturally as pointers
15
+ arrayDims: string; // Array dimensions if applicable
16
+ }>;
17
+ typedefName: string; // e.g., "onReceive_fp"
18
+ }
19
+
20
+ export default ICallbackTypeInfo;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Function signature for const parameter tracking
3
+ * Used to validate const-to-non-const errors at call sites
4
+ */
5
+
6
+ interface IFunctionSignature {
7
+ name: string;
8
+ parameters: Array<{
9
+ name: string;
10
+ baseType: string; // The C-Next type (e.g., 'u32', 'f32')
11
+ isConst: boolean;
12
+ isArray: boolean;
13
+ }>;
14
+ }
15
+
16
+ export default IFunctionSignature;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Target platform capabilities for code generation
3
+ * Determines which atomic instructions and features are available
4
+ */
5
+
6
+ interface ITargetCapabilities {
7
+ wordSize: 8 | 16 | 32;
8
+ hasLdrexStrex: boolean;
9
+ hasBasepri: boolean;
10
+ }
11
+
12
+ export default ITargetCapabilities;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Code generation context - shared state across all codegen components
3
+ * Tracks current scope, variables, types, and generation state
4
+ */
5
+
6
+ import TParameterInfo from "./TParameterInfo";
7
+ import TTypeInfo from "./TTypeInfo";
8
+ import TOverflowBehavior from "./TOverflowBehavior";
9
+ import ITargetCapabilities from "./ITargetCapabilities";
10
+
11
+ /**
12
+ * Assignment context for overflow behavior tracking
13
+ */
14
+ export interface IAssignmentContext {
15
+ targetName: string | null;
16
+ targetType: string | null;
17
+ overflowBehavior: TOverflowBehavior;
18
+ }
19
+
20
+ /**
21
+ * Code generation context - mutable state passed to all codegen components
22
+ */
23
+ type TCodeGenContext = {
24
+ currentScope: string | null;
25
+ indentLevel: number;
26
+ scopeMembers: Map<string, Set<string>>;
27
+ currentParameters: Map<string, TParameterInfo>;
28
+ localArrays: Set<string>;
29
+ localVariables: Set<string>;
30
+ inFunctionBody: boolean;
31
+ typeRegistry: Map<string, TTypeInfo>;
32
+ expectedType: string | null;
33
+ mainArgsName: string | null;
34
+ assignmentContext: IAssignmentContext;
35
+ lastArrayInitCount: number;
36
+ lastArrayFillValue: string | undefined;
37
+ lengthCache: Map<string, string> | null;
38
+ targetCapabilities: ITargetCapabilities;
39
+ };
40
+
41
+ export default TCodeGenContext;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Codegen types barrel export
3
+ * Central export point for all codegen type definitions
4
+ */
5
+
6
+ export { default as ECommentType } from "./ECommentType";
7
+ export { default as IComment } from "./IComment";
8
+ export { default as ICommentError } from "./ICommentError";
9
+ export { default as TParameterInfo } from "./TParameterInfo";
10
+ export { default as TOverflowBehavior } from "./TOverflowBehavior";
11
+ export { default as TTypeInfo } from "./TTypeInfo";
12
+ export { default as TCodeGenContext } from "./TCodeGenContext";
13
+ export type { IAssignmentContext } from "./TCodeGenContext";
14
+ export { default as ITargetCapabilities } from "./ITargetCapabilities";
15
+ export { default as IFunctionSignature } from "./IFunctionSignature";
16
+ export { default as ICallbackTypeInfo } from "./ICallbackTypeInfo";
17
+ export * from "./TTypeConstants";