the new gforth header
play

The new Gforth Header Bernd Paysan, net2o M. Anton Ertl, TU Wien - PowerPoint PPT Presentation

The new Gforth Header Bernd Paysan, net2o M. Anton Ertl, TU Wien Traditional Header New Requirements Complete Name Long Name alias compile-only machine-independence Old Gforth Header Complete Name Long Name alias compile-only


  1. The new Gforth Header Bernd Paysan, net2o M. Anton Ertl, TU Wien

  2. Traditional Header

  3. New Requirements Complete Name Long Name alias compile-only machine-independence

  4. Old Gforth Header Complete Name Long Name alias compile-only machine-independence nt link i count name xt code field does-code body parameter field many if s

  5. More Requirements intelligent compile, dual-semantics words synonym to for value variations defer variations reduce if s (mostly) unify nt and xt

  6. New Header padding compile, intelligent compile, name (to) dual-semantics words defer@ synonym mcompile-only count does/extra link name>interpret to for value variations vt name>compile defer variations xt=nt code field name>string reduce if s body parameter field name>link (mostly) unify nt and xt

  7. Setters setter stack effect sets ( addr -- ) code field set-execute compile, code field set-does> ( xt -- ) does> does compile, padding compile, set-optimizer ( xt -- ) compile, name (to) opt: defer@ count does/extra set->int ( xt -- ) name>interpret link name>interpret set->comp ( xt -- ) name>compile vt name>compile xt=nt compsem: code field name>string body immediate parameter field name>link (to) / defer! set-to ( xt -- ) set-defer@ ( xt -- ) defer@ set->string ( xt -- ) name>string set->link ( xt -- ) name>link

  8. Example: Immediate : imm>comp ( nt -- xt1 xt2 ) name>int [’] execute ; : immediate ( -- ) [’] imm>comp set->comp ; : default-name>comp ( nt -- xt1 xt2 ) name>int [’] compile, ; defer name>x : [ [’] name>interpret is name>x false state ! ; : ] [’] name>compile is name>x true state ! ; \ in text interpreter: ( c-addr u ) 2dup find-name dup if nip nip name>x execute else ( ... number handling ... ) then

  9. Example: Constant : constant ( x "name" -- ) create , [’] @ set-does> [: >body @ ]] literal [[ ;] set-optimizer ;

  10. Example: Fvalue : fvalue-to ( r xt-fvalue -- ) >body f! ; opt: drop ]] >body f! [[ ; : fvalue ( r "name" -- ) \ float-ext fconstant [: >body ]] Literal f@ [[ ;] set-optimizer [’] fvalue-to set-to ;

  11. Example: Defer : value-to ( x xt -- ) >body ! ; opt: ( xt -- ) \ run-time: ( x -- ) drop ]] >body ! [[ ; : defer-defer@ ( xt1 -- xt2 ) >body @ ; opt: ( xt -- ) drop ]] >body @ [[ ; : perform @ execute ; : defer ( "name" -- ) create [’] abort , [’] perform set-does> [: >body ]] literal perform [[ ;] set-optimizer [’] value-to set-to [’] defer-defer@ set-defer@ ;

  12. Example: Dual-semantics: To : to-int ( v "name" -- ) parse-name find-name dup 0= -13 and throw (to) ; : to-comp ( compilation: "name" -- ) ( run-time: v -- ) parse-name find-name dup 0= -13 and throw ]] literal (to) [[ ; immediate : to-name>comp ( nt -- xt1 xt2 ) drop [’] to-comp [’] execute ; : to to-int ; ’ to-name>comp set->comp

  13. Example: Interpret/compile: : i/c>comp ( nt -- xt1 xt2 ) >body cell+ @ [’] execute ; : interpret/compile: ( int-xt comp-xt "name" --) defer , latestxt defer! [: >body @ ;] set->int [’] i/c>comp set->comp [’] no-to set-to to [’] no-defer@ set-defer@ ; header body int-xt comp-xt ’ to-int ’ to-comp interpret/compile: to

  14. Example: Synonym : s-to ( val nt -- ) >body @ (to) ; opt: ( xt -- ) ?fold-to >body @ ]] literal (to) [[ ; : s-defer@ ( xt1 -- xt2 ) >body @ defer@ ; opt: ( xt -- ) ?fold-to >body @ ]] literal defer@ [[ ; : synonym ( "name" "oldname" -- ) defer parse-name find-name dup 0= -13 and throw dup lastxt defer! compile-only? if compile-only then [: >body @ compile, ;] set-optimizer [: >body @ name>interpret ;] set->int [: >body @ name>compile ;] set->comp [’] s-to set-to [’] s-defer@ set-defer@ ;

  15. Example: data structures x ... fvalue-to compile, vt ... (to) ... ... docol vt ... vt drop ]] >body f! [[ ; dodoes does f@ docol 5e ... >body f! ;s 5e fvalue x y ... s-to compile, vt ... (to) ... ... docol synonym y x vt ... vt ?fold-to >body @ dodoes does perform docol ]] literal (to) [[ ; : foo to y ; x ... >body @ ⇓ (to) : foo ;s [ ’ x >body ] to ... to-name>comp to-comp literal f! ; ... ... ... vt name>compile vt vt dodoes ... docol docol to-int drop ... [’] to-comp ]] literal (to) [[ ; [’] execute ;

  16. Deduplication 5 constant five 6 constant six five 4 link vt constant, dodoes no-to 5 no-defer@ @ six noop 3 default-name>comp link named>string vt named>link dodoes 6 117 vts in Gforth (4000 words)

  17. Create from a prototype create constant-prototype [’] @ set-does> [: >body @ ]] literal [[ ;] set-optimizer : constant ( x "name" -- ) [’] constant-prototype create-from , reveal ;

  18. NT = XT? • For most words: nt = xt • Exceptions: synonym alias interpret/compile: • Plausible results for the exceptions

  19. Out-of-band data • Hash table • locate data

  20. Why name>comp and compile, ? • compilation semantics: name>compile • code generation, optimization: compile, equivalent to : compile, ]] literal execute [[ ; Equivalence is widely used

  21. Conclusion • New requirements ⇒ header redesign • Prototype-based object-oriented approach • Method dispatch replaces if -cascades better extensibility • Supports optimization, dual-semantics, synonym , to , defer variations • Deduplication and create-from • nt = xt, with exceptions

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend