if _capacity <= old_cap then return
- var new_array = _array
# Reput items in the array
var node = _first_item
while node != null do
end
f.write("#endif\n")
f.close
- var f = new OFStream.open("{tc.compdir}/{name}._sep.c")
+
+ f = new OFStream.open("{tc.compdir}/{name}._sep.c")
f.write("/* This C file is generated by NIT to compile module {name}. */\n")
f.write("#include \"{name}._sep.h\"\n")
for s in v.ctx.instrs do
if pg.is_init_for(c) then
# Declare constructors
var params = new Array[String]
- for i in [0..p.signature.arity[ do
- params.add("val_t p{i}")
+ for j in [0..p.signature.arity[ do
+ params.add("val_t p{j}")
end
v.add_decl("val_t NEW_{c}_{p.global.intro.cname}({params.join(", ")});")
end
var pi = primitive_info
if pi == null then
- var iself = new IRegister(get_type)
- var iselfa = [iself]
- var iroutine = new IRoutine(new Array[IRegister], iself)
- var icb = new ICodeBuilder(module, iroutine, null)
- var obj = new INative("OBJ2VAL(obj)", null)
- obj.result = iself
- icb.stmt(obj)
-
- for g in global_properties do
- var p = self[g]
- var t = p.signature.return_type
- if p isa MMAttribute and t != null then
- var ir = p.iroutine
- if ir == null then continue
- # FIXME: Not compatible with sep compilation
- var e = ir.inline_in_seq(icb.seq, iselfa).as(not null)
- icb.stmt(new IAttrWrite(p, iself, e))
+ do
+ var iself = new IRegister(get_type)
+ var iselfa = [iself]
+ var iroutine = new IRoutine(new Array[IRegister], iself)
+ var icb = new ICodeBuilder(module, iroutine, null)
+ var obj = new INative("OBJ2VAL(obj)", null)
+ obj.result = iself
+ icb.stmt(obj)
+
+ for g in global_properties do
+ var p = self[g]
+ var t = p.signature.return_type
+ if p isa MMAttribute and t != null then
+ var ir = p.iroutine
+ if ir == null then continue
+ # FIXME: Not compatible with sep compilation
+ var e = ir.inline_in_seq(icb.seq, iselfa).as(not null)
+ icb.stmt(new IAttrWrite(p, iself, e))
+ end
end
- end
- var cname = "NEW_{name}"
- var args = iroutine.compile_signature_to_c(v, cname, "new {name}", null, null)
- var ctx_old = v.ctx
- v.ctx = new CContext
- v.add_decl("obj_t obj;")
- v.add_instr("obj = alloc(sizeof(val_t) * {itab.length});")
- v.add_instr("obj->vft = (classtable_elt_t*)VFT_{name};")
- var r = iroutine.compile_to_c(v, cname, args).as(not null)
- v.add_instr("return {r};")
- ctx_old.append(v.ctx)
- v.ctx = ctx_old
- v.unindent
- v.add_instr("}")
+ var cname = "NEW_{name}"
+ var args = iroutine.compile_signature_to_c(v, cname, "new {name}", null, null)
+ var ctx_old = v.ctx
+ v.ctx = new CContext
+ v.add_decl("obj_t obj;")
+ v.add_instr("obj = alloc(sizeof(val_t) * {itab.length});")
+ v.add_instr("obj->vft = (classtable_elt_t*)VFT_{name};")
+ var r = iroutine.compile_to_c(v, cname, args).as(not null)
+ v.add_instr("return {r};")
+ ctx_old.append(v.ctx)
+ v.ctx = ctx_old
+ v.unindent
+ v.add_instr("}")
+ end
- # Compile CHECKNAME
- var iself = new IRegister(get_type)
- var iselfa = [iself]
- var iroutine = new IRoutine(iselfa, null)
- var icb = new ICodeBuilder(module, iroutine, null)
- for g in global_properties do
- var p = self[g]
- var t = p.signature.return_type
- if p isa MMAttribute and t != null and not t.is_nullable then
- icb.add_attr_check(p, iself)
+ do
+ # Compile CHECKNAME
+ var iself = new IRegister(get_type)
+ var iselfa = [iself]
+ var iroutine = new IRoutine(iselfa, null)
+ var icb = new ICodeBuilder(module, iroutine, null)
+ for g in global_properties do
+ var p = self[g]
+ var t = p.signature.return_type
+ if p isa MMAttribute and t != null and not t.is_nullable then
+ icb.add_attr_check(p, iself)
+ end
end
+ var cname = "CHECKNEW_{name}"
+ var args = iroutine.compile_signature_to_c(v, cname, "check new {name}", null, null)
+ var ctx_old = v.ctx
+ v.ctx = new CContext
+ iroutine.compile_to_c(v, cname, args)
+ ctx_old.append(v.ctx)
+ v.ctx = ctx_old
+ v.unindent
+ v.add_instr("}")
end
- var cname = "CHECKNEW_{name}"
- var args = iroutine.compile_signature_to_c(v, cname, "check new {name}", null, null)
- var ctx_old = v.ctx
- v.ctx = new CContext
- iroutine.compile_to_c(v, cname, args)
- ctx_old.append(v.ctx)
- v.ctx = ctx_old
- v.unindent
- v.add_instr("}")
var init_table_size = cshe.greaters.length + 1
var init_table_decl = "int init_table[{init_table_size}] = \{0{", 0" * (init_table_size-1)}};"
else
v.add_decl("struct WBT_ **CREG = NULL;")
end
- var i = 0
+ var k = 0
for r in params do
- if r.slot_index != null then v.add_assignment(v.register(r), args[i])
- i += 1
+ if r.slot_index != null then v.add_assignment(v.register(r), args[k])
+ k += 1
end
- var iclosdecls = closure_decls
if iclosdecls != null then
for i in [0..iclosdecls.length[ do
var iclosdecl = iclosdecls[i]
# If the module is already loaded, just return it without further processing.
fun get_module(module_name: Symbol, from: nullable MMModule): MMModule
do
- var m: MMModule
if from != null then
var dir: nullable MMDirectory = from.directory
while dir != null do
if clibdir == null then
var dir = once ("NIT_DIR".to_symbol).environ
if dir.is_empty then
- var dir = "{sys.program_name.dirname}/../lib"
+ dir = "{sys.program_name.dirname}/../lib"
if dir.file_exists then clibdir = dir
else
dir = "{dir}/lib"
if bindir == null then
var dir = once ("NIT_DIR".to_symbol).environ
if dir.is_empty then
- var dir = "{sys.program_name.dirname}/../bin"
+ dir = "{sys.program_name.dirname}/../bin"
if dir.file_exists then bindir = dir
else
dir = "{dir}/bin"
do
var m = module
if not need_doc(dctx) then m = global.intro.module
- var m = dctx.known_owner_of(m)
+ m = dctx.known_owner_of(m)
if m == dctx.module then
return "<a href=\"#{html_anchor}\">{self}</a>"
else
do
var m = module
if not need_doc(dctx) then m = global.module
- var m = dctx.known_owner_of(m)
+ m = dctx.known_owner_of(m)
if m == dctx.module then
return "<a href=\"#{html_anchor}\">{self}</a>"
else
# skip pass 1 because constructors are not inherited
var cmap = new HashMap[MMLocalClass, Array[MMLocalProperty]]
var mmap = new HashMap[MMModule, Array[MMLocalProperty]]
- var props = new Array[MMLocalClass]
for c in che.greaters do
if c isa MMSrcLocalClass then
var km = dctx.known_owner_of(c.module)
end
var mmap = new HashMap[MMModule, Array[MMLocalProperty]]
- var props = new Array[MMLocalClass]
for c in crhe.order do
if module.mhe <= c.module or dctx.owned_modules.has(c.module) or not c isa MMSrcLocalClass then continue
var km = dctx.known_owner_of(c.module)
end
var l = n.super_init_calls.length
while i < l do
- var p = n.super_init_calls[i]
- if p == stop_prop then break
+ var sp = n.super_init_calls[i]
+ if sp == stop_prop then break
var cargs = new Array[IRegister]
- if p.signature.arity == 0 then
+ if sp.signature.arity == 0 then
cargs.add(iroutine.params.first)
else
for va in iroutine.params do
cargs.add(va)
end
end
- stmt(new ICall(p, cargs))
+ stmt(new ICall(sp, cargs))
i += 1
end
end
return null
end
else
- var p = prop
+ p = prop
var rtype = p.signature.return_type
if rtype == null then
v.stmt(new ISuper(p, args))
end
# Check class conformity
- var mmbv1b = new ClassVerifierVisitor(tc, self)
+ var mmbv1c = new ClassVerifierVisitor(tc, self)
for c in classes do
- c.accept_class_visitor(mmbv1b)
+ c.accept_class_visitor(mmbv1c)
end
tc.check_errors
if s.arity != isig.arity then
v.error(self, "Redef error: {prop.local_class}::{prop} redefines {ip.local_class}::{ip} with {isig.arity} parameter(s).")
else
- for i in [0..s.arity[ do
- if s[i] != isig[i] then
- v.error(self, "Redef error: Expected {isig[i]} (as in {ip.local_class}::{ip}), got {s[i]} in {prop.local_class}::{prop}.")
+ for j in [0..s.arity[ do
+ if s[j] != isig[j] then
+ v.error(self, "Redef error: Expected {isig[j]} (as in {ip.local_class}::{ip}), got {s[j]} in {prop.local_class}::{prop}.")
end
end
end
(i*10).output
end
-#alt1# var a = [10, true]
+#alt1# var b = [10, true]
var v: V = new V
var w: W = new W
-var y: Object
+var y: Object#!alt1#
#alt1#var y: U
y = a.foo !bar do 0.output
y = a.foo !bar do break t
fun file_open(i: Int)
!work(f: File)
- break !error(i: Int) do abort
+ break !error(j: Int) do abort
do
var f = new File(i)
if not f.is_open then error(404)
import kernel
-var i = 1
+var i = 1#!alt1#
#alt1#var i: Object = 1
i += 2
i.output
redef fun output do _i.output
end
-var a: A
-var na: nullable A
-var o: Object
-var no: nullable Object
+
+
+
+
var a: A = new A(1)
var na: nullable A = new A(2)
a4.output
var a5 = foo
a5.output
-#alt7#var a4: Int = bar
-#alt8#var a5 = bar
+#alt7#var a6: Int = bar
+#alt8#var a7 = bar
while true do fail
for i in fail do trash(0) # no rtype (hum...)
-for i in [0..1] do fail
+for j in [0..1] do fail
assert fail
trash(once fail) # no rtype
trash(fail or true)
#alt7# var v = [1..10]
#alt8# for i in new L do
#alt8# end
- var v: Object
+ var y: Object
end
-alt/base_closure6_alt1.nit:53,5--25: Type error: expected U, got T
-alt/base_closure6_alt1.nit:55,25: Type error: no most general type. Got V and U.
-alt/base_closure6_alt1.nit:57,5--61,8: Type error: expected U, got T
-alt/base_closure6_alt1.nit:65,8: Type error: no most general type. Got V and U at 64,8.
+alt/base_closure6_alt1.nit:52,5--25: Type error: expected U, got T
+alt/base_closure6_alt1.nit:54,25: Type error: no most general type. Got V and U.
+alt/base_closure6_alt1.nit:56,5--60,8: Type error: expected U, got T
+alt/base_closure6_alt1.nit:64,8: Type error: no most general type. Got V and U at 63,8.
-alt/base_combined_assignment_alt1.nit:21,1--6: Error: Method '+' doesn't exists in Object.
+alt/base_combined_assignment_alt1.nit:20,1--6: Error: Method '+' doesn't exists in Object.
+++ /dev/null
-5
-0
-a
-6
-a
-a
-5
-0
-a
print(i)
end
-var i = 0
-while i < 10 do
- if i == 3 then
- i = i + 2
- continue
- else if i == 7 then
- break
+do
+ var i = 0
+ while i < 10 do
+ if i == 3 then
+ i = i + 2
+ continue
+ else if i == 7 then
+ break
+ end
+ print(i)
+ i = i + 1
end
- print(i)
- i = i + 1
end
for i in [0..10[ do
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2004-2008 Jean Privat <jean@pryen.org>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-var i = 0
-var j: Object = i
-var k: Object
-
-i = 5
-k = 'a'
-print(i)
-print(j)
-print(k)
-
-do
- var i = i + 1
- var j = k
- var k = j
-
- print(i)
- print(j)
- print(k)
-end
-
-print(i)
-print(j)
-print(k)
var l = new List[Int]
l.add_all([1, 2, 3, 4, 5, 6])
print l.join(", ")
-var it = l.iterator
-while it.is_ok do
- it.item += 10
- it.next
+do
+ var it = l.iterator
+ while it.is_ok do
+ it.item += 10
+ it.next
+ end
end
print l.join(", ")
-var it = l.iterator
-while it.is_ok do
- it.insert_before(it.item-10)
- it.insert_before(it.item+10)
- it.delete
- it.next
+do
+ var it = l.iterator
+ while it.is_ok do
+ it.insert_before(it.item-10)
+ it.insert_before(it.item+10)
+ it.delete
+ it.next
+ end
end
print l.join(", ")