Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rofl0r committed Aug 21, 2010
2 parents 05d64ff + b08dd35 commit 4ffe224
Show file tree
Hide file tree
Showing 66 changed files with 1,756 additions and 1,079 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -4,6 +4,8 @@ build
*~
*.swp
bin
bin-win32
bin-linux
*tmp*
.libs
callgrind.out.*
6 changes: 3 additions & 3 deletions CHANGELOG
Expand Up @@ -39,11 +39,11 @@ pre-history
github project. nagaqueen (its fancy name) is now needed to make rock compile
- 2009-10 : Made a leg frontend, builds the AST, ported a lot of Java code with itrekkie,
rock now compiles things =)
- 2009-10 : Creating the AST structure, code generation works well, putting the
- 2009-10 : Creating the AST structure, code generation works well, putting the
frontend on hold for a moment
- 20.9.19 : The tokenizing code is all there, and it's working simply great.
- 2009-09 : The tokenizing code is all there, and it's working simply great.
Now onto constructing AST nodes.
- 20.9.16 : Basic structure, it's gonna be some time till it can do anything useful
- 2009-06 : Basic structure, it's gonna be some time till it can do anything useful



Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -32,7 +32,7 @@ grammar:

.libs/NagaQueen.o: source/rock/frontend/NagaQueen.c
mkdir -p .libs
gcc -std=c99 ${NQ_PATH} -D__OOC_USE_GC__ -w -c -o .libs/NagaQueen.o
gcc -std=c99 ${NQ_PATH} -O3 -fomit-frame-pointer -D__OOC_USE_GC__ -w -c -o .libs/NagaQueen.o


# Prepares the build/ directory, used for bootstrapping
Expand Down
31 changes: 16 additions & 15 deletions libs/headers/gc/gc.h
@@ -1,4 +1,4 @@
/*
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
* Copyright 1996-1999 by Silicon Graphics. All rights reserved.
Expand Down Expand Up @@ -26,7 +26,7 @@
* Everything else is best ignored unless you encounter performance
* problems.
*/

#ifndef _GC_H

# define _GC_H
Expand Down Expand Up @@ -77,7 +77,7 @@ GC_API int GC_parallel; /* GC is parallelized for performance on */
/* If GC_parallel is set, incremental */
/* collection is only partially functional, */
/* and may not be desirable. */


/* Public R/W variables */

Expand Down Expand Up @@ -166,7 +166,7 @@ GC_API int GC_full_freq; /* Number of partial collections between */
/* blocks. Values in the tens are now */
/* perfectly reasonable, unlike for */
/* earlier GC versions. */

GC_API GC_word GC_non_gc_bytes;
/* Bytes not considered candidates for collection. */
/* Used only to control scheduling of collections. */
Expand Down Expand Up @@ -199,7 +199,7 @@ GC_API GC_word GC_max_retries;
/* The maximum number of GCs attempted before */
/* reporting out of memory after heap */
/* expansion fails. Initially 0. */


GC_API char *GC_stackbottom; /* Cool end of user stack. */
/* May be set in the client prior to */
Expand All @@ -211,8 +211,8 @@ GC_API char *GC_stackbottom; /* Cool end of user stack. */
/* automatically. */
/* For multithreaded code, this is the */
/* cold end of the stack for the */
/* primordial thread. */
/* primordial thread. */

GC_API int GC_dont_precollect; /* Don't collect as part of */
/* initialization. Should be set only */
/* if the client wants a chance to */
Expand Down Expand Up @@ -321,7 +321,7 @@ GC_API size_t GC_size(void * object_addr);
/* It is an error to have changes enabled for the original object. */
/* Follows ANSI comventions for NULL old_object. */
GC_API void * GC_realloc(void * old_object, size_t new_size_in_bytes);

/* Explicitly increase the heap size. */
/* Returns 0 on failure, 1 on success. */
GC_API int GC_expand_hp(size_t number_of_bytes);
Expand Down Expand Up @@ -464,7 +464,8 @@ GC_API void * GC_malloc_atomic_ignore_off_page(size_t lb);
#endif

#if defined(__linux__) || defined(__GLIBC__)
# include <features.h>
// Google Native Client doesn't have features.h, and it doesn't seem to hurt to not include it on Linux at least
//# include <features.h>
# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 || __GLIBC__ > 2) \
&& !defined(__ia64__) && !defined(__UCLIBC__)
# ifndef GC_HAVE_BUILTIN_BACKTRACE
Expand Down Expand Up @@ -503,7 +504,7 @@ GC_API void * GC_malloc_atomic_ignore_off_page(size_t lb);
#if (defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) \
|| defined(__FreeBSD__) || defined(__DragonFly__)) & !defined(GC_CAN_SAVE_CALL_STACKS)
# define GC_ADD_CALLER
# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
# if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
/* gcc knows how to retrieve return address, but we don't know */
/* how to generate call stacks. */
# define GC_RETURN_ADDR (GC_word)__builtin_return_address(0)
Expand Down Expand Up @@ -555,7 +556,7 @@ GC_API void GC_debug_end_stubborn_change(void *);
GC_API void * GC_debug_malloc_replacement (size_t size_in_bytes);
GC_API void * GC_debug_realloc_replacement
(void * object_addr, size_t size_in_bytes);

