Make __field__ take a symbol instead of a string
authorDavid Kerkeslager <kerkeslager@gmail.com>
Sun, 3 Jan 2021 19:28:31 +0000 (14:28 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Sun, 3 Jan 2021 19:28:31 +0000 (14:28 -0500)
desugaring.py
normalization.py
templates/program2.c

index 28d1a78..b04cf1a 100644 (file)
@@ -88,6 +88,14 @@ DesugaredSymbolExpression = collections.namedtuple(
     ),
 )
 
+DesugaredSymbolLiteralExpression = collections.namedtuple(
+    'DesugaredSymbolLiteralExpression',
+    (
+        'metadata',
+        'symbol',
+    ),
+)
+
 DesugaredAssignmentStatement = collections.namedtuple(
     'DesugaredAssignmentStatement',
     (
@@ -166,7 +174,7 @@ def desugar_infix_expression(expression):
             ),
             argument_list=(
                 desugar_expression(expression.left),
-                DesugaredStringLiteralExpression(string=expression.right.symbol),
+                desugar_symbol_literal_expression(expression.right),
             ),
         )
 
@@ -259,6 +267,12 @@ def desugar_symbol_expression(expression):
         symbol=expression.symbol,
     )
 
+def desugar_symbol_literal_expression(expression):
+    return DesugaredSymbolLiteralExpression(
+        metadata=expression.metadata,
+        symbol=expression.symbol,
+    )
+
 def desugar_expression(expression):
     return {
         parsing.FurFunctionCallExpression: desugar_function_call_expression,
index 83e24dd..8248169 100644 (file)
@@ -231,6 +231,13 @@ def normalize_symbol_expression(counter, expression):
         NormalSymbolExpression(symbol=expression.symbol),
     )
 
+def normalize_symbol_literal_expression(counter, expression):
+    return (
+        counter,
+        (),
+        NormalSymbolLiteralExpression(symbol=expression.symbol),
+    )
+
 def normalize_function_call_expression(counter, expression):
     prestatements = []
 
@@ -300,6 +307,7 @@ def normalize_expression(counter, expression):
         desugaring.DesugaredStringLiteralExpression: normalize_string_literal_expression,
         desugaring.DesugaredStructureLiteralExpression: normalize_structure_literal_expression,
         desugaring.DesugaredSymbolExpression: normalize_symbol_expression,
+        desugaring.DesugaredSymbolLiteralExpression: normalize_symbol_literal_expression,
     }[type(expression)](counter, expression)
 
 def normalize_expression_statement(counter, statement):
index 679bbfb..d22d595 100644 (file)
@@ -131,7 +131,7 @@ void callBuiltinField(Thread* thread, size_t argumentCount) {
 
   assert(!Stack_isEmpty(&(thread->stack)));
   Object key = Stack_pop(&(thread->stack));
-  assert(key.type == STRING); // TODO Make this a symbol
+  assert(key.type == SYMBOL);
 
   assert(!Stack_isEmpty(&(thread->stack)));
   Object structure = Stack_pop(&(thread->stack));