Created
          July 28, 2010 19:41 
        
      - 
      
- 
        Save od0x0/495975 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Vec3: inline cover<T>{ | |
| x, y, z: T | |
| init: func@(=x, =y, =z) | |
| plus: func(v: This) -> This{ | |
| new(x + v x, y + v y, z+ v z) | |
| } | |
| print: func{ | |
| printf("Vec3("(%s, %s, %s)\n", x as String, y as String, z as String) | |
| } | |
| } | |
| v:=Vec3<Float> new(0,0,0) | |
| v plus(Vec3<Float> new(1,0,1)) print() | |
| //Vec3 is not actually a true type, it is literally being inlined (as a generated mangled named (like anonymous functions are) structure) | |
| //This would be the equivalent C (more or less) | |
| struct Vec3inlinedfloat{ | |
| float x, y, z; | |
| } | |
| static inline Vec3inlinedfloat Vec3inlinedfloat_plus(Vec3inlinedfloat this,Vec3inlinedfloat v){ | |
| Vec3inlinedfloat temp; | |
| temp.x=v.x+this.x; | |
| .... | |
| return temp; | |
| } | |
| static inline void Vec3inlinedfloat_print(Vec3inlinedfloat this){ | |
| printf("Vec3("(%s, %s, %s)\n", Float_OP_as_String(x), Float_OP_as_String(y), Float_OP_as_String(z)); | |
| } | |
| Vec3inlinedfloat v=((Vec3inlinedfloat){.x=0,.y=0,.z=0}); | |
| Vec3inlinedfloat_print(Vec3inlinedfloat_plus(v,((Vec3inlinedfloat){.x=0,.y=0,.z=0}))); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment