Skip to content
Browse files

BasicTypes parses fully except generics

  • Loading branch information...
1 parent 8c197c1 commit b073cecda7d21e40d55566e07c0456051b73f279 n ddrylliog committed
Showing with 40 additions and 5 deletions.
  1. +11 −1 nagaqueen.leg
  2. +29 −4 samples/realworld/BasicTypes.ooc
View
12 nagaqueen.leg
@@ -203,9 +203,10 @@ VariableDecl =
)*
- COLON { printf(": "); }
+ (- STATIC_KW { printf("static "); })?
- Type
-Type = < (CONST_KW { printf("const "); } -)?
+Type = FuncType | (< (CONST_KW { printf("const "); } -)?
(
( "unsigned" - { printf("unsigned ") }
| "signed" - { printf("signed ") }
@@ -217,6 +218,15 @@ Type = < (CONST_KW { printf("const "); } -)?
| "[" { printf("["); } - Expr? "]" { printf("]"); }
)*
> - { $$=strdup(yytext); }
+ )
+
+FuncType = "Func" { printf("Func") }
+ (
+ - OPEN_PAREN { printf(" (") }
+ (- Argument)?
+ (COMMA { printf(", ") } - Argument)*
+ - CLOS_PAREN { printf(")") }
+ )?
Stmt = { printf("\n"); } (
( # some statements need an EOL after them...
View
33 samples/realworld/BasicTypes.ooc
@@ -2,15 +2,40 @@
* objects
*/
Class: abstract class {
-
+
+ /// Number of octets to allocate for a new instance of this class
+ instanceSize: SizeT
+
+ /// Number of octets to allocate to hold an instance of this class
+ /// it's different because for classes, instanceSize may greatly
+ /// vary, but size will always be equal to the size of a Pointer.
+ /// for basic types (e.g. Int, Char, Pointer), size == instanceSize
+ size: SizeT
+
+ /// Human readable representation of the name of this class
+ name: String
+
+ /// Pointer to instance of super-class
+ super: const Class
+
+ /// Create a new instance of the object of type defined by this class
+ alloc: final func -> Object {
+ object := gc_malloc(instanceSize) as Object
+ if(object) {
+ object class = this
+ object __defaults__()
+ }
+ return object
+ }
+
instanceof: final func (T: Class) -> Bool {
if(this == T) return true
return (super ? super as This instanceof(T) : false)
}
// workaround needed to avoid C circular dependency with _ObjectClass
- //__defaults__: static Func (Class)
- //__destroy__: static Func (Class)
- //__load__: static Func
+ __defaults__: static Func (Class)
+ __destroy__: static Func (Class)
+ __load__: static Func
}

0 comments on commit b073cec

Please sign in to comment.
Something went wrong with that request. Please try again.