|
@ -19,8 +19,6 @@ struct Symbol *newSymbol(char *name) |
|
|
struct Symbol **symbols = 0; |
|
|
struct Symbol **symbols = 0; |
|
|
int nSymbols = 0; |
|
|
int nSymbols = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Symbol *intern(char *name) |
|
|
struct Symbol *intern(char *name) |
|
|
{ |
|
|
{ |
|
|
int lo = 0; |
|
|
int lo = 0; |
|
@ -147,19 +145,57 @@ typedef struct __oop *oop; |
|
|
exp; |
|
|
exp; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
method(object_name) |
|
|
|
|
|
|
|
|
method() |
|
|
{ |
|
|
{ |
|
|
program.objects.currentClassName = object_name; |
|
|
|
|
|
program.objects.function = "method"; |
|
|
|
|
|
|
|
|
id = string(parseFrom("id").identifier); |
|
|
|
|
|
decl = parseFrom("func"); |
|
|
|
|
|
intern(program.objects.methods, decl.declarators.declarators.identifier); |
|
|
|
|
|
for (i in program.objects.class) { |
|
|
|
|
|
if (string(i) == id) intern(program.objects.class[i], decl.declarators.declarators.identifier); |
|
|
|
|
|
} |
|
|
|
|
|
decl.declarators.declarators.identifier = id + "_" + string(decl.declarators.declarators.identifier); |
|
|
|
|
|
param = rmSemi(`declaration struct __oop *__self;); |
|
|
|
|
|
if (length(decl.declarators.paramTypeL) > 0) { |
|
|
|
|
|
append(decl.declarators.paramTypeL, newComma()); |
|
|
|
|
|
append(decl.declarators.paramTypeL, treeCopy(param)); |
|
|
|
|
|
} else { |
|
|
|
|
|
decl.declarators.paramTypeL = {}; |
|
|
|
|
|
decl.declarators.paramTypeL[0] = treeCopy(param); |
|
|
|
|
|
} |
|
|
|
|
|
tmp = {}; |
|
|
|
|
|
tmp[0] = makeln(`declaration struct @@(newId(id, " ")) *self = (struct @@(newId(id, " ")) *) __self;, 1); |
|
|
|
|
|
decl.compoundS.expression = treeCopy(fusion(tmp, decl.compoundS.expression)); |
|
|
|
|
|
program.objects.function = "none"; |
|
|
nil; |
|
|
nil; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
constructor(object_name) { |
|
|
|
|
|
program.objects.currentClassName = object_name; |
|
|
|
|
|
program.objects.function = "constructor"; |
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
|
|
id = string(parseFrom("id").identifier); |
|
|
|
|
|
decl = parseFrom("func"); |
|
|
|
|
|
rawDeclaration = makeln(`declaration class = findClass(@@(newText("\"" + id + "\"")));, 1); |
|
|
|
|
|
t = {}; |
|
|
|
|
|
append(t, treeCopy(makeln(`declaration struct @@(newId(id, " ")) *self = calloc(1, sizeof *self);, 1))); |
|
|
|
|
|
// take the structure of self->foo |
|
|
|
|
|
lhs = treeCopy(decl.compoundS.expression[0].expression.lhs); |
|
|
|
|
|
lhs.rhs = newId("class", " "); |
|
|
|
|
|
// Change foo to Class |
|
|
|
|
|
rawDeclaration.declarators[0].lhs = lhs; |
|
|
|
|
|
// prepare the right object to return |
|
|
|
|
|
append(decl.compoundS.expression, rawDeclaration); |
|
|
|
|
|
append(decl.compoundS.expression, makeln(`statement return (struct __oop *) self;)); |
|
|
|
|
|
decl.compoundS.expression = fusion(t, decl.compoundS.expression); |
|
|
|
|
|
program.objects.function = "none"; |
|
|
nil; |
|
|
nil; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
send2() |
|
|
|
|
|
{ |
|
|
|
|
|
object = string(parseFrom("id").identifier); |
|
|
|
|
|
method = parseFrom("declaration"); |
|
|
|
|
|
// treeCopy(rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));)); |
|
|
|
|
|
nil; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
send(object, method) |
|
|
send(object, method) |
|
|
{ |
|
|
{ |
|
|
treeCopy(rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));)); |
|
|
treeCopy(rmSemi(`declaration send(@@(newText(object)), @@(newText(method)));)); |
|
@ -167,54 +203,6 @@ typedef struct __oop *oop; |
|
|
|
|
|
|
|
|
everyExternalDeclaration(s) |
|
|
everyExternalDeclaration(s) |
|
|
{ |
|
|
{ |
|
|
/*********** Class function ************/ |
|
|
|
|
|
if (program.objects.function == "class") { |
|
|
|
|
|
program.objects.class[program.last.name.identifier] = {}; |
|
|
|
|
|
for (i=length(program.last.declarationL); i>0; i--) { |
|
|
|
|
|
program.last.declarationL[i] = program.last.declarationL[i-1]; |
|
|
|
|
|
}; |
|
|
|
|
|
program.last.declarationL[0] = treeCopy(`declaration int class; ); |
|
|
|
|
|
program.objects.function = "none"; |
|
|
|
|
|
return s; |
|
|
|
|
|
} |
|
|
|
|
|
/*********** Method function ************/ |
|
|
|
|
|
if (program.objects.function == "method") { |
|
|
|
|
|
intern(program.objects.methods, program.last.declarators.declarators.identifier); |
|
|
|
|
|
for (i in program.objects.class) { |
|
|
|
|
|
if (string(i) == program.objects.currentClassName) intern(program.objects.class[i], program.last.declarators.declarators.identifier); |
|
|
|
|
|
} |
|
|
|
|
|
program.last.declarators.declarators.identifier = program.objects.currentClassName + "_" + string(program.last.declarators.declarators.identifier); |
|
|
|
|
|
param = rmSemi(`declaration struct __oop *__self;); |
|
|
|
|
|
if (length(s.declarators.paramTypeL) > 0) { |
|
|
|
|
|
append(s.declarators.paramTypeL, newComma()); |
|
|
|
|
|
append(s.declarators.paramTypeL, treeCopy(param)); |
|
|
|
|
|
} else { |
|
|
|
|
|
s.declarators.paramTypeL = {}; |
|
|
|
|
|
s.declarators.paramTypeL[0] = treeCopy(param); |
|
|
|
|
|
} |
|
|
|
|
|
tmp = {}; |
|
|
|
|
|
tmp[0] = makeln(`declaration struct @@(newId(program.objects.currentClassName, " ")) *self = (struct @@(newId(program.objects.currentClassName, " ")) *) __self;, 1); |
|
|
|
|
|
s.compoundS.expression = treeCopy(fusion(tmp, s.compoundS.expression)); |
|
|
|
|
|
program.objects.function = "none"; |
|
|
|
|
|
return s; |
|
|
|
|
|
} |
|
|
|
|
|
/*********** Constructor function ************/ |
|
|
|
|
|
if (program.objects.function == "constructor") { |
|
|
|
|
|
rawDeclaration = makeln(`declaration class = findClass(@@(newText("\"" + program.objects.currentClassName + "\"")));, 1); |
|
|
|
|
|
t = {}; |
|
|
|
|
|
append(t, treeCopy(makeln(`declaration struct @@(newId(program.objects.currentClassName, " ")) *self = calloc(1, sizeof *self);, 1))); |
|
|
|
|
|
// take the structure of self->foo |
|
|
|
|
|
lhs = treeCopy(s.compoundS.expression[0].expression.lhs); |
|
|
|
|
|
lhs.rhs = newId("class", " "); |
|
|
|
|
|
// Change foo to Class |
|
|
|
|
|
rawDeclaration.declarators[0].lhs = lhs; |
|
|
|
|
|
// prepare the right object to return |
|
|
|
|
|
append(s.compoundS.expression, rawDeclaration); |
|
|
|
|
|
append(s.compoundS.expression, makeln(`statement return (struct __oop *) self;)); |
|
|
|
|
|
s.compoundS.expression = fusion(t, s.compoundS.expression); |
|
|
|
|
|
program.objects.function = "none"; |
|
|
|
|
|
return s; |
|
|
|
|
|
} |
|
|
|
|
|
/*********** Main function ************/ |
|
|
/*********** Main function ************/ |
|
|
if (s.declarators != null && s.declarators.declarators != null && string(s.declarators.declarators.identifier) == "main") { |
|
|
if (s.declarators != null && s.declarators.declarators != null && string(s.declarators.declarators.identifier) == "main") { |
|
|
t = {}; |
|
|
t = {}; |
|
|