Skip to content

Commit 1ce4fb2

Browse files
committed
Merge branch 'release/0.31.3'
2 parents 290f3fe + 26524ff commit 1ce4fb2

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

build/supertiny.flx

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ export supertiny
77
import "libc" as _
88
// import "stdio" as _
99

10+
11+
12+
ffi fn rofl() as "lmao"
13+
ffi fn rofl(x: int) -> void as "haha"
14+
1015
@entry fn main()
1116
{
12-
printf("!\n")
17+
rofl()
18+
rofl(20)
1319
}
1420

21+
22+
1523
/*
1624
! more things.
1725
! caa 03/10

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## CHANGELOG (FIXED / IMPLEMENTED THINGS)
22

33
`(??)`
4+
- 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
5+
flax-illegal characters inside)
6+
7+
`(a2721fc)`
48
- declare foreign functions `as` something -- useful for OpenGL especially, (1) to deduplicate the `gl` prefix, and (2) to allow overloading of all
59
the different `glVertex<N><T>` where `N = 2, 3, 4`, `T = i, f, d` or something.
610

source/frontend/parser/function.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ namespace parser
169169
if(st.front() == TT::As)
170170
{
171171
st.pop();
172-
if(st.front() != TT::Identifier)
173-
expectedAfter(st.loc(), "identifier", "'as' in foreign function declaration", st.front().str());
172+
if(st.front() != TT::StringLiteral)
173+
expectedAfter(st.loc(), "string literal", "'as' in foreign function declaration", st.front().str());
174174

175-
ffn->asName = st.eat().str();
175+
ffn->realName = st.eat().str();
176176
}
177177
else
178178
{
179-
ffn->asName = ffn->name;
179+
ffn->realName = ffn->name;
180180
}
181181

182182
return ffn;

source/include/ast.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ namespace ast
190190
using Arg = FuncDefn::Arg;
191191

192192
std::string name;
193-
std::string asName;
193+
std::string realName;
194194

195195
std::vector<Arg> args;
196196
pts::Type* returnType = 0;

source/main.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ struct timer
2323
};
2424

2525

26+
#ifdef _WIN32
27+
#define DLLEXPORT __declspec(dllexport)
28+
#else
29+
#define DLLEXPORT
30+
#endif
31+
32+
extern "C" DLLEXPORT void lmao()
33+
{
34+
printf("LMAO!\n");
35+
}
36+
37+
extern "C" DLLEXPORT void haha(int x)
38+
{
39+
for(int i = 0; i < x; i++)
40+
printf("HA");
41+
42+
printf("!\n");
43+
}
44+
45+
2646
static void compile(std::string in, std::string out)
2747
{
2848
auto ts = std::chrono::high_resolution_clock::now();

source/typecheck/function.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,15 @@ TCResult ast::ForeignFuncDefn::typecheck(sst::TypecheckState* fs, fir::Type* inf
189189

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

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

195194
defn->params = ps;
196195
defn->returnType = retty;
197196
defn->visibility = this->visibility;
198197
defn->isVarArg = this->isVarArg;
199198

200199
// the realname is the actual name of the function.
201-
defn->realName = this->name;
200+
defn->realName = this->realName;
202201

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

235234
this->generatedDecl = defn;
236235

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

240238
return TCResult(defn);
241239
}

0 commit comments

Comments
 (0)