@@ -331,7 +331,7 @@ checkstat = util.make_visitor({
331331 local texp = var ._type
332332 if texp ._tag == " Type.Module" then
333333 checker .typeerror (errors , var .loc , " trying to assign to a module" )
334- elseif texp ._tag == " Type.Function" or texp ._tag == " Type.BuiltinFunction " then
334+ elseif texp ._tag == " Type.Function" or texp ._tag == " Type.ForeignFunction " then
335335 checker .typeerror (errors , var .loc , " trying to assign to a function" )
336336 else
337337 -- mark this declared variable as assigned to
@@ -768,7 +768,7 @@ checkexp = util.make_visitor({
768768 " trying to access module '%s' as a first-class value" ,
769769 node .var .name )
770770 node ._type = types .Invalid ()
771- elseif texp ._tag == " Type.Function" or texp ._tag == " Type.BuiltinFunction " then
771+ elseif texp ._tag == " Type.Function" or texp ._tag == " Type.ForeignFunction " then
772772 checker .typeerror (errors , node .loc ,
773773 " trying to access a function as a first-class value" )
774774 node ._type = types .Invalid ()
@@ -1032,14 +1032,14 @@ checkexp = util.make_visitor({
10321032 local fname = expname (node .exp )
10331033 local var = node .exp .var
10341034 if not (var and var ._decl and
1035- (var ._decl ._tag == " Ast.TopLevelBuiltin " or
1035+ (var ._decl ._tag == " Ast.TopLevelForeignFunc " or
10361036 var ._decl ._tag == " Ast.TopLevelFunc" or
10371037 var ._decl ._tag == " Type.ModuleMember" or
10381038 var ._decl ._tag == " Type.StaticMethod" )) then
10391039 checker .typeerror (errors , node .loc ,
10401040 " first-class functions are not supported in this version of Titan" )
10411041 end
1042- if ftype ._tag ~= " Type.Function" and ftype ._tag ~= " Type.BuiltinFunction " then
1042+ if ftype ._tag ~= " Type.Function" and ftype ._tag ~= " Type.ForeignFunction " then
10431043 checker .typeerror (errors , node .loc ,
10441044 " '%s' is not a function but %s" ,
10451045 fname , types .tostring (ftype ))
@@ -1257,7 +1257,7 @@ local function toplevel_name(node)
12571257 return node .decl .name
12581258 elseif tag == " Ast.TopLevelFunc" or
12591259 tag == " Ast.TopLevelRecord" or
1260- tag == " Ast.TopLevelBuiltin " then
1260+ tag == " Ast.TopLevelForeignFunc " then
12611261 return node .name
12621262 elseif tag == " Ast.TopLevelMethod" or tag == " Ast.TopLevelStatic" then
12631263 return nil
@@ -1490,7 +1490,7 @@ local toplevel_visitor = util.make_visitor({
14901490 rectype .methods [node .name ] = node ._type
14911491 end ,
14921492
1493- [" Ast.TopLevelBuiltin " ] = function (node , st , errors )
1493+ [" Ast.TopLevelForeignFunc " ] = function (node , st , errors )
14941494 local ptypes = {}
14951495 local vararg = false
14961496 for i , pdecl in ipairs (node .params ) do
@@ -1511,7 +1511,7 @@ local toplevel_visitor = util.make_visitor({
15111511 table.insert (rettypes , typefromnode (rt , st , errors ))
15121512 end
15131513 local fname = st and st .modname .. " ." .. node .name or node .name
1514- node ._type = types .BuiltinFunction (fname ,
1514+ node ._type = types .ForeignFunction (fname ,
15151515 ptypes , rettypes , vararg )
15161516 return node
15171517 end ,
@@ -1579,7 +1579,7 @@ local function makemoduletype(modname, modast)
15791579 local tag = tlnode ._tag
15801580 if tag == " Ast.TopLevelFunc" or
15811581 tag == " Ast.TopLevelRecord" or
1582- tag == " Ast.TopLevelBuiltin " then
1582+ tag == " Ast.TopLevelForeignFunc " then
15831583 members [tlnode .name ] = types .ModuleMember (modname , tlnode .name , tlnode ._type )
15841584 elseif tag == " Ast.TopLevelVar" then
15851585 members [tlnode .decl .name ] = types .ModuleMember (modname , tlnode .decl .name , tlnode ._type )
@@ -1589,16 +1589,16 @@ local function makemoduletype(modname, modast)
15891589 return types .Module (modname , members )
15901590end
15911591
1592- local function add_builtins (st )
1593- local nodes = parser .parse (" builtin .titan" , [[
1594- builtin function print(...: value)
1595- builtin function assert(val: value, msg: string): value
1596- builtin function dofile(fname: string, ...: value): {value}
1597- builtin function dostring(fname: string, ...: value): {value}
1598- builtin function error(msg: string)
1599- builtin function tostring(val: value): string
1600- builtin function tofloat(val: string): float
1601- builtin function tointeger(val: string): integer
1592+ local function add_foreigns (st )
1593+ local nodes = parser .parse (" foreign .titan" , [[
1594+ foreign function print(...: value)
1595+ foreign function assert(val: value, msg: string): value
1596+ foreign function dofile(fname: string, ...: value): {value}
1597+ foreign function dostring(fname: string, ...: value): {value}
1598+ foreign function error(msg: string)
1599+ foreign function tostring(val: value): string
1600+ foreign function tofloat(val: string): float
1601+ foreign function tointeger(val: string): integer
16021602 ]] )
16031603 for _ , node in ipairs (nodes ) do
16041604 st :add_symbol (node .name , toplevel_visitor (node ))
@@ -1621,7 +1621,7 @@ function checker.check(modname, ast, subject, filename, loader)
16211621 return nil , " you must pass a loader to import modules"
16221622 end
16231623 local st = symtab .new (modname )
1624- add_builtins (st )
1624+ add_foreigns (st )
16251625 local errors = {subject = subject , filename = filename }
16261626 checktoplevel (ast , st , errors , loader )
16271627 checkbodies (ast , st , errors )
0 commit comments