# ifdef GC_DEBUG
# define GC_MALLOC(sz) GC_debug_malloc(sz, GC_EXTRAS)
# define GC_MALLOC_ATOMIC(sz) GC_debug_malloc_atomic(sz, GC_EXTRAS)
Expand Down Expand Up @@ -649,7 +650,7 @@ GC_API void GC_debug_register_finalizer
/* Finalizers are implicitly unregistered just before */
/* they are invoked. */
/* The old finalizer and client data are stored in */
/* *ofn and *ocd. */
/* *ofn and *ocd. */
/* Fn is never invoked on an accessible object, */
/* provided hidden pointers are converted to real */
/* pointers only if the allocation lock is held, and */
Expand Down Expand Up @@ -742,7 +743,7 @@ GC_API int GC_register_disappearing_link(void * * link );
/* registration succeeded, 2 if it failed for lack of */
/* memory, and GC_oom_fn did not handle the problem. */
/* Only exists for backward compatibility. See below: */

GC_API int GC_general_register_disappearing_link (void * * link, void * obj);
/* A slight generalization of the above. *link is */
/* cleared when obj first becomes inaccessible. This */
Expand Down Expand Up @@ -812,7 +813,7 @@ GC_API GC_warn_proc GC_set_warn_proc(GC_warn_proc p);
GC_API GC_word GC_set_free_space_divisor(GC_word value);
/* Set free_space_divisor. See above for definition. */
/* Returns old value. */

/* The following is intended to be used by a higher level */
/* (e.g. Java-like) finalization facility. It is expected */
/* that finalization code will arrange for hidden pointers to */
Expand Down Expand Up @@ -1005,7 +1006,7 @@ void * GC_malloc_many(size_t lb);
first call a user-supplied routine with filename of the library and
the address and length of the memory region. This routine should
return nonzero if that region should be scanned. */
GC_API void
GC_API void
GC_register_has_static_roots_callback
(int (*callback)(const char *, void *, size_t));

Expand Down
6 changes: 1 addition & 5 deletions sdk/io/File.ooc
Expand Up @@ -325,11 +325,7 @@ File: abstract class {
:return: the current working directory
*/
getCwd: static func -> String {
ret := String new(File MAX_PATH_LENGTH + 1)
if(!_getcwd(ret, File MAX_PATH_LENGTH)) {
Exception new("Failed to get current directory!") throw()
}
return ret
ooc_get_cwd()
}

}
11 changes: 10 additions & 1 deletion sdk/io/native/FileUnix.ooc
@@ -1,4 +1,4 @@
import ../File, os/Time, structs/ArrayList
import ../File, structs/ArrayList

include dirent

