Made system builtins properties instead of an enum.
This commit is contained in:
parent
4365a6b894
commit
31adcc5d6c
3 changed files with 36 additions and 37 deletions
|
@ -37,12 +37,12 @@ namespace arookas {
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunContext context) {
|
||||
var callableInfo = context.MustResolveCallable(this);
|
||||
if (!callableInfo.Parameters.ValidateArgumentCount(Arguments.Count)) {
|
||||
throw new sunArgumentCountException(this, callableInfo);
|
||||
var symbol = context.MustResolveCallable(this);
|
||||
if (!symbol.Parameters.ValidateArgumentCount(Arguments.Count)) {
|
||||
throw new sunArgumentCountException(this, symbol);
|
||||
}
|
||||
Arguments.Compile(context);
|
||||
callableInfo.OpenCallSite(context, Arguments.Count);
|
||||
symbol.OpenCallSite(context, Arguments.Count);
|
||||
if (IsStatement) {
|
||||
context.Text.WritePOP();
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ namespace arookas {
|
|||
|
||||
public sunParameterList(sunSourceLocation location)
|
||||
: base(location) {
|
||||
int count = this.Count(i => i is sunEllipsis);
|
||||
var count = this.Count(i => i is sunEllipsis);
|
||||
if (count > 1 || (count > 0 && !(this[Count - 1] is sunEllipsis))) {
|
||||
throw new sunVariadicParameterListException(this);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunContext context) {
|
||||
context.Text.WriteFUNC((int)sunSystemBuiltins.Yield, 0);
|
||||
context.Yield.OpenCallSite(context, 0);
|
||||
context.Text.WritePOP();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunContext context) {
|
||||
context.Text.WriteFUNC((int)sunSystemBuiltins.Exit, 0);
|
||||
context.Exit.OpenCallSite(context, 0);
|
||||
context.Text.WritePOP();
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunContext context) {
|
||||
context.Text.WriteFUNC((int)sunSystemBuiltins.Lock, 0);
|
||||
context.Lock.OpenCallSite(context, 0);
|
||||
context.Text.WritePOP();
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunContext context) {
|
||||
context.Text.WriteFUNC((int)sunSystemBuiltins.Unlock, 0);
|
||||
context.Unlock.OpenCallSite(context, 0);
|
||||
context.Text.WritePOP();
|
||||
}
|
||||
}
|
||||
|
@ -45,11 +45,6 @@
|
|||
protected sunCast(sunSourceLocation location)
|
||||
: base(location) { }
|
||||
|
||||
protected void Compile(sunContext context, int index) {
|
||||
Argument.Compile(context);
|
||||
context.Text.WriteFUNC(index, 1);
|
||||
}
|
||||
|
||||
sunExpressionFlags sunTerm.GetExpressionFlags(sunContext context) {
|
||||
return sunExpressionFlags.Casts | Argument.Analyze(context);
|
||||
}
|
||||
|
@ -60,7 +55,8 @@
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunContext context) {
|
||||
Compile(context, (int)sunSystemBuiltins.Int);
|
||||
Argument.Compile(context);
|
||||
context.Int.OpenCallSite(context, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +65,8 @@
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunContext context) {
|
||||
Compile(context, (int)sunSystemBuiltins.Float);
|
||||
Argument.Compile(context);
|
||||
context.Float.OpenCallSite(context, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +75,8 @@
|
|||
: base(location) { }
|
||||
|
||||
public override void Compile(sunContext context) {
|
||||
Compile(context, (int)sunSystemBuiltins.Typeof);
|
||||
Argument.Compile(context);
|
||||
context.Typeof.OpenCallSite(context, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,15 @@ namespace arookas {
|
|||
public sunLoopStack Loops { get; private set; }
|
||||
public sunImportResolver ImportResolver { get; private set; }
|
||||
|
||||
// system builtins
|
||||
public sunCallableSymbol Yield { get; private set; }
|
||||
public sunCallableSymbol Exit { get; private set; }
|
||||
public sunCallableSymbol Lock { get; private set; }
|
||||
public sunCallableSymbol Unlock { get; private set; }
|
||||
public sunCallableSymbol Int { get; private set; }
|
||||
public sunCallableSymbol Float { get; private set; }
|
||||
public sunCallableSymbol Typeof { get; private set; }
|
||||
|
||||
public sunContext() {
|
||||
DataTable = new sunDataTable();
|
||||
SymbolTable = new sunSymbolTable();
|
||||
|
@ -56,14 +65,14 @@ namespace arookas {
|
|||
mTextOffset = (uint)mWriter.Position;
|
||||
mWriter.PushAnchor(); // match code offsets and writer offsets
|
||||
|
||||
// add system builtins (must be same order as constants)
|
||||
AddSystemBuiltin("yield");
|
||||
AddSystemBuiltin("exit");
|
||||
AddSystemBuiltin("lock");
|
||||
AddSystemBuiltin("unlock");
|
||||
AddSystemBuiltin("int");
|
||||
AddSystemBuiltin("float");
|
||||
AddSystemBuiltin("typeof");
|
||||
// add system builtins
|
||||
Yield = AddSystemBuiltin("yield");
|
||||
Exit = AddSystemBuiltin("exit");
|
||||
Lock = AddSystemBuiltin("lock");
|
||||
Unlock = AddSystemBuiltin("unlock");
|
||||
Int = AddSystemBuiltin("int");
|
||||
Float = AddSystemBuiltin("float");
|
||||
Typeof = AddSystemBuiltin("typeof");
|
||||
|
||||
}
|
||||
public void Close() {
|
||||
|
@ -219,8 +228,10 @@ namespace arookas {
|
|||
return null;
|
||||
}
|
||||
|
||||
void AddSystemBuiltin(string name) {
|
||||
SymbolTable.Add(new sunBuiltinSymbol(name, SymbolTable.Count));
|
||||
sunCallableSymbol AddSystemBuiltin(string name) {
|
||||
var symbol = new sunBuiltinSymbol(name, SymbolTable.Count);
|
||||
SymbolTable.Add(symbol);
|
||||
return symbol;
|
||||
}
|
||||
void WriteHeader() {
|
||||
mWriter.WriteString("SPCB");
|
||||
|
@ -232,14 +243,4 @@ namespace arookas {
|
|||
mWriter.WriteS32(SymbolTable.VariableCount);
|
||||
}
|
||||
}
|
||||
|
||||
enum sunSystemBuiltins {
|
||||
Yield,
|
||||
Exit,
|
||||
Lock,
|
||||
Unlock,
|
||||
Int,
|
||||
Float,
|
||||
Typeof,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue