<commit_before>//
//  codegen.c
//  v6502
//
//  Created by <NAME> on H.25/05/21.
//  Copyright (c) 平成25年 Hello-Channel, LLC. All rights reserved.
//

#include "codegen.h"
#include "parser.h"
#include "linectl.h"

#include <string.h>
#include <stdlib.h>

static size_t _lengthOfValue(char *start) {
	
}

void as6502_resolveArithmetic(char *line, size_t len) {
	char *cur, start;
	size_t clause = 0;
	uint16_t left, right;
	uint8_t high, low;
	
	// Check for addition
	cur = memchr(line, '+', len);
	if (cur) {
		v6502_valueForString(&high, &low, NULL, cur + 1);
		right = (high << 8) | low;
		
		// FIXME: This currently relies on the first space found in reverse
		// being separate from the arithmetic clause, and a delimeter for the
		// left hand value. Not sure if this is proper if whitespace is allowed
		// in between operators and values.
		cur = rev_strnchr(line, cur, ' ');
		v6502_valueForString(&high, &low, NULL, cur + 1);
		left = (high << 8) | low;
		
		// Solve
		left += right;
	}
	
	
	// Put resolved value in
	if (clause) {
		//as6502
	}
}

int as6502_resolveVariableDeclaration(char *line, size_t len) {
	// This will take 1 line in and output 4 lines
	// e.g.	 IN: var1 = $ff
	//		OUT:	pha
	//				lda #$ff
	//				sta var1
	//				pla
	
	return NO;
}
<commit_msg>Use strnchr and _lengthOfValue to properly come up with the arithmetic result and clause size now<commit_after>//
//  codegen.c
//  v6502
//
//  Created by <NAME> on H.25/05/21.
//  Copyright (c) 平成25年 Hello-Channel, LLC. All rights reserved.
//

#include "codegen.h"
#include "parser.h"
#include "linectl.h"
#include "symbols.h"

#include <string.h>
#include <stdlib.h>

static size_t _lengthOfValue(char *start) {
	size_t i;
	for (i = 0; start[i]; i++) {
		if (!v6502_isDigit(start[i])) {
			return i;
		}
	}
	return i;
}

void as6502_resolveArithmetic(char *line, size_t len) {
	char *cur, *start;
	size_t clause = 0;
	uint16_t left, right, result;
	uint8_t high, low;
	
	// Check for addition
	cur = strnchr(line, '+', len);
	if (cur) {
		// Get right hand side
		cur++;
		v6502_valueForString(&high, &low, NULL, cur);
		right = (high << 8) | low;
		
		// Get left hand side
		// FIXME: This currently relies on the first space found in reverse
		// being separate from the arithmetic clause, and a delimeter for the
		// left hand value. Not sure if this is proper if whitespace is allowed
		// in between operators and values.
		start = rev_strnchr(line, cur, ' ') + 1;
		v6502_valueForString(&high, &low, NULL, start);
		left = (high << 8) | low;
		
		// Solve
		result = left + right;
		clause = (cur + _lengthOfValue(cur)) - start;
	}
	
	
	// Put resolved value in
	if (clause) {
		//as6502_replaceSymbolInLineAtLocationWithText(line, len, start, <#const char *symbol#>, <#const char *text#>);
	}
}

int as6502_resolveVariableDeclaration(char *line, size_t len) {
	// This will take 1 line in and output 4 lines
	// e.g.	 IN: var1 = $ff
	//		OUT:	pha
	//				lda #$ff
	//				sta var1
	//				pla
	
	return NO;
}

{'fraction_non_alphanumeric': 0.13790806129247168, 'fraction_numerical': 0.030646235842771485, 'mean_word_length': 2.961741424802111, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 11, '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': '605749', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1126, 'n_words': 360}