Expand Down Expand Up @@ -38,6 +38,15 @@ version(unix || apple) {

_getcwd: extern (getcwd) func(buf: Char*, size: SizeT) -> Char*

ooc_get_cwd: unmangled func -> String {
ret := String new(File MAX_PATH_LENGTH + 1)
if(!_getcwd(ret, File MAX_PATH_LENGTH)) {
Exception new("Failed to get current directory!") throw()
}
return ret
}

TimeT: cover from time_t
ModeT: cover from mode_t

FileStat: cover from struct stat {
Expand Down
9 changes: 9 additions & 0 deletions sdk/io/native/FileWin32.ooc
Expand Up @@ -40,6 +40,7 @@ version(windows) {
FindClose: extern func (Handle)
GetFileAttributes: extern func (Char*) -> Long
CreateDirectory:extern func (Char*, Pointer) -> Bool
GetCurrentDirectory: extern func (Long, Pointer) -> Int

/*
* remove implementation
Expand All @@ -48,6 +49,14 @@ version(windows) {
printf("Win32: should remove file %s\n", path)
}

ooc_get_cwd: unmangled func -> String {
ret := String new(File MAX_PATH_LENGTH + 1)
if(!GetCurrentDirectory(File MAX_PATH_LENGTH, ret)) {
Exception new("Failed to get current directory!") throw()
}
return ret
}

/*
* Win32 implementation of File
*/
Expand Down
81 changes: 61 additions & 20 deletions sdk/lang/Exception.ooc
@@ -1,37 +1,78 @@
/**
* exceptions
* Base class for all exceptions that can be thrown
*
* @author Amos Wenger (nddrylliog)
*/
Exception: class {

/** Class which threw the exception. May be null */
origin: Class
msg : String

init: func ~originMsg (=origin, =msg) {}
init: func ~noOrigin (=msg) {}
/** Message associated with this exception. Printed when the exception is thrown. */
message : String

crash: func {
fflush(stdout)
x := 0
x = 1 / x
"%d" format( x) println()
}

getMessage: func -> String {
//max := const 1024
max : const SizeT = 1024
buffer := String new (max)
if(origin) snprintf(buffer, max, "[%s in %s]: %s\n", this as Object class name, origin name, msg)
else snprintf(buffer, max, "[%s]: %s\n", this as Object class name, msg)
return buffer
/**
* Create an exception
*
* @param origin The class throwing this exception
* @param message A short text explaning why the exception was thrown
*/
init: func (=origin, =message) {}

/**
* Create an exception
*
* @param message A short text explaning why the exception was thrown
*/
init: func ~noOrigin (=message) {}


/**
* @return the exception's message, nicely formatted
*/
format: func -> String {
if(origin)
"[%s in %s]: %s" format(class name, origin name, message)
else
"[%s]: %s" format(class name, message)
}

/**
* Print this exception, with its origin, if specified, and its message
*/
print: func {
fprintf(stderr, "%s", getMessage())
fprintf(stderr, "%s", format())
}

throw: func {
/**
* Throw this exception
*/
throw: inline final func {
print()
crash()
abort()
}

}

/* ------ C interfacing ------ */

include stdlib

/** stdlib.h -
*
* The abort() first unblocks the SIGABRT signal, and then raises that
* signal for the calling process. This results in the abnormal
* termination of the process unless the SIGABRT signal is caught
* and the signal handler does not return (see longjmp(3)).
*
* If the abort() function causes process termination, all open streams
* are closed and flushed.
*
* If the SIGABRT signal is ignored, or caught by a handler that returns,
* the abort() function will still terminate the process. It does this
* by restoring the default disposition for SIGABRT and then raising
* the signal for a second time.
*/
abort: extern func

7 changes: 6 additions & 1 deletion sdk/lang/Memory.ooc
@@ -1,4 +1,7 @@
include memory

// as goofy as it sounds, memory-related routines are actually in string.h
// yay C. (Also, Google Native Client doesn't have memory.h)
include string

version(!gc) {
// GC_MALLOC zeroes the memory, so in the non-gc version, we prefer to use calloc
Expand All @@ -12,6 +15,7 @@ version(!gc) {
gc_malloc_atomic: extern(malloc) func (size: SizeT) -> Pointer
gc_realloc: extern(realloc) func (ptr: Pointer, size: SizeT) -> Pointer
gc_calloc: extern(calloc) func (nmemb: SizeT, size: SizeT) -> Pointer
gc_free: extern(free) func (ptr: Pointer)
}

version(gc) {
Expand All @@ -23,6 +27,7 @@ version(gc) {
gc_calloc: func (nmemb: SizeT, size: SizeT) -> Pointer {
gc_malloc(nmemb * size)
}
gc_free: extern(GC_FREE) func (ptr: Pointer)
}

// memory management
Expand Down
14 changes: 10 additions & 4 deletions sdk/lang/Numbers.ooc
@@ -1,4 +1,4 @@
include stdlib, stdint, stdbool, float, ctype, sys/types
include stdlib, stdint, stddef, float, ctype, sys/types

LLong: cover from signed long long {

Expand Down Expand Up @@ -26,6 +26,11 @@ LLong: cover from signed long long {
}
}

times: func ~withIndex (fn: Func(This)) {
for (i in 0..this) {
fn(i)
}
}
}

Long: cover from signed long extends LLong
Expand All @@ -46,9 +51,9 @@ UInt: cover from unsigned int extends ULLong
UShort: cover from unsigned short extends ULLong

//INT_MIN, INT_MAX : extern const static Int
//UINT_MAX : extern const static UInt
//UINT_MAX : extern const static UInt
//LONG_MIN, LONG_MAX : extern const static Long
//ULONG_MAX : extern const static ULong
//ULONG_MAX : extern const static ULong
//LLONG_MIN, LLONG_MAX : extern const static LLong
//ULLONG_MAX : extern const static ULLong

Expand All @@ -71,6 +76,7 @@ UInt64: cover from uint64_t extends ULLong
Octet: cover from uint8_t
SizeT: cover from size_t extends ULLong
SSizeT: cover from ssize_t extends LLong
PtrDiff: cover from ptrdiff_t extends SizeT

/**
* real types
Expand Down Expand Up @@ -116,4 +122,4 @@ Range: cover {
acc
}

}
}
7 changes: 6 additions & 1 deletion sdk/lang/types.ooc
@@ -1,4 +1,9 @@
include stddef, stdlib, stdio, ctype, stdbool, ./Array
include stddef, stdlib, stdio, ctype, ./Array

version(!_MSC_VER) {
// MSVC doesn't support C99, so no stdbool for it
include stdbool
}

/**
* objects
Expand Down

0 comments on commit 4ffe224

Please sign in to comment.