From c4de9dca8a54bb5eb611a87b4d9fe36b0fe9a0b1 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Sun, 3 Jan 2021 14:28:31 -0500 Subject: [PATCH] Make __field__ take a symbol instead of a string --- desugaring.py | 16 +++++++++++++++- normalization.py | 8 ++++++++ templates/program2.c | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/desugaring.py b/desugaring.py index 28d1a78..b04cf1a 100644 --- a/desugaring.py +++ b/desugaring.py @@ -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, diff --git a/normalization.py b/normalization.py index 83e24dd..8248169 100644 --- a/normalization.py +++ b/normalization.py @@ -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): diff --git a/templates/program2.c b/templates/program2.c index 679bbfb..d22d595 100644 --- a/templates/program2.c +++ b/templates/program2.c @@ -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)); -- 2.20.1