--- /dev/null
+print(true)
+print('\n')
+print(false)
--- /dev/null
+true
+false
\ No newline at end of file
''.join(c_escape(ch for ch in c_string_literal.value)),
)
+
+CONSTANT_EXPRESSION_MAPPING = {
+ 'true': 'TRUE',
+ 'false': 'FALSE',
+}
+
+def generate_constant_expression(c_constant_expression):
+ return CONSTANT_EXPRESSION_MAPPING[c_constant_expression.value]
+
def generate_symbol_expression(c_symbol_expression):
return 'Environment_get(environment, SYMBOL_LIST[{}] /* symbol: {} */)'.format(
c_symbol_expression.symbol_list_index,
LITERAL_TYPE_MAPPING = {
transformation.CIntegerLiteral: generate_integer_literal,
transformation.CStringLiteral: generate_string_literal,
+ transformation.CConstantExpression: generate_constant_expression,
transformation.CSymbolExpression: generate_symbol_expression,
}
enum Type
{
+ BOOLEAN,
INTEGER,
STRING
};
union Instance
{
+ bool boolean;
int32_t integer;
String* string;
};
Instance instance;
};
+const Object TRUE = {
+ BOOLEAN,
+ true
+};
+
+const Object FALSE = {
+ BOOLEAN,
+ false
+};
+
struct EnvironmentNode;
typedef struct EnvironmentNode EnvironmentNode;
struct EnvironmentNode
{
switch(output.type)
{
+ case BOOLEAN:
+ fputs(output.instance.boolean ? "true" : "false", stdout);
+ break;
+
case INTEGER:
printf("%" PRId32, output.instance.integer);
break;
],
)
+CConstantExpression = collections.namedtuple(
+ 'CConstantExpression',
+ [
+ 'value'
+ ],
+)
+
CSymbolExpression = collections.namedtuple(
'CSymbolExpression',
[
)
BUILTINS = {
+ 'false': [],
'pow': ['math.h'],
'print': ['stdio.h'],
+ 'true': [],
}
def transform_expression(builtin_dependencies, symbol_list, expression):
return transform_function_call_expression(builtin_dependencies, symbol_list, expression)
if isinstance(expression, parsing.FurSymbolExpression):
+ if expression.value in ['true', 'false']:
+ return CConstantExpression(value=expression.value)
+
if expression.value not in symbol_list:
symbol_list.append(expression.value)
def transform_function_call_expression(builtin_dependencies, symbol_list, function_call):
if function_call.function.value in BUILTINS.keys():
+ # TODO Check that the builtin is actually callable
builtin_dependencies.add(function_call.function.value)
return CFunctionCallExpression(