2010-01-14 10:10:13 -05:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
2008-09-10 23:11:03 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: classes.tuple classes.tuple.parser kernel words
|
2009-09-02 07:22:37 -04:00
|
|
|
make fry sequences parser accessors effects namespaces
|
2009-09-04 04:01:18 -04:00
|
|
|
combinators splitting classes.parser lexer quotations ;
|
2008-09-15 02:54:48 -04:00
|
|
|
IN: compiler.cfg.instructions.syntax
|
2008-09-10 23:11:03 -04:00
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
SYMBOLS: def use temp literal constant ;
|
|
|
|
|
2009-09-03 03:33:07 -04:00
|
|
|
SYMBOL: scalar-rep
|
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
TUPLE: insn-slot-spec type name rep ;
|
|
|
|
|
2009-09-03 03:33:07 -04:00
|
|
|
: parse-rep ( str/f -- rep )
|
|
|
|
{
|
|
|
|
{ [ dup not ] [ ] }
|
|
|
|
{ [ dup "scalar-rep" = ] [ drop scalar-rep ] }
|
|
|
|
[ "cpu.architecture" lookup ]
|
|
|
|
} cond ;
|
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
: parse-insn-slot-spec ( type string -- spec )
|
|
|
|
over [ "Missing type" throw ] unless
|
2009-09-03 03:33:07 -04:00
|
|
|
"/" split1 parse-rep
|
2009-09-02 07:22:37 -04:00
|
|
|
insn-slot-spec boa ;
|
|
|
|
|
|
|
|
: parse-insn-slot-specs ( seq -- specs )
|
|
|
|
[
|
|
|
|
f [
|
|
|
|
{
|
|
|
|
{ "def:" [ drop def ] }
|
|
|
|
{ "use:" [ drop use ] }
|
|
|
|
{ "temp:" [ drop temp ] }
|
|
|
|
{ "literal:" [ drop literal ] }
|
|
|
|
{ "constant:" [ drop constant ] }
|
|
|
|
[ dupd parse-insn-slot-spec , ]
|
|
|
|
} case
|
|
|
|
] reduce drop
|
|
|
|
] { } make ;
|
|
|
|
|
2010-04-21 03:08:52 -04:00
|
|
|
: find-def-slot ( slots -- slot/f )
|
2009-09-02 07:22:37 -04:00
|
|
|
[ type>> def eq? ] find nip ;
|
|
|
|
|
2010-04-21 03:08:52 -04:00
|
|
|
: insn-def-slot ( class -- slot/f )
|
|
|
|
"insn-slots" word-prop find-def-slot ;
|
|
|
|
|
2009-09-08 22:50:55 -04:00
|
|
|
: insn-use-slots ( class -- slots )
|
2010-04-21 03:08:52 -04:00
|
|
|
"insn-slots" word-prop [ type>> use eq? ] filter ;
|
2009-09-02 07:22:37 -04:00
|
|
|
|
2009-09-08 22:50:55 -04:00
|
|
|
: insn-temp-slots ( class -- slots )
|
2010-04-21 03:08:52 -04:00
|
|
|
"insn-slots" word-prop [ type>> temp eq? ] filter ;
|
2009-09-02 07:22:37 -04:00
|
|
|
|
|
|
|
! We cannot reference words in compiler.cfg.instructions directly
|
|
|
|
! since that would create circularity.
|
|
|
|
: insn-classes-word ( -- word )
|
|
|
|
"insn-classes" "compiler.cfg.instructions" lookup ;
|
|
|
|
|
2008-10-24 10:17:06 -04:00
|
|
|
: insn-word ( -- word )
|
|
|
|
"insn" "compiler.cfg.instructions" lookup ;
|
2008-09-10 23:11:03 -04:00
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
: pure-insn-word ( -- word )
|
|
|
|
"pure-insn" "compiler.cfg.instructions" lookup ;
|
|
|
|
|
2008-12-15 20:44:56 -05:00
|
|
|
: insn-effect ( word -- effect )
|
2010-01-14 10:10:13 -05:00
|
|
|
boa-effect in>> but-last { } <effect> ;
|
2008-12-15 20:44:56 -05:00
|
|
|
|
2009-09-02 07:22:37 -04:00
|
|
|
: define-insn-tuple ( class superclass specs -- )
|
|
|
|
[ name>> ] map "insn#" suffix define-tuple-class ;
|
|
|
|
|
|
|
|
: define-insn-ctor ( class specs -- )
|
2009-09-04 04:01:18 -04:00
|
|
|
[ dup '[ _ ] [ f ] [ boa , ] surround ] dip
|
2010-01-14 10:10:13 -05:00
|
|
|
[ name>> ] map { } <effect> define-declared ;
|
2009-09-02 07:22:37 -04:00
|
|
|
|
|
|
|
: define-insn ( class superclass specs -- )
|
|
|
|
parse-insn-slot-specs {
|
|
|
|
[ nip "insn-slots" set-word-prop ]
|
|
|
|
[ 2drop insn-classes-word get push ]
|
|
|
|
[ define-insn-tuple ]
|
|
|
|
[ 2drop save-location ]
|
|
|
|
[ nip define-insn-ctor ]
|
|
|
|
} 3cleave ;
|
|
|
|
|
|
|
|
SYNTAX: INSN: CREATE-CLASS insn-word ";" parse-tokens define-insn ;
|
|
|
|
|
|
|
|
SYNTAX: PURE-INSN: CREATE-CLASS pure-insn-word ";" parse-tokens define-insn ;
|