Reduced number of tokens processed
This commit is contained in:
parent
4f6750dc8e
commit
31845dbc48
@ -62,12 +62,6 @@ func (f *Function) Compile() {
|
|||||||
|
|
||||||
case token.GroupEnd:
|
case token.GroupEnd:
|
||||||
groupLevel--
|
groupLevel--
|
||||||
|
|
||||||
case token.BlockStart:
|
|
||||||
// Add scope
|
|
||||||
|
|
||||||
case token.BlockEnd:
|
|
||||||
// Remove scope
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,9 +123,8 @@ func (f *Function) CompileVariableDefinition(expr *expression.Expression) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := expr.Children[0].Token.Text()
|
name := expr.Children[0].Token.Text()
|
||||||
_, exists := f.Variables[name]
|
|
||||||
|
|
||||||
if exists {
|
if f.identifierExists(name) {
|
||||||
return errors.New(&errors.VariableAlreadyExists{Name: name}, f.File, expr.Children[0].Token.Position)
|
return errors.New(&errors.VariableAlreadyExists{Name: name}, f.File, expr.Children[0].Token.Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,11 +154,6 @@ func (f *Function) CompileVariableDefinition(expr *expression.Expression) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Function) identifierExists(name string) bool {
|
|
||||||
_, exists := f.Variables[name]
|
|
||||||
return exists
|
|
||||||
}
|
|
||||||
|
|
||||||
// CompileFunctionCall compiles a function call.
|
// CompileFunctionCall compiles a function call.
|
||||||
func (f *Function) CompileFunctionCall(expr *expression.Expression) error {
|
func (f *Function) CompileFunctionCall(expr *expression.Expression) error {
|
||||||
funcName := expr.Children[0].Token.Text()
|
funcName := expr.Children[0].Token.Text()
|
||||||
@ -254,6 +242,12 @@ func (f *Function) String() string {
|
|||||||
return f.Name
|
return f.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// identifierExists returns true if the identifier has been defined.
|
||||||
|
func (f *Function) identifierExists(name string) bool {
|
||||||
|
_, exists := f.Variables[name]
|
||||||
|
return exists
|
||||||
|
}
|
||||||
|
|
||||||
// isVariableDefinition returns true if the expression is a variable definition.
|
// isVariableDefinition returns true if the expression is a variable definition.
|
||||||
func isVariableDefinition(expr *expression.Expression) bool {
|
func isVariableDefinition(expr *expression.Expression) bool {
|
||||||
return expr.Token.Kind == token.Operator && expr.Token.Text() == ":="
|
return expr.Token.Kind == token.Operator && expr.Token.Text() == ":="
|
||||||
|
@ -176,12 +176,12 @@ func scanFile(path string, functions chan<- *Function) error {
|
|||||||
for i < len(tokens) {
|
for i < len(tokens) {
|
||||||
if tokens[i].Kind == token.BlockStart {
|
if tokens[i].Kind == token.BlockStart {
|
||||||
blockLevel++
|
blockLevel++
|
||||||
|
i++
|
||||||
|
|
||||||
if blockLevel == 1 {
|
if blockLevel == 1 {
|
||||||
bodyStart = i
|
bodyStart = i
|
||||||
}
|
}
|
||||||
|
|
||||||
i++
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ func scanFile(path string, functions chan<- *Function) error {
|
|||||||
Name: tokens[nameStart].Text(),
|
Name: tokens[nameStart].Text(),
|
||||||
File: file,
|
File: file,
|
||||||
Head: tokens[paramsStart:bodyStart],
|
Head: tokens[paramsStart:bodyStart],
|
||||||
Body: tokens[bodyStart : i+1],
|
Body: tokens[bodyStart:i],
|
||||||
Variables: map[string]*Variable{},
|
Variables: map[string]*Variable{},
|
||||||
CPU: cpu.CPU{
|
CPU: cpu.CPU{
|
||||||
General: x64.GeneralRegisters,
|
General: x64.GeneralRegisters,
|
||||||
|
Loading…
Reference in New Issue
Block a user