-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We have implemented function calls in a way which should facilitate closures and interfaces a great deal. rather than the traditional Anderson copy/transfer constraints of arguments to parameters and function results to caller local results, we 1. represent each function in contiguous memory as a sequence (p0, p1, ..., pn, r0, r1, ..., rm) where each pi is a pointer to an object of type of parameter i, and each ri is a pointer to an object of type of return i. 2. upon analyzing a function we take *pi as the starting value of the parameter. 3. Upon calling a function, we set *pi = argi and resi = *ri. Now, given 2 functions f, g of the same signature, we have copy/transfer constraints (fp0, fp1, ..., fpn, fr0, fr1, ..., frm) = (gp0, gp1, ..., gpn, gr0, gr1, ..., grn). then the points-to of each parameter and result are transfered to f from g. In this way, dynamic dispatch should be a cinch: just call the function object associated with the node, it will have all the loads/stores of any function assigned to it. Something similar should work for interfaces: we just keep a struct of function objects defined as above, and on assignment to an interface value, we assign the functions from the concrete type. Likewise, this should facilitate closures by adding a free variables component like the pi,ri components.
- Loading branch information
1 parent
2d2291b
commit 6fbbef6
Showing
4 changed files
with
109 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2021 The pal authors (see AUTHORS) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package objects | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-air/pal/memory" | ||
) | ||
|
||
// dst is the memory loc of the result. | ||
// - if f returns a single value, then that | ||
// - otherwise it is a tuple. | ||
// | ||
// args indicate the arguments at the call site. | ||
func (b *Builder) Call(f *Func, dst memory.Loc, args []memory.Loc) { | ||
fmt.Printf("n args %d n params %d\n", len(args), len(f.params)) | ||
start := 0 | ||
if f.recv != memory.NoLoc { | ||
start = 1 | ||
b.AddStore(f.recv, args[0]) | ||
} | ||
for i, arg := range args[start:] { | ||
b.AddStore(f.params[i], arg) | ||
} | ||
if dst == memory.NoLoc { | ||
return | ||
} | ||
switch len(f.results) { | ||
case 0: | ||
case 1: | ||
b.AddLoad(dst, f.results[0]) | ||
default: | ||
dstTuple := b.omap[dst].(*Tuple) | ||
for i, ret := range f.results { | ||
b.AddLoad(dstTuple.At(i), ret) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters