Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CRAB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</None>
<!-- Include the Testing/HelloWorld.cs file -->
<Compile Include="Testing\HelloWorld.cs" />
<Compile Include="Testing\Program.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
27 changes: 19 additions & 8 deletions Compiler/Core/MapSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2212,8 +2212,13 @@ private static string MapTypeNodeToWasm(AstNode typeNode)
// VARIABLE DECLARATIONS (Extended)
// ============================================================

/// <summary>Local declaration statement</summary>
public Map LocalDeclaration = "{type} {declarators}";
/// <summary>Local declaration statement.
/// Due to CDTk parser field shifting when the optional 'modifier' is absent,
/// the actual AST layout is: modifier=LocalVariableType, type=LocalVariableDeclarators.
/// {modifier} routes through LocalVariableType to emit the WASM type (i32/i64/f32/f64).
/// {type} routes through LocalVariableDeclarators to emit declarator info.
/// </summary>
public Map LocalDeclaration = "{modifier} {type}";

/// <summary>Local variable declarator</summary>
public Map LocalVariableDeclarator = "(local ${name} {type} {init})";
Expand All @@ -2227,8 +2232,9 @@ private static string MapTypeNodeToWasm(AstNode typeNode)
/// <summary>Local variable modifier (const, ref, etc.)</summary>
public Map LocalVariableModifier = "{modifier}";

/// <summary>Local variable type</summary>
public Map LocalVariableType = "{type}";
/// <summary>Local variable type. Uses {base} field (not {type}) because CDTk places
/// the matched alternative in 'base' for this rule pattern.</summary>
public Map LocalVariableType = "{base}";

/// <summary>Constant declarator</summary>
public Map ConstantDeclarator = "(global ${name} {type} {value})";
Expand Down Expand Up @@ -2327,11 +2333,16 @@ private static string MapTypeNodeToWasm(AstNode typeNode)
/// <summary>Primitive type dispatcher</summary>
public Map PrimitiveType = "{type}";

/// <summary>Integral type - most map to i32 in WASM (except long/ulong)</summary>
public Map IntegralType = "i32";
/// <summary>Integral type - delegates to the matched keyword token via {type}.
/// The {type} field contains a KwXxx token node (e.g. KwLong, KwInt) whose Maps
/// produce the correct WASM type: KwInt-&gt;i32, KwLong-&gt;i64, KwUlong-&gt;i64, etc.
/// Requires FloatingPointType rule to have .Returns("type") to work correctly.</summary>
public Map IntegralType = "{type}";

/// <summary>Floating point type - default to f64</summary>
public Map FloatingPointType = "f64";
/// <summary>Floating point type - delegates to the matched keyword token via {type}.
/// The {type} field contains KwFloat or KwDouble, whose Maps produce f32 and f64 respectively.
/// Requires FloatingPointType rule to have .Returns("type") to work correctly.</summary>
public Map FloatingPointType = "{type}";

/// <summary>Named type (user-defined type)</summary>
public Map NamedType = "(ref ${name}{typeArgs})";
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Core/RuleSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ public class Rules : RuleSet
public Rule IntegralType = new Rule("type:@KwSbyte | type:@KwByte | type:@KwShort | type:@KwUshort | type:@KwInt | type:@KwUint | type:@KwLong | type:@KwUlong | type:@KwNint | type:@KwNuint")
.Returns("type");

public Rule FloatingPointType = "type:@KwFloat | type:@KwDouble";
public Rule FloatingPointType = new Rule("type:@KwFloat | type:@KwDouble")
.Returns("type");

public Rule TypeArgumentList = new Rule("@LessThan args:TypeArguments @GreaterThan")
.Returns("args");
Expand Down
Loading