ecs: start tests
This commit is contained in:
parent
0904e83bf6
commit
d986cda3b3
|
@ -194,7 +194,7 @@ interface ComponentFieldPair {
|
||||||
|
|
||||||
export class Dialect_CA65 {
|
export class Dialect_CA65 {
|
||||||
|
|
||||||
readonly ASM_ITERATE_EACH = `
|
ASM_ITERATE_EACH = `
|
||||||
ldx #0
|
ldx #0
|
||||||
@__each:
|
@__each:
|
||||||
{{%code}}
|
{{%code}}
|
||||||
|
@ -204,7 +204,7 @@ export class Dialect_CA65 {
|
||||||
@__exit:
|
@__exit:
|
||||||
`;
|
`;
|
||||||
|
|
||||||
readonly ASM_ITERATE_JOIN = `
|
ASM_ITERATE_JOIN = `
|
||||||
ldy #0
|
ldy #0
|
||||||
@__each:
|
@__each:
|
||||||
ldx {{%joinfield}},y
|
ldx {{%joinfield}},y
|
||||||
|
@ -215,14 +215,14 @@ export class Dialect_CA65 {
|
||||||
@__exit:
|
@__exit:
|
||||||
`;
|
`;
|
||||||
|
|
||||||
readonly ASM_FILTER_RANGE_LO_X = `
|
ASM_FILTER_RANGE_LO_X = `
|
||||||
cpx #{{%xofs}}
|
cpx #{{%xofs}}
|
||||||
bcc @__skipxlo
|
bcc @__skipxlo
|
||||||
{{%code}}
|
{{%code}}
|
||||||
@__skipxlo:
|
@__skipxlo:
|
||||||
`
|
`
|
||||||
|
|
||||||
readonly ASM_FILTER_RANGE_HI_X = `
|
ASM_FILTER_RANGE_HI_X = `
|
||||||
cpx #{{%xofs}}+{{%ecount}}
|
cpx #{{%xofs}}+{{%ecount}}
|
||||||
bcs @__skipxhi
|
bcs @__skipxhi
|
||||||
{{%code}}
|
{{%code}}
|
||||||
|
@ -230,7 +230,7 @@ export class Dialect_CA65 {
|
||||||
`
|
`
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
readonly ASM_MAP_RANGES = `
|
ASM_MAP_RANGES = `
|
||||||
txa
|
txa
|
||||||
pha
|
pha
|
||||||
lda {{%mapping}},x
|
lda {{%mapping}},x
|
||||||
|
@ -242,26 +242,26 @@ export class Dialect_CA65 {
|
||||||
tax
|
tax
|
||||||
`;
|
`;
|
||||||
|
|
||||||
readonly INIT_FROM_ARRAY = `
|
INIT_FROM_ARRAY = `
|
||||||
ldy #{{%nbytes}}
|
ldy #{{%nbytes}}
|
||||||
: lda {{%src}}-1,y
|
: lda {{%src}}-1,y
|
||||||
sta {{%dest}}-1,y
|
sta {{%dest}}-1,y
|
||||||
dey
|
dey
|
||||||
bne :-
|
bne :-
|
||||||
`
|
`
|
||||||
readonly HEADER = `
|
HEADER = `
|
||||||
.include "vcs-ca65.h"
|
.include "vcs-ca65.h"
|
||||||
.define PAL 0
|
.define PAL 0
|
||||||
.code
|
.code
|
||||||
`
|
`
|
||||||
readonly FOOTER = `
|
FOOTER = `
|
||||||
.segment "VECTORS"
|
.segment "VECTORS"
|
||||||
Return: .word $6060
|
Return: .word $6060
|
||||||
VecNMI:
|
VecNMI:
|
||||||
VecReset: .word Main::__Reset
|
VecReset: .word Main::__Reset
|
||||||
VecBRK: .word Main::__BRK
|
VecBRK: .word Main::__BRK
|
||||||
`
|
`
|
||||||
readonly TEMPLATE_INIT_MAIN = `
|
TEMPLATE_INIT_MAIN = `
|
||||||
__NMI:
|
__NMI:
|
||||||
__Reset:
|
__Reset:
|
||||||
__BRK:
|
__BRK:
|
||||||
|
@ -433,6 +433,12 @@ class DataSegment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UninitDataSegment extends DataSegment {
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConstDataSegment extends DataSegment {
|
||||||
|
}
|
||||||
|
|
||||||
function getFieldBits(f: IntType) {
|
function getFieldBits(f: IntType) {
|
||||||
let n = f.hi - f.lo + 1;
|
let n = f.hi - f.lo + 1;
|
||||||
return Math.ceil(Math.log2(n));
|
return Math.ceil(Math.log2(n));
|
||||||
|
@ -820,8 +826,8 @@ export class EntityScope implements SourceLocated {
|
||||||
systems: System[] = [];
|
systems: System[] = [];
|
||||||
entities: Entity[] = [];
|
entities: Entity[] = [];
|
||||||
fieldtypes: { [name: string]: 'init' | 'const' } = {};
|
fieldtypes: { [name: string]: 'init' | 'const' } = {};
|
||||||
bss = new DataSegment();
|
bss = new UninitDataSegment();
|
||||||
rodata = new DataSegment();
|
rodata = new ConstDataSegment();
|
||||||
code = new CodeSegment();
|
code = new CodeSegment();
|
||||||
componentsInScope = new Set();
|
componentsInScope = new Set();
|
||||||
tempOffset = 0;
|
tempOffset = 0;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { readdirSync, readFileSync } from "fs";
|
||||||
import { describe } from "mocha";
|
import { describe } from "mocha";
|
||||||
import { ECSCompiler } from "../common/ecs/compiler";
|
import { ECSCompiler } from "../common/ecs/compiler";
|
||||||
import { Dialect_CA65, EntityManager, SourceFileExport } from "../common/ecs/ecs";
|
import { Dialect_CA65, EntityManager, SourceFileExport } from "../common/ecs/ecs";
|
||||||
|
@ -363,3 +364,20 @@ describe('Tokenizer', function() {
|
||||||
testCompiler();
|
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());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -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…
Reference in New Issue