mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-11 08:30:02 +00:00
ecs: start tests
This commit is contained in:
parent
0904e83bf6
commit
d986cda3b3
@ -194,7 +194,7 @@ interface ComponentFieldPair {
|
||||
|
||||
export class Dialect_CA65 {
|
||||
|
||||
readonly ASM_ITERATE_EACH = `
|
||||
ASM_ITERATE_EACH = `
|
||||
ldx #0
|
||||
@__each:
|
||||
{{%code}}
|
||||
@ -204,7 +204,7 @@ export class Dialect_CA65 {
|
||||
@__exit:
|
||||
`;
|
||||
|
||||
readonly ASM_ITERATE_JOIN = `
|
||||
ASM_ITERATE_JOIN = `
|
||||
ldy #0
|
||||
@__each:
|
||||
ldx {{%joinfield}},y
|
||||
@ -215,14 +215,14 @@ export class Dialect_CA65 {
|
||||
@__exit:
|
||||
`;
|
||||
|
||||
readonly ASM_FILTER_RANGE_LO_X = `
|
||||
ASM_FILTER_RANGE_LO_X = `
|
||||
cpx #{{%xofs}}
|
||||
bcc @__skipxlo
|
||||
{{%code}}
|
||||
@__skipxlo:
|
||||
`
|
||||
|
||||
readonly ASM_FILTER_RANGE_HI_X = `
|
||||
ASM_FILTER_RANGE_HI_X = `
|
||||
cpx #{{%xofs}}+{{%ecount}}
|
||||
bcs @__skipxhi
|
||||
{{%code}}
|
||||
@ -230,7 +230,7 @@ export class Dialect_CA65 {
|
||||
`
|
||||
|
||||
// TODO
|
||||
readonly ASM_MAP_RANGES = `
|
||||
ASM_MAP_RANGES = `
|
||||
txa
|
||||
pha
|
||||
lda {{%mapping}},x
|
||||
@ -242,26 +242,26 @@ export class Dialect_CA65 {
|
||||
tax
|
||||
`;
|
||||
|
||||
readonly INIT_FROM_ARRAY = `
|
||||
INIT_FROM_ARRAY = `
|
||||
ldy #{{%nbytes}}
|
||||
: lda {{%src}}-1,y
|
||||
sta {{%dest}}-1,y
|
||||
dey
|
||||
bne :-
|
||||
`
|
||||
readonly HEADER = `
|
||||
HEADER = `
|
||||
.include "vcs-ca65.h"
|
||||
.define PAL 0
|
||||
.code
|
||||
`
|
||||
readonly FOOTER = `
|
||||
FOOTER = `
|
||||
.segment "VECTORS"
|
||||
Return: .word $6060
|
||||
VecNMI:
|
||||
VecReset: .word Main::__Reset
|
||||
VecBRK: .word Main::__BRK
|
||||
`
|
||||
readonly TEMPLATE_INIT_MAIN = `
|
||||
TEMPLATE_INIT_MAIN = `
|
||||
__NMI:
|
||||
__Reset:
|
||||
__BRK:
|
||||
@ -433,6 +433,12 @@ class DataSegment {
|
||||
}
|
||||
}
|
||||
|
||||
class UninitDataSegment extends DataSegment {
|
||||
}
|
||||
|
||||
class ConstDataSegment extends DataSegment {
|
||||
}
|
||||
|
||||
function getFieldBits(f: IntType) {
|
||||
let n = f.hi - f.lo + 1;
|
||||
return Math.ceil(Math.log2(n));
|
||||
@ -820,8 +826,8 @@ export class EntityScope implements SourceLocated {
|
||||
systems: System[] = [];
|
||||
entities: Entity[] = [];
|
||||
fieldtypes: { [name: string]: 'init' | 'const' } = {};
|
||||
bss = new DataSegment();
|
||||
rodata = new DataSegment();
|
||||
bss = new UninitDataSegment();
|
||||
rodata = new ConstDataSegment();
|
||||
code = new CodeSegment();
|
||||
componentsInScope = new Set();
|
||||
tempOffset = 0;
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { readdirSync, readFileSync } from "fs";
|
||||
import { describe } from "mocha";
|
||||
import { ECSCompiler } from "../common/ecs/compiler";
|
||||
import { Dialect_CA65, EntityManager, SourceFileExport } from "../common/ecs/ecs";
|
||||
@ -363,3 +364,20 @@ describe('Tokenizer', function() {
|
||||
testCompiler();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Compiler', function() {
|
||||
let testdir = './test/ecs/';
|
||||
let files = readdirSync(testdir).filter(f => f.endsWith('.ecs'));
|
||||
files.forEach((ecspath) => {
|
||||
let dialect = new Dialect_CA65();
|
||||
dialect.HEADER = '';
|
||||
dialect.FOOTER = '';
|
||||
let em = new EntityManager(dialect);
|
||||
let compiler = new ECSCompiler(em);
|
||||
let code = readFileSync(testdir + ecspath, 'utf-8');
|
||||
compiler.parseFile(code, ecspath);
|
||||
let out = new SourceFileExport();
|
||||
em.exportToFile(out);
|
||||
console.log(out.toString());
|
||||
});
|
||||
});
|
||||
|
16
test/ecs/basic1.ecs
Normal file
16
test/ecs/basic1.ecs
Normal file
@ -0,0 +1,16 @@
|
||||
// comment
|
||||
/*
|
||||
mju,fjeqowfjqewiofjqe
|
||||
*/
|
||||
component Kernel
|
||||
lines: 0..255
|
||||
bgcolor: 0..255
|
||||
end
|
||||
|
||||
component Bitmap
|
||||
data: array of 0..255
|
||||
end
|
||||
|
||||
component HasBitmap
|
||||
bitmap: [Bitmap]
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user