[gogc] push by bytbox - ran gofmt on all go files on 2010-08-20 22:23 GMT

2 views
Skip to first unread message

go...@googlecode.com

unread,
Aug 20, 2010, 6:23:22 PM8/20/10
to go...@googlegroups.com
Revision: 02c6cd88d5
Author: Scott Lawrence <byt...@gmail.com>
Date: Wed Aug 18 10:20:16 2010
Log: ran gofmt on all go files
http://code.google.com/p/gogc/source/detail?r=02c6cd88d5

Modified:
/src/asm_out.go
/src/codegen.go
/src/fib.go
/src/gen-arith.go
/src/gen-assign.go
/src/gen-cond.go
/src/gen-const.go
/src/gen-expr.go
/src/gen-fcn.go
/src/gen-for.go
/src/gen-if.go
/src/globals.go
/src/gogo.go
/src/inspector.go
/src/libgogo/convert.go
/src/libgogo/io.go
/src/libgogo/item.go
/src/libgogo/libgogo.go
/src/libgogo/list.go
/src/libgogo/memmgr.go
/src/libgogo/stack.go
/src/libgogo/string.go
/src/libgogo/strlist.go
/src/libgogo/symbol.go
/src/libgogo/test/libgogotest.go
/src/linker.go
/src/parse-utils.go
/src/parser.go
/src/scanner.go
/src/symtable.go
/src/token.go
/src/utils.go

=======================================
--- /src/asm_out.go Tue Aug 17 09:58:38 2010
+++ /src/asm_out.go Wed Aug 18 10:20:16 2010
@@ -9,59 +9,59 @@
//
// Variables holding the compiled code and data segment (as assembly code)
//
-var Header string; //Header
-var DataSegmentList libgogo.StringList;
-var DataSegment string; //Data section for global variables
-var InitCodeSegmentList libgogo.StringList;
-var InitCodeSegment string; //Global variable initialization code
-var CodeSegmentList libgogo.StringList;
-var CodeSegment string; //Actual code
+var Header string //Header
+var DataSegmentList libgogo.StringList
+var DataSegment string //Data section for global variables
+var InitCodeSegmentList libgogo.StringList
+var InitCodeSegment string //Global variable initialization code
+var CodeSegmentList libgogo.StringList
+var CodeSegment string //Actual code

//
// String lists containing the symbol tables
//
-var FunctionSymbolTable libgogo.StringList;
-var TypeSymbolTable libgogo.StringList;
+var FunctionSymbolTable libgogo.StringList
+var TypeSymbolTable libgogo.StringList

//
// Pointer used to decide to which string to append output
// There are functions like SwitchOutputToCodeSegment() to change this
pointer in a clean way
// By default, it points to the code segment string
//
-var OutputStringPtr *string = &CodeSegment;
+var OutputStringPtr *string = &CodeSegment

//
// Size of the data segment
//
-var DataSegmentSize uint64 = 0;
+var DataSegmentSize uint64 = 0

//
// Reseting the code before a new compile round starts
//
func ResetCode() {
- Header = `
+ Header = `
//\n
// --------------------\n
// GoGC compiler output\n
// --------------------\n
//\n
-`;
- libgogo.StringAppend(&Header, fileInfo[curFileIndex].filename);
- libgogo.StringAppend(&Header,`\n
+`
+ libgogo.StringAppend(&Header, fileInfo[curFileIndex].filename)
+ libgogo.StringAppend(&Header, `\n
// Syntax: Plan-9 assembler\n
//\n
// This code is automatically generated. DO NOT EDIT IT!\n
//\n
-`);
- InspectorGadget();
- InitCodeSegment = "TEXT main·init(SB),0,$0-0\n";
-
- libgogo.InitializeStringList(&DataSegmentList);
- libgogo.InitializeStringList(&InitCodeSegmentList);
- libgogo.InitializeStringList(&CodeSegmentList);
-
- libgogo.InitializeStringList(&FunctionSymbolTable);
- libgogo.InitializeStringList(&TypeSymbolTable);
+`)
+ InspectorGadget()
+ InitCodeSegment = "TEXT main·init(SB),0,$0-0\n"
+
+ libgogo.InitializeStringList(&DataSegmentList)
+ libgogo.InitializeStringList(&InitCodeSegmentList)
+ libgogo.InitializeStringList(&CodeSegmentList)
+
+ libgogo.InitializeStringList(&FunctionSymbolTable)
+ libgogo.InitializeStringList(&TypeSymbolTable)
}

//
@@ -69,450 +69,450 @@
// same name as the input file + '.sog' extension
//
func PrintFile(Functions *libgogo.TypeDesc, Types *libgogo.TypeDesc) {
- var fd uint64;
- var outfile string = "_gogo_.sog";
- var DataSegmentSizeStr string;
- // The following line creates a new file for the assembler code
- // flags: O_WRONLY | O_CREAT | O_TRUNC => 577
- // mode: S_IWUSR | S_IRUSR | S_IRGRP => 416
- fd = libgogo.FileOpen2(outfile,577,416);
-
- libgogo.WriteString(fd, Header);
- libgogo.WriteString(fd, "\n"); //Separator
- if NeedsLink != 0 {
- libgogo.WriteString(fd, "__UNLINKED_CODE\n");
- }
- libgogo.WriteString(fd, "//Symbol table:\n"); //Separator
- libgogo.SymbolTableTypesToStringList(Types, &TypeSymbolTable);
- PrintStringList(fd, &TypeSymbolTable, 1); //Type symbol table
- libgogo.SymbolTableFunctionsToStringList(Functions,
&FunctionSymbolTable);
- PrintStringList(fd, &FunctionSymbolTable, 1); //Function symbol table
- libgogo.WriteString(fd, "//End Symbol table\n");
- libgogo.WriteString(fd, "\n"); //Separator
- PrintStringList(fd, &DataSegmentList, 0);
- libgogo.WriteString(fd, DataSegment); //Data segment
- libgogo.WriteString(fd, "GLOBL data(SB),$"); //(Begin of) end of data
segment
- DataSegmentSizeStr = libgogo.IntToString(DataSegmentSize);
- libgogo.WriteString(fd, DataSegmentSizeStr); //Size of data segment
- libgogo.WriteString(fd, "\n"); //End of data segment
- libgogo.WriteString(fd, "\n"); //Separator
- PrintStringList(fd, &InitCodeSegmentList, 0);
- libgogo.WriteString(fd, InitCodeSegment); //main.init
- libgogo.WriteString(fd, " RET\n"); //End of function (main.init)
- libgogo.WriteString(fd, "\n"); //Separator
- PrintStringList(fd, &CodeSegmentList, 0);
- libgogo.WriteString(fd, CodeSegment); //Code segment
- libgogo.FileClose(fd);
+ var fd uint64
+ var outfile string = "_gogo_.sog"
+ var DataSegmentSizeStr string
+ // The following line creates a new file for the assembler code
+ // flags: O_WRONLY | O_CREAT | O_TRUNC => 577
+ // mode: S_IWUSR | S_IRUSR | S_IRGRP => 416
+ fd = libgogo.FileOpen2(outfile, 577, 416)
+
+ libgogo.WriteString(fd, Header)
+ libgogo.WriteString(fd, "\n") //Separator
+ if NeedsLink != 0 {
+ libgogo.WriteString(fd, "__UNLINKED_CODE\n")
+ }
+ libgogo.WriteString(fd, "//Symbol table:\n") //Separator
+ libgogo.SymbolTableTypesToStringList(Types, &TypeSymbolTable)
+ PrintStringList(fd, &TypeSymbolTable, 1) //Type symbol table
+ libgogo.SymbolTableFunctionsToStringList(Functions, &FunctionSymbolTable)
+ PrintStringList(fd, &FunctionSymbolTable, 1) //Function symbol table
+ libgogo.WriteString(fd, "//End Symbol table\n")
+ libgogo.WriteString(fd, "\n") //Separator
+ PrintStringList(fd, &DataSegmentList, 0)
+ libgogo.WriteString(fd, DataSegment) //Data segment
+ libgogo.WriteString(fd, "GLOBL data(SB),$") //(Begin of) end of data
segment
+ DataSegmentSizeStr = libgogo.IntToString(DataSegmentSize)
+ libgogo.WriteString(fd, DataSegmentSizeStr) //Size of data segment
+ libgogo.WriteString(fd, "\n") //End of data segment
+ libgogo.WriteString(fd, "\n") //Separator
+ PrintStringList(fd, &InitCodeSegmentList, 0)
+ libgogo.WriteString(fd, InitCodeSegment) //main.init
+ libgogo.WriteString(fd, " RET\n") //End of function (main.init)
+ libgogo.WriteString(fd, "\n") //Separator
+ PrintStringList(fd, &CodeSegmentList, 0)
+ libgogo.WriteString(fd, CodeSegment) //Code segment
+ libgogo.FileClose(fd)
}

func PrintStringList(fd uint64, list *libgogo.StringList, comment uint64) {
- var i uint64;
- var n uint64;
- var temp string;
- n = libgogo.GetStringListItemCount(list);
- for i = 0; i < n; i = i + 1 {
- temp = libgogo.GetStringItemAt(list, i);
- if comment != 0 {
- libgogo.WriteString(fd, "//");
- }
- libgogo.WriteString(fd, temp);
- if comment != 0 {
- libgogo.WriteString(fd, "\n");
- }
- }
+ var i uint64
+ var n uint64
+ var temp string
+ n = libgogo.GetStringListItemCount(list)
+ for i = 0; i < n; i = i + 1 {
+ temp = libgogo.GetStringItemAt(list, i)
+ if comment != 0 {
+ libgogo.WriteString(fd, "//")
+ }
+ libgogo.WriteString(fd, temp)
+ if comment != 0 {
+ libgogo.WriteString(fd, "\n")
+ }
+ }
}

func SwitchOutputToInitCodeSegment() {
- OutputStringPtr = &InitCodeSegment;
+ OutputStringPtr = &InitCodeSegment
}

func SwitchOutputToCodeSegment() {
- OutputStringPtr = &CodeSegment;
+ OutputStringPtr = &CodeSegment
}

func SwitchOutputToDataSegment() {
- OutputStringPtr = &DataSegment;
+ OutputStringPtr = &DataSegment
}

func SplitStringIfNecessary(appendLength uint64) {
- var tempPtr *string;
- var oldLength uint64;
- oldLength = libgogo.StringLength2(OutputStringPtr);
- if oldLength + appendLength >= 65534 { //If code output exceeds max.
string size allowed by Go runtime...
- tempPtr = &DataSegment;
- if OutputStringPtr == tempPtr {
- libgogo.AddStringItem(&DataSegmentList, DataSegment);
//...save the current code to the code list...
- }
- tempPtr = &InitCodeSegment;
- if OutputStringPtr == tempPtr {
- libgogo.AddStringItem(&InitCodeSegmentList, InitCodeSegment);
//...save the current code to the code list...
- }
- tempPtr = &CodeSegment;
- if OutputStringPtr == tempPtr {
- libgogo.AddStringItem(&CodeSegmentList, CodeSegment);
//...save the current code to the code list...
- }
- libgogo.ResetString(OutputStringPtr); //... and start over with a
new output string
- }
+ var tempPtr *string
+ var oldLength uint64
+ oldLength = libgogo.StringLength2(OutputStringPtr)
+ if oldLength+appendLength >= 65534 { //If code output exceeds max. string
size allowed by Go runtime...
+ tempPtr = &DataSegment
+ if OutputStringPtr == tempPtr {
+ libgogo.AddStringItem(&DataSegmentList, DataSegment) //...save the
current code to the code list...
+ }
+ tempPtr = &InitCodeSegment
+ if OutputStringPtr == tempPtr {
+ libgogo.AddStringItem(&InitCodeSegmentList, InitCodeSegment) //...save
the current code to the code list...
+ }
+ tempPtr = &CodeSegment
+ if OutputStringPtr == tempPtr {
+ libgogo.AddStringItem(&CodeSegmentList, CodeSegment) //...save the
current code to the code list...
+ }
+ libgogo.ResetString(OutputStringPtr) //... and start over with a new
output string
+ }
}

func PrintCodeOutput(output string) {
- var appendLength uint64;
- appendLength = libgogo.StringLength(output);
- SplitStringIfNecessary(appendLength);
- libgogo.StringAppend(OutputStringPtr, output);
+ var appendLength uint64
+ appendLength = libgogo.StringLength(output)
+ SplitStringIfNecessary(appendLength)
+ libgogo.StringAppend(OutputStringPtr, output)
}

func PrintCodeOutputChar(output byte) {
- SplitStringIfNecessary(1);
- libgogo.CharAppend(OutputStringPtr, output);
+ SplitStringIfNecessary(1)
+ libgogo.CharAppend(OutputStringPtr, output)
}

func PrintCodeOutputValue(value uint64) {
- var temp string;
- temp = libgogo.IntToString(value);
- PrintCodeOutput(temp);
+ var temp string
+ temp = libgogo.IntToString(value)
+ PrintCodeOutput(temp)
}

func GenerateCommentInternal(msg string, forcePrint uint64) {
- var str string = "";
- var tmpPtr *string;
- var temp string;
- var i uint64;
- var n uint64;
- if (DEBUG_LEVEL >= 10) || (forcePrint != 0) {
- tmpPtr = &DataSegment;
- if (OutputStringPtr != tmpPtr) {
- str = " //--- ";
- } else { //No indentation in data segment
- str = "//--- ";
- }
- n = libgogo.StringLength(msg);
- for i = 0; i < n; i = i + 1 {
- if msg[i] == 10 { //Unescape line breaks in comments to avoid
invalid assembly code
- libgogo.StringAppend(&str, "\\n"); //Literal \n, not
actual \n
- } else {
- libgogo.CharAppend(&str, msg[i]);
- }
- }
- libgogo.StringAppend(&str, " at ");
- temp = BuildHead();
- libgogo.StringAppend(&str, temp);
- libgogo.StringAppend(&str, "\n");
- PrintCodeOutput(str);
- }
+ var str string = ""
+ var tmpPtr *string
+ var temp string
+ var i uint64
+ var n uint64
+ if (DEBUG_LEVEL >= 10) || (forcePrint != 0) {
+ tmpPtr = &DataSegment
+ if OutputStringPtr != tmpPtr {
+ str = " //--- "
+ } else { //No indentation in data segment
+ str = "//--- "
+ }
+ n = libgogo.StringLength(msg)
+ for i = 0; i < n; i = i + 1 {
+ if msg[i] == 10 { //Unescape line breaks in comments to avoid invalid
assembly code
+ libgogo.StringAppend(&str, "\\n") //Literal \n, not actual \n
+ } else {
+ libgogo.CharAppend(&str, msg[i])
+ }
+ }
+ libgogo.StringAppend(&str, " at ")
+ temp = BuildHead()
+ libgogo.StringAppend(&str, temp)
+ libgogo.StringAppend(&str, "\n")
+ PrintCodeOutput(str)
+ }
}

func GenerateComment(msg string) {
- GenerateCommentInternal(msg, 0);
+ GenerateCommentInternal(msg, 0)
}

func GenerateLinkerComment(msg string) {
- GenerateCommentInternal(msg, 1); //Force comment printing regardless
of debug level
+ GenerateCommentInternal(msg, 1) //Force comment printing regardless of
debug level
}

func PrintRegister(name string, number uint64, indirect uint64, offset
uint64, negativeoffset uint64, optionaloffsetname string) {
- var R uint64;
- if indirect != 0 {
- PrintCodeOutput(optionaloffsetname);
- if offset != 0 {
- if negativeoffset != 0 {
- PrintCodeOutput("-");
- } else {
- R = libgogo.StringLength(optionaloffsetname);
- if R != 0 { //Print positive offset if there is an offset
name
- PrintCodeOutput("+");
- }
- }
- PrintCodeOutputValue(offset);
- }
- PrintCodeOutput("(");
- }
- PrintCodeOutput(name); //Print register name
- R = libgogo.StringCompare(name, "R");
- if R == 0 { //p.e. R8 => consider number; else: p.e. AX => ignore
number
- PrintCodeOutputValue(number);
- }
- if indirect != 0 {
- PrintCodeOutput(")");
- }
+ var R uint64
+ if indirect != 0 {
+ PrintCodeOutput(optionaloffsetname)
+ if offset != 0 {
+ if negativeoffset != 0 {
+ PrintCodeOutput("-")
+ } else {
+ R = libgogo.StringLength(optionaloffsetname)
+ if R != 0 { //Print positive offset if there is an offset name
+ PrintCodeOutput("+")
+ }
+ }
+ PrintCodeOutputValue(offset)
+ }
+ PrintCodeOutput("(")
+ }
+ PrintCodeOutput(name) //Print register name
+ R = libgogo.StringCompare(name, "R")
+ if R == 0 { //p.e. R8 => consider number; else: p.e. AX => ignore number
+ PrintCodeOutputValue(number)
+ }
+ if indirect != 0 {
+ PrintCodeOutput(")")
+ }
}

func PrintImmediate(value uint64) {
- PrintCodeOutput("$");
- PrintCodeOutputValue(value);
+ PrintCodeOutput("$")
+ PrintCodeOutputValue(value)
}

func GetOpSize(item *libgogo.Item, op string) uint64 {
- var size uint64;
- size = libgogo.StringCompare(op, "LEA");
- if size == 0 { //Always use 64 bits when performing LEA (=> LEAQ) as
reading something else than a 64 bit pointer on a 64 bit architecture does
not make any sense
- size = 8;
- } else {
- if (item.PtrType == 1) || ((item.Mode == libgogo.MODE_REG) &&
(item.A != 0)) { //Pointer type or register with address
- size = 8; //Pointers always have a size of 64 bits
- } else { //Value type
- if item.Itemtype.Form == libgogo.FORM_SIMPLE { //Simple type
- size = item.Itemtype.Len; //Size of type
- } else {
- if item.Itemtype == string_t { //Special treatment for
strings => 16 bytes
- size = 16;
- } else {
- size = 8; //Use 64 bits in all other cases (address
calculations, records etc.)
- }
- }
- }
- }
- return size;
+ var size uint64
+ size = libgogo.StringCompare(op, "LEA")
+ if size == 0 { //Always use 64 bits when performing LEA (=> LEAQ) as
reading something else than a 64 bit pointer on a 64 bit architecture does
not make any sense
+ size = 8
+ } else {
+ if (item.PtrType == 1) || ((item.Mode == libgogo.MODE_REG) && (item.A !=
0)) { //Pointer type or register with address
+ size = 8 //Pointers always have a size of 64 bits
+ } else { //Value type
+ if item.Itemtype.Form == libgogo.FORM_SIMPLE { //Simple type
+ size = item.Itemtype.Len //Size of type
+ } else {
+ if item.Itemtype == string_t { //Special treatment for strings => 16
bytes
+ size = 16
+ } else {
+ size = 8 //Use 64 bits in all other cases (address calculations,
records etc.)
+ }
+ }
+ }
+ }
+ return size
}

func PrintInstructionStart(op string, opsize uint64) uint64 {
- var retVal uint64 = 0;
- PrintCodeOutput(" ");
- PrintCodeOutput(op);
- if opsize == 1 { //byte => B
- PrintCodeOutput("B");
- } else {
- if opsize == 8 { //uint64 => Q
- PrintCodeOutput("Q");
- } else {
- if opsize > 8 { //>uint64 => Q and return rest of size to be
handled additionally
- PrintCodeOutput("Q");
- retVal = opsize - 8;
- } else { //Size between 1 and 8 which is neither byte nor
uint64
- PrintCodeOutput("?"); //TODO: Error: invalid opsize
- }
- }
- }
- PrintCodeOutput(" ");
- return retVal;
+ var retVal uint64 = 0
+ PrintCodeOutput(" ")
+ PrintCodeOutput(op)
+ if opsize == 1 { //byte => B
+ PrintCodeOutput("B")
+ } else {
+ if opsize == 8 { //uint64 => Q
+ PrintCodeOutput("Q")
+ } else {
+ if opsize > 8 { //>uint64 => Q and return rest of size to be handled
additionally
+ PrintCodeOutput("Q")
+ retVal = opsize - 8
+ } else { //Size between 1 and 8 which is neither byte nor uint64
+ PrintCodeOutput("?") //TODO: Error: invalid opsize
+ }
+ }
+ }
+ PrintCodeOutput(" ")
+ return retVal
}

func PrintInstructionOperandSeparator() {
- PrintCodeOutput(", ");
+ PrintCodeOutput(", ")
}

func PrintInstructionEnd() {
- PrintCodeOutput("\n");
+ PrintCodeOutput("\n")
}

func PrintInstruction_Reg(op string, opsize uint64, name string, number
uint64, indirect uint64, offset uint64, offsetnegative uint64,
optionaloffsetname string) uint64 {
- var retVal uint64;
- retVal = PrintInstructionStart(op, opsize);
- PrintRegister(name, number, indirect, offset, offsetnegative,
optionaloffsetname);
- PrintInstructionEnd();
- return retVal;
+ var retVal uint64
+ retVal = PrintInstructionStart(op, opsize)
+ PrintRegister(name, number, indirect, offset, offsetnegative,
optionaloffsetname)
+ PrintInstructionEnd()
+ return retVal
}

func PrintInstruction_Reg_Reg(op string, opsize uint64, reg1name string,
reg1number uint64, reg1indirect uint64, reg1offset uint64,
reg1offsetnegative uint64, reg1optionaloffsetname string, reg2name string,
reg2number uint64, reg2indirect uint64, reg2offset uint64,
reg2offsetnegative uint64, reg2optionaloffsetname string) uint64 {
- var retVal uint64;
- var ANDafter uint64 = 0;
- if (opsize == 1) && (reg2indirect == 0) { //Clear upper bits using AND
mask when operating on bytes; don't clear memory as op could be MOV and
therefore set 7 bytes unrecoverably to zero
- if (reg1indirect == 1) && (reg1number == reg2number) { //When
dereferring to the same register, perform AND operation afterwards in order
to maintain address to derefer
- ANDafter = 1;
- } else {
- PrintInstruction_Imm_Reg("AND", 8, 255, reg2name, reg2number,
reg2indirect, reg2offset, reg2offsetnegative, reg2optionaloffsetname);
//ANDQ $255, R
- }
- }
- retVal = PrintInstructionStart(op, opsize);
- PrintRegister(reg1name, reg1number, reg1indirect, reg1offset,
reg1offsetnegative, reg1optionaloffsetname);
- PrintInstructionOperandSeparator();
- PrintRegister(reg2name, reg2number, reg2indirect, reg2offset,
reg2offsetnegative, reg2optionaloffsetname);
- PrintInstructionEnd();
- if ANDafter == 1 {
- PrintInstruction_Imm_Reg("AND", 8, 255, reg2name, reg2number,
reg2indirect, reg2offset, reg2offsetnegative, reg2optionaloffsetname);
//ANDQ $255, R
- }
- return retVal;
+ var retVal uint64
+ var ANDafter uint64 = 0
+ if (opsize == 1) && (reg2indirect == 0) { //Clear upper bits using AND
mask when operating on bytes; don't clear memory as op could be MOV and
therefore set 7 bytes unrecoverably to zero
+ if (reg1indirect == 1) && (reg1number == reg2number) { //When
dereferring to the same register, perform AND operation afterwards in order
to maintain address to derefer
+ ANDafter = 1
+ } else {
+ PrintInstruction_Imm_Reg("AND", 8, 255, reg2name, reg2number,
reg2indirect, reg2offset, reg2offsetnegative, reg2optionaloffsetname)
//ANDQ $255, R
+ }
+ }
+ retVal = PrintInstructionStart(op, opsize)
+ PrintRegister(reg1name, reg1number, reg1indirect, reg1offset,
reg1offsetnegative, reg1optionaloffsetname)
+ PrintInstructionOperandSeparator()
+ PrintRegister(reg2name, reg2number, reg2indirect, reg2offset,
reg2offsetnegative, reg2optionaloffsetname)
+ PrintInstructionEnd()
+ if ANDafter == 1 {
+ PrintInstruction_Imm_Reg("AND", 8, 255, reg2name, reg2number,
reg2indirect, reg2offset, reg2offsetnegative, reg2optionaloffsetname)
//ANDQ $255, R
+ }
+ return retVal
}

func PrintInstruction_Reg_Imm(op string, opsize uint64, regname string,
regnumber uint64, regindirect uint64, regoffset uint64, regoffsetnegative
uint64, regoptionaloffsetname string, value uint64) {
- //No opcode check necessary here
- PrintInstructionStart(op, opsize);
- PrintRegister(regname, regnumber, regindirect, regoffset,
regoffsetnegative, regoptionaloffsetname);
- PrintInstructionOperandSeparator();
- PrintImmediate(value);
- PrintInstructionEnd();
+ //No opcode check necessary here
+ PrintInstructionStart(op, opsize)
+ PrintRegister(regname, regnumber, regindirect, regoffset,
regoffsetnegative, regoptionaloffsetname)
+ PrintInstructionOperandSeparator()
+ PrintImmediate(value)
+ PrintInstructionEnd()
}

func PrintInstruction_Imm_Reg(op string, opsize uint64, value uint64,
regname string, regnumber uint64, regindirect uint64, regoffset uint64,
regoffsetnegative uint64, regoptionaloffsetname string) {
- if (opsize == 1) && (regindirect == 0) { //Clear upper bits using AND
mask when operating on bytes; don't clear memory as op could be MOV and
therefore set 7 bytes unrecoverably to zero
- PrintInstruction_Imm_Reg("AND", 8, 255, regname, regnumber,
regindirect, regoffset, regoffsetnegative, regoptionaloffsetname); //ANDQ
$255, R
- }
- PrintInstructionStart(op, opsize);
- PrintImmediate(value);
- PrintInstructionOperandSeparator();
- PrintRegister(regname, regnumber, regindirect, regoffset,
regoffsetnegative, regoptionaloffsetname);
- PrintInstructionEnd();
+ if (opsize == 1) && (regindirect == 0) { //Clear upper bits using AND
mask when operating on bytes; don't clear memory as op could be MOV and
therefore set 7 bytes unrecoverably to zero
+ PrintInstruction_Imm_Reg("AND", 8, 255, regname, regnumber, regindirect,
regoffset, regoffsetnegative, regoptionaloffsetname) //ANDQ $255, R
+ }
+ PrintInstructionStart(op, opsize)
+ PrintImmediate(value)
+ PrintInstructionOperandSeparator()
+ PrintRegister(regname, regnumber, regindirect, regoffset,
regoffsetnegative, regoptionaloffsetname)
+ PrintInstructionEnd()
}

func PrintInstruction_Imm_Var(op string, value uint64, variable
*libgogo.Item) {
- var opsize uint64;
- var temp uint64;
- opsize = GetOpSize(variable, op);
- if variable.Global == 1 { //Global
- PrintInstruction_Imm_Reg(op, opsize, value, "SB", 0, 1,
variable.A, 0, "data"); //OP $value, data+variable.A(SB)
- } else { //Local
- if variable.Global == 2 { //Parameter
- PrintInstruction_Imm_Reg(op, opsize, value, "SP", 0, 1,
variable.A + 8, 0, ""); //OP $value, [variable.A+8](SP)
- } else { //Local
- temp = libgogo.StringLength(variable.LinkerInformation);
- if temp != 0 {
- GenerateLinkerComment(variable.LinkerInformation);
- }
- PrintInstruction_Imm_Reg(op, opsize, value, "SP", 0, 1,
variable.A + 8, 1, ""); //OP $value, -[variable.A+8](SP)
- }
- }
+ var opsize uint64
+ var temp uint64
+ opsize = GetOpSize(variable, op)
+ if variable.Global == 1 { //Global
+ PrintInstruction_Imm_Reg(op, opsize, value, "SB", 0, 1, variable.A,
0, "data") //OP $value, data+variable.A(SB)
+ } else { //Local
+ if variable.Global == 2 { //Parameter
+ PrintInstruction_Imm_Reg(op, opsize, value, "SP", 0, 1, variable.A+8,
0, "") //OP $value, [variable.A+8](SP)
+ } else { //Local
+ temp = libgogo.StringLength(variable.LinkerInformation)
+ if temp != 0 {
+ GenerateLinkerComment(variable.LinkerInformation)
+ }
+ PrintInstruction_Imm_Reg(op, opsize, value, "SP", 0, 1, variable.A+8,
1, "") //OP $value, -[variable.A+8](SP)
+ }
+ }
}

func PrintInstruction_Var_Imm(op string, variable *libgogo.Item, value
uint64) {
- var opsize uint64;
- var temp uint64;
- opsize = GetOpSize(variable, op);
- if variable.Global == 1 { //Global
- PrintInstruction_Reg_Imm(op, opsize, "SB", 0, 1, variable.A,
0, "data", value); // OP data+variable.A(SB), $value
- } else { //Local
- if variable.Global == 2 { //Parameter
- PrintInstruction_Reg_Imm(op, opsize, "SP", 0, 1, variable.A +
8, 0, "", value); // OP [variable.A+8](SP), $value
- } else { //Local
- temp = libgogo.StringLength(variable.LinkerInformation);
- if temp != 0 {
- GenerateLinkerComment(variable.LinkerInformation);
- }
- PrintInstruction_Reg_Imm(op, opsize, "SP", 0, 1, variable.A +
8, 1, "", value); // OP -[variable.A+8](SP), $value
- }
- }
+ var opsize uint64
+ var temp uint64
+ opsize = GetOpSize(variable, op)
+ if variable.Global == 1 { //Global
+ PrintInstruction_Reg_Imm(op, opsize, "SB", 0, 1, variable.A, 0, "data",
value) // OP data+variable.A(SB), $value
+ } else { //Local
+ if variable.Global == 2 { //Parameter
+ PrintInstruction_Reg_Imm(op, opsize, "SP", 0, 1, variable.A+8, 0, "",
value) // OP [variable.A+8](SP), $value
+ } else { //Local
+ temp = libgogo.StringLength(variable.LinkerInformation)
+ if temp != 0 {
+ GenerateLinkerComment(variable.LinkerInformation)
+ }
+ PrintInstruction_Reg_Imm(op, opsize, "SP", 0, 1, variable.A+8, 1, "",
value) // OP -[variable.A+8](SP), $value
+ }
+ }
}

func PrintInstruction_Reg_Var(op string, regname string, regnumber uint64,
optregname string, optregnumber uint64, variable *libgogo.Item) {
- var opsize uint64;
- var retVal uint64;
- var temp uint64;
- opsize = GetOpSize(variable, op);
- if variable.Global == 1 { //Global
- retVal = PrintInstruction_Reg_Reg(op, opsize, regname, regnumber,
0, 0, 0, "", "SB", 0, 1, variable.A, 0, "data"); //OP regname_regnumber,
data+variable.A(SB)
- if retVal != 0 { //Handle operands > 8 bytes
- PrintInstruction_Reg_Reg(op, retVal, optregname, optregnumber,
0, 0, 0, "", "SB", 0, 1, variable.A + 8, 0, "data"); //OP
optregname_optregnumber, data+variable.A+8(SB)
- }
- } else { //Local
- if variable.Global == 2 { //Parameter
- retVal = PrintInstruction_Reg_Reg(op, opsize, regname,
regnumber, 0, 0, 0, "", "SP", 0, 1, variable.A + 8, 0, ""); //OP
regname_regnumber, [variable.A+8](SP)
- if retVal != 0 { //Handle operands > 8 bytes
- PrintInstruction_Reg_Reg(op, retVal, optregname,
optregnumber, 0, 0, 0, "", "SP", 0, 1, variable.A + 16, 0, ""); //OP
optregname_optregnumber, [variable.A+8+8](SP)
- }
- } else { //Local
- temp = libgogo.StringLength(variable.LinkerInformation);
- if temp != 0 {
- GenerateLinkerComment(variable.LinkerInformation);
- }
- retVal = PrintInstruction_Reg_Reg(op, opsize, regname,
regnumber, 0, 0, 0, "", "SP", 0, 1, variable.A + 8, 1, ""); //OP
regname_regnumber, -[variable.A+8](SP)
- if retVal != 0 { //Handle operands > 8 bytes
- if temp != 0 {
- GenerateLinkerComment(variable.LinkerInformation);
- }
- PrintInstruction_Reg_Reg(op, retVal, optregname,
optregnumber, 0, 0, 0, "", "SP", 0, 1, variable.A, 1, ""); //OP
optregname_optregnumber, -[variable.A+8-8](SP)
- }
- }
- }
+ var opsize uint64
+ var retVal uint64
+ var temp uint64
+ opsize = GetOpSize(variable, op)
+ if variable.Global == 1 { //Global
+ retVal = PrintInstruction_Reg_Reg(op, opsize, regname, regnumber, 0, 0,
0, "", "SB", 0, 1, variable.A, 0, "data") //OP regname_regnumber,
data+variable.A(SB)
+ if retVal != 0
{
//Handle operands > 8 bytes
+ PrintInstruction_Reg_Reg(op, retVal, optregname, optregnumber, 0, 0,
0, "", "SB", 0, 1, variable.A+8, 0, "data") //OP optregname_optregnumber,
data+variable.A+8(SB)
+ }
+ } else { //Local
+ if variable.Global == 2 { //Parameter
+ retVal = PrintInstruction_Reg_Reg(op, opsize, regname, regnumber, 0, 0,
0, "", "SP", 0, 1, variable.A+8, 0, "") //OP regname_regnumber,
[variable.A+8](SP)
+ if retVal != 0
{
//Handle operands > 8 bytes
+ PrintInstruction_Reg_Reg(op, retVal, optregname, optregnumber, 0, 0,
0, "", "SP", 0, 1, variable.A+16, 0, "") //OP optregname_optregnumber,
[variable.A+8+8](SP)
+ }
+ } else { //Local
+ temp = libgogo.StringLength(variable.LinkerInformation)
+ if temp != 0 {
+ GenerateLinkerComment(variable.LinkerInformation)
+ }
+ retVal = PrintInstruction_Reg_Reg(op, opsize, regname, regnumber, 0, 0,
0, "", "SP", 0, 1, variable.A+8, 1, "") //OP regname_regnumber,
-[variable.A+8](SP)
+ if retVal != 0
{
//Handle operands > 8 bytes
+ if temp != 0 {
+ GenerateLinkerComment(variable.LinkerInformation)
+ }
+ PrintInstruction_Reg_Reg(op, retVal, optregname, optregnumber, 0, 0,
0, "", "SP", 0, 1, variable.A, 1, "") //OP optregname_optregnumber,
-[variable.A+8-8](SP)
+ }
+ }
+ }
}

func PrintInstruction_Var_Reg(op string, variable *libgogo.Item, regname
string, regnumber uint64, optregname string, optregnumber uint64) {
- var opsize uint64;
- var retVal uint64;
- var temp uint64;
- opsize = GetOpSize(variable, op);
- if variable.Global == 1 { //Global
- retVal = PrintInstruction_Reg_Reg(op, opsize, "SB", 0, 1,
variable.A, 0, "data", regname, regnumber, 0, 0, 0, ""); //OP
data+variable.A(SB), regname_regnumber
- if retVal != 0 { //Handle operands > 8 byte
- PrintInstruction_Reg_Reg(op, retVal, "SB", 0, 1, variable.A +
8, 0, "data", optregname, optregnumber, 0, 0, 0, ""); //OP
data+variable.A+8(SB), optregname_optregnumber
- }
- } else { //Local
- if variable.Global == 2 { //Parameter
- retVal = PrintInstruction_Reg_Reg(op, opsize, "SP", 0, 1,
variable.A + 8, 0, "", regname, regnumber, 0, 0, 0, ""); //OP
[variable.A+8](SP), regname_regnumber
- if retVal != 0 { //Handle operands > 8 byte
- PrintInstruction_Reg_Reg(op, retVal, "SP", 0, 1,
variable.A + 16, 0, "", optregname, optregnumber, 0, 0, 0, ""); //OP
[variable.A+8+8](SP), optregname_optregnumber
- }
- } else { //Local
- temp = libgogo.StringLength(variable.LinkerInformation);
- if temp != 0 {
- GenerateLinkerComment(variable.LinkerInformation);
- }
- retVal = PrintInstruction_Reg_Reg(op, opsize, "SP", 0, 1,
variable.A + 8, 1, "", regname, regnumber, 0, 0, 0, ""); //OP
-[variable.A+8](SP), regname_regnumber
- if retVal != 0 { //Handle operands > 8 byte
- if temp != 0 {
- GenerateLinkerComment(variable.LinkerInformation);
- }
- PrintInstruction_Reg_Reg(op, retVal, "SP", 0, 1,
variable.A, 1, "", optregname, optregnumber, 0, 0, 0, ""); //OP
-[variable.A+8-8](SP), optregname_optregnumber
- }
- }
- }
+ var opsize uint64
+ var retVal uint64
+ var temp uint64
+ opsize = GetOpSize(variable, op)
+ if variable.Global == 1 { //Global
+ retVal = PrintInstruction_Reg_Reg(op, opsize, "SB", 0, 1, variable.A,
0, "data", regname, regnumber, 0, 0, 0, "") //OP data+variable.A(SB),
regname_regnumber
+ if retVal != 0
{
//Handle operands > 8 byte
+ PrintInstruction_Reg_Reg(op, retVal, "SB", 0, 1, variable.A+8,
0, "data", optregname, optregnumber, 0, 0, 0, "") //OP
data+variable.A+8(SB), optregname_optregnumber
+ }
+ } else { //Local
+ if variable.Global == 2 { //Parameter
+ retVal = PrintInstruction_Reg_Reg(op, opsize, "SP", 0, 1, variable.A+8,
0, "", regname, regnumber, 0, 0, 0, "") //OP [variable.A+8](SP),
regname_regnumber
+ if retVal != 0
{
//Handle operands > 8 byte
+ PrintInstruction_Reg_Reg(op, retVal, "SP", 0, 1, variable.A+16, 0, "",
optregname, optregnumber, 0, 0, 0, "") //OP [variable.A+8+8](SP),
optregname_optregnumber
+ }
+ } else { //Local
+ temp = libgogo.StringLength(variable.LinkerInformation)
+ if temp != 0 {
+ GenerateLinkerComment(variable.LinkerInformation)
+ }
+ retVal = PrintInstruction_Reg_Reg(op, opsize, "SP", 0, 1, variable.A+8,
1, "", regname, regnumber, 0, 0, 0, "") //OP -[variable.A+8](SP),
regname_regnumber
+ if retVal != 0
{
//Handle operands > 8 byte
+ if temp != 0 {
+ GenerateLinkerComment(variable.LinkerInformation)
+ }
+ PrintInstruction_Reg_Reg(op, retVal, "SP", 0, 1, variable.A, 1, "",
optregname, optregnumber, 0, 0, 0, "") //OP -[variable.A+8-8](SP),
optregname_optregnumber
+ }
+ }
+ }
}

func PrintJump(jump string, label string) {
- PrintCodeOutput(" ");
- PrintCodeOutput(jump);
- PrintCodeOutput(" ");
- PrintCodeOutput(label);
- PrintInstructionEnd();
+ PrintCodeOutput(" ")
+ PrintCodeOutput(jump)
+ PrintCodeOutput(" ")
+ PrintCodeOutput(label)
+ PrintInstructionEnd()
}

func PrintLabel(label string) {
- PrintCodeOutput(label);
- PrintCodeOutput(":");
- PrintInstructionEnd();
+ PrintCodeOutput(label)
+ PrintCodeOutput(":")
+ PrintInstructionEnd()
}

func PrintFunctionCall(packagename string, label string, stackoffset
uint64, unknownoffset uint64) {
- var comment string = "";
- GenerateComment("Stack pointer offset before function call for local
variables start");
- if unknownoffset != 0 { //Output linker information
- comment = "##2##";
- libgogo.StringAppend(&comment, packagename);
- libgogo.StringAppend(&comment, "·");
- libgogo.StringAppend(&comment, label);
- libgogo.StringAppend(&comment, "##");
- GenerateLinkerComment(comment);
- }
- PrintInstruction_Imm_Reg("SUB", 8, stackoffset, "SP", 0, 0, 0, 0, "");
//SUBQ $stackoffset, SP
- GenerateComment("Stack pointer offset before function call for local
variables end");
- PrintCodeOutput(" CALL ");
- PrintCodeOutput(packagename);
- PrintCodeOutput("·");
- PrintCodeOutput(label);
- PrintCodeOutput("(SB)");
- PrintInstructionEnd();
- GenerateComment("Stack pointer offset after function call for local
variables start");
- if unknownoffset != 0 { //Output linker information
- GenerateLinkerComment(comment);
- }
- PrintInstruction_Imm_Reg("ADD", 8, stackoffset, "SP", 0, 0, 0, 0, "");
//ADDQ $stackoffset, SP
- GenerateComment("Stack pointer offset after function call for local
variables end");
+ var comment string = ""
+ GenerateComment("Stack pointer offset before function call for local
variables start")
+ if unknownoffset != 0 { //Output linker information
+ comment = "##2##"
+ libgogo.StringAppend(&comment, packagename)
+ libgogo.StringAppend(&comment, "·")
+ libgogo.StringAppend(&comment, label)
+ libgogo.StringAppend(&comment, "##")
+ GenerateLinkerComment(comment)
+ }
+ PrintInstruction_Imm_Reg("SUB", 8, stackoffset, "SP", 0, 0, 0, 0, "")
//SUBQ $stackoffset, SP
+ GenerateComment("Stack pointer offset before function call for local
variables end")
+ PrintCodeOutput(" CALL ")
+ PrintCodeOutput(packagename)
+ PrintCodeOutput("·")
+ PrintCodeOutput(label)
+ PrintCodeOutput("(SB)")
+ PrintInstructionEnd()
+ GenerateComment("Stack pointer offset after function call for local
variables start")
+ if unknownoffset != 0 { //Output linker information
+ GenerateLinkerComment(comment)
+ }
+ PrintInstruction_Imm_Reg("ADD", 8, stackoffset, "SP", 0, 0, 0, 0, "")
//ADDQ $stackoffset, SP
+ GenerateComment("Stack pointer offset after function call for local
variables end")
}

func PrintFunctionStart(packagename string, label string) {
- PrintCodeOutput("TEXT ");
- PrintCodeOutput(packagename);
- PrintCodeOutput("·");
- PrintCodeOutput(label);
- PrintCodeOutput("(SB),0,$0-0"); //Stack is managed manually
- PrintInstructionEnd();
+ PrintCodeOutput("TEXT ")
+ PrintCodeOutput(packagename)
+ PrintCodeOutput("·")
+ PrintCodeOutput(label)
+ PrintCodeOutput("(SB),0,$0-0") //Stack is managed manually
+ PrintInstructionEnd()
}

func PrintFunctionEnd() {
- PrintCodeOutput(" RET");
- PrintInstructionEnd();
- PrintInstructionEnd(); //Additional new line separation
+ PrintCodeOutput(" RET")
+ PrintInstructionEnd()
+ PrintInstructionEnd() //Additional new line separation
}

func SetDataSegmentSize(size uint64) {
- DataSegmentSize = size;
+ DataSegmentSize = size
}

func PutDataByte(offset uint64, value byte) {
- var temp uint64;
- PrintCodeOutput("DATA ");
- PrintRegister("SB", 0, 1, offset, 0, "data");
- PrintCodeOutput("/1");
- PrintInstructionOperandSeparator();
- temp = libgogo.ToIntFromByte(value);
- PrintImmediate(temp);
- PrintInstructionEnd();
-}
+ var temp uint64
+ PrintCodeOutput("DATA ")
+ PrintRegister("SB", 0, 1, offset, 0, "data")
+ PrintCodeOutput("/1")
+ PrintInstructionOperandSeparator()
+ temp = libgogo.ToIntFromByte(value)
+ PrintImmediate(temp)
+ PrintInstructionEnd()
+}
=======================================
--- /src/codegen.go Tue Aug 17 09:58:38 2010
+++ /src/codegen.go Wed Aug 18 10:20:16 2010
@@ -12,100 +12,100 @@
import "./libgogo/_obj/libgogo"

// Currently register from R8-R15 are available for usage
-var NumRegisters uint64 = 8;
-var FreeRegisters [8]byte;
+var NumRegisters uint64 = 8
+var FreeRegisters [8]byte

//
// Initialize the register to free-state.
//
func InitFreeRegisters() {
- var i uint64;
- for i = 0; i < NumRegisters; i = i + 1 {
- FreeRegisters[i] = 1;
- }
+ var i uint64
+ for i = 0; i < NumRegisters; i = i + 1 {
+ FreeRegisters[i] = 1
+ }
}

//
// Function returns a free register, BUT is not set to occupied.
//
func GetFreeRegister() uint64 {
- var i uint64;
- for i = 0; FreeRegisters[i] == 0; {
- i = i + 1;
- if i == NumRegisters {
- PrintHead();
- libgogo.ExitError("No more free registers available for code
generation", 5);
- }
- }
- return i+8;
+ var i uint64
+ for i = 0; FreeRegisters[i] == 0; {
+ i = i + 1
+ if i == NumRegisters {
+ PrintHead()
+ libgogo.ExitError("No more free registers available for code
generation", 5)
+ }
+ }
+ return i + 8
}

//
// Occupy a given register.
//
func OccupyRegister(index uint64) {
- var realIndex uint64;
- realIndex = index-8;
- FreeRegisters[realIndex] = 0;
+ var realIndex uint64
+ realIndex = index - 8
+ FreeRegisters[realIndex] = 0
}

//
// Free a given register.
//
func FreeRegister(index uint64) {
- var realIndex uint64;
- realIndex = index-8;
- FreeRegisters[realIndex] = 1;
+ var realIndex uint64
+ realIndex = index - 8
+ FreeRegisters[realIndex] = 1
}

//
// Saves the currently used registers to the stack
//
func SaveUsedRegisters(LocalVariableOffset uint64) uint64 {
- var i uint64;
- var counter uint64 = 0;
- var LHSItem *libgogo.Item;
-
- GenerateComment("Saving registers before function call start");
- for i = 0; i < NumRegisters; i = i + 1 {
- if FreeRegisters[i] == 0 {
- LHSItem = libgogo.NewItem();
- libgogo.SetItem(LHSItem, libgogo.MODE_VAR, uint64_t, 0,
LocalVariableOffset + counter * 8, 0, 0); //Local variable with additional
offset
- PrintInstruction_Reg_Var("MOV", "R", i + 8, "", 0, LHSItem);
//Save register i + 8
- counter = counter + 1;
- }
- }
- GenerateComment("Saving registers before function call end");
- return counter * 8; //Number of registers times 64 bit is new offset
+ var i uint64
+ var counter uint64 = 0
+ var LHSItem *libgogo.Item
+
+ GenerateComment("Saving registers before function call start")
+ for i = 0; i < NumRegisters; i = i + 1 {
+ if FreeRegisters[i] == 0 {
+ LHSItem = libgogo.NewItem()
+ libgogo.SetItem(LHSItem, libgogo.MODE_VAR, uint64_t, 0,
LocalVariableOffset+counter*8, 0, 0) //Local variable with additional offset
+ PrintInstruction_Reg_Var("MOV", "R", i+8, "", 0,
LHSItem) //Save register i + 8
+ counter = counter + 1
+ }
+ }
+ GenerateComment("Saving registers before function call end")
+ return counter * 8 //Number of registers times 64 bit is new offset
}

//
// Restores the currently used registers from the stack
//
func RestoreUsedRegisters(LocalVariableOffset uint64, RegisterOffset
uint64) {
- var i uint64;
- var counter uint64 = RegisterOffset / 8;
- var RHSItem *libgogo.Item;
-
- GenerateComment("Restoring registers after function call start");
- for i = NumRegisters - 1; i >= 0; i = i - 1 { //Reverse order (stack!)
- if FreeRegisters[i] == 0 {
- if counter == 0 {
- GenErrorWeak("Internal error: number of registers to
restore does not match (too large)");
- }
- RHSItem = libgogo.NewItem();
- libgogo.SetItem(RHSItem, libgogo.MODE_VAR, uint64_t, 0,
LocalVariableOffset - counter * 8, 0, 0); //Local variable with additional
offset
- PrintInstruction_Var_Reg("MOV", RHSItem, "R", i + 8, "", 0);
//Restore register i + 8
- counter = counter - 1;
- }
- if i == 0 { //Break on i = 0 as i-1 on uint64 yields an underflow
- break;
- }
- }
- if counter > 0 {
- GenErrorWeak("Internal error: number of registers to restore does
not match (too small)");
- }
- GenerateComment("Restoring registers after function call end");
+ var i uint64
+ var counter uint64 = RegisterOffset / 8
+ var RHSItem *libgogo.Item
+
+ GenerateComment("Restoring registers after function call start")
+ for i = NumRegisters - 1; i >= 0; i = i - 1 { //Reverse order (stack!)
+ if FreeRegisters[i] == 0 {
+ if counter == 0 {
+ GenErrorWeak("Internal error: number of registers to restore does not
match (too large)")
+ }
+ RHSItem = libgogo.NewItem()
+ libgogo.SetItem(RHSItem, libgogo.MODE_VAR, uint64_t, 0,
LocalVariableOffset-counter*8, 0, 0) //Local variable with additional offset
+ PrintInstruction_Var_Reg("MOV", RHSItem, "R", i+8, "",
0) //Restore register i + 8
+ counter = counter - 1
+ }
+ if i == 0 { //Break on i = 0 as i-1 on uint64 yields an underflow
+ break
+ }
+ }
+ if counter > 0 {
+ GenErrorWeak("Internal error: number of registers to restore does not
match (too small)")
+ }
+ GenerateComment("Restoring registers after function call end")
}

//
@@ -113,102 +113,102 @@
// Freeing is only possible if the mode is registered.
//
func FreeRegisterIfRequired(item *libgogo.Item) {
- if item.Mode == libgogo.MODE_REG {
- FreeRegister(item.R);
- if item.C != 0 {
- FreeRegister(item.C);
- }
- }
- if (item.Mode == libgogo.MODE_COND) && (item.R != 0) {
- FreeRegister(item.R);
- }
+ if item.Mode == libgogo.MODE_REG {
+ FreeRegister(item.R)
+ if item.C != 0 {
+ FreeRegister(item.C)
+ }
+ }
+ if (item.Mode == libgogo.MODE_COND) && (item.R != 0) {
+ FreeRegister(item.R)
+ }
}

//
// Moves the value of the address a register is currently pointing to into
the register itself
//
func DereferRegisterIfNecessary(item *libgogo.Item) {
- var opsize uint64;
- var retVal uint64;
- var addReg uint64;
- if (item.Mode == libgogo.MODE_REG) && (item.A != 0) { //Derefer
register if it contains an address
- item.A = 0; //Register will soon contain a value; make sure op
size calculation is based on the actual type size, not on the pointer size
- opsize = GetOpSize(item, "MOV");
- if opsize <= 8 {
- PrintInstruction_Reg_Reg("MOV", opsize, "R", item.R, 1, 0,
0, "", "R", item.R, 0, 0, 0, ""); //MOV (item.R), item.R
- } else { //Use intermediate register to maintain address to derefer
- PrintInstruction_Reg_Reg("MOV", 8, "R", item.R, 0, 0,
0, "", "BX", 0, 0, 0, 0, ""); //MOV item.R, BX
- retVal = PrintInstruction_Reg_Reg("MOV", opsize, "BX", 0, 1,
0, 0, "", "R", item.R, 0, 0, 0, ""); //MOV (BX), item.R
- if retVal != 0 {
- addReg = GetFreeRegister(); //Additional register required
- OccupyRegister(addReg);
- item.C = addReg;
- PrintInstruction_Reg_Reg("MOV", retVal, "BX", 0, 1, 8,
0, "", "R", item.C, 0, 0, 0, ""); //MOV 8(BX), item.C
- }
- }
- }
+ var opsize uint64
+ var retVal uint64
+ var addReg uint64
+ if (item.Mode == libgogo.MODE_REG) && (item.A != 0) { //Derefer register
if it contains an address
+ item.A = 0 //Register will soon contain a value; make sure op size
calculation is based on the actual type size, not on the pointer size
+ opsize = GetOpSize(item, "MOV")
+ if opsize <= 8 {
+ PrintInstruction_Reg_Reg("MOV", opsize, "R", item.R, 1, 0, 0, "", "R",
item.R, 0, 0, 0, "") //MOV (item.R), item.R
+ } else { //Use intermediate register to maintain address to derefer
+ PrintInstruction_Reg_Reg("MOV", 8, "R", item.R, 0, 0, 0, "", "BX", 0,
0, 0, 0, "") //MOV item.R, BX
+ retVal = PrintInstruction_Reg_Reg("MOV", opsize, "BX", 0, 1, 0,
0, "", "R", item.R, 0, 0, 0, "") //MOV (BX), item.R
+ if retVal != 0 {
+ addReg = GetFreeRegister() //Additional register required
+ OccupyRegister(addReg)
+ item.C = addReg
+ PrintInstruction_Reg_Reg("MOV", retVal, "BX", 0, 1, 8, 0, "", "R",
item.C, 0, 0, 0, "") //MOV 8(BX), item.C
+ }
+ }
+ }
}

//
// Derefers the item given if its type is a pointer
//
func DereferItemIfNecessary(item *libgogo.Item) {
- var opsize uint64;
- var retVal uint64;
- var addReg uint64;
- if item.PtrType == 1 {
- if item.Mode == libgogo.MODE_REG { //Item is already in a register
=> derefer register
- opsize = GetOpSize(item, "MOV");
- if opsize <= 8 {
- PrintInstruction_Reg_Reg("MOV", opsize, "R", item.R, 1, 0,
0, "", "R", item.R, 0, 0, 0, ""); //MOV (item.R), item.R
- } else { //Use intermediate register to maintain address to
derefer
- PrintInstruction_Reg_Reg("MOV", 8, "R", item.R, 0, 0,
0, "", "BX", 0, 0, 0, 0, ""); //MOV item.R, BX
- retVal = PrintInstruction_Reg_Reg("MOV", opsize, "BX", 0,
1, 0, 0, "", "R", item.R, 0, 0, 0, ""); //MOV (BX), item.R
- if retVal != 0 {
- addReg = GetFreeRegister(); //Additional register
required
- OccupyRegister(addReg);
- item.C = addReg;
- PrintInstruction_Reg_Reg("MOV", retVal, "BX", 0, 1, 8,
0, "", "R", item.C, 0, 0, 0, ""); //MOV 8(BX), item.C
- }
- }
- } else { //Item is not a register yet => make it a register by
loading its value
- MakeRegistered(item, 0); //Don't load address as loading the
value automatically derefers the item
- item.A = 1;
- }
- item.PtrType = 0; //Item type is no longer a pointer
- }
+ var opsize uint64
+ var retVal uint64
+ var addReg uint64
+ if item.PtrType == 1 {
+ if item.Mode == libgogo.MODE_REG { //Item is already in a register =>
derefer register
+ opsize = GetOpSize(item, "MOV")
+ if opsize <= 8 {
+ PrintInstruction_Reg_Reg("MOV", opsize, "R", item.R, 1, 0, 0, "", "R",
item.R, 0, 0, 0, "") //MOV (item.R), item.R
+ } else { //Use intermediate register to maintain address to derefer
+ PrintInstruction_Reg_Reg("MOV", 8, "R", item.R, 0, 0, 0, "", "BX", 0,
0, 0, 0, "") //MOV item.R, BX
+ retVal = PrintInstruction_Reg_Reg("MOV", opsize, "BX", 0, 1, 0,
0, "", "R", item.R, 0, 0, 0, "") //MOV (BX), item.R
+ if retVal != 0 {
+ addReg = GetFreeRegister() //Additional register required
+ OccupyRegister(addReg)
+ item.C = addReg
+ PrintInstruction_Reg_Reg("MOV", retVal, "BX", 0, 1, 8, 0, "", "R",
item.C, 0, 0, 0, "") //MOV 8(BX), item.C
+ }
+ }
+ } else { //Item is not a register yet => make it a register by loading
its value
+ MakeRegistered(item, 0) //Don't load address as loading the value
automatically derefers the item
+ item.A = 1
+ }
+ item.PtrType = 0 //Item type is no longer a pointer
+ }
}

func GenerateFieldAccess(item *libgogo.Item, offset uint64) {
- var offsetItem *libgogo.Item;
- if Compile != 0 {
- DereferItemIfNecessary(item); //Derefer address if item is a
pointer
- if item.Mode == libgogo.MODE_VAR { //Variable
- if item.Global == 0 { //Local variable offset calculation
- item.A = item.A - offset; //Reverse order due to sign
(p.e. -24(SP) with offset 16 is to be -8(SP) and thus 24-16)
- } else { //Global variable offset calculation
- item.A = item.A + offset;
- }
- } else { //Register
- offsetItem = libgogo.NewItem(); //For direct and indirect
offset calculation
- libgogo.SetItem(offsetItem, libgogo.MODE_CONST, uint64_t, 0,
offset, 0, 0); //Constant item for offset
- AddSubInstruction("ADD", item, offsetItem, 0, 1); //Add
constant item (offset), calculating with addresses
- }
- }
+ var offsetItem *libgogo.Item
+ if Compile != 0 {
+ DereferItemIfNecessary(item) //Derefer address if item is a pointer
+ if item.Mode == libgogo.MODE_VAR { //Variable
+ if item.Global == 0 { //Local variable offset calculation
+ item.A = item.A - offset //Reverse order due to sign (p.e. -24(SP)
with offset 16 is to be -8(SP) and thus 24-16)
+ } else { //Global variable offset calculation
+ item.A = item.A + offset
+ }
+ } else { //Register
+ offsetItem =
libgogo.NewItem() //For direct
and indirect offset calculation
+ libgogo.SetItem(offsetItem, libgogo.MODE_CONST, uint64_t, 0, offset, 0,
0) //Constant item for offset
+ AddSubInstruction("ADD", item, offsetItem, 0,
1) //Add constant item (offset), calculating with
addresses
+ }
+ }
}

func GenerateVariableFieldAccess(item *libgogo.Item, offsetItem
*libgogo.Item, baseTypeSize uint64) {
- var sizeItem *libgogo.Item;
- if Compile != 0 {
- DereferItemIfNecessary(item); //Derefer address if item is a
pointer
- if (offsetItem.Itemtype != byte_t) && (offsetItem.Itemtype !=
uint64_t) {
- SymbolTableError("Invalid index type for", "", "array
access:", offsetItem.Itemtype.Name);
- }
- sizeItem = libgogo.NewItem();
- libgogo.SetItem(sizeItem, libgogo.MODE_CONST, uint64_t, 0,
baseTypeSize, 0, 0); //Constant item
- DivMulInstruction("MUL", offsetItem, sizeItem, 0, 1); //Multiply
identifier value by array base type size => offsetItem now constains the
field offset
- AddSubInstruction("ADD", item, offsetItem, 0, 1); //Add calculated
offset to base address
- }
+ var sizeItem *libgogo.Item
+ if Compile != 0 {
+ DereferItemIfNecessary(item) //Derefer address if item is a pointer
+ if (offsetItem.Itemtype != byte_t) && (offsetItem.Itemtype != uint64_t) {
+ SymbolTableError("Invalid index type for", "", "array access:",
offsetItem.Itemtype.Name)
+ }
+ sizeItem = libgogo.NewItem()
+ libgogo.SetItem(sizeItem, libgogo.MODE_CONST, uint64_t, 0, baseTypeSize,
0, 0) //Constant item
+ DivMulInstruction("MUL", offsetItem, sizeItem, 0,
1) //Multiply identifier value by array base type
size => offsetItem now constains the field offset
+ AddSubInstruction("ADD", item, offsetItem, 0,
1) //Add calculated offset to base address
+ }
}

//
@@ -216,35 +216,35 @@
// a register. This function does not check whether the item is a pointer
type!
//
func MakeRegistered(item *libgogo.Item, calculatewithaddresses uint64) {
- var reg uint64;
- var reg2 uint64;
- var opsize uint64;
- if item.Mode != libgogo.MODE_REG {
- reg = GetFreeRegister();
- OccupyRegister(reg);
-
- if item.Mode == libgogo.MODE_CONST { // const item
- opsize = GetOpSize(item, "MOV");
- PrintInstruction_Imm_Reg("MOV", opsize, item.A, "R", reg, 0,
0, 0, ""); // MOV $item.A, Rdone (soon to be item.R)
- } else { // var item
- if calculatewithaddresses == 0 {
- opsize = GetOpSize(item, "MOV");
- if opsize > 8 { //Occupy additional register if operand
size is higher than 8 bytes
- reg2 = GetFreeRegister();
- OccupyRegister(reg2);
- item.C = reg2;
- }
- PrintInstruction_Var_Reg("MOV", item, "R", reg, "R",
reg2); // MOV item.A(SB), Rdone (soon to be item.R)
- } else {
- opsize = GetOpSize(item, "LEA");
- PrintInstruction_Var_Reg("LEA", item, "R", reg, "", 0); //
LEA item.A(SB), Rdone (soon to be item.R)
- }
- }
-
- item.Mode = libgogo.MODE_REG;
- item.R = reg; // item is now a register
- item.A = calculatewithaddresses; // item now contains a value if
calculatewithaddresses is 0, or an address if calculatewithaddress is 1
- }
+ var reg uint64
+ var reg2 uint64
+ var opsize uint64
+ if item.Mode != libgogo.MODE_REG {
+ reg = GetFreeRegister()
+ OccupyRegister(reg)
+
+ if item.Mode == libgogo.MODE_CONST { // const item
+ opsize = GetOpSize(item, "MOV")
+ PrintInstruction_Imm_Reg("MOV", opsize, item.A, "R", reg, 0, 0, 0, "")
// MOV $item.A, Rdone (soon to be item.R)
+ } else { // var item
+ if calculatewithaddresses == 0 {
+ opsize = GetOpSize(item, "MOV")
+ if opsize > 8 { //Occupy additional register if operand size is higher
than 8 bytes
+ reg2 = GetFreeRegister()
+ OccupyRegister(reg2)
+ item.C = reg2
+ }
+ PrintInstruction_Var_Reg("MOV", item, "R", reg, "R", reg2) // MOV
item.A(SB), Rdone (soon to be item.R)
+ } else {
+ opsize = GetOpSize(item, "LEA")
+ PrintInstruction_Var_Reg("LEA", item, "R", reg, "", 0) // LEA
item.A(SB), Rdone (soon to be item.R)
+ }
+ }
+
+ item.Mode = libgogo.MODE_REG
+ item.R = reg // item is now a register
+ item.A = calculatewithaddresses // item now contains a value if
calculatewithaddresses is 0, or an address if calculatewithaddress is 1
+ }
}

//
@@ -252,10 +252,10 @@
// done in the compiler.
//
func ConstFolding(item1 *libgogo.Item, item2 *libgogo.Item, constvalue
uint64) uint64 {
- var boolFlag uint64 = 0;
- if (item1.Mode == libgogo.MODE_CONST) && (item2.Mode ==
libgogo.MODE_CONST) {
- item1.A = constvalue;
- boolFlag = 1;
- }
- return boolFlag;
-}
+ var boolFlag uint64 = 0
+ if (item1.Mode == libgogo.MODE_CONST) && (item2.Mode ==
libgogo.MODE_CONST) {
+ item1.A = constvalue
+ boolFlag = 1
+ }
+ return boolFlag
+}
=======================================
--- /src/fib.go Tue Jun 22 11:11:47 2010
+++ /src/fib.go Wed Aug 18 10:20:16 2010
@@ -3,68 +3,67 @@
package main

type FibHolder struct {
- Unused uint64;
- Fibs [2]uint64;
-};
+ Unused uint64
+ Fibs [2]uint64
+}

func main() uint64 {
- var retValue uint64;
- var tofib1 uint64;
- var tofib2 uint64;
- var tmpStr string;
- var fibHolder FibHolder;
- var index uint64;
-
- index = 0;
- fibHolder.Fibs[index] = fib1(11);
- index = 1;
- fibHolder.Fibs[index] = fib2(93);
-
- libgogo.PrintString("Fibonacci\n");
- libgogo.PrintString("=========\n");
- libgogo.PrintString("Rekursiv(11): ");
- tmpStr = libgogo.IntToString(fibHolder.Fibs[0]);
- libgogo.PrintString(tmpStr);
- libgogo.PrintString("\n");
- libgogo.PrintString("Iterativ(93): ");
- tmpStr = libgogo.IntToString(fibHolder.Fibs[1]);
- libgogo.PrintString(tmpStr);
- libgogo.PrintString("\n");
+ var retValue uint64
+ var tofib1 uint64
+ var tofib2 uint64
+ var tmpStr string
+ var fibHolder FibHolder
+ var index uint64
+
+ index = 0
+ fibHolder.Fibs[index] = fib1(11)
+ index = 1
+ fibHolder.Fibs[index] = fib2(93)
+
+ libgogo.PrintString("Fibonacci\n")
+ libgogo.PrintString("=========\n")
+ libgogo.PrintString("Rekursiv(11): ")
+ tmpStr = libgogo.IntToString(fibHolder.Fibs[0])
+ libgogo.PrintString(tmpStr)
+ libgogo.PrintString("\n")
+ libgogo.PrintString("Iterativ(93): ")
+ tmpStr = libgogo.IntToString(fibHolder.Fibs[1])
+ libgogo.PrintString(tmpStr)
+ libgogo.PrintString("\n")
}

func fib1(i uint64) uint64 {
- var retVal uint64;
- var fib1 uint64;
- var fib2 uint64;
- if i <= 2 {
- retVal = 1;
- } else {
- fib1 = fib1(i-1);
- fib2 = fib1(i-2);
- retVal = fib1 + fib2;
- }
- return retVal;
+ var retVal uint64
+ var fib1 uint64
+ var fib2 uint64
+ if i <= 2 {
+ retVal = 1
+ } else {
+ fib1 = fib1(i - 1)
+ fib2 = fib1(i - 2)
+ retVal = fib1 + fib2
+ }
+ return retVal
}

func fib2(n uint64) uint64 {
- var a uint64;
- var b uint64;
- var new uint64;
- var cnt uint64;
- var retValue uint64;
-
- if n<=2 {
- retValue = 1;
- } else {
- a = 1;
- b = 1;
- for cnt=3;cnt<=n;cnt=cnt+1 {
- new = a+b;
- a = b;
- b = new;
- }
- retValue = new;
- }
- return retValue;
-}
-
+ var a uint64
+ var b uint64
+ var new uint64
+ var cnt uint64
+ var retValue uint64
+
+ if n <= 2 {
+ retValue = 1
+ } else {
+ a = 1
+ b = 1
+ for cnt = 3; cnt <= n; cnt = cnt + 1 {
+ new = a + b
+ a = b
+ b = new
+ }
+ retValue = new
+ }
+ return retValue
+}
=======================================
--- /src/gen-arith.go Tue Aug 17 09:58:38 2010
+++ /src/gen-arith.go Wed Aug 18 10:20:16 2010
@@ -21,74 +21,74 @@
// Note: This function can only handle operands with a maximum of 8 bytes
in size
//
func AddSubInstruction(op string, item1 *libgogo.Item, item2
*libgogo.Item, constvalue uint64, calculatewithaddresses uint64) {
- var done uint64 = 0;
- var opsize1 uint64;
- var opsize2 uint64;
-
- done = ConstFolding(item1, item2, constvalue);
-
- if (done == 0) && (item2.Mode == libgogo.MODE_CONST) && (item2.A == 0)
{ //Omit addition/subtraction by zero
- if calculatewithaddresses == 0 { //Calculate with values
- DereferRegisterIfNecessary(item1); //Calculate with values
- }
- GenerateComment("Addition/subtraction by zero omitted");
- done = 1;
- }
-
- if (done == 0) && (item1.Mode != libgogo.MODE_REG) { //item1 is not a
register => make it a register
- MakeRegistered(item1, calculatewithaddresses);
- }
-
- if done == 0 { //item1 is now (or has even already been) a register =>
use it
- if calculatewithaddresses == 0 { //Calculate with values
- DereferRegisterIfNecessary(item1); //Calculate with values
- }
-
- //byte + byte = byte, byte + uint64 = uint64, uint64 + byte =
uint64, uint64 + uint64 = uint64
- if (item1.Itemtype == byte_t) && (item2.Itemtype == uint64_t) {
- if item1.Mode != libgogo.MODE_CONST { //No need to convert
constants, as their upper bits are already implicitly zeroed
- MakeRegistered(item1, calculatewithaddresses);
//Implicitly convert to uint64 by moving item1 to a register, thereby
zeroing the upper bits if necessary
- }
- item1.Itemtype = uint64_t;
- }
- if (item2.Itemtype == byte_t) && (item1.Itemtype == uint64_t) {
- if item2.Mode != libgogo.MODE_CONST { //No need to convert
constants, as their upper bits are already implicitly zeroed
- MakeRegistered(item2, calculatewithaddresses);
//Implicitly convert to uint64 by moving item2 to a register, thereby
zeroing the upper bits if necessary
- }
- item2.Itemtype = uint64_t;
- }
- opsize1 = GetOpSize(item1, op);
- opsize2 = GetOpSize(item2, op);
- if opsize1 > opsize2 {
- opsize2 = opsize1;
- } else {
- opsize1 = opsize2;
- }
-
- if (done == 0) && (item2.Mode == libgogo.MODE_CONST) {
- PrintInstruction_Imm_Reg(op, opsize2, item2.A, "R", item1.R,
0, 0, 0, ""); //OP $item2.A, item1.R
- done = 1;
- }
- if (done == 0) && (item2.Mode == libgogo.MODE_VAR) {
- PrintInstruction_Var_Reg(op, item2, "R", item1.R, "", 0); //OP
item2.A(SB), item1.R
- done = 1;
- }
- if (done == 0) && (item2.Mode == libgogo.MODE_REG) {
- if calculatewithaddresses == 0 { // Calculate with values
- DereferRegisterIfNecessary(item2);
- }
- opsize2 = GetOpSize(item2, op); //Recalculate op size for
item2 as it may have been deref.
- if opsize1 > opsize2 {
- opsize2 = opsize1;
- } else {
- opsize1 = opsize2;
- }
- PrintInstruction_Reg_Reg(op, opsize2, "R", item2.R, 0, 0,
0, "", "R", item1.R, 0, 0, 0, ""); //OP item2.R, item1.R
- done = 1;
- }
- }
-
- FreeRegisterIfRequired(item2); // item2 should be useless by now
+ var done uint64 = 0
+ var opsize1 uint64
+ var opsize2 uint64
+
+ done = ConstFolding(item1, item2, constvalue)
+
+ if (done == 0) && (item2.Mode == libgogo.MODE_CONST) && (item2.A == 0) {
//Omit addition/subtraction by zero
+ if calculatewithaddresses == 0 { //Calculate with values
+ DereferRegisterIfNecessary(item1) //Calculate with values
+ }
+ GenerateComment("Addition/subtraction by zero omitted")
+ done = 1
+ }
+
+ if (done == 0) && (item1.Mode != libgogo.MODE_REG) { //item1 is not a
register => make it a register
+ MakeRegistered(item1, calculatewithaddresses)
+ }
+
+ if done == 0 { //item1 is now (or has even already been) a register =>
use it
+ if calculatewithaddresses == 0 { //Calculate with values
+ DereferRegisterIfNecessary(item1) //Calculate with values
+ }
+
+ //byte + byte = byte, byte + uint64 = uint64, uint64 + byte = uint64,
uint64 + uint64 = uint64
+ if (item1.Itemtype == byte_t) && (item2.Itemtype == uint64_t) {
+ if item1.Mode != libgogo.MODE_CONST { //No need to convert constants,
as their upper bits are already implicitly zeroed
+ MakeRegistered(item1, calculatewithaddresses) //Implicitly convert to
uint64 by moving item1 to a register, thereby zeroing the upper bits if
necessary
+ }
+ item1.Itemtype = uint64_t
+ }
+ if (item2.Itemtype == byte_t) && (item1.Itemtype == uint64_t) {
+ if item2.Mode != libgogo.MODE_CONST { //No need to convert constants,
as their upper bits are already implicitly zeroed
+ MakeRegistered(item2, calculatewithaddresses) //Implicitly convert to
uint64 by moving item2 to a register, thereby zeroing the upper bits if
necessary
+ }
+ item2.Itemtype = uint64_t
+ }
+ opsize1 = GetOpSize(item1, op)
+ opsize2 = GetOpSize(item2, op)
+ if opsize1 > opsize2 {
+ opsize2 = opsize1
+ } else {
+ opsize1 = opsize2
+ }
+
+ if (done == 0) && (item2.Mode == libgogo.MODE_CONST) {
+ PrintInstruction_Imm_Reg(op, opsize2, item2.A, "R", item1.R, 0, 0,
0, "") //OP $item2.A, item1.R
+ done = 1
+ }
+ if (done == 0) && (item2.Mode == libgogo.MODE_VAR) {
+ PrintInstruction_Var_Reg(op, item2, "R", item1.R, "", 0) //OP
item2.A(SB), item1.R
+ done = 1
+ }
+ if (done == 0) && (item2.Mode == libgogo.MODE_REG) {
+ if calculatewithaddresses == 0 { // Calculate with values
+ DereferRegisterIfNecessary(item2)
+ }
+ opsize2 = GetOpSize(item2, op) //Recalculate op size for item2 as it
may have been deref.
+ if opsize1 > opsize2 {
+ opsize2 = opsize1
+ } else {
+ opsize1 = opsize2
+ }
+ PrintInstruction_Reg_Reg(op, opsize2, "R", item2.R, 0, 0, 0, "", "R",
item1.R, 0, 0, 0, "") //OP item2.R, item1.R
+ done = 1
+ }
+ }
+
+ FreeRegisterIfRequired(item2) // item2 should be useless by now
}

//
@@ -100,81 +100,81 @@
// Note: This function can only handle operands with a maximum of 8 bytes
in size
//
func DivMulInstruction(op string, item1 *libgogo.Item, item2
*libgogo.Item, constvalue uint64, calculatewithaddresses uint64) {
- var done uint64 = 0;
- var opsize1 uint64;
- var opsize2 uint64;
-
- done = ConstFolding(item1, item2, constvalue);
-
- if (done == 0) && (item2.Mode == libgogo.MODE_CONST) && (item2.A == 1)
{ //Omit multiplication/division by one
- GenerateComment("Multiplication/division by one omitted");
- done = 1;
- }
-
- if done == 0 { // item1 is now (or has even already been) a register
=> use it
- if calculatewithaddresses == 0 { // Calculate with values
- DereferRegisterIfNecessary(item1); // Calculate with values
- }
-
- opsize1 = GetOpSize(item1, "MOV");
- if item1.Mode == libgogo.MODE_CONST {
- PrintInstruction_Imm_Reg("MOV", opsize1, item1.A, "AX", 0, 0,
0, 0, "") // move $item1.A into AX
- }
- if item1.Mode == libgogo.MODE_VAR {
- PrintInstruction_Var_Reg("MOV", item1, "AX", 0, "", 0); //
move item2.A(SB), AX
- }
- if item1.Mode == libgogo.MODE_REG {
- PrintInstruction_Reg_Reg("MOV", opsize1, "R", item1.R, 0, 0,
0, "", "AX", 0, 0, 0, 0, "") // move item1.R into AX
- }
-
- //byte * byte = byte, byte * uint64 = uint64, uint64 * byte =
uint64, uint64 * uint64 = uint64
- if (item1.Itemtype == byte_t) && (item2.Itemtype == uint64_t) {
- if item1.Mode != libgogo.MODE_CONST { //No need to convert
constants, as their upper bits are already implicitly zeroed
- MakeRegistered(item1, calculatewithaddresses);
//Implicitly convert to uint64 by moving item1 to a register, thereby
zeroing the upper bits if necessary
- }
- item1.Itemtype = uint64_t;
- }
- if (item2.Itemtype == byte_t) && (item1.Itemtype == uint64_t) {
- if item2.Mode != libgogo.MODE_CONST { //No need to convert
constants, as their upper bits are already implicitly zeroed
- MakeRegistered(item2, calculatewithaddresses);
//Implicitly convert to uint64 by moving item2 to a register, thereby
zeroing the upper bits if necessary
- }
- item2.Itemtype = uint64_t;
- }
-
- if item2.Mode != libgogo.MODE_REG {
- // item2 needs to be registered as the second operand of a
DIV/MUL
- // instruction always needs to be a register
- MakeRegistered(item2, calculatewithaddresses);
- }
-
- // OP item2.R
- if calculatewithaddresses == 0 { // Calculate with values
- DereferRegisterIfNecessary(item2);
- }
- done = libgogo.StringCompare(op, "DIV");
- if done == 0 { //Set DX to zero to avoid 128 bit division as DX
is "high" part of DX:AX 128 bit register
- PrintInstruction_Reg_Reg("XOR", 8, "DX", 0, 0, 0, 0, "", "DX",
0, 0, 0, 0, ""); //XORQ DX, DX is equal to MOVQ $0, DX
- }
-
- opsize1 = GetOpSize(item1, op);
- opsize2 = GetOpSize(item2, op);
- if opsize1 > opsize2 {
- opsize2 = opsize1;
- } else {
- opsize1 = opsize2;
- }
-
- PrintInstruction_Reg(op, opsize2, "R", item2.R, 0, 0, 0, ""); //op
item2.R
- PrintInstruction_Reg_Reg("MOV", opsize2, "AX", 0, 0, 0,
0, "", "R", item2.R, 0, 0, 0, "") // move AX into item2.R
-
- // Since item2 already had to be converted to a register, we now
assign
- // item2 to item1 after freeing item1 first (if necessary)
- FreeRegisterIfRequired(item1);
- item1.Mode = item2.Mode;
- item1.R = item2.R;
- item1.A = item2.A;
- item1.Itemtype = item2.Itemtype;
- item1.PtrType = item2.PtrType; //Should always be 0
- item1.Global = item2.Global;
- }
-}
+ var done uint64 = 0
+ var opsize1 uint64
+ var opsize2 uint64
+
+ done = ConstFolding(item1, item2, constvalue)
+
+ if (done == 0) && (item2.Mode == libgogo.MODE_CONST) && (item2.A == 1) {
//Omit multiplication/division by one
+ GenerateComment("Multiplication/division by one omitted")
+ done = 1
+ }
+
+ if done == 0 { // item1 is now (or has even already been) a register =>
use it
+ if calculatewithaddresses == 0 { // Calculate with values
+ DereferRegisterIfNecessary(item1) // Calculate with values
+ }
+
+ opsize1 = GetOpSize(item1, "MOV")
+ if item1.Mode == libgogo.MODE_CONST {
+ PrintInstruction_Imm_Reg("MOV", opsize1, item1.A, "AX", 0, 0, 0, 0, "")
// move $item1.A into AX
+ }
+ if item1.Mode == libgogo.MODE_VAR {
+ PrintInstruction_Var_Reg("MOV", item1, "AX", 0, "", 0) // move
item2.A(SB), AX
+ }
+ if item1.Mode == libgogo.MODE_REG {
+ PrintInstruction_Reg_Reg("MOV", opsize1, "R", item1.R, 0, 0,
0, "", "AX", 0, 0, 0, 0, "") // move item1.R into AX
+ }
+
+ //byte * byte = byte, byte * uint64 = uint64, uint64 * byte = uint64,
uint64 * uint64 = uint64
+ if (item1.Itemtype == byte_t) && (item2.Itemtype == uint64_t) {
+ if item1.Mode != libgogo.MODE_CONST { //No need to convert constants,
as their upper bits are already implicitly zeroed
+ MakeRegistered(item1, calculatewithaddresses) //Implicitly convert to
uint64 by moving item1 to a register, thereby zeroing the upper bits if
necessary
+ }
+ item1.Itemtype = uint64_t
+ }
+ if (item2.Itemtype == byte_t) && (item1.Itemtype == uint64_t) {
+ if item2.Mode != libgogo.MODE_CONST { //No need to convert constants,
as their upper bits are already implicitly zeroed
+ MakeRegistered(item2, calculatewithaddresses) //Implicitly convert to
uint64 by moving item2 to a register, thereby zeroing the upper bits if
necessary
+ }
+ item2.Itemtype = uint64_t
+ }
+
+ if item2.Mode != libgogo.MODE_REG {
+ // item2 needs to be registered as the second operand of a DIV/MUL
+ // instruction always needs to be a register
+ MakeRegistered(item2, calculatewithaddresses)
+ }
+
+ // OP item2.R
+ if calculatewithaddresses == 0 { // Calculate with values
+ DereferRegisterIfNecessary(item2)
+ }
+ done = libgogo.StringCompare(op, "DIV")
+ if done == 0 { //Set DX to zero to avoid 128 bit division as DX
is "high" part of DX:AX 128 bit register
+ PrintInstruction_Reg_Reg("XOR", 8, "DX", 0, 0, 0, 0, "", "DX", 0, 0, 0,
0, "") //XORQ DX, DX is equal to MOVQ $0, DX
+ }
+
+ opsize1 = GetOpSize(item1, op)
+ opsize2 = GetOpSize(item2, op)
+ if opsize1 > opsize2 {
+ opsize2 = opsize1
+ } else {
+ opsize1 = opsize2
+ }
+
+ PrintInstruction_Reg(op, opsize2, "R", item2.R, 0, 0,
0, "") //op item2.R
+ PrintInstruction_Reg_Reg("MOV", opsize2, "AX", 0, 0, 0, 0, "", "R",
item2.R, 0, 0, 0, "") // move AX into item2.R
+
+ // Since item2 already had to be converted to a register, we now assign
+ // item2 to item1 after freeing item1 first (if necessary)
+ FreeRegisterIfRequired(item1)
+ item1.Mode = item2.Mode
+ item1.R = item2.R
+ item1.A = item2.A
+ item1.Itemtype = item2.Itemtype
+ item1.PtrType = item2.PtrType //Should always be 0
+ item1.Global = item2.Global
+ }
+}
=======================================
--- /src/gen-assign.go Tue Aug 17 09:58:38 2010
+++ /src/gen-assign.go Wed Aug 18 10:20:16 2010
@@ -11,16 +11,16 @@
import "./libgogo/_obj/libgogo"

func GenerateAssignment(LHSItem *libgogo.Item, RHSItem *libgogo.Item,
address uint64) {
- if Compile != 0 {
- if (LHSItem.Mode == libgogo.MODE_UNDEF) || (RHSItem.Mode ==
libgogo.MODE_UNDEF) {
- GenErrorWeak("internal compiler error. stopping code
generation.");
- }
- if address == 0 { //LHS = RHS
- GenerateRawAssignment(LHSItem, RHSItem);
- } else { //LHS = &RHS
- GenerateAssignmentWithAmpersandOnRHS(LHSItem, RHSItem);
- }
- }
+ if Compile != 0 {
+ if (LHSItem.Mode == libgogo.MODE_UNDEF) || (RHSItem.Mode ==
libgogo.MODE_UNDEF) {
+ GenErrorWeak("internal compiler error. stopping code generation.")
+ }
+ if address == 0 { //LHS = RHS
+ GenerateRawAssignment(LHSItem, RHSItem)
+ } else { //LHS = &RHS
+ GenerateAssignmentWithAmpersandOnRHS(LHSItem, RHSItem)
+ }
+ }
}

//
@@ -28,121 +28,121 @@
// Converts the RHS to a uint64 if the LHS is a uint64 and the RHS is a
byte
//
func GenerateRawAssignment(LHSItem *libgogo.Item, RHSItem *libgogo.Item) {
- var done uint64 = 0;
- var opsize uint64;
-
- if LHSItem.PtrType == 1 { //Pointer assignment
- if RHSItem.PtrType != 1 {
- SymbolTableError("Cannot assign a value type to a
pointer", "", "type:", RHSItem.Itemtype.Name);
- }
- if (LHSItem.Itemtype != RHSItem.Itemtype) && (RHSItem.Itemtype !=
nil) { //Itemtype nil refers to the "nil" object
- SymbolTableError("Incompatible pointer types:",
LHSItem.Itemtype.Name, "and", RHSItem.Itemtype.Name);
- }
- } else { //Value assignment
- if RHSItem.PtrType == 1 {
- SymbolTableError("Cannot assign a pointer type to a
value", "", "type:", RHSItem.Itemtype.Name);
- }
-
- //Allow assigning a byte to a uint64
- if (LHSItem.Itemtype == uint64_t) && (RHSItem.Itemtype == byte_t) {
- if RHSItem.Mode != libgogo.MODE_CONST { //No need to convert
constants, as their upper bits are already implicitly zeroed
- MakeRegistered(RHSItem, 0); //Implicitly convert to uint64
by moving RHSItem to a register, thereby zeroing the upper bits if necessary
- }
- RHSItem.Itemtype = uint64_t;
- }
-
- if LHSItem.Itemtype != RHSItem.Itemtype {
- SymbolTableError("Incompatible types:",
LHSItem.Itemtype.Name, "and", RHSItem.Itemtype.Name);
- }
- if (LHSItem.Itemtype != byte_t) && (LHSItem.Itemtype != uint64_t)
&& (LHSItem.Itemtype != string_t) {
- SymbolTableError("Cannot assign to", "", "type",
LHSItem.Itemtype.Name);
- }
- }
-
- if LHSItem.Mode == libgogo.MODE_VAR { //Variable on LHS
- if (done == 0) && (RHSItem.Mode == libgogo.MODE_CONST) { //Const
RHS
- PrintInstruction_Imm_Var("MOV", RHSItem.A, LHSItem); //MOV
$RHSItem.A, LHSItem.A(SB)
- done = 1;
- }
- if (done == 0) && (RHSItem.Mode == libgogo.MODE_VAR) { //Var RHS
- MakeRegistered(RHSItem, 0); //Load value
- PrintInstruction_Reg_Var("MOV", "R", RHSItem.R, "R",
RHSItem.C, LHSItem); //MOV RHSItem.R, LHSItem.A(SB)
- done = 1;
- }
- if (done == 0) && (RHSItem.Mode == libgogo.MODE_REG) { //Reg RHS
- DereferRegisterIfNecessary(RHSItem); //Make sure to work with
the value, not the address
- PrintInstruction_Reg_Var("MOV", "R", RHSItem.R, "R",
RHSItem.C, LHSItem); //MOV RHSItem.R, LHSItem.A(SB)
- done = 1;
- }
- } else { //Register with address of variable on LHS; assertion:
Register contains address and global/local flag is set correctly
- if (done == 0) && (RHSItem.Mode == libgogo.MODE_CONST) { //Const
RHS
- opsize = GetOpSize(RHSItem, "MOV");
- PrintInstruction_Imm_Reg("MOV", opsize, RHSItem.A, "R",
LHSItem.R, 1, 0, 0, ""); //MOV $RHSItem.A, (LHSItem.R)
- done = 1;
- }
- if (done == 0) && (RHSItem.Mode == libgogo.MODE_VAR) { //Var RHS
- MakeRegistered(RHSItem, 0); //Load value
- opsize = GetOpSize(RHSItem, "MOV");
- done = PrintInstruction_Reg_Reg("MOV", opsize, "R", RHSItem.R,
0, 0, 0, "", "R", LHSItem.R, 1, 0, 0, ""); //MOV RHSItem.R, (LHSItem.R)
- if done != 0 { //Handle operands > 8 bytes
- if LHSItem.C != 0 {
- PrintInstruction_Reg_Reg("MOV", done, "R", RHSItem.C,
0, 0, 0, "", "R", LHSItem.C, 1, 0, 0, ""); //MOV RHSItem.C, (LHSItem.C)
- } else {
- PrintInstruction_Reg_Reg("MOV", done, "R", RHSItem.C,
0, 0, 0, "", "R", LHSItem.R, 1, 8, 0, ""); //MOV RHSItem.C, 8(LHSItem.R)
- }
- }
- done = 1;
- }
- if (done == 0) && (RHSItem.Mode == libgogo.MODE_REG) { //Reg RHS
- DereferRegisterIfNecessary(RHSItem); //Make sure to work with
the value, not the address
- opsize = GetOpSize(RHSItem, "MOV");
- done = PrintInstruction_Reg_Reg("MOV", opsize, "R", RHSItem.R,
0, 0, 0, "", "R", LHSItem.R, 1, 0, 0, ""); //MOV RHSItem.R, (LHSItem.R)
- if done != 0 { //Handle operands > 8 bytes
- if LHSItem.C != 0 {
- PrintInstruction_Reg_Reg("MOV", done, "R", RHSItem.C,
0, 0, 0, "", "R", LHSItem.C, 1, 0, 0, ""); //MOV RHSItem.C, (LHSItem.C)
- } else {
- PrintInstruction_Reg_Reg("MOV", done, "R", RHSItem.C,
0, 0, 0, "", "R", LHSItem.R, 1, 8, 0, ""); //MOV RHSItem.C, 8(LHSItem.R)
- }
- }
- done = 1;
- }
- }
- FreeRegisterIfRequired(LHSItem);
- FreeRegisterIfRequired(RHSItem);
+ var done uint64 = 0
+ var opsize uint64
+
+ if LHSItem.PtrType == 1 { //Pointer assignment
+ if RHSItem.PtrType != 1 {
+ SymbolTableError("Cannot assign a value type to a
pointer", "", "type:", RHSItem.Itemtype.Name)
+ }
+ if (LHSItem.Itemtype != RHSItem.Itemtype) && (RHSItem.Itemtype != nil) {
//Itemtype nil refers to the "nil" object
+ SymbolTableError("Incompatible pointer types:",
LHSItem.Itemtype.Name, "and", RHSItem.Itemtype.Name)
+ }
+ } else { //Value assignment
+ if RHSItem.PtrType == 1 {
+ SymbolTableError("Cannot assign a pointer type to a
value", "", "type:", RHSItem.Itemtype.Name)
+ }
+
+ //Allow assigning a byte to a uint64
+ if (LHSItem.Itemtype == uint64_t) && (RHSItem.Itemtype == byte_t) {
+ if RHSItem.Mode != libgogo.MODE_CONST { //No need to convert constants,
as their upper bits are already implicitly zeroed
+ MakeRegistered(RHSItem, 0) //Implicitly convert to uint64 by moving
RHSItem to a register, thereby zeroing the upper bits if necessary
+ }
+ RHSItem.Itemtype = uint64_t
+ }
+
+ if LHSItem.Itemtype != RHSItem.Itemtype {
+ SymbolTableError("Incompatible types:", LHSItem.Itemtype.Name, "and",
RHSItem.Itemtype.Name)
+ }
+ if (LHSItem.Itemtype != byte_t) && (LHSItem.Itemtype != uint64_t) &&
(LHSItem.Itemtype != string_t) {
+ SymbolTableError("Cannot assign to", "", "type", LHSItem.Itemtype.Name)
+ }
+ }
+
+ if LHSItem.Mode == libgogo.MODE_VAR { //Variable on LHS
+ if (done == 0) && (RHSItem.Mode == libgogo.MODE_CONST) { //Const RHS
+ PrintInstruction_Imm_Var("MOV", RHSItem.A, LHSItem) //MOV $RHSItem.A,
LHSItem.A(SB)
+ done = 1
+ }
+ if (done == 0) && (RHSItem.Mode == libgogo.MODE_VAR) { //Var RHS
+ MakeRegistered(RHSItem,
0) //Load value
+ PrintInstruction_Reg_Var("MOV", "R", RHSItem.R, "R", RHSItem.C,
LHSItem) //MOV RHSItem.R, LHSItem.A(SB)
+ done = 1
+ }
+ if (done == 0) && (RHSItem.Mode == libgogo.MODE_REG) { //Reg RHS
+
DereferRegisterIfNecessary(RHSItem)
//Make sure to work with the value, not the address
+ PrintInstruction_Reg_Var("MOV", "R", RHSItem.R, "R", RHSItem.C,
LHSItem) //MOV RHSItem.R, LHSItem.A(SB)
+ done = 1
+ }
+ } else { //Register with address of variable on LHS; assertion: Register
contains address and global/local flag is set correctly
+ if (done == 0) && (RHSItem.Mode == libgogo.MODE_CONST) { //Const RHS
+ opsize = GetOpSize(RHSItem, "MOV")
+ PrintInstruction_Imm_Reg("MOV", opsize, RHSItem.A, "R", LHSItem.R, 1,
0, 0, "") //MOV $RHSItem.A, (LHSItem.R)
+ done = 1
+ }
+ if (done == 0) && (RHSItem.Mode == libgogo.MODE_VAR) { //Var RHS
+ MakeRegistered(RHSItem, 0) //Load value
+ opsize = GetOpSize(RHSItem, "MOV")
+ done = PrintInstruction_Reg_Reg("MOV", opsize, "R", RHSItem.R, 0, 0,
0, "", "R", LHSItem.R, 1, 0, 0, "") //MOV RHSItem.R, (LHSItem.R)
+ if done != 0
{
//Handle operands > 8 bytes
+ if LHSItem.C != 0 {
+ PrintInstruction_Reg_Reg("MOV", done, "R", RHSItem.C, 0, 0,
0, "", "R", LHSItem.C, 1, 0, 0, "") //MOV RHSItem.C, (LHSItem.C)
+ } else {
+ PrintInstruction_Reg_Reg("MOV", done, "R", RHSItem.C, 0, 0,
0, "", "R", LHSItem.R, 1, 8, 0, "") //MOV RHSItem.C, 8(LHSItem.R)
+ }
+ }
+ done = 1
+ }
+ if (done == 0) && (RHSItem.Mode == libgogo.MODE_REG) { //Reg RHS
+ DereferRegisterIfNecessary(RHSItem) //Make sure to work with the value,
not the address
+ opsize = GetOpSize(RHSItem, "MOV")
+ done = PrintInstruction_Reg_Reg("MOV", opsize, "R", RHSItem.R, 0, 0,
0, "", "R", LHSItem.R, 1, 0, 0, "") //MOV RHSItem.R, (LHSItem.R)
+ if done != 0
{
//Handle operands > 8 bytes
+ if LHSItem.C != 0 {
+ PrintInstruction_Reg_Reg("MOV", done, "R", RHSItem.C, 0, 0,
0, "", "R", LHSItem.C, 1, 0, 0, "") //MOV RHSItem.C, (LHSItem.C)
+ } else {
+ PrintInstruction_Reg_Reg("MOV", done, "R", RHSItem.C, 0, 0,
0, "", "R", LHSItem.R, 1, 8, 0, "") //MOV RHSItem.C, 8(LHSItem.R)
+ }
+ }
+ done = 1
+ }
+ }
+ FreeRegisterIfRequired(LHSItem)
+ FreeRegisterIfRequired(RHSItem)
}

//
// Performs the assignment LHS = &RHS
//
func GenerateAssignmentWithAmpersandOnRHS(LHSItem *libgogo.Item, RHSItem
*libgogo.Item) {
- var opsize uint64;
- var retVal uint64;
- if LHSItem.PtrType == 0 {
- SymbolTableError("Cannot assign a pointer type to a
value", "", "type:", LHSItem.Itemtype.Name);
- }
- if RHSItem.PtrType == 1 {
- SymbolTableError("Cannot assign a pointer's address to a
pointer", "", "type:", LHSItem.Itemtype.Name);
- }
- if LHSItem.Itemtype != RHSItem.Itemtype {
- SymbolTableError("Incompatible pointer types:",
LHSItem.Itemtype.Name, "and", RHSItem.Itemtype.Name);
- }
-
- if RHSItem.Mode == libgogo.MODE_VAR { //Var RHS => load address to
register
- MakeRegistered(RHSItem, 1); //LEA RHSItem.A(SB), to be RHSItem.R
- } //Reg RHS
- if LHSItem.Mode == libgogo.MODE_VAR { //Variable on LHS
- PrintInstruction_Reg_Var("MOV", "R", RHSItem.R, "R", RHSItem.C,
LHSItem); //MOV RHSItem.R, LHSItem.A(SB)
- } else { //Register with address of variable on LHS; assertion:
Register contains address and global/local flag is set correctly
- opsize = GetOpSize(RHSItem, "MOV");
- retVal = PrintInstruction_Reg_Reg("MOV", opsize, "R", RHSItem.R,
0, 0, 0, "", "R", LHSItem.R, 1, 0, 0, ""); //MOV RHSItem.R, (LHSItem.R)
- if retVal != 0 { //Handle operands > 8 bytes
- if LHSItem.C != 0 {
- PrintInstruction_Reg_Reg("MOV", retVal, "R", RHSItem.C, 0,
0, 0, "", "R", LHSItem.C, 1, 0, 0, ""); //MOV RHSItem.C, (LHSItem.C)
- } else {
- PrintInstruction_Reg_Reg("MOV", retVal, "R", RHSItem.C, 0,
0, 0, "", "R", LHSItem.R, 1, 8, 0, ""); //MOV RHSItem.C, 8(LHSItem.R)
- }
- }
- }
- FreeRegisterIfRequired(LHSItem);
- FreeRegisterIfRequired(RHSItem);
-}
+ var opsize uint64
+ var retVal uint64
+ if LHSItem.PtrType == 0 {
+ SymbolTableError("Cannot assign a pointer type to a value", "", "type:",
LHSItem.Itemtype.Name)
+ }
+ if RHSItem.PtrType == 1 {
+ SymbolTableError("Cannot assign a pointer's address to a
pointer", "", "type:", LHSItem.Itemtype.Name)
+ }
+ if LHSItem.Itemtype != RHSItem.Itemtype {
+ SymbolTableError("Incompatible pointer types:",
LHSItem.Itemtype.Name, "and", RHSItem.Itemtype.Name)
+ }
+
+ if RHSItem.Mode == libgogo.MODE_VAR { //Var RHS => load address to
register
+ MakeRegistered(RHSItem, 1) //LEA RHSItem.A(SB), to be RHSItem.R
+ } //Reg RHS
+ if LHSItem.Mode == libgogo.MODE_VAR { //Variable on LHS
+ PrintInstruction_Reg_Var("MOV", "R", RHSItem.R, "R", RHSItem.C, LHSItem)
//MOV RHSItem.R, LHSItem.A(SB)
+ } else { //Register with address of variable on LHS; assertion: Register
contains address and global/local flag is set correctly
+ opsize = GetOpSize(RHSItem, "MOV")
+ retVal = PrintInstruction_Reg_Reg("MOV", opsize, "R", RHSItem.R, 0, 0,
0, "", "R", LHSItem.R, 1, 0, 0, "") //MOV RHSItem.R, (LHSItem.R)
+ if retVal != 0
{
//Handle operands > 8 bytes
+ if LHSItem.C != 0 {
+ PrintInstruction_Reg_Reg("MOV", retVal, "R", RHSItem.C, 0, 0,
0, "", "R", LHSItem.C, 1, 0, 0, "") //MOV RHSItem.C, (LHSItem.C)
+ } else {
+ PrintInstruction_Reg_Reg("MOV", retVal, "R", RHSItem.C, 0, 0,
0, "", "R", LHSItem.R, 1, 8, 0, "") //MOV RHSItem.C, 8(LHSItem.R)
+ }
+ }
+ }
+ FreeRegisterIfRequired(LHSItem)
+ FreeRegisterIfRequired(RHSItem)
+}
=======================================
--- /src/gen-cond.go Tue Aug 17 09:58:38 2010
+++ /src/gen-cond.go Wed Aug 18 10:20:16 2010
@@ -16,13 +16,13 @@
// Internally using the asm version for the final formatting.
//
func PrintJumpWrapped(jump string, ed *ExpressionDescriptor, global
uint64, localBranch uint64, suffix string) {
- var labelString string;
- if global == 0 {
- labelString = GetGlobLabel(ed, suffix);
- } else {
- labelString = GetSubLabel(ed, localBranch, suffix);
- }
- PrintJump(jump, labelString);
+ var labelString string
+ if global == 0 {
+ labelString = GetGlobLabel(ed, suffix)
+ } else {
+ labelString = GetSubLabel(ed, localBranch, suffix)
+ }
+ PrintJump(jump, labelString)
}

//
@@ -30,13 +30,13 @@
// Internally using the asm version for the final formatting.
//
func PrintLabelWrapped(ed *ExpressionDescriptor, global uint64,
localBranch uint64, suffix string) {
- var labelString string;
- if global == 0 {
- labelString = GetGlobLabel(ed, suffix);
- } else {
- labelString = GetSubLabel(ed, localBranch, suffix);
- }
- PrintLabel(labelString);
+ var labelString string
+ if global == 0 {
+ labelString = GetGlobLabel(ed, suffix)
+ } else {
+ labelString = GetSubLabel(ed, localBranch, suffix)
+ }
+ PrintLabel(labelString)
}

//
@@ -44,89 +44,89 @@
// by GetSubLabel().
//
func GenerateSubLabel(ed *ExpressionDescriptor, i uint64, label string)
string {
- var str string = "";
- var tmpStr string;
-
- var depth uint64;
- var labelnr uint64;
- var stacksize uint64;
-
- libgogo.StringAppend(&str, ed.CurFile);
- libgogo.StringAppend(&str, "_");
- tmpStr = libgogo.IntToString(ed.CurLine);
- libgogo.StringAppend(&str, tmpStr);
- libgogo.StringAppend(&str, "_");
-
- if i == 0 {
- stacksize = libgogo.GetStackItemCount(&ed.FS);
- if stacksize == 0 {
- tmpStr = libgogo.IntToString(ed.IncCnt);
- labelnr = ed.IncCnt;
- depth = ed.ExpressionDepth;
- ed.IncCnt = ed.IncCnt + 1;
- libgogo.Push(&ed.FS, labelnr);
- libgogo.Push(&ed.FDepthS, depth);
- } else {
- labelnr = libgogo.Peek(&ed.FS);
- depth = libgogo.Peek(&ed.FDepthS);
- if ed.ExpressionDepth > depth {
- labelnr = ed.IncCnt;
- depth = ed.ExpressionDepth;
- libgogo.Push(&ed.FS, labelnr);
- libgogo.Push(&ed.FDepthS, depth);
- ed.IncCnt = ed.IncCnt +1;
- }
- }
- tmpStr = libgogo.IntToString(labelnr);
- } else {
- stacksize = libgogo.GetStackItemCount(&ed.TS);
- if stacksize == 0 {
- tmpStr = libgogo.IntToString(ed.IncCnt);
- labelnr = ed.IncCnt;
- depth = ed.ExpressionDepth;
- ed.IncCnt = ed.IncCnt + 1;
- libgogo.Push(&ed.TS, labelnr);
- libgogo.Push(&ed.TDepthS, depth);
- } else {
- labelnr = libgogo.Peek(&ed.TS);
- depth = libgogo.Peek(&ed.TDepthS);
- if ed.ExpressionDepth > depth {
- labelnr = ed.IncCnt;
- depth = ed.ExpressionDepth;
- libgogo.Push(&ed.TS, labelnr);
- libgogo.Push(&ed.TDepthS, depth);
- ed.IncCnt = ed.IncCnt + 1;
- }
- }
- tmpStr = libgogo.IntToString(labelnr);
- }
-
-/*
- if i == 0 {
- if ed.F == 0 {
- tmpStr = libgogo.IntToString(ed.IncCnt);
- ed.F = ed.IncCnt;
- ed.FDepth = ed.ExpressionDepth+1;
- ed.IncCnt = ed.IncCnt + 1;
- } else {
- tmpStr = libgogo.IntToString(ed.F);
- }
- } else {
- if ed.T == 0 {
- tmpStr = libgogo.IntToString(ed.IncCnt);
- ed.T = ed.IncCnt;
- ed.TDepth = ed.ExpressionDepth+1;
- ed.IncCnt = ed.IncCnt + 1;
- } else {
- tmpStr = libgogo.IntToString(ed.T);
- }
- }
-*/
- libgogo.StringAppend(&str, tmpStr);
-
- libgogo.StringAppend(&str, "_");
- libgogo.StringAppend(&str, label);
- return str;
+ var str string = ""
+ var tmpStr string
+
+ var depth uint64
+ var labelnr uint64
+ var stacksize uint64
+
+ libgogo.StringAppend(&str, ed.CurFile)
+ libgogo.StringAppend(&str, "_")
+ tmpStr = libgogo.IntToString(ed.CurLine)
+ libgogo.StringAppend(&str, tmpStr)
+ libgogo.StringAppend(&str, "_")
+
+ if i == 0 {
+ stacksize = libgogo.GetStackItemCount(&ed.FS)
+ if stacksize == 0 {
+ tmpStr = libgogo.IntToString(ed.IncCnt)
+ labelnr = ed.IncCnt
+ depth = ed.ExpressionDepth
+ ed.IncCnt = ed.IncCnt + 1
+ libgogo.Push(&ed.FS, labelnr)
+ libgogo.Push(&ed.FDepthS, depth)
+ } else {
+ labelnr = libgogo.Peek(&ed.FS)
+ depth = libgogo.Peek(&ed.FDepthS)
+ if ed.ExpressionDepth > depth {
+ labelnr = ed.IncCnt
+ depth = ed.ExpressionDepth
+ libgogo.Push(&ed.FS, labelnr)
+ libgogo.Push(&ed.FDepthS, depth)
+ ed.IncCnt = ed.IncCnt + 1
+ }
+ }
+ tmpStr = libgogo.IntToString(labelnr)
+ } else {
+ stacksize = libgogo.GetStackItemCount(&ed.TS)
+ if stacksize == 0 {
+ tmpStr = libgogo.IntToString(ed.IncCnt)
+ labelnr = ed.IncCnt
+ depth = ed.ExpressionDepth
+ ed.IncCnt = ed.IncCnt + 1
+ libgogo.Push(&ed.TS, labelnr)
+ libgogo.Push(&ed.TDepthS, depth)
+ } else {
+ labelnr = libgogo.Peek(&ed.TS)
+ depth = libgogo.Peek(&ed.TDepthS)
+ if ed.ExpressionDepth > depth {
+ labelnr = ed.IncCnt
+ depth = ed.ExpressionDepth
+ libgogo.Push(&ed.TS, labelnr)
+ libgogo.Push(&ed.TDepthS, depth)
+ ed.IncCnt = ed.IncCnt + 1
+ }
+ }
+ tmpStr = libgogo.IntToString(labelnr)
+ }
+
+ /*
+ if i == 0 {
+ if ed.F == 0 {
+ tmpStr = libgogo.IntToString(ed.IncCnt);
+ ed.F = ed.IncCnt;
+ ed.FDepth = ed.ExpressionDepth+1;
+ ed.IncCnt = ed.IncCnt + 1;
+ } else {
+ tmpStr = libgogo.IntToString(ed.F);
+ }
+ } else {
+ if ed.T == 0 {
+ tmpStr = libgogo.IntToString(ed.IncCnt);
+ ed.T = ed.IncCnt;
+ ed.TDepth = ed.ExpressionDepth+1;
+ ed.IncCnt = ed.IncCnt + 1;
+ } else {
+ tmpStr = libgogo.IntToString(ed.T);
+ }
+ }
+ */
+ libgogo.StringAppend(&str, tmpStr)
+
+ libgogo.StringAppend(&str, "_")
+ libgogo.StringAppend(&str, label)
+ return str
}

//
@@ -134,80 +134,80 @@
// (=Global Label + True|False Branch)
//
func GetSubLabel(ed *ExpressionDescriptor, i uint64, label string) string {
- var str string = "";
- var tmpStr string;
- var labelnr uint64;
-
- libgogo.StringAppend(&str, ed.CurFile);
- libgogo.StringAppend(&str, "_");
- tmpStr = libgogo.IntToString(ed.CurLine);
- libgogo.StringAppend(&str, tmpStr);
- libgogo.StringAppend(&str, "_");
-
- if i == 0 {
- labelnr = libgogo.Peek(&ed.FS);
- tmpStr = libgogo.IntToString(labelnr);
- //tmpStr = libgogo.IntToString(ed.F);
- } else {
- labelnr = libgogo.Peek(&ed.TS);
- tmpStr = libgogo.IntToString(labelnr);
- //tmpStr = libgogo.IntToString(ed.T);
- }
- libgogo.StringAppend(&str, tmpStr);
-
- libgogo.StringAppend(&str, "_");
- libgogo.StringAppend(&str, label);
- return str;
+ var str string = ""
+ var tmpStr string
+ var labelnr uint64
+
+ libgogo.StringAppend(&str, ed.CurFile)
+ libgogo.StringAppend(&str, "_")
+ tmpStr = libgogo.IntToString(ed.CurLine)
+ libgogo.StringAppend(&str, tmpStr)
+ libgogo.StringAppend(&str, "_")
+
+ if i == 0 {
+ labelnr = libgogo.Peek(&ed.FS)
+ tmpStr = libgogo.IntToString(labelnr)
+ //tmpStr = libgogo.IntToString(ed.F);
+ } else {
+ labelnr = libgogo.Peek(&ed.TS)
+ tmpStr = libgogo.IntToString(labelnr)
+ //tmpStr = libgogo.IntToString(ed.T);
+ }
+ libgogo.StringAppend(&str, tmpStr)
+
+ libgogo.StringAppend(&str, "_")
+ libgogo.StringAppend(&str, label)
+ return str
}

//
// Returns the global label that is represented by an ExpressionDescriptor.
//
func GetGlobLabel(ed *ExpressionDescriptor, label string) string {
- var str string = "";
- var tmpStr string;
- libgogo.StringAppend(&str, ed.CurFile);
- libgogo.StringAppend(&str, "_");
- tmpStr = libgogo.IntToString(ed.CurLine);
- libgogo.StringAppend(&str, tmpStr);
- libgogo.StringAppend(&str, "_");
- libgogo.StringAppend(&str, label);
- return str;
+ var str string = ""
+ var tmpStr string
+ libgogo.StringAppend(&str, ed.CurFile)
+ libgogo.StringAppend(&str, "_")
+ tmpStr = libgogo.IntToString(ed.CurLine)
+ libgogo.StringAppend(&str, tmpStr)
+ libgogo.StringAppend(&str, "_")
+ libgogo.StringAppend(&str, label)
+ return str
}

//
// Returns the jump expression that represents a given conditional
//
func GetJump(condition uint64, invert uint64) string {
- var jmp string = "J?";
-
- if invert != 0 { // invert logic if necessary (T|F jump)
- if (condition == 0) || (condition == 2) || (condition == 4) {
- condition = condition + 1;
- } else {
- condition = condition - 1;
- }
- }
-
- // Information taken from go/src/cmd/6a/<file>
- if condition == libgogo.REL_EQ {
- jmp = "JE"; // lex.c:466
- }
- if condition == libgogo.REL_NEQ {
- jmp = "JNE"; // lex.c:468
- }
- if condition == libgogo.REL_GT {
- jmp = "JG"; // lex.c:494
- }
- if condition == libgogo.REL_GTE {
- jmp = "JGE"; // lex.c:489
- }
- if condition == libgogo.REL_LT {
- jmp = "JL"; // lex.c:487
- }
- if condition == libgogo.REL_LTE {
- jmp = "JLE"; // lex.c:491
- }
-
- return jmp;
-}
+ var jmp string = "J?"
+
+ if invert != 0 { // invert logic if necessary (T|F jump)
+ if (condition == 0) || (condition == 2) || (condition == 4) {
+ condition = condition + 1
+ } else {
+ condition = condition - 1
+ }
+ }
+
+ // Information taken from go/src/cmd/6a/<file>
+ if condition == libgogo.REL_EQ {
+ jmp = "JE" // lex.c:466
+ }
+ if condition == libgogo.REL_NEQ {
+ jmp = "JNE" // lex.c:468
+ }
+ if condition == libgogo.REL_GT {
+ jmp = "JG" // lex.c:494
+ }
+ if condition == libgogo.REL_GTE {
+ jmp = "JGE" // lex.c:489
+ }
+ if condition == libgogo.REL_LT {
+ jmp = "JL" // lex.c:487
+ }
+ if condition == libgogo.REL_LTE {
+ jmp = "JLE" // lex.c:491
+ }
+
+ return jmp
+}
=======================================
--- /src/gen-const.go Tue Aug 17 09:58:38 2010
+++ /src/gen-const.go Wed Aug 18 10:20:16 2010
@@ -7,67 +7,67 @@
import "./libgogo/_obj/libgogo"

func CreateIntegerConstant(value uint64, item *libgogo.Item) {
- if (value <= 255) { //Value fits into byte_t
- libgogo.SetItem(item, libgogo.MODE_CONST, byte_t, 0, value, 0, 0);
//Constant item
- } else { //Value does not fit into byte_t
- libgogo.SetItem(item, libgogo.MODE_CONST, uint64_t, 0, value, 0,
0); //Constant item
- }
+ if value <= 255 { //Value fits into byte_t
+ libgogo.SetItem(item, libgogo.MODE_CONST, byte_t, 0, value, 0, 0)
//Constant item
+ } else { //Value does not fit into byte_t
+ libgogo.SetItem(item, libgogo.MODE_CONST, uint64_t, 0, value, 0, 0)
//Constant item
+ }
}

func CreateStringConstant(str string, item *libgogo.Item) {
- var boolFlag uint64;
- var doneFlag uint64;
- var tempType *libgogo.TypeDesc;
- var tempByteArray *libgogo.ObjectDesc;
- var tempString *libgogo.ObjectDesc;
- var startAddress uint64;
- var LHSItem *libgogo.Item;
- var RHSItem *libgogo.Item;
- var s string = "String buffer start ('";
-
- boolFlag = libgogo.StringLength(str); //Compute length
- tempType = libgogo.NewType("byteArray", ".internal", 0, boolFlag + 1,
byte_t); //Create byte array type of according length (including trailing
0) to be able to address the characters
- tempByteArray = libgogo.NewObject("tempByteArray", ".internal",
libgogo.CLASS_VAR); //Create object of previously declared byte array type
- tempByteArray.ObjType = tempType;
- libgogo.AppendObject(tempByteArray, GlobalObjects); //Add byte array
to global objects
- startAddress = libgogo.GetObjectOffset(tempByteArray, GlobalObjects);
//Calculate buffer start address
-
- SwitchOutputToDataSegment(); //Place content of byte array in data
segment
- libgogo.StringAppend(&s, str);
- libgogo.StringAppend(&s, "')");
- GenerateComment(s); //Output string in comment
- for doneFlag = 0; doneFlag < boolFlag; doneFlag = doneFlag + 1 { //Set
values in data segment accordingly
- PutDataByte(startAddress + doneFlag, str[doneFlag]);
- }
- PutDataByte(startAddress + doneFlag, 0); //Add trailing 0
- GenerateComment("String buffer end");
- //SwitchOutputToCodeSegment(); //Reset to default output
-
- tempString = libgogo.NewObject("tempString", ".internal",
libgogo.CLASS_VAR); //Create object for actual string
- tempString.ObjType = string_t;
- libgogo.AppendObject(tempString, GlobalObjects); //Add string to
global objects
-
- SwitchOutputToInitCodeSegment(); //Initialize strings globally
- GenerateComment("Assign byte buffer to new string constant start");
- LHSItem = libgogo.NewItem();
- VariableObjectDescToItem(tempString, LHSItem, 1); //Global variable
- LHSItem.Itemtype = byte_t; //Set appropriate type for byte (array)
pointer
- LHSItem.PtrType = 1;
- RHSItem = libgogo.NewItem();
- VariableObjectDescToItem(tempByteArray, RHSItem, 1); //Global variable
- RHSItem.Itemtype = byte_t; //Set appropriate type for byte (array) to
be pointed at
- GenerateAssignment(LHSItem, RHSItem, 1); //tempString{first qword} =
&tempByteArray
- GenerateComment("Assign byte buffer to new string constant end");
- GenerateComment("Assign string length to new string constant start");
- LHSItem = libgogo.NewItem();
- VariableObjectDescToItem(tempString, LHSItem, 1); //Global variable
- LHSItem.A = LHSItem.A + 8; //Access second qword of string to place
length in there
- LHSItem.Itemtype = uint64_t; //Set appropriate type for string length
- RHSItem = libgogo.NewItem();
- libgogo.SetItem(RHSItem, libgogo.MODE_CONST, uint64_t, 0, boolFlag, 0,
0); //Constant item containing the length of the string
- GenerateAssignment(LHSItem, RHSItem, 0); //tempString{second qword} =
boolFlag (string length)
- GenerateComment("Assign string length to new string constant end");
- SwitchOutputToCodeSegment(); //Reset to default output
-
- VariableObjectDescToItem(tempString, item, 1); //Global variable to
return (reference to properly initialized, global string)
-}
+ var boolFlag uint64
+ var doneFlag uint64
+ var tempType *libgogo.TypeDesc
+ var tempByteArray *libgogo.ObjectDesc
+ var tempString *libgogo.ObjectDesc
+ var startAddress uint64
+ var LHSItem *libgogo.Item
+ var RHSItem *libgogo.Item
+ var s string = "String buffer start ('"
+
+ boolFlag =
libgogo.StringLength(str)
//Compute length
+ tempType = libgogo.NewType("byteArray", ".internal", 0, boolFlag+1,
byte_t) //Create byte array type of according length (including
trailing 0) to be able to address the characters
+ tempByteArray = libgogo.NewObject("tempByteArray", ".internal",
libgogo.CLASS_VAR) //Create object of previously declared byte array type
+ tempByteArray.ObjType = tempType
+ libgogo.AppendObject(tempByteArray, GlobalObjects)
//Add byte array to global objects
+ startAddress = libgogo.GetObjectOffset(tempByteArray, GlobalObjects)
//Calculate buffer start address
+
+ SwitchOutputToDataSegment() //Place content of byte array in data segment
+ libgogo.StringAppend(&s, str)
+ libgogo.StringAppend(&s, "')")
+ GenerateComment(s) //Output
string in comment
+ for doneFlag = 0; doneFlag < boolFlag; doneFlag = doneFlag + 1 { //Set
values in data segment accordingly
+ PutDataByte(startAddress+doneFlag, str[doneFlag])
+ }
+ PutDataByte(startAddress+doneFlag, 0) //Add trailing 0
+ GenerateComment("String buffer end")
+ //SwitchOutputToCodeSegment(); //Reset to default output
+
+ tempString = libgogo.NewObject("tempString", ".internal",
libgogo.CLASS_VAR) //Create object for actual string
+ tempString.ObjType = string_t
+ libgogo.AppendObject(tempString, GlobalObjects) //Add string to global
objects
+
+ SwitchOutputToInitCodeSegment() //Initialize strings globally
+ GenerateComment("Assign byte buffer to new string constant start")
+ LHSItem = libgogo.NewItem()
+ VariableObjectDescToItem(tempString, LHSItem, 1) //Global variable
+ LHSItem.Itemtype = byte_t //Set appropriate type
for byte (array) pointer
+ LHSItem.PtrType = 1
+ RHSItem = libgogo.NewItem()
+ VariableObjectDescToItem(tempByteArray, RHSItem, 1) //Global variable
+ RHSItem.Itemtype = byte_t //Set appropriate
type for byte (array) to be pointed at
+ GenerateAssignment(LHSItem, RHSItem, 1) //tempString{first
qword} = &tempByteArray
+ GenerateComment("Assign byte buffer to new string constant end")
+ GenerateComment("Assign string length to new string constant start")
+ LHSItem = libgogo.NewItem()
+ VariableObjectDescToItem(tempString, LHSItem, 1) //Global variable
+ LHSItem.A = LHSItem.A + 8 //Access second qword of
string to place length in there
+ LHSItem.Itemtype = uint64_t //Set appropriate type
for string length
+ RHSItem = libgogo.NewItem()
+ libgogo.SetItem(RHSItem, libgogo.MODE_CONST, uint64_t, 0, boolFlag, 0, 0)
//Constant item containing the length of the string
+ GenerateAssignment(LHSItem, RHSItem, 0)
//tempString{second qword} = boolFlag (string length)
+ GenerateComment("Assign string length to new string constant end")
+ SwitchOutputToCodeSegment() //Reset to default output
+
+ VariableObjectDescToItem(tempString, item, 1) //Global variable to return
(reference to properly initialized, global string)
+}
=======================================
--- /src/gen-expr.go Tue Aug 17 09:58:38 2010
+++ /src/gen-expr.go Wed Aug 18 10:20:16 2010
@@ -11,193 +11,193 @@
import "./libgogo/_obj/libgogo"

func SwapExpressionBranches(ed *ExpressionDescriptor) {
- var stacksize uint64;
- var depth uint64;
- var tvalue uint64 = 0;
- var fvalue uint64 = 0;
-
- stacksize = libgogo.GetStackItemCount(&ed.FS);
- if stacksize > 0 {
- depth = libgogo.Peek(&ed.FDepthS);
- if depth >= ed.ExpressionDepth {
- fvalue = libgogo.Pop(&ed.FS);
- }
- }
-
- stacksize = libgogo.GetStackItemCount(&ed.TS);
- if stacksize > 0 {
- depth = libgogo.Peek(&ed.TDepthS);
- if depth >= ed.ExpressionDepth {
- tvalue = libgogo.Pop(&ed.TS);
- }
- }
-
- if tvalue != 0 {
- libgogo.Push(&ed.FS, tvalue);
- }
- if fvalue != 0 {
- libgogo.Push(&ed.TS, fvalue);
- }
+ var stacksize uint64
+ var depth uint64
+ var tvalue uint64 = 0
+ var fvalue uint64 = 0
+
+ stacksize = libgogo.GetStackItemCount(&ed.FS)
+ if stacksize > 0 {
+ depth = libgogo.Peek(&ed.FDepthS)
+ if depth >= ed.ExpressionDepth {
+ fvalue = libgogo.Pop(&ed.FS)
+ }
+ }
+
+ stacksize = libgogo.GetStackItemCount(&ed.TS)
+ if stacksize > 0 {
+ depth = libgogo.Peek(&ed.TDepthS)
+ if depth >= ed.ExpressionDepth {
+ tvalue = libgogo.Pop(&ed.TS)
+ }
+ }
+
+ if tvalue != 0 {
+ libgogo.Push(&ed.FS, tvalue)
+ }
+ if fvalue != 0 {
+ libgogo.Push(&ed.TS, fvalue)
+ }
}

//
//
//
func SetExpressionDescriptor(ed *ExpressionDescriptor, labelPrefix string)
{
- var strLen uint64;
- var singleChar byte;
- var i uint64;
- ed.CurFile = labelPrefix;
- strLen = libgogo.StringLength(fileInfo[curFileIndex].filename);
- for i=0;(i<strLen) &&
(fileInfo[curFileIndex].filename[i] != '.');i=i+1 {
- singleChar = fileInfo[curFileIndex].filename[i];
- if ((singleChar>=48) && (singleChar<=57)) || ((singleChar>=65) &&
(singleChar<=90)) || ((singleChar>=97) && (singleChar<=122)) {
- libgogo.CharAppend(&ed.CurFile,
fileInfo[curFileIndex].filename[i]);
- } else {
- libgogo.CharAppend(&ed.CurFile, '_');
- }
- }
- ed.ExpressionDepth = 0;
- ed.CurLine = fileInfo[curFileIndex].lineCounter;
- ed.IncCnt = 1;
- ed.T = 0;
- ed.F = 0;
- ed.TDepth = 0;
- ed.FDepth = 0;
- ed.Not = 0;
-
- libgogo.InitializeStack(&ed.TS);
- libgogo.InitializeStack(&ed.FS);
- libgogo.InitializeStack(&ed.TDepthS);
- libgogo.InitializeStack(&ed.FDepthS);
+ var strLen uint64
+ var singleChar byte
+ var i uint64
+ ed.CurFile = labelPrefix
+ strLen = libgogo.StringLength(fileInfo[curFileIndex].filename)
+ for i = 0; (i < strLen) && (fileInfo[curFileIndex].filename[i] != '.'); i
= i + 1 {
+ singleChar = fileInfo[curFileIndex].filename[i]
+ if ((singleChar >= 48) && (singleChar <= 57)) || ((singleChar >= 65) &&
(singleChar <= 90)) || ((singleChar >= 97) && (singleChar <= 122)) {
+ libgogo.CharAppend(&ed.CurFile, fileInfo[curFileIndex].filename[i])
+ } else {
+ libgogo.CharAppend(&ed.CurFile, '_')
+ }
+ }
+ ed.ExpressionDepth = 0
+ ed.CurLine = fileInfo[curFileIndex].lineCounter
+ ed.IncCnt = 1
+ ed.T = 0
+ ed.F = 0
+ ed.TDepth = 0
+ ed.FDepth = 0
+ ed.Not = 0
+
+ libgogo.InitializeStack(&ed.TS)
+ libgogo.InitializeStack(&ed.FS)
+ libgogo.InitializeStack(&ed.TDepthS)
+ libgogo.InitializeStack(&ed.FDepthS)
}

//
// Called by parser (ParseSimpleExpression)
//
func GenerateSimpleExpressionArith(item1 *libgogo.Item, item2
*libgogo.Item, op uint64) {
- if Compile != 0 {
- if (item1.Itemtype != byte_t) && (item1.Itemtype != uint64_t) {
- SymbolTableError("Invalid left operand type
for", "", "addition/subtraction:", item1.Itemtype.Name);
- }
- if (item2.Itemtype != byte_t) && (item2.Itemtype != uint64_t) {
- SymbolTableError("Invalid right operand type
for", "", "addition/subtraction:", item2.Itemtype.Name);
- }
- if op == TOKEN_ARITH_PLUS { //Add
- AddSubInstruction("ADD", item1, item2, item1.A + item2.A, 0);
- } else { //Subtract
- AddSubInstruction("SUB", item1, item2, item1.A - item2.A, 0);
- }
- }
+ if Compile != 0 {
+ if (item1.Itemtype != byte_t) && (item1.Itemtype != uint64_t) {
+ SymbolTableError("Invalid left operand type
for", "", "addition/subtraction:", item1.Itemtype.Name)
+ }
+ if (item2.Itemtype != byte_t) && (item2.Itemtype != uint64_t) {
+ SymbolTableError("Invalid right operand type
for", "", "addition/subtraction:", item2.Itemtype.Name)
+ }
+ if op == TOKEN_ARITH_PLUS { //Add
+ AddSubInstruction("ADD", item1, item2, item1.A+item2.A, 0)
+ } else { //Subtract
+ AddSubInstruction("SUB", item1, item2, item1.A-item2.A, 0)
+ }
+ }
}

//
// Called by parser (ParseTerm)
//
func GenerateTermArith(item1 *libgogo.Item, item2 *libgogo.Item, op
uint64) {
- if Compile != 0 {
- if (op == TOKEN_ARITH_DIV) || op == (TOKEN_ARITH_MUL) {
- if (item1.Itemtype != byte_t) && (item1.Itemtype != uint64_t) {
- SymbolTableError("Invalid left operand type
for", "", "multiplication/division:", item1.Itemtype.Name);
- }
- if (item2.Itemtype != byte_t) && (item2.Itemtype != uint64_t) {
- SymbolTableError("Invalid right operand type
for", "", "multiplication/division:", item2.Itemtype.Name);
- }
- }
- if op == TOKEN_ARITH_DIV { // Division
- if item2.Mode == libgogo.MODE_CONST {
- if item2.A == 0 {
- GenErrorWeak("Division by zero.");
- }
- }
- if item2.A != 0 { //Avoid division by zero for constvalue
parameter
- DivMulInstruction("DIV", item1, item2, item1.A / item2.A,
0);
- } else {
- DivMulInstruction("DIV", item1, item2, 0, 0);
- }
- }
- if op == TOKEN_ARITH_MUL { // Multiplication
- DivMulInstruction("MUL", item1, item2, item1.A * item2.A, 0);
- }
- }
+ if Compile != 0 {
+ if (op == TOKEN_ARITH_DIV) || op == (TOKEN_ARITH_MUL) {
+ if (item1.Itemtype != byte_t) && (item1.Itemtype != uint64_t) {
+ SymbolTableError("Invalid left operand type
for", "", "multiplication/division:", item1.Itemtype.Name)
+ }
+ if (item2.Itemtype != byte_t) && (item2.Itemtype != uint64_t) {
+ SymbolTableError("Invalid right operand type
for", "", "multiplication/division:", item2.Itemtype.Name)
+ }
+ }
+ if op == TOKEN_ARITH_DIV { // Division
+ if item2.Mode == libgogo.MODE_CONST {
+ if item2.A == 0 {
+ GenErrorWeak("Division by zero.")
+ }
+ }
+ if item2.A != 0 { //Avoid division by zero for constvalue parameter
+ DivMulInstruction("DIV", item1, item2, item1.A/item2.A, 0)
+ } else {
+ DivMulInstruction("DIV", item1, item2, 0, 0)
+ }
+ }
+ if op == TOKEN_ARITH_MUL { // Multiplication
+ DivMulInstruction("MUL", item1, item2, item1.A*item2.A, 0)
+ }
+ }
}

func GenerateRelative(item *libgogo.Item, op uint64, ed
*ExpressionDescriptor) {
- var labelString string;
- var jmp string;
- var depth uint64;
- var stacksize uint64;
-
- if Compile != 0 {
- if item.Mode != libgogo.MODE_COND {
- GenErrorWeak("Can use relative operators only with
conditionals.");
- }
- if op == TOKEN_REL_AND {
- labelString = GenerateSubLabel(ed,0 /*negative*/,"END");
- if ed.Not == 0 {
- jmp = GetJump(item.C, 1);
- } else {
- ed.Not = 0;
- stacksize = libgogo.GetStackItemCount(&ed.TS);
- if stacksize > 0 {
- depth = libgogo.Peek(&ed.TDepthS);
- if depth >= ed.ExpressionDepth {
- labelString = GenerateSubLabel(ed,1,"END");
- jmp = GetJump(item.C, 0);
- SwapExpressionBranches(ed);
- }
- } else {
- jmp = GetJump(item.C,0);
- }
- }
- PrintJump(jmp, labelString);
-
- stacksize = libgogo.GetStackItemCount(&ed.TS);
- if stacksize > 0 {
- depth = libgogo.Peek(&ed.TDepthS);
- if depth >= ed.ExpressionDepth {
- PrintLabelWrapped(ed, 1 /*local*/, 1
/*positive*/, "END");
- libgogo.Pop(&ed.TS);
- libgogo.Pop(&ed.TDepthS);
- }
- }
- } else {
- if op == TOKEN_REL_OR {
- labelString = GenerateSubLabel(ed,1,"END");
- if ed.Not == 0 {
- jmp = GetJump(item.C, 0);
- } else {
- ed.Not = 0;
- stacksize = libgogo.GetStackItemCount(&ed.FS);
- if stacksize > 0 {
- depth = libgogo.Peek(&ed.FDepthS);
- if depth >= ed.ExpressionDepth {
-
- labelString = GenerateSubLabel(ed,0,"END");
- jmp = GetJump(item.C, 1);
- SwapExpressionBranches(ed);
- }
- } else {
- jmp = GetJump(item.C,1);
- }
- }
- PrintJump(jmp, labelString);
- stacksize = libgogo.GetStackItemCount(&ed.FS);
- if stacksize > 0 {
- depth = libgogo.Peek(&ed.FDepthS);
- if depth >= ed.ExpressionDepth {
- PrintLabelWrapped(ed, 1 /*local*/, 0
/*negative*/, "END");
- libgogo.Pop(&ed.FS);
- libgogo.Pop(&ed.FDepthS);
- }
- }
- } else {
- GenErrorWeak("Relative AND or OR expected.");
- }
- }
- item.C =0;
- FreeRegisterIfRequired(item);
- }
+ var labelString string
+ var jmp string
+ var depth uint64
+ var stacksize uint64
+
+ if Compile != 0 {
+ if item.Mode != libgogo.MODE_COND {
+ GenErrorWeak("Can use relative operators only with conditionals.")
+ }
+ if op == TOKEN_REL_AND {
+ labelString = GenerateSubLabel(ed, 0 /*negative*/ , "END")
+ if ed.Not == 0 {
+ jmp = GetJump(item.C, 1)
+ } else {
+ ed.Not = 0
+ stacksize = libgogo.GetStackItemCount(&ed.TS)
+ if stacksize > 0 {
+ depth = libgogo.Peek(&ed.TDepthS)
+ if depth >= ed.ExpressionDepth {
+ labelString = GenerateSubLabel(ed, 1, "END")
+ jmp = GetJump(item.C, 0)
+ SwapExpressionBranches(ed)
+ }
+ } else {
+ jmp = GetJump(item.C, 0)
+ }
+ }
+ PrintJump(jmp, labelString)
+
+ stacksize = libgogo.GetStackItemCount(&ed.TS)
+ if stacksize > 0 {
+ depth = libgogo.Peek(&ed.TDepthS)
+ if depth >= ed.ExpressionDepth {
+ PrintLabelWrapped(ed, 1 /*local*/ , 1 /*positive*/ , "END")
+ libgogo.Pop(&ed.TS)
+ libgogo.Pop(&ed.TDepthS)
+ }
+ }
+ } else {
+ if op == TOKEN_REL_OR {
+ labelString = GenerateSubLabel(ed, 1, "END")
+ if ed.Not == 0 {
+ jmp = GetJump(item.C, 0)
+ } else {
+ ed.Not = 0
+ stacksize = libgogo.GetStackItemCount(&ed.FS)
+ if stacksize > 0 {
+ depth = libgogo.Peek(&ed.FDepthS)
+ if depth >= ed.ExpressionDepth {
+
+ labelString = GenerateSubLabel(ed, 0, "END")
+ jmp = GetJump(item.C, 1)
+ SwapExpressionBranches(ed)
+ }
+ } else {
+ jmp = GetJump(item.C, 1)
+ }
+ }
+ PrintJump(jmp, labelString)
+ stacksize = libgogo.GetStackItemCount(&ed.FS)
+ if stacksize > 0 {
+ depth = libgogo.Peek(&ed.FDepthS)
+ if depth >= ed.ExpressionDepth {
+ PrintLabelWrapped(ed, 1 /*local*/ , 0 /*negative*/ , "END")
+ libgogo.Pop(&ed.FS)
+ libgogo.Pop(&ed.FDepthS)
+ }
+ }
+ } else {
+ GenErrorWeak("Relative AND or OR expected.")
+ }
+ }
+ item.C = 0
+ FreeRegisterIfRequired(item)
+ }
}

//
@@ -205,173 +205,172 @@
// Note: This function can only handle operands with a maximum of 8 bytes
in size
//
func GenerateComparison(item1 *libgogo.Item, item2 *libgogo.Item, op
uint64) {
- var opsize uint64;
- if Compile != 0 {
- // Type/Pointer checking
-
- //byte op byte = byte, byte op uint64 = uint64, uint64 op byte =
uint64, uint64 op uint64 = uint64
- if (item1.Itemtype == byte_t) && (item2.Itemtype == uint64_t) {
- if item1.Mode != libgogo.MODE_CONST { //No need to convert
constants, as their upper bits are already implicitly zeroed
- MakeRegistered(item1, item1.PtrType); //Implicitly convert
to uint64 by moving item1 to a register, thereby zeroing the upper bits if
necessary
- }
- item1.Itemtype = uint64_t;
- }
- if (item2.Itemtype == byte_t) && (item1.Itemtype == uint64_t) {
- if item2.Mode != libgogo.MODE_CONST { //No need to convert
constants, as their upper bits are already implicitly zeroed
- MakeRegistered(item2, item2.PtrType); //Implicitly convert
to uint64 by moving item2 to a register, thereby zeroing the upper bits if
necessary
- }
- item2.Itemtype = uint64_t;
- }
-
- if (item1.Itemtype != item2.Itemtype) && (item1.Itemtype !=
string_t) && (item2.Itemtype != string_t) {
- if (item1.PtrType == 1) && (item2.PtrType == 1) &&
((item1.Itemtype != nil) || (item2.Itemtype != nil)) {
- ;
- } else {
- GenErrorWeak("Can only compare variables of same type.");
- }
- }
- if (item1.Itemtype == string_t) || (item2.Itemtype == string_t) {
- if (item1.PtrType != 1) && (item2.PtrType != 1) {
- GenErrorWeak("Cannot compare string types.");
- }
- }
- if item1.PtrType == 1 {
- if item2.PtrType == 1 {
- if (op != TOKEN_EQUALS) && (op != TOKEN_NOTEQUAL) {
- GenErrorWeak("Can only compare '==' or '!=' on
pointers'");
- }
- if (item1.Mode == libgogo.MODE_CONST) || (item2.Mode ==
libgogo.MODE_CONST) {
- GenErrorWeak("Const pointers not allowed. This should
not happen.");
- }
- }
- }
- if (item2.PtrType == 1) && (item1.PtrType != 1) {
- GenErrorWeak("Non-pointer to pointer comparison.");
- }
- if (item1.PtrType ==1) && (item2.PtrType != 1) {
- GenErrorWeak("Pointer to non-pointer comparison.");
- }
-
- // Generate CMP statements depending on items
- if item1.Mode == libgogo.MODE_CONST {
- if item2.Mode == libgogo.MODE_CONST { // Values here, since
Ptrs are not allowed
- // Move constvalue to register and compare it against 0
- item1.Itemtype = bool_t;
- item1.A = GetConditionalBool(op, item1.A, item2.A);
- MakeRegistered(item1, 0);
- // CMP is handled by other if branch (free optimization,
yey)
- item2.A = 0;
- op = TOKEN_NOTEQUAL; // Force != for comparison against 0
- } else {
- MakeRegistered(item1, 0);
- if item2.Mode == libgogo.MODE_REG {
- opsize = GetOpSize(item2, "CMP");
- PrintInstruction_Reg_Reg("CMP", opsize, "R", item1.R,
0, 0, 0, "", "R", item2.R, 0, 0, 0, "");
- }
- if item2.Mode == libgogo.MODE_VAR {
- PrintInstruction_Reg_Var("CMP", "R", item1.R, "", 0,
item2);
- }
- }
- }
- if item1.Mode == libgogo.MODE_REG {
- DereferRegisterIfNecessary(item1);
- if item2.Mode == libgogo.MODE_CONST {
- PrintInstruction_Reg_Imm("CMP", 8, "R", item1.R, 0, 0,
0, "", item2.A);
- }
- if item2.Mode == libgogo.MODE_REG {
- DereferRegisterIfNecessary(item2);
- opsize = GetOpSize(item2, "CMP");
- PrintInstruction_Reg_Reg("CMP", opsize, "R", item1.R, 0,
0, 0, "", "R", item2.R, 0, 0, 0, "");
- }
- if item2.Mode == libgogo.MODE_VAR {
- PrintInstruction_Reg_Var("CMP", "R", item1.R, "", 0,
item2);
- }
- }
- if item1.Mode == libgogo.MODE_VAR {
- if item2.Mode == libgogo.MODE_CONST {
- PrintInstruction_Var_Imm("CMP", item1, item2.A);
- }
- if item2.Mode == libgogo.MODE_REG {
- DereferRegisterIfNecessary(item2);
- PrintInstruction_Var_Reg("CMP", item1, "R", item2.R, "",
0);
- }
- if item2.Mode == libgogo.MODE_VAR {
- MakeRegistered(item2, 0);
- PrintInstruction_Var_Reg("CMP", item1, "R", item2.R, "",
0);
- }
- }
-
- // Prepare item
- item1.Itemtype = bool_t;
- item1.Mode = libgogo.MODE_COND;
- if op == TOKEN_EQUALS {
- item1.C = libgogo.REL_EQ;
- }
- if op == TOKEN_NOTEQUAL {
- item1.C = libgogo.REL_NEQ;
- }
- if op == TOKEN_REL_LT {
- item1.C = libgogo.REL_LT;
- }
- if op == TOKEN_REL_LTOE {
- item1.C = libgogo.REL_LTE;
- }
- if op == TOKEN_REL_GT {
- item1.C = libgogo.REL_GT;
- }
- if op == TOKEN_REL_GTOE {
- item1.C = libgogo.REL_GTE;
- }
-
- FreeRegisterIfRequired(item1);
- FreeRegisterIfRequired(item2);
- }
+ var opsize uint64
+ if Compile != 0 {
+ // Type/Pointer checking
+
+ //byte op byte = byte, byte op uint64 = uint64, uint64 op byte = uint64,
uint64 op uint64 = uint64
+ if (item1.Itemtype == byte_t) && (item2.Itemtype == uint64_t) {
+ if item1.Mode != libgogo.MODE_CONST { //No need to convert constants,
as their upper bits are already implicitly zeroed
+ MakeRegistered(item1, item1.PtrType) //Implicitly convert to uint64 by
moving item1 to a register, thereby zeroing the upper bits if necessary
+ }
+ item1.Itemtype = uint64_t
+ }
+ if (item2.Itemtype == byte_t) && (item1.Itemtype == uint64_t) {
+ if item2.Mode != libgogo.MODE_CONST { //No need to convert constants,
as their upper bits are already implicitly zeroed
+ MakeRegistered(item2, item2.PtrType) //Implicitly convert to uint64 by
moving item2 to a register, thereby zeroing the upper bits if necessary
+ }
+ item2.Itemtype = uint64_t
+ }
+
+ if (item1.Itemtype != item2.Itemtype) && (item1.Itemtype != string_t) &&
(item2.Itemtype != string_t) {
+ if (item1.PtrType == 1) && (item2.PtrType == 1) && ((item1.Itemtype !=
nil) || (item2.Itemtype != nil)) {
+
+ } else {
+ GenErrorWeak("Can only compare variables of same type.")
+ }
+ }
+ if (item1.Itemtype == string_t) || (item2.Itemtype == string_t) {
+ if (item1.PtrType != 1) && (item2.PtrType != 1) {
+ GenErrorWeak("Cannot compare string types.")
+ }
+ }
+ if item1.PtrType == 1 {
+ if item2.PtrType == 1 {
+ if (op != TOKEN_EQUALS) && (op != TOKEN_NOTEQUAL) {
+ GenErrorWeak("Can only compare '==' or '!=' on pointers'")
+ }
+ if (item1.Mode == libgogo.MODE_CONST) || (item2.Mode ==
libgogo.MODE_CONST) {
+ GenErrorWeak("Const pointers not allowed. This should not happen.")
+ }
+ }
+ }
+ if (item2.PtrType == 1) && (item1.PtrType != 1) {
+ GenErrorWeak("Non-pointer to pointer comparison.")
+ }
+ if (item1.PtrType == 1) && (item2.PtrType != 1) {
+ GenErrorWeak("Pointer to non-pointer comparison.")
+ }
+
+ // Generate CMP statements depending on items
+ if item1.Mode == libgogo.MODE_CONST {
+ if item2.Mode == libgogo.MODE_CONST { // Values here, since Ptrs are
not allowed
+ // Move constvalue to register and compare it against 0
+ item1.Itemtype = bool_t
+ item1.A = GetConditionalBool(op, item1.A, item2.A)
+ MakeRegistered(item1, 0)
+ // CMP is handled by other if branch (free optimization, yey)
+ item2.A = 0
+ op = TOKEN_NOTEQUAL // Force != for comparison against 0
+ } else {
+ MakeRegistered(item1, 0)
+ if item2.Mode == libgogo.MODE_REG {
+ opsize = GetOpSize(item2, "CMP")
+ PrintInstruction_Reg_Reg("CMP", opsize, "R", item1.R, 0, 0,
0, "", "R", item2.R, 0, 0, 0, "")
+ }
+ if item2.Mode == libgogo.MODE_VAR {
+ PrintInstruction_Reg_Var("CMP", "R", item1.R, "", 0, item2)
+ }
+ }
+ }
+ if item1.Mode == libgogo.MODE_REG {
+ DereferRegisterIfNecessary(item1)
+ if item2.Mode == libgogo.MODE_CONST {
+ PrintInstruction_Reg_Imm("CMP", 8, "R", item1.R, 0, 0, 0, "", item2.A)
+ }
+ if item2.Mode == libgogo.MODE_REG {
+ DereferRegisterIfNecessary(item2)
+ opsize = GetOpSize(item2, "CMP")
+ PrintInstruction_Reg_Reg("CMP", opsize, "R", item1.R, 0, 0,
0, "", "R", item2.R, 0, 0, 0, "")
+ }
+ if item2.Mode == libgogo.MODE_VAR {
+ PrintInstruction_Reg_Var("CMP", "R", item1.R, "", 0, item2)
+ }
+ }
+ if item1.Mode == libgogo.MODE_VAR {
+ if item2.Mode == libgogo.MODE_CONST {
+ PrintInstruction_Var_Imm("CMP", item1, item2.A)
+ }
+ if item2.Mode == libgogo.MODE_REG {
+ DereferRegisterIfNecessary(item2)
+ PrintInstruction_Var_Reg("CMP", item1, "R", item2.R, "", 0)
+ }
+ if item2.Mode == libgogo.MODE_VAR {
+ MakeRegistered(item2, 0)
+ PrintInstruction_Var_Reg("CMP", item1, "R", item2.R, "", 0)
+ }
+ }
+
+ // Prepare item
+ item1.Itemtype = bool_t
+ item1.Mode = libgogo.MODE_COND
+ if op == TOKEN_EQUALS {
+ item1.C = libgogo.REL_EQ
+ }
+ if op == TOKEN_NOTEQUAL {
+ item1.C = libgogo.REL_NEQ
+ }
+ if op == TOKEN_REL_LT {
+ item1.C = libgogo.REL_LT
+ }
+ if op == TOKEN_REL_LTOE {
+ item1.C = libgogo.REL_LTE
+ }
+ if op == TOKEN_REL_GT {
+ item1.C = libgogo.REL_GT
+ }
+ if op == TOKEN_REL_GTOE {
+ item1.C = libgogo.REL_GTE
+ }
+
+ FreeRegisterIfRequired(item1)
+ FreeRegisterIfRequired(item2)
+ }
}

func GetConditionalBool(op uint64, val1 uint64, val2 uint64) uint64 {
- var ret uint64;
- if op == TOKEN_EQUALS {
- if val1 == val2 {
- ret = 1;
- } else {
- ret = 0;
- }
- }
- if op == TOKEN_NOTEQUAL {
- if val1 == val2 {
- ret = 0;
- } else {
- ret = 1;
- }
- }
- if op == TOKEN_REL_GTOE {
- if val1 >= val2 {
- ret = 1;
- } else {
- ret = 0;
- }
- }
- if op == TOKEN_REL_LTOE {
- if val1 <= val2 {
- ret = 1;
- } else {
- ret = 0;
- }
- }
- if op == TOKEN_REL_GT {
- if val1 > val2 {
- ret = 1;
- } else {
- ret = 0;
- }
- }
- if op == TOKEN_REL_LT {
- if val1 < val2 {
- ret = 1;
- } else {
- ret = 0;
- }
- }
- return ret;
-}
-
+ var ret uint64
+ if op == TOKEN_EQUALS {
+ if val1 == val2 {
+ ret = 1
+ } else {
+ ret = 0
+ }
+ }
+ if op == TOKEN_NOTEQUAL {
+ if val1 == val2 {
+ ret = 0
+ } else {
+ ret = 1
+ }
+ }
+ if op == TOKEN_REL_GTOE {
+ if val1 >= val2 {
+ ret = 1
+ } else {
+ ret = 0
+ }
+ }
+ if op == TOKEN_REL_LTOE {
+ if val1 <= val2 {
+ ret = 1
+ } else {
+ ret = 0
+ }
+ }
+ if op == TOKEN_REL_GT {
+ if val1 > val2 {
+ ret = 1
+ } else {
+ ret = 0
+ }
+ }
+ if op == TOKEN_REL_LT {
+ if val1 < val2 {
+ ret = 1
+ } else {
+ ret = 0
+ }
+ }
+ return ret
+}
=======================================
--- /src/gen-fcn.go Tue Aug 17 09:58:38 2010
+++ /src/gen-fcn.go Wed Aug 18 10:20:16 2010
@@ -7,123 +7,123 @@
import "./libgogo/_obj/libgogo"

func ZeroParameterCheck(FunctionCalled *libgogo.TypeDesc) {
- var FullFunctionName string = "";
- if FunctionCalled.Len == 0 { //Check if function expects parameters
- FullFunctionName = "";
- libgogo.StringAppend(&FullFunctionName,
FunctionCalled.PackageName);
- libgogo.CharAppend(&FullFunctionName, '.');
- libgogo.StringAppend(&FullFunctionName, FunctionCalled.Name);
- SymbolTableError("Function expects", "no", "parameters:",
FullFunctionName);
- }
+ var FullFunctionName string = ""
+ if FunctionCalled.Len == 0 { //Check if function expects parameters
+ FullFunctionName = ""
+ libgogo.StringAppend(&FullFunctionName, FunctionCalled.PackageName)
+ libgogo.CharAppend(&FullFunctionName, '.')
+ libgogo.StringAppend(&FullFunctionName, FunctionCalled.Name)
+ SymbolTableError("Function expects", "no", "parameters:",
FullFunctionName)
+ }
}

func ParameterCheck_More(FunctionCalled *libgogo.TypeDesc, paramCount
uint64) {
- var FullFunctionName string = "";
- var tempString string;
- if FunctionCalled.Len > paramCount { //Compare number of actual
parameters
- libgogo.StringAppend(&FullFunctionName,
FunctionCalled.PackageName);
- libgogo.CharAppend(&FullFunctionName, '.');
- libgogo.StringAppend(&FullFunctionName, FunctionCalled.Name);
- tempString = libgogo.IntToString(FunctionCalled.Len);
- SymbolTableError("Expecting", tempString, "parameters (more than
the actual ones) for function", FullFunctionName);
- }
+ var FullFunctionName string = ""
+ var tempString string
+ if FunctionCalled.Len > paramCount { //Compare number of actual parameters
+ libgogo.StringAppend(&FullFunctionName, FunctionCalled.PackageName)
+ libgogo.CharAppend(&FullFunctionName, '.')
+ libgogo.StringAppend(&FullFunctionName, FunctionCalled.Name)
+ tempString = libgogo.IntToString(FunctionCalled.Len)
+ SymbolTableError("Expecting", tempString, "parameters (more than the
actual ones) for function", FullFunctionName)
+ }
}

func ParameterCheck_Less(FunctionCalled *libgogo.TypeDesc, paramCount
uint64) {
- var FullFunctionName string = "";
- var tempString string;
- if FunctionCalled.Len < paramCount { //Compare number of actual
parameters
- libgogo.StringAppend(&FullFunctionName,
FunctionCalled.PackageName);
- libgogo.CharAppend(&FullFunctionName, '.');
- libgogo.StringAppend(&FullFunctionName, FunctionCalled.Name);
- tempString = libgogo.IntToString(FunctionCalled.Len);
- SymbolTableError("Expecting", tempString, "parameters (less than
the actual ones) for function", FullFunctionName);
- }
+ var FullFunctionName string = ""
+ var tempString string
+ if FunctionCalled.Len < paramCount { //Compare number of actual parameters
+ libgogo.StringAppend(&FullFunctionName, FunctionCalled.PackageName)
+ libgogo.CharAppend(&FullFunctionName, '.')
+ libgogo.StringAppend(&FullFunctionName, FunctionCalled.Name)
+ tempString = libgogo.IntToString(FunctionCalled.Len)
+ SymbolTableError("Expecting", tempString, "parameters (less than the
actual ones) for function", FullFunctionName)
+ }
}

func PrintActualFunctionCall(FunctionCalled *libgogo.TypeDesc,
TotalLocalVariableSize uint64, TotalParameterSize uint64) {
- if FunctionCalled.ForwardDecl == 1 {
- PrintFunctionCall(FunctionCalled.PackageName, FunctionCalled.Name,
TotalLocalVariableSize, 1);
- } else {
- PrintFunctionCall(FunctionCalled.PackageName, FunctionCalled.Name,
TotalParameterSize + TotalLocalVariableSize, 0);
- }
+ if FunctionCalled.ForwardDecl == 1 {
+ PrintFunctionCall(FunctionCalled.PackageName, FunctionCalled.Name,
TotalLocalVariableSize, 1)
+ } else {
+ PrintFunctionCall(FunctionCalled.PackageName, FunctionCalled.Name,
TotalParameterSize+TotalLocalVariableSize, 0)
+ }
}

func GetReturnItem(FunctionCalled *libgogo.TypeDesc,
TotalLocalVariableSize uint64, TotalParameterSize uint64,
SavedRegisterOffset uint64) *libgogo.Item {
- var ReturnObject *libgogo.ObjectDesc;
- var ReturnItem *libgogo.Item;
- ReturnObject = libgogo.GetObject("return value", "",
FunctionCalled.Fields); //Find return value
- if ReturnObject == nil {
- ReturnItem = nil;
- } else {
- if FunctionCalled.ForwardDecl == 1 {
- ReturnItem = ObjectToStackParameter(ReturnObject,
FunctionCalled, TotalLocalVariableSize);
- } else {
- ReturnItem = ObjectToStackParameter(ReturnObject,
FunctionCalled, TotalParameterSize + TotalLocalVariableSize);
- }
- ReturnItem.A = ReturnItem.A + SavedRegisterOffset;
- }
- return ReturnItem;
+ var ReturnObject *libgogo.ObjectDesc
+ var ReturnItem *libgogo.Item
+ ReturnObject = libgogo.GetObject("return value", "",
FunctionCalled.Fields) //Find return value
+ if ReturnObject == nil {
+ ReturnItem = nil
+ } else {
+ if FunctionCalled.ForwardDecl == 1 {
+ ReturnItem = ObjectToStackParameter(ReturnObject, FunctionCalled,
TotalLocalVariableSize)
+ } else {
+ ReturnItem = ObjectToStackParameter(ReturnObject, FunctionCalled,
TotalParameterSize+TotalLocalVariableSize)
+ }
+ ReturnItem.A = ReturnItem.A + SavedRegisterOffset
+ }
+ return ReturnItem
}

func AddArtificialParameterIfNecessary(FunctionCalled *libgogo.TypeDesc,
ExprItem *libgogo.Item, addressOperator uint64) {
- var TempObject *libgogo.ObjectDesc;
- if (FunctionCalled.ForwardDecl == 1) && (FunctionCalled.Base == nil) {
//Create artificial parameter from expression (based on the latter's type)
if the function is called the first time without being declared
- TempObject = libgogo.NewObject("Artificial parameter", "",
libgogo.CLASS_PARAMETER);
- TempObject.ObjType = ExprItem.Itemtype; //Derive type from
expression
- TempObject.PtrType = ExprItem.PtrType; //Derive pointer type from
expression
- if addressOperator != 0 { //& in expression forces pointer type
- if TempObject.PtrType == 0 {
- TempObject.PtrType = 1;
- } else {
- SymbolTableError("& operator on pointer type not
allowed,", "", "type: pointer to", ExprItem.Itemtype.Name);
- }
- }
- libgogo.AddParameters(TempObject, FunctionCalled); //Add a new,
artificial parameter
- }
+ var TempObject *libgogo.ObjectDesc
+ if (FunctionCalled.ForwardDecl == 1) && (FunctionCalled.Base == nil) {
//Create artificial parameter from expression (based on the latter's type)
if the function is called the first time without being declared
+ TempObject = libgogo.NewObject("Artificial parameter", "",
libgogo.CLASS_PARAMETER)
+ TempObject.ObjType = ExprItem.Itemtype //Derive type from expression
+ TempObject.PtrType = ExprItem.PtrType //Derive pointer type from
expression
+ if addressOperator != 0 { //& in expression forces pointer
type
+ if TempObject.PtrType == 0 {
+ TempObject.PtrType = 1
+ } else {
+ SymbolTableError("& operator on pointer type not allowed,", "", "type:
pointer to", ExprItem.Itemtype.Name)
+ }
+ }
+ libgogo.AddParameters(TempObject, FunctionCalled) //Add a new,
artificial parameter
+ }
}

func AddArtificialReturnValueIfNecessary(FunctionCalled *libgogo.TypeDesc,
ReturnValue *libgogo.Item, ForwardDeclExpectedReturnType *libgogo.TypeDesc,
ForwardDeclExpectedReturnPtrType uint64, SavedRegisterOffset uint64)
*libgogo.Item {
- var TotalLocalVariableSize uint64;
- var TempObject *libgogo.ObjectDesc;
- if FunctionCalled.ForwardDecl == 1 { //Create artifical return value
if function is called in a forward declaration
- if ForwardDeclExpectedReturnType != nil { //Return type expected
- TempObject = libgogo.GetObject("return value", "",
FunctionCalled.Fields); //Check if there is a return value
- if TempObject == nil { //If there is no return value, create
one
- TempObject = libgogo.NewObject("return value", "",
libgogo.CLASS_PARAMETER); //Create artificial return value
- TempObject.ObjType = ForwardDeclExpectedReturnType;
- TempObject.PtrType = ForwardDeclExpectedReturnPtrType;
- libgogo.AddParameters(TempObject, FunctionCalled); //Add a
new, artificial return value
- FunctionCalled.Len = FunctionCalled.Len - 1; //Don't count
parameter as input parameter
- } else { //If there is already a return value, validate it
- if (TempObject.ObjType != ForwardDeclExpectedReturnType) |
| (TempObject.PtrType != ForwardDeclExpectedReturnPtrType) {
- SymbolTableError("Function has been forward declared
with", "different", "return value type, function", CurrentFunction.Name);
- }
- }
- TotalLocalVariableSize =
libgogo.GetAlignedObjectListSize(LocalObjects); //Take local variable size
into consideration for offset below
- ReturnValue = ObjectToStackParameter(TempObject,
FunctionCalled, TotalLocalVariableSize);
- ReturnValue.A = ReturnValue.A + SavedRegisterOffset;
- } else { //No return type expected
- ReturnValue = nil;
- }
- }
- return ReturnValue;
+ var TotalLocalVariableSize uint64
+ var TempObject *libgogo.ObjectDesc
+ if FunctionCalled.ForwardDecl == 1 { //Create artifical return value if
function is called in a forward declaration
+ if ForwardDeclExpectedReturnType != nil { //Return type expected
+ TempObject = libgogo.GetObject("return value", "",
FunctionCalled.Fields) //Check if there is a return value
+ if TempObject == nil
{ //If there is no
return value, create one
+ TempObject = libgogo.NewObject("return value", "",
libgogo.CLASS_PARAMETER) //Create artificial return value
+ TempObject.ObjType = ForwardDeclExpectedReturnType
+ TempObject.PtrType = ForwardDeclExpectedReturnPtrType
+ libgogo.AddParameters(TempObject, FunctionCalled) //Add a new,
artificial return value
+ FunctionCalled.Len = FunctionCalled.Len - 1 //Don't count
parameter as input parameter
+ } else { //If there is already a return value, validate it
+ if (TempObject.ObjType != ForwardDeclExpectedReturnType) ||
(TempObject.PtrType != ForwardDeclExpectedReturnPtrType) {
+ SymbolTableError("Function has been forward declared
with", "different", "return value type, function", CurrentFunction.Name)
+ }
+ }
+ TotalLocalVariableSize = libgogo.GetAlignedObjectListSize(LocalObjects)
//Take local variable size into consideration for offset below
+ ReturnValue = ObjectToStackParameter(TempObject, FunctionCalled,
TotalLocalVariableSize)
+ ReturnValue.A = ReturnValue.A + SavedRegisterOffset
+ } else { //No return type expected
+ ReturnValue = nil
+ }
+ }
+ return ReturnValue
}

func CorrectArtificialParameterIfNecessary(FunctionCalled
*libgogo.TypeDesc, ParameterLHSObject *libgogo.ObjectDesc, ExprItemType
*libgogo.TypeDesc, ExprItemPtrType uint64, addressOperator uint64) {
- if FunctionCalled.ForwardDecl == 1 { //Parameter type up-conversion
- if (ParameterLHSObject.ObjType == byte_t) &&
(ParameterLHSObject.PtrType == 0) && (ExprItemType == uint64_t) &&
(ExprItemPtrType == 0) && (addressOperator == 0) { //If previous forward
declaration of this parameter was of type byte, it is possible that is was
a byte constant and is now of type uint64 => set to type uint64 in
declaration
- ParameterLHSObject.ObjType = uint64_t;
- }
- if (ParameterLHSObject.ObjType == nil) &&
(((ParameterLHSObject.PtrType == 1) && (ExprItemPtrType == 1) &&
(addressOperator == 0)) || ((ParameterLHSObject.PtrType == 1) &&
(ExprItemPtrType == 0) && (addressOperator == 1))) { //If previous forward
declaration of this parameter was of type unspecified pointer, it was nil
and is now of type *rhs_type => set to type of RHS in declaration
- ParameterLHSObject.ObjType = ExprItemType;
- }
- }
+ if FunctionCalled.ForwardDecl == 1 { //Parameter type up-conversion
+ if (ParameterLHSObject.ObjType == byte_t) && (ParameterLHSObject.PtrType
== 0) && (ExprItemType == uint64_t) && (ExprItemPtrType == 0) &&
(addressOperator == 0) { //If previous forward declaration of this
parameter was of type byte, it is possible that is was a byte constant and
is now of type uint64 => set to type uint64 in declaration
+ ParameterLHSObject.ObjType = uint64_t
+ }
+ if (ParameterLHSObject.ObjType == nil) && (((ParameterLHSObject.PtrType
== 1) && (ExprItemPtrType == 1) && (addressOperator == 0)) ||
((ParameterLHSObject.PtrType == 1) && (ExprItemPtrType == 0) &&
(addressOperator == 1))) { //If previous forward declaration of this
parameter was of type unspecified pointer, it was nil and is now of type
*rhs_type => set to type of RHS in declaration
+ ParameterLHSObject.ObjType = ExprItemType
+ }
+ }
}

func CorrectArtificialParameterForced(FunctionCalled *libgogo.TypeDesc,
ParameterLHSObject *libgogo.ObjectDesc, ExprItemType *libgogo.TypeDesc,
ExprItemPtrType uint64, addressOperator uint64) {
- var oldFwdDecl uint64 = FunctionCalled.ForwardDecl;
- FunctionCalled.ForwardDecl = 1; //Force correction
- CorrectArtificialParameterIfNecessary(FunctionCalled,
ParameterLHSObject, ExprItemType, ExprItemPtrType, addressOperator);
- FunctionCalled.ForwardDecl = oldFwdDecl;
-}
+ var oldFwdDecl uint64 = FunctionCalled.ForwardDecl
+ FunctionCalled.ForwardDecl = 1 //Force correction
+ CorrectArtificialParameterIfNecessary(FunctionCalled, ParameterLHSObject,
ExprItemType, ExprItemPtrType, addressOperator)
+ FunctionCalled.ForwardDecl = oldFwdDecl
+}
=======================================
--- /src/gen-for.go Tue Aug 17 09:58:38 2010
+++ /src/gen-for.go Wed Aug 18 10:20:16 2010
@@ -11,80 +11,78 @@
import "./libgogo/_obj/libgogo"

func GenerateForStart(item *libgogo.Item, ed *ExpressionDescriptor) {
- var labelString string;
- var jmp string;
- var stacksize uint64;
-
- labelString = GenerateSubLabel(ed,1,"END");
- if ed.Not == 0 {
- jmp = GetJump(item.C, 0);
- } else {
- labelString = GenerateSubLabel(ed,1,"END");
- jmp = GetJump(item.C, 1);
- }
- PrintJump(jmp, labelString);
-
- // Important: Since last jump is a positive one, we have to start with
the
- // negative path
- for stacksize = libgogo.GetStackItemCount(&ed.FS); stacksize > 0 ;
stacksize = libgogo.GetStackItemCount(&ed.FS) {
- PrintLabelWrapped(ed, 1 /*local*/, 0 /*negative*/, "END");
- libgogo.Pop(&ed.FS);
- libgogo.Pop(&ed.FDepthS);
- }
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0 /*unused*/, "END");
-
- // Positive branch starts after this label, thus insert last remaining
- // positive label (if available) here
- for stacksize = libgogo.GetStackItemCount(&ed.TS); stacksize > 0 ;
stacksize = libgogo.GetStackItemCount(&ed.TS) {
- PrintLabelWrapped(ed, 1 /*local*/, 1 /*positive*/, "END");
- libgogo.Pop(&ed.TS);
- libgogo.Pop(&ed.TDepthS);
- }
-
-
- item.C = 0;
- FreeRegisterIfRequired(item);
+ var labelString string
+ var jmp string
+ var stacksize uint64
+
+ labelString = GenerateSubLabel(ed, 1, "END")
+ if ed.Not == 0 {
+ jmp = GetJump(item.C, 0)
+ } else {
+ labelString = GenerateSubLabel(ed, 1, "END")
+ jmp = GetJump(item.C, 1)
+ }
+ PrintJump(jmp, labelString)
+
+ // Important: Since last jump is a positive one, we have to start with the
+ // negative path
+ for stacksize = libgogo.GetStackItemCount(&ed.FS); stacksize > 0;
stacksize = libgogo.GetStackItemCount(&ed.FS) {
+ PrintLabelWrapped(ed, 1 /*local*/ , 0 /*negative*/ , "END")
+ libgogo.Pop(&ed.FS)
+ libgogo.Pop(&ed.FDepthS)
+ }
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0 /*unused*/ , "END")
+
+ // Positive branch starts after this label, thus insert last remaining
+ // positive label (if available) here
+ for stacksize = libgogo.GetStackItemCount(&ed.TS); stacksize > 0;
stacksize = libgogo.GetStackItemCount(&ed.TS) {
+ PrintLabelWrapped(ed, 1 /*local*/ , 1 /*positive*/ , "END")
+ libgogo.Pop(&ed.TS)
+ libgogo.Pop(&ed.TDepthS)
+ }
+
+ item.C = 0
+ FreeRegisterIfRequired(item)
}

func GenerateForEnd(ed *ExpressionDescriptor, postassign uint64) {
- if postassign != 0 {
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0
/*unused*/, "EXTENDED_BODY");
- } else {
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0
/*unused*/, "EXPR_START");
- }
- PrintLabelWrapped(ed, 0 /*global*/, 0 /*unused*/, "END");
+ if postassign != 0 {
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0
/*unused*/ , "EXTENDED_BODY")
+ } else {
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0 /*unused*/ , "EXPR_START")
+ }
+ PrintLabelWrapped(ed, 0 /*global*/ , 0 /*unused*/ , "END")
}

func GenerateForBodyExtended(ed *ExpressionDescriptor) {
- PrintLabelWrapped(ed, 0 /*global*/, 0 /*unused*/, "EXTENDED_BODY");
+ PrintLabelWrapped(ed, 0 /*global*/ , 0 /*unused*/ , "EXTENDED_BODY")
}

func GenerateForBody(ed *ExpressionDescriptor, postassign uint64, expr
uint64) {
- if postassign != 0 {
- if expr != 0 {
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0
/*unused*/, "EXPR_START");
- }
- PrintLabelWrapped(ed, 0 /*global*/, 0 /*unused*/, "BODY");
- }
+ if postassign != 0 {
+ if expr != 0 {
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0 /*unused*/ , "EXPR_START")
+ }
+ PrintLabelWrapped(ed, 0 /*global*/ , 0 /*unused*/ , "BODY")
+ }
}

func GenerateForBodyJump(ed *ExpressionDescriptor) {
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0 /*unused*/, "BODY");
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0 /*unused*/ , "BODY")
}

func GenerateExpressionStart(ed *ExpressionDescriptor) {
- PrintLabelWrapped(ed, 0 /*global*/, 0 /*unused*/, "EXPR_START");
+ PrintLabelWrapped(ed, 0 /*global*/ , 0 /*unused*/ , "EXPR_START")
}

func GenerateBreak(ed *ExpressionDescriptor) {
- PrintJumpWrapped("JMP", ed.ForEd, 0 /*global*/, 0 /*unused*/, "END");
+ PrintJumpWrapped("JMP", ed.ForEd, 0 /*global*/ , 0 /*unused*/ , "END")
}

func GenerateContinue(ed *ExpressionDescriptor) {
- if ed.ForEd.ForPost != 0 {
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0
/*unused*/, "EXTENDED_BODY");
- } else {
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0
/*unused*/, "EXPR_START");
- }
-}
-
+ if ed.ForEd.ForPost != 0 {
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0
/*unused*/ , "EXTENDED_BODY")
+ } else {
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0 /*unused*/ , "EXPR_START")
+ }
+}
=======================================
--- /src/gen-if.go Tue Aug 17 09:58:38 2010
+++ /src/gen-if.go Wed Aug 18 10:20:16 2010
@@ -11,50 +11,49 @@
import "./libgogo/_obj/libgogo"

func GenerateIfStart(item *libgogo.Item, ed *ExpressionDescriptor) {
- var labelString string;
- var jmp string;
- var stacksize uint64;
- labelString = GenerateSubLabel(ed,1,"END");
- if ed.Not == 0 {
- jmp = GetJump(item.C, 0);
- } else {
- labelString = GenerateSubLabel(ed,1,"END");
- jmp = GetJump(item.C, 1);
- }
- PrintJump(jmp, labelString);
-
- // Important: Since last jump is a positive one, we have to start with
the
- // negative path
- for stacksize = libgogo.GetStackItemCount(&ed.FS); stacksize > 0 ;
stacksize = libgogo.GetStackItemCount(&ed.FS) {
- PrintLabelWrapped(ed, 1 /*local*/, 0 /*negative*/, "END");
- libgogo.Pop(&ed.FS);
- libgogo.Pop(&ed.FDepthS);
- }
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0 /*unused*/, "END");
-
- // Positive branch starts after this label, thus insert last remaining
- // positive label (if available) here
- for stacksize = libgogo.GetStackItemCount(&ed.TS); stacksize > 0 ;
stacksize = libgogo.GetStackItemCount(&ed.TS) {
- PrintLabelWrapped(ed, 1 /*local*/, 1 /*positive*/, "END");
- libgogo.Pop(&ed.TS);
- libgogo.Pop(&ed.TDepthS);
- }
-
- item.C = 0;
- FreeRegisterIfRequired(item);
+ var labelString string
+ var jmp string
+ var stacksize uint64
+ labelString = GenerateSubLabel(ed, 1, "END")
+ if ed.Not == 0 {
+ jmp = GetJump(item.C, 0)
+ } else {
+ labelString = GenerateSubLabel(ed, 1, "END")
+ jmp = GetJump(item.C, 1)
+ }
+ PrintJump(jmp, labelString)
+
+ // Important: Since last jump is a positive one, we have to start with the
+ // negative path
+ for stacksize = libgogo.GetStackItemCount(&ed.FS); stacksize > 0;
stacksize = libgogo.GetStackItemCount(&ed.FS) {
+ PrintLabelWrapped(ed, 1 /*local*/ , 0 /*negative*/ , "END")
+ libgogo.Pop(&ed.FS)
+ libgogo.Pop(&ed.FDepthS)
+ }
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0 /*unused*/ , "END")
+
+ // Positive branch starts after this label, thus insert last remaining
+ // positive label (if available) here
+ for stacksize = libgogo.GetStackItemCount(&ed.TS); stacksize > 0;
stacksize = libgogo.GetStackItemCount(&ed.TS) {
+ PrintLabelWrapped(ed, 1 /*local*/ , 1 /*positive*/ , "END")
+ libgogo.Pop(&ed.TS)
+ libgogo.Pop(&ed.TDepthS)
+ }
+
+ item.C = 0
+ FreeRegisterIfRequired(item)
}

func GenerateIfEnd(ed *ExpressionDescriptor) {
- PrintLabelWrapped(ed, 0 /*global*/, 0 /*unused*/, "END");
- PrintLabelWrapped(ed, 0 /*global*/, 0 /*unused*/, "ELSE_END");
+ PrintLabelWrapped(ed, 0 /*global*/ , 0 /*unused*/ , "END")
+ PrintLabelWrapped(ed, 0 /*global*/ , 0 /*unused*/ , "ELSE_END")
}

func GenerateElseStart(ed *ExpressionDescriptor) {
- PrintJumpWrapped("JMP", ed, 0 /*global*/, 0 /*unused*/, "ELSE_END");
- PrintLabelWrapped(ed, 0 /*global*/, 0 /*unused*/, "END");
+ PrintJumpWrapped("JMP", ed, 0 /*global*/ , 0 /*unused*/ , "ELSE_END")
+ PrintLabelWrapped(ed, 0 /*global*/ , 0 /*unused*/ , "END")
}

func GenerateElseEnd(ed *ExpressionDescriptor) {
- PrintLabelWrapped(ed, 0 /*global*/, 0 /*unused*/, "ELSE_END");
-}
-
+ PrintLabelWrapped(ed, 0 /*global*/ , 0 /*unused*/ , "ELSE_END")
+}
=======================================
--- /src/globals.go Tue Aug 17 09:58:38 2010
+++ /src/globals.go Wed Aug 18 10:20:16 2010
@@ -14,51 +14,51 @@
// Struct holding the information about a file that is compiled
//
type FileInfo struct {
- filename string;
- lineCounter uint64;
- charCounter uint64;
- fd uint64;
-};
+ filename string
+ lineCounter uint64
+ charCounter uint64
+ fd uint64
+}

type ExpressionDescriptor struct {
- //
- // Labeling information
- //
- ExpressionDepth uint64; // The current expression depth.
- IncCnt uint64; // Some incremental counter to guarantee uniqueness
- CurFile string; // Current file begining with a specified prefix.
- CurLine uint64; // Current line in parser. Used for label generation.
-
- //
- // True/False branches (merge) information
- //
- T uint64; // True branch
- F uint64; // False branch
- TDepth uint64; /* Depth when true branch has been started. Used for
merge
- and printing. */
- FDepth uint64; // Same as true depth.
- Not uint64; // Flag indicating not branch
-
- TS libgogo.Stack;
- FS libgogo.Stack;
- TDepthS libgogo.Stack;
- FDepthS libgogo.Stack;
-
- //
- // Break continue information
- //
- ForEd *ExpressionDescriptor;
- ForPost uint64;
-};
+ //
+ // Labeling information
+ //
+ ExpressionDepth uint64 // The current expression depth.
+ IncCnt uint64 // Some incremental counter to guarantee uniqueness
+ CurFile string // Current file begining with a specified prefix.
+ CurLine uint64 // Current line in parser. Used for label
generation.
+
+ //
+ // True/False branches (merge) information
+ //
+ T uint64 // True branch
+ F uint64 // False branch
+ TDepth uint64 /* Depth when true branch has been started. Used for merge
+ and printing. */
+ FDepth uint64 // Same as true depth.
+ Not uint64 // Flag indicating not branch
+
+ TS libgogo.Stack
+ FS libgogo.Stack
+ TDepthS libgogo.Stack
+ FDepthS libgogo.Stack
+
+ //
+ // Break continue information
+ //
+ ForEd *ExpressionDescriptor
+ ForPost uint64
+}

//
// Fileinformation for all files that are compiled in this run
// Is limited by 40 to reduce memory consumption, but to allow
// self compilation via "./gogo libgogo/*.go *.go"
//
-var fileInfo [40]FileInfo;
-var fileInfoLen uint64 = 0;
-var curFileIndex uint64 = 0;
+var fileInfo [40]FileInfo
+var fileInfoLen uint64 = 0
+var curFileIndex uint64 = 0

//
// Compiler flag indicating in which mode the compiler is
@@ -66,7 +66,7 @@
// 1 ... compile (code generation)
// 2 ... link
//
-var Compile uint64 = 0;
+var Compile uint64 = 0

//
// A very basic debug flag
@@ -74,15 +74,13 @@
// Set to 100 to enable all symbol tables
// Set to 10 to enable asm debugging
//
-var DEBUG_LEVEL uint64 = 10;
+var DEBUG_LEVEL uint64 = 10

//
// Package name of currently processed file
//
-var CurrentPackage string = "<no package>";
-
-var InsideFunction uint64 = 0;
-var InsideStructDecl uint64 = 0;
-var InsideFunctionVarDecl uint64 = 0;
-
-
+var CurrentPackage string = "<no package>"
+
+var InsideFunction uint64 = 0
+var InsideStructDecl uint64 = 0
+var InsideFunctionVarDecl uint64 = 0
=======================================
--- /src/gogo.go Tue Aug 17 09:58:38 2010
+++ /src/gogo.go Wed Aug 18 10:20:16 2010
@@ -10,133 +10,133 @@
// Entry point of the compiler
//
func main() {
- var errno uint64;
- var i uint64;
- var j uint64;
- var k uint64;
- var singleChar byte;
-
- libgogo.GetArgv();
-
- ParseOption();
-
- if libgogo.Argc > 40 {
- libgogo.ExitError("Cannot compile more than 38 files at once",1);
- }
-
- InitSymbolTable(); //Initialize symbol table
- InitFreeRegisters(); //Init registers for code generation
-
- ResetCode();
-
- for i=2; i < libgogo.Argc ; i= i+1 {
- curFileIndex = i-2;
- fileInfo[curFileIndex].filename = libgogo.Argv[i];
- fileInfo[curFileIndex].lineCounter = 1;
- fileInfo[curFileIndex].charCounter = 1;
-
- fileInfo[curFileIndex].fd = libgogo.FileOpen(libgogo.Argv[i], 0);
- if (fileInfo[curFileIndex].fd == 0) {
- GlobalError("Cannot open file.");
- }
- }
- fileInfoLen = i-2;
-
- if (Compile == 0) || (Compile == 1) { // Compile == 0|1 =>
Parse/Compile
- for
curFileIndex=0;curFileIndex<fileInfoLen;curFileIndex=curFileIndex+1 {
- i = libgogo.StringLength(fileInfo[curFileIndex].filename);
- if i > 2 { //Check for assembly files
- j = i - 2;
- k = i - 1;
- if (Compile == 1) && (fileInfo[curFileIndex].filename[j]
== '.') && (fileInfo[curFileIndex].filename[k] == 's') {
- // Assembly file: compile if in compiler mode
- if curFileIndex == 0 {
- GlobalError("The first file in the list cannot be
an assembly file");
- }
- for singleChar =
libgogo.GetChar(fileInfo[curFileIndex].fd); singleChar != 0; singleChar =
libgogo.GetChar(fileInfo[curFileIndex].fd) { //Copy file to output
character by character
- /* middot '·' is U+00C7 => UTF-8: C2B7*/
- if singleChar != 194 /*C2*/ {
- if singleChar == 183 /*B7*/ { //Prepend
package name
- PrintCodeOutput(CurrentPackage);
- PrintCodeOutputChar(194);
- PrintCodeOutputChar(183);
- } else {
- PrintCodeOutputChar(singleChar);
- }
- }
- }
- } else {
- // Go file: parse and/or compile
- Parse();
- }
- } else { //Go file: parse and/or compile
- Parse();
- }
- }
- } else { // Compile==2 => Link
- Link();
- }
-
- for
curFileIndex=0;curFileIndex<fileInfoLen;curFileIndex=curFileIndex+1 {
- errno = libgogo.FileClose(fileInfo[curFileIndex].fd);
- if errno != 0 {
- GlobalError("Cannot close file.");
- }
- }
-
- PrintGlobalSymbolTable();
-
- if Compile == 1 {
- i = libgogo.GetAlignedObjectListSize(GlobalObjects); //Get
required data segment size
- SetDataSegmentSize(i); //Set data segment size
- PrintFile(GlobalFunctions, GlobalTypes); //Print compiled output
to file
- }
+ var errno uint64
+ var i uint64
+ var j uint64
+ var k uint64
+ var singleChar byte
+
+ libgogo.GetArgv()
+
+ ParseOption()
+
+ if libgogo.Argc > 40 {
+ libgogo.ExitError("Cannot compile more than 38 files at once", 1)
+ }
+
+ InitSymbolTable() //Initialize symbol table
+ InitFreeRegisters() //Init registers for code generation
+
+ ResetCode()
+
+ for i = 2; i < libgogo.Argc; i = i + 1 {
+ curFileIndex = i - 2
+ fileInfo[curFileIndex].filename = libgogo.Argv[i]
+ fileInfo[curFileIndex].lineCounter = 1
+ fileInfo[curFileIndex].charCounter = 1
+
+ fileInfo[curFileIndex].fd = libgogo.FileOpen(libgogo.Argv[i], 0)
+ if fileInfo[curFileIndex].fd == 0 {
+ GlobalError("Cannot open file.")
+ }
+ }
+ fileInfoLen = i - 2
+
+ if (Compile == 0) || (Compile == 1) { // Compile == 0|1 => Parse/Compile
+ for curFileIndex = 0; curFileIndex < fileInfoLen; curFileIndex =
curFileIndex + 1 {
+ i = libgogo.StringLength(fileInfo[curFileIndex].filename)
+ if i > 2 { //Check for assembly files
+ j = i - 2
+ k = i - 1
+ if (Compile == 1) && (fileInfo[curFileIndex].filename[j] == '.') &&
(fileInfo[curFileIndex].filename[k] == 's') {
+ // Assembly file: compile if in compiler mode
+ if curFileIndex == 0 {
+ GlobalError("The first file in the list cannot be an assembly file")
+ }
+ for singleChar = libgogo.GetChar(fileInfo[curFileIndex].fd);
singleChar != 0; singleChar = libgogo.GetChar(fileInfo[curFileIndex].fd) {
//Copy file to output character by character
+ /* middot '·' is U+00C7 => UTF-8: C2B7*/
+ if singleChar != 194 /*C2*/ {
+ if singleChar == 183 /*B7*/ { //Prepend package name
+ PrintCodeOutput(CurrentPackage)
+ PrintCodeOutputChar(194)
+ PrintCodeOutputChar(183)
+ } else {
+ PrintCodeOutputChar(singleChar)
+ }
+ }
+ }
+ } else {
+ // Go file: parse and/or compile
+ Parse()
+ }
+ } else { //Go file: parse and/or compile
+ Parse()
+ }
+ }
+ } else { // Compile==2 => Link
+ Link()
+ }
+
+ for curFileIndex = 0; curFileIndex < fileInfoLen; curFileIndex =
curFileIndex + 1 {
+ errno = libgogo.FileClose(fileInfo[curFileIndex].fd)
+ if errno != 0 {
+ GlobalError("Cannot close file.")
+ }
+ }
+
+ PrintGlobalSymbolTable()
+
+ if Compile == 1 {
+ i = libgogo.GetAlignedObjectListSize(GlobalObjects) //Get required data
segment size
+ SetDataSegmentSize(i) //Set data segment
size
+ PrintFile(GlobalFunctions, GlobalTypes) //Print compiled
output to file
+ }
}

func ParseOption() {
- var strIndicator uint64;
- var done uint64 = 0;
-
- // handle -h and --help
- strIndicator = libgogo.StringCompare("--help", libgogo.Argv[1]);
- if strIndicator != 0 {
- strIndicator = libgogo.StringCompare("-h", libgogo.Argv[1]);
- }
-
- if strIndicator == 0 {
- libgogo.PrintString("Usage: gogo option file1.go
[file2.go ...]\n\n");
- libgogo.PrintString("GoGC - A go compiler\n\n");
- libgogo.PrintString("Options:\n");
- libgogo.PrintString("-h, --help show this help message and
exit\n");
- libgogo.PrintString("-p, parser mode\n");
- libgogo.PrintString("-c compiler mode\n");
- libgogo.PrintString("-l linker mode\n");
- libgogo.Exit(1);
- }
-
- strIndicator = libgogo.StringCompare("-c", libgogo.Argv[1]);
- if (done == 0) && (strIndicator == 0) {
- Compile = 1;
- done = 1;
- }
-
- strIndicator = libgogo.StringCompare("-p", libgogo.Argv[1]);
- if (done == 0) && (strIndicator == 0) {
- Compile = 0;
- done = 1;
- }
-
- strIndicator = libgogo.StringCompare("-l", libgogo.Argv[1]);
- if (done == 0) && (strIndicator == 0) {
- Compile = 2;
- done = 1;
- }
-
- if done == 0 {
- libgogo.ExitError("Usage: gogo option file1.go [file2.go ...]",1);
- }
-
- if libgogo.Argc <= 2 {
- libgogo.ExitError("Usage: gogo option file1.go [file2.go ...]",1);
- }
-}
+ var strIndicator uint64
+ var done uint64 = 0
+
+ // handle -h and --help
+ strIndicator = libgogo.StringCompare("--help", libgogo.Argv[1])
+ if strIndicator != 0 {
+ strIndicator = libgogo.StringCompare("-h", libgogo.Argv[1])
+ }
+
+ if strIndicator == 0 {
+ libgogo.PrintString("Usage: gogo option file1.go [file2.go ...]\n\n")
+ libgogo.PrintString("GoGC - A go compiler\n\n")
+ libgogo.PrintString("Options:\n")
+ libgogo.PrintString("-h, --help show this help message and exit\n")
+ libgogo.PrintString("-p, parser mode\n")
+ libgogo.PrintString("-c compiler mode\n")
+ libgogo.PrintString("-l linker mode\n")
+ libgogo.Exit(1)
+ }
+
+ strIndicator = libgogo.StringCompare("-c", libgogo.Argv[1])
+ if (done == 0) && (strIndicator == 0) {
+ Compile = 1
+ done = 1
+ }
+
+ strIndicator = libgogo.StringCompare("-p", libgogo.Argv[1])
+ if (done == 0) && (strIndicator == 0) {
+ Compile = 0
+ done = 1
+ }
+
+ strIndicator = libgogo.StringCompare("-l", libgogo.Argv[1])
+ if (done == 0) && (strIndicator == 0) {
+ Compile = 2
+ done = 1
+ }
+
+ if done == 0 {
+ libgogo.ExitError("Usage: gogo option file1.go [file2.go ...]", 1)
+ }
+
+ if libgogo.Argc <= 2 {
+ libgogo.ExitError("Usage: gogo option file1.go [file2.go ...]", 1)
+ }
+}
=======================================
--- /src/inspector.go Sun Aug 15 16:12:55 2010
+++ /src/inspector.go Wed Aug 18 10:20:16 2010
@@ -7,7 +7,7 @@
import "./libgogo/_obj/libgogo"

func InspectorGadget() {
- libgogo.StringAppend(&Header,`
+ libgogo.StringAppend(&Header, `

// .........................,,,,,,,,,,,,,,,,,,,,,,,..,..........................\n

// ..................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..,.....................\n

// .............,,,,,,,,,,,,,,,,,,,,,,,,,:,,,..=,..,:,,,,,,,,,,.................\n
@@ -74,5 +74,5 @@

// ......,,,,,,,,,,,:.?~~~::~~~~~~~~~~~~~~~~~~~~~~~~~:I7??:,,,,,,,,,,...........\n

// ........,,,,,,,,,,.:~~~::~~~~~~~~~~~~~~~~~~~~~~~~~:7II7,,,,,,,...............\n

// ........,,,,,,,,,,~~~~~+~~~~~~~~~~~~~~~~~~~~~~~~~~~III7,,,,,,,,..............\n
-`);
-}
+`)
+}
=======================================
--- /src/libgogo/convert.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/convert.go Wed Aug 18 10:20:16 2010
@@ -8,88 +8,87 @@

package libgogo

-func DerefUint64Ptr(ptr *uint64) uint64;
+func DerefUint64Ptr(ptr *uint64) uint64

//
// Converts a byte to an unsigned 64-bit integer
// Implemented in assembler (see corresponding .s file)
//
-func ToIntFromByte(b byte) uint64;
+func ToIntFromByte(b byte) uint64

//
// Converts an unsigned 64-bit integer to a byte
// Implemented in assembler (see corresponding .s file)
//
-func ToByteFromInt(i uint64) byte;
+func ToByteFromInt(i uint64) byte

//
// Converts a pointer to an unsigned 64-bit integer
// Implemented in assembler (see corresponding .s file)
//
-func ToUint64FromBytePtr(char *byte) uint64;
+func ToUint64FromBytePtr(char *byte) uint64

//
// Converts a pointer to an unsigned 64-bit integer
// Implemented in assembler (see corresponding .s file)
//
-func ToUint64FromUint64Ptr(value *uint64) uint64;
+func ToUint64FromUint64Ptr(value *uint64) uint64

//
// Converts an unsigned 64-bit integer to a pointer
// Implemented in assembler (see corresponding .s file)
//
-func ToUint64PtrFromUint64(value uint64) *uint64;
+func ToUint64PtrFromUint64(value uint64) *uint64

//
// Converts a string pointer to an unsigned 64-bit integer
// Implemented in assembler (see corresponding .s file)
//
-func ToUint64FromStringPtr(value *string) uint64;
+func ToUint64FromStringPtr(value *string) uint64

//
// Interprets the given address as a string pointer and returns it
// Implemented in assembler (see corresponding .s file)
//
-func GetStringFromAddress(addr uint64) *string;
+func GetStringFromAddress(addr uint64) *string

//
// Converts a string to a string to an unsigned 64-bit integer by
intepreting it as valid a decimal number in form of ASCII characters
//
func StringToInt(str string) uint64 {
- var n uint64;
- var i uint64;
- var temp uint64;
- var val uint64 = 0;
- n = StringLength(str);
- for i = 0; i < n ; i = i + 1 { //Process digit by digit
- val = val * 10; //Next digit => Move old value one digit to the
left
- temp = ToIntFromByte(str[i]);
- val = val + temp - 48; //Add the new digit as the last (rightmost)
one (ASCII 48 = '0', 49 = '1' etc.)
- }
- return val;
+ var n uint64
+ var i uint64
+ var temp uint64
+ var val uint64 = 0
+ n = StringLength(str)
+ for i = 0; i < n; i = i + 1 { //Process digit by digit
+ val = val * 10 //Next digit => Move old value one digit to the left
+ temp = ToIntFromByte(str[i])
+ val = val + temp - 48 //Add the new digit as the last (rightmost) one
(ASCII 48 = '0', 49 = '1' etc.)
+ }
+ return val
}

//
// Converts an unsigned 64-bit integer to a string denoting its decimal
digits
//
func IntToString(num uint64) string {
- var str string = "";
- var i uint64;
- var buf [20]byte; //The decimal representation of the longest unsigned
64-bit integer possible is 20 digits long
- for i = 0; num != 0; i = i + 1 { //Process digits one by one in
reverse order
- buf[i] = ToByteFromInt(num - (num / 10) * 10 + 48); //Get first
(leftmost) digit (ASCII '0' = 48, '1' = 49 etc.)
- num = num / 10; //Next digit => Move value one digit to the right
- }
- if i == 0 { //Special case: 0 (no digits processed)
- buf[0] = 48; //Put ASCII '0' into buffer
- i = 0;
- } else {
- i = i - 1; //Decrement i due to the last loop increment
- }
- for ; i != 0; i = i - 1 { //Reverse the digit order (for all digits
but the last one)
- CharAppend(&str, buf[i]);
- }
- CharAppend(&str,buf[0]); //Get the last digit (has to be appended if
the value is 0)
- return str;
-}
-
+ var str string = ""
+ var i uint64
+ var buf [20]byte //The decimal representation of the
longest unsigned 64-bit integer possible is 20 digits long
+ for i = 0; num != 0; i = i + 1 { //Process digits one by one in reverse
order
+ buf[i] = ToByteFromInt(num - (num/10)*10 + 48) //Get first (leftmost)
digit (ASCII '0' = 48, '1' = 49 etc.)
+ num = num / 10 //Next digit => Move
value one digit to the right
+ }
+ if i == 0 { //Special case: 0 (no digits processed)
+ buf[0] = 48 //Put ASCII '0' into buffer
+ i = 0
+ } else {
+ i = i - 1 //Decrement i due to the last loop increment
+ }
+ for ; i != 0; i = i - 1 { //Reverse the digit order (for all digits but
the last one)
+ CharAppend(&str, buf[i])
+ }
+ CharAppend(&str, buf[0]) //Get the last digit (has to be appended if the
value is 0)
+ return str
+}
=======================================
--- /src/libgogo/io.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/io.go Wed Aug 18 10:20:16 2010
@@ -13,38 +13,38 @@
// Write returns the number of characters actually written or 0 in case of
an error
// Implemented in assembler (see corresponding .s file)
//
-func Write(fd uint64, text string, length uint64) uint64;
+func Write(fd uint64, text string, length uint64) uint64

//
// Writes the specified string to the given file descriptor
//
func WriteString(fd uint64, msg string) {
- var strLen uint64;
- strLen = StringLength(msg);
- Write(fd, msg, strLen);
+ var strLen uint64
+ strLen = StringLength(msg)
+ Write(fd, msg, strLen)
}

//
// Writes the specified string to the (console) standard output
//
func PrintString(msg string) {
- WriteString(1, msg); //1 = standard output
+ WriteString(1, msg) //1 = standard output
}

//
// Prints a single character to the (console) standard output
// Implemented in assembler (see corresponding .s file)
//
-func PrintChar(char byte);
+func PrintChar(char byte)

//
// Prints the specified number to the (console) standard output
// This function simplified string handling as the conversion is wrapped
and has not to be done every time outside the library
//
func PrintNumber(num uint64) {
- var str string;
- str = IntToString(num);
- PrintString(str);
+ var str string
+ str = IntToString(num)
+ PrintString(str)
}

//
@@ -52,30 +52,30 @@
// Note that the string has to be at least of size buffer_size. Read
returns 0 if an error occured or the end of the file has been reached
// Implemented in assembler (see corresponding .s file)
//
-func Read(fd uint64, buffer string, buffer_size uint64) uint64;
+func Read(fd uint64, buffer string, buffer_size uint64) uint64

//
// Reads a single character from the file descriptor specified
// Note that Read returns 0 if there was an error (p.e. end of file)
// Implemented in assembler (see corresponding .s file)
//
-func GetChar(fd uint64) byte;
+func GetChar(fd uint64) byte

//
// Opens the file with the name and flags specified and returns a file
descriptor or 0 if there was an error
// Implemented in assembler (see corresponding .s file)
//
-func FileOpen(filename string, flags uint64) uint64;
+func FileOpen(filename string, flags uint64) uint64

//
// Same as libgogo.FileOpen, but also allows the third parameter to be set.
// See 'man open' for relevance.
// Implemented in assembler (see corresponding .s file)
//
-func FileOpen2(filename string, flags uint64, mode uint64) uint64;
+func FileOpen2(filename string, flags uint64, mode uint64) uint64

//
// Closes the specified file descriptor and returns errno
// Implemented in assembler (see corresponding .s file)
//
-func FileClose(fd uint64) uint64;
+func FileClose(fd uint64) uint64
=======================================
--- /src/libgogo/item.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/item.go Wed Aug 18 10:20:16 2010
@@ -5,72 +5,72 @@
package libgogo

type Item struct {
- Mode uint64;
- Itemtype *TypeDesc;
- PtrType uint64; //If 1, item is of type *Itemtype, otherwise it is of
type Itemtype
- A uint64; //Mode = MODE_VAR: variable address; Mode = MODE_CONST:
const value; Mode = MODE_REG: 0 = register contains value, 1 = register
contains address
- R uint64; //Mode = MODE_REGISTER: register number
- C uint64; // Mode = MODE_COND: Type of comparison; Mode = MODE_REG:
Optional second register occupied
- Global uint64; //If 1, the variable is global, 0 if it is
function-local, 2 if it is a function parameter
- LinkerInformation string; //Mode = MODE_VAR and Global = 0: If
non-empty, indicates unknown parameter offset to be replaced by the linker
-};
+ Mode uint64
+ Itemtype *TypeDesc
+ PtrType uint64 //If 1, item is of type *Itemtype, otherwise it
is of type Itemtype
+ A uint64 //Mode = MODE_VAR: variable address; Mode =
MODE_CONST: const value; Mode = MODE_REG: 0 = register contains value, 1 =
register contains address
+ R uint64 //Mode = MODE_REGISTER: register number
+ C uint64 // Mode = MODE_COND: Type of comparison; Mode =
MODE_REG: Optional second register occupied
+ Global uint64 //If 1, the variable is global, 0 if it is
function-local, 2 if it is a function parameter
+ LinkerInformation string //Mode = MODE_VAR and Global = 0: If non-empty,
indicates unknown parameter offset to be replaced by the linker
+}

//
// Pseudo constants that specify the descriptor sizes
//
-var ITEM_SIZE uint64 = 72; //9*8 bytes space for an object
+var ITEM_SIZE uint64 = 72 //9*8 bytes space for an object

//
// Modes for items
//
-var MODE_VAR uint64 = 1;
-var MODE_CONST uint64 = 2;
-var MODE_REG uint64 = 3;
-var MODE_COND uint64 = 4;
-var MODE_UNDEF uint64 = 5;
+var MODE_VAR uint64 = 1
+var MODE_CONST uint64 = 2
+var MODE_REG uint64 = 3
+var MODE_COND uint64 = 4
+var MODE_UNDEF uint64 = 5

//
// Relation types
//
-var REL_EQ uint64 = 0;
-var REL_NEQ uint64 = 1;
-var REL_LT uint64 = 2;
-var REL_GTE uint64 = 3;
-var REL_LTE uint64 = 4;
-var REL_GT uint64 = 5;
+var REL_EQ uint64 = 0
+var REL_NEQ uint64 = 1
+var REL_LT uint64 = 2
+var REL_GTE uint64 = 3
+var REL_LTE uint64 = 4
+var REL_GT uint64 = 5

//
// Convert the uint64 value (returned from malloc) to a real item address
//
-func Uint64ToItemPtr(adr uint64) *Item;
+func Uint64ToItemPtr(adr uint64) *Item

//
//
//
-func ItemPtrToUint64(item *Item) uint64;
+func ItemPtrToUint64(item *Item) uint64

//
// Creates a new, uninitialized item
//
func NewItem() *Item {
- var adr uint64;
- var item *Item;
- adr = Alloc(ITEM_SIZE);
- item = Uint64ToItemPtr(adr);
- item.Mode = MODE_UNDEF;
- return item;
+ var adr uint64
+ var item *Item
+ adr = Alloc(ITEM_SIZE)
+ item = Uint64ToItemPtr(adr)
+ item.Mode = MODE_UNDEF
+ return item
}

//
// Sets the given item's properties
//
func SetItem(item *Item, mode uint64, itemtype *TypeDesc, ptrtype uint64,
a uint64, r uint64, global uint64) {
- item.Mode = mode;
- item.Itemtype = itemtype;
- item.PtrType = ptrtype;
- item.A = a;
- item.C = 0;
- item.R = r;
- item.Global = global;
- item.LinkerInformation = "";
-}
+ item.Mode = mode
+ item.Itemtype = itemtype
+ item.PtrType = ptrtype
+ item.A = a
+ item.C = 0
+ item.R = r
+ item.Global = global
+ item.LinkerInformation = ""
+}
=======================================
--- /src/libgogo/libgogo.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/libgogo.go Wed Aug 18 10:20:16 2010
@@ -12,56 +12,56 @@
// Argc/Argv variables.
// Are available AFTER they have been set by libgogo.GetArgv()
//
-var Argv [255]string;
-var Argc uint64 = 0;
+var Argv [255]string
+var Argc uint64 = 0

//
// Sets the program's arguments as globally available variables
libgogo.Argc and libgogo.Argv
// This function uses the Linux proc fs to determine its command line
arguments. It is not possible to get these arguments from the stack as the
Go runtime also uses the latter. In order to be compatible with the Go
runtime, the arguments are therefore not read from the stack
//
func GetArgv() {
- var fd uint64;
- var errno uint64;
- var singleChar byte;
- var lastChar byte = 1; // needs to be != 0 at start
-
- fd = FileOpen("/proc/self/cmdline", 0); //Open file that contains the
program's arguments
- if fd == 0 { //Error check (the system may have been compiled with
proc fs disabled)
- ExitError("Error opening /proc/self/cmdline. Currently GoGC is
only supported on systems with /proc enabled.", 1);
- }
-
- for singleChar = GetChar(fd);(singleChar != 0) || (lastChar != 0);
singleChar = GetChar(fd) {
- if (singleChar == 0) {
- Argc = Argc +1;
- } else {
- CharAppend(&Argv[Argc], singleChar);
- }
- lastChar = singleChar;
- }
-
- errno = FileClose(fd);
- if errno != 0 {
- ExitError("Error closing file /proc/self/cmdline",1);
- }
+ var fd uint64
+ var errno uint64
+ var singleChar byte
+ var lastChar byte = 1 // needs to be != 0 at start
+
+ fd = FileOpen("/proc/self/cmdline", 0) //Open file that contains the
program's arguments
+ if fd == 0 { //Error check (the system may have
been compiled with proc fs disabled)
+ ExitError("Error opening /proc/self/cmdline. Currently GoGC is only
supported on systems with /proc enabled.", 1)
+ }
+
+ for singleChar = GetChar(fd); (singleChar != 0) || (lastChar != 0);
singleChar = GetChar(fd) {
+ if singleChar == 0 {
+ Argc = Argc + 1
+ } else {
+ CharAppend(&Argv[Argc], singleChar)
+ }
+ lastChar = singleChar
+ }
+
+ errno = FileClose(fd)
+ if errno != 0 {
+ ExitError("Error closing file /proc/self/cmdline", 1)
+ }
}

//
// Copies size bytes of memory from one location to another
// Implemented in assembler (see corresponding .s file)
//
-func CopyMem(source uint64, dest uint64, size uint64);
+func CopyMem(source uint64, dest uint64, size uint64)

//
// Exits the current program with an error number (return value) as
parameter
// Implemented in assembler (see corresponding .s file)
//
-func Exit(code uint64);
+func Exit(code uint64)

//
// Wrapper printing a given message and exiting the program with an error
number
//
func ExitError(msg string, code uint64) {
- PrintString(msg);
- PrintChar(10); //Print new line ('\n' = 10)
- Exit(code);
-}
+ PrintString(msg)
+ PrintChar(10) //Print new line ('\n' = 10)
+ Exit(code)
+}
=======================================
--- /src/libgogo/list.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/list.go Wed Aug 18 10:20:16 2010
@@ -12,37 +12,37 @@
// List data structure
//
type List struct {
- baseAddress uint64; //Where the list starts
- itemSize uint64; //Size of one item in bytes
- itemCount uint64; //How many items there currently are in the list
- capacity uint64; //How many items there can be max. (not to be changed
from outside the library)
-};
+ baseAddress uint64 //Where the list starts
+ itemSize uint64 //Size of one item in bytes
+ itemCount uint64 //How many items there currently are in the list
+ capacity uint64 //How many items there can be max. (not to be changed
from outside the library)
+}

//
// Initializes the given list
//
func InitializeList(uninitializedList *List, itemSize uint64) {
- uninitializedList.itemSize = itemSize;
- uninitializedList.capacity = 16; //Allocate 16 items by default
- uninitializedList.baseAddress = Alloc(uninitializedList.capacity *
uninitializedList.itemSize);
- uninitializedList.itemCount = 0; //Reset item count (to zero)
+ uninitializedList.itemSize = itemSize
+ uninitializedList.capacity = 16 //Allocate 16 items by default
+ uninitializedList.baseAddress = Alloc(uninitializedList.capacity *
uninitializedList.itemSize)
+ uninitializedList.itemCount = 0 //Reset item count (to zero)
}

//
// Adds an item (referred to via the given pointer) to the given list,
increasing its capacity if required
//
func AddItem(list *List, valuePtr *uint64) {
- var newAddress uint64;
- var valueAddr uint64;
- if (list.capacity == list.itemCount) { //Grow list if its capacity
doesn't suffice to add another item
- newAddress = Alloc(list.capacity * 2 * list.itemSize); //Double
the capacity
- CopyMem(list.baseAddress, newAddress, list.capacity *
list.itemSize); //Copy old list items
- list.baseAddress = newAddress; //Set new address as base address
- list.capacity = list.capacity * 2; //Update (increase) capacity
- }
- valueAddr = ToUint64FromUint64Ptr(valuePtr);
- CopyMem(valueAddr, list.baseAddress + list.itemSize * list.itemCount,
list.itemSize); //Append the new value by copying its value into the memory
of the corresponding list item
- list.itemCount = list.itemCount + 1; //Update item count
+ var newAddress uint64
+ var valueAddr uint64
+ if list.capacity == list.itemCount { //Grow list if its capacity doesn't
suffice to add another item
+ newAddress = Alloc(list.capacity * 2 * list.itemSize)
//Double the capacity
+ CopyMem(list.baseAddress, newAddress, list.capacity*list.itemSize)
//Copy old list items
+ list.baseAddress = newAddress //Set
new address as base address
+ list.capacity = list.capacity * 2
//Update (increase) capacity
+ }
+ valueAddr = ToUint64FromUint64Ptr(valuePtr)
+ CopyMem(valueAddr, list.baseAddress+list.itemSize*list.itemCount,
list.itemSize) //Append the new value by copying its value into the memory
of the corresponding list item
+ list.itemCount = list.itemCount +
1 //Update item count
}

//
@@ -50,21 +50,21 @@
// Note that this function call fails if there are less than i items in
the list or if the list is empty
//
func RemoveItemAt(list *List, index uint64) *uint64 {
- var returnPtr *uint64;
- var returnAddr uint64;
- var newReturnPtr uint64;
- var actualReturnPtr *uint64;
- var i uint64;
- returnPtr = GetItemAt(list, index); //Get the correspondig value value
from the list
- newReturnPtr = Alloc(list.itemSize); //Allocate memory to store the
item to be removed
- returnAddr = ToUint64FromUint64Ptr(returnPtr);
- CopyMem(returnAddr, newReturnPtr, list.itemSize); //Save item to be
removed in order to return it
- for i = index; i < list.itemCount - 1; i = i + 1 { //Remove item by
moving the following ones "backwards" in order to fill the gap caused by
the deleted item
- CopyMem(list.baseAddress + (i + 1) * list.itemSize,
list.baseAddress + list.itemSize * i, list.itemSize); //Move item at
position i + 1 to position i
- }
- list.itemCount = list.itemCount - 1; //Update (decrease) item count
- actualReturnPtr = ToUint64PtrFromUint64(newReturnPtr);
- return actualReturnPtr; //Return value removed from list
+ var returnPtr *uint64
+ var returnAddr uint64
+ var newReturnPtr uint64
+ var actualReturnPtr *uint64
+ var i uint64
+ returnPtr = GetItemAt(list, index) //Get the correspondig value value
from the list
+ newReturnPtr = Alloc(list.itemSize) //Allocate memory to store the item
to be removed
+ returnAddr = ToUint64FromUint64Ptr(returnPtr)
+ CopyMem(returnAddr, newReturnPtr, list.itemSize) //Save item to be
removed in order to return it
+ for i = index; i < list.itemCount-1; i = i + 1 { //Remove item by moving
the following ones "backwards" in order to fill the gap caused by the
deleted item
+ CopyMem(list.baseAddress+(i+1)*list.itemSize,
list.baseAddress+list.itemSize*i, list.itemSize) //Move item at position i
+ 1 to position i
+ }
+ list.itemCount = list.itemCount - 1 //Update (decrease) item count
+ actualReturnPtr = ToUint64PtrFromUint64(newReturnPtr)
+ return actualReturnPtr //Return value removed from list
}

//
@@ -72,28 +72,28 @@
// Note that this function call fails if there are less than i items in
the list or if the list is empty
//
func GetItemAt(list *List, index uint64) *uint64 {
- var returnPtr *uint64;
- if (list.itemCount <= index) { //Check if there are enough items in
the list
- PrintString("Tried to GetItemAt(");
- PrintNumber(index);
- PrintString(") from a list with only ");
- PrintNumber(list.itemCount);
- ExitError(" items - out of bounds error", 125);
- }
- returnPtr = ToUint64PtrFromUint64(list.baseAddress + index *
list.itemSize);
- return returnPtr; //Get the value on position i of the list (e.g. its
corresponding memory) into the return variable
+ var returnPtr *uint64
+ if list.itemCount <= index { //Check if there are enough items in the list
+ PrintString("Tried to GetItemAt(")
+ PrintNumber(index)
+ PrintString(") from a list with only ")
+ PrintNumber(list.itemCount)
+ ExitError(" items - out of bounds error", 125)
+ }
+ returnPtr = ToUint64PtrFromUint64(list.baseAddress + index*list.itemSize)
+ return returnPtr //Get the value on position i of the list (e.g. its
corresponding memory) into the return variable
}

//
// Returns the number of items in the given list
//
func GetListItemCount(list *List) uint64 {
- return list.itemCount;
+ return list.itemCount
}

//
// Returns the current capacity of the given list
//
func GetListCapacity(list *List) uint64 {
- return list.capacity;
-}
+ return list.capacity
+}
=======================================
--- /src/libgogo/memmgr.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/memmgr.go Wed Aug 18 10:20:16 2010
@@ -11,7 +11,7 @@
//
// Default size increment in bytes when allocating more memory for the
memory manager
//
-var INC_SIZE uint64 = 1024; //Default 1 KB
+var INC_SIZE uint64 = 1024 //Default 1 KB

//
// Pointers used for memory management
@@ -19,89 +19,89 @@
// Bump pointer: Pointer to next free address in memory
// End pointer: Pointer to the end of the free memory available for use
through the memory manager
//
-var start_ptr uint64 = 0;
-var bump_ptr uint64 = 0;
-var end_ptr uint64 = 0;
+var start_ptr uint64 = 0
+var bump_ptr uint64 = 0
+var end_ptr uint64 = 0

//
// Sets the end address of the data segment to the one specified, thereby
resizing it
// Brk returns 0 if the data segment could not be resized
// Implemented in assembler (see corresponding .s file)
//
-func Brk(brk uint64) uint64;
+func Brk(brk uint64) uint64

//
// Gets the current end address of the data segment
// GetBrk returns 0 in case of an error
// Implemented in assembler (see corresponding .s file)
//
-func GetBrk() uint64;
+func GetBrk() uint64

//
// Tests newly allocated memory by writing to the address given and
verifying the result by re-reading it
// TestMem returns 0 in case of success; it is very improbable for the
return value to be unequal 0 as an invalid address will most likely lead to
a program crash before the function is able to return
// Implemented in assembler (see corresponding .s file)
//
-func TestMem(address uint64) uint64;
+func TestMem(address uint64) uint64

//
// Initializes the memory manager by setting the end and bump pointer
//
func InitMemoryManager() {
- start_ptr = GetBrk(); //Get current end of data segment
- if start_ptr == 0 { //Error check
- ExitError("GetBrk failed\n", 127);
- }
- start_ptr = start_ptr + 1; //First useable address in new memory (will
be allocated below)
- end_ptr = start_ptr; //No free memory yet (will be allocated below)
- bump_ptr = end_ptr;
- MoreMemory(); //Allocate memory for the memory manager to work with
+ start_ptr = GetBrk() //Get current end of data segment
+ if start_ptr == 0 { //Error check
+ ExitError("GetBrk failed\n", 127)
+ }
+ start_ptr = start_ptr + 1 //First useable address in new memory (will be
allocated below)
+ end_ptr = start_ptr //No free memory yet (will be allocated below)
+ bump_ptr = end_ptr
+ MoreMemory() //Allocate memory for the memory manager to work with
}

//
// Allocates more memory, more precisely the amount in bytes specified by
INC_SIZE
//
func MoreMemory() {
- var errno uint64;
-
- end_ptr = end_ptr + INC_SIZE; //Increment end pointer
- errno = Brk(end_ptr); //Resize data segment
- if errno != 0 { //Error check
- PrintString("Brk failed while allocating ");
- PrintNumber(INC_SIZE);
- PrintString(" bytes. Errno: ");
- PrintNumber(errno);
- ExitError("\n", 127);
- }
- errno = TestMem(end_ptr - INC_SIZE + 1); //Sanity check for newly
allocated memory
- if errno != 0 { //Error handling in case sanity check fails
- PrintString("Failed to write to newly allocated memory at ");
- PrintNumber(end_ptr - INC_SIZE + 1);
- ExitError("\n", 127);
- }
+ var errno uint64
+
+ end_ptr = end_ptr + INC_SIZE //Increment end pointer
+ errno = Brk(end_ptr) //Resize data segment
+ if errno != 0 { //Error check
+ PrintString("Brk failed while allocating ")
+ PrintNumber(INC_SIZE)
+ PrintString(" bytes. Errno: ")
+ PrintNumber(errno)
+ ExitError("\n", 127)
+ }
+ errno = TestMem(end_ptr - INC_SIZE + 1) //Sanity check for newly
allocated memory
+ if errno != 0 { //Error handling in case sanity
check fails
+ PrintString("Failed to write to newly allocated memory at ")
+ PrintNumber(end_ptr - INC_SIZE + 1)
+ ExitError("\n", 127)
+ }
}

//
// Allocated size bytes of memory through the memory manager and returns
the address of the newly allocated memory
//
func Alloc(size uint64) uint64 {
- var addr uint64;
-
- if (bump_ptr == 0) && (end_ptr == 0) { //First call => initialization
required
- InitMemoryManager();
- }
- for ; bump_ptr + size >= end_ptr; { //Ensure there is enough memory;
if there isn't, get more memory until there is enough
- MoreMemory();
- }
-
- addr = bump_ptr; //Return bump pointer (next free address)
- bump_ptr = bump_ptr + size; //Update bump pointer for next call
- return addr;
+ var addr uint64
+
+ if (bump_ptr == 0) && (end_ptr == 0) { //First call => initialization
required
+ InitMemoryManager()
+ }
+ for bump_ptr+size >= end_ptr { //Ensure there is enough memory; if there
isn't, get more memory until there is enough
+ MoreMemory()
+ }
+
+ addr = bump_ptr //Return bump pointer (next free address)
+ bump_ptr = bump_ptr + size //Update bump pointer for next call
+ return addr
}

//
// Returns the number of bytes which are currently free and available
through the memory manager without reallocation operations
//
func GetFreeMemory() uint64 {
- return end_ptr - bump_ptr; //Free memory are all addresses/bytes
between the bump pointer and the end pointer
-}
+ return end_ptr - bump_ptr //Free memory are all addresses/bytes between
the bump pointer and the end pointer
+}
=======================================
--- /src/libgogo/stack.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/stack.go Wed Aug 18 10:20:16 2010
@@ -12,34 +12,34 @@
// Stack data structure
//
type Stack struct {
- baseAddress uint64; //Where the stack starts
- itemCount uint64; //How many items there currently are on the stack
- capacity uint64; //How many items there can be max. (not to be changed
from outside the library)
-};
+ baseAddress uint64 //Where the stack starts
+ itemCount uint64 //How many items there currently are on the stack
+ capacity uint64 //How many items there can be max. (not to be changed
from outside the library)
+}

//
// Initializes the given stack
//
func InitializeStack(uninitializedStack *Stack) {
- uninitializedStack.baseAddress = Alloc(16 * 8); //Allocate 16 items by
default
- uninitializedStack.capacity = 16;
- uninitializedStack.itemCount = 0; //Reset item count (to zero)
+ uninitializedStack.baseAddress = Alloc(16 * 8) //Allocate 16 items by
default
+ uninitializedStack.capacity = 16
+ uninitializedStack.itemCount = 0 //Reset item count (to zero)
}

//
// Pushes an item onto the given stack, increasing its capacity if required
//
func Push(stack *Stack, value uint64) {
- var newAddress uint64;
- if (stack.capacity == stack.itemCount) { //Grow stack if its capacity
doesn't suffice to push another item
- newAddress = Alloc(stack.capacity * 2 * 8); //Double the capacity
- CopyMem(stack.baseAddress, newAddress, stack.capacity * 8); //Copy
old stack items
- stack.baseAddress = newAddress; //Set new address as base address
- stack.capacity = stack.capacity * 2; //Update (increase) capacity
- }
- newAddress = ToUint64FromUint64Ptr(&value);
- CopyMem(newAddress, stack.baseAddress + 8 * stack.itemCount, 8);
//Push the new value by copying its value into the memory of the
corresponding stack item
- stack.itemCount = stack.itemCount + 1; //Update item count
+ var newAddress uint64
+ if stack.capacity == stack.itemCount { //Grow stack if its capacity
doesn't suffice to push another item
+ newAddress = Alloc(stack.capacity * 2 * 8) //Double the
capacity
+ CopyMem(stack.baseAddress, newAddress, stack.capacity*8) //Copy old
stack items
+ stack.baseAddress = newAddress //Set new
address as base address
+ stack.capacity = stack.capacity * 2 //Update
(increase) capacity
+ }
+ newAddress = ToUint64FromUint64Ptr(&value)
+ CopyMem(newAddress, stack.baseAddress+8*stack.itemCount, 8) //Push the
new value by copying its value into the memory of the corresponding stack
item
+ stack.itemCount = stack.itemCount + 1 //Update item
count
}

//
@@ -47,10 +47,10 @@
// Note that this function call fails if there are no items on the stack,
e.g. the stack is empty
//
func Pop(stack *Stack) uint64 {
- var returnValue uint64;
- returnValue = Peek(stack); //Peek in order to get the last value from
the stack
- stack.itemCount = stack.itemCount - 1; //Update (decrease) item count
- return returnValue; //Return value taken from stack
+ var returnValue uint64
+ returnValue = Peek(stack) //Peek in order to get the last
value from the stack
+ stack.itemCount = stack.itemCount - 1 //Update (decrease) item count
+ return returnValue //Return value taken from stack
}

//
@@ -58,26 +58,26 @@
// Note that this function call fails if there are no items on the stack,
e.g. the stack is empty
//
func Peek(stack *Stack) uint64 {
- var returnValue uint64;
- var temp uint64;
- if (stack.itemCount == 0) { //Check if there is an item on the stack
- ExitError("Tried to Peek() from an empty stack", 126);
- }
- temp = ToUint64FromUint64Ptr(&returnValue);
- CopyMem(stack.baseAddress + (stack.itemCount - 1) * 8, temp, 8);
//Copy the last value from the stack (e.g. its corresponding memory) into
the return variable
- return returnValue; //Return peeked value
+ var returnValue uint64
+ var temp uint64
+ if stack.itemCount == 0 { //Check if there is an item on the stack
+ ExitError("Tried to Peek() from an empty stack", 126)
+ }
+ temp = ToUint64FromUint64Ptr(&returnValue)
+ CopyMem(stack.baseAddress+(stack.itemCount-1)*8, temp, 8) //Copy the last
value from the stack (e.g. its corresponding memory) into the return
variable
+ return returnValue //Return peeked
value
}

//
// Returns the number of items on the given stack
//
func GetStackItemCount(stack *Stack) uint64 {
- return stack.itemCount;
+ return stack.itemCount
}

//
// Returns the current capacity of the given stack
//
func GetStackCapacity(stack *Stack) uint64 {
- return stack.capacity;
-}
+ return stack.capacity
+}
=======================================
--- /src/libgogo/string.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/string.go Wed Aug 18 10:20:16 2010
@@ -12,76 +12,76 @@
// Returns the length of an ASCII string
// Implemented in assembler (see corresponding .s file)
//
-func StringLength(str string) uint64;
+func StringLength(str string) uint64

//
// Returns the length of an ASCII string referred to by the string pointer
given
// Implemented in assembler (see corresponding .s file)
//
-func StringLength2(str *string) uint64;
+func StringLength2(str *string) uint64

//
// Returns the internal address of the character sequence referred to by
the string pointer given
// Implemented in assembler (see corresponding .s file)
//
-func GetStringAddress(str *string) uint64;
+func GetStringAddress(str *string) uint64

//
// Allocates a new, empty byte array for a string
//
func ResetString(str *string) {
- var nullByte byte = 0; //End of string constant
- var nullByte_addr uint64;
- var n uint64;
- n = Alloc(1);
- nullByte_addr = ToUint64FromBytePtr(&nullByte);
- CopyMem(n, nullByte_addr, 1);
- SetStringAddressAndLength(str, n, 0); //New string with length 0
+ var nullByte byte = 0 //End of string constant
+ var nullByte_addr uint64
+ var n uint64
+ n = Alloc(1)
+ nullByte_addr = ToUint64FromBytePtr(&nullByte)
+ CopyMem(n, nullByte_addr, 1)
+ SetStringAddressAndLength(str, n, 0) //New string with length 0
}

//
// Compares to strings and returns 0 for equality and 1 otherwise
//
func StringCompare(str1 string, str2 string) uint64 {
- var i uint64;
- var equal uint64 = 0; //Assume equality by default
- var strlen1 uint64;
- var strlen2 uint64;
- strlen1 = StringLength(str1);
- strlen2 = StringLength(str2);
- if strlen1 != strlen2 { //Return inequality if lengths are not equal
- equal = 1;
- } else {
- for i = 0; i < strlen1; i = i + 1 { //If lengths are equal compare
every character
- if str1[i] != str2[i] { //If two characters differ =>
inequality
- equal = 1;
- }
- }
- }
- return equal;
+ var i uint64
+ var equal uint64 = 0 //Assume equality by default
+ var strlen1 uint64
+ var strlen2 uint64
+ strlen1 = StringLength(str1)
+ strlen2 = StringLength(str2)
+ if strlen1 != strlen2 { //Return inequality if lengths are not equal
+ equal = 1
+ } else {
+ for i = 0; i < strlen1; i = i + 1 { //If lengths are equal compare every
character
+ if str1[i] != str2[i] { //If two characters differ => inequality
+ equal = 1
+ }
+ }
+ }
+ return equal
}

//
// Sets a string's internal address and length; the string given by the
specified string pointer referring to it
// Implemented in assembler (see corresponding .s file)
//
-func SetStringAddressAndLength(str *string, new_addr uint64, new_length
uint64);
+func SetStringAddressAndLength(str *string, new_addr uint64, new_length
uint64)

//
// Rounds length to the next power of two
//
func GetMaxStringLength(length uint64) uint64 {
- var i uint64;
- var j uint64;
- length = length - 1; //Assure that powers of two will be returned
exactly as they are
- for i = 0; length != 0; i = i + 1 { //Calculate number of divisions by
2 required to reach 0 => log2(length), rounded towards +inf
- length = length / 2;
- }
- length = 1; //Restart with length of 1
- for j = 0; j < i; j = j + 1 { //Multiply by 2 as many times as divided
previously => 2^i
- length = length * 2;
- }
- return length;
+ var i uint64
+ var j uint64
+ length = length - 1 //Assure that powers of two will be
returned exactly as they are
+ for i = 0; length != 0; i = i + 1 { //Calculate number of divisions by 2
required to reach 0 => log2(length), rounded towards +inf
+ length = length / 2
+ }
+ length = 1 //Restart with length of 1
+ for j = 0; j < i; j = j + 1 { //Multiply by 2 as many times as divided
previously => 2^i
+ length = length * 2
+ }
+ return length
}

//
@@ -89,32 +89,32 @@
// This functions creates a new string by copying the old one and then
appending the character
//
func CharAppend(str *string, char byte) {
- var nullByte byte = 0; //End of string constant
- var strlen uint64;
- var new_length uint64;
- var max_length uint64;
- var new_addr uint64;
- var old_addr uint64;
- var char_addr uint64;
- var nullByte_addr uint64;
- strlen = StringLength2(str); //Get length of old string
- new_length = strlen + 1; //The length of the new string the length of
the old string plus the length of the character to be appended (1)
- max_length = GetMaxStringLength(strlen + 1); //Get maximum capacity of
old string, considering its trailing '\0'
- old_addr = GetStringAddress(str);
- if (old_addr < start_ptr) || ((new_length + 1) > max_length) { //If
using non-managed address or the old string's capacity doesn't suffice =>
allocate more memory
- max_length = GetMaxStringLength(new_length + 1); //Consider
trailing '\0'
- new_addr = Alloc(max_length); //Allocate memory for the new
string, including the space for the end of string constant
- if strlen > 0 { //Only copy old content if there is content to copy
- CopyMem(old_addr, new_addr, strlen); //Copy the content of the
old string to the newly allocated memory
- }
- } else { //Re-use old address as capacity suffices; no copy operation
necessary
- new_addr = old_addr;
- }
- char_addr = ToUint64FromBytePtr(&char);
- CopyMem(char_addr, new_addr + strlen, 1); //Copy the additional
character to its according position at the end of the new string
- nullByte_addr = ToUint64FromBytePtr(&nullByte);
- CopyMem(nullByte_addr, new_addr+strlen + 1, 1); //Append the end of
string constant
- SetStringAddressAndLength(str, new_addr, new_length); //Update the
string in order to point to the new character sequence with the new length
+ var nullByte byte = 0 //End of string constant
+ var strlen uint64
+ var new_length uint64
+ var max_length uint64
+ var new_addr uint64
+ var old_addr uint64
+ var char_addr uint64
+ var nullByte_addr uint64
+ strlen = StringLength2(str) //Get length of old string
+ new_length = strlen + 1 //The length of the new
string the length of the old string plus the length of the character to be
appended (1)
+ max_length = GetMaxStringLength(strlen + 1) //Get maximum capacity of old
string, considering its trailing '\0'
+ old_addr = GetStringAddress(str)
+ if (old_addr < start_ptr) || ((new_length + 1) > max_length) { //If using
non-managed address or the old string's capacity doesn't suffice =>
allocate more memory
+ max_length = GetMaxStringLength(new_length + 1) //Consider trailing '\0'
+ new_addr = Alloc(max_length) //Allocate memory for
the new string, including the space for the end of string constant
+ if strlen > 0 { //Only copy old content
if there is content to copy
+ CopyMem(old_addr, new_addr, strlen) //Copy the content of the old
string to the newly allocated memory
+ }
+ } else { //Re-use old address as capacity suffices; no copy operation
necessary
+ new_addr = old_addr
+ }
+ char_addr = ToUint64FromBytePtr(&char)
+ CopyMem(char_addr, new_addr+strlen, 1) //Copy the additional character to
its according position at the end of the new string
+ nullByte_addr = ToUint64FromBytePtr(&nullByte)
+ CopyMem(nullByte_addr, new_addr+strlen+1, 1) //Append the end of
string constant
+ SetStringAddressAndLength(str, new_addr, new_length) //Update the string
in order to point to the new character sequence with the new length
}

//
@@ -122,32 +122,32 @@
// This function creates a new string by copying the first one and
appending the second one
//
func StringAppend(str *string, append_str string) {
- var nullByte byte = 0; //End of string constant
- var strlen uint64;
- var strappendlen uint64;
- var new_length uint64;
- var max_length uint64;
- var new_addr uint64;
- var old_addr uint64;
- var append_addr uint64;
- var nullByte_addr uint64;
- strlen = StringLength2(str); //Get length of first string
- max_length = GetMaxStringLength(strlen + 1); //Get maximum capacity of
old string, considering its trailing '\0'
- strappendlen = StringLength(append_str); //Get length of second string
- new_length = strlen + strappendlen; //The length of the new string is
the length of the first plus the length of the second string
- old_addr = GetStringAddress(str);
- if (old_addr < start_ptr) || ((new_length + 1) > max_length) { //If
using non-managed address or the old string's capacity doesn't suffice =>
allocate more memory
- max_length = GetMaxStringLength(new_length + 1); //Consider
trailing '\0'
- new_addr = Alloc(max_length); //Allocate memory for the new
string, including the space for the end of string constant
- if strlen > 0 { //Only copy old content if there is content to copy
- CopyMem(old_addr, new_addr, strlen); //Copy the content of the
old string to the newly allocated memory
- }
- } else { //Re-use old address as capacity suffices; no copy operation
necessary
- new_addr = old_addr;
- }
- append_addr = GetStringAddress(&append_str);
- CopyMem(append_addr, new_addr + strlen, strappendlen); //Copy the
second string to its according position at the end of the new string
- nullByte_addr = ToUint64FromBytePtr(&nullByte);
- CopyMem(nullByte_addr, new_addr + strlen + strappendlen, 1); //Append
the end of string constant
- SetStringAddressAndLength(str, new_addr, new_length); //Update the
string in order to point to the new character sequence with the new length
-}
+ var nullByte byte = 0 //End of string constant
+ var strlen uint64
+ var strappendlen uint64
+ var new_length uint64
+ var max_length uint64
+ var new_addr uint64
+ var old_addr uint64
+ var append_addr uint64
+ var nullByte_addr uint64
+ strlen = StringLength2(str) //Get length of first string
+ max_length = GetMaxStringLength(strlen + 1) //Get maximum capacity of old
string, considering its trailing '\0'
+ strappendlen = StringLength(append_str) //Get length of second string
+ new_length = strlen + strappendlen //The length of the new
string is the length of the first plus the length of the second string
+ old_addr = GetStringAddress(str)
+ if (old_addr < start_ptr) || ((new_length + 1) > max_length) { //If using
non-managed address or the old string's capacity doesn't suffice =>
allocate more memory
+ max_length = GetMaxStringLength(new_length + 1) //Consider trailing '\0'
+ new_addr = Alloc(max_length) //Allocate memory for
the new string, including the space for the end of string constant
+ if strlen > 0 { //Only copy old content
if there is content to copy
+ CopyMem(old_addr, new_addr, strlen) //Copy the content of the old
string to the newly allocated memory
+ }
+ } else { //Re-use old address as capacity suffices; no copy operation
necessary
+ new_addr = old_addr
+ }
+ append_addr = GetStringAddress(&append_str)
+ CopyMem(append_addr, new_addr+strlen, strappendlen) //Copy the second
string to its according position at the end of the new string
+ nullByte_addr = ToUint64FromBytePtr(&nullByte)
+ CopyMem(nullByte_addr, new_addr+strlen+strappendlen, 1) //Append the end
of string constant
+ SetStringAddressAndLength(str, new_addr, new_length) //Update the
string in order to point to the new character sequence with the new length
+}
=======================================
--- /src/libgogo/strlist.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/strlist.go Wed Aug 18 10:20:16 2010
@@ -12,25 +12,25 @@
// String list data structure
//
type StringList struct {
- internalList List; //List used internally
-};
+ internalList List //List used internally
+}

//
// Initializes the given string list
//
func InitializeStringList(uninitializedList *StringList) {
- InitializeList(&uninitializedList.internalList, 16); //A string has a
size of 16 bytes
+ InitializeList(&uninitializedList.internalList, 16) //A string has a size
of 16 bytes
}

//
// Adds an item to the given string list, increasing its capacity if
required
//
func AddStringItem(list *StringList, value string) {
- var newAddress uint64;
- var ptr *uint64;
- newAddress = ToUint64FromStringPtr(&value);
- ptr = ToUint64PtrFromUint64(newAddress);
- AddItem(&list.internalList, ptr);
+ var newAddress uint64
+ var ptr *uint64
+ newAddress = ToUint64FromStringPtr(&value)
+ ptr = ToUint64PtrFromUint64(newAddress)
+ AddItem(&list.internalList, ptr)
}

//
@@ -38,27 +38,27 @@
// Note that this function call fails if there are less than i items in
the list or if the list is empty
//
func GetStringItemAt(list *StringList, index uint64) string {
- var returnPtr *uint64;
- var returnAddr uint64;
- var returnValue string;
- var temp uint64;
- returnPtr = GetItemAt(&list.internalList, index);
- returnAddr = ToUint64FromUint64Ptr(returnPtr);
- temp = ToUint64FromStringPtr(&returnValue);
- CopyMem(returnAddr, temp, 16); //Copy the value into the return
variable
- return returnValue;
+ var returnPtr *uint64
+ var returnAddr uint64
+ var returnValue string
+ var temp uint64
+ returnPtr = GetItemAt(&list.internalList, index)
+ returnAddr = ToUint64FromUint64Ptr(returnPtr)
+ temp = ToUint64FromStringPtr(&returnValue)
+ CopyMem(returnAddr, temp, 16) //Copy the value into the return variable
+ return returnValue
}

//
// Returns the number of items in the given list
//
func GetStringListItemCount(list *StringList) uint64 {
- return list.internalList.itemCount;
+ return list.internalList.itemCount
}

//
// Returns the current capacity of the given list
//
func GetStringListCapacity(list *StringList) uint64 {
- return list.internalList.capacity;
-}
+ return list.internalList.capacity
+}
=======================================
--- /src/libgogo/symbol.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/symbol.go Wed Aug 18 10:20:16 2010
@@ -5,129 +5,130 @@
package libgogo

type ObjectDesc struct {
- Name string;
- PackageName string;
- Class uint64;
- ObjType *TypeDesc;
- PtrType uint64; //If 0, type objtype, otherwise type *objtype
- Next *ObjectDesc;
-};
+ Name string
+ PackageName string
+ Class uint64
+ ObjType *TypeDesc
+ PtrType uint64 //If 0, type objtype, otherwise type *objtype
+ Next *ObjectDesc
+}

type TypeDesc struct {
- Name string;
- PackageName string;
- ForwardDecl uint64; //If 1, type is forward declared
- Form uint64;
- Len uint64; // Len is array length if Base != nil, the size of the
type otherwise
- Fields *ObjectDesc;
- Base *TypeDesc; //If Form=FORM_FUNCTION, a value unequal nil indicates
that the function has been called at least once
- Next *TypeDesc;
-};
+ Name string
+ PackageName string
+ ForwardDecl uint64 //If 1, type is forward declared
+ Form uint64
+ Len uint64 // Len is array length if Base != nil, the size of the
type otherwise
+ Fields *ObjectDesc
+ Base *TypeDesc //If Form=FORM_FUNCTION, a value unequal nil
indicates that the function has been called at least once
+ Next *TypeDesc
+}

//
// Pseudo constants that specify the descriptor sizes
//
-var OBJECT_SIZE uint64 = 64; //8*8 bytes space for an object
-var TYPE_SIZE uint64 = 80; //10*8 bytes space for a type
+var OBJECT_SIZE uint64 = 64 //8*8 bytes space for an object
+var TYPE_SIZE uint64 = 80 //10*8 bytes space for a type

//
// Classes for objects
//
-var CLASS_VAR uint64 = 1;
-var CLASS_FIELD uint64 = 2;
-var CLASS_PARAMETER uint64 = 3;
+var CLASS_VAR uint64 = 1
+var CLASS_FIELD uint64 = 2
+var CLASS_PARAMETER uint64 = 3

//
// Forms for types
//
-var FORM_SIMPLE uint64 = 1;
-var FORM_STRUCT uint64 = 2;
-var FORM_ARRAY uint64 = 3;
-var FORM_FUNCTION uint64 = 4;
+var FORM_SIMPLE uint64 = 1
+var FORM_STRUCT uint64 = 2
+var FORM_ARRAY uint64 = 3
+var FORM_FUNCTION uint64 = 4

//
// Convert the uint64 value (returned from malloc) to a real object address
//
-func Uint64ToObjectDescPtr(adr uint64) *ObjectDesc;
+func Uint64ToObjectDescPtr(adr uint64) *ObjectDesc

//
// Convert the uint64 value (returned from malloc) to a real type object
address
//
-func Uint64ToTypeDescPtr(adr uint64) *TypeDesc;
+func Uint64ToTypeDescPtr(adr uint64) *TypeDesc


//
// Appends an object to the list
//
func AppendObject(object *ObjectDesc, list *ObjectDesc) *ObjectDesc {
- var tmpObj *ObjectDesc = object;
- if list != nil {
- for tmpObj = list; tmpObj.Next != nil; tmpObj = tmpObj.Next {
- }
- tmpObj.Next = object;
- tmpObj = list;
- }
- return tmpObj;
-
- //Alternate version: PrependObject:
- /*object.Next = list;
- return object;*/
+ var tmpObj *ObjectDesc = object
+ if list != nil {
+ for tmpObj = list; tmpObj.Next != nil; tmpObj = tmpObj.Next {
+ }
+ tmpObj.Next = object
+ tmpObj = list
+ }
+ return tmpObj
+
+ //Alternate version: PrependObject:
+ /*object.Next = list;
+ return object;*/
}

//
// Appends a type to the list
//
func AppendType(objtype *TypeDesc, list *TypeDesc) *TypeDesc {
- var tmpObjType *TypeDesc = objtype;
- if list != nil {
- for tmpObjType = list; tmpObjType.Next != nil; tmpObjType =
tmpObjType.Next { }
- tmpObjType.Next = objtype;
- tmpObjType = list;
- }
- return tmpObjType;
-
- //Alternate version: PrependType:
- /*objtype.Next = list;
- return objtype;*/
+ var tmpObjType *TypeDesc = objtype
+ if list != nil {
+ for tmpObjType = list; tmpObjType.Next != nil; tmpObjType =
tmpObjType.Next {
+ }
+ tmpObjType.Next = objtype
+ tmpObjType = list
+ }
+ return tmpObjType
+
+ //Alternate version: PrependType:
+ /*objtype.Next = list;
+ return objtype;*/
}

//
// Adds a field in form of an object descriptor to the type descriptor
given
//
func AddFields(object *ObjectDesc, objtype *TypeDesc) {
- objtype.Form = FORM_STRUCT;
- objtype.Fields = AppendObject(object, objtype.Fields);
+ objtype.Form = FORM_STRUCT
+ objtype.Fields = AppendObject(object, objtype.Fields)
}

//
// Returns 1 if the given (struct) type has a field with the given name,
or 0 otherwise
//
func HasField(name string, objtype *TypeDesc) uint64 {
- var tmpObj *ObjectDesc;
- var retVal uint64 = 0;
- tmpObj = GetField(name, objtype);
- if tmpObj != nil {
- retVal = 1;
- }
- return retVal;
+ var tmpObj *ObjectDesc
+ var retVal uint64 = 0
+ tmpObj = GetField(name, objtype)
+ if tmpObj != nil {
+ retVal = 1
+ }
+ return retVal
}

//
// Returns the given struct's field with the name given, or nil if a field
with that name does not exist
//
func GetField(name string, objtype *TypeDesc) *ObjectDesc {
- var tmpObj *ObjectDesc;
- tmpObj = GetObject(name, "", objtype.Fields);
- return tmpObj;
+ var tmpObj *ObjectDesc
+ tmpObj = GetObject(name, "", objtype.Fields)
+ return tmpObj
}

//
// Adds a parameter in form of an object descriptor to the function (type
descriptor) given
//
func AddParameters(object *ObjectDesc, fcn *TypeDesc) {
- fcn.Form = FORM_FUNCTION;
- fcn.Fields = AppendObject(object, fcn.Fields);
- fcn.Len = fcn.Len + 1; //Increase number of parameters
+ fcn.Form = FORM_FUNCTION
+ fcn.Fields = AppendObject(object, fcn.Fields)
+ fcn.Len = fcn.Len + 1 //Increase number of parameters
}

//
@@ -135,49 +136,49 @@
// Same semantics as sizeof(objtype)
//
func GetTypeSize(objtype *TypeDesc) uint64 {
- var size uint64 = 0;
- var tempobj *ObjectDesc;
- var tmpSize uint64;
- if objtype != nil {
- if objtype.ForwardDecl == 0 {
- if objtype.Form == FORM_SIMPLE {
- size = objtype.Len;
- }
- if objtype.Form == FORM_STRUCT {
- for tempobj = objtype.Fields; tempobj != nil; tempobj =
tempobj.Next { //Sum of all fields
- tmpSize = GetObjectSizeAligned(tempobj);
- size = size + tmpSize; //Add size of each field
- }
- }
- if objtype.Form == FORM_ARRAY {
- tmpSize = GetTypeSize(objtype.Base); //Get unaligned size
of base type
- size = objtype.Len * tmpSize; //Array length * size of one
item
- size = AlignTo64Bit(size); //Align to 64 bit
- }
- } else {
- ; //TODO: if type is only forward declared => error!
- }
- } else {
- ; //TODO: if objtype is nil => error!
- }
- return size;
+ var size uint64 = 0
+ var tempobj *ObjectDesc
+ var tmpSize uint64
+ if objtype != nil {
+ if objtype.ForwardDecl == 0 {
+ if objtype.Form == FORM_SIMPLE {
+ size = objtype.Len
+ }
+ if objtype.Form == FORM_STRUCT {
+ for tempobj = objtype.Fields; tempobj != nil; tempobj = tempobj.Next {
//Sum of all fields
+ tmpSize = GetObjectSizeAligned(tempobj)
+ size = size + tmpSize //Add size of each field
+ }
+ }
+ if objtype.Form == FORM_ARRAY {
+ tmpSize = GetTypeSize(objtype.Base) //Get unaligned size of base type
+ size = objtype.Len * tmpSize //Array length * size of one item
+ size = AlignTo64Bit(size) //Align to 64 bit
+ }
+ } else {
+ //TODO: if type is only forward declared => error!
+ }
+ } else {
+ //TODO: if objtype is nil => error!
+ }
+ return size
}

//
// Returns a 64 bit aligned address of the given one
//
func AlignTo64Bit(adr uint64) uint64 {
- return ((adr + 7) / 8) * 8;
+ return ((adr + 7) / 8) * 8
}

//
// Returns the aligned (memory) size of the given type in bytes
//
func GetTypeSizeAligned(objtype *TypeDesc) uint64 {
- var size uint64;
- size = GetTypeSize(objtype);
- size = AlignTo64Bit(size); //64 bit alignment
- return size;
+ var size uint64
+ size = GetTypeSize(objtype)
+ size = AlignTo64Bit(size) //64 bit alignment
+ return size
}

//
@@ -185,23 +186,23 @@
// Same semantics as sizeof(obj)
//
func GetObjectSize(obj *ObjectDesc) uint64 {
- var size uint64;
- if obj.PtrType == 1 {
- size = 8;
- } else { //Actual type
- size = GetTypeSize(obj.ObjType);
- }
- return size;
+ var size uint64
+ if obj.PtrType == 1 {
+ size = 8
+ } else { //Actual type
+ size = GetTypeSize(obj.ObjType)
+ }
+ return size
}

//
// Returns the aligned size required by the object in bytes, considering
whether or not the object is a pointer
//
func GetObjectSizeAligned(obj *ObjectDesc) uint64 {
- var size uint64;
- size = GetObjectSize(obj);
- size = AlignTo64Bit(size); //64 bit alignment
- return size;
+ var size uint64
+ size = GetObjectSize(obj)
+ size = AlignTo64Bit(size) //64 bit alignment
+ return size
}

//
@@ -209,20 +210,20 @@
// Note that the calculated size always 64 bit aligned
//
func GetObjectOffset(obj *ObjectDesc, list *ObjectDesc) uint64 {
- var offset uint64 = 0;
- var tmp *ObjectDesc;
- var tmpSize uint64;
- for tmp = list; tmp != nil; tmp = tmp.Next {
- if tmp == obj {
- break;
- }
- tmpSize = GetObjectSizeAligned(tmp);
- offset = offset + tmpSize; //Add field size
- }
- if tmp == nil {
- offset = 0; //TODO: Raise error as obj is appearently not in the
list
- }
- return offset;
+ var offset uint64 = 0
+ var tmp *ObjectDesc
+ var tmpSize uint64
+ for tmp = list; tmp != nil; tmp = tmp.Next {
+ if tmp == obj {
+ break
+ }
+ tmpSize = GetObjectSizeAligned(tmp)
+ offset = offset + tmpSize //Add field size
+ }
+ if tmp == nil {
+ offset = 0 //TODO: Raise error as obj is appearently not in the list
+ }
+ return offset
}

//
@@ -230,9 +231,9 @@
// Note that the calculated size always 64 bit aligned
//
func GetFieldOffset(obj *ObjectDesc, objtype *TypeDesc) uint64 {
- var offset uint64;
- offset = GetObjectOffset(obj, objtype.Fields);
- return offset;
+ var offset uint64
+ offset = GetObjectOffset(obj, objtype.Fields)
+ return offset
}

//
@@ -240,40 +241,40 @@
// Note that the calculated size is always 64 bit aligned
//
func GetAlignedObjectListSize(objList *ObjectDesc) uint64 {
- var i uint64 = 0; //Init data segment size with 0 in case there are no
global objects
- var j uint64;
- var lastObj *ObjectDesc = objList; //Initialize last object with the
beginning of the global variable list
- var obj *ObjectDesc;
- for obj = objList; obj != nil; obj = obj.Next { //Calculate offset of
last global variable //TODO: Do this more efficiently
- i = GetObjectOffset(obj, objList);
- lastObj = obj;
- }
- if lastObj != nil { //Add size of last object to its offset in order
to get the total size required for the data segment
- j = GetObjectSizeAligned(lastObj);
- i = i + j;
- }
- return i;
+ var i uint64 = 0 //Init data segment size with 0 in case there are no
global objects
+ var j uint64
+ var lastObj *ObjectDesc = objList //Initialize last object with the
beginning of the global variable list
+ var obj *ObjectDesc
+ for obj = objList; obj != nil; obj = obj.Next { //Calculate offset of
last global variable //TODO: Do this more efficiently
+ i = GetObjectOffset(obj, objList)
+ lastObj = obj
+ }
+ if lastObj != nil { //Add size of last object to its offset in order to
get the total size required for the data segment
+ j = GetObjectSizeAligned(lastObj)
+ i = i + j
+ }
+ return i
}

//
// Fetches an object with a specific identifier or nil if it is not in the
specified list
//
func GetObject(name string, packagename string, list *ObjectDesc)
*ObjectDesc {
- var tmpObject *ObjectDesc;
- var retValue *ObjectDesc = nil;
- var nameCompare uint64;
- var strLen uint64;
- var packageNameCompare uint64;
- for tmpObject = list; tmpObject != nil; tmpObject = tmpObject.Next {
- nameCompare = StringCompare(tmpObject.Name,name);
- strLen = StringLength(tmpObject.PackageName);
- packageNameCompare =
StringCompare(tmpObject.PackageName,packagename);
- if (nameCompare == 0) && ((strLen == 0) || (packageNameCompare ==
0)) { //Empty package name indicates internal types
- retValue = tmpObject;
- break;
- }
- }
- return retValue;
+ var tmpObject *ObjectDesc
+ var retValue *ObjectDesc = nil
+ var nameCompare uint64
+ var strLen uint64
+ var packageNameCompare uint64
+ for tmpObject = list; tmpObject != nil; tmpObject = tmpObject.Next {
+ nameCompare = StringCompare(tmpObject.Name, name)
+ strLen = StringLength(tmpObject.PackageName)
+ packageNameCompare = StringCompare(tmpObject.PackageName, packagename)
+ if (nameCompare == 0) && ((strLen == 0) || (packageNameCompare == 0)) {
//Empty package name indicates internal types
+ retValue = tmpObject
+ break
+ }
+ }
+ return retValue
}

//
@@ -281,23 +282,23 @@
// If includeforward is 0, no forward declared types will be returned;
otherwise, forward declared types will also be returned
//
func GetType(name string, packagename string, list *TypeDesc,
includeforward uint64) *TypeDesc {
- var tmpType *TypeDesc;
- var retValue *TypeDesc = nil;
- var nameCompare uint64;
- var strLen uint64;
- var packageNameCompare uint64;
- for tmpType = list; tmpType != nil; tmpType = tmpType.Next {
- nameCompare = StringCompare(tmpType.Name,name);
- strLen = StringLength(tmpType.PackageName);
- packageNameCompare =
StringCompare(tmpType.PackageName,packagename);
- if (nameCompare == 0) && ((strLen == 0) || (packageNameCompare ==
0)) { //Empty package name indicates internal types
- if (includeforward == 1) || ((includeforward == 0) &&
(tmpType.ForwardDecl == 0)) {
- retValue = tmpType;
- break;
- }
- }
- }
- return retValue;
+ var tmpType *TypeDesc
+ var retValue *TypeDesc = nil
+ var nameCompare uint64
+ var strLen uint64
+ var packageNameCompare uint64
+ for tmpType = list; tmpType != nil; tmpType = tmpType.Next {
+ nameCompare = StringCompare(tmpType.Name, name)
+ strLen = StringLength(tmpType.PackageName)
+ packageNameCompare = StringCompare(tmpType.PackageName, packagename)
+ if (nameCompare == 0) && ((strLen == 0) || (packageNameCompare == 0)) {
//Empty package name indicates internal types
+ if (includeforward == 1) || ((includeforward == 0) &&
(tmpType.ForwardDecl == 0)) {
+ retValue = tmpType
+ break
+ }
+ }
+ }
+ return retValue
}

//
@@ -305,17 +306,17 @@
// Returns 1 if an object has been found, or 0 otherwise
//
func FindPackageName(packagename string, list *ObjectDesc) uint64 {
- var retVal uint64 = 0;
- var tmpObj *ObjectDesc;
- var packageNameCompare uint64;
- for tmpObj = list; tmpObj != nil; tmpObj = tmpObj.Next {
- packageNameCompare = StringCompare(tmpObj.PackageName,
packagename);
- if packageNameCompare == 0 {
- retVal = 1;
- break;
- }
- }
- return retVal;
+ var retVal uint64 = 0
+ var tmpObj *ObjectDesc
+ var packageNameCompare uint64
+ for tmpObj = list; tmpObj != nil; tmpObj = tmpObj.Next {
+ packageNameCompare = StringCompare(tmpObj.PackageName, packagename)
+ if packageNameCompare == 0 {
+ retVal = 1
+ break
+ }
+ }
+ return retVal
}

//
@@ -323,17 +324,17 @@
// Returns 1 if an object has been found, or 0 otherwise
//
func FindTypePackageName(packagename string, list *TypeDesc) uint64 {
- var retVal uint64 = 0;
- var tmpObj *TypeDesc;
- var packageNameCompare uint64;
- for tmpObj = list; tmpObj != nil; tmpObj = tmpObj.Next {
- packageNameCompare = StringCompare(tmpObj.PackageName,
packagename);
- if packageNameCompare == 0 {
- retVal = 1;
- break;
- }
- }
- return retVal;
+ var retVal uint64 = 0
+ var tmpObj *TypeDesc
+ var packageNameCompare uint64
+ for tmpObj = list; tmpObj != nil; tmpObj = tmpObj.Next {
+ packageNameCompare = StringCompare(tmpObj.PackageName, packagename)
+ if packageNameCompare == 0 {
+ retVal = 1
+ break
+ }
+ }
+ return retVal
}

//
@@ -341,206 +342,206 @@
// Note that counting starts at 1, not at 0!
//
func GetParameterAt(index uint64, list *TypeDesc) *ObjectDesc {
- var retValue *ObjectDesc;
- for retValue = list.Fields; retValue != nil; retValue = retValue.Next {
- index = index - 1;
- if index == 0 {
- break;
- }
- }
- return retValue;
+ var retValue *ObjectDesc
+ for retValue = list.Fields; retValue != nil; retValue = retValue.Next {
+ index = index - 1
+ if index == 0 {
+ break
+ }
+ }
+ return retValue
}

//
// Creates a new object
//
func NewObject(name string, packagename string, class uint64) *ObjectDesc {
- var adr uint64;
- var obj *ObjectDesc;
- adr = Alloc(OBJECT_SIZE);
- obj = Uint64ToObjectDescPtr(adr);
- obj.Name = name; //TODO: Copy string?
- obj.PackageName = packagename; //Copy string?
- obj.Class = class;
- obj.ObjType = nil;
- obj.PtrType = 0;
- obj.Next = nil;
- return obj;
+ var adr uint64
+ var obj *ObjectDesc
+ adr = Alloc(OBJECT_SIZE)
+ obj = Uint64ToObjectDescPtr(adr)
+ obj.Name = name //TODO: Copy string?
+ obj.PackageName = packagename //Copy string?
+ obj.Class = class
+ obj.ObjType = nil
+ obj.PtrType = 0
+ obj.Next = nil
+ return obj
}

//
// Creates a new type
//
func NewType(name string, packagename string, forwarddecl uint64, len
uint64, basetype *TypeDesc) *TypeDesc {
- var adr uint64;
- var objtype *TypeDesc;
- adr = Alloc(TYPE_SIZE);
- objtype = Uint64ToTypeDescPtr(adr);
- objtype.Name = name; //TODO: Copy string?
- objtype.ForwardDecl = forwarddecl;
- objtype.PackageName = packagename; //TODO: Copy string?
- if basetype != nil {
- objtype.Form = FORM_ARRAY;
- } else {
- objtype.Form = FORM_SIMPLE;
- }
- objtype.Len = len;
- objtype.Next = nil;
- objtype.Fields = nil;
- objtype.Base = basetype;
- return objtype;
+ var adr uint64
+ var objtype *TypeDesc
+ adr = Alloc(TYPE_SIZE)
+ objtype = Uint64ToTypeDescPtr(adr)
+ objtype.Name = name //TODO: Copy string?
+ objtype.ForwardDecl = forwarddecl
+ objtype.PackageName = packagename //TODO: Copy string?
+ if basetype != nil {
+ objtype.Form = FORM_ARRAY
+ } else {
+ objtype.Form = FORM_SIMPLE
+ }
+ objtype.Len = len
+ objtype.Next = nil
+ objtype.Fields = nil
+ objtype.Base = basetype
+ return objtype
}

//
// Prints a formatted output of a given list of objects, including type,
size etc.
//
func PrintObjects(list *ObjectDesc) {
- var o *ObjectDesc;
- var strLen uint64;
- var tmp uint64;
- for o = list; o != nil; o = o.Next {
- PrintString("Object ");
- strLen = StringLength(o.PackageName);
- if strLen != 0 {
- PrintString(o.PackageName);
- PrintChar('.');
- }
- PrintString(o.Name);
- PrintString(" (type: ");
- if o.PtrType != 0 {
- PrintString("pointer to ");
- }
- if o.ObjType != nil {
- if o.ObjType.Base != nil {
- PrintString("array of ");
- PrintString(o.ObjType.Base.Name);
- PrintString(" of length ");
- PrintNumber(o.ObjType.Len);
- PrintString(", internally named ");
- }
- strLen = StringLength(o.ObjType.PackageName);
- if strLen != 0 {
- PrintString(o.ObjType.PackageName);
- PrintChar('.');
- }
- PrintString(o.ObjType.Name);
- } else {
- PrintString("<unknown>");
- }
- PrintString(", size: ");
- tmp = GetObjectSize(o);
- PrintNumber(tmp);
- PrintString(", offset: ");
- tmp = GetObjectOffset(o, list);
- PrintNumber(tmp);
- PrintString(")\n");
- }
+ var o *ObjectDesc
+ var strLen uint64
+ var tmp uint64
+ for o = list; o != nil; o = o.Next {
+ PrintString("Object ")
+ strLen = StringLength(o.PackageName)
+ if strLen != 0 {
+ PrintString(o.PackageName)
+ PrintChar('.')
+ }
+ PrintString(o.Name)
+ PrintString(" (type: ")
+ if o.PtrType != 0 {
+ PrintString("pointer to ")
+ }
+ if o.ObjType != nil {
+ if o.ObjType.Base != nil {
+ PrintString("array of ")
+ PrintString(o.ObjType.Base.Name)
+ PrintString(" of length ")
+ PrintNumber(o.ObjType.Len)
+ PrintString(", internally named ")
+ }
+ strLen = StringLength(o.ObjType.PackageName)
+ if strLen != 0 {
+ PrintString(o.ObjType.PackageName)
+ PrintChar('.')
+ }
+ PrintString(o.ObjType.Name)
+ } else {
+ PrintString("<unknown>")
+ }
+ PrintString(", size: ")
+ tmp = GetObjectSize(o)
+ PrintNumber(tmp)
+ PrintString(", offset: ")
+ tmp = GetObjectOffset(o, list)
+ PrintNumber(tmp)
+ PrintString(")\n")
+ }
}

//
// Prints a formatted output of a given list of types, including form,
size etc.
//
func PrintTypes(list *TypeDesc) {
- var t *TypeDesc;
- var o *ObjectDesc;
- var strLen uint64;
- var tmp uint64;
- for t = list; t != nil; t = t.Next {
- PrintString("Type ");
- strLen = StringLength(t.PackageName);
- if strLen != 0 {
- PrintString(t.PackageName);
- PrintChar('.');
- }
- PrintString(t.Name);
- PrintString(" (size: ");
- tmp = GetTypeSize(t);
- PrintNumber(tmp);
- PrintString(")\n");
- for o = t.Fields; o != nil; o = o.Next {
- PrintString(" ");
- PrintString(o.Name);
- PrintString(" (type: ");
- if o.PtrType != 0 {
- PrintString("pointer to ");
- }
- if o.ObjType != nil {
- if o.ObjType.Base != nil {
- PrintString("array of ");
- PrintString(o.ObjType.Base.Name);
- PrintString(" of length ");
- PrintNumber(o.ObjType.Len);
- PrintString(", internally named ");
- }
- strLen = StringLength(o.ObjType.PackageName);
- if strLen != 0 {
- PrintString(o.ObjType.PackageName);
- PrintChar('.');
- }
- PrintString(o.ObjType.Name);
- } else {
- PrintString("<unknown>");
- }
- PrintString(", size: ");
- tmp = GetObjectSize(o);
- PrintNumber(tmp);
- PrintString(", offset: ");
- tmp = GetObjectOffset(o, t.Fields);
- PrintNumber(tmp);
- PrintString(")\n");
- }
- }
+ var t *TypeDesc
+ var o *ObjectDesc
+ var strLen uint64
+ var tmp uint64
+ for t = list; t != nil; t = t.Next {
+ PrintString("Type ")
+ strLen = StringLength(t.PackageName)
+ if strLen != 0 {
+ PrintString(t.PackageName)
+ PrintChar('.')
+ }
+ PrintString(t.Name)
+ PrintString(" (size: ")
+ tmp = GetTypeSize(t)
+ PrintNumber(tmp)
+ PrintString(")\n")
+ for o = t.Fields; o != nil; o = o.Next {
+ PrintString(" ")
+ PrintString(o.Name)
+ PrintString(" (type: ")
+ if o.PtrType != 0 {
+ PrintString("pointer to ")
+ }
+ if o.ObjType != nil {
+ if o.ObjType.Base != nil {
+ PrintString("array of ")
+ PrintString(o.ObjType.Base.Name)
+ PrintString(" of length ")
+ PrintNumber(o.ObjType.Len)
+ PrintString(", internally named ")
+ }
+ strLen = StringLength(o.ObjType.PackageName)
+ if strLen != 0 {
+ PrintString(o.ObjType.PackageName)
+ PrintChar('.')
+ }
+ PrintString(o.ObjType.Name)
+ } else {
+ PrintString("<unknown>")
+ }
+ PrintString(", size: ")
+ tmp = GetObjectSize(o)
+ PrintNumber(tmp)
+ PrintString(", offset: ")
+ tmp = GetObjectOffset(o, t.Fields)
+ PrintNumber(tmp)
+ PrintString(")\n")
+ }
+ }
}

//
// Prints a formatted output of a given list of functions, including
parameters etc.
//
func PrintFunctions(list *TypeDesc) {
- var t *TypeDesc;
- var o *ObjectDesc;
- var strLen uint64;
- var tmp uint64;
- for t = list; t != nil; t = t.Next {
- PrintString("Function ");
- PrintString(t.PackageName);
- PrintChar('.');
- PrintString(t.Name);
- PrintString(" (number of parameters: ");
- PrintNumber(t.Len);
- PrintString(")\n");
- for o = t.Fields; o != nil; o = o.Next {
- PrintString(" ");
- PrintString(o.Name);
- PrintString(" (type: ");
- if o.PtrType != 0 {
- PrintString("pointer to ");
- }
- if o.ObjType != nil {
- if o.ObjType.Base != nil {
- PrintString("array of ");
- PrintString(o.ObjType.Base.Name);
- PrintString(" of length ");
- PrintNumber(o.ObjType.Len);
- PrintString(", internally named ");
- }
- strLen = StringLength(o.ObjType.PackageName);
- if strLen != 0 {
- PrintString(o.ObjType.PackageName);
- PrintChar('.');
- }
- PrintString(o.ObjType.Name);
- } else {
- PrintString("<unknown>");
- }
- PrintString(", size: ");
- tmp = GetObjectSize(o);
- PrintNumber(tmp);
- PrintString(", offset: ");
- tmp = GetObjectOffset(o, t.Fields);
- PrintNumber(tmp);
- PrintString(")\n");
- }
- }
+ var t *TypeDesc
+ var o *ObjectDesc
+ var strLen uint64
+ var tmp uint64
+ for t = list; t != nil; t = t.Next {
+ PrintString("Function ")
+ PrintString(t.PackageName)
+ PrintChar('.')
+ PrintString(t.Name)
+ PrintString(" (number of parameters: ")
+ PrintNumber(t.Len)
+ PrintString(")\n")
+ for o = t.Fields; o != nil; o = o.Next {
+ PrintString(" ")
+ PrintString(o.Name)
+ PrintString(" (type: ")
+ if o.PtrType != 0 {
+ PrintString("pointer to ")
+ }
+ if o.ObjType != nil {
+ if o.ObjType.Base != nil {
+ PrintString("array of ")
+ PrintString(o.ObjType.Base.Name)
+ PrintString(" of length ")
+ PrintNumber(o.ObjType.Len)
+ PrintString(", internally named ")
+ }
+ strLen = StringLength(o.ObjType.PackageName)
+ if strLen != 0 {
+ PrintString(o.ObjType.PackageName)
+ PrintChar('.')
+ }
+ PrintString(o.ObjType.Name)
+ } else {
+ PrintString("<unknown>")
+ }
+ PrintString(", size: ")
+ tmp = GetObjectSize(o)
+ PrintNumber(tmp)
+ PrintString(", offset: ")
+ tmp = GetObjectOffset(o, t.Fields)
+ PrintNumber(tmp)
+ PrintString(")\n")
+ }
+ }
}

//
@@ -548,39 +549,39 @@
// Syntax per item:
FUNC,forwarddecl,package,name,parameter1name:parameter1type,parameter2name:parameter2type...
//
func SymbolTableFunctionsToStringList(list *TypeDesc, result *StringList) {
- var t *TypeDesc;
- var o *ObjectDesc;
- var temp string;
- var temp2 string;
- for t = list; t != nil; t = t.Next {
- temp = "FUNC,";
- temp2 = IntToString(t.ForwardDecl);
- StringAppend(&temp, temp2);
- StringAppend(&temp, ",");
- StringAppend(&temp, t.PackageName);
- StringAppend(&temp, "·");
- StringAppend(&temp, t.Name);
- o = t.Fields;
- if o != nil {
- StringAppend(&temp, ",");
- }
- for ; o != nil; o = o.Next {
- StringAppend(&temp, o.Name);
- StringAppend(&temp, ":");
- if o.PtrType != 0 {
- CharAppend(&temp, '*');
- }
- if o.ObjType != nil {
- StringAppend(&temp, o.ObjType.PackageName);
- StringAppend(&temp, "·");
- StringAppend(&temp, o.ObjType.Name);
- }
- if o.Next != nil {
- StringAppend(&temp, ",");
- }
- }
- AddStringItem(result, temp);
- }
+ var t *TypeDesc
+ var o *ObjectDesc
+ var temp string
+ var temp2 string
+ for t = list; t != nil; t = t.Next {
+ temp = "FUNC,"
+ temp2 = IntToString(t.ForwardDecl)
+ StringAppend(&temp, temp2)
+ StringAppend(&temp, ",")
+ StringAppend(&temp, t.PackageName)
+ StringAppend(&temp, "·")
+ StringAppend(&temp, t.Name)
+ o = t.Fields
+ if o != nil {
+ StringAppend(&temp, ",")
+ }
+ for ; o != nil; o = o.Next {
+ StringAppend(&temp, o.Name)
+ StringAppend(&temp, ":")
+ if o.PtrType != 0 {
+ CharAppend(&temp, '*')
+ }
+ if o.ObjType != nil {
+ StringAppend(&temp, o.ObjType.PackageName)
+ StringAppend(&temp, "·")
+ StringAppend(&temp, o.ObjType.Name)
+ }
+ if o.Next != nil {
+ StringAppend(&temp, ",")
+ }
+ }
+ AddStringItem(result, temp)
+ }
}

//
@@ -588,26 +589,26 @@
// Syntax per item: TYPE,package.name,size,aligned_size
//
func SymbolTableTypesToStringList(list *TypeDesc, result *StringList) {
- var t *TypeDesc;
- var temp string;
- var tmp uint64;
- var temp2 string;
- for t = list; t != nil; t = t.Next {
- temp = "TYPE,";
- temp2 = IntToString(t.ForwardDecl);
- StringAppend(&temp, temp2);
- StringAppend(&temp, ",");
- StringAppend(&temp, t.PackageName);
- StringAppend(&temp, "·");
- StringAppend(&temp, t.Name);
- StringAppend(&temp, ",");
- tmp = GetTypeSize(t);
- temp2 = IntToString(tmp);
- StringAppend(&temp, temp2);
- StringAppend(&temp, ",");
***The diff for this file has been truncated for email.***
=======================================
--- /src/libgogo/test/libgogotest.go Tue Aug 17 09:58:38 2010
+++ /src/libgogo/test/libgogotest.go Wed Aug 18 10:20:16 2010
@@ -10,125 +10,125 @@

func main() {
if len(os.Args) != 2 {
- fmt.Printf("Usage: libgogotest file\n");
- return;
+ fmt.Printf("Usage: libgogotest file\n")
+ return
}

- //Library test I
- const test_text string = "Hello world\n";
- const test_len uint64 = 12;
- var test_ret uint64;
- fmt.Printf("Library test (should write Hello world): ");
- test_ret = libgogo.Write(1, test_text, test_len);
- fmt.Printf("Library test (should write %d and %d): %d and %d\n",
test_len, test_len, test_ret, libgogo.StringLength(test_text));
-
- //Library test II
- var fd uint64;
- var ten_char_string string = "##########";
- var read_ret uint64;
- fd = libgogo.FileOpen(os.Args[1], 0);
- fmt.Printf("Library test for '%s' (should neither be 0 nor -1): %d\n",
os.Args[1], fd);
- read_ret = libgogo.Read(fd, ten_char_string, 10);
- var next_byte byte;
- next_byte = libgogo.GetChar(fd);
- fmt.Printf("Library test (should write the first 11 characters of '%s'
and 10): '%s%c' and %d\n", os.Args[1], ten_char_string, next_byte,
read_ret);
- libgogo.FileClose(fd);
-
- //Library test III
- var testString string = "Hell";
- testString += "o";
- fmt.Printf("Library test: string length of '%s' (len vs. myLen): %d
vs. %d\n", testString, len(testString), libgogo.StringLength(testString));
- var testStringPtr *string = &testString;
- fmt.Printf("Library test 2: string length 2 of '%s' (len vs. myLen): %d
vs. %d\n", *testStringPtr, len(*testStringPtr),
libgogo.StringLength2(testStringPtr));
- fmt.Printf("Library test: '%s' and '", testString);
- libgogo.PrintString(testString);
- fmt.Printf("' are identical\n");
-
- //Library test IV
- var chr byte = '\n';
- for fd = libgogo.FileOpen(os.Args[1], 0); chr != 0; chr =
libgogo.GetChar(fd) {
- //libgogo.PrintChar(chr);
- }
- libgogo.FileClose(fd);
-
- //Library test V
- var oldsize uint64 = libgogo.GetBrk();
- if oldsize != 0 {
- fmt.Printf("Brk returned: %d\n", oldsize);
- var newsize uint64 = oldsize + 100 * 1024 * 1024;
- var errno uint64 = libgogo.Brk(newsize);
- if errno == 0 {
- fmt.Printf("Brk successfully allocated 100 MB\n");
- var newreadsize uint64 = libgogo.GetBrk();
- if newreadsize != 0 {
- fmt.Printf("Brk returned: %d, so %d MB of space have been
allocated\n", newreadsize, (newreadsize - oldsize) >> 20);
- newreadsize = libgogo.TestMem(oldsize + 1);
- if newreadsize == 0 {
- fmt.Printf("Successfully wrote to address %d\n", oldsize + 1);
- } else {
- fmt.Printf("Failed to write to address %d\n", oldsize + 1);
- }
- }
- } else {
- fmt.Printf("Brk failed to allocate 100 MB: errno %d\n", errno);
- }
- } else {
- fmt.Printf("Brk failed\n");
- }
-
- //Library test VI
- var a uint64 = 0;
- var someString string = libgogo.IntToString(a);
- fmt.Printf("Library test: %s (should be '0')\n", someString);
-
- //Library test VII
- var test_str string = "Hello ";
- var test_appendstr string = "world";
- libgogo.StringAppend(&test_str, test_appendstr);
- libgogo.PrintString(test_str);
- libgogo.PrintString("\n");
-
- //Library test VIII
- var stack libgogo.Stack;
- libgogo.InitializeStack(&stack);
- fmt.Printf("Stack initialized: item count: %d, capacity: %d\n",
libgogo.GetStackItemCount(&stack), libgogo.GetStackCapacity(&stack));
- var val uint64;
- fmt.Printf("Pushing the 20 values onto the stack\n");
- for val = 1; val <= 20; val++ {
- libgogo.Push(&stack, val);
- //fmt.Printf("DEBUG %d: item count: %d, capacity: %d, peek
item: %d\n", val, libgogo.GetStackItemCount(&stack),
libgogo.GetStackCapacity(&stack), libgogo.Peek(&stack));
- }
- fmt.Printf("Taking 19 values from the stack\n");
- var j uint64;
- for j = 20; j > 1; j-- {
- val = libgogo.Pop(&stack);
- //fmt.Printf("DEBUG %d: item count: %d, capacity: %d, peek
item: %d\n", j, libgogo.GetStackItemCount(&stack),
libgogo.GetStackCapacity(&stack), libgogo.Peek(&stack));
- if (j != val) {
- fmt.Printf("ERROR: Unexpected value from stack: %d (should
be %d)\n", val, j);
- }
- }
- fmt.Printf("Library test: Number of values left on stack and peek value
(should both be 1): %d and %d\n", libgogo.GetStackItemCount(&stack),
libgogo.Peek(&stack));
-
- //Library test IX
- var list libgogo.List;
- libgogo.InitializeList(&list, 8);
- fmt.Printf("List initialized: item count: %d, capacity: %d\n",
libgogo.GetListItemCount(&list), libgogo.GetListCapacity(&list));
- fmt.Printf("Putting the 20 values into the list\n");
- for val = 1; val <= 20; val++ {
- libgogo.AddItem(&list, &val);
- //fmt.Printf("DEBUG %d: item count: %d, capacity: %d, first item: %d,
last item: %d\n", val, libgogo.GetListItemCount(&list),
libgogo.GetListCapacity(&list), libgogo.GetItemAt(&list, 0),
libgogo.GetItemAt(&list, libgogo.GetListItemCount(&list) - 1));
- }
- fmt.Printf("Removing 19 values from the list\n");
- for j = 1; j < 20; j++ {
- val = *(libgogo.RemoveItemAt(&list, 0));
- //fmt.Printf("DEBUG %d: item count: %d, capacity: %d, first item: %d,
last item: %d\n", j, libgogo.GetListItemCount(&list),
libgogo.GetListCapacity(&list), libgogo.GetItemAt(&list, 0),
libgogo.GetItemAt(&list, libgogo.GetListItemCount(&list) - 1));
- if (j != val) {
- fmt.Printf("ERROR: Unexpected value from list: %d (should be %d)\n",
val, j);
- }
- }
- fmt.Printf("Library test: Number of values left in list and value
(should be 1 and 20): %d and %d\n", libgogo.GetListItemCount(&list),
*libgogo.GetItemAt(&list, 0));
-
- //Library test X
- libgogo.Exit(0);
- fmt.Printf("If you can read this, something is wrong");
-}
+ //Library test I
+ const test_text string = "Hello world\n"
+ const test_len uint64 = 12
+ var test_ret uint64
+ fmt.Printf("Library test (should write Hello world): ")
+ test_ret = libgogo.Write(1, test_text, test_len)
+ fmt.Printf("Library test (should write %d and %d): %d and %d\n",
test_len, test_len, test_ret, libgogo.StringLength(test_text))
+
+ //Library test II
+ var fd uint64
+ var ten_char_string string = "##########"
+ var read_ret uint64
+ fd = libgogo.FileOpen(os.Args[1], 0)
+ fmt.Printf("Library test for '%s' (should neither be 0 nor -1): %d\n",
os.Args[1], fd)
+ read_ret = libgogo.Read(fd, ten_char_string, 10)
+ var next_byte byte
+ next_byte = libgogo.GetChar(fd)
+ fmt.Printf("Library test (should write the first 11 characters of '%s'
and 10): '%s%c' and %d\n", os.Args[1], ten_char_string, next_byte, read_ret)
+ libgogo.FileClose(fd)
+
+ //Library test III
+ var testString string = "Hell"
+ testString += "o"
+ fmt.Printf("Library test: string length of '%s' (len vs. myLen): %d
vs. %d\n", testString, len(testString), libgogo.StringLength(testString))
+ var testStringPtr *string = &testString
+ fmt.Printf("Library test 2: string length 2 of '%s' (len vs. myLen): %d
vs. %d\n", *testStringPtr, len(*testStringPtr),
libgogo.StringLength2(testStringPtr))
+ fmt.Printf("Library test: '%s' and '", testString)
+ libgogo.PrintString(testString)
+ fmt.Printf("' are identical\n")
+
+ //Library test IV
+ var chr byte = '\n'
+ for fd = libgogo.FileOpen(os.Args[1], 0); chr != 0; chr =
libgogo.GetChar(fd) {
+ //libgogo.PrintChar(chr);
+ }
+ libgogo.FileClose(fd)
+
+ //Library test V
+ var oldsize uint64 = libgogo.GetBrk()
+ if oldsize != 0 {
+ fmt.Printf("Brk returned: %d\n", oldsize)
+ var newsize uint64 = oldsize + 100*1024*1024
+ var errno uint64 = libgogo.Brk(newsize)
+ if errno == 0 {
+ fmt.Printf("Brk successfully allocated 100 MB\n")
+ var newreadsize uint64 = libgogo.GetBrk()
+ if newreadsize != 0 {
+ fmt.Printf("Brk returned: %d, so %d MB of space have been
allocated\n", newreadsize, (newreadsize-oldsize)>>20)
+ newreadsize = libgogo.TestMem(oldsize + 1)
+ if newreadsize == 0 {
+ fmt.Printf("Successfully wrote to address %d\n", oldsize+1)
+ } else {
+ fmt.Printf("Failed to write to address %d\n", oldsize+1)
+ }
+ }
+ } else {
+ fmt.Printf("Brk failed to allocate 100 MB: errno %d\n", errno)
+ }
+ } else {
+ fmt.Printf("Brk failed\n")
+ }
+
+ //Library test VI
+ var a uint64 = 0
+ var someString string = libgogo.IntToString(a)
+ fmt.Printf("Library test: %s (should be '0')\n", someString)
+
+ //Library test VII
+ var test_str string = "Hello "
+ var test_appendstr string = "world"
+ libgogo.StringAppend(&test_str, test_appendstr)
+ libgogo.PrintString(test_str)
+ libgogo.PrintString("\n")
+
+ //Library test VIII
+ var stack libgogo.Stack
+ libgogo.InitializeStack(&stack)
+ fmt.Printf("Stack initialized: item count: %d, capacity: %d\n",
libgogo.GetStackItemCount(&stack), libgogo.GetStackCapacity(&stack))
+ var val uint64
+ fmt.Printf("Pushing the 20 values onto the stack\n")
+ for val = 1; val <= 20; val++ {
+ libgogo.Push(&stack, val)
+ //fmt.Printf("DEBUG %d: item count: %d, capacity: %d, peek item: %d\n",
val, libgogo.GetStackItemCount(&stack), libgogo.GetStackCapacity(&stack),
libgogo.Peek(&stack));
+ }
+ fmt.Printf("Taking 19 values from the stack\n")
+ var j uint64
+ for j = 20; j > 1; j-- {
+ val = libgogo.Pop(&stack)
+ //fmt.Printf("DEBUG %d: item count: %d, capacity: %d, peek item: %d\n",
j, libgogo.GetStackItemCount(&stack), libgogo.GetStackCapacity(&stack),
libgogo.Peek(&stack));
+ if j != val {
+ fmt.Printf("ERROR: Unexpected value from stack: %d (should be %d)\n",
val, j)
+ }
+ }
+ fmt.Printf("Library test: Number of values left on stack and peek value
(should both be 1): %d and %d\n", libgogo.GetStackItemCount(&stack),
libgogo.Peek(&stack))
+
+ //Library test IX
+ var list libgogo.List
+ libgogo.InitializeList(&list, 8)
+ fmt.Printf("List initialized: item count: %d, capacity: %d\n",
libgogo.GetListItemCount(&list), libgogo.GetListCapacity(&list))
+ fmt.Printf("Putting the 20 values into the list\n")
+ for val = 1; val <= 20; val++ {
+ libgogo.AddItem(&list, &val)
+ //fmt.Printf("DEBUG %d: item count: %d, capacity: %d, first item: %d,
last item: %d\n", val, libgogo.GetListItemCount(&list),
libgogo.GetListCapacity(&list), libgogo.GetItemAt(&list, 0),
libgogo.GetItemAt(&list, libgogo.GetListItemCount(&list) - 1));
+ }
+ fmt.Printf("Removing 19 values from the list\n")
+ for j = 1; j < 20; j++ {
+ val = *(libgogo.RemoveItemAt(&list, 0))
+ //fmt.Printf("DEBUG %d: item count: %d, capacity: %d, first item: %d,
last item: %d\n", j, libgogo.GetListItemCount(&list),
libgogo.GetListCapacity(&list), libgogo.GetItemAt(&list, 0),
libgogo.GetItemAt(&list, libgogo.GetListItemCount(&list) - 1));
+ if j != val {
+ fmt.Printf("ERROR: Unexpected value from list: %d (should be %d)\n",
val, j)
+ }
+ }
+ fmt.Printf("Library test: Number of values left in list and value (should
be 1 and 20): %d and %d\n", libgogo.GetListItemCount(&list),
*libgogo.GetItemAt(&list, 0))
+
+ //Library test X
+ libgogo.Exit(0)
+ fmt.Printf("If you can read this, something is wrong")
+}
=======================================
--- /src/linker.go Tue Aug 17 09:58:38 2010
+++ /src/linker.go Wed Aug 18 10:20:16 2010
@@ -7,176 +7,176 @@
import "./libgogo/_obj/libgogo"

type LineDesc struct {
- Line string;
- Offset uint64;
-
- NeedsFix uint64;
- NeedsByteFix uint64;
- PackageName string;
- FunctionName string;
-};
+ Line string
+ Offset uint64
+
+ NeedsFix uint64
+ NeedsByteFix uint64
+ PackageName string
+ FunctionName string
+}

type ParamDesc struct {
- Name string;
- TypePackage string;
- TypeName string;
- Ptr uint64;
-};
+ Name string
+ TypePackage string
+ TypeName string
+ Ptr uint64
+}

//
// Function fetches the next line from the assembly file.
//
func GetLine(ld *LineDesc) {
- var line string = "";
- var i uint64 = 0;
- var singleChar byte;
- var cmp uint64;
-
- for singleChar = GetCharWrapped(); (i<10) && (singleChar!=10) &&
(singleChar!=0); singleChar = GetCharWrapped() {
- libgogo.CharAppend(&line, singleChar);
- i = i +1;
- }
- cmp = libgogo.StringCompare(line, " //--- ##");
- if cmp == 0 {
- // actual singleChar should be the number
- ld.NeedsFix = libgogo.ToIntFromByte(singleChar);
- ld.NeedsFix = ld.NeedsFix - 48;
- if (ld.NeedsFix != 1) && (ld.NeedsFix != 2) {
- LinkError("encountered internal error when reading fixups.
file edited by hand?", "", "", "", "");
- }
- ld.PackageName = "";
- ld.FunctionName = "";
-
- GetCharWrapped(); // Abolish '#'
- GetCharWrapped(); // Abolish '#'
-
- for singleChar = GetCharWrapped(); singleChar != 194 ; singleChar
= GetCharWrapped() {
- libgogo.CharAppend(&ld.PackageName, singleChar);
- }
- GetCharWrapped(); // Abolish second part of dot (183)
- for singleChar = GetCharWrapped(); (singleChar != '#'); singleChar
= GetCharWrapped() {
- libgogo.CharAppend(&ld.FunctionName, singleChar);
- }
-
- if (singleChar != 10) && (singleChar != 0) {
- for ; (singleChar != 0) && (singleChar != 10); singleChar =
GetCharWrapped() {
- libgogo.CharAppend(&line, singleChar);
- }
- }
- } else {
- for ; (singleChar != 0) && (singleChar != 10); singleChar =
GetCharWrapped() {
- libgogo.CharAppend(&line, singleChar);
- }
- }
-
- if singleChar == 0 {
- tok.id = TOKEN_EOS;
- }
- ld.Line = line;
- ld.Offset = 0;
+ var line string = ""
+ var i uint64 = 0
+ var singleChar byte
+ var cmp uint64
+
+ for singleChar = GetCharWrapped(); (i < 10) && (singleChar != 10) &&
(singleChar != 0); singleChar = GetCharWrapped() {
+ libgogo.CharAppend(&line, singleChar)
+ i = i + 1
+ }
+ cmp = libgogo.StringCompare(line, " //--- ##")
+ if cmp == 0 {
+ // actual singleChar should be the number
+ ld.NeedsFix = libgogo.ToIntFromByte(singleChar)
+ ld.NeedsFix = ld.NeedsFix - 48
+ if (ld.NeedsFix != 1) && (ld.NeedsFix != 2) {
+ LinkError("encountered internal error when reading fixups. file edited
by hand?", "", "", "", "")
+ }
+ ld.PackageName = ""
+ ld.FunctionName = ""
+
+ GetCharWrapped() // Abolish '#'
+ GetCharWrapped() // Abolish '#'
+
+ for singleChar = GetCharWrapped(); singleChar != 194; singleChar =
GetCharWrapped() {
+ libgogo.CharAppend(&ld.PackageName, singleChar)
+ }
+ GetCharWrapped() // Abolish second part of dot (183)
+ for singleChar = GetCharWrapped(); singleChar != '#'; singleChar =
GetCharWrapped() {
+ libgogo.CharAppend(&ld.FunctionName, singleChar)
+ }
+
+ if (singleChar != 10) && (singleChar != 0) {
+ for ; (singleChar != 0) && (singleChar != 10); singleChar =
GetCharWrapped() {
+ libgogo.CharAppend(&line, singleChar)
+ }
+ }
+ } else {
+ for ; (singleChar != 0) && (singleChar != 10); singleChar =
GetCharWrapped() {
+ libgogo.CharAppend(&line, singleChar)
+ }
+ }
+
+ if singleChar == 0 {
+ tok.id = TOKEN_EOS
+ }
+ ld.Line = line
+ ld.Offset = 0
}

func GetNextSymToken(ld *LineDesc) string {
- var symtoken string = "";
- var i uint64;
- var len uint64;
- len = libgogo.StringLength(ld.Line);
- for i = ld.Offset; (i < len) && (ld.Line[i] != ','); i=i+1 {
- if (ld.Line[i] != '/') {
- libgogo.CharAppend(&symtoken, ld.Line[i]);
- }
- }
- ld.Offset = i+1;
- return symtoken;
+ var symtoken string = ""
+ var i uint64
+ var len uint64
+ len = libgogo.StringLength(ld.Line)
+ for i = ld.Offset; (i < len) && (ld.Line[i] != ','); i = i + 1 {
+ if ld.Line[i] != '/' {
+ libgogo.CharAppend(&symtoken, ld.Line[i])
+ }
+ }
+ ld.Offset = i + 1
+ return symtoken
}


func ParseSymTblLine(ld *LineDesc) {
- var symtype string;
- var strCmp uint64;
-
- symtype = GetNextSymToken(ld);
- strCmp = libgogo.StringCompare(symtype, "TYPE");
- if strCmp == 0 {
- ParseSymTblType(ld);
- }
- strCmp = libgogo.StringCompare(symtype, "FUNC");
- if strCmp == 0 {
- ParseSymTblFunc(ld);
- }
+ var symtype string
+ var strCmp uint64
+
+ symtype = GetNextSymToken(ld)
+ strCmp = libgogo.StringCompare(symtype, "TYPE")
+ if strCmp == 0 {
+ ParseSymTblType(ld)
+ }
+ strCmp = libgogo.StringCompare(symtype, "FUNC")
+ if strCmp == 0 {
+ ParseSymTblFunc(ld)
+ }
}

func IsDefaultType(pkgType string) uint64 {
- var strCmp uint64;
- var retValue uint64 = 0;
- strCmp = libgogo.StringCompare(pkgType, "·uint64");
- if strCmp == 0 {
- retValue = 1;
- }
- strCmp = libgogo.StringCompare(pkgType, "·byte");
- if strCmp == 0 {
- retValue = 1;
- }
- strCmp = libgogo.StringCompare(pkgType, "·string");
- if strCmp == 0 {
- retValue = 1;
- }
- strCmp = libgogo.StringCompare(pkgType, "·bool");
- if strCmp == 0 {
- retValue = 1;
- }
- return retValue;
+ var strCmp uint64
+ var retValue uint64 = 0
+ strCmp = libgogo.StringCompare(pkgType, "·uint64")
+ if strCmp == 0 {
+ retValue = 1
+ }
+ strCmp = libgogo.StringCompare(pkgType, "·byte")
+ if strCmp == 0 {
+ retValue = 1
+ }
+ strCmp = libgogo.StringCompare(pkgType, "·string")
+ if strCmp == 0 {
+ retValue = 1
+ }
+ strCmp = libgogo.StringCompare(pkgType, "·bool")
+ if strCmp == 0 {
+ retValue = 1
+ }
+ return retValue
}

func GetPackageName(pkgType string) string {
- var retStr string = "";
- var i uint64;
- for i = 0; pkgType[i] != 194 ; i=i+1 {
- libgogo.CharAppend(&retStr, pkgType[i]);
- }
- return retStr;
+ var retStr string = ""
+ var i uint64
+ for i = 0; pkgType[i] != 194; i = i + 1 {
+ libgogo.CharAppend(&retStr, pkgType[i])
+ }
+ return retStr
}

func GetFuncName(pkgType string) string {
- var retStr string = "";
- var i uint64;
- var strLen uint64;
- strLen = libgogo.StringLength(pkgType);
- for i = 0; pkgType[i] != 183; i = i +1 {
- }
- i = i+1;
- for ; i < strLen; i = i +1 {
- libgogo.CharAppend(&retStr, pkgType[i]);
- }
- return retStr;
+ var retStr string = ""
+ var i uint64
+ var strLen uint64
+ strLen = libgogo.StringLength(pkgType)
+ for i = 0; pkgType[i] != 183; i = i + 1 {
+ }
+ i = i + 1
+ for ; i < strLen; i = i + 1 {
+ libgogo.CharAppend(&retStr, pkgType[i])
+ }
+ return retStr
}

func ParseSymbolParam(pd *ParamDesc, paramType string) {
- var i uint64 = 0;
- var strLen uint64;
-
- pd.Name = "";
- pd.TypePackage = "";
- pd.TypeName = "";
- pd.Ptr = 0;
-
- strLen = libgogo.StringLength(paramType);
- if strLen > 0 {
- for i = 0; paramType[i] != ':' ; i=i+1 {
- libgogo.CharAppend(&pd.Name, paramType[i]);
- }
- i=i+1;
- if paramType[i] == '*' {
- pd.Ptr = 1;
- i=i+1;
- }
- for ;paramType[i] != 194; i=i+1 {
- libgogo.CharAppend(&pd.TypePackage, paramType[i]);
- }
- for i=i+2;i < strLen; i=i+1 {
- libgogo.CharAppend(&pd.TypeName, paramType[i]);
- }
- }
+ var i uint64 = 0
+ var strLen uint64
+
+ pd.Name = ""
+ pd.TypePackage = ""
+ pd.TypeName = ""
+ pd.Ptr = 0
+
+ strLen = libgogo.StringLength(paramType)
+ if strLen > 0 {
+ for i = 0; paramType[i] != ':'; i = i + 1 {
+ libgogo.CharAppend(&pd.Name, paramType[i])
+ }
+ i = i + 1
+ if paramType[i] == '*' {
+ pd.Ptr = 1
+ i = i + 1
+ }
+ for ; paramType[i] != 194; i = i + 1 {
+ libgogo.CharAppend(&pd.TypePackage, paramType[i])
+ }
+ for i = i + 2; i < strLen; i = i + 1 {
+ libgogo.CharAppend(&pd.TypeName, paramType[i])
+ }
+ }
}

//
@@ -184,45 +184,45 @@
// to the global symbol table.
//
func ParseSymTblFunc(ld *LineDesc) {
- var pd ParamDesc;
- var func_t *libgogo.TypeDesc = nil;
- var some_t *libgogo.TypeDesc = nil;
- var fwdStr string;
- var fwdNum uint64;
- var pkgFunc string;
- var funcName string;
- var pkgName string;
- var ind uint64;
- var paramType string;
- var tmpParam *libgogo.ObjectDesc;
-
- InitParamDesc(&pd);
-
- fwdStr = GetNextSymToken(ld);
- fwdNum = libgogo.StringToInt(fwdStr);
- pkgFunc = GetNextSymToken(ld);
- ind = libgogo.StringCompare(pkgFunc, "main·init");
- if ind != 0 {
- pkgName = GetPackageName(pkgFunc);
- funcName = GetFuncName(pkgFunc);
- func_t = NewFunction(funcName, pkgName, fwdNum);
- paramType = GetNextSymToken(ld);
- ind = libgogo.StringLength(paramType);
- for ; ind != 0 ; {
- ParseSymbolParam(&pd, paramType);
- tmpParam = libgogo.NewObject(pd.Name, "",
libgogo.CLASS_PARAMETER);
- some_t = libgogo.GetType(pd.TypeName, pd.TypePackage,
GlobalTypes, 1);
- if some_t != nil {
- tmpParam.ObjType = some_t;
- tmpParam.PtrType = pd.Ptr;
- libgogo.AddParameters(tmpParam, func_t);
- } else {
- LinkError("unable to find
type '",pd.TypePackage,"·",pd.TypeName,"'.");
- }
- paramType = GetNextSymToken(ld);
- ind = libgogo.StringLength(paramType);
- }
- }
+ var pd ParamDesc
+ var func_t *libgogo.TypeDesc = nil
+ var some_t *libgogo.TypeDesc = nil
+ var fwdStr string
+ var fwdNum uint64
+ var pkgFunc string
+ var funcName string
+ var pkgName string
+ var ind uint64
+ var paramType string
+ var tmpParam *libgogo.ObjectDesc
+
+ InitParamDesc(&pd)
+
+ fwdStr = GetNextSymToken(ld)
+ fwdNum = libgogo.StringToInt(fwdStr)
+ pkgFunc = GetNextSymToken(ld)
+ ind = libgogo.StringCompare(pkgFunc, "main·init")
+ if ind != 0 {
+ pkgName = GetPackageName(pkgFunc)
+ funcName = GetFuncName(pkgFunc)
+ func_t = NewFunction(funcName, pkgName, fwdNum)
+ paramType = GetNextSymToken(ld)
+ ind = libgogo.StringLength(paramType)
+ for ind != 0 {
+ ParseSymbolParam(&pd, paramType)
+ tmpParam = libgogo.NewObject(pd.Name, "", libgogo.CLASS_PARAMETER)
+ some_t = libgogo.GetType(pd.TypeName, pd.TypePackage, GlobalTypes, 1)
+ if some_t != nil {
+ tmpParam.ObjType = some_t
+ tmpParam.PtrType = pd.Ptr
+ libgogo.AddParameters(tmpParam, func_t)
+ } else {
+ LinkError("unable to find type '", pd.TypePackage, "·",
pd.TypeName, "'.")
+ }
+ paramType = GetNextSymToken(ld)
+ ind = libgogo.StringLength(paramType)
+ }
+ }

}

@@ -231,243 +231,242 @@
// to the global symbol table.
//
func ParseSymTblType(ld *LineDesc) {
- var some_t *libgogo.TypeDesc = nil;
- var fwdStr string;
- var fwdNum uint64;
- var pkgType string;
- var pkgName string;
- var typeName string;
- var sizeStr string;
- var sizeNum uint64;
- var alignStr string;
- var alignNum uint64;
- var ind uint64;
- var tmp1 uint64;
- var tmp2 uint64;
- var tmpStr1 string = "";
- var tmpStr2 string;
- // maybe some more flags, indicators, temps, strings,
numbers, ... ?!? ;)
-
- fwdStr = GetNextSymToken(ld);
- fwdNum = libgogo.StringToInt(fwdStr);
- pkgType = GetNextSymToken(ld);
- sizeStr = GetNextSymToken(ld);
- sizeNum = libgogo.StringToInt(sizeStr);
- alignStr = GetNextSymToken(ld);
- alignNum = libgogo.StringToInt(alignStr);
- ind = IsDefaultType(pkgType);
- if ind == 0 { // non-default type, try to add
- pkgName = GetPackageName(pkgType);
- typeName = GetFuncName(pkgType);
- some_t = libgogo.GetType(typeName, pkgName, GlobalTypes, 1);
- if some_t == nil {
- some_t = libgogo.NewType(typeName, pkgName, fwdNum, sizeNum,
nil);
- GlobalTypes = libgogo.AppendType(some_t, GlobalTypes);
- } else {
- /* All kings of fwd declaration combinations need to be
checked */
- if (some_t.ForwardDecl == 0) && (fwdNum == 0) {
- tmp1 = libgogo.GetTypeSize(some_t);
- tmp2 = libgogo.GetTypeSizeAligned(some_t);
- if (sizeNum == tmp1) && (alignNum == tmp2) {
- LinkWarn("duplicated type (", pkgType, "). sizes
matched.", "", "");
- } else {
- libgogo.StringAppend(&tmpStr1, "new: ");
- libgogo.StringAppend(&tmpStr1, sizeStr);
- libgogo.StringAppend(&tmpStr1, "; defined: ");
- tmpStr2 = libgogo.IntToString(tmp1);
- libgogo.StringAppend(&tmpStr1, tmpStr2);
- LinkError("duplicate type: ", pkgType, ". Incompatible
sizes: ",tmpStr1, "");
- }
- }
- if (some_t.ForwardDecl == 1) && (fwdNum == 0) {
- /* Fix the params of the fwd. declared type */
- some_t.ForwardDecl = 0;
- some_t.Len = sizeNum;
- }
- if (some_t.ForwardDecl == 0) && (fwdNum == 1) {
- ; // skip since this is useless
- }
- if (some_t.ForwardDecl == 1) && (fwdNum == 1) {
- ; // skip since this is useless
- }
- }
- }
+ var some_t *libgogo.TypeDesc = nil
+ var fwdStr string
+ var fwdNum uint64
+ var pkgType string
+ var pkgName string
+ var typeName string
+ var sizeStr string
+ var sizeNum uint64
+ var alignStr string
+ var alignNum uint64
+ var ind uint64
+ var tmp1 uint64
+ var tmp2 uint64
+ var tmpStr1 string = ""
+ var tmpStr2 string
+ // maybe some more flags, indicators, temps, strings, numbers, ... ?!? ;)
+
+ fwdStr = GetNextSymToken(ld)
+ fwdNum = libgogo.StringToInt(fwdStr)
+ pkgType = GetNextSymToken(ld)
+ sizeStr = GetNextSymToken(ld)
+ sizeNum = libgogo.StringToInt(sizeStr)
+ alignStr = GetNextSymToken(ld)
+ alignNum = libgogo.StringToInt(alignStr)
+ ind = IsDefaultType(pkgType)
+ if ind == 0 { // non-default type, try to add
+ pkgName = GetPackageName(pkgType)
+ typeName = GetFuncName(pkgType)
+ some_t = libgogo.GetType(typeName, pkgName, GlobalTypes, 1)
+ if some_t == nil {
+ some_t = libgogo.NewType(typeName, pkgName, fwdNum, sizeNum, nil)
+ GlobalTypes = libgogo.AppendType(some_t, GlobalTypes)
+ } else {
+ /* All kings of fwd declaration combinations need to be checked */
+ if (some_t.ForwardDecl == 0) && (fwdNum == 0) {
+ tmp1 = libgogo.GetTypeSize(some_t)
+ tmp2 = libgogo.GetTypeSizeAligned(some_t)
+ if (sizeNum == tmp1) && (alignNum == tmp2) {
+ LinkWarn("duplicated type (", pkgType, "). sizes matched.", "", "")
+ } else {
+ libgogo.StringAppend(&tmpStr1, "new: ")
+ libgogo.StringAppend(&tmpStr1, sizeStr)
+ libgogo.StringAppend(&tmpStr1, "; defined: ")
+ tmpStr2 = libgogo.IntToString(tmp1)
+ libgogo.StringAppend(&tmpStr1, tmpStr2)
+ LinkError("duplicate type: ", pkgType, ". Incompatible sizes: ",
tmpStr1, "")
+ }
+ }
+ if (some_t.ForwardDecl == 1) && (fwdNum == 0) {
+ /* Fix the params of the fwd. declared type */
+ some_t.ForwardDecl = 0
+ some_t.Len = sizeNum
+ }
+ if (some_t.ForwardDecl == 0) && (fwdNum == 1) {
+ // skip since this is useless
+ }
+ if (some_t.ForwardDecl == 1) && (fwdNum == 1) {
+ // skip since this is useless
+ }
+ }
+ }
}

func GetParameterSize(pkgName string, funcName string) uint64 {
- var size uint64;
- var func_t *libgogo.TypeDesc = nil;
- func_t = libgogo.GetType(funcName, pkgName, GlobalFunctions, 1);
- if func_t != nil {
- size = libgogo.GetAlignedObjectListSize(func_t.Fields);
- } else {
- LinkError("unable to look up function '", pkgName, "·",
funcName, "' in symtable.");
- }
- return size;
+ var size uint64
+ var func_t *libgogo.TypeDesc = nil
+ func_t = libgogo.GetType(funcName, pkgName, GlobalFunctions, 1)
+ if func_t != nil {
+ size = libgogo.GetAlignedObjectListSize(func_t.Fields)
+ } else {
+ LinkError("unable to look up function '", pkgName, "·", funcName, "' in
symtable.")
+ }
+ return size
}

//
// Function processing a line and fixing offsets if necessary
//
func FixOffset(fd uint64, ld *LineDesc) {
- var i uint64;
- var strLen uint64;
- var size uint64;
- var oldsize uint64;
- var numstr string = "";
- var newLine string = "";
- var strCmp uint64;
- var fixedAdr string = "-";
- var skip uint64 = 0;
-
- for i = 0; i < 6;i = i+1 {
- libgogo.CharAppend(&newLine, ld.Line[i]);
- }
-
- strCmp = libgogo.StringCompare(" ANDQ", newLine);
- if (strCmp == 0) { // this line needs to be skipped
- skip = ld.NeedsFix;
- ld.NeedsFix = 0;
- }
-
- strCmp = libgogo.StringCompare(" MOVB", newLine);
- if strCmp == 0 {
- ld.NeedsByteFix = 1;
- } else {
- ld.NeedsByteFix = 0;
- }
-
- if ld.NeedsFix == 1 { // Type 1 fix of offsets
- strLen = libgogo.StringLength(ld.Line);
- size = GetParameterSize(ld.PackageName, ld.FunctionName);
-
- for i = 6; ld.Line[i] != '-' ; i = i +1 {
- libgogo.CharAppend(&newLine, ld.Line[i]);
- }
- libgogo.CharAppend(&newLine, ld.Line[i]);
- for i = i+1 ;ld.Line[i]!='(';i=i+1 {//Dismiss '-'
- libgogo.CharAppend(&numstr, ld.Line[i]);
- }
- oldsize = libgogo.StringToInt(numstr);
- size = size + oldsize;
- size = size - 100000;
- numstr = libgogo.IntToString(size);
- libgogo.StringAppend(&newLine, numstr);
- libgogo.StringAppend(&fixedAdr, numstr);
- libgogo.StringAppend(&fixedAdr, "(SP)");
- for ; i < strLen; i = i +1 {
- libgogo.CharAppend(&newLine, ld.Line[i]);
- }
- }
- if ld.NeedsFix == 2 { // Type 2 fix of offsets
- strLen = libgogo.StringLength(ld.Line);
- size = GetParameterSize(ld.PackageName, ld.FunctionName);
- for i = 6; ld.Line[i] != '$' ; i = i +1 {
- libgogo.CharAppend(&newLine, ld.Line[i]);
- }
-
- libgogo.CharAppend(&newLine, ld.Line[i]);
- for i = i+1 ;ld.Line[i]!=',';i=i+1 {//Dismiss '-'
- libgogo.CharAppend(&numstr, ld.Line[i]);
- }
- oldsize = libgogo.StringToInt(numstr);
- size = size + oldsize;
- numstr = libgogo.IntToString(size);
- libgogo.StringAppend(&newLine, numstr);
- for ; i < strLen; i = i +1 {
- libgogo.CharAppend(&newLine, ld.Line[i]);
- }
-
- }
-
- if skip != 0 {
- ld.NeedsFix = skip;
- strLen = libgogo.StringLength(ld.Line);
- for i = 6; i < strLen; i = i + 1 {
- libgogo.CharAppend(&newLine, ld.Line[i]);
- }
- } else {
- ld.Line = newLine;
- ld.NeedsFix = 0;
- }
-
-
- libgogo.WriteString(fd, newLine);
- libgogo.WriteString(fd, "\n");
- if ld.NeedsByteFix == 1 {
- libgogo.WriteString(fd, " ANDQ $255, ");
- libgogo.WriteString(fd, fixedAdr);
- libgogo.WriteString(fd, "\n");
- ld.NeedsByteFix = 0;
- }
+ var i uint64
+ var strLen uint64
+ var size uint64
+ var oldsize uint64
+ var numstr string = ""
+ var newLine string = ""
+ var strCmp uint64
+ var fixedAdr string = "-"
+ var skip uint64 = 0
+
+ for i = 0; i < 6; i = i + 1 {
+ libgogo.CharAppend(&newLine, ld.Line[i])
+ }
+
+ strCmp = libgogo.StringCompare(" ANDQ", newLine)
+ if strCmp == 0 { // this line needs to be skipped
+ skip = ld.NeedsFix
+ ld.NeedsFix = 0
+ }
+
+ strCmp = libgogo.StringCompare(" MOVB", newLine)
+ if strCmp == 0 {
+ ld.NeedsByteFix = 1
+ } else {
+ ld.NeedsByteFix = 0
+ }
+
+ if ld.NeedsFix == 1 { // Type 1 fix of offsets
+ strLen = libgogo.StringLength(ld.Line)
+ size = GetParameterSize(ld.PackageName, ld.FunctionName)
+
+ for i = 6; ld.Line[i] != '-'; i = i + 1 {
+ libgogo.CharAppend(&newLine, ld.Line[i])
+ }
+ libgogo.CharAppend(&newLine, ld.Line[i])
+ for i = i + 1; ld.Line[i] != '('; i = i + 1 { //Dismiss '-'
+ libgogo.CharAppend(&numstr, ld.Line[i])
+ }
+ oldsize = libgogo.StringToInt(numstr)
+ size = size + oldsize
+ size = size - 100000
+ numstr = libgogo.IntToString(size)
+ libgogo.StringAppend(&newLine, numstr)
+ libgogo.StringAppend(&fixedAdr, numstr)
+ libgogo.StringAppend(&fixedAdr, "(SP)")
+ for ; i < strLen; i = i + 1 {
+ libgogo.CharAppend(&newLine, ld.Line[i])
+ }
+ }
+ if ld.NeedsFix == 2 { // Type 2 fix of offsets
+ strLen = libgogo.StringLength(ld.Line)
+ size = GetParameterSize(ld.PackageName, ld.FunctionName)
+ for i = 6; ld.Line[i] != '$'; i = i + 1 {
+ libgogo.CharAppend(&newLine, ld.Line[i])
+ }
+
+ libgogo.CharAppend(&newLine, ld.Line[i])
+ for i = i + 1; ld.Line[i] != ','; i = i + 1 { //Dismiss '-'
+ libgogo.CharAppend(&numstr, ld.Line[i])
+ }
+ oldsize = libgogo.StringToInt(numstr)
+ size = size + oldsize
+ numstr = libgogo.IntToString(size)
+ libgogo.StringAppend(&newLine, numstr)
+ for ; i < strLen; i = i + 1 {
+ libgogo.CharAppend(&newLine, ld.Line[i])
+ }
+
+ }
+
+ if skip != 0 {
+ ld.NeedsFix = skip
+ strLen = libgogo.StringLength(ld.Line)
+ for i = 6; i < strLen; i = i + 1 {
+ libgogo.CharAppend(&newLine, ld.Line[i])
+ }
+ } else {
+ ld.Line = newLine
+ ld.NeedsFix = 0
+ }
+
+ libgogo.WriteString(fd, newLine)
+ libgogo.WriteString(fd, "\n")
+ if ld.NeedsByteFix == 1 {
+ libgogo.WriteString(fd, " ANDQ $255, ")
+ libgogo.WriteString(fd, fixedAdr)
+ libgogo.WriteString(fd, "\n")
+ ld.NeedsByteFix = 0
+ }
}

//
// Main linking method
//
func Link() {
- var strCmp uint64;
- var symtable uint64 = 0;
- var ld LineDesc;
- var fd uint64;
-
- InitLineDesc(&ld);
-
- // The following line creates a new file for the assembler code
- // flags: O_WRONLY | O_CREAT | O_TRUNC => 577
- // mode: S_IWUSR | S_IRUSR | S_IRGRP => 416
- fd = libgogo.FileOpen2("_final_.sog", 577, 416);
-
- for
curFileIndex=0;curFileIndex<fileInfoLen;curFileIndex=curFileIndex+1 {
-
- ResetToken();
- GetLine(&ld);
- for ;tok.id != TOKEN_EOS;{
- strCmp = libgogo.StringCompare("//Symbol table:", ld.Line);
- if strCmp == 0 {
- symtable = 1;
- GetLine(&ld); // Proceed to next line
- }
- if symtable != 0 { // Parse symtable entries
- strCmp = libgogo.StringCompare("//End Symbol table",
ld.Line);
- if strCmp == 0 {
- symtable = 0;
- } else {
- ParseSymTblLine(&ld);
- }
- } else { // Parse normal lines and fix everything
- if ld.NeedsFix != 0 {
- GetLine(&ld);
- FixOffset(fd, &ld);
- } else {
- strCmp =
libgogo.StringCompare(ld.Line, "__UNLINKED_CODE");
- if strCmp != 0 {
- libgogo.WriteString(fd, ld.Line);
- libgogo.WriteString(fd, "\n");
- }
- }
-
- }
- if ld.NeedsFix == 0 { // fetch a new line if currently no fix
needed
- GetLine(&ld);
- }
- }
-
- }
+ var strCmp uint64
+ var symtable uint64 = 0
+ var ld LineDesc
+ var fd uint64
+
+ InitLineDesc(&ld)
+
+ // The following line creates a new file for the assembler code
+ // flags: O_WRONLY | O_CREAT | O_TRUNC => 577
+ // mode: S_IWUSR | S_IRUSR | S_IRGRP => 416
+ fd = libgogo.FileOpen2("_final_.sog", 577, 416)
+
+ for curFileIndex = 0; curFileIndex < fileInfoLen; curFileIndex =
curFileIndex + 1 {
+
+ ResetToken()
+ GetLine(&ld)
+ for tok.id != TOKEN_EOS {
+ strCmp = libgogo.StringCompare("//Symbol table:", ld.Line)
+ if strCmp == 0 {
+ symtable = 1
+ GetLine(&ld) // Proceed to next line
+ }
+ if symtable != 0 { // Parse symtable entries
+ strCmp = libgogo.StringCompare("//End Symbol table", ld.Line)
+ if strCmp == 0 {
+ symtable = 0
+ } else {
+ ParseSymTblLine(&ld)
+ }
+ } else { // Parse normal lines and fix everything
+ if ld.NeedsFix != 0 {
+ GetLine(&ld)
+ FixOffset(fd, &ld)
+ } else {
+ strCmp = libgogo.StringCompare(ld.Line, "__UNLINKED_CODE")
+ if strCmp != 0 {
+ libgogo.WriteString(fd, ld.Line)
+ libgogo.WriteString(fd, "\n")
+ }
+ }
+
+ }
+ if ld.NeedsFix == 0 { // fetch a new line if currently no fix needed
+ GetLine(&ld)
+ }
+ }
+
+ }
}

func InitLineDesc(ld *LineDesc) {
- ld.Line = "";
- ld.Offset = 0;
- ld.NeedsFix = 0;
- ld.NeedsByteFix = 0;
- ld.PackageName = "";
- ld.FunctionName = "";
+ ld.Line = ""
+ ld.Offset = 0
+ ld.NeedsFix = 0
+ ld.NeedsByteFix = 0
+ ld.PackageName = ""
+ ld.FunctionName = ""
}

func InitParamDesc(pd *ParamDesc) {
- pd.Name = "";
- pd.TypePackage = "";
- pd.TypeName = "";
- pd.Ptr = 0;
-}
+ pd.Name = ""
+ pd.TypePackage = ""
+ pd.TypeName = ""
+ pd.Ptr = 0
+}
=======================================
--- /src/parse-utils.go Tue Aug 17 09:58:38 2010
+++ /src/parse-utils.go Wed Aug 18 10:20:16 2010
@@ -13,65 +13,65 @@
// Returns: 0 if tokens match, 1 otherwise
//
func LookAheadAndCheck(tokenNumber uint64) uint64 {
- var boolFlag uint64;
- GetNextTokenSafe();
- if (tok.id == tokenNumber) {
- boolFlag = 0;
- } else {
- boolFlag = 1;
- }
- tok.nextToken = tok.id;
- return boolFlag;
+ var boolFlag uint64
+ GetNextTokenSafe()
+ if tok.id == tokenNumber {
+ boolFlag = 0
+ } else {
+ boolFlag = 1
+ }
+ tok.nextToken = tok.id
+ return boolFlag
}

//
// Safely gets the next token and stores it in the supplied token.
//
func GetNextTokenSafe() {
- var tokenString string;
- var index uint64;
-
- if tok.nextToken != 0 {
- tok.id = tok.nextToken;
- tok.nextToken = 0;
- } else {
- if tok.llCnt > 0 {
- index = tok.toRead;
- tok.id = tok.nextTokenId[index];
- tok.strValue = tok.nextTokenValStr[index];
- tok.llCnt = tok.llCnt-1;
- tok.toRead = index+1;
- } else {
- GetNextToken();
- tokenString = TokenToString(tok.id);
- PrintDebugString(tokenString, 1000);
- }
- }
+ var tokenString string
+ var index uint64
+
+ if tok.nextToken != 0 {
+ tok.id = tok.nextToken
+ tok.nextToken = 0
+ } else {
+ if tok.llCnt > 0 {
+ index = tok.toRead
+ tok.id = tok.nextTokenId[index]
+ tok.strValue = tok.nextTokenValStr[index]
+ tok.llCnt = tok.llCnt - 1
+ tok.toRead = index + 1
+ } else {
+ GetNextToken()
+ tokenString = TokenToString(tok.id)
+ PrintDebugString(tokenString, 1000)
+ }
+ }
}

func AssertNextTokenWeak(tokenNumber uint64) {
- GetNextTokenSafe();
- if tok.id != tokenNumber {
- ParseErrorWeak(tok.id, tokenNumber, 0, 1);
- tok.nextToken = tok.id;
- }
+ GetNextTokenSafe()
+ if tok.id != tokenNumber {
+ ParseErrorWeak(tok.id, tokenNumber, 0, 1)
+ tok.nextToken = tok.id
+ }
}

//
// Checks if the next token matches a tokenNumber, or produces an error.
//
func AssertNextToken(tokenNumber uint64) {
- GetNextTokenSafe();
- AssertToken(tokenNumber);
+ GetNextTokenSafe()
+ AssertToken(tokenNumber)
}

//
// Asserts an already read token. (no GetNextToken() before the check)
//
func AssertToken(tokenNumber uint64) {
- if tok.id != tokenNumber {
- ParseErrorWeak(tok.id, tokenNumber, 0, 1);
- //tok.nextToken = tok.id;
- ParserSync();
- }
-}
+ if tok.id != tokenNumber {
+ ParseErrorWeak(tok.id, tokenNumber, 0, 1)
+ //tok.nextToken = tok.id;
+ ParserSync()
+ }
+}
=======================================
--- /src/parser.go Tue Aug 17 09:58:38 2010
+++ /src/parser.go Wed Aug 18 10:20:16 2010
@@ -6,52 +6,52 @@

import "./libgogo/_obj/libgogo"

-var Operators libgogo.Stack;
+var Operators libgogo.Stack

//
// Pseudo object representing a function's return value
//
-var ReturnValuePseudoObject *libgogo.ObjectDesc = nil;
+var ReturnValuePseudoObject *libgogo.ObjectDesc = nil

//
// Temporary function object to reassign pointer in
ParseSelectorSub_FunctionCall
//
-var ReturnedFunction *libgogo.TypeDesc = nil;
+var ReturnedFunction *libgogo.TypeDesc = nil

//
// Temporary offset used in ParseFunctionCall(Statement) which cannot be
assigned through return values
//
-var CurrentFunctionSavedRegisterOffset uint64;
+var CurrentFunctionSavedRegisterOffset uint64

//
// Main parsing function. Corresponds to the EBNF main structure called
// go_program.
//
func Parse() {
- ResetToken();
-
- libgogo.InitializeStack(&Operators);
-
- ParsePackageStatement();
- ParseImportStatementList();
- ParseStructDeclList();
- ParseVarDeclList();
- ParseFuncDeclList();
-
- AssertNextToken(TOKEN_EOS);
+ ResetToken()
+
+ libgogo.InitializeStack(&Operators)
+
+ ParsePackageStatement()
+ ParseImportStatementList()
+ ParseStructDeclList()
+ ParseVarDeclList()
+ ParseFuncDeclList()
+
+ AssertNextToken(TOKEN_EOS)
}

//
// Parses: package identifier
// This is enforced by the go language as first statement in a source file.
//
-func ParsePackageStatement() {
- PrintDebugString("Entering ParsePackageStatement()",1000);
- AssertNextTokenWeak(TOKEN_PACKAGE);
- AssertNextTokenWeak(TOKEN_IDENTIFIER);
- // package ok, value in tok.strValue
- CurrentPackage = tok.strValue;
- PrintDebugString("Leaving ParsePackageStatement()",1000);
+func ParsePackageStatement() {
+ PrintDebugString("Entering ParsePackageStatement()", 1000)
+ AssertNextTokenWeak(TOKEN_PACKAGE)
+ AssertNextTokenWeak(TOKEN_IDENTIFIER)
+ // package ok, value in tok.strValue
+ CurrentPackage = tok.strValue
+ PrintDebugString("Leaving ParsePackageStatement()", 1000)
}

//
@@ -59,12 +59,11 @@
// Function parsing the whole import block (which is optional) of a go
program
//
func ParseImportStatementList() {
- var validImport uint64;
- PrintDebugString("Entering ParseImportStatementList()",1000);
- for validImport = ParseImportStatement();
- validImport == 0;
- validImport = ParseImportStatement() { }
- PrintDebugString("Leaving ParseImportStatementList()",1000);
+ var validImport uint64
+ PrintDebugString("Entering ParseImportStatementList()", 1000)
+ for validImport = ParseImportStatement(); validImport == 0; validImport =
ParseImportStatement() {
+ }
+ PrintDebugString("Leaving ParseImportStatementList()", 1000)
}

//
@@ -73,19 +72,19 @@
// Returning 0 if import statement is valid, 1 otherwise.
//
func ParseImportStatement() uint64 {
- var boolFlag uint64;
- PrintDebugString("Entering ParseImportStatement()",1000);
- GetNextTokenSafe();
- if tok.id == TOKEN_IMPORT {
- AssertNextToken(TOKEN_STRING);
- // import ok, value in tok.strValue
- boolFlag = 0;
- } else {
- boolFlag = 1;
- tok.nextToken = tok.id;
- }
- PrintDebugString("Leaving ParseImportStatement()",1000);
- return boolFlag;
+ var boolFlag uint64
+ PrintDebugString("Entering ParseImportStatement()", 1000)
+ GetNextTokenSafe()
+ if tok.id == TOKEN_IMPORT {
+ AssertNextToken(TOKEN_STRING)
+ // import ok, value in tok.strValue
+ boolFlag = 0
+ } else {
+ boolFlag = 1
+ tok.nextToken = tok.id
+ }
+ PrintDebugString("Leaving ParseImportStatement()", 1000)
+ return boolFlag
}

//
@@ -93,12 +92,11 @@
// A list of struct declarations.
//
func ParseStructDeclList() {
- var boolFlag uint64;
- PrintDebugString("Entering ParseStructDeclList()",1000);
- for boolFlag = ParseStructDecl();
- boolFlag == 0;
- boolFlag = ParseStructDecl() { }
- PrintDebugString("Leaving ParseStructDeclList()",1000);
+ var boolFlag uint64
+ PrintDebugString("Entering ParseStructDeclList()", 1000)
+ for boolFlag = ParseStructDecl(); boolFlag == 0; boolFlag =
ParseStructDecl() {
+ }
+ PrintDebugString("Leaving ParseStructDeclList()", 1000)
}

//
@@ -106,29 +104,29 @@
// This is basically the skeleton of a struct.
//
func ParseStructDecl() uint64 {
- var boolFlag uint64;
- var dontAddType uint64;
- PrintDebugString("Entering ParseStructDecl()",1000);
- GetNextTokenSafe();
- if tok.id == TOKEN_TYPE {
- AssertNextToken(TOKEN_IDENTIFIER);
- // identifier of struct in tok.strValue
- dontAddType = NewType(tok.strValue); //Create type
- AssertNextToken(TOKEN_STRUCT);
- AssertNextToken(TOKEN_LCBRAC);
- InsideStructDecl = 1;
- ParseStructVarDeclList();
- InsideStructDecl = 0;
- AssertNextTokenWeak(TOKEN_RCBRAC);
- AssertNextTokenWeak(TOKEN_SEMICOLON);
- AddType(dontAddType); //Add type
- boolFlag = 0;
- } else {
- boolFlag = 1;
- tok.nextToken = tok.id;
- }
- PrintDebugString("Leaving ParseStructDecl()",1000);
- return boolFlag;
+ var boolFlag uint64
+ var dontAddType uint64
+ PrintDebugString("Entering ParseStructDecl()", 1000)
+ GetNextTokenSafe()
+ if tok.id == TOKEN_TYPE {
+ AssertNextToken(TOKEN_IDENTIFIER)
+ // identifier of struct in tok.strValue
+ dontAddType = NewType(tok.strValue) //Create type
+ AssertNextToken(TOKEN_STRUCT)
+ AssertNextToken(TOKEN_LCBRAC)
+ InsideStructDecl = 1
+ ParseStructVarDeclList()
+ InsideStructDecl = 0
+ AssertNextTokenWeak(TOKEN_RCBRAC)
+ AssertNextTokenWeak(TOKEN_SEMICOLON)
+ AddType(dontAddType) //Add type
+ boolFlag = 0
+ } else {
+ boolFlag = 1
+ tok.nextToken = tok.id
+ }
+ PrintDebugString("Leaving ParseStructDecl()", 1000)
+ return boolFlag
}

//
@@ -136,12 +134,11 @@
// The variable declaration list of a struct.
//
func ParseStructVarDeclList() {
- var boolFlag uint64;
- PrintDebugString("Entering ParseStructVarDeclList()",1000);
- for boolFlag = ParseStructVarDecl();
- boolFlag == 0;
- boolFlag = ParseStructVarDecl() { }
- PrintDebugString("Leaving ParseStructVarDeclList()",1000);
+ var boolFlag uint64
+ PrintDebugString("Entering ParseStructVarDeclList()", 1000)
+ for boolFlag = ParseStructVarDecl(); boolFlag == 0; boolFlag =
ParseStructVarDecl() {
+ }
+ PrintDebugString("Leaving ParseStructVarDeclList()", 1000)
}

//
@@ -149,20 +146,20 @@
// A single variable declaration in a struct.
//
func ParseStructVarDecl() uint64 {
- var boolFlag uint64;
- PrintDebugString("Entering ParseStructVarDecl()",1000);
- GetNextTokenSafe();
- if tok.id == TOKEN_IDENTIFIER {
- AddStructField(tok.strValue); //Add field to struct
- ParseType();
- AssertNextTokenWeak(TOKEN_SEMICOLON);
- boolFlag = 0;
- } else {
- boolFlag = 1;
- tok.nextToken = tok.id;
- }
- PrintDebugString("Leaving ParseStructVarDecl()",1000);
- return boolFlag;
+ var boolFlag uint64
+ PrintDebugString("Entering ParseStructVarDecl()", 1000)
+ GetNextTokenSafe()
+ if tok.id == TOKEN_IDENTIFIER {
+ AddStructField(tok.strValue) //Add field to struct
+ ParseType()
+ AssertNextTokenWeak(TOKEN_SEMICOLON)
+ boolFlag = 0
+ } else {
+ boolFlag = 1
+ tok.nextToken = tok.id
+ }
+ PrintDebugString("Leaving ParseStructVarDecl()", 1000)
+ return boolFlag
}

//
@@ -171,37 +168,37 @@
// heads and functions
//
func ParseType() {
- var arraydim uint64 = 0;
- var boolFlag uint64;
- var packagename string = CurrentPackage;
- var typename string;
-
- PrintDebugString("Entering ParseType()",1000);
- GetNextTokenSafe();
- if tok.id == TOKEN_LSBRAC {
- AssertNextToken(TOKEN_INTEGER);
- // value of integer in tok.intValue
- arraydim = tok.intValue;
- AssertNextToken(TOKEN_RSBRAC);
- } else {
- tok.nextToken = tok.id;
- }
- GetNextTokenSafe();
- if tok.id != TOKEN_ARITH_MUL {
- tok.nextToken = tok.id;
- } else {
- SetCurrentObjectTypeToPointer(); //Pointer type (indicated by *)
- }
- AssertNextToken(TOKEN_IDENTIFIER);
- // typename in tok.strValue
- typename = tok.strValue;
- boolFlag = ParseSimpleSelector();
- if boolFlag == 0 { //Take selector into consideration if there is one
- packagename = typename; //Previously read namespace is actually
the namespace
- typename = tok.strValue;
- }
- SetCurrentObjectType(typename, packagename, arraydim);
- PrintDebugString("Leaving ParseType()",1000);
+ var arraydim uint64 = 0
+ var boolFlag uint64
+ var packagename string = CurrentPackage
+ var typename string
+
+ PrintDebugString("Entering ParseType()", 1000)
+ GetNextTokenSafe()
+ if tok.id == TOKEN_LSBRAC {
+ AssertNextToken(TOKEN_INTEGER)
+ // value of integer in tok.intValue
+ arraydim = tok.intValue
+ AssertNextToken(TOKEN_RSBRAC)
+ } else {
+ tok.nextToken = tok.id
+ }
+ GetNextTokenSafe()
+ if tok.id != TOKEN_ARITH_MUL {
+ tok.nextToken = tok.id
+ } else {
+ SetCurrentObjectTypeToPointer() //Pointer type (indicated by *)
+ }
+ AssertNextToken(TOKEN_IDENTIFIER)
+ // typename in tok.strValue
+ typename = tok.strValue
+ boolFlag = ParseSimpleSelector()
+ if boolFlag == 0 { //Take selector into consideration if there is one
+ packagename = typename //Previously read namespace is actually the
namespace
+ typename = tok.strValue
+ }
+ SetCurrentObjectType(typename, packagename, arraydim)
+ PrintDebugString("Leaving ParseType()", 1000)
}

//
@@ -210,51 +207,51 @@
// declaration.
//
func ParseTypeOptional() {
- var arraydim uint64 = 0;
- var boolFlag uint64;
- var packagename string = CurrentPackage;
- var typename string;
-
- PrintDebugString("Entering ParseTypeOptional()",1000);
- ReturnValuePseudoObject = nil;
- CurrentObject = libgogo.NewObject("return value", "",
libgogo.CLASS_PARAMETER); //Return value object with a name which is
impossible to declare (contains spaces) and therefore needs no additional
checking
- GetNextTokenSafe();
- if tok.id == TOKEN_LSBRAC {
- AssertNextToken(TOKEN_INTEGER);
- arraydim = tok.intValue;
- AssertNextToken(TOKEN_RSBRAC);
- } else {
- tok.nextToken = tok.id;
- }
- if tok.id == TOKEN_ARITH_MUL {
- // Return type is a pointer
- SetCurrentObjectTypeToPointer(); //Pointer type (indicated by *)
- GetNextTokenSafe();
- }
-
- GetNextTokenSafe();
- if tok.id != TOKEN_IDENTIFIER {
- if Compile != 0 { //Check if forward declaration also has no
return type
- AssertReturnTypeIfNecessary(ReturnValuePseudoObject);
- }
- tok.nextToken = tok.id;
- } else {
- typename = tok.strValue;
- boolFlag = ParseSimpleSelector();
- if boolFlag == 0 { //Take selector into consideration if there is
one
- packagename = typename; //Previously read namespace is
actually the namespace
- typename = tok.strValue;
- }
- SetCurrentObjectType(typename, packagename, arraydim);
- ReturnValuePseudoObject = CurrentObject;
- if Compile != 0 {
- ReturnValuePseudoObject = AddReturnParameter(CurrentFunction,
ReturnValuePseudoObject);
- }
- }
- if Compile != 0 {
- FwdDeclCheckIfNecessary();
- }
- PrintDebugString("Leaving ParseTypeOptional()",1000);
+ var arraydim uint64 = 0
+ var boolFlag uint64
+ var packagename string = CurrentPackage
+ var typename string
+
+ PrintDebugString("Entering ParseTypeOptional()", 1000)
+ ReturnValuePseudoObject = nil
+ CurrentObject = libgogo.NewObject("return value", "",
libgogo.CLASS_PARAMETER) //Return value object with a name which is
impossible to declare (contains spaces) and therefore needs no additional
checking
+ GetNextTokenSafe()
+ if tok.id == TOKEN_LSBRAC {
+ AssertNextToken(TOKEN_INTEGER)
+ arraydim = tok.intValue
+ AssertNextToken(TOKEN_RSBRAC)
+ } else {
+ tok.nextToken = tok.id
+ }
+ if tok.id == TOKEN_ARITH_MUL {
+ // Return type is a pointer
+ SetCurrentObjectTypeToPointer() //Pointer type (indicated by *)
+ GetNextTokenSafe()
+ }
+
+ GetNextTokenSafe()
+ if tok.id != TOKEN_IDENTIFIER {
+ if Compile != 0 { //Check if forward declaration also has no return type
+ AssertReturnTypeIfNecessary(ReturnValuePseudoObject)
+ }
+ tok.nextToken = tok.id
+ } else {
+ typename = tok.strValue
+ boolFlag = ParseSimpleSelector()
+ if boolFlag == 0 { //Take selector into consideration if there is one
+ packagename = typename //Previously read namespace is actually the
namespace
+ typename = tok.strValue
+ }
+ SetCurrentObjectType(typename, packagename, arraydim)
+ ReturnValuePseudoObject = CurrentObject
+ if Compile != 0 {
+ ReturnValuePseudoObject = AddReturnParameter(CurrentFunction,
ReturnValuePseudoObject)
+ }
+ }
+ if Compile != 0 {
+ FwdDeclCheckIfNecessary()
+ }
+ PrintDebugString("Leaving ParseTypeOptional()", 1000)
}

//
@@ -263,12 +260,11 @@
// functions.
//
func ParseVarDeclList() {
- var boolFlag uint64;
- PrintDebugString("Entering ParseVarDeclList()",1000);
- for boolFlag = ParseVarDecl();
- boolFlag == 0;
- boolFlag = ParseVarDecl() { }
- PrintDebugString("Leaving ParseVarDeclList()",1000);
+ var boolFlag uint64
+ PrintDebugString("Entering ParseVarDeclList()", 1000)
+ for boolFlag = ParseVarDecl(); boolFlag == 0; boolFlag = ParseVarDecl() {
+ }
+ PrintDebugString("Leaving ParseVarDeclList()", 1000)
}

//
@@ -276,161 +272,159 @@
// Is used to parse a single variable declaration with optional
initializer.
//
func ParseVarDecl() uint64 {
- var boolFlag uint64;
- var ed ExpressionDescriptor;
- var exprIndicator uint64;
- var LHSItem *libgogo.Item;
- var RHSItem *libgogo.Item;
- PrintDebugString("Entering ParseVarDecl()",1000);
- boolFlag = LookAheadAndCheck(TOKEN_VAR);
- if boolFlag == 0 {
- AssertNextToken(TOKEN_VAR);
- AssertNextToken(TOKEN_IDENTIFIER);
- NewVariable(tok.strValue); //New object
- // variable name in tok.strValue
- ParseType();
-
- GetNextTokenSafe();
- if tok.id == TOKEN_ASSIGN {
- if Compile != 0 {
- LHSItem = libgogo.NewItem();
- RHSItem = libgogo.NewItem();
- if InsideFunction != 0 { //Local variable
- GenerateComment("Local variable assignment start");
- VariableObjectDescToItem(CurrentObject, LHSItem, 0);
//Local variable
- GenerateComment("Local variable assignment RHS load
start");
- exprIndicator = ParseExpression(RHSItem, &ed); //Parse
RHS
- GenerateComment("Local variable assignment RHS load
end");
- GenerateAssignment(LHSItem, RHSItem, exprIndicator);
//LHS = RHS
- GenerateComment("Local variable assignment end");
- } else { //Global variable
- SwitchOutputToInitCodeSegment(); //Write code to
main.init in order to make sure that the variables are initialized globaly
- GenerateComment("Global variable assignment start");
- VariableObjectDescToItem(CurrentObject, LHSItem, 1);
//Global variable
- GenerateComment("Global variable assignment RHS load
start");
- exprIndicator = ParseExpression(RHSItem, &ed); //Parse
RHS
- GenerateComment("Global variable assignment RHS load
end");
- GenerateAssignment(LHSItem, RHSItem, exprIndicator);
//LHS = RHS
- GenerateComment("Global variable assignment end");
- SwitchOutputToCodeSegment(); //Write the rest of the
code to the code segment
- }
- } else {
- ParseExpression(nil, &ed);
- }
- } else {
- tok.nextToken = tok.id;
- }
-
- AssertNextTokenWeak(TOKEN_SEMICOLON);
- boolFlag = 0;
- }
- PrintDebugString("Leaving ParseVarDecl()",1000);
- return boolFlag;
+ var boolFlag uint64
+ var ed ExpressionDescriptor
+ var exprIndicator uint64
+ var LHSItem *libgogo.Item
+ var RHSItem *libgogo.Item
+ PrintDebugString("Entering ParseVarDecl()", 1000)
+ boolFlag = LookAheadAndCheck(TOKEN_VAR)
+ if boolFlag == 0 {
+ AssertNextToken(TOKEN_VAR)
+ AssertNextToken(TOKEN_IDENTIFIER)
+ NewVariable(tok.strValue) //New object
+ // variable name in tok.strValue
+ ParseType()
+
+ GetNextTokenSafe()
+ if tok.id == TOKEN_ASSIGN {
+ if Compile != 0 {
+ LHSItem = libgogo.NewItem()
+ RHSItem = libgogo.NewItem()
+ if InsideFunction != 0 { //Local variable
+ GenerateComment("Local variable assignment start")
+ VariableObjectDescToItem(CurrentObject, LHSItem, 0) //Local variable
+ GenerateComment("Local variable assignment RHS load start")
+ exprIndicator = ParseExpression(RHSItem, &ed) //Parse RHS
+ GenerateComment("Local variable assignment RHS load end")
+ GenerateAssignment(LHSItem, RHSItem, exprIndicator) //LHS = RHS
+ GenerateComment("Local variable assignment end")
+ } else { //Global variable
+ SwitchOutputToInitCodeSegment() //Write code to main.init in order to
make sure that the variables are initialized globaly
+ GenerateComment("Global variable assignment start")
+ VariableObjectDescToItem(CurrentObject, LHSItem, 1) //Global variable
+ GenerateComment("Global variable assignment RHS load start")
+ exprIndicator = ParseExpression(RHSItem, &ed) //Parse RHS
+ GenerateComment("Global variable assignment RHS load end")
+ GenerateAssignment(LHSItem, RHSItem, exprIndicator) //LHS = RHS
+ GenerateComment("Global variable assignment end")
+ SwitchOutputToCodeSegment() //Write the rest of the code to the code
segment
+ }
+ } else {
+ ParseExpression(nil, &ed)
+ }
+ } else {
+ tok.nextToken = tok.id
+ }
+
+ AssertNextTokenWeak(TOKEN_SEMICOLON)
+ boolFlag = 0
+ }
+ PrintDebugString("Leaving ParseVarDecl()", 1000)
+ return boolFlag
}

//
//
//
func ParseExpression(item *libgogo.Item, ed *ExpressionDescriptor) uint64 {
- var boolFlag uint64;
- var op uint64;
- var tempItem2 *libgogo.Item;
- var retValue uint64 = 0;
- if ed != nil {
- ed.ExpressionDepth = ed.ExpressionDepth + 1;
- }
- PrintDebugString("Entering ParseExpression()",1000);
- if item == nil {
- item = libgogo.NewItem();
- }
- GetNextTokenSafe();
- if tok.id == TOKEN_OP_ADR {
- AssertNextToken(TOKEN_IDENTIFIER);
- FindIdentifierAndParseSelector(item);
- retValue = 1;
- } else {
- tok.nextToken = tok.id;
- ParseSimpleExpression(item, ed);
- boolFlag = ParseCmpOp();
- if boolFlag == 0 {
- tempItem2 = libgogo.NewItem();
- ParseSimpleExpression(tempItem2, ed);
- op = libgogo.Pop(&Operators);
- GenerateComparison(item, tempItem2, op);
- }
- }
- if ed != nil {
- ed.ExpressionDepth = ed.ExpressionDepth - 1;
- }
- PrintDebugString("Leaving ParseExpression()",1000);
- return retValue;
+ var boolFlag uint64
+ var op uint64
+ var tempItem2 *libgogo.Item
+ var retValue uint64 = 0
+ if ed != nil {
+ ed.ExpressionDepth = ed.ExpressionDepth + 1
+ }
+ PrintDebugString("Entering ParseExpression()", 1000)
+ if item == nil {
+ item = libgogo.NewItem()
+ }
+ GetNextTokenSafe()
+ if tok.id == TOKEN_OP_ADR {
+ AssertNextToken(TOKEN_IDENTIFIER)
+ FindIdentifierAndParseSelector(item)
+ retValue = 1
+ } else {
+ tok.nextToken = tok.id
+ ParseSimpleExpression(item, ed)
+ boolFlag = ParseCmpOp()
+ if boolFlag == 0 {
+ tempItem2 = libgogo.NewItem()
+ ParseSimpleExpression(tempItem2, ed)
+ op = libgogo.Pop(&Operators)
+ GenerateComparison(item, tempItem2, op)
+ }
+ }
+ if ed != nil {
+ ed.ExpressionDepth = ed.ExpressionDepth - 1
+ }
+ PrintDebugString("Leaving ParseExpression()", 1000)
+ return retValue
}

//
//
//
func ParseCmpOp() uint64 {
- var boolFlag uint64;
- PrintDebugString("Entering ParseCmpOp()",1000);
- GetNextTokenSafe();
- if (tok.id == TOKEN_EQUALS) || (tok.id == TOKEN_NOTEQUAL) ||
- (tok.id == TOKEN_REL_LT) || (tok.id == TOKEN_REL_LTOE) ||
- (tok.id == TOKEN_REL_GT) || (tok.id == TOKEN_REL_GTOE) {
- libgogo.Push(&Operators, tok.id);
- boolFlag = 0;
- } else {
- tok.nextToken = tok.id;
- boolFlag = 1;
- }
- PrintDebugString("Leaving ParseCmpOp()",1000);
- return boolFlag;
+ var boolFlag uint64
+ PrintDebugString("Entering ParseCmpOp()", 1000)
+ GetNextTokenSafe()
+ if (tok.id == TOKEN_EQUALS) || (tok.id == TOKEN_NOTEQUAL) ||
+ (tok.id == TOKEN_REL_LT) || (tok.id == TOKEN_REL_LTOE) ||
+ (tok.id == TOKEN_REL_GT) || (tok.id == TOKEN_REL_GTOE) {
+ libgogo.Push(&Operators, tok.id)
+ boolFlag = 0
+ } else {
+ tok.nextToken = tok.id
+ boolFlag = 1
+ }
+ PrintDebugString("Leaving ParseCmpOp()", 1000)
+ return boolFlag
}

//
//
//
func ParseSimpleExpression(item *libgogo.Item, ed *ExpressionDescriptor) {
- var boolFlag uint64;
- var tempItem2 *libgogo.Item;
- var op uint64;
- PrintDebugString("Entering ParseSimpleExpression()",1000);
- ParseUnaryArithOp();
- tempItem2 = libgogo.NewItem();
- ParseTerm(item, ed);
- for boolFlag = ParseSimpleExpressionOp(item, tempItem2, ed);
- boolFlag == 0;
- boolFlag = ParseSimpleExpressionOp(item, tempItem2, ed) {
- op = libgogo.Pop(&Operators);
- if op != TOKEN_REL_OR {
- GenerateSimpleExpressionArith(item, tempItem2, op);
- }
- }
- PrintDebugString("Leaving ParseSimpleExpression()",1000);
+ var boolFlag uint64
+ var tempItem2 *libgogo.Item
+ var op uint64
+ PrintDebugString("Entering ParseSimpleExpression()", 1000)
+ ParseUnaryArithOp()
+ tempItem2 = libgogo.NewItem()
+ ParseTerm(item, ed)
+ for boolFlag = ParseSimpleExpressionOp(item, tempItem2, ed); boolFlag ==
0; boolFlag = ParseSimpleExpressionOp(item, tempItem2, ed) {
+ op = libgogo.Pop(&Operators)
+ if op != TOKEN_REL_OR {
+ GenerateSimpleExpressionArith(item, tempItem2, op)
+ }
+ }
+ PrintDebugString("Leaving ParseSimpleExpression()", 1000)
}

//
//
//
func ParseSimpleExpressionOp(item1 *libgogo.Item, item2 *libgogo.Item, ed
*ExpressionDescriptor) uint64 {
- var boolFlag uint64 = 1;
- PrintDebugString("Entering ParseSimpleExpressionOp()",1000);
- boolFlag = ParseUnaryArithOp(); // +,-
- if boolFlag == 0 {
- ParseTerm(item2, ed);
- } else {
- GetNextTokenSafe();
- if tok.id == TOKEN_REL_OR {
- // ||
- GenerateRelative(item1, TOKEN_REL_OR, ed);
- libgogo.Push(&Operators, TOKEN_REL_OR);
- ParseTerm(item1, ed);
- boolFlag = 0;
- } else {
- tok.nextToken = tok.id;
- }
- }
- PrintDebugString("Leaving ParseSimpleExpressionOp()",1000);
- return boolFlag;
+ var boolFlag uint64 = 1
+ PrintDebugString("Entering ParseSimpleExpressionOp()", 1000)
+ boolFlag = ParseUnaryArithOp() // +,-
+ if boolFlag == 0 {
+ ParseTerm(item2, ed)
+ } else {
+ GetNextTokenSafe()
+ if tok.id == TOKEN_REL_OR {
+ // ||
+ GenerateRelative(item1, TOKEN_REL_OR, ed)
+ libgogo.Push(&Operators, TOKEN_REL_OR)
+ ParseTerm(item1, ed)
+ boolFlag = 0
+ } else {
+ tok.nextToken = tok.id
+ }
+ }
+ PrintDebugString("Leaving ParseSimpleExpressionOp()", 1000)
+ return boolFlag
}

//
@@ -438,63 +432,61 @@
// Returns: 0 if matched, 1 otherwise.
//
func ParseUnaryArithOp() uint64 {
- var boolFlag uint64 = 1;
- PrintDebugString("Entering ParseUnaryArithOp()",1000);
- GetNextTokenSafe();
- if (tok.id == TOKEN_ARITH_PLUS) || (tok.id == TOKEN_ARITH_MINUS) {
- libgogo.Push(&Operators, tok.id);
- boolFlag = 0;
- } else {
- tok.nextToken = tok.id;
- }
- PrintDebugString("Leaving ParseUnaryArithOp()",1000);
- return boolFlag;
+ var boolFlag uint64 = 1
+ PrintDebugString("Entering ParseUnaryArithOp()", 1000)
+ GetNextTokenSafe()
+ if (tok.id == TOKEN_ARITH_PLUS) || (tok.id == TOKEN_ARITH_MINUS) {
+ libgogo.Push(&Operators, tok.id)
+ boolFlag = 0
+ } else {
+ tok.nextToken = tok.id
+ }
+ PrintDebugString("Leaving ParseUnaryArithOp()", 1000)
+ return boolFlag
}

//
//
//
func ParseTerm(item *libgogo.Item, ed *ExpressionDescriptor) {
- var boolFlag uint64;
- var tempItem2 *libgogo.Item;
- var op uint64;
- PrintDebugString("Entering ParseTerm()",1000);
- ParseFactor(item, ed);
- tempItem2 = libgogo.NewItem();
- for boolFlag = ParseTermOp(item, tempItem2, ed);
- boolFlag == 0;
- boolFlag = ParseTermOp(item, tempItem2, ed) {
- op = libgogo.Pop(&Operators);
- if op != TOKEN_REL_AND {
- GenerateTermArith(item, tempItem2, op);
- }
- }
- PrintDebugString("Leaving ParseTerm()",1000);
+ var boolFlag uint64
+ var tempItem2 *libgogo.Item
+ var op uint64
+ PrintDebugString("Entering ParseTerm()", 1000)
+ ParseFactor(item, ed)
+ tempItem2 = libgogo.NewItem()
+ for boolFlag = ParseTermOp(item, tempItem2, ed); boolFlag == 0; boolFlag
= ParseTermOp(item, tempItem2, ed) {
+ op = libgogo.Pop(&Operators)
+ if op != TOKEN_REL_AND {
+ GenerateTermArith(item, tempItem2, op)
+ }
+ }
+ PrintDebugString("Leaving ParseTerm()", 1000)
}

//
//
//
func ParseTermOp(item1 *libgogo.Item, item2 *libgogo.Item, ed
*ExpressionDescriptor) uint64 {
- var boolFlag uint64;
- PrintDebugString("Entering ParseTermOp()",1000);
- boolFlag = ParseBinaryArithOp(); // *,/
- if boolFlag == 0 {
- ParseFactor(item2, ed); //Arith items
- } else {
- GetNextTokenSafe();
- if tok.id == TOKEN_REL_AND {
- // &&
- GenerateRelative(item1, TOKEN_REL_AND, ed);
- libgogo.Push(&Operators, TOKEN_REL_AND);
- ParseFactor(item1, ed); //Rel items
- boolFlag = 0;
- } else {
- tok.nextToken = tok.id;
- }
- }
- PrintDebugString("Leaving ParseTermOp()",1000);
- return boolFlag;
+ var boolFlag uint64
+ PrintDebugString("Entering ParseTermOp()", 1000)
+ boolFlag = ParseBinaryArithOp() // *,/
+ if boolFlag == 0 {
+ ParseFactor(item2, ed) //Arith items
+ } else {
+ GetNextTokenSafe()
+ if tok.id == TOKEN_REL_AND {
+ // &&
+ GenerateRelative(item1, TOKEN_REL_AND, ed)
+ libgogo.Push(&Operators, TOKEN_REL_AND)
+ ParseFactor(item1, ed) //Rel items
+ boolFlag = 0
+ } else {
+ tok.nextToken = tok.id
+ }
+ }
+ PrintDebugString("Leaving ParseTermOp()", 1000)
+ return boolFlag
}

//
@@ -502,421 +494,416 @@
// Returns: 0 if matched, 1 otherwise.
//
func ParseBinaryArithOp() uint64 {
- var boolFlag uint64 = 1;
- PrintDebugString("Entering ParseBinaryArithOp()",1000);
- GetNextTokenSafe();
- if (tok.id == TOKEN_ARITH_MUL) || (tok.id == TOKEN_ARITH_DIV) {
- libgogo.Push(&Operators, tok.id);
- boolFlag = 0;
- } else {
- tok.nextToken = tok.id;
- }
- PrintDebugString("Leaving ParseBinaryArithOp()",1000);
- return boolFlag;
+ var boolFlag uint64 = 1
+ PrintDebugString("Entering ParseBinaryArithOp()", 1000)
+ GetNextTokenSafe()
+ if (tok.id == TOKEN_ARITH_MUL) || (tok.id == TOKEN_ARITH_DIV) {
+ libgogo.Push(&Operators, tok.id)
+ boolFlag = 0
+ } else {
+ tok.nextToken = tok.id
+ }
+ PrintDebugString("Leaving ParseBinaryArithOp()", 1000)
+ return boolFlag
}

//
//
//
func ParseFactor(item *libgogo.Item, ed *ExpressionDescriptor) {
- var doneFlag uint64 = 1;
-
- GetNextTokenSafe();
- if (doneFlag == 1) && (tok.id == TOKEN_IDENTIFIER) {
- FindIdentifierAndParseSelector(item);
- doneFlag = 0;
- }
- if (doneFlag == 1) && (tok.id == TOKEN_INTEGER) {
- if Compile != 0 {
- CreateIntegerConstant(tok.intValue, item);
- }
- doneFlag = 0;
- }
- if (doneFlag == 1) && (tok.id == TOKEN_STRING) {
- if Compile != 0 {
- CreateStringConstant(tok.strValue, item);
- }
- doneFlag = 0;
- }
- if (doneFlag == 1) && (tok.id == TOKEN_LBRAC) {
- ParseExpression(item, ed);
- AssertNextTokenWeak(TOKEN_RBRAC);
- doneFlag = 0;
- }
- if (doneFlag == 1) && (tok.id == TOKEN_NOT) {
- if ed.Not == 1 {
- ed.Not = 0;
- } else {
- ed.Not = 1;
- }
- SwapExpressionBranches(ed);
- ParseFactor(item, ed);
- doneFlag = 0;
- }
-
- if doneFlag != 0 {
- tok.nextToken = tok.id;
- // Fix (?) empty factor, which should not be possible.
- ParseErrorWeak(tok.id, 0, 0, 0);
- ParserSync();
- }
- PrintDebugString("Leaving ParseFactor()",1000);
+ var doneFlag uint64 = 1
+
+ GetNextTokenSafe()
+ if (doneFlag == 1) && (tok.id == TOKEN_IDENTIFIER) {
+ FindIdentifierAndParseSelector(item)
+ doneFlag = 0
+ }
+ if (doneFlag == 1) && (tok.id == TOKEN_INTEGER) {
+ if Compile != 0 {
+ CreateIntegerConstant(tok.intValue, item)
+ }
+ doneFlag = 0
+ }
+ if (doneFlag == 1) && (tok.id == TOKEN_STRING) {
+ if Compile != 0 {
+ CreateStringConstant(tok.strValue, item)
+ }
+ doneFlag = 0
+ }
+ if (doneFlag == 1) && (tok.id == TOKEN_LBRAC) {
+ ParseExpression(item, ed)
+ AssertNextTokenWeak(TOKEN_RBRAC)
+ doneFlag = 0
+ }
+ if (doneFlag == 1) && (tok.id == TOKEN_NOT) {
+ if ed.Not == 1 {
+ ed.Not = 0
+ } else {
+ ed.Not = 1
+ }
+ SwapExpressionBranches(ed)
+ ParseFactor(item, ed)
+ doneFlag = 0
+ }
+
+ if doneFlag != 0 {
+ tok.nextToken = tok.id
+ // Fix (?) empty factor, which should not be possible.
+ ParseErrorWeak(tok.id, 0, 0, 0)
+ ParserSync()
+ }
+ PrintDebugString("Leaving ParseFactor()", 1000)
}

func ParseSimpleSelector() uint64 {
- var boolFlag uint64;
- GetNextTokenSafe();
- if tok.id == TOKEN_PT {
- AssertNextToken(TOKEN_IDENTIFIER);
- // value in tok.strValue
- boolFlag = 0;
- } else {
- tok.nextToken = tok.id;
- boolFlag = 1;
- }
- return boolFlag;
+ var boolFlag uint64
+ GetNextTokenSafe()
+ if tok.id == TOKEN_PT {
+ AssertNextToken(TOKEN_IDENTIFIER)
+ // value in tok.strValue
+ boolFlag = 0
+ } else {
+ tok.nextToken = tok.id
+ boolFlag = 1
+ }
+ return boolFlag
}

//
//
//
func ParseSelector(item *libgogo.Item, packagename string) {
- var boolFlag uint64;
- if item == nil { //TODO: Remove. This is only temporary until all
calls to ParseSelector are fully implemented and correct
- item = libgogo.NewItem();
- libgogo.SetItem(item, 0, nil, 0, 0, 0, 0); //Mark item as not
being set
- }
- PrintDebugString("Entering ParseSelector()",1000);
- for boolFlag = ParseSelectorSub(item, packagename);
- boolFlag == 0;
- boolFlag = ParseSelectorSub(item, packagename) {
- }
- PrintDebugString("Leaving ParseSelector()",1000);
+ var boolFlag uint64
+ if item == nil { //TODO: Remove. This is only temporary until all calls
to ParseSelector are fully implemented and correct
+ item = libgogo.NewItem()
+ libgogo.SetItem(item, 0, nil, 0, 0, 0, 0) //Mark item as not being set
+ }
+ PrintDebugString("Entering ParseSelector()", 1000)
+ for boolFlag = ParseSelectorSub(item, packagename); boolFlag == 0;
boolFlag = ParseSelectorSub(item, packagename) {
+ }
+ PrintDebugString("Leaving ParseSelector()", 1000)
***The diff for this file has been truncated for email.***
=======================================
--- /src/scanner.go Tue Aug 17 09:58:38 2010
+++ /src/scanner.go Wed Aug 18 10:20:16 2010
@@ -14,361 +14,360 @@
// Adds counters for line and columns
//
func GetCharWrapped() byte {
- var singleChar byte;
- if tok.nextChar == 0 {
- singleChar = libgogo.GetChar(fileInfo[curFileIndex].fd);
- if (singleChar == 10) {
- fileInfo[curFileIndex].charCounter = 1;
- fileInfo[curFileIndex].lineCounter =
fileInfo[curFileIndex].lineCounter + 1;
- } else {
- fileInfo[curFileIndex].charCounter =
fileInfo[curFileIndex].charCounter + 1;
- }
- } else {
- singleChar = tok.nextChar;
- tok.nextChar = 0;
- }
-
- return singleChar;
+ var singleChar byte
+ if tok.nextChar == 0 {
+ singleChar = libgogo.GetChar(fileInfo[curFileIndex].fd)
+ if singleChar == 10 {
+ fileInfo[curFileIndex].charCounter = 1
+ fileInfo[curFileIndex].lineCounter = fileInfo[curFileIndex].lineCounter
+ 1
+ } else {
+ fileInfo[curFileIndex].charCounter = fileInfo[curFileIndex].charCounter
+ 1
+ }
+ } else {
+ singleChar = tok.nextChar
+ tok.nextChar = 0
+ }
+
+ return singleChar
}

func GetEscapedCharWrapped() byte {
- var singleChar byte;
- var nextChar byte;
- var returnChar byte;
- singleChar = GetCharWrapped();
- if singleChar == '\\' { //Escaped character
- nextChar = GetCharWrapped();
- if nextChar == 'n' { //n => \n
- returnChar = '\n';
- } else {
- if nextChar == '\n' { //Line break in string
- returnChar = GetCharWrapped(); //Return character after
line break
- } else {
- if nextChar == '\\' { //\ => \ (single \)
- returnChar = '\\';
- } else {
- if nextChar == 'b' { //b => \b
- returnChar = '\b';
- } else {
- ScanErrorString("Unknown escape sequence.");
- }
- }
- }
- }
- } else { //Normal character
- returnChar = singleChar;
- }
- return returnChar;
+ var singleChar byte
+ var nextChar byte
+ var returnChar byte
+ singleChar = GetCharWrapped()
+ if singleChar == '\\' { //Escaped character
+ nextChar = GetCharWrapped()
+ if nextChar == 'n' { //n => \n
+ returnChar = '\n'
+ } else {
+ if nextChar == '\n' { //Line break in string
+ returnChar = GetCharWrapped() //Return character after line break
+ } else {
+ if nextChar == '\\' { //\ => \ (single \)
+ returnChar = '\\'
+ } else {
+ if nextChar == 'b' { //b => \b
+ returnChar = '\b'
+ } else {
+ ScanErrorString("Unknown escape sequence.")
+ }
+ }
+ }
+ }
+ } else { //Normal character
+ returnChar = singleChar
+ }
+ return returnChar
}

func GetNextTokenRaw() {
- var singleChar byte; // Byte holding the last read value
- // Flag indicating whether we are in a comment.
- // 0 for no comment
- // 1 for a single line comment
- // 2 for a multi line comment
- var inComment uint64;
- var done uint64; // Flag indicating whether a cycle (Token) is finsihed
- var spaceDone uint64; // Flag indicating whether an abolishment cycle
is finished
- var numBuf string;
-
- // Initialize variables
- done = 0;
- spaceDone = 0;
- inComment = 0;
- tok.strValue = "";
-
- // If the previous cycle had to read the next char (and stored it), it
is
- // now used as first read
- singleChar = GetCharWrapped();
-
- // check if it is a valid read, or an EOF
- if singleChar == 0 {
- tok.id = TOKEN_EOS;
- done = 1;
- spaceDone = 1;
- }
-
- //
- // Cleaning Tasks
- // The next part strips out spaces, newlines, tabs, and comments
- // Comments can either be single line with double slashes (//) or
multiline
- // using C++ syntax /* */
- //
- for ;spaceDone != 1; {
-
- // check whether a comment is starting
- if singleChar == '/' {
- // if we are in a comment skip the rest, get the next char
otherwise
- if inComment == 0 {
- singleChar = GetCharWrapped();
- if singleChar == '/' {
- // we are in a single line comment (until newline is
found)
- inComment = 1;
- } else {
- if singleChar == '*' {
- // we are in a multiline comment (until ending is
found)
- inComment = 2;
- } else {
- tok.nextChar = singleChar;
- singleChar = '/';
- }
- }
- }
- }
-
- if inComment == 2 {
- // check whether a multi-line comment is ending
- if singleChar == '*' {
- singleChar = GetCharWrapped();
- if singleChar == '/' {
- if inComment == 2 {
- inComment = 0;
- singleChar = GetCharWrapped();
- }
- }
- }
- }
-
- // if character is a newline:
- // *) if in a singleline comment, exit the comment
- // *) skip otherwise
- if singleChar == 10 {
- if inComment == 1 {
- inComment = 0;
- }
- }
-
- // handle everything that is not a space,tab,newline
- if (singleChar != ' ') && (singleChar != 9) && (singleChar != 10) {
- // if not in a comment we have our current valid char
- if inComment == 0 {
- spaceDone = 1;
- }
-
- // check if GetChar() returned EOF while skipping
- if singleChar == 0 {
- tok.id = TOKEN_EOS;
- spaceDone = 1;
- done = 1;
- }
- }
-
-
- // if we are not done until now, get a new character and start
another abolishing cycle
- if spaceDone == 0 {
- singleChar=GetCharWrapped();
- }
- }
-
- //
- // Actual scanning part starts here
- //
-
- // Catch identifiers
- // identifier = letter { letter | digit }.
- if (done != 1) && ((singleChar >= 'A') && (singleChar <= 'Z')) ||
((singleChar >= 'a') && (singleChar <= 'z')) || (singleChar == '_') { //
check for letter or _
- tok.id = TOKEN_IDENTIFIER;
- // preceding characters may be letter,_, or a number
- for ; ((singleChar >= 'A') && (singleChar <= 'Z')) || ((singleChar
>= 'a') && (singleChar <= 'z')) || (singleChar == '_') || ((singleChar
>= '0') && (singleChar <= '9')); singleChar = GetCharWrapped() {
- libgogo.CharAppend(&tok.strValue, singleChar);
- }
- // save the last read character for the next GetNextToken() cycle
- tok.nextChar = singleChar;
- done = 1;
- }
-
- // string "..."
- if (done != 1) && (singleChar == '"') {
- tok.id = TOKEN_STRING;
- for singleChar = GetEscapedCharWrapped();
singleChar != '"';singleChar = GetEscapedCharWrapped() {
- libgogo.CharAppend(&tok.strValue, singleChar);
- }
- if singleChar != '"' {
- ScanErrorString("String not closing.");
- }
- done = 1;
- }
-
- // Single Quoted Character
- if (done != 1) && singleChar == 39 {
- singleChar = GetEscapedCharWrapped();
- if singleChar != 39 {
- tok.id = TOKEN_INTEGER;
- tok.intValue = libgogo.ToIntFromByte(singleChar);
- } else {
- ScanErrorString("Unknown character.");
- }
- singleChar = GetCharWrapped();
- if singleChar != 39 {
- ScanErrorString("Only single characters allowed. Use
corresponding integer for special characters.");
- }
- done = 1;
- }
-
- // left brace (
- if (done != 1) && singleChar == '(' {
- tok.id = TOKEN_LBRAC;
- done = 1;
- }
-
- // right brace )
- if (done != 1) && singleChar == ')' {
- tok.id = TOKEN_RBRAC;
- done = 1;
- }
-
- // left square bracket [
- if (done != 1) && singleChar == '[' {
- tok.id = TOKEN_LSBRAC;
- done = 1;
- }
-
- // right square bracket ]
- if (done != 1) && singleChar == ']' {
- tok.id = TOKEN_RSBRAC;
- done = 1;
- }
-
- // integer
- if (done != 1) && (singleChar > 47) && (singleChar < 58) {
- numBuf = "";
-
- for ; (singleChar > 47) && (singleChar < 58) ; singleChar =
GetCharWrapped() {
- libgogo.CharAppend(&numBuf, singleChar);
- }
-
- tok.nextChar = singleChar;
- tok.id = TOKEN_INTEGER;
- tok.intValue = libgogo.StringToInt(numBuf);
-
- done = 1;
- }
-
- // Left curly bracket '{'
- if (done != 1) && (singleChar == '{') {
- tok.id = TOKEN_LCBRAC;
- done = 1;
- }
-
- // Right curly bracket '}'
- if (done != 1) && (singleChar == '}') {
- tok.id = TOKEN_RCBRAC;
- done = 1;
- }
-
- // Point '.'
- if (done != 1) && (singleChar == '.') {
- tok.id = TOKEN_PT;
- done = 1;
- }
-
- // Not ('!') or Not Equal ('!=')
- if (done != 1) && (singleChar == '!') {
- singleChar = GetCharWrapped();
- if singleChar == '=' {
- tok.id = TOKEN_NOTEQUAL;
- } else {
- tok.id = TOKEN_NOT;
- tok.nextChar = singleChar;
- }
- done = 1;
- }
-
- // Semicolon ';'
- if (done != 1) && (singleChar == ';') {
- tok.id = TOKEN_SEMICOLON;
- done = 1;
- }
-
- // Colon ','
- if (done != 1) && (singleChar == ',') {
- tok.id = TOKEN_COLON;
- done = 1;
- }
-
- // Assignment '=' or Equals comparison '=='
- if (done != 1) && (singleChar == '=') {
- singleChar = GetCharWrapped();
- if singleChar == '=' {
- tok.id = TOKEN_EQUALS;
- } else {
- tok.id = TOKEN_ASSIGN;
- tok.nextChar = singleChar;
- }
- done = 1;
- }
-
- // AND Relation '&&'
- if (done != 1) && (singleChar == '&') {
- singleChar = GetCharWrapped();
- if singleChar == '&' {
- tok.id = TOKEN_REL_AND;
- } else {
- tok.id = TOKEN_OP_ADR;
- tok.nextChar = singleChar;
- }
- done = 1;
- }
-
- // OR Relation '||'
- if (done != 1) && (singleChar == '|') {
- singleChar = GetCharWrapped();
- if singleChar == '|' {
- tok.id = TOKEN_REL_OR;
- } else {
- ScanErrorString("No binary OR (|) supported. Only ||.");
- }
- done = 1;
- }
-
- // Greater and Greater-Than relation
- if (done != 1) && (singleChar == '>') {
- singleChar = GetCharWrapped();
- if singleChar == '=' {
- tok.id = TOKEN_REL_GTOE;
- } else {
- tok.id = TOKEN_REL_GT;
- tok.nextChar = singleChar;
- }
- done = 1;
- }
-
- // Less and Less-Than relation
- if (done != 1) && (singleChar == '<') {
- singleChar = GetCharWrapped();
- if singleChar == '=' {
- tok.id = TOKEN_REL_LTOE;
- } else {
- tok.id = TOKEN_REL_LT;
- tok.nextChar = singleChar;
- }
- done = 1;
- }
-
- if (done != 1) && (singleChar == '+') {
- tok.id = TOKEN_ARITH_PLUS;
- done = 1;
- }
-
- if (done != 1) && (singleChar == '-') {
- tok.id = TOKEN_ARITH_MINUS;
- done = 1;
- }
-
- if (done != 1) && (singleChar == '*') {
- tok.id = TOKEN_ARITH_MUL;
- done = 1;
- }
-
- if (done != 1) && (singleChar == '/') {
- tok.id = TOKEN_ARITH_DIV;
- done = 1;
- }
-
- if (done != 1) {
- ScanErrorChar(singleChar);
- }
+ var singleChar byte // Byte holding the last read value
+ // Flag indicating whether we are in a comment.
+ // 0 for no comment
+ // 1 for a single line comment
+ // 2 for a multi line comment
+ var inComment uint64
+ var done uint64 // Flag indicating whether a cycle (Token) is
finsihed
+ var spaceDone uint64 // Flag indicating whether an abolishment cycle is
finished
+ var numBuf string
+
+ // Initialize variables
+ done = 0
+ spaceDone = 0
+ inComment = 0
+ tok.strValue = ""
+
+ // If the previous cycle had to read the next char (and stored it), it is
+ // now used as first read
+ singleChar = GetCharWrapped()
+
+ // check if it is a valid read, or an EOF
+ if singleChar == 0 {
+ tok.id = TOKEN_EOS
+ done = 1
+ spaceDone = 1
+ }
+
+ //
+ // Cleaning Tasks
+ // The next part strips out spaces, newlines, tabs, and comments
+ // Comments can either be single line with double slashes (//) or
multiline
+ // using C++ syntax /* */
+ //
+ for spaceDone != 1 {
+
+ // check whether a comment is starting
+ if singleChar == '/' {
+ // if we are in a comment skip the rest, get the next char otherwise
+ if inComment == 0 {
+ singleChar = GetCharWrapped()
+ if singleChar == '/' {
+ // we are in a single line comment (until newline is found)
+ inComment = 1
+ } else {
+ if singleChar == '*' {
+ // we are in a multiline comment (until ending is found)
+ inComment = 2
+ } else {
+ tok.nextChar = singleChar
+ singleChar = '/'
+ }
+ }
+ }
+ }
+
+ if inComment == 2 {
+ // check whether a multi-line comment is ending
+ if singleChar == '*' {
+ singleChar = GetCharWrapped()
+ if singleChar == '/' {
+ if inComment == 2 {
+ inComment = 0
+ singleChar = GetCharWrapped()
+ }
+ }
+ }
+ }
+
+ // if character is a newline:
+ // *) if in a singleline comment, exit the comment
+ // *) skip otherwise
+ if singleChar == 10 {
+ if inComment == 1 {
+ inComment = 0
+ }
+ }
+
+ // handle everything that is not a space,tab,newline
+ if (singleChar != ' ') && (singleChar != 9) && (singleChar != 10) {
+ // if not in a comment we have our current valid char
+ if inComment == 0 {
+ spaceDone = 1
+ }
+
+ // check if GetChar() returned EOF while skipping
+ if singleChar == 0 {
+ tok.id = TOKEN_EOS
+ spaceDone = 1
+ done = 1
+ }
+ }
+
+ // if we are not done until now, get a new character and start another
abolishing cycle
+ if spaceDone == 0 {
+ singleChar = GetCharWrapped()
+ }
+ }
+
+ //
+ // Actual scanning part starts here
+ //
+
+ // Catch identifiers
+ // identifier = letter { letter | digit }.
+ if (done != 1) && ((singleChar >= 'A') && (singleChar <= 'Z')) ||
((singleChar >= 'a') && (singleChar <= 'z')) || (singleChar == '_') { //
check for letter or _
+ tok.id = TOKEN_IDENTIFIER
+ // preceding characters may be letter,_, or a number
+ for ; ((singleChar >= 'A') && (singleChar <= 'Z')) || ((singleChar
>= 'a') && (singleChar <= 'z')) || (singleChar == '_') || ((singleChar
>= '0') && (singleChar <= '9')); singleChar = GetCharWrapped() {
+ libgogo.CharAppend(&tok.strValue, singleChar)
+ }
+ // save the last read character for the next GetNextToken() cycle
+ tok.nextChar = singleChar
+ done = 1
+ }
+
+ // string "..."
+ if (done != 1) && (singleChar == '"') {
+ tok.id = TOKEN_STRING
+ for singleChar = GetEscapedCharWrapped(); singleChar != '"'; singleChar
= GetEscapedCharWrapped() {
+ libgogo.CharAppend(&tok.strValue, singleChar)
+ }
+ if singleChar != '"' {
+ ScanErrorString("String not closing.")
+ }
+ done = 1
+ }
+
+ // Single Quoted Character
+ if (done != 1) && singleChar == 39 {
+ singleChar = GetEscapedCharWrapped()
+ if singleChar != 39 {
+ tok.id = TOKEN_INTEGER
+ tok.intValue = libgogo.ToIntFromByte(singleChar)
+ } else {
+ ScanErrorString("Unknown character.")
+ }
+ singleChar = GetCharWrapped()
+ if singleChar != 39 {
+ ScanErrorString("Only single characters allowed. Use corresponding
integer for special characters.")
+ }
+ done = 1
+ }
+
+ // left brace (
+ if (done != 1) && singleChar == '(' {
+ tok.id = TOKEN_LBRAC
+ done = 1
+ }
+
+ // right brace )
+ if (done != 1) && singleChar == ')' {
+ tok.id = TOKEN_RBRAC
+ done = 1
+ }
+
+ // left square bracket [
+ if (done != 1) && singleChar == '[' {
+ tok.id = TOKEN_LSBRAC
+ done = 1
+ }
+
+ // right square bracket ]
+ if (done != 1) && singleChar == ']' {
+ tok.id = TOKEN_RSBRAC
+ done = 1
+ }
+
+ // integer
+ if (done != 1) && (singleChar > 47) && (singleChar < 58) {
+ numBuf = ""
+
+ for ; (singleChar > 47) && (singleChar < 58); singleChar =
GetCharWrapped() {
+ libgogo.CharAppend(&numBuf, singleChar)
+ }
+
+ tok.nextChar = singleChar
+ tok.id = TOKEN_INTEGER
+ tok.intValue = libgogo.StringToInt(numBuf)
+
+ done = 1
+ }
+
+ // Left curly bracket '{'
+ if (done != 1) && (singleChar == '{') {
+ tok.id = TOKEN_LCBRAC
+ done = 1
+ }
+
+ // Right curly bracket '}'
+ if (done != 1) && (singleChar == '}') {
+ tok.id = TOKEN_RCBRAC
+ done = 1
+ }
+
+ // Point '.'
+ if (done != 1) && (singleChar == '.') {
+ tok.id = TOKEN_PT
+ done = 1
+ }
+
+ // Not ('!') or Not Equal ('!=')
+ if (done != 1) && (singleChar == '!') {
+ singleChar = GetCharWrapped()
+ if singleChar == '=' {
+ tok.id = TOKEN_NOTEQUAL
+ } else {
+ tok.id = TOKEN_NOT
+ tok.nextChar = singleChar
+ }
+ done = 1
+ }
+
+ // Semicolon ';'
+ if (done != 1) && (singleChar == ';') {
+ tok.id = TOKEN_SEMICOLON
+ done = 1
+ }
+
+ // Colon ','
+ if (done != 1) && (singleChar == ',') {
+ tok.id = TOKEN_COLON
+ done = 1
+ }
+
+ // Assignment '=' or Equals comparison '=='
+ if (done != 1) && (singleChar == '=') {
+ singleChar = GetCharWrapped()
+ if singleChar == '=' {
+ tok.id = TOKEN_EQUALS
+ } else {
+ tok.id = TOKEN_ASSIGN
+ tok.nextChar = singleChar
+ }
+ done = 1
+ }
+
+ // AND Relation '&&'
+ if (done != 1) && (singleChar == '&') {
+ singleChar = GetCharWrapped()
+ if singleChar == '&' {
+ tok.id = TOKEN_REL_AND
+ } else {
+ tok.id = TOKEN_OP_ADR
+ tok.nextChar = singleChar
+ }
+ done = 1
+ }
+
+ // OR Relation '||'
+ if (done != 1) && (singleChar == '|') {
+ singleChar = GetCharWrapped()
+ if singleChar == '|' {
+ tok.id = TOKEN_REL_OR
+ } else {
+ ScanErrorString("No binary OR (|) supported. Only ||.")
+ }
+ done = 1
+ }
+
+ // Greater and Greater-Than relation
+ if (done != 1) && (singleChar == '>') {
+ singleChar = GetCharWrapped()
+ if singleChar == '=' {
+ tok.id = TOKEN_REL_GTOE
+ } else {
+ tok.id = TOKEN_REL_GT
+ tok.nextChar = singleChar
+ }
+ done = 1
+ }
+
+ // Less and Less-Than relation
+ if (done != 1) && (singleChar == '<') {
+ singleChar = GetCharWrapped()
+ if singleChar == '=' {
+ tok.id = TOKEN_REL_LTOE
+ } else {
+ tok.id = TOKEN_REL_LT
+ tok.nextChar = singleChar
+ }
+ done = 1
+ }
+
+ if (done != 1) && (singleChar == '+') {
+ tok.id = TOKEN_ARITH_PLUS
+ done = 1
+ }
+
+ if (done != 1) && (singleChar == '-') {
+ tok.id = TOKEN_ARITH_MINUS
+ done = 1
+ }
+
+ if (done != 1) && (singleChar == '*') {
+ tok.id = TOKEN_ARITH_MUL
+ done = 1
+ }
+
+ if (done != 1) && (singleChar == '/') {
+ tok.id = TOKEN_ARITH_DIV
+ done = 1
+ }
+
+ if done != 1 {
+ ScanErrorChar(singleChar)
+ }
}


@@ -378,66 +377,66 @@
// keywords.
//
func GetNextToken() {
- var cmpValue uint64;
- GetNextTokenRaw();
-
- // Convert identifier to keyworded tokens
- if tok.id == TOKEN_IDENTIFIER {
- cmpValue = libgogo.StringCompare("if",tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_IF;
- }
- cmpValue = libgogo.StringCompare("else",tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_ELSE;
- }
- cmpValue = libgogo.StringCompare("for",tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_FOR;
- }
- cmpValue = libgogo.StringCompare("type",tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_TYPE;
- }
- cmpValue = libgogo.StringCompare("const",tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_CONST;
- }
- cmpValue = libgogo.StringCompare("var",tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_VAR;
- }
- cmpValue = libgogo.StringCompare("struct", tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_STRUCT;
- }
- cmpValue = libgogo.StringCompare("return", tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_RETURN;
- }
- cmpValue = libgogo.StringCompare("func", tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_FUNC;
- }
- cmpValue = libgogo.StringCompare("import", tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_IMPORT;
- }
- cmpValue = libgogo.StringCompare("package", tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_PACKAGE;
- }
- cmpValue = libgogo.StringCompare("break", tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_BREAK;
- }
- cmpValue = libgogo.StringCompare("continue", tok.strValue);
- if cmpValue == 0 {
- tok.id = TOKEN_CONTINUE;
- }
- }
-
- tok.nextToken = 0;
+ var cmpValue uint64
+ GetNextTokenRaw()
+
+ // Convert identifier to keyworded tokens
+ if tok.id == TOKEN_IDENTIFIER {
+ cmpValue = libgogo.StringCompare("if", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_IF
+ }
+ cmpValue = libgogo.StringCompare("else", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_ELSE
+ }
+ cmpValue = libgogo.StringCompare("for", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_FOR
+ }
+ cmpValue = libgogo.StringCompare("type", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_TYPE
+ }
+ cmpValue = libgogo.StringCompare("const", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_CONST
+ }
+ cmpValue = libgogo.StringCompare("var", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_VAR
+ }
+ cmpValue = libgogo.StringCompare("struct", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_STRUCT
+ }
+ cmpValue = libgogo.StringCompare("return", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_RETURN
+ }
+ cmpValue = libgogo.StringCompare("func", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_FUNC
+ }
+ cmpValue = libgogo.StringCompare("import", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_IMPORT
+ }
+ cmpValue = libgogo.StringCompare("package", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_PACKAGE
+ }
+ cmpValue = libgogo.StringCompare("break", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_BREAK
+ }
+ cmpValue = libgogo.StringCompare("continue", tok.strValue)
+ if cmpValue == 0 {
+ tok.id = TOKEN_CONTINUE
+ }
+ }
+
+ tok.nextToken = 0
}

//
@@ -445,18 +444,18 @@
//

func debugToken(tok *Token) {
- libgogo.PrintString("---------------------\n");
- libgogo.PrintString("Token Id: ");
- libgogo.PrintNumber(tok.id);
- libgogo.PrintString("\n");
- if (tok.id == TOKEN_IDENTIFIER) || (tok.id == TOKEN_STRING) {
- libgogo.PrintString("Stored string: ");
- libgogo.PrintString(tok.strValue);
- libgogo.PrintString("\n");
- }
- if tok.id == TOKEN_INTEGER {
- libgogo.PrintString("Stored integer: ");
- libgogo.PrintNumber(tok.intValue);
- libgogo.PrintString("\n");
- }
-}
+ libgogo.PrintString("---------------------\n")
+ libgogo.PrintString("Token Id: ")
+ libgogo.PrintNumber(tok.id)
+ libgogo.PrintString("\n")
+ if (tok.id == TOKEN_IDENTIFIER) || (tok.id == TOKEN_STRING) {
+ libgogo.PrintString("Stored string: ")
+ libgogo.PrintString(tok.strValue)
+ libgogo.PrintString("\n")
+ }
+ if tok.id == TOKEN_INTEGER {
+ libgogo.PrintString("Stored integer: ")
+ libgogo.PrintNumber(tok.intValue)
+ libgogo.PrintString("\n")
+ }
+}
=======================================
--- /src/symtable.go Tue Aug 17 09:58:38 2010
+++ /src/symtable.go Wed Aug 18 10:20:16 2010
@@ -9,70 +9,70 @@
//
// List of global objects and declared types
//
-var GlobalObjects *libgogo.ObjectDesc = nil;
-var GlobalTypes *libgogo.TypeDesc = nil;
-var GlobalFunctions *libgogo.TypeDesc = nil;
+var GlobalObjects *libgogo.ObjectDesc = nil
+var GlobalTypes *libgogo.TypeDesc = nil
+var GlobalFunctions *libgogo.TypeDesc = nil

//
// List of function-local objects
//
-var LocalObjects *libgogo.ObjectDesc = nil;
+var LocalObjects *libgogo.ObjectDesc = nil

//
// List of currently processed objects and types
//
-var CurrentType *libgogo.TypeDesc;
-var CurrentObject *libgogo.ObjectDesc;
-var CurrentFunction *libgogo.TypeDesc;
+var CurrentType *libgogo.TypeDesc
+var CurrentObject *libgogo.ObjectDesc
+var CurrentFunction *libgogo.TypeDesc

//
// Parameter counter when parsing implementations of previously forward
declared functions
//
-var fwdParamCount uint64 = 0;
+var fwdParamCount uint64 = 0

//
// Basic types for reference
//
-var uint64_t *libgogo.TypeDesc = nil;
-var byte_t *libgogo.TypeDesc = nil;
-var string_t *libgogo.TypeDesc = nil;
-var bool_t *libgogo.TypeDesc = nil;
+var uint64_t *libgogo.TypeDesc = nil
+var byte_t *libgogo.TypeDesc = nil
+var string_t *libgogo.TypeDesc = nil
+var bool_t *libgogo.TypeDesc = nil

//
// Nil pointer for reference
//
-var nilPtr *libgogo.ObjectDesc = nil;
+var nilPtr *libgogo.ObjectDesc = nil

//
// Flag indicating whether file needs linking
//
-var NeedsLink uint64 = 0;
+var NeedsLink uint64 = 0

//
// Initializes the global symbol table (objects and types)
//
func InitSymbolTable() {
- var main_init_fcn *libgogo.TypeDesc;
-
- //Default data types
- uint64_t = libgogo.NewType("uint64", "", 0, 8, nil);
- GlobalTypes = libgogo.AppendType(uint64_t, GlobalTypes);
- byte_t = libgogo.NewType("byte", "", 0, 1, nil);
- GlobalTypes = libgogo.AppendType(byte_t, GlobalTypes);
- string_t = libgogo.NewType("string", "", 0, 16, byte_t); //Hybrid
string type: 16 byte value on the one hand, byte array on the other in
order to allow item/char access
- GlobalTypes = libgogo.AppendType(string_t, GlobalTypes);
- bool_t = libgogo.NewType("bool", "", 0, 8, nil);
- GlobalTypes = libgogo.AppendType(bool_t, GlobalTypes);
-
- //Default objects
- nilPtr = libgogo.NewObject("nil", "", libgogo.CLASS_VAR);
- nilPtr.ObjType = nil;
- nilPtr.PtrType = 1; //nil is a pointer to no specified type (universal)
- GlobalObjects = libgogo.AppendObject(nilPtr, GlobalObjects);
-
- //Default functions
- main_init_fcn = libgogo.NewType("init", "main", 0, 0, nil);
//main.init (avoid external redeclaraction)
- GlobalFunctions = libgogo.AppendType(main_init_fcn, GlobalFunctions);
+ var main_init_fcn *libgogo.TypeDesc
+
+ //Default data types
+ uint64_t = libgogo.NewType("uint64", "", 0, 8, nil)
+ GlobalTypes = libgogo.AppendType(uint64_t, GlobalTypes)
+ byte_t = libgogo.NewType("byte", "", 0, 1, nil)
+ GlobalTypes = libgogo.AppendType(byte_t, GlobalTypes)
+ string_t = libgogo.NewType("string", "", 0, 16, byte_t) //Hybrid string
type: 16 byte value on the one hand, byte array on the other in order to
allow item/char access
+ GlobalTypes = libgogo.AppendType(string_t, GlobalTypes)
+ bool_t = libgogo.NewType("bool", "", 0, 8, nil)
+ GlobalTypes = libgogo.AppendType(bool_t, GlobalTypes)
+
+ //Default objects
+ nilPtr = libgogo.NewObject("nil", "", libgogo.CLASS_VAR)
+ nilPtr.ObjType = nil
+ nilPtr.PtrType = 1 //nil is a pointer to no specified type (universal)
+ GlobalObjects = libgogo.AppendObject(nilPtr, GlobalObjects)
+
+ //Default functions
+ main_init_fcn = libgogo.NewType("init", "main", 0, 0, nil) //main.init
(avoid external redeclaraction)
+ GlobalFunctions = libgogo.AppendType(main_init_fcn, GlobalFunctions)
}

//
@@ -80,15 +80,15 @@
// subject to the current debug level
//
func PrintGlobalSymbolTable() {
- var temp uint64;
- temp = CheckDebugLevel(100);
- if temp == 1 {
- libgogo.PrintString("\nGlobal symbol table:\n");
- libgogo.PrintString("--------------------\n");
- libgogo.PrintTypes(GlobalTypes);
- libgogo.PrintObjects(GlobalObjects);
- libgogo.PrintFunctions(GlobalFunctions);
- }
+ var temp uint64
+ temp = CheckDebugLevel(100)
+ if temp == 1 {
+ libgogo.PrintString("\nGlobal symbol table:\n")
+ libgogo.PrintString("--------------------\n")
+ libgogo.PrintTypes(GlobalTypes)
+ libgogo.PrintObjects(GlobalObjects)
+ libgogo.PrintFunctions(GlobalFunctions)
+ }
}

//
@@ -96,18 +96,18 @@
// to the current debug level
//
func PrintLocalSymbolTable() {
- var temp uint64;
- temp = CheckDebugLevel(100);
- if temp == 1 { //Function-local symbol table
- libgogo.PrintString("\nFunction-local symbol table until line ");
- libgogo.PrintNumber(fileInfo[curFileIndex].lineCounter);
- libgogo.PrintString(" of ");
- libgogo.PrintString(fileInfo[curFileIndex].filename);
-
libgogo.PrintString(":\n----------------------------------------------------------------------------\n");
- libgogo.PrintObjects(CurrentFunction.Fields);
- libgogo.PrintString("--- End of parameters, begin of local
variables ---\n");
- libgogo.PrintObjects(LocalObjects);
- }
+ var temp uint64
+ temp = CheckDebugLevel(100)
+ if temp == 1 { //Function-local symbol table
+ libgogo.PrintString("\nFunction-local symbol table until line ")
+ libgogo.PrintNumber(fileInfo[curFileIndex].lineCounter)
+ libgogo.PrintString(" of ")
+ libgogo.PrintString(fileInfo[curFileIndex].filename)
+
libgogo.PrintString(":\n----------------------------------------------------------------------------\n")
+ libgogo.PrintObjects(CurrentFunction.Fields)
+ libgogo.PrintString("--- End of parameters, begin of local variables
---\n")
+ libgogo.PrintObjects(LocalObjects)
+ }
}

//
@@ -117,23 +117,23 @@
// the whole type is specified using AddType
//
func NewType(name string) uint64 {
- var dontAddType uint64 = 0;
- var tempType *libgogo.TypeDesc;
- if Compile != 0 {
- tempType = libgogo.GetType(name, CurrentPackage, GlobalTypes, 1);
- if tempType != nil { //Check for duplicates
- if tempType.ForwardDecl != 0 { //Separate handling of forward
declarations => unset forward declaration flag
- tempType.ForwardDecl = 0;
- CurrentType = tempType;
- dontAddType = 1;
- } else { //Real duplicate
- SymbolTableError("duplicate type", name, "in package",
CurrentPackage);
- }
+ var dontAddType uint64 = 0
+ var tempType *libgogo.TypeDesc
+ if Compile != 0 {
+ tempType = libgogo.GetType(name, CurrentPackage, GlobalTypes, 1)
+ if tempType != nil { //Check for duplicates
+ if tempType.ForwardDecl != 0 { //Separate handling of forward
declarations => unset forward declaration flag
+ tempType.ForwardDecl = 0
+ CurrentType = tempType
+ dontAddType = 1
+ } else { //Real duplicate
+ SymbolTableError("duplicate type", name, "in package", CurrentPackage)
+ }
} else {
- CurrentType = libgogo.NewType(name, CurrentPackage, 0, 0, nil);
- }
- }
- return dontAddType;
+ CurrentType = libgogo.NewType(name, CurrentPackage, 0, 0, nil)
+ }
+ }
+ return dontAddType
}

//
@@ -142,9 +142,9 @@
// the type actually needs to be added to the global symbol tables
//
func AddType(dontAddType uint64) {
- if (Compile != 0) && (dontAddType == 0) {
- GlobalTypes = libgogo.AppendType(CurrentType, GlobalTypes);
- }
+ if (Compile != 0) && (dontAddType == 0) {
+ GlobalTypes = libgogo.AppendType(CurrentType, GlobalTypes)
+ }
}

//
@@ -152,16 +152,16 @@
// NewType. The field's type has to be set using SetCurrentObjectType
//
func AddStructField(fieldname string) {
- var temp uint64;
- if Compile != 0 {
- temp = libgogo.HasField(fieldname, CurrentType);
+ var temp uint64
+ if Compile != 0 {
+ temp = libgogo.HasField(fieldname, CurrentType)
if temp != 0 {
- SymbolTableError("duplicate", "", "field", fieldname);
+ SymbolTableError("duplicate", "", "field", fieldname)
} else {
- CurrentObject = libgogo.NewObject(fieldname, "",
libgogo.CLASS_FIELD); //A field has no package name
- libgogo.AddFields(CurrentObject, CurrentType);
- }
- }
+ CurrentObject = libgogo.NewObject(fieldname, "", libgogo.CLASS_FIELD)
//A field has no package name
+ libgogo.AddFields(CurrentObject, CurrentType)
+ }
+ }
}

//
@@ -169,9 +169,9 @@
// not the type itself
//
func SetCurrentObjectTypeToPointer() {
- if Compile != 0 {
- CurrentObject.PtrType = 1; //Type is pointer
- }
+ if Compile != 0 {
+ CurrentObject.PtrType = 1 //Type is pointer
+ }
}

//
@@ -181,64 +181,64 @@
// to represent an array type of the specified size
//
func SetCurrentObjectType(typename string, packagename string, arraydim
uint64) {
- var basetype *libgogo.TypeDesc;
- var temptype *libgogo.TypeDesc;
- var tempstr string = "";
- var tempstr2 string;
- var boolFlag uint64;
- var TempObject *libgogo.ObjectDesc;
-
- if Compile != 0 {
- if InsideStructDecl == 1 { //Allow types in struct declarations which
are already forward declared
- basetype = libgogo.GetType(typename, packagename, GlobalTypes, 1);
- } else {
- basetype = libgogo.GetType(typename, packagename, GlobalTypes, 0);
- }
- if basetype == nil {
- if InsideStructDecl == 1 {
- boolFlag = libgogo.StringCompare(typename, CurrentType.Name);
- if boolFlag == 0 {
- if CurrentObject.PtrType == 1 { //Allow pointer to own
type
- basetype = CurrentType;
- } else {
- SymbolTableError("A type cannot contain
itself,", "", "type", typename);
- }
- } else { //Forward declaration
- basetype = libgogo.NewType(typename, packagename, 1, 0,
nil);
- NeedsLink = 1; // We need linking because of a fwd.
declared type
- GlobalTypes = libgogo.AppendType(basetype, GlobalTypes);
//Add forward declared type to global list
- }
- } else {
- libgogo.StringAppend(&tempstr, packagename);
- libgogo.CharAppend(&tempstr, '.');
- libgogo.StringAppend(&tempstr, typename);
- SymbolTableError("Unknown", "", "type", tempstr);
- }
- }
- if arraydim == 0 { //No array
- CurrentObject.ObjType = basetype;
- } else { //Array
- if basetype != nil {
- libgogo.StringAppend(&tempstr, basetype.Name);
- }
- libgogo.StringAppend(&tempstr, "Array");
- tempstr2 = libgogo.IntToString(arraydim);
- libgogo.StringAppend(&tempstr, tempstr2);
- temptype = libgogo.NewType(tempstr, packagename, 0, arraydim,
basetype);
- CurrentObject.ObjType = temptype; //Don't add array type to
global list to avoid duplicate type name errors
- }
-
- if (InsideFunction == 0) && (InsideFunctionVarDecl == 1) { //Function
parameters
- if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base !=
nil) { //Check implementation of forward declaration
- TempObject = libgogo.GetParameterAt(fwdParamCount,
CurrentFunction);
- CorrectArtificialParameterForced(CurrentFunction, TempObject,
CurrentObject.ObjType, CurrentObject.PtrType, 0); //Perform up-conversion
if necessary
- if (TempObject.ObjType != CurrentObject.ObjType) ||
(TempObject.PtrType != CurrentObject.PtrType) {
- tempstr = libgogo.IntToString(fwdParamCount);
- SymbolTableError("Parameter", tempstr, "has been
forward declared with different type, function", CurrentFunction.Name);
- }
- }
- }
- }
+ var basetype *libgogo.TypeDesc
+ var temptype *libgogo.TypeDesc
+ var tempstr string = ""
+ var tempstr2 string
+ var boolFlag uint64
+ var TempObject *libgogo.ObjectDesc
+
+ if Compile != 0 {
+ if InsideStructDecl == 1 { //Allow types in struct declarations which
are already forward declared
+ basetype = libgogo.GetType(typename, packagename, GlobalTypes, 1)
+ } else {
+ basetype = libgogo.GetType(typename, packagename, GlobalTypes, 0)
+ }
+ if basetype == nil {
+ if InsideStructDecl == 1 {
+ boolFlag = libgogo.StringCompare(typename, CurrentType.Name)
+ if boolFlag == 0 {
+ if CurrentObject.PtrType == 1 { //Allow pointer to own type
+ basetype = CurrentType
+ } else {
+ SymbolTableError("A type cannot contain itself,", "", "type",
typename)
+ }
+ } else { //Forward declaration
+ basetype = libgogo.NewType(typename, packagename, 1, 0, nil)
+ NeedsLink = 1 // We need
linking because of a fwd. declared type
+ GlobalTypes = libgogo.AppendType(basetype, GlobalTypes) //Add forward
declared type to global list
+ }
+ } else {
+ libgogo.StringAppend(&tempstr, packagename)
+ libgogo.CharAppend(&tempstr, '.')
+ libgogo.StringAppend(&tempstr, typename)
+ SymbolTableError("Unknown", "", "type", tempstr)
+ }
+ }
+ if arraydim == 0 { //No array
+ CurrentObject.ObjType = basetype
+ } else { //Array
+ if basetype != nil {
+ libgogo.StringAppend(&tempstr, basetype.Name)
+ }
+ libgogo.StringAppend(&tempstr, "Array")
+ tempstr2 = libgogo.IntToString(arraydim)
+ libgogo.StringAppend(&tempstr, tempstr2)
+ temptype = libgogo.NewType(tempstr, packagename, 0, arraydim, basetype)
+ CurrentObject.ObjType = temptype //Don't add array type to global list
to avoid duplicate type name errors
+ }
+
+ if (InsideFunction == 0) && (InsideFunctionVarDecl == 1) { //Function
parameters
+ if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base != nil)
{ //Check implementation of forward declaration
+ TempObject = libgogo.GetParameterAt(fwdParamCount, CurrentFunction)
+ CorrectArtificialParameterForced(CurrentFunction, TempObject,
CurrentObject.ObjType, CurrentObject.PtrType, 0) //Perform up-conversion if
necessary
+ if (TempObject.ObjType != CurrentObject.ObjType) ||
(TempObject.PtrType != CurrentObject.PtrType) {
+ tempstr = libgogo.IntToString(fwdParamCount)
+ SymbolTableError("Parameter", tempstr, "has been forward declared
with different type, function", CurrentFunction.Name)
+ }
+ }
+ }
+ }
}

//
@@ -246,52 +246,52 @@
// name. The variable type has to be set using SetCurrentObjectType
//
func NewVariable(name string) {
- var TempObject *libgogo.ObjectDesc;
- var temp uint64;
- if Compile != 0 {
- CurrentObject = libgogo.NewObject(name, CurrentPackage,
libgogo.CLASS_VAR);
+ var TempObject *libgogo.ObjectDesc
+ var temp uint64
+ if Compile != 0 {
+ CurrentObject = libgogo.NewObject(name, CurrentPackage,
libgogo.CLASS_VAR)
if InsideFunction == 0 { //Global objects or function parameters
- if InsideFunctionVarDecl == 0 { //Global objects
- TempObject = libgogo.GetObject(name, CurrentPackage,
GlobalObjects);
- if TempObject != nil {
- SymbolTableError("duplicate", "global", "identifier", name);
- }
- GlobalObjects = libgogo.AppendObject(CurrentObject,
GlobalObjects);
- } else { //Function parameters
- if (CurrentFunction.ForwardDecl == 0) &&
(CurrentFunction.Base != nil) { //Check implementation of forward
declaration
- fwdParamCount = fwdParamCount + 1; //One more parameter
- ParameterCheck_Less(CurrentFunction, fwdParamCount); //Check
number of parameters
- TempObject = libgogo.GetParameterAt(fwdParamCount,
CurrentFunction);
- temp = libgogo.HasField(name, CurrentFunction); //Check for
duplicate parameter names
- if temp != 0 {
- SymbolTableError("duplicate", "parameter", "name",
name);
- }
- TempObject.PackageName = CurrentFunction.PackageName;
- TempObject.Name = name; //Set name of current parameter
- //A type check can only be performed as soon as the type is
parsed (see parser.go)
- } else {
- temp = libgogo.HasField(name, CurrentFunction);
- if temp != 0 {
- SymbolTableError("duplicate", "parameter", "name",
name);
- } else {
- CurrentObject.Class = libgogo.CLASS_PARAMETER;
- CurrentObject.PackageName =
CurrentFunction.PackageName;
- libgogo.AddParameters(CurrentObject, CurrentFunction);
- }
- }
- }
+ if InsideFunctionVarDecl == 0 { //Global objects
+ TempObject = libgogo.GetObject(name, CurrentPackage, GlobalObjects)
+ if TempObject != nil {
+ SymbolTableError("duplicate", "global", "identifier", name)
+ }
+ GlobalObjects = libgogo.AppendObject(CurrentObject, GlobalObjects)
+ } else { //Function parameters
+ if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base != nil)
{ //Check implementation of forward declaration
+ fwdParamCount = fwdParamCount + 1 //One more
parameter
+ ParameterCheck_Less(CurrentFunction, fwdParamCount) //Check number of
parameters
+ TempObject = libgogo.GetParameterAt(fwdParamCount, CurrentFunction)
+ temp = libgogo.HasField(name, CurrentFunction) //Check for duplicate
parameter names
+ if temp != 0 {
+ SymbolTableError("duplicate", "parameter", "name", name)
+ }
+ TempObject.PackageName = CurrentFunction.PackageName
+ TempObject.Name = name //Set name of current parameter
+ //A type check can only be performed as soon as the type is parsed
(see parser.go)
+ } else {
+ temp = libgogo.HasField(name, CurrentFunction)
+ if temp != 0 {
+ SymbolTableError("duplicate", "parameter", "name", name)
+ } else {
+ CurrentObject.Class = libgogo.CLASS_PARAMETER
+ CurrentObject.PackageName = CurrentFunction.PackageName
+ libgogo.AddParameters(CurrentObject, CurrentFunction)
+ }
+ }
+ }
} else { //Function-local objects
- TempObject = libgogo.GetObject(name, CurrentPackage,
LocalObjects);
- if TempObject != nil {
- SymbolTableError("duplicate", "local", "identifier", name);
- }
- TempObject = libgogo.GetObject(name, CurrentPackage,
CurrentFunction.Fields);
- if TempObject != nil {
- SymbolTableError("There is already a parameter", "", "named",
name);
- }
- LocalObjects = libgogo.AppendObject(CurrentObject, LocalObjects);
- }
- }
+ TempObject = libgogo.GetObject(name, CurrentPackage, LocalObjects)
+ if TempObject != nil {
+ SymbolTableError("duplicate", "local", "identifier", name)
+ }
+ TempObject = libgogo.GetObject(name, CurrentPackage,
CurrentFunction.Fields)
+ if TempObject != nil {
+ SymbolTableError("There is already a parameter", "", "named", name)
+ }
+ LocalObjects = libgogo.AppendObject(CurrentObject, LocalObjects)
+ }
+ }
}

//
@@ -300,10 +300,10 @@
// symbol table before purging are printed
//
func EndOfFunction() {
- if Compile != 0 {
- PrintLocalSymbolTable(); //Print local symbol table
- LocalObjects = nil; //Delete local objects
- }
+ if Compile != 0 {
+ PrintLocalSymbolTable() //Print local symbol table
+ LocalObjects = nil //Delete local objects
+ }
}

//
@@ -311,45 +311,45 @@
// kind = 0: Local variable, 1: Global variable, 2: Local parameter
//
func VariableObjectDescToItem(obj *libgogo.ObjectDesc, item *libgogo.Item,
kind uint64) {
- var tempAddr uint64;
- var size uint64;
- if kind == 0 { //Local variable
- tempAddr = libgogo.GetObjectOffset(obj, LocalObjects);
- size = libgogo.GetObjectSizeAligned(obj);
- tempAddr = tempAddr + size - 8; //Due to sign of the offset (p.e.
-8(SP)), the offsets starts at the last byte and end at the first one
- } else { //Global variable or local parameter
- if kind == 1 { //Global variable
- tempAddr = libgogo.GetObjectOffset(obj, GlobalObjects);
- } else { //Local parameter (kind = 2)
- tempAddr = libgogo.GetObjectOffset(obj,
CurrentFunction.Fields);
- }
- }
- libgogo.SetItem(item, libgogo.MODE_VAR, obj.ObjType, obj.PtrType,
tempAddr, 0, kind); //Varible item of given kind
+ var tempAddr uint64
+ var size uint64
+ if kind == 0 { //Local variable
+ tempAddr = libgogo.GetObjectOffset(obj, LocalObjects)
+ size = libgogo.GetObjectSizeAligned(obj)
+ tempAddr = tempAddr + size - 8 //Due to sign of the offset (p.e.
-8(SP)), the offsets starts at the last byte and end at the first one
+ } else { //Global variable or local parameter
+ if kind == 1 { //Global variable
+ tempAddr = libgogo.GetObjectOffset(obj, GlobalObjects)
+ } else { //Local parameter (kind = 2)
+ tempAddr = libgogo.GetObjectOffset(obj, CurrentFunction.Fields)
+ }
+ }
+ libgogo.SetItem(item, libgogo.MODE_VAR, obj.ObjType, obj.PtrType,
tempAddr, 0, kind) //Varible item of given kind
}

//
// Converts an object representing a parameter of a function call into an
item with the correct address offset
//
func ObjectToStackParameter(obj *libgogo.ObjectDesc, FunctionCalled
*libgogo.TypeDesc, stackoffset uint64) *libgogo.Item {
- var OldLocalObjects *libgogo.ObjectDesc;
- var ReturnItem *libgogo.Item;
- var ObjSize uint64;
- ObjSize = libgogo.GetObjectSizeAligned(obj);
- OldLocalObjects = LocalObjects; //Save pointer to local objects
- LocalObjects = FunctionCalled.Fields; //Use parameters with local
object offsets
- ReturnItem = libgogo.NewItem();
- VariableObjectDescToItem(obj, ReturnItem, 0); //Treat parameter as if
it was a local object
- ReturnItem.A = stackoffset - 8 - ReturnItem.A - 8 + ObjSize; //Add
offset (total size of parameters and variables); compensate both local
offsets (stackoffset and ReturnItem.A) by subtracting -8 for each, then
adding the parameter size
- if FunctionCalled.ForwardDecl == 1 { //Add linker information
- ReturnItem.LinkerInformation = "##1##";
- libgogo.StringAppend(&ReturnItem.LinkerInformation,
FunctionCalled.PackageName);
- libgogo.StringAppend(&ReturnItem.LinkerInformation, "·");
- libgogo.StringAppend(&ReturnItem.LinkerInformation,
FunctionCalled.Name);
- libgogo.StringAppend(&ReturnItem.LinkerInformation, "##");
- ReturnItem.A = ReturnItem.A + 100000; //Bias to avoid underflows
- }
- LocalObjects = OldLocalObjects; //Restore old local objects pointer
- return ReturnItem;
+ var OldLocalObjects *libgogo.ObjectDesc
+ var ReturnItem *libgogo.Item
+ var ObjSize uint64
+ ObjSize = libgogo.GetObjectSizeAligned(obj)
+ OldLocalObjects = LocalObjects //Save pointer to local objects
+ LocalObjects = FunctionCalled.Fields //Use parameters with local object
offsets
+ ReturnItem = libgogo.NewItem()
+ VariableObjectDescToItem(obj, ReturnItem, 0) //Treat
parameter as if it was a local object
+ ReturnItem.A = stackoffset - 8 - ReturnItem.A - 8 + ObjSize //Add offset
(total size of parameters and variables); compensate both local offsets
(stackoffset and ReturnItem.A) by subtracting -8 for each, then adding the
parameter size
+ if FunctionCalled.ForwardDecl == 1 { //Add linker
information
+ ReturnItem.LinkerInformation = "##1##"
+ libgogo.StringAppend(&ReturnItem.LinkerInformation,
FunctionCalled.PackageName)
+ libgogo.StringAppend(&ReturnItem.LinkerInformation, "·")
+ libgogo.StringAppend(&ReturnItem.LinkerInformation, FunctionCalled.Name)
+ libgogo.StringAppend(&ReturnItem.LinkerInformation, "##")
+ ReturnItem.A = ReturnItem.A + 100000 //Bias to avoid underflows
+ }
+ LocalObjects = OldLocalObjects //Restore old local objects pointer
+ return ReturnItem
}

//
@@ -357,79 +357,79 @@
// name
//
func NewFunction(name string, packagename string, forwarddecl uint64)
*libgogo.TypeDesc {
- var TempType *libgogo.TypeDesc;
- var DontAppend uint64 = 0;
- var NewFct *libgogo.TypeDesc;
- if Compile != 0 {
- NewFct = libgogo.NewType(name, packagename, forwarddecl, 0, nil);
+ var TempType *libgogo.TypeDesc
+ var DontAppend uint64 = 0
+ var NewFct *libgogo.TypeDesc
+ if Compile != 0 {
+ NewFct = libgogo.NewType(name, packagename, forwarddecl, 0, nil)
if forwarddecl == 0 {
- CurrentFunction = NewFct;
+ CurrentFunction = NewFct
} else {
- NeedsLink = 1; // We need linking because of a fwd declared
function
- }
- TempType = libgogo.GetType(name, packagename, GlobalFunctions, 1);
- if TempType != nil {
- if TempType.ForwardDecl == 1 { //Unset forward declaration
- TempType.ForwardDecl = forwarddecl;
- DontAppend = 1; //Don't add function again
- NewFct = TempType;
- CurrentFunction = NewFct;
- fwdParamCount = 0; //Start over with new parameters
- } else {
- SymbolTableError("duplicate function", name, "in package",
packagename);
- }
- }
- if DontAppend == 0 {
- GlobalFunctions = libgogo.AppendType(NewFct, GlobalFunctions);
- }
- }
- return NewFct;
+ NeedsLink = 1 // We need linking because of a fwd declared function
+ }
+ TempType = libgogo.GetType(name, packagename, GlobalFunctions, 1)
+ if TempType != nil {
+ if TempType.ForwardDecl == 1 { //Unset forward declaration
+ TempType.ForwardDecl = forwarddecl
+ DontAppend = 1 //Don't add function again
+ NewFct = TempType
+ CurrentFunction = NewFct
+ fwdParamCount = 0 //Start over with new parameters
+ } else {
+ SymbolTableError("duplicate function", name, "in package", packagename)
+ }
+ }
+ if DontAppend == 0 {
+ GlobalFunctions = libgogo.AppendType(NewFct, GlobalFunctions)
+ }
+ }
+ return NewFct
}

//
// Adds a return parameter to the given function if necessary and returns
it
//
func AddReturnParameter(CurrentFunction *libgogo.TypeDesc,
ReturnValuePseudoObject *libgogo.ObjectDesc) *libgogo.ObjectDesc {
- var TempObject *libgogo.ObjectDesc;
- if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base != nil)
{ //Implementation of forward declared function
- TempObject = libgogo.GetObject("return value", "",
CurrentFunction.Fields); //Check if there is a return value
- if TempObject != nil { //Type check
- //TODO (maybe): Actually required down-conversion
- //CorrectArtificialParameterForced(CurrentFunction,
TempObject, ReturnValuePseudoObject.ObjType,
ReturnValuePseudoObject.PtrType, 0); //Perform up-conversion if necessary
- if (TempObject.ObjType != ReturnValuePseudoObject.ObjType) ||
(TempObject.PtrType != ReturnValuePseudoObject.PtrType) {
- SymbolTableError("Function has been forward declared
with", "different", "return value type, function", CurrentFunction.Name);
- }
- }
- ReturnValuePseudoObject = TempObject; //Return return value object
of forward declaration
- } else { //Default return value declaration
- if ReturnValuePseudoObject != nil {
- libgogo.AddParameters(ReturnValuePseudoObject,
CurrentFunction); //Treat return value like an additional parameter at the
end of the parameter list
- CurrentFunction.Len = CurrentFunction.Len - 1; //Don't count
parameter as input parameter
- }
- }
- return ReturnValuePseudoObject;
+ var TempObject *libgogo.ObjectDesc
+ if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base != nil) {
//Implementation of forward declared function
+ TempObject = libgogo.GetObject("return value", "",
CurrentFunction.Fields) //Check if there is a return value
+ if TempObject != nil
{ //Type check
+ //TODO (maybe): Actually required down-conversion
+ //CorrectArtificialParameterForced(CurrentFunction, TempObject,
ReturnValuePseudoObject.ObjType, ReturnValuePseudoObject.PtrType, 0);
//Perform up-conversion if necessary
+ if (TempObject.ObjType != ReturnValuePseudoObject.ObjType) ||
(TempObject.PtrType != ReturnValuePseudoObject.PtrType) {
+ SymbolTableError("Function has been forward declared
with", "different", "return value type, function", CurrentFunction.Name)
+ }
+ }
+ ReturnValuePseudoObject = TempObject //Return return value object of
forward declaration
+ } else { //Default return value declaration
+ if ReturnValuePseudoObject != nil {
+ libgogo.AddParameters(ReturnValuePseudoObject, CurrentFunction) //Treat
return value like an additional parameter at the end of the parameter list
+ CurrentFunction.Len = CurrentFunction.Len - 1 //Don't
count parameter as input parameter
+ }
+ }
+ return ReturnValuePseudoObject
}

//
// Checks if there are sufficient parameters for a previously forward
declared function
//
func FwdDeclCheckIfNecessary() {
- if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base != nil)
{
- ParameterCheck_More(CurrentFunction, fwdParamCount); //Check
parameter count
- }
+ if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base != nil) {
+ ParameterCheck_More(CurrentFunction, fwdParamCount) //Check parameter
count
+ }
}

//
// Fails if the current function declaration has no return value, but is
required to have one through previous forward declarations
//
func AssertReturnTypeIfNecessary(ReturnValuePseudoObject
*libgogo.ObjectDesc) {
- var TempObject *libgogo.ObjectDesc;
- if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base != nil)
{ //Implementation of forward declared function
- TempObject = libgogo.GetObject("return value", "",
CurrentFunction.Fields); //Check if there is a return value
- if (TempObject != nil) && (ReturnValuePseudoObject == nil) {
- SymbolTableError("Function has been forward declared
with", "a", "return value, function", CurrentFunction.Name);
- }
- }
+ var TempObject *libgogo.ObjectDesc
+ if (CurrentFunction.ForwardDecl == 0) && (CurrentFunction.Base != nil) {
//Implementation of forward declared function
+ TempObject = libgogo.GetObject("return value", "",
CurrentFunction.Fields) //Check if there is a return value
+ if (TempObject != nil) && (ReturnValuePseudoObject == nil) {
+ SymbolTableError("Function has been forward declared
with", "a", "return value, function", CurrentFunction.Name)
+ }
+ }
}

//
@@ -437,25 +437,25 @@
// Returns a new forward declared function if there is no function name
matching in the package given
//
func ApplyFunctionSelector(PackageFunction *libgogo.TypeDesc, name string)
*libgogo.TypeDesc {
- var boolFlag uint64;
- var tempFcn *libgogo.TypeDesc;
- var ReturnedFunction *libgogo.TypeDesc = nil;
- boolFlag = libgogo.StringLength(PackageFunction.Name);
- if boolFlag != 0 {
- SymbolTableError("Cannot apply a selector to", "a", "function,
function", PackageFunction.Name);
- } else {
- tempFcn = libgogo.GetType(name, PackageFunction.PackageName,
GlobalFunctions, 1); //Check global functions
- if tempFcn == nil { //New forward declaration
- tempFcn = NewFunction(name, PackageFunction.PackageName, 1);
- ReturnedFunction = tempFcn; //Assign new tempFcn pointer to
PackageFunction (outside this function)
- }
- PackageFunction.Name = tempFcn.Name;
- PackageFunction.Len = tempFcn.Len;
- PackageFunction.Fields = tempFcn.Fields;
- PackageFunction.ForwardDecl = tempFcn.ForwardDecl;
- PackageFunction.Base = tempFcn.Base;
- }
- return ReturnedFunction;
+ var boolFlag uint64
+ var tempFcn *libgogo.TypeDesc
+ var ReturnedFunction *libgogo.TypeDesc = nil
+ boolFlag = libgogo.StringLength(PackageFunction.Name)
+ if boolFlag != 0 {
+ SymbolTableError("Cannot apply a selector to", "a", "function,
function", PackageFunction.Name)
+ } else {
+ tempFcn = libgogo.GetType(name, PackageFunction.PackageName,
GlobalFunctions, 1) //Check global functions
+ if tempFcn == nil
{ //New
forward declaration
+ tempFcn = NewFunction(name, PackageFunction.PackageName, 1)
+ ReturnedFunction = tempFcn //Assign new tempFcn pointer to
PackageFunction (outside this function)
+ }
+ PackageFunction.Name = tempFcn.Name
+ PackageFunction.Len = tempFcn.Len
+ PackageFunction.Fields = tempFcn.Fields
+ PackageFunction.ForwardDecl = tempFcn.ForwardDecl
+ PackageFunction.Base = tempFcn.Base
+ }
+ return ReturnedFunction
}

//
@@ -463,172 +463,172 @@
// Returns a new forward declared function if there is no function name
matching in current package
//
func PackageFunctionToNameFunction(PackageFunction *libgogo.TypeDesc)
*libgogo.TypeDesc {
- var tempFcn *libgogo.TypeDesc;
- var ReturnedFunction *libgogo.TypeDesc = nil;
- tempFcn = libgogo.GetType(PackageFunction.PackageName, CurrentPackage,
GlobalFunctions, 1); //Check global functions
- if tempFcn == nil { //New forward declaration
- tempFcn = NewFunction(PackageFunction.PackageName, CurrentPackage,
1);
- ReturnedFunction = tempFcn; //Assign new tempFcn pointer to
PackageFunction (outside this function)
- }
- PackageFunction.Name = tempFcn.Name;
- PackageFunction.PackageName = tempFcn.PackageName;
- PackageFunction.Len = tempFcn.Len;
- PackageFunction.Fields = tempFcn.Fields;
- PackageFunction.ForwardDecl = tempFcn.ForwardDecl;
- PackageFunction.Base = tempFcn.Base;
- return ReturnedFunction;
+ var tempFcn *libgogo.TypeDesc
+ var ReturnedFunction *libgogo.TypeDesc = nil
+ tempFcn = libgogo.GetType(PackageFunction.PackageName, CurrentPackage,
GlobalFunctions, 1) //Check global functions
+ if tempFcn == nil
{
//New forward declaration
+ tempFcn = NewFunction(PackageFunction.PackageName, CurrentPackage, 1)
+ ReturnedFunction = tempFcn //Assign new tempFcn pointer to
PackageFunction (outside this function)
+ }
+ PackageFunction.Name = tempFcn.Name
+ PackageFunction.PackageName = tempFcn.PackageName
+ PackageFunction.Len = tempFcn.Len
+ PackageFunction.Fields = tempFcn.Fields
+ PackageFunction.ForwardDecl = tempFcn.ForwardDecl
+ PackageFunction.Base = tempFcn.Base
+ return ReturnedFunction
}

func VariableOrFieldAccess(item *libgogo.Item, packagename string, name
string) {
- var boolFlag uint64;
- var tempObject *libgogo.ObjectDesc;
- var tempList *libgogo.ObjectDesc;
- if (item.Itemtype == nil) && (item.A == 0) && (item.R == 0) { //Item
undefined, only package known => Find object
- tempObject = libgogo.GetObject(name, packagename, LocalObjects);
//Check local objects
- tempList = LocalObjects;
- if tempObject == nil {
- tempObject = libgogo.GetObject(name, packagename, GlobalObjects);
//Check global objects
- tempList = GlobalObjects;
- }
- if tempObject == nil {
- SymbolTableError("Package", packagename, "has no variable named",
name);
- }
- if tempList == LocalObjects { //Local
- VariableObjectDescToItem(tempObject, item, 0); //Local variable
- } else { //Global
- VariableObjectDescToItem(tempObject, item, 1); //Global variable
- }
- } else { //Field access
- if Compile != 0 {
- if item.Itemtype == nil {
- SymbolTableError("Type has", "no", "fields:", "?");
- }
- if item.Itemtype.Form != libgogo.FORM_STRUCT { //Struct check
- SymbolTableError("Type is", "not a", "struct:",
item.Itemtype.Name);
- } else {
- boolFlag = libgogo.HasField(name, item.Itemtype);
- if boolFlag == 0 { //Field check
- SymbolTableError("Type", item.Itemtype.Name, "has no
field named", name);
- } else {
- tempObject = libgogo.GetField(name, item.Itemtype);
- boolFlag = libgogo.GetFieldOffset(tempObject,
item.Itemtype); //Calculate offset
- GenerateFieldAccess(item, boolFlag);
- item.Itemtype = tempObject.ObjType; //Set item type to
field type
- item.PtrType = tempObject.PtrType;
- }
- }
- }
- }
+ var boolFlag uint64
+ var tempObject *libgogo.ObjectDesc
+ var tempList *libgogo.ObjectDesc
+ if (item.Itemtype == nil) && (item.A == 0) && (item.R == 0) { //Item
undefined, only package known => Find object
+ tempObject = libgogo.GetObject(name, packagename, LocalObjects) //Check
local objects
+ tempList = LocalObjects
+ if tempObject == nil {
+ tempObject = libgogo.GetObject(name, packagename, GlobalObjects)
//Check global objects
+ tempList = GlobalObjects
+ }
+ if tempObject == nil {
+ SymbolTableError("Package", packagename, "has no variable named", name)
+ }
+ if tempList == LocalObjects { //Local
+ VariableObjectDescToItem(tempObject, item, 0) //Local variable
+ } else { //Global
+ VariableObjectDescToItem(tempObject, item, 1) //Global variable
+ }
+ } else { //Field access
+ if Compile != 0 {
+ if item.Itemtype == nil {
+ SymbolTableError("Type has", "no", "fields:", "?")
+ }
+ if item.Itemtype.Form != libgogo.FORM_STRUCT { //Struct check
+ SymbolTableError("Type is", "not a", "struct:", item.Itemtype.Name)
+ } else {
+ boolFlag = libgogo.HasField(name, item.Itemtype)
+ if boolFlag == 0 { //Field check
+ SymbolTableError("Type", item.Itemtype.Name, "has no field named",
name)
+ } else {
+ tempObject = libgogo.GetField(name, item.Itemtype)
+ boolFlag = libgogo.GetFieldOffset(tempObject, item.Itemtype)
//Calculate offset
+ GenerateFieldAccess(item, boolFlag)
+ item.Itemtype = tempObject.ObjType //Set item type to field type
+ item.PtrType = tempObject.PtrType
+ }
+ }
+ }
+ }
}

//
// Checks whether array access is possible to the given item
//
-func ArrayAccessCheck(item *libgogo.Item, packagename string) {
- var boolFlag uint64;
- if Compile != 0 {
- if (item.Itemtype == nil) && (item.A == 0) && (item.R == 0) {
- SymbolTableError("No array access possible to", "", "package",
packagename);
- }
- if item.Itemtype.Form != libgogo.FORM_ARRAY { //Array check
- SymbolTableError("Type is", "not an", "array:",
item.Itemtype.Name);
- }
- if item.Itemtype == string_t { //Derefer string address at offset
0 to access actual byte array of characters
- boolFlag = item.PtrType; //Save old value of PtrType
- item.PtrType = 1; //Force deref.
- DereferItemIfNecessary(item); //Actual deref.
- item.PtrType = boolFlag; //Restore old value of PtrType
- }
- }
+func ArrayAccessCheck(item *libgogo.Item, packagename string) {
+ var boolFlag uint64
+ if Compile != 0 {
+ if (item.Itemtype == nil) && (item.A == 0) && (item.R == 0) {
+ SymbolTableError("No array access possible to", "", "package",
packagename)
+ }
+ if item.Itemtype.Form != libgogo.FORM_ARRAY { //Array check
+ SymbolTableError("Type is", "not an", "array:", item.Itemtype.Name)
+ }
+ if item.Itemtype == string_t { //Derefer string address at offset 0 to
access actual byte array of characters
+ boolFlag = item.PtrType //Save old value of PtrType
+ item.PtrType = 1 //Force deref.
+ DereferItemIfNecessary(item) //Actual deref.
+ item.PtrType = boolFlag //Restore old value of PtrType
+ }
+ }
}

//
// Tries to find a variable based on the information collected in the item
given
//
func FindIdentifierAndParseSelector(item *libgogo.Item) {
- var boolFlag uint64;
- var tempObject *libgogo.ObjectDesc;
- var tempList *libgogo.ObjectDesc;
- var packagename string;
- if Compile != 0 {
+ var boolFlag uint64
+ var tempObject *libgogo.ObjectDesc
+ var tempList *libgogo.ObjectDesc
+ var packagename string
+ if Compile != 0 {
//Token can be package name
- boolFlag = libgogo.FindPackageName(tok.strValue, GlobalObjects); //Check
global objects
+ boolFlag = libgogo.FindPackageName(tok.strValue, GlobalObjects) //Check
global objects
if boolFlag == 0 {
- boolFlag = libgogo.FindPackageName(tok.strValue, LocalObjects);
//Check local objects
+ boolFlag = libgogo.FindPackageName(tok.strValue, LocalObjects) //Check
local objects
}
if (boolFlag == 0) && (CurrentFunction != nil) {
- boolFlag = libgogo.FindPackageName(tok.strValue,
CurrentFunction.Fields); //Check local parameters
+ boolFlag = libgogo.FindPackageName(tok.strValue,
CurrentFunction.Fields) //Check local parameters
}
if boolFlag == 0 { //Token is not package name, but identifier
- tempObject = libgogo.GetObject(tok.strValue, CurrentPackage,
LocalObjects); //Check local objects
- tempList = LocalObjects;
+ tempObject = libgogo.GetObject(tok.strValue, CurrentPackage,
LocalObjects) //Check local objects
+ tempList = LocalObjects
if tempObject == nil {
- if CurrentFunction != nil {
- tempObject = libgogo.GetObject(tok.strValue, CurrentPackage,
CurrentFunction.Fields); //Check local parameters
- tempList = CurrentFunction.Fields;
- }
- if tempObject == nil {
- tempObject = libgogo.GetObject(tok.strValue, CurrentPackage,
GlobalObjects); //Check global objects
- tempList = GlobalObjects;
- }
+ if CurrentFunction != nil {
+ tempObject = libgogo.GetObject(tok.strValue, CurrentPackage,
CurrentFunction.Fields) //Check local parameters
+ tempList = CurrentFunction.Fields
+ }
+ if tempObject == nil {
+ tempObject = libgogo.GetObject(tok.strValue, CurrentPackage,
GlobalObjects) //Check global objects
+ tempList = GlobalObjects
+ }
}
if tempObject == nil {
- SymbolTableError("Undefined", "", "variable", tok.strValue);
+ SymbolTableError("Undefined", "", "variable", tok.strValue)
}
if tempList == LocalObjects { //Local
- VariableObjectDescToItem(tempObject, item, 0); //Local variable
+ VariableObjectDescToItem(tempObject, item, 0) //Local variable
} else { //Global or parameter
- if tempList == GlobalObjects { //Global
- VariableObjectDescToItem(tempObject, item, 1); //Global variable
- } else { //Parameter
- VariableObjectDescToItem(tempObject, item, 2); //Local parameter
- }
- }
- ParseSelector(item, CurrentPackage); //Parse selectors for an object
in the current package
+ if tempList == GlobalObjects { //Global
+ VariableObjectDescToItem(tempObject, item, 1) //Global variable
+ } else { //Parameter
+ VariableObjectDescToItem(tempObject, item, 2) //Local parameter
+ }
+ }
+ ParseSelector(item, CurrentPackage) //Parse selectors for an object in
the current package
} else { //Token is package name
- libgogo.SetItem(item, 0, nil, 0, 0, 0, 0); //Mark item as not being
set
- packagename = tok.strValue; //Save package name
- ParseSelector(item, tok.strValue); //Parse selectors for an
undefined object in the given package
- if (item.Itemtype == nil) && (item.A == 0) && (item.R == 0) {
- SymbolTableError("Cannot use package", "", "as a variable:",
packagename);
- }
- }
- } else {
- ParseSelector(item, CurrentPackage);
- }
+ libgogo.SetItem(item, 0, nil, 0, 0, 0, 0) //Mark item as not being set
+ packagename = tok.strValue //Save package name
+ ParseSelector(item, tok.strValue) //Parse selectors for an
undefined object in the given package
+ if (item.Itemtype == nil) && (item.A == 0) && (item.R == 0) {
+ SymbolTableError("Cannot use package", "", "as a variable:",
packagename)
+ }
+ }
+ } else {
+ ParseSelector(item, CurrentPackage)
+ }
}

//
// Tries to find a function based on the information collected in the item
given; if there is none, an according forward declaration will be made
//
func FindIdentifierAndParseSelector_FunctionCall(FunctionCalled
*libgogo.TypeDesc) *libgogo.TypeDesc {
- var boolFlag uint64;
- var tempFcn *libgogo.TypeDesc;
- if Compile != 0 {
+ var boolFlag uint64
+ var tempFcn *libgogo.TypeDesc
***The diff for this file has been truncated for email.***
=======================================
--- /src/token.go Tue Aug 17 09:58:38 2010
+++ /src/token.go Wed Aug 18 10:20:16 2010
@@ -11,76 +11,76 @@
// The struct is used by the scanner and parser.
//
type Token struct {
- id uint64; // The id. Is one of TOKEN_*
- intValue uint64; /* value storing the integer value if the token is
-TOKEN_INTEGER */
- strValue string; /* Value storing the token string if the token is
-TOKEN_STRING or TOKEN_IDENTIFIER */
- nextChar byte; /* Sometime the next char is already read. It is
stored
-here to be re-assigned in the next GetNextToken() round [used by the
scanner] */
- nextToken uint64; // look-ahead (LL1) token [used by the parser]
-
- nextTokenId[4] uint64;
- nextTokenValStr[4] string;
- llCnt uint64;
- toRead uint64;
-};
+ id uint64 // The id. Is one of TOKEN_*
+ intValue uint64 /* value storing the integer value if the token is
+ TOKEN_INTEGER */
+ strValue string /* Value storing the token string if the token is
+ TOKEN_STRING or TOKEN_IDENTIFIER */
+ nextChar byte /* Sometime the next char is already read. It is stored
+ here to be re-assigned in the next GetNextToken() round [used by the
scanner] */
+ nextToken uint64 // look-ahead (LL1) token [used by the parser]
+
+ nextTokenId [4]uint64
+ nextTokenValStr [4]string
+ llCnt uint64
+ toRead uint64
+}

//
// Global token (current token processed)
//
-var tok Token;
+var tok Token

//
// Set of recognized tokens
//
-var TOKEN_IDENTIFIER uint64 = 1; // Identifier
-var TOKEN_STRING uint64 = 2; // String using "..."
-var TOKEN_EOS uint64 = 3; // End of Scan
-var TOKEN_LBRAC uint64 = 4; // Left bracket '('
-var TOKEN_RBRAC uint64 = 5; // Right bracket ')'
-var TOKEN_LSBRAC uint64 = 6; // Left square bracket '['
-var TOKEN_RSBRAC uint64 = 7; // Right square bracket ']'
-var TOKEN_INTEGER uint64 = 8; // Integer number
-var TOKEN_LCBRAC uint64 = 9; // Left curly bracket '{'
-var TOKEN_RCBRAC uint64 = 10; // Right curly bracket '}'
-var TOKEN_PT uint64 = 11; // Point '.'
-var TOKEN_NOT uint64 = 12; // Boolean negation '!'
-var TOKEN_NOTEQUAL uint64 = 13; // Comparison, not equal '!='
-var TOKEN_SEMICOLON uint64 = 14; // Semi-colon ';'
-var TOKEN_COLON uint64 = 15; // Colon ','
-var TOKEN_ASSIGN uint64 = 16; // Assignment '='
-var TOKEN_EQUALS uint64 = 17; // Equal comparison '=='
-var TOKEN_CHAR uint64 = 18; // Single Quoted Character 'x'
-var TOKEN_REL_AND uint64 = 19; // AND Relation '&&'
-var TOKEN_REL_OR uint64 = 20; // OR Relation '||'
-var TOKEN_REL_GTOE uint64 = 21; // Greather-Than or Equal '>='
-var TOKEN_REL_GT uint64 = 22; // Greather-Than '>'
-var TOKEN_REL_LTOE uint64 = 23; // Less-Than or Equal '<='
-var TOKEN_REL_LT uint64 = 24; // Less-Than '<'
-var TOKEN_ARITH_PLUS uint64 = 25; // Arith. Plus '+'
-var TOKEN_ARITH_MINUS uint64 = 26;// Arith. Minus '-'
-var TOKEN_ARITH_MUL uint64 = 27; // Arith. Multiplication '*'
-var TOKEN_ARITH_DIV uint64 = 28; // Arith. Division '/'
-var TOKEN_OP_ADR uint64 = 29; // Address operator '&'
+var TOKEN_IDENTIFIER uint64 = 1 // Identifier
+var TOKEN_STRING uint64 = 2 // String using "..."
+var TOKEN_EOS uint64 = 3 // End of Scan
+var TOKEN_LBRAC uint64 = 4 // Left bracket '('
+var TOKEN_RBRAC uint64 = 5 // Right bracket ')'
+var TOKEN_LSBRAC uint64 = 6 // Left square bracket '['
+var TOKEN_RSBRAC uint64 = 7 // Right square bracket ']'
+var TOKEN_INTEGER uint64 = 8 // Integer number
+var TOKEN_LCBRAC uint64 = 9 // Left curly bracket '{'
+var TOKEN_RCBRAC uint64 = 10 // Right curly bracket '}'
+var TOKEN_PT uint64 = 11 // Point '.'
+var TOKEN_NOT uint64 = 12 // Boolean negation '!'
+var TOKEN_NOTEQUAL uint64 = 13 // Comparison, not equal '!='
+var TOKEN_SEMICOLON uint64 = 14 // Semi-colon ';'
+var TOKEN_COLON uint64 = 15 // Colon ','
+var TOKEN_ASSIGN uint64 = 16 // Assignment '='
+var TOKEN_EQUALS uint64 = 17 // Equal comparison '=='
+var TOKEN_CHAR uint64 = 18 // Single Quoted Character 'x'
+var TOKEN_REL_AND uint64 = 19 // AND Relation '&&'
+var TOKEN_REL_OR uint64 = 20 // OR Relation '||'
+var TOKEN_REL_GTOE uint64 = 21 // Greather-Than or Equal '>='
+var TOKEN_REL_GT uint64 = 22 // Greather-Than '>'
+var TOKEN_REL_LTOE uint64 = 23 // Less-Than or Equal '<='
+var TOKEN_REL_LT uint64 = 24 // Less-Than '<'
+var TOKEN_ARITH_PLUS uint64 = 25 // Arith. Plus '+'
+var TOKEN_ARITH_MINUS uint64 = 26 // Arith. Minus '-'
+var TOKEN_ARITH_MUL uint64 = 27 // Arith. Multiplication '*'
+var TOKEN_ARITH_DIV uint64 = 28 // Arith. Division '/'
+var TOKEN_OP_ADR uint64 = 29 // Address operator '&'

//
// Advanced tokens, that are generated in the 2nd step from identifiers
// The tokens represent the corresponding language keywords.
//
-var TOKEN_FOR uint64 = 101;
-var TOKEN_IF uint64 = 102;
-var TOKEN_TYPE uint64 = 103;
-var TOKEN_CONST uint64 = 104;
-var TOKEN_VAR uint64 = 105;
-var TOKEN_STRUCT uint64 = 106;
-var TOKEN_RETURN uint64 = 107;
-var TOKEN_FUNC uint64 = 108;
-var TOKEN_PACKAGE uint64 = 109;
-var TOKEN_IMPORT uint64 = 110;
-var TOKEN_ELSE uint64 = 111;
-var TOKEN_BREAK uint64 = 112;
-var TOKEN_CONTINUE uint64 = 113;
+var TOKEN_FOR uint64 = 101
+var TOKEN_IF uint64 = 102
+var TOKEN_TYPE uint64 = 103
+var TOKEN_CONST uint64 = 104
+var TOKEN_VAR uint64 = 105
+var TOKEN_STRUCT uint64 = 106
+var TOKEN_RETURN uint64 = 107
+var TOKEN_FUNC uint64 = 108
+var TOKEN_PACKAGE uint64 = 109
+var TOKEN_IMPORT uint64 = 110
+var TOKEN_ELSE uint64 = 111
+var TOKEN_BREAK uint64 = 112
+var TOKEN_CONTINUE uint64 = 113

//
// Helper functions
@@ -90,146 +90,146 @@
// Resets the token to the initial state
//
func ResetToken() {
- tok.id = 0;
- tok.nextChar = 0;
- tok.nextToken = 0;
- tok.llCnt = 0;
- tok.intValue = 0;
- tok.strValue = "";
- tok.toRead = 0;
+ tok.id = 0
+ tok.nextChar = 0
+ tok.nextToken = 0
+ tok.llCnt = 0
+ tok.intValue = 0
+ tok.strValue = ""
+ tok.toRead = 0
}

//
// Returns a string representation of a supplied token.
//
-func TokenToString (id uint64) string {
- var retStr string = "";
- var strBuf string = "";
-
- if id == TOKEN_IDENTIFIER {
- retStr = "<identifier> (value: ";
- libgogo.StringAppend(&retStr, tok.strValue);
- libgogo.CharAppend(&retStr,')');
- }
- if id == TOKEN_STRING {
- retStr = "<string> (value: ";
- libgogo.StringAppend(&retStr, tok.strValue);
- libgogo.CharAppend(&retStr,')');
- }
- if id == TOKEN_EOS {
- retStr = "<END-OF-SCAN>";
- }
- if id == TOKEN_LBRAC {
- retStr = "(";
- }
- if id == TOKEN_RBRAC {
- retStr = ")";
- }
- if id == TOKEN_LSBRAC {
- retStr = "[";
- }
- if id == TOKEN_RSBRAC {
- retStr = "]";
- }
- if id == TOKEN_INTEGER {
- retStr = "<integer> (value: ";
- strBuf = libgogo.IntToString(tok.intValue);
- libgogo.StringAppend(&retStr, strBuf);
- libgogo.CharAppend(&retStr,')');
- }
- if id == TOKEN_LCBRAC {
- retStr = "{";
- }
- if id == TOKEN_RCBRAC {
- retStr = "}";
- }
- if id == TOKEN_PT {
- retStr = ".";
- }
- if id == TOKEN_NOT {
- retStr = "!";
- }
- if id == TOKEN_NOTEQUAL {
- retStr = "!=";
- }
- if id == TOKEN_SEMICOLON {
- retStr = ";";
- }
- if id == TOKEN_COLON {
- retStr = ",";
- }
- if id == TOKEN_ASSIGN {
- retStr = "=";
- }
- if id == TOKEN_EQUALS {
- retStr = "==";
- }
- if id == TOKEN_CHAR {
- retStr = "'<char>'";
- }
- if id == TOKEN_REL_AND {
- retStr = "&&";
- }
- if id == TOKEN_REL_OR {
- retStr = "||";
- }
- if id == TOKEN_REL_GTOE {
- retStr = ">=";
- }
- if id == TOKEN_REL_GT {
- retStr = ">";
- }
- if id == TOKEN_REL_LTOE {
- retStr = "<=";
- }
- if id == TOKEN_REL_LT {
- retStr = "<";
- }
- if id == TOKEN_ARITH_PLUS {
- retStr = "+";
- }
- if id == TOKEN_ARITH_MINUS {
- retStr = "-";
- }
- if id == TOKEN_ARITH_MUL {
- retStr = "*";
- }
- if id == TOKEN_ARITH_DIV {
- retStr = "/";
- }
- if id == TOKEN_OP_ADR {
- retStr = "&";
- }
- if id == TOKEN_FOR {
- retStr = "for";
- }
- if id == TOKEN_IF {
- retStr = "if";
- }
- if id == TOKEN_TYPE {
- retStr = "type";
- }
- if id == TOKEN_CONST {
- retStr = "const";
- }
- if id == TOKEN_VAR {
- retStr = "var";
- }
- if id == TOKEN_STRUCT {
- retStr = "struct";
- }
- if id == TOKEN_RETURN {
- retStr = "return";
- }
- if id == TOKEN_FUNC {
- retStr = "func";
- }
- if id == TOKEN_PACKAGE {
- retStr = "package";
- }
- if id == TOKEN_IMPORT {
- retStr = "import";
- }
-
- return retStr;
-}
+func TokenToString(id uint64) string {
+ var retStr string = ""
+ var strBuf string = ""
+
+ if id == TOKEN_IDENTIFIER {
+ retStr = "<identifier> (value: "
+ libgogo.StringAppend(&retStr, tok.strValue)
+ libgogo.CharAppend(&retStr, ')')
+ }
+ if id == TOKEN_STRING {
+ retStr = "<string> (value: "
+ libgogo.StringAppend(&retStr, tok.strValue)
+ libgogo.CharAppend(&retStr, ')')
+ }
+ if id == TOKEN_EOS {
+ retStr = "<END-OF-SCAN>"
+ }
+ if id == TOKEN_LBRAC {
+ retStr = "("
+ }
+ if id == TOKEN_RBRAC {
+ retStr = ")"
+ }
+ if id == TOKEN_LSBRAC {
+ retStr = "["
+ }
+ if id == TOKEN_RSBRAC {
+ retStr = "]"
+ }
+ if id == TOKEN_INTEGER {
+ retStr = "<integer> (value: "
+ strBuf = libgogo.IntToString(tok.intValue)
+ libgogo.StringAppend(&retStr, strBuf)
+ libgogo.CharAppend(&retStr, ')')
+ }
+ if id == TOKEN_LCBRAC {
+ retStr = "{"
+ }
+ if id == TOKEN_RCBRAC {
+ retStr = "}"
+ }
+ if id == TOKEN_PT {
+ retStr = "."
+ }
+ if id == TOKEN_NOT {
+ retStr = "!"
+ }
+ if id == TOKEN_NOTEQUAL {
+ retStr = "!="
+ }
+ if id == TOKEN_SEMICOLON {
+ retStr = ";"
+ }
+ if id == TOKEN_COLON {
+ retStr = ","
+ }
+ if id == TOKEN_ASSIGN {
+ retStr = "="
+ }
+ if id == TOKEN_EQUALS {
+ retStr = "=="
+ }
+ if id == TOKEN_CHAR {
+ retStr = "'<char>'"
+ }
+ if id == TOKEN_REL_AND {
+ retStr = "&&"
+ }
+ if id == TOKEN_REL_OR {
+ retStr = "||"
+ }
+ if id == TOKEN_REL_GTOE {
+ retStr = ">="
+ }
+ if id == TOKEN_REL_GT {
+ retStr = ">"
+ }
+ if id == TOKEN_REL_LTOE {
+ retStr = "<="
+ }
+ if id == TOKEN_REL_LT {
+ retStr = "<"
+ }
+ if id == TOKEN_ARITH_PLUS {
+ retStr = "+"
+ }
+ if id == TOKEN_ARITH_MINUS {
+ retStr = "-"
+ }
+ if id == TOKEN_ARITH_MUL {
+ retStr = "*"
+ }
+ if id == TOKEN_ARITH_DIV {
+ retStr = "/"
+ }
+ if id == TOKEN_OP_ADR {
+ retStr = "&"
+ }
+ if id == TOKEN_FOR {
+ retStr = "for"
+ }
+ if id == TOKEN_IF {
+ retStr = "if"
+ }
+ if id == TOKEN_TYPE {
+ retStr = "type"
+ }
+ if id == TOKEN_CONST {
+ retStr = "const"
+ }
+ if id == TOKEN_VAR {
+ retStr = "var"
+ }
+ if id == TOKEN_STRUCT {
+ retStr = "struct"
+ }
+ if id == TOKEN_RETURN {
+ retStr = "return"
+ }
+ if id == TOKEN_FUNC {
+ retStr = "func"
+ }
+ if id == TOKEN_PACKAGE {
+ retStr = "package"
+ }
+ if id == TOKEN_IMPORT {
+ retStr = "import"
+ }
+
+ return retStr
+}
=======================================
--- /src/utils.go Tue Aug 17 09:58:38 2010
+++ /src/utils.go Wed Aug 18 10:20:16 2010
@@ -6,117 +6,117 @@

import "./libgogo/_obj/libgogo"

-var maxErrors uint64 = 10;
-var errors uint64 = 0;
+var maxErrors uint64 = 10
+var errors uint64 = 0

func CheckDebugLevel(debugLevel uint64) uint64 {
- var retVal uint64 = 0;
- if debugLevel <= DEBUG_LEVEL {
- retVal = 1;
- }
- return retVal;
+ var retVal uint64 = 0
+ if debugLevel <= DEBUG_LEVEL {
+ retVal = 1
+ }
+ return retVal
}

func PrintDebugString(msg string, debugLevel uint64) {
- var flag uint64;
- flag = CheckDebugLevel(debugLevel);
- if flag == 1 {
- PrintHead();
- libgogo.PrintString(": DEBUG: ");
- libgogo.PrintString(msg);
- libgogo.PrintString("\n");
- }
+ var flag uint64
+ flag = CheckDebugLevel(debugLevel)
+ if flag == 1 {
+ PrintHead()
+ libgogo.PrintString(": DEBUG: ")
+ libgogo.PrintString(msg)
+ libgogo.PrintString("\n")
+ }
}

func PrintDebugChar(char byte, debugLevel uint64) {
- var flag uint64;
- flag = CheckDebugLevel(debugLevel);
- if flag == 1 {
- PrintHead();
- libgogo.PrintString(": DEBUG: ");
- libgogo.PrintChar(char);
- libgogo.PrintString("\n");
- }
+ var flag uint64
+ flag = CheckDebugLevel(debugLevel)
+ if flag == 1 {
+ PrintHead()
+ libgogo.PrintString(": DEBUG: ")
+ libgogo.PrintChar(char)
+ libgogo.PrintString("\n")
+ }
}

func BuildHead() string {
- var text string = "";
- var temp string;
- libgogo.StringAppend(&text, fileInfo[curFileIndex].filename);
- libgogo.StringAppend(&text, ":");
- temp = libgogo.IntToString(fileInfo[curFileIndex].lineCounter);
- libgogo.StringAppend(&text, temp);
- libgogo.StringAppend(&text, ":");
- temp = libgogo.IntToString(fileInfo[curFileIndex].charCounter);
- libgogo.StringAppend(&text, temp);
- return text;
+ var text string = ""
+ var temp string
+ libgogo.StringAppend(&text, fileInfo[curFileIndex].filename)
+ libgogo.StringAppend(&text, ":")
+ temp = libgogo.IntToString(fileInfo[curFileIndex].lineCounter)
+ libgogo.StringAppend(&text, temp)
+ libgogo.StringAppend(&text, ":")
+ temp = libgogo.IntToString(fileInfo[curFileIndex].charCounter)
+ libgogo.StringAppend(&text, temp)
+ return text
}

func PrintHead() {
- var head string;
- head = BuildHead();
- libgogo.PrintString(head);
+ var head string
+ head = BuildHead()
+ libgogo.PrintString(head)
}

func GlobalError(msg string) {
- PrintHead();
- libgogo.PrintString(": error: ");
- libgogo.ExitError(msg,1);
+ PrintHead()
+ libgogo.PrintString(": error: ")
+ libgogo.ExitError(msg, 1)
}

func ScanErrorString(msg string) {
- PrintHead();
- libgogo.PrintString(": syntax error: ");
- libgogo.ExitError(msg,2);
+ PrintHead()
+ libgogo.PrintString(": syntax error: ")
+ libgogo.ExitError(msg, 2)
}

func ScanErrorChar(char byte) {
- PrintHead();
- libgogo.PrintString(": syntax error: Unknown char '");
- libgogo.PrintChar(char);
- libgogo.PrintString("'.\n");
- libgogo.Exit(2);
+ PrintHead()
+ libgogo.PrintString(": syntax error: Unknown char '")
+ libgogo.PrintChar(char)
+ libgogo.PrintString("'.\n")
+ libgogo.Exit(2)
}

func ParseErrorWeak(ue uint64, expectedToken1 uint64, expectedToken2
uint64, expectedLen uint64) {
- var str string;
-
- errors = errors+1;
- PrintHead();
- libgogo.PrintString(": syntax error: unexpected token '");
- str = TokenToString(ue);
- libgogo.PrintString(str);
- libgogo.PrintString("'");
-
- if tok.id == TOKEN_INTEGER {
- libgogo.PrintString(" (value: ");
- libgogo.PrintNumber(tok.intValue);
- libgogo.PrintString(")");
- }
-
- if tok.id == TOKEN_STRING {
- libgogo.PrintString(" (value: ");
- libgogo.PrintString(tok.strValue);
- libgogo.PrintString(")");
- }
-
- if expectedLen > 0 {
- libgogo.PrintString(", expecting one of: ");
- str = TokenToString(expectedToken1);
- libgogo.PrintString(str);
- if expectedLen >= 2 {
- libgogo.PrintString(", ");
- str = TokenToString(expectedToken2);
- libgogo.PrintString(str);
- }
- }
- libgogo.PrintString("\n");
- if errors == maxErrors {
- libgogo.PrintString("Maximum number of errors (");
- libgogo.PrintNumber(maxErrors);
- libgogo.PrintString(") reached. Exiting.\n");
- libgogo.Exit(3);
- }
+ var str string
+
+ errors = errors + 1
+ PrintHead()
+ libgogo.PrintString(": syntax error: unexpected token '")
+ str = TokenToString(ue)
+ libgogo.PrintString(str)
+ libgogo.PrintString("'")
+
+ if tok.id == TOKEN_INTEGER {
+ libgogo.PrintString(" (value: ")
+ libgogo.PrintNumber(tok.intValue)
+ libgogo.PrintString(")")
+ }
+
+ if tok.id == TOKEN_STRING {
+ libgogo.PrintString(" (value: ")
+ libgogo.PrintString(tok.strValue)
+ libgogo.PrintString(")")
+ }
+
+ if expectedLen > 0 {
+ libgogo.PrintString(", expecting one of: ")
+ str = TokenToString(expectedToken1)
+ libgogo.PrintString(str)
+ if expectedLen >= 2 {
+ libgogo.PrintString(", ")
+ str = TokenToString(expectedToken2)
+ libgogo.PrintString(str)
+ }
+ }
+ libgogo.PrintString("\n")
+ if errors == maxErrors {
+ libgogo.PrintString("Maximum number of errors (")
+ libgogo.PrintNumber(maxErrors)
+ libgogo.PrintString(") reached. Exiting.\n")
+ libgogo.Exit(3)
+ }
}

//
@@ -126,68 +126,67 @@
// expectedLen . actual number of expected tokens (others will be ignored)
//
func ParseErrorFatal(ue uint64, expectedToken1 uint64, expectedToken2
uint64, expectedLen uint64) {
- ParseErrorWeak(ue, expectedToken1, expectedToken2, expectedLen);
- libgogo.Exit(3);
+ ParseErrorWeak(ue, expectedToken1, expectedToken2, expectedLen)
+ libgogo.Exit(3)
}

//
// Print an error, stop compilation and parse rest.
//
func GenErrorWeak(msg string) {
- PrintHead();
- libgogo.PrintString(": generation error: ");
- libgogo.PrintString(msg);
- libgogo.PrintString("\n");
- Compile = 0;
- ParserSync();
+ PrintHead()
+ libgogo.PrintString(": generation error: ")
+ libgogo.PrintString(msg)
+ libgogo.PrintString("\n")
+ Compile = 0
+ ParserSync()
}

//
// Linker error. Always Fatal.
//
func LinkError(msg1 string, msg2 string, msg3 string, msg4 string, msg5
string) {
- PrintHead();
- libgogo.PrintString(": linker error: ");
- libgogo.PrintString(msg1);
- libgogo.PrintString(msg2);
- libgogo.PrintString(msg3);
- libgogo.PrintString(msg4);
- libgogo.PrintString(msg5);
- libgogo.PrintString("\n");
- libgogo.Exit(5);
+ PrintHead()
+ libgogo.PrintString(": linker error: ")
+ libgogo.PrintString(msg1)
+ libgogo.PrintString(msg2)
+ libgogo.PrintString(msg3)
+ libgogo.PrintString(msg4)
+ libgogo.PrintString(msg5)
+ libgogo.PrintString("\n")
+ libgogo.Exit(5)
}

//
// Linker warning
//
func LinkWarn(msg1 string, msg2 string, msg3 string, msg4 string, msg5
string) {
- PrintHead();
- libgogo.PrintString(": linker warning: ");
- libgogo.PrintString(msg1);
- libgogo.PrintString(msg2);
- libgogo.PrintString(msg3);
- libgogo.PrintString(msg4);
- libgogo.PrintString(msg5);
- libgogo.PrintString("\n");
+ PrintHead()
+ libgogo.PrintString(": linker warning: ")
+ libgogo.PrintString(msg1)
+ libgogo.PrintString(msg2)
+ libgogo.PrintString(msg3)
+ libgogo.PrintString(msg4)
+ libgogo.PrintString(msg5)
+ libgogo.PrintString("\n")
}

func SymbolTableError(msg string, position string, msg2 string, identifier
string) {
- var strLen uint64;
- PrintHead();
- libgogo.PrintString(": symbol table error: ");
- libgogo.PrintString(msg);
- libgogo.PrintString(" ");
- libgogo.PrintString(position);
- strLen = libgogo.StringLength(position);
- if strLen != 0 {
- libgogo.PrintString(" ");
- }
- libgogo.PrintString(msg2);
- libgogo.PrintString(" '");
- libgogo.PrintString(identifier);
- libgogo.PrintString("'\n");
- PrintGlobalSymbolTable(); //May be useful for debugging purposes
- PrintLocalSymbolTable();
- libgogo.Exit(4);
-}
-
+ var strLen uint64
+ PrintHead()
+ libgogo.PrintString(": symbol table error: ")
+ libgogo.PrintString(msg)
+ libgogo.PrintString(" ")
+ libgogo.PrintString(position)
+ strLen = libgogo.StringLength(position)
+ if strLen != 0 {
+ libgogo.PrintString(" ")
+ }
+ libgogo.PrintString(msg2)
+ libgogo.PrintString(" '")
+ libgogo.PrintString(identifier)
+ libgogo.PrintString("'\n")
+ PrintGlobalSymbolTable() //May be useful for debugging purposes
+ PrintLocalSymbolTable()
+ libgogo.Exit(4)
+}
Reply all
Reply to author
Forward
0 new messages