<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pastel.Nodes;

namespace LangC
{
    public abstract class CTranslator : Platform.CurlyBraceTranslator
    {
        public StringTableBuilder StringTableBuilder { get; set; }

        public CTranslator(Platform.AbstractPlatform platform) : base(platform, "    ", "\n", false)
        { }

        public override void TranslateArrayGet(StringBuilder sb, Expression array, Expression index)
        {
            this.TranslateExpression(sb, array);
            sb.Append('[');
            this.TranslateExpression(sb, index);
            sb.Append(']');
        }

        public override void TranslateArrayJoin(StringBuilder sb, Expression array, Expression sep)
        {
            sb.Append("TranslationHelper_array_join(");
            this.TranslateExpression(sb, array);
            sb.Append(", ");
            this.TranslateExpression(sb, sep);
            sb.Append(')');
        }

        public override void TranslateArrayLength(StringBuilder sb, Expression array)
        {
            PType itemType = array.ResolvedType.Generics[0];
            if (itemType.RootValue == "int")
            {
                this.TranslateExpression(sb, array);
                sb.Append("[-1]");
            }
            else
            {
                sb.Append("(int*)(");
                this.TranslateExpression(sb, array);
                sb.Append(")[-1]");
            }
        }

        public override void TranslateArrayNew(StringBuilder sb, PType arrayType, Expression lengthExpression)
        {
            // TODO: I'd like to make a distinction (in the VM source) between arrays that need to have array
            // length and arrays that don't. If array length isn't needed, the malloc can go inline and it saves
            // an extra 4 bytes of space and time.
            // Potentially there'd be a virtual function called TranslateArrayNewWithoutLength that just calls this
            // and so it won't clutter up the interface implementation for 90% of languages that don't need the
            // distinction.t
            string type = this.Platform.TranslateType(arrayType);
            sb.Append("(");
            sb.Append(type);<commit_msg>Fix some C compilation errors due to bad parenthesis association<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pastel.Nodes;

namespace LangC
{
    public abstract class CTranslator : Platform.CurlyBraceTranslator
    {
        public StringTableBuilder StringTableBuilder { get; set; }

        public CTranslator(Platform.AbstractPlatform platform) : base(platform, "    ", "\n", false)
        { }

        public override void TranslateArrayGet(StringBuilder sb, Expression array, Expression index)
        {
            this.TranslateExpression(sb, array);
            sb.Append('[');
            this.TranslateExpression(sb, index);
            sb.Append(']');
        }

        public override void TranslateArrayJoin(StringBuilder sb, Expression array, Expression sep)
        {
            sb.Append("TranslationHelper_array_join(");
            this.TranslateExpression(sb, array);
            sb.Append(", ");
            this.TranslateExpression(sb, sep);
            sb.Append(')');
        }

        public override void TranslateArrayLength(StringBuilder sb, Expression array)
        {
            PType itemType = array.ResolvedType.Generics[0];
            if (itemType.RootValue == "int")
            {
                sb.Append('(');
                this.TranslateExpression(sb, array);
                sb.Append(")[-1]");
            }
            else
            {
                sb.Append("((int*)(");
                this.TranslateExpression(sb, array);
                sb.Append("))[-1]");
            }
        }

        public override void TranslateArrayNew(StringBuilder sb, PType arrayType, Expression lengthExpression)
        {
            // TODO: I'd like to make a distinction (in the VM source) between arrays that need to have array
            // length and arrays that don't. If array length isn't needed, the malloc can go inline and it saves
            // an extra 4 bytes of space and time.
            // Potentially there'd be a virtual function called TranslateArrayNewWithoutLength that just calls this
            // and so it won't clutter up the interface implementation for 90% of languages that don't need the
            // distinction.t
            string type = this.Platform.TranslateType(arrayType);
            sb.Append("(");
            sb.Append(type);
{'fraction_non_alphanumeric': 0.09379014989293362, 'fraction_numerical': 0.002569593147751606, 'mean_word_length': 2.044980443285528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5806135', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1135, 'n_words': 345}