Changed how system builtins are initialized.
This commit is contained in:
parent
ed4822ee29
commit
9f8f21c7bf
3 changed files with 35 additions and 34 deletions
|
@ -4,8 +4,7 @@
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
var builtinInfo = context.ResolveSystemBuiltin("yield");
|
context.Text.WriteFUNC((int)sunSystemBuiltins.Yield, 0);
|
||||||
context.Text.WriteFUNC(builtinInfo.Index, 0);
|
|
||||||
context.Text.WritePOP();
|
context.Text.WritePOP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +14,7 @@
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
var builtinInfo = context.ResolveSystemBuiltin("exit");
|
context.Text.WriteFUNC((int)sunSystemBuiltins.Exit, 0);
|
||||||
context.Text.WriteFUNC(builtinInfo.Index, 0);
|
|
||||||
context.Text.WritePOP();
|
|
||||||
context.Text.WritePOP();
|
context.Text.WritePOP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +24,7 @@
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
var builtinInfo = context.ResolveSystemBuiltin("lock");
|
context.Text.WriteFUNC((int)sunSystemBuiltins.Lock, 0);
|
||||||
context.Text.WriteFUNC(builtinInfo.Index, 0);
|
|
||||||
context.Text.WritePOP();
|
context.Text.WritePOP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,8 +34,7 @@
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
var builtinInfo = context.ResolveSystemBuiltin("unlock");
|
context.Text.WriteFUNC((int)sunSystemBuiltins.Unlock, 0);
|
||||||
context.Text.WriteFUNC(builtinInfo.Index, 0);
|
|
||||||
context.Text.WritePOP();
|
context.Text.WritePOP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,9 +45,9 @@
|
||||||
protected sunCast(sunSourceLocation location)
|
protected sunCast(sunSourceLocation location)
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
protected void Compile(sunContext context, sunBuiltinSymbol symbol) {
|
protected void Compile(sunContext context, int index) {
|
||||||
Argument.Compile(context);
|
Argument.Compile(context);
|
||||||
context.Text.WriteFUNC(symbol.Index, 1);
|
context.Text.WriteFUNC(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sunExpressionFlags sunTerm.GetExpressionFlags(sunContext context) {
|
sunExpressionFlags sunTerm.GetExpressionFlags(sunContext context) {
|
||||||
|
@ -65,7 +60,7 @@
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
Compile(context, context.ResolveSystemBuiltin("int"));
|
Compile(context, (int)sunSystemBuiltins.Int);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +69,7 @@
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
Compile(context, context.ResolveSystemBuiltin("float"));
|
Compile(context, (int)sunSystemBuiltins.Float);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +78,7 @@
|
||||||
: base(location) { }
|
: base(location) { }
|
||||||
|
|
||||||
public override void Compile(sunContext context) {
|
public override void Compile(sunContext context) {
|
||||||
Compile(context, context.ResolveSystemBuiltin("typeof"));
|
Compile(context, (int)sunSystemBuiltins.Typeof);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,14 +56,15 @@ namespace arookas {
|
||||||
mTextOffset = (uint)mWriter.Position;
|
mTextOffset = (uint)mWriter.Position;
|
||||||
mWriter.PushAnchor(); // match code offsets and writer offsets
|
mWriter.PushAnchor(); // match code offsets and writer offsets
|
||||||
|
|
||||||
// add system builtins
|
// add system builtins (must be same order as constants)
|
||||||
DeclareSystemBuiltin("yield", false);
|
AddSystemBuiltin("yield");
|
||||||
DeclareSystemBuiltin("exit", false);
|
AddSystemBuiltin("exit");
|
||||||
DeclareSystemBuiltin("lock", false);
|
AddSystemBuiltin("lock");
|
||||||
DeclareSystemBuiltin("unlock", false);
|
AddSystemBuiltin("unlock");
|
||||||
DeclareSystemBuiltin("int", false, "x");
|
AddSystemBuiltin("int");
|
||||||
DeclareSystemBuiltin("float", false, "x");
|
AddSystemBuiltin("float");
|
||||||
DeclareSystemBuiltin("typeof", false, "x");
|
AddSystemBuiltin("typeof");
|
||||||
|
|
||||||
}
|
}
|
||||||
public void Close() {
|
public void Close() {
|
||||||
if (!mOpen) {
|
if (!mOpen) {
|
||||||
|
@ -136,18 +137,6 @@ namespace arookas {
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public sunBuiltinSymbol DeclareSystemBuiltin(string name, bool variadic, params string[] parameters) {
|
|
||||||
var symbol = SymbolTable.Builtins.FirstOrDefault(i => i.Name == name);
|
|
||||||
if (symbol == null) {
|
|
||||||
symbol = new sunBuiltinSymbol(name, new sunParameterInfo(parameters, variadic), SymbolTable.Count);
|
|
||||||
SymbolTable.Add(symbol);
|
|
||||||
}
|
|
||||||
return symbol;
|
|
||||||
}
|
|
||||||
public sunBuiltinSymbol ResolveSystemBuiltin(string name) {
|
|
||||||
return SymbolTable.Builtins.FirstOrDefault(i => i.Name == name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// storables
|
// storables
|
||||||
public sunVariableSymbol DeclareVariable(sunIdentifier node) {
|
public sunVariableSymbol DeclareVariable(sunIdentifier node) {
|
||||||
#if SSC_PACK_VARS
|
#if SSC_PACK_VARS
|
||||||
|
@ -230,6 +219,9 @@ namespace arookas {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddSystemBuiltin(string name) {
|
||||||
|
SymbolTable.Add(new sunBuiltinSymbol(name, SymbolTable.Count));
|
||||||
|
}
|
||||||
void WriteHeader() {
|
void WriteHeader() {
|
||||||
mWriter.WriteString("SPCB");
|
mWriter.WriteString("SPCB");
|
||||||
mWriter.Write32(mTextOffset);
|
mWriter.Write32(mTextOffset);
|
||||||
|
@ -240,4 +232,14 @@ namespace arookas {
|
||||||
mWriter.WriteS32(SymbolTable.VariableCount);
|
mWriter.WriteS32(SymbolTable.VariableCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum sunSystemBuiltins {
|
||||||
|
Yield,
|
||||||
|
Exit,
|
||||||
|
Lock,
|
||||||
|
Unlock,
|
||||||
|
Int,
|
||||||
|
Float,
|
||||||
|
Typeof,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,10 @@ namespace arookas {
|
||||||
public override sunSymbolType Type { get { return sunSymbolType.Builtin; } }
|
public override sunSymbolType Type { get { return sunSymbolType.Builtin; } }
|
||||||
public override uint Data { get { return (uint)Index; } }
|
public override uint Data { get { return (uint)Index; } }
|
||||||
|
|
||||||
|
public sunBuiltinSymbol(string name, int index)
|
||||||
|
: base(name, null) {
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
public sunBuiltinSymbol(string name, sunParameterInfo parameters, int index)
|
public sunBuiltinSymbol(string name, sunParameterInfo parameters, int index)
|
||||||
: base(name, parameters) {
|
: base(name, parameters) {
|
||||||
Index = index;
|
Index = index;
|
||||||
|
|
Loading…
Reference in a new issue