From: Michael D. Lowis Date: Fri, 11 Jul 2014 15:22:15 +0000 (-0400) Subject: Added bunch of changed files, i dunno what they are X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=500bb8a37466a806dead7575c12f9be8b3eacae6;p=archive%2Fbitbucket.git Added bunch of changed files, i dunno what they are --- diff --git a/lang_design/cont_gc/alloca.c b/lang_design/cont_gc/alloca.c new file mode 100755 index 0000000..8f98b73 --- /dev/null +++ b/lang_design/cont_gc/alloca.c @@ -0,0 +1,504 @@ +/* alloca.c -- allocate automatically reclaimed memory + (Mostly) portable public-domain implementation -- D A Gwyn + + This implementation of the PWB library alloca function, + which is used to allocate space off the run-time stack so + that it is automatically reclaimed upon procedure exit, + was inspired by discussions with J. Q. Johnson of Cornell. + J.Otto Tennant contributed the Cray support. + + There are some preprocessor constants that can + be defined when compiling for your specific system, for + improved efficiency; however, the defaults should be okay. + + The general concept of this implementation is to keep + track of all alloca-allocated blocks, and reclaim any + that are found to be deeper in the stack than the current + invocation. This heuristic does not reclaim storage as + soon as it becomes invalid, but it will do so eventually. + + As a special case, alloca(0) reclaims storage without + allocating any. It is a good idea to use alloca(0) in + your main control loop, etc. to force garbage collection. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef emacs +#include "blockinput.h" +#endif + +/* If compiling with GCC 2, this file's not needed. */ +#if !defined (__GNUC__) || __GNUC__ < 2 + +/* If someone has defined alloca as a macro, + there must be some other way alloca is supposed to work. */ +#ifndef alloca + +#ifdef emacs +#ifdef static +/* actually, only want this if static is defined as "" + -- this is for usg, in which emacs must undefine static + in order to make unexec workable + */ +#ifndef STACK_DIRECTION +you +lose +-- must know STACK_DIRECTION at compile-time +#endif /* STACK_DIRECTION undefined */ +#endif /* static */ +#endif /* emacs */ + +/* If your stack is a linked list of frames, you have to + provide an "address metric" ADDRESS_FUNCTION macro. */ + +#if defined (CRAY) && defined (CRAY_STACKSEG_END) +long i00afunc (); +#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) +#else +#define ADDRESS_FUNCTION(arg) &(arg) +#endif + +#if __STDC__ +typedef void *pointer; +#else +typedef char *pointer; +#endif + +#ifndef NULL +#define NULL 0 +#endif + +/* Different portions of Emacs need to call different versions of + malloc. The Emacs executable needs alloca to call xmalloc, because + ordinary malloc isn't protected from input signals. On the other + hand, the utilities in lib-src need alloca to call malloc; some of + them are very simple, and don't have an xmalloc routine. + + Non-Emacs programs expect this to call use xmalloc. + + Callers below should use malloc. */ + +#ifndef emacs +#define malloc xmalloc +#endif +extern pointer malloc (); + +/* Define STACK_DIRECTION if you know the direction of stack + growth for your system; otherwise it will be automatically + deduced at run-time. + + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ + +#ifndef STACK_DIRECTION +#define STACK_DIRECTION 0 /* Direction unknown. */ +#endif + +#if STACK_DIRECTION != 0 + +#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ + +#else /* STACK_DIRECTION == 0; need run-time code. */ + +static int stack_dir; /* 1 or -1 once known. */ +#define STACK_DIR stack_dir + +static void +find_stack_direction () +{ + static char *addr = NULL; /* Address of first `dummy', once known. */ + auto char dummy; /* To get stack address. */ + + if (addr == NULL) + { /* Initial entry. */ + addr = ADDRESS_FUNCTION (dummy); + + find_stack_direction (); /* Recurse once. */ + } + else + { + /* Second entry. */ + if (ADDRESS_FUNCTION (dummy) > addr) + stack_dir = 1; /* Stack grew upward. */ + else + stack_dir = -1; /* Stack grew downward. */ + } +} + +#endif /* STACK_DIRECTION == 0 */ + +/* An "alloca header" is used to: + (a) chain together all alloca'ed blocks; + (b) keep track of stack depth. + + It is very important that sizeof(header) agree with malloc + alignment chunk size. The following default should work okay. */ + +#ifndef ALIGN_SIZE +#define ALIGN_SIZE sizeof(double) +#endif + +typedef union hdr +{ + char align[ALIGN_SIZE]; /* To force sizeof(header). */ + struct + { + union hdr *next; /* For chaining headers. */ + char *deep; /* For stack depth measure. */ + } h; +} header; + +static header *last_alloca_header = NULL; /* -> last alloca header. */ + +/* Return a pointer to at least SIZE bytes of storage, + which will be automatically reclaimed upon exit from + the procedure that called alloca. Originally, this space + was supposed to be taken from the current stack frame of the + caller, but that method cannot be made to work for some + implementations of C, for example under Gould's UTX/32. */ + +pointer +alloca (size) + unsigned size; +{ + auto char probe; /* Probes stack depth: */ + register char *depth = ADDRESS_FUNCTION (probe); + +#if STACK_DIRECTION == 0 + if (STACK_DIR == 0) /* Unknown growth direction. */ + find_stack_direction (); +#endif + + /* Reclaim garbage, defined as all alloca'd storage that + was allocated from deeper in the stack than currently. */ + + { + register header *hp; /* Traverses linked list. */ + +#ifdef emacs + BLOCK_INPUT; +#endif + + for (hp = last_alloca_header; hp != NULL;) + if ((STACK_DIR > 0 && hp->h.deep > depth) + || (STACK_DIR < 0 && hp->h.deep < depth)) + { + register header *np = hp->h.next; + + free ((pointer) hp); /* Collect garbage. */ + + hp = np; /* -> next header. */ + } + else + break; /* Rest are not deeper. */ + + last_alloca_header = hp; /* -> last valid storage. */ + +#ifdef emacs + UNBLOCK_INPUT; +#endif + } + + if (size == 0) + return NULL; /* No allocation required. */ + + /* Allocate combined header + user data storage. */ + + { + register pointer new = malloc (sizeof (header) + size); + /* Address of header. */ + + if (new == 0) + abort(); + + ((header *) new)->h.next = last_alloca_header; + ((header *) new)->h.deep = depth; + + last_alloca_header = (header *) new; + + /* User storage begins just after header. */ + + return (pointer) ((char *) new + sizeof (header)); + } +} + +#if defined (CRAY) && defined (CRAY_STACKSEG_END) + +#ifdef DEBUG_I00AFUNC +#include +#endif + +#ifndef CRAY_STACK +#define CRAY_STACK +#ifndef CRAY2 +/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ +struct stack_control_header + { + long shgrow:32; /* Number of times stack has grown. */ + long shaseg:32; /* Size of increments to stack. */ + long shhwm:32; /* High water mark of stack. */ + long shsize:32; /* Current size of stack (all segments). */ + }; + +/* The stack segment linkage control information occurs at + the high-address end of a stack segment. (The stack + grows from low addresses to high addresses.) The initial + part of the stack segment linkage control information is + 0200 (octal) words. This provides for register storage + for the routine which overflows the stack. */ + +struct stack_segment_linkage + { + long ss[0200]; /* 0200 overflow words. */ + long sssize:32; /* Number of words in this segment. */ + long ssbase:32; /* Offset to stack base. */ + long:32; + long sspseg:32; /* Offset to linkage control of previous + segment of stack. */ + long:32; + long sstcpt:32; /* Pointer to task common address block. */ + long sscsnm; /* Private control structure number for + microtasking. */ + long ssusr1; /* Reserved for user. */ + long ssusr2; /* Reserved for user. */ + long sstpid; /* Process ID for pid based multi-tasking. */ + long ssgvup; /* Pointer to multitasking thread giveup. */ + long sscray[7]; /* Reserved for Cray Research. */ + long ssa0; + long ssa1; + long ssa2; + long ssa3; + long ssa4; + long ssa5; + long ssa6; + long ssa7; + long sss0; + long sss1; + long sss2; + long sss3; + long sss4; + long sss5; + long sss6; + long sss7; + }; + +#else /* CRAY2 */ +/* The following structure defines the vector of words + returned by the STKSTAT library routine. */ +struct stk_stat + { + long now; /* Current total stack size. */ + long maxc; /* Amount of contiguous space which would + be required to satisfy the maximum + stack demand to date. */ + long high_water; /* Stack high-water mark. */ + long overflows; /* Number of stack overflow ($STKOFEN) calls. */ + long hits; /* Number of internal buffer hits. */ + long extends; /* Number of block extensions. */ + long stko_mallocs; /* Block allocations by $STKOFEN. */ + long underflows; /* Number of stack underflow calls ($STKRETN). */ + long stko_free; /* Number of deallocations by $STKRETN. */ + long stkm_free; /* Number of deallocations by $STKMRET. */ + long segments; /* Current number of stack segments. */ + long maxs; /* Maximum number of stack segments so far. */ + long pad_size; /* Stack pad size. */ + long current_address; /* Current stack segment address. */ + long current_size; /* Current stack segment size. This + number is actually corrupted by STKSTAT to + include the fifteen word trailer area. */ + long initial_address; /* Address of initial segment. */ + long initial_size; /* Size of initial segment. */ + }; + +/* The following structure describes the data structure which trails + any stack segment. I think that the description in 'asdef' is + out of date. I only describe the parts that I am sure about. */ + +struct stk_trailer + { + long this_address; /* Address of this block. */ + long this_size; /* Size of this block (does not include + this trailer). */ + long unknown2; + long unknown3; + long link; /* Address of trailer block of previous + segment. */ + long unknown5; + long unknown6; + long unknown7; + long unknown8; + long unknown9; + long unknown10; + long unknown11; + long unknown12; + long unknown13; + long unknown14; + }; + +#endif /* CRAY2 */ +#endif /* not CRAY_STACK */ + +#ifdef CRAY2 +/* Determine a "stack measure" for an arbitrary ADDRESS. + I doubt that "lint" will like this much. */ + +static long +i00afunc (long *address) +{ + struct stk_stat status; + struct stk_trailer *trailer; + long *block, size; + long result = 0; + + /* We want to iterate through all of the segments. The first + step is to get the stack status structure. We could do this + more quickly and more directly, perhaps, by referencing the + $LM00 common block, but I know that this works. */ + + STKSTAT (&status); + + /* Set up the iteration. */ + + trailer = (struct stk_trailer *) (status.current_address + + status.current_size + - 15); + + /* There must be at least one stack segment. Therefore it is + a fatal error if "trailer" is null. */ + + if (trailer == 0) + abort (); + + /* Discard segments that do not contain our argument address. */ + + while (trailer != 0) + { + block = (long *) trailer->this_address; + size = trailer->this_size; + if (block == 0 || size == 0) + abort (); + trailer = (struct stk_trailer *) trailer->link; + if ((block <= address) && (address < (block + size))) + break; + } + + /* Set the result to the offset in this segment and add the sizes + of all predecessor segments. */ + + result = address - block; + + if (trailer == 0) + { + return result; + } + + do + { + if (trailer->this_size <= 0) + abort (); + result += trailer->this_size; + trailer = (struct stk_trailer *) trailer->link; + } + while (trailer != 0); + + /* We are done. Note that if you present a bogus address (one + not in any segment), you will get a different number back, formed + from subtracting the address of the first block. This is probably + not what you want. */ + + return (result); +} + +#else /* not CRAY2 */ +/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. + Determine the number of the cell within the stack, + given the address of the cell. The purpose of this + routine is to linearize, in some sense, stack addresses + for alloca. */ + +static long +i00afunc (long address) +{ + long stkl = 0; + + long size, pseg, this_segment, stack; + long result = 0; + + struct stack_segment_linkage *ssptr; + + /* Register B67 contains the address of the end of the + current stack segment. If you (as a subprogram) store + your registers on the stack and find that you are past + the contents of B67, you have overflowed the segment. + + B67 also points to the stack segment linkage control + area, which is what we are really interested in. */ + + stkl = CRAY_STACKSEG_END (); + ssptr = (struct stack_segment_linkage *) stkl; + + /* If one subtracts 'size' from the end of the segment, + one has the address of the first word of the segment. + + If this is not the first segment, 'pseg' will be + nonzero. */ + + pseg = ssptr->sspseg; + size = ssptr->sssize; + + this_segment = stkl - size; + + /* It is possible that calling this routine itself caused + a stack overflow. Discard stack segments which do not + contain the target address. */ + + while (!(this_segment <= address && address <= stkl)) + { +#ifdef DEBUG_I00AFUNC + fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); +#endif + if (pseg == 0) + break; + stkl = stkl - pseg; + ssptr = (struct stack_segment_linkage *) stkl; + size = ssptr->sssize; + pseg = ssptr->sspseg; + this_segment = stkl - size; + } + + result = address - this_segment; + + /* If you subtract pseg from the current end of the stack, + you get the address of the previous stack segment's end. + This seems a little convoluted to me, but I'll bet you save + a cycle somewhere. */ + + while (pseg != 0) + { +#ifdef DEBUG_I00AFUNC + fprintf (stderr, "%011o %011o\n", pseg, size); +#endif + stkl = stkl - pseg; + ssptr = (struct stack_segment_linkage *) stkl; + size = ssptr->sssize; + pseg = ssptr->sspseg; + result += size; + } + return (result); +} + +#endif /* not CRAY2 */ +#endif /* CRAY */ + +#endif /* no alloca */ +#endif /* not GCC version 2 */ diff --git a/lang_design/lang.h b/lang_design/lang.h new file mode 100755 index 0000000..62ceec3 --- /dev/null +++ b/lang_design/lang.h @@ -0,0 +1,74 @@ + +typedef struct { + long type: 8; + long size: 24; +} type_header_t; + +typedef struct { + type_header_t header; + char data[4]; +} object_t; + +typedef object_t* var_t; + +// Atomic types +typedef long char_t; + +typedef double num_t; + +// Collections +typedef struct { + type_header_t header; + char_t* data; +} symbol_t; + +typedef struct { + type_header_t header; + char_t* data; +} string_t; + +typedef struct { + type_header_t header; + var_t* data; +} vector_t; + +typedef struct { + type_header_t header; + var_t head; + var_t tail; +} list_t; + +// Other +typedef struct { + type_header_t header; + var_t context; + var_t (*fn)(var_t args); +} func_t; + +typedef struct { + type_header_t header; + char* data; +} port_t; + +#define MACRO(name) void name(var_t args) { +#define END_MACRO } + +#define FUNC(name) var_t name(var_t args) { +#define END_FUNC } + +#define PACKAGE() void* init_package() +#define END_PACKAGE } + +#define REGISTER(name,val) register_val( intern(#name), val ) + +MACRO(genname_1) +END_MACRO + +FUNC(genname_2) +END_FUNC + +PACKAGE() + REGISTER(some_macro, genname_1); + REGISTER(some_func, genname_2); +END_PACKAGE + diff --git a/lang_design/prototypes/main.c b/lang_design/prototypes/main.c new file mode 100755 index 0000000..b29e30a --- /dev/null +++ b/lang_design/prototypes/main.c @@ -0,0 +1,27 @@ +typedef unsigned int Word; + +typedef enum { + STRING +} eDataType; + +typedef struct { + Word length : 24; + Word type : 3; + Word spare : 5; +} ObjectHeader; + +typedef struct { + Word* parent; + Word* self; +} Prototype; + +typedef struct { + ObjectHeader header; + Prototype proto; + Word data[1]; +} Object; + +int main(int argc, char** argv) +{ + return 0; +} diff --git a/lang_design/types/c_types.c b/lang_design/types/c_types.c new file mode 100755 index 0000000..a2f2f8e --- /dev/null +++ b/lang_design/types/c_types.c @@ -0,0 +1,139 @@ +#include +#include + +/****************************************************************************** + * Type Definitions + *****************************************************************************/ +/* Type definitions */ +#ifdef C_SIXTY_FOUR + typedef unsigned long Word; +#else + typedef unsigned int Word; +#endif +typedef char Byte; + +typedef struct +{ + Word header; + Word[1] data; +} ObjectBlock; + +typedef struct +{ + Word header; + ObjectBlock* parent; + Word* table; +} Prototype; + +#ifdef C_SIXTY_FOUR + # define C_INT_SIGN_BIT 0x8000000000000000L + # define C_INT_TOP_BIT 0x4000000000000000L + # define C_HEADER_BITS_MASK 0xff00000000000000L + # define C_HEADER_TYPE_BITS 0x0f00000000000000L + # define C_HEADER_SIZE_MASK 0x00ffffffffffffffL + # define C_GC_FORWARDING_BIT 0x8000000000000000L /* header contains forwarding pointer */ + # define C_BYTEBLOCK_BIT 0x4000000000000000L /* block contains bytes instead of slots */ + # define C_SPECIALBLOCK_BIT 0x2000000000000000L /* 1st item is a non-value */ + # define C_8ALIGN_BIT 0x1000000000000000L /* data is aligned to 8-byte boundary */ + + # define C_SYMBOL_TYPE (0x0100000000000000L) + # define C_STRING_TYPE (0x0200000000000000L | C_BYTEBLOCK_BIT) + # define C_PAIR_TYPE (0x0300000000000000L) + # define C_CLOSURE_TYPE (0x0400000000000000L | C_SPECIALBLOCK_BIT) + # define C_FLONUM_TYPE (0x0500000000000000L | C_BYTEBLOCK_BIT | C_8ALIGN_BIT) + /* unused (0x0600000000000000L ...) */ + # define C_PORT_TYPE (0x0700000000000000L | C_SPECIALBLOCK_BIT) + # define C_STRUCTURE_TYPE (0x0800000000000000L) + # define C_POINTER_TYPE (0x0900000000000000L | C_SPECIALBLOCK_BIT) + # define C_LOCATIVE_TYPE (0x0a00000000000000L | C_SPECIALBLOCK_BIT) + # define C_TAGGED_POINTER_TYPE (0x0b00000000000000L | C_SPECIALBLOCK_BIT) + # define C_SWIG_POINTER_TYPE (0x0c00000000000000L | C_SPECIALBLOCK_BIT) + # define C_LAMBDA_INFO_TYPE (0x0d00000000000000L | C_BYTEBLOCK_BIT) + /* unused (0x0e00000000000000L ...) */ + # define C_BUCKET_TYPE (0x0f00000000000000L) +#else + # define C_INT_SIGN_BIT 0x80000000 + # define C_INT_TOP_BIT 0x40000000 + # define C_HEADER_BITS_MASK 0xff000000 + # define C_HEADER_TYPE_BITS 0x0f000000 + # define C_HEADER_SIZE_MASK 0x00ffffff + # define C_GC_FORWARDING_BIT 0x80000000 + # define C_BYTEBLOCK_BIT 0x40000000 + # define C_SPECIALBLOCK_BIT 0x20000000 + # define C_8ALIGN_BIT 0x10000000 + + # define C_SYMBOL_TYPE (0x01000000) + # define C_STRING_TYPE (0x02000000 | C_BYTEBLOCK_BIT) + # define C_PAIR_TYPE (0x03000000) + # define C_CLOSURE_TYPE (0x04000000 | C_SPECIALBLOCK_BIT) + # ifdef C_DOUBLE_IS_32_BITS + # define C_FLONUM_TYPE (0x05000000 | C_BYTEBLOCK_BIT) + # else + # define C_FLONUM_TYPE (0x05000000 | C_BYTEBLOCK_BIT | C_8ALIGN_BIT) + # endif + /* unused (0x06000000 ...) */ + # define C_PORT_TYPE (0x07000000 | C_SPECIALBLOCK_BIT) + # define C_STRUCTURE_TYPE (0x08000000) + # define C_POINTER_TYPE (0x09000000 | C_SPECIALBLOCK_BIT) + # define C_LOCATIVE_TYPE (0x0a000000 | C_SPECIALBLOCK_BIT) + # define C_TAGGED_POINTER_TYPE (0x0b000000 | C_SPECIALBLOCK_BIT) + # define C_SWIG_POINTER_TYPE (0x0c000000 | C_SPECIALBLOCK_BIT) + # define C_LAMBDA_INFO_TYPE (0x0d000000 | C_BYTEBLOCK_BIT) + /* unused (0x0e000000 ...) */ + # define C_BUCKET_TYPE (0x0f000000) +#endif + + +/* Hooray for dynamic stack allocation */ +#ifdef HAVE_ALLOCA_H + #include +#elif !defined(alloca) + #error "Must have alloca support" +#endif + +// Save 16K to prevent buffer overflows +#define AX_STACK_RESERVE 0x10000 +#define AX_setjmp(a) setjmp(a) +#define AX_alloca(n) alloca(n) +#define AX_stack_pointer ((Word*)AX_alloca(0)) + +/* Global Variables */ +Word* Stack_Limit; +unsigned int stack_size; +unsigned int stack_bottom; +jmp_buf restart_point; +Bool return_to_host; + +//Word ax_run(void* toplevel) +//{ +// // Configure the stack size and pointers +//#if C_STACK_GROWS_DOWNWARD +// Stack_Limit = (Word*)((Byte*)AX_stack_pointer - stack_size); +//#else +// Stack_Limit = (Word*)((Byte*)AX_stack_pointer + stack_size); +//#endif +// stack_bottom = AX_stack_pointer; +// +// // Make note of our start point +// AX_setjmp(restart_point); +// +// // If we end up back here then check whether we restart or not +// //if(!return_to_host) +// // (C_restart_trampoline)(C_restart_address); +//} + +int main(int argc, char** argv) +{ + // Configure the stack size and pointers +#if C_STACK_GROWS_DOWNWARD + Stack_Limit = (Word*)((Byte*)AX_stack_pointer - stack_size); +#else + Stack_Limit = (Word*)((Byte*)AX_stack_pointer + stack_size); +#endif + stack_bottom = AX_stack_pointer; + + while(1) + { + printf("%d\n", alloca(4)); + } +} diff --git a/llvm/fib.c b/llvm/fib.c new file mode 100755 index 0000000..8776295 --- /dev/null +++ b/llvm/fib.c @@ -0,0 +1,28 @@ +//#include + +int count(int x, int n) +{ + if( x == n ) + { + return x; + } + else + { + return count( x+1, n ); + } +} + +int main(int argc, char** argv) +{ + int ret = 0; + if( 2 == argc ) + { + printf( "%d\n", count( 0, atoi( argv[1] ) ) ); + } + else + { + printf( "Usage: %s \n", argv[0] ); + ret = 1; + } + return ret; +} diff --git a/llvm/fib.s b/llvm/fib.s new file mode 100755 index 0000000..f513ecd --- /dev/null +++ b/llvm/fib.s @@ -0,0 +1,41 @@ +; ModuleID = 'fib.c' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" +target triple = "i386-pc-mingw32" + +@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00" +@.str1 = private unnamed_addr constant [15 x i8] c"Usage: %s \0A\00" + +define i32 @count(i32 %x, i32 %n) nounwind readnone { + %1 = icmp eq i32 %x, %n + %x.tr.lcssa = select i1 %1, i32 %x, i32 %n + ret i32 %x.tr.lcssa +} + +define i32 @main(i32 %argc, i8** nocapture %argv) nounwind { + %1 = icmp eq i32 %argc, 2 + br i1 %1, label %2, label %7 + +;