Skip to content

Commit

Permalink
Merge branch 'release/0.31.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiayang committed Nov 6, 2018
2 parents 290f3fe + 26524ff commit 1ce4fb2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
10 changes: 9 additions & 1 deletion build/supertiny.flx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ export supertiny
import "libc" as _
// import "stdio" as _



ffi fn rofl() as "lmao"
ffi fn rofl(x: int) -> void as "haha"

@entry fn main()
{
printf("!\n")
rofl()
rofl(20)
}



/*
! more things.
! caa 03/10
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## CHANGELOG (FIXED / IMPLEMENTED THINGS)

`(??)`
- flip the declaration of `ffi-as` so the external name is after `as` -- and now as a string literal (because your external names might have
flax-illegal characters inside)

`(a2721fc)`
- declare foreign functions `as` something -- useful for OpenGL especially, (1) to deduplicate the `gl` prefix, and (2) to allow overloading of all
the different `glVertex<N><T>` where `N = 2, 3, 4`, `T = i, f, d` or something.

Expand Down
8 changes: 4 additions & 4 deletions source/frontend/parser/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ namespace parser
if(st.front() == TT::As)
{
st.pop();
if(st.front() != TT::Identifier)
expectedAfter(st.loc(), "identifier", "'as' in foreign function declaration", st.front().str());
if(st.front() != TT::StringLiteral)
expectedAfter(st.loc(), "string literal", "'as' in foreign function declaration", st.front().str());

ffn->asName = st.eat().str();
ffn->realName = st.eat().str();
}
else
{
ffn->asName = ffn->name;
ffn->realName = ffn->name;
}

return ffn;
Expand Down
2 changes: 1 addition & 1 deletion source/include/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace ast
using Arg = FuncDefn::Arg;

std::string name;
std::string asName;
std::string realName;

std::vector<Arg> args;
pts::Type* returnType = 0;
Expand Down
20 changes: 20 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ struct timer
};


#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

extern "C" DLLEXPORT void lmao()
{
printf("LMAO!\n");
}

extern "C" DLLEXPORT void haha(int x)
{
for(int i = 0; i < x; i++)
printf("HA");

printf("!\n");
}


static void compile(std::string in, std::string out)
{
auto ts = std::chrono::high_resolution_clock::now();
Expand Down
8 changes: 3 additions & 5 deletions source/typecheck/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,15 @@ TCResult ast::ForeignFuncDefn::typecheck(sst::TypecheckState* fs, fir::Type* inf

auto retty = fs->convertParserTypeToFIR(this->returnType);

// use our 'asname' as the identifier.
defn->id = Identifier(this->asName, IdKind::Name);
defn->id = Identifier(this->name, IdKind::Name);

defn->params = ps;
defn->returnType = retty;
defn->visibility = this->visibility;
defn->isVarArg = this->isVarArg;

// the realname is the actual name of the function.
defn->realName = this->name;
defn->realName = this->realName;

if(this->isVarArg)
defn->type = fir::FunctionType::getCVariadicFunc(util::map(ps, [](FnParam p) -> auto { return p.type; }), retty);
Expand Down Expand Up @@ -234,8 +233,7 @@ TCResult ast::ForeignFuncDefn::typecheck(sst::TypecheckState* fs, fir::Type* inf

this->generatedDecl = defn;

// same, use our 'asname'.
fs->stree->addDefinition(this->asName, defn);
fs->stree->addDefinition(this->name, defn);

return TCResult(defn);
}
Expand Down

0 comments on commit 1ce4fb2

Please sign in to comment.