func insert(list:@node; new:string):@node
p:=list
prev := @nil
- while ?p and then p@.this < new:
+ while ?p and then p.this < new:
prev = p
- p = p@.next
+ p = p.next
if ?prev:
- prev@.next = @new()
- prev@.next@.next = p
- prev@.next@.this = new
+ prev.next = @new()
+ prev.next.next = p
+ prev.next.this = new
else
list = @new()
- list@.next = p
- list@.this = new
+ list.next = p
+ list.this = new
use list
func printlist(list:@node)
func freelist(list:@node)
if list != @nil:
- freelist(list@.next)
+ freelist(list.next)
@free = list
func main(argv:[ac::]string)
ref2:@string
num:number = @new()
print num@
- if num == @nil or ref == ref2 or ref == 2:
+ if num == @nil or ref == ref2 or ref == 2 or ref.foo:
@free = num
###### output: ref_err2
.tmp.code:7:33: error: expected @number but variable 'ref2' is @string
.tmp.code:4:8: info: this is where 'ref2' was set to @string
.tmp.code:7:48: error: expected @number found number
+ .tmp.code:7:53: error: field reference on number is not supported
+ .tmp.code:7:56: error: have none but need Boolean
.tmp.code:8:17: error: @free can only be assigned a reference, not number
.tmp.code:8:17: error: @free can only be assigned a reference, not number
oceani: type error in program - not running.
return val->ref != NULL;
}
+ static struct type *reference_fieldref(struct type *t, struct parse_context *c,
+ struct fieldref *f, struct value **vp)
+ {
+ struct type *rt = t->reference.referent;
+
+ if (rt->fieldref) {
+ if (vp)
+ *vp = (*vp)->ref;
+ return rt->fieldref(rt, c, f, vp);
+ }
+ type_err(c, "error: field reference on %1 is not supported",
+ f->left, rt, 0, NULL);
+ return Tnone;
+ }
+
+
static struct type reference_prototype = {
.print_type = reference_print_type,
.cmp_eq = reference_cmp,
.test = reference_test,
.free = reference_free,
.compat = reference_compat,
+ .fieldref = reference_fieldref,
.size = sizeof(void*),
.align = sizeof(void*),
};