C compiler with embedded metalanguage.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

40 líneas
710 B

@import("parsimonyLibrary/dynamicObject.mc")
#include <math.h>
struct __oop { int class; };
typedef struct __oop *oop;
@class struct Point { double x, y; };
@constructor("Point") oop newPoint(double x, double y)
{
struct Point *p = calloc(1, sizeof *p); // auto
self->x = x;
self->y = y;
return self; // need to cast (struct __oop *) self
}
@method("Point") double magnitude()
{
printf("point method : %f\n", sqrt(self->x * self->x * self->y * self->y));
return sqrt(self->x * self->x * self->y * self->y);
}
@method("Point") double getX()
{
printf("point method : %f\n", self->x);
return self->x;
}
int main()
{
oop p = newPoint(3, 4);
@send("p", "magnitude");
return 0;
}