<commit_before>#ifndef _COMP_C
#define _COMP_C

#include <stdio.h>
#include "main.h"

typedef enum {
  INTEGER,
  PLUS,
  MINUS,
  MULTIPLY,
  DIVIDE
} NodeTypes;

typedef struct Node {
  int type; //from NodeTypes
  int value;
  struct Node* left;    //left operand
  struct Node* right;    //right operand
} Node;

Node NodeBuilder(int type, int value, Node* left, Node* right) {
  Node o;
  o.type = type;
  if (o.type == INTEGER) o.value = value;
  else o.value = 0;
  o.left = left;
  o.right = right;
  return o;
}

void parse(const char* code, DWORD* program) {
  printf("Beginning parsing.\n");
  DWORD* buffer[1024];  //buffer for compiled code
  int count = 0;        //number of compiled instructions

  count = 6;  //TEST COUNT

  program[0] = count; //pack count into first position
  DWORD test[] = {PUSH, 2, PUSH, 2, ADD, HALT}; //TEST PROGRAM
  printf("Copying memory.\n");
  memcpy(program, test, 6 * sizeof(DWORD));
  printf("Finished parsing. Returning compiled program.\n");
}

//insert one char into output file
void insertchar(const char input, FILE* file) {
  putc(input, file);
  int subdivisions = sizeof(DWORD) / sizeof(char);
  subdivisions--;
  int i;
  for(i = 0; i < subdivisions; i++) {
    putc((char)0, file);
  }
}

//concatenates directory and filename into one string, or any two strings
char* catstr(char* dir, char* file) {
  //allocate enough space for full filename
  char* fullname = malloc(strlen(dir) + strlen(file) + 2);
  strcpy(fullname, dir);
  strcat(fullname, file);
  return fullname;
}

void compile(char* code, char* outfile) {
  
  printf("Beginning compilation.\n");

  //setup output file
  char* filename = catstr("../bin/", outfile);
  FILE* out = fopen(filename, "w"); //open file for writing<commit_msg>Minor changes. I'm getting so lazy with these commit messages.<commit_after>#ifndef _COMP_C
#define _COMP_C

#include <stdio.h>
#include "main.h"

typedef enum {
  INTEGER,
  PLUS,
  MINUS,
  MULTIPLY,
  DIVIDE
} NodeTypes;

typedef struct Node {
  int type; //from NodeTypes
  int value;
  struct Node* left;    //left operand
  struct Node* right;    //right operand
} Node;

Node NodeBuilder(int type, int value, Node* left, Node* right) {
  Node o;
  o.type = type;
  if (o.type == INTEGER) o.value = value;
  else o.value = 0;
  o.left = left;
  o.right = right;
  return o;
}

void removewhitespace(FILE* rawcode, char* purecode) {
  int c;
  while((c = fgetc(rawcode)) != EOF) {
  printf("\nTEMP\n");
    switch(c) {
      case ' ': break;  //ignore spaces
      default: break; //ignore unknown characters
    }
  }
}

void parse(const FILE* code, DWORD* program) {
  printf("Beginning parsing.\n");
  DWORD* buffer[1024];  //compiled code buffer: 1024 * 32b = 4kB
  int count = 0;        //number of compiled instructions

  char purecode[1024 * 16];  //uncompiled code buffer: 1024 * 16kB * 8b = 256kB
  removewhitespace(code, purecode);

  count = 6;  //TEST COUNT

  program[0] = count; //pack count into first position
  DWORD test[] = {PUSH, 2, PUSH, 2, ADD, HALT}; //TEST PROGRAM
  printf("Copying memory.\n");
  memcpy(program, test, 6 * sizeof(DWORD));
  printf("Finished parsing. Returning compiled program.\n");
}

//insert one char into output file
void insertchar(const char input, FILE* file) {
  putc(input, file);
  int subdivisions = sizeof(DWORD) / sizeof(char);
  subdivisions--;
  int i;
  for(i = 0; i < subdivisions; i++) {
    putc((char)0, file);
  }
}

//concatenates directory and filename into one string, or any two strings
char* catstr(char* dir, char* file) {
  //allocate enough space for full filename
  char* fullname = malloc(strlen(dir) + strlen(file) + 2);
  strcpy(fullname, dir);
  strcat(fullname, file);
  return fullname;
}

void compile(const FILE* code, char* outfile) {
  
  printf("Beginning compilation.\n");

  //setup output file
  char* filename = catstr("../bin/", outfile);
  FILE* out = fopen(filename, "w"); //open file for writing
{'fraction_non_alphanumeric': 0.139099645928174, 'fraction_numerical': 0.012898330804248861, 'mean_word_length': 3.3944444444444444, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2515284', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1347, 'n_words': 442}