diff --git a/basis/alien/c-types/c-types-tests.factor b/basis/alien/c-types/c-types-tests.factor index 276dd581c5..edda9e7fdb 100755 --- a/basis/alien/c-types/c-types-tests.factor +++ b/basis/alien/c-types/c-types-tests.factor @@ -2,6 +2,12 @@ IN: alien.c-types.tests USING: alien alien.syntax alien.c-types kernel tools.test sequences system libc alien.strings io.encodings.utf8 ; +\ expand-constants must-infer + +: xyz 123 ; + +[ { "blah" 123 } ] [ { "blah" xyz } expand-constants ] unit-test + : foo ( -- n ) "fdafd" f dlsym [ 123 ] unless* ; [ 123 ] [ foo ] unit-test diff --git a/basis/alien/c-types/c-types.factor b/basis/alien/c-types/c-types.factor index c553ca5cfb..a9b39f80ab 100755 --- a/basis/alien/c-types/c-types.factor +++ b/basis/alien/c-types/c-types.factor @@ -4,7 +4,7 @@ USING: byte-arrays arrays assocs kernel kernel.private libc math namespaces parser sequences strings words assocs splitting math.parser cpu.architecture alien alien.accessors quotations layouts system compiler.units io.files io.encodings.binary -accessors combinators effects ; +accessors combinators effects continuations ; IN: alien.c-types DEFER: @@ -239,15 +239,20 @@ M: long-long-type box-return ( type -- ) } 2cleave ; : expand-constants ( c-type -- c-type' ) - #! We use def>> call instead of execute to get around - #! staging violations dup array? [ - unclip >r [ dup word? [ def>> call ] when ] map r> prefix + unclip >r [ + dup word? [ + def>> { } swap with-datastack first + ] when + ] map r> prefix ] when ; : malloc-file-contents ( path -- alien len ) binary file-contents dup malloc-byte-array swap length ; +: if-void ( type true false -- ) + pick "void" = [ drop nip call ] [ nip call ] if ; inline + [ [ alien-cell ] >>getter diff --git a/unfinished/compiler/generator/authors.txt b/unfinished/compiler/generator/authors.txt new file mode 100644 index 0000000000..1901f27a24 --- /dev/null +++ b/unfinished/compiler/generator/authors.txt @@ -0,0 +1 @@ +Slava Pestov diff --git a/unfinished/compiler/generator/fixup/authors.txt b/unfinished/compiler/generator/fixup/authors.txt new file mode 100644 index 0000000000..1901f27a24 --- /dev/null +++ b/unfinished/compiler/generator/fixup/authors.txt @@ -0,0 +1 @@ +Slava Pestov diff --git a/unfinished/compiler/generator/fixup/fixup-docs.factor b/unfinished/compiler/generator/fixup/fixup-docs.factor new file mode 100644 index 0000000000..a4ff549e8e --- /dev/null +++ b/unfinished/compiler/generator/fixup/fixup-docs.factor @@ -0,0 +1,16 @@ +USING: help.syntax help.markup math kernel +words strings alien ; +IN: compiler.generator.fixup + +HELP: frame-required +{ $values { "n" "a non-negative integer" } } +{ $description "Notify the code generator that the currently compiling code block needs a stack frame with room for at least " { $snippet "n" } " parameters." } ; + +HELP: add-literal +{ $values { "obj" object } { "n" integer } } +{ $description "Adds a literal to the " { $link literal-table } ", if it is not already there, and outputs the index of the literal in the table. This literal can then be used as an argument for a " { $link rt-literal } " relocation with " { $link rel-fixup } "." } ; + +HELP: rel-dlsym +{ $values { "name" string } { "dll" "a " { $link dll } " or " { $link f } } { "class" "a relocation class" } } +{ $description "Records that the most recently assembled instruction contains a reference to the " { $snippet "name" } " symbol from " { $snippet "dll" } ". The correct " { $snippet "class" } " to use depends on instruction formats." +} ; diff --git a/unfinished/compiler/generator/fixup/fixup.factor b/unfinished/compiler/generator/fixup/fixup.factor new file mode 100755 index 0000000000..e1b4e42e67 --- /dev/null +++ b/unfinished/compiler/generator/fixup/fixup.factor @@ -0,0 +1,154 @@ +! Copyright (C) 2007, 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: arrays byte-arrays generic assocs hashtables io.binary +kernel kernel.private math namespaces sequences words +quotations strings alien.accessors alien.strings layouts system +combinators math.bitfields words.private cpu.architecture +math.order accessors growable ; +IN: compiler.generator.fixup + +: no-stack-frame -1 ; inline + +TUPLE: frame-required n ; + +: frame-required ( n -- ) \ frame-required boa , ; + +: stack-frame-size ( code -- n ) + no-stack-frame [ + dup frame-required? [ frame-required-n max ] [ drop ] if + ] reduce ; + +GENERIC: fixup* ( frame-size obj -- frame-size ) + +: code-format 22 getenv ; + +: compiled-offset ( -- n ) building get length code-format * ; + +TUPLE: label offset ; + +: