mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-17 12:08:54 +00:00
Added more general pointer support
This commit is contained in:
parent
b3dfb503f5
commit
5c907162f3
@ -0,0 +1,4 @@
|
||||
txa
|
||||
clc
|
||||
adc #{coby1}
|
||||
sta {zpby1}
|
@ -0,0 +1,7 @@
|
||||
lda {zpptrby2}
|
||||
clc
|
||||
adc #1
|
||||
sta {zpptrby1}
|
||||
lda {zpptrby2}+1
|
||||
adc #0
|
||||
sta {zpptrby1}+1
|
@ -40,6 +40,15 @@ public class Pass1GenerateSingleStaticAssignmentForm {
|
||||
VariableUnversioned assignedSymbol = (VariableUnversioned) lValue;
|
||||
VariableVersion version = symbols.createVersion(assignedSymbol);
|
||||
assignment.setLValue(version);
|
||||
} else if(lValue instanceof PointerDereferenceVariable) {
|
||||
PointerDereferenceVariable deref = (PointerDereferenceVariable) lValue;
|
||||
Variable pointer = deref.getPointer();
|
||||
if(pointer instanceof VariableUnversioned) {
|
||||
// Assignment to a non-versioned non-intermediary variable
|
||||
VariableUnversioned assignedSymbol = (VariableUnversioned) pointer;
|
||||
VariableVersion version = symbols.createVersion(assignedSymbol);
|
||||
deref.setPointerVariable(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,8 +154,13 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
||||
|
||||
@Override
|
||||
public LValue visitLvaluePtr(KickCParser.LvaluePtrContext ctx) {
|
||||
LValue lval = (LValue) visit(ctx.lvalue());
|
||||
if(lval instanceof Variable) {
|
||||
return new PointerDereferenceVariable((Variable) lval);
|
||||
} else {
|
||||
throw new RuntimeException("Not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LValue visitLvalueArray(KickCParser.LvalueArrayContext ctx) {
|
||||
@ -185,7 +190,8 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
||||
|
||||
@Override
|
||||
public SymbolType visitTypePtr(KickCParser.TypePtrContext ctx) {
|
||||
throw new RuntimeException("Not implemented");
|
||||
SymbolType elementType = (SymbolType) visit(ctx.typeDecl());
|
||||
return new SymbolTypePointer(elementType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,6 +31,9 @@ public class Pass3RegisterAllocation {
|
||||
allocation.allocate(symbols.getVariable("i#3"), RegisterAllocation.getRegisterX());
|
||||
allocation.allocate(symbols.getVariable("n1#1"), RegisterAllocation.getRegisterY());
|
||||
allocation.allocate(symbols.getVariable("n1#2"), RegisterAllocation.getRegisterY());
|
||||
allocation.allocate(symbols.getVariable("ptr#1"), new RegisterAllocation.RegisterZpPointerByte(2));
|
||||
allocation.allocate(symbols.getVariable("ptr#2"), new RegisterAllocation.RegisterZpPointerByte(2));
|
||||
allocation.allocate(symbols.getVariable("ptr#3"), new RegisterAllocation.RegisterZpPointerByte(2));
|
||||
symbols.setAllocation(allocation);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
/** Test my KickC Grammar */
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
final String fileName = "src/dk/camelot64/kickc/test/fibmem.kc";
|
||||
final String fileName = "src/dk/camelot64/kickc/test/memptr.kc";
|
||||
final CharStream input = CharStreams.fromFileName(fileName);
|
||||
System.out.println(input.toString());
|
||||
KickCLexer lexer = new KickCLexer(input);
|
||||
|
8
src/dk/camelot64/kickc/test/memptr.kc
Normal file
8
src/dk/camelot64/kickc/test/memptr.kc
Normal file
@ -0,0 +1,8 @@
|
||||
byte[256] tab = $1100;
|
||||
byte* ptr = tab;
|
||||
byte i=0;
|
||||
do {
|
||||
*ptr = i;
|
||||
ptr = ptr+1;
|
||||
i = i+1;
|
||||
} while (i!=0)
|
Loading…
Reference in New Issue
Block a user