1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-03 07:29:37 +00:00

Retired special file extension .kc. Now using .c for all examples and tests. Closes #195

This commit is contained in:
jespergravgaard 2020-04-11 16:06:15 +02:00
parent d95fea6975
commit c150976b2f
823 changed files with 1136 additions and 1122 deletions

View File

@ -67,7 +67,8 @@
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**/*.kc</include>
<include>**/*.c</include>
<include>**/*.h</include>
<include>**/*.asm</include>
<include>**/*.sym</include>
<include>**/*.cfg</include>

View File

@ -15,7 +15,8 @@
<directory>src/main/kc/stdlib</directory>
<outputDirectory>stdlib</outputDirectory>
<includes>
<include>*.kc</include>
<include>*.c</include>
<include>*.h</include>
</includes>
</fileSet>
<fileSet>
@ -30,7 +31,8 @@
<directory>src/test/kc/examples</directory>
<outputDirectory>examples</outputDirectory>
<includes>
<include>*/*.kc</include>
<include>*/*.c</include>
<include>*/*.h</include>
<include>*/*.ld</include>
<include>*/*.png</include>
<include>*/*.sid</include>

View File

@ -144,11 +144,11 @@ public class Compiler {
program.getImportPaths().add(path);
}
public void preprocess(List<Path> files) {
public void preprocess(List<Path> cFiles) {
Path currentPath = new File(".").toPath();
CParser cParser = new CParser(program);
for(Path file : files) {
final KickCLexer fileLexer = cParser.loadCFile(file.toString(), currentPath);
for(Path cFile : cFiles) {
final KickCLexer fileLexer = cParser.loadCFile(cFile.toString(), currentPath);
cParser.addSourceLast(fileLexer);
}
final CPreprocessor preprocessor = cParser.getPreprocessor();
@ -160,16 +160,13 @@ public class Compiler {
System.out.println();
}
public void compile(List<Path> files) {
if(files.size() == 0)
public void compile(List<Path> cFiles) {
if(cFiles.size() == 0)
throw new CompileError("Error! You must supply at least one file to compile!");
final Path primaryFile = files.get(0);
String primaryFileName = primaryFile.toString();
if(primaryFileName.endsWith(".kc")) {
primaryFileName = primaryFileName.substring(0, primaryFileName.length() - 3);
}
program.setPrimaryFileName(primaryFileName);
final Path primaryCFile = cFiles.get(0);
String primaryCFileBaseName = removeFileNameExtension(primaryCFile.toString());
program.setPrimaryFileName(primaryCFileBaseName);
try {
Path currentPath = new File(".").toPath();
@ -178,7 +175,7 @@ public class Compiler {
}
program.setStatementSequence(new StatementSequence());
CParser cParser = new CParser(program);
for(Path file : files) {
for(Path file : cFiles) {
final KickCLexer fileLexer = cParser.loadCFile(file.toString(), currentPath);
cParser.addSourceLast(fileLexer);
}
@ -223,6 +220,21 @@ public class Compiler {
}
}
/**
* Remove extension from a file name if it is present.
*
* @param fileName The file name
* @return file name without extension
*/
public static String removeFileNameExtension(String fileName) {
final int lastDotIdx = fileName.lastIndexOf('.');
final int lastSlashIdx = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
if(lastDotIdx > 0 && lastDotIdx > (lastSlashIdx + 1)) {
fileName = fileName.substring(0, lastDotIdx);
}
return fileName;
}
private void pass1GenerateSSA() {
if(getLog().isVerboseStatementSequence()) {
getLog().append("\nSTATEMENTS");

View File

@ -23,7 +23,7 @@ import java.util.stream.Collectors;
/** KickC Commandline */
@CommandLine.Command(
description = "Compiles a KickC source file, creating a KickAssembler source file. " +
description = "Compiles C source files. " +
"KickC is a C-compiler creating optimized and readable 6502 assembler code.%n%n" +
"See https://gitlab.com/camelot/kickc for detailed information about KickC.",
name = "kickc",
@ -33,12 +33,12 @@ import java.util.stream.Collectors;
descriptionHeading = "%nDescription:%n%n",
parameterListHeading = "%nParameters:%n",
optionListHeading = "%nOptions:%n",
version = "KickC 0.7.12 BETA (master)"
version = "KickC 0.8 BETA (master)"
)
public class KickC implements Callable<Void> {
@CommandLine.Parameters(index = "0", arity = "0..n", description = "The KickC source files to compile.")
private List<Path> kcFiles = null;
@CommandLine.Parameters(index = "0", arity = "0..n", description = "The C source files to compile.")
private List<Path> cFiles = null;
@CommandLine.Option(names = {"-I", "-libdir"}, description = "Path to a library folder, where the compiler looks for included files. This option can be repeated to add multiple library folders.")
private List<Path> libDir = null;
@ -241,18 +241,18 @@ public class KickC implements Callable<Void> {
}
}
if(kcFiles != null && !kcFiles.isEmpty()) {
if(cFiles != null && !cFiles.isEmpty()) {
final Path primaryKcFile = kcFiles.get(0);
String primaryFileBaseName = getFileBaseName(primaryKcFile);
final Path primaryCFile = cFiles.get(0);
String primaryFileBaseName = getFileBaseName(primaryCFile);
Path kcFileDir = primaryKcFile.getParent();
if(kcFileDir == null) {
kcFileDir = FileSystems.getDefault().getPath(".");
Path CFileDir = primaryCFile.getParent();
if(CFileDir == null) {
CFileDir = FileSystems.getDefault().getPath(".");
}
if(outputDir == null) {
outputDir = kcFileDir;
outputDir = CFileDir;
}
if(!Files.exists(outputDir)) {
Files.createDirectory(outputDir);
@ -328,13 +328,13 @@ public class KickC implements Callable<Void> {
compiler.setCallingConvention(callingConvention);
}
StringBuilder kcFileNames = new StringBuilder();
kcFiles.stream().forEach(path -> kcFileNames.append(path.toString()).append(" "));
StringBuilder CFileNames = new StringBuilder();
cFiles.stream().forEach(path -> CFileNames.append(path.toString()).append(" "));
if(preprocess) {
System.out.println("Preprocessing " + kcFileNames);
System.out.println("Preprocessing " + CFileNames);
try {
compiler.preprocess(kcFiles);
compiler.preprocess(cFiles);
} catch(CompileError e) {
// Print the error and exit with compile error
System.err.println(e.getMessage());
@ -343,10 +343,10 @@ public class KickC implements Callable<Void> {
return null;
}
System.out.println("Compiling " + kcFileNames);
System.out.println("Compiling " + CFileNames);
Program program = compiler.getProgram();
try {
compiler.compile(kcFiles);
compiler.compile(cFiles);
} catch(CompileError e) {
// Print the error and exit with compile error
System.err.println(e.getMessage());
@ -366,7 +366,7 @@ public class KickC implements Callable<Void> {
compiler.getAsmFragmentSynthesizer().finalize(compiler.getLog());
// Copy Resource Files (if out-dir is different from in-dir)
if(!kcFileDir.toAbsolutePath().equals(outputDir.toAbsolutePath())) {
if(!CFileDir.toAbsolutePath().equals(outputDir.toAbsolutePath())) {
for(Path resourcePath : program.getAsmResourceFiles()) {
Path outResourcePath = outputDir.resolve(resourcePath.getFileName().toString());
System.out.println("Copying resource " + outResourcePath);
@ -503,7 +503,7 @@ public class KickC implements Callable<Void> {
return new CommandLine(new KickC()).getCommandSpec().version()[0];
}
String getFileBaseName(Path file) {
static String getFileBaseName(Path file) {
String name = file.getFileName().toString();
int i = name.lastIndexOf('.');
return i > 0 ? name.substring(0, i) : name;

View File

@ -163,16 +163,13 @@ public class CParser {
*
* @param fileName The file name of the file
* @param currentPath The path of the current folder (searched before the search path).
* @return The lexer to be inserted into the source-list using onw of the {@link #addSourceFirst(KickCLexer)} methods.
* @return The lexer to be inserted into the source-list using one of the {@link #addSourceFirst(KickCLexer)} / {@link #addSourceLast(KickCLexer)} methods.
*/
public KickCLexer loadCFile(String fileName, Path currentPath) {
try {
if(fileName.startsWith("\"") || fileName.startsWith("<")) {
fileName = fileName.substring(1, fileName.length() - 1);
}
if(!fileName.endsWith(".kc") && !fileName.contains(".")) {
fileName += ".kc";
}
File file = SourceLoader.loadFile(fileName, currentPath, program);
List<String> imported = program.getImported();
if(imported.contains(file.getAbsolutePath())) {

View File

@ -1,5 +1,5 @@
// Simple single-color (320x200) bitmap routines
#include <string>
#include <string.c>
// The adddress of the bitmap screen (used for colors)
byte* bitmap_screen;

View File

@ -4,7 +4,7 @@
// (J) https://www.c64-wiki.com/wiki/C64DTV_Programming_Guide
// (H) http://dtvhacking.cbm8bit.com/dtv_wiki/images/d/d9/Dtv_registers_full.txt
#include <c64.kc>
#include <c64.c>
// Feature enables or disables the extra C64 DTV features
byte* const DTV_FEATURE = $d03f;

View File

@ -16,7 +16,7 @@
// |7. | #%01111111 (127/$7f) | STOP ($ )| q ($11)|COMMODR($ )| SPACE ($20)| 2 ($32)|CONTROL($ )| <- ($1f)| 1 ($31)|
// +----+----------------------+------------+------------+------------+------------+------------+------------+------------+------------+
#include <c64>
#include <c64.c>
// Keyboard Codes for all 63 keys.
// Keyboard Codes are %00rrrccc, where rrr is the row ID (0-7) and ccc is the column ID (0-7).

View File

@ -12,7 +12,7 @@
// In practice a good method is to wait until the raster is beyond plexFreeNextYpos() and then call plexShowSprite(). Repeat until all 32 sprites have been shown.
// TODO: Let the caller specify the number of sprites to use (or add PLEX_ENABLE[PLEX_COUNT])
#include <c64>
#include <c64.c>
// The number of sprites in the multiplexer
const char PLEX_COUNT = 32;

View File

@ -1,5 +1,5 @@
#include <stdlib>
#include <string>
#include <stdlib.c>
#include <string.c>
byte* print_screen = $0400;
byte* print_line_cursor = print_screen;

View File

@ -4,8 +4,8 @@
// Uses the approximation sin(x) = x - x^/6 + x^/128
// Optimization possibility: Use symmetries when generating sinustables. wavelength%2==0 -> mirror symmetry over PI, wavelength%4==0 -> mirror symmetry over PI/2.
#include <division>
#include <multiply>
#include <division.c>
#include <multiply.c>
// PI*2 in u[4.28] format
const dword PI2_u4f28 = $6487ed51;

View File

@ -1,6 +1,6 @@
// Table-based implementation of integer square sqr() and square root sqrt()
#include <stdlib>
#include <stdlib.c>
// The number of squares to pre-calculate. Limits what values sqr() can calculate and the result of sqrt()
byte NUM_SQUARES = 0xff;

View File

@ -1,6 +1,6 @@
// C standard library stdlib.h
// Implementation of functions found int C stdlib.h / stdlib.c
#include <string>
#include <string.c>
// Top of the heap used by malloc()
unsigned char* HEAP_TOP = 0xa000;

View File

@ -1,7 +1,7 @@
// C standard library time.h
// Functions to get and manipulate date and time information.
#include <c64>
#include <c64.c>
// Type suitable for storing the processor time.
typedef unsigned long clock_t;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
#include "bgblacklib"
#include "bgblacklib.c"
void main() {
*BGCOL = BLACK;
}

View File

@ -1,4 +1,4 @@
#include <c64>
#include <c64.c>
byte* const SCREEN = $400;
byte* const BITMAP = $2000;

View File

@ -2,7 +2,7 @@
// Coded by Richard-William Loerakker
// Original Source https://bcaorganizer.blogspot.com/p/c-program-for_21.html?fbclid=IwAR0iL8pYcCqhCPa6LmtQ9qej-YonYVepY2cBegYRIWO0l8RPeOnTVniMAac
#include <c64>
#include <c64.c>
byte* const SCREEN = $400;
byte* const BITMAP = $2000;

View File

@ -1,8 +1,8 @@
// Illustrates problem with bitmap-draw.kc line()
// Reported by Janne Johansson
#include <c64>
#include <bitmap-draw>
#include <c64.c>
#include <bitmap-draw.c>
byte* const SCREEN = $400;
byte* const BITMAP = $2000;

View File

@ -1,8 +1,8 @@
// Shows that bitmap2.kc line() does not have the same problem as bitmap-draw.kc
// See bitmap-line-anim-1.kc
#include <c64>
#include <bitmap2>
#include <c64.c>
#include <bitmap2.c>
byte* const SCREEN = $400;
byte* const BITMAP = $2000;

View File

@ -1,7 +1,7 @@
// Tests the simple bitmap plotter - and counts plots per frame in an IRQ
// Plots simple plots
#include <c64>
#include <bitmap2>
#include <c64.c>
#include <bitmap2.c>
byte* BITMAP = 0x2000;
byte* SCREEN = 0x0400;

View File

@ -1,9 +1,9 @@
// Tests the simple bitmap plotter - and counts plots per frame in an IRQ
// Plots a fullscreen elipsis
#include <c64>
#include <sinus>
#include <multiply>
#include <bitmap2>
#include <c64.c>
#include <sinus.c>
#include <multiply.c>
#include <bitmap2.c>
byte* BITMAP = 0x2000;
byte* SCREEN = 0x0400;

View File

@ -1,9 +1,9 @@
// Tests the simple bitmap plotter - and counts plots per frame in an IRQ
// Plots a spiral
#include <c64>
#include <sinus>
#include <multiply>
#include <bitmap2>
#include <c64.c>
#include <sinus.c>
#include <multiply.c>
#include <bitmap2.c>
byte* BITMAP = 0x2000;
byte* SCREEN = 0x0400;

View File

@ -1,8 +1,8 @@
// Tests the simple bitmap plotter
// Plots a few lines using the bresenham line algorithm
#include <c64>
#include <bitmap2>
#include <print>
#include <c64.c>
#include <bitmap2.c>
#include <print.c>
byte* BITMAP = 0x2000;
byte* SCREEN = 0x0400;

View File

@ -1,6 +1,6 @@
// Tests the different standard C types
#include <print>
#include <print.c>
void main() {
print_cls();

View File

@ -1,5 +1,5 @@
// C64DTV 8bpp charmode stretcher
#include <c64dtv>
#include <c64dtv.c>
// Plane with the screen
byte* const SCREEN = $7c00;

View File

@ -1,5 +1,5 @@
// C64DTV 8bpp charmode stretcher
#include <c64dtv>
#include <c64dtv.c>
// Plane with all pixels
byte* const CHUNKY = $8000;

View File

@ -1,6 +1,6 @@
// Fill a box on the screen using the blitter
#include <c64dtv>
#include <c64dtv.c>
byte* const SCREEN = $400;
const byte SRCA[] = "camelot rules!";

View File

@ -1,4 +1,4 @@
#include <c64dtv>
#include <c64dtv.c>
byte* const SCREEN = $400;
const byte SRCA[] = { 'c', 'a', 'm', 'e', 'l', 'o', 't', '!', ' '};

View File

@ -1,6 +1,6 @@
// Test C64DTV v2 256-colors and the 16-color redefinable palette
#include <c64dtv>
#include <c64dtv.c>
void main() {
asm { sei }

View File

@ -1,8 +1,8 @@
// Interactive Explorer for C64DTV Screen Modes
#include <c64dtv>
#include <print>
#include <keyboard>
#include <bitmap-draw>
#include <c64dtv.c>
#include <print.c>
#include <keyboard.c>
#include <bitmap-draw.c>
void main() {
asm { sei } // Disable normal interrupt (prevent keyboard reading glitches and allows to hide basic/kernal)

View File

@ -1,8 +1,8 @@
// Exploring C64DTV Screen Modes
#include <c64dtv>
#include <print>
#include <keyboard>
#include <bitmap-draw>
#include <c64dtv.c>
#include <print.c>
#include <keyboard.c>
#include <bitmap-draw.c>
void main() {
asm { sei } // Disable normal interrupt (prevent keyboard reading glitches and allows to hide basic/kernal)

Some files were not shown because too many files have changed in this diff Show More