Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Changed the global variable rt.INTEGER to rt.INT.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjstahl committed May 30, 2013
1 parent 7483d22 commit 958af15
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/soma/ast/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func (i *Integer) Visit(s *rt.Scope) rt.Value {

// Methods to satisfy the rt.Value interface
func (i *Integer) Address() rt.Mailbox {
return rt.INTEGER.Address()
return rt.INT.Address()
}

func (i *Integer) LookupBehavior(name string) rt.Value {
return rt.INTEGER.LookupBehavior(name)
return rt.INT.LookupBehavior(name)
}

func (i *Integer) OID() uint64 {
Expand Down
27 changes: 10 additions & 17 deletions src/soma/lib/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ import (
"soma/rt"
)

func LoadIntegers() {
integer := rt.CreateObject(&ast.Global{Value: "Integer"}, nil, 0x7)
integer.New()

intBehaviorObj := rt.CreateObject(nil, nil, 0)
startPrimitiveBehaviors(integer, intBehaviorObj, intBehaviorMap)

rt.RT.Globals.Insert("Integer", integer.ID)
rt.INTEGER = integer
}

var intBehaviorMap = map[string]primitiveFn{
"+": intAdd,
"-": intSub,
Expand All @@ -42,31 +31,31 @@ var intBehaviorMap = map[string]primitiveFn{

func intAdd(msg *rt.AsyncMsg) {
go func() {
recv, arg := int64(msg.Args[0])>>8, int64(msg.Args[2])>>8
recv, arg := getArgIntegerValues(msg)
result := recv + arg
formatAndReturn(msg, result)
}()
}

func intSub(msg *rt.AsyncMsg) {
go func() {
recv, arg := int64(msg.Args[0])>>8, int64(msg.Args[2])>>8
recv, arg := getArgIntegerValues(msg)
result := recv - arg
formatAndReturn(msg, result)
}()
}

func intMul(msg *rt.AsyncMsg) {
go func() {
recv, arg := int64(msg.Args[0])>>8, int64(msg.Args[2])>>8
recv, arg := getArgIntegerValues(msg)
result := recv * arg
formatAndReturn(msg, result)
}()
}

func intDiv(msg *rt.AsyncMsg) {
go func() {
recv, arg := int64(msg.Args[0])>>8, int64(msg.Args[2])>>8
recv, arg := getArgIntegerValues(msg)
if arg == 0 {
rt.NIL.Return(msg)
return
Expand All @@ -78,7 +67,7 @@ func intDiv(msg *rt.AsyncMsg) {

func intEqu(msg *rt.AsyncMsg) {
go func() {
recv, arg := int64(msg.Args[0])>>8, int64(msg.Args[2])>>8
recv, arg := getArgIntegerValues(msg)
if recv == arg {
rt.TRUE.Return(msg)
} else {
Expand All @@ -87,10 +76,14 @@ func intEqu(msg *rt.AsyncMsg) {
}()
}

func getArgIntegerValues(msg *rt.AsyncMsg) (int64, int64) {
return int64(msg.Args[0]) >> 8, int64(msg.Args[2]) >> 8
}

func formatAndReturn(msg *rt.AsyncMsg, result int64) {
literal := fmt.Sprintf("%d", result)
integer := ast.NewInteger(literal)
integer.Return(msg)

rt.INTEGER.(*rt.Object).ID = 0x7
rt.INT.(*rt.Object).ID = 0x7
}
2 changes: 1 addition & 1 deletion src/soma/rt/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
var NIL Value
var FALSE Value
var TRUE Value
var INTEGER Value
var INT Value

var RT *Runtime

Expand Down
2 changes: 1 addition & 1 deletion src/soma/rt/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (h *Heap) Lookup(oid uint64) Value {

switch oid & 0xF {
case 0x7:
return INTEGER
return INT
}

val := h.Values[oid]
Expand Down

0 comments on commit 958af15

Please sign in to comment.