Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct ExpressionEmitter{
- method buildI8(self:ref ExpressionEmitter, val:i8):gc[Expression];
- method buildI16(self:ref ExpressionEmitter, val:i16):gc[Expression];
- method buildI32(self:ref ExpressionEmitter, val:i32):gc[Expression];
- method buildI64(self:ref ExpressionEmitter, val:i64):gc[Expression];
- method buildString(self:ref ExpressionEmitter, val:ptr[] u8):gc[Expression];
- method buildCall(self:ref ExpressionEmitter, head:gc[Expression], args:slice[gc[Expression]]):gc[Expression];
- ....
- }
- class ToExpression[T]{
- method materialize(emitter:ref ExpressionEmitter, val:ref T):gc[Expression];
- }
- instance ToExpression[i32]{
- method materialize(emitter:ref ExpressionEmitter, val:ref i32):gc[Expression]{
- return emitter.buildI32(*val);
- }
- }
- ...
- struct MyData{
- field x y:i32;
- }
- instance ToExpression[MyData]{
- method materialize(emitter:ref ExpressionEmitter, val:ref MyData):gc[Expression]{
- let constr = emitter.buildConstructor(reflect(MyData));
- constr.addField(reflect(MyData.x), @val->x);
- constr.addField(reflect(MyData.y), @val->y);
- return constr.toExpression();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement