primitive application
This commit is contained in:
parent
c08c6ed667
commit
4924f92528
|
@ -207,7 +207,15 @@
|
|||
(MakeCompiledProcedure-closed-vals op))))]
|
||||
|
||||
[(ApplyPrimitiveProcedure? op)
|
||||
m]
|
||||
(let: ([prim : SlotValue (machine-proc m)]
|
||||
[args : (Listof PrimitiveValue)
|
||||
(map ensure-primitive-value (take (machine-env m)
|
||||
(ApplyPrimitiveProcedure-arity op)))])
|
||||
(cond
|
||||
[(primitive-proc? prim)
|
||||
(target-updater m (ensure-primitive-value (apply (primitive-proc-f prim) args)))]
|
||||
[else
|
||||
(error 'apply-primitive-procedure)]))]
|
||||
|
||||
[(LookupLexicalAddress? op)
|
||||
(let: ([a-val : SlotValue (env-ref m (LookupLexicalAddress-depth op))])
|
||||
|
|
|
@ -400,6 +400,20 @@
|
|||
(test (machine-val (run m))
|
||||
'curly))
|
||||
|
||||
;; ApplyPrimitiveProcedure
|
||||
;; Adding two numbers
|
||||
(let ([m (new-machine `(,(make-PerformStatement (make-ExtendEnvironment/Prefix! '(+)))
|
||||
,(make-AssignPrimOpStatement 'proc (make-LookupToplevelAddress 0 0 '+))
|
||||
,(make-PushEnvironment 2)
|
||||
,(make-AssignImmediateStatement (make-EnvLexicalReference 0) (make-Const 126389))
|
||||
,(make-AssignImmediateStatement (make-EnvLexicalReference 1) (make-Const 42))
|
||||
,(make-AssignPrimOpStatement 'val (make-ApplyPrimitiveProcedure 2))))])
|
||||
(test (machine-val (run m))
|
||||
(+ 126389 42))
|
||||
|
||||
(test (machine-env (run m))
|
||||
(list 126389 42 (make-toplevel (list (lookup-primitive '+))))))
|
||||
|
||||
|
||||
|
||||
#;(let ([m (new-machine `(,(make-AssignPrimOpStatement (make-LookupLexicalAddress))))])
|
||||
|
|
Loading…
Reference in New Issue
Block a user