Skip to content

Conversation

@mascarenhas
Copy link
Member

@mascarenhas mascarenhas commented May 16, 2018

Adds the capability of having builtin functions in the Titan runtime that are callable directly from Titan code, and defines a few builtins available to all Titan modules (such as print).

The idea is to use builtin functions for standard library functions that need to access Titan's Lua state, and for functions that do not need to access the Lua state but where it is incovenient or impossible to define the function by a combination of Titan code plus FFI calls.

These builtin functions have the Titan calling convention, apart from the addition of variadic arguments, encoded as an int parameter that takes the size of the variadic argument list, and a standard C variadic parameter.

The C name of a builtin function is always titan_<name> for the builtins that are not part of any module, such as print and tostring, and titan_<mangled_fqtn> for builtins declared in as part of a module, where mangled_fqtn is the fully-qualified name of the function with all dashes and dots replaced by underscores.

@mascarenhas mascarenhas requested a review from hishamhm May 16, 2018 02:37
@mascarenhas
Copy link
Member Author

By the way, let's not get hung up on the specific interfaces and implementations for the builtin functions included in this PR, the lack of option types (and optional parameters) and proper error handling in Titan right now restricts what we can do. These builtin functions can improve later as the type system improves.

@codecov-io
Copy link

codecov-io commented May 17, 2018

Codecov Report

Merging #232 into master will decrease coverage by 0.41%.
The diff coverage is 81.93%.

Impacted Files Coverage Δ
titan-compiler/driver.lua 81.71% <100%> (+2.19%) ⬆️
titan-compiler/lexer.lua 100% <100%> (ø) ⬆️
titan-compiler/ast.lua 100% <100%> (ø) ⬆️
titan-compiler/syntax_errors.lua 100% <100%> (ø) ⬆️
titan-compiler/types.lua 83.5% <31.25%> (-3.21%) ⬇️
titan-compiler/checker.lua 89.27% <78.57%> (-0.56%) ⬇️
titan-compiler/parser.lua 95.3% <85.71%> (-1.03%) ⬇️
titan-compiler/coder.lua 96.24% <92.3%> (-0.13%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c09bf8...2784c32. Read the comment docs.

@mascarenhas
Copy link
Member Author

Rebased this onto the current master.

@hishamhm hishamhm changed the title Bultin functions Builtin functions May 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants