-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
326 additions
and
2,185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
|
||
version 10.4.1 | ||
|
||
Continue to implement C-FFI on JIT. | ||
|
||
version 10.4.0 | ||
|
||
Continue to implement C-FFI on JIT. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
class CLangVariable | ||
{ | ||
var name:String; | ||
var type:String; | ||
|
||
def initialize(name:String, type:String) { | ||
self.name = name.clone(); | ||
self.type = type.clone(); | ||
} | ||
|
||
def clone():CLangVariable { | ||
result := CLangVariable(self.name, self.type); | ||
|
||
return result; | ||
} | ||
def compare(right:CLangVariable): int { | ||
return self.name.compare(right.name); | ||
} | ||
def equals(right:CLangVariable): bool { | ||
return self.name.equals(right.name) && self.type.equals(right.type); | ||
} | ||
} | ||
|
||
class CLangFunc { | ||
var type:String; | ||
var name:String; | ||
var params:SortableList<CLangVariable>; | ||
|
||
def initialize(type:String, name:String, params:SortableList<CLangVariable>) | ||
{ | ||
self.type = type.clone(); | ||
self.name = name.clone(); | ||
self.params = params.clone(); | ||
} | ||
|
||
def clone():CLangFunc { | ||
result := CLangFunc(self.type, self.name, self.params); | ||
|
||
return result; | ||
} | ||
def compare(right:CLangFunc): int { | ||
return self.name.compare(right.name); | ||
} | ||
def equals(right:CLangFunc): bool { | ||
return self.name.equals(right.name) && self.type.equals(right.type) && self.params.equals(right.params); | ||
} | ||
} | ||
|
||
class CLang | ||
{ | ||
var p:Buffer; | ||
var source:Buffer; | ||
|
||
var funcs:SortableList<CLangFunc>; | ||
|
||
def initialize(source:Buffer) { | ||
self.p = source; | ||
self.source = source; | ||
|
||
self.funcs = SortableList<CLangFunc>(); | ||
} | ||
|
||
def skipLFAndSpaces() { | ||
while(p->byte == ' ' || p->byte == '\t' || p->byte == '\n') | ||
{ | ||
p++; | ||
} | ||
} | ||
|
||
def getWord():String { | ||
buf := ""; | ||
while(p->byte != '\0') { | ||
if(isalnum(p->byte.to_char) || p->byte == '_') | ||
{ | ||
buf.append(p->byte.to_char); | ||
p++; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
skipLFAndSpaces(); | ||
|
||
return buf; | ||
|
||
} | ||
def parseParams():SortableList<CLangVariable> { | ||
result := SortableList<CLangVariable>(); | ||
|
||
while(p->byte != '\0') { | ||
type := getWord(); | ||
name := getWord(); | ||
|
||
variable := CLangVariable(name, type); | ||
|
||
result.push(variable); | ||
|
||
if(p->byte == ',') { | ||
p++; | ||
skipLFAndSpaces(); | ||
} | ||
elif(p->byte == ')') { | ||
p++; | ||
skipLFAndSpaces(); | ||
break; | ||
} | ||
else { | ||
throw Exception("Require , or )"); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
def parseHeader() { | ||
skipLFAndSpaces(); | ||
|
||
while(p->byte != '\0') { | ||
buf := getWord(); | ||
|
||
if(buf.equals("struct")) { | ||
} | ||
elif(buf.equals("typedef")) { | ||
} | ||
elif(buf.equals("extern")) { | ||
buf2 := getWord(); | ||
buf3 := getWord(); | ||
|
||
if(p->byte == '(') { | ||
p++; | ||
skipLFAndSpaces(); | ||
|
||
type := buf2; | ||
name := buf3; | ||
|
||
params := parseParams(); | ||
|
||
if(p->byte == ';') { | ||
p++; | ||
skipLFAndSpaces(); | ||
} | ||
|
||
fun := CLangFunc(type, name, params); | ||
funcs.push(fun); | ||
} | ||
} | ||
### Function ### | ||
else { | ||
buf2 := getWord(); | ||
|
||
if(p->byte == '(') { | ||
p++; | ||
skipLFAndSpaces(); | ||
|
||
type := buf; | ||
name := buf2; | ||
|
||
params := parseParams(); | ||
|
||
if(p->byte == ';') { | ||
p++; | ||
skipLFAndSpaces(); | ||
} | ||
fun := CLangFunc(type, name, params); | ||
|
||
funcs.push(fun); | ||
} | ||
} | ||
} | ||
} | ||
def include(fname:String): static CLang { | ||
source := fname.toPath().read(); | ||
source.append('\0'); | ||
|
||
result := CLang(source); | ||
result.parseHeader(); | ||
return result; | ||
} | ||
|
||
def pasteHeader():String { | ||
result := ""; | ||
for(it in funcs) { | ||
params := ""; | ||
i := 0; | ||
for(it2 in it.params) { | ||
params.append("\{it2.type} \{it2.name}"); | ||
|
||
if(i != it.params.length()-1) { | ||
params.append(", "); | ||
} | ||
|
||
i++; | ||
} | ||
result.append("def \{it.name}(\{params}):\{it.type};\n"); | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ NODEJS=@NODEJS@ | |
########################################################## | ||
# main | ||
########################################################## | ||
all: cclover2 clover2 tyclover2 $(INTERPRETER) SortableArray.oclcl String.ojsclcl libclover2.so.1.0.0 jit-compile | ||
all: cclover2 clover2 tyclover2 $(INTERPRETER) SortableArray.oclcl String.ojsclcl CLang.oclcl libclover2.so.1.0.0 jit-compile | ||
# if which ctags > /dev/null; then if test $(OS) = DARWIN; then ctags src/*.c > /dev/null 2>&1; else ctags -R; fi; fi | ||
|
||
cclover2: config.h src/compiler.o $(COMMON_OBJS) $(COMPILER_OBJS) $(OBJS) $(JIT_OBJS) $(JIT_RUNTIME_OBJS) | ||
|
@@ -110,6 +110,9 @@ String.ojsclcl: JS.jsclcl | |
PWD=`pwd`; ./cclover2 -core Float64Array.ojsclcl | ||
PWD=`pwd`; ./cclover2 -core DataView.ojsclcl | ||
|
||
CLang.oclcl: CLang.clcl | ||
PWD=`pwd`; ./cclover2 CLang.clcl | ||
|
||
libclover2.so.1.0.0: $(COMMON_OBJ) $(COMPILER_OBJS) $(OBJS) $(JIT_RUNTIME_OBJS) $(JIT_SCRIPT_RUNTIME_OBJS) $(JIT_MAIN_OBJ) | ||
$(CC) -shared -o libclover2.so.1.0.0 $(JIT_SCRIPT_RUNTIME_OBJS) $(CFLAGS) $(LIBS) | ||
ln -s -f libclover2.so.1.0.0 libclover2.so.1 | ||
|
@@ -123,7 +126,7 @@ $(OBJ): src/*.h Makefile configure | |
######################################################### | ||
# JIT compile | ||
######################################################### | ||
jit-compile: Clover.so PcreOVec.so System.so Global.so Buffer.so Exception.so Byte.so UByte.so Short.so UShort.so Integer.so UInteger.so Long.so ULong.so Float.so Double.so Pointer.so Char.so Bool.so Array.so EqualableArray.so SortableArray.so HashItem.so Hash.so ListItem.so List.so EqualableList.so SortableList.so Tuple1.so Tuple2.so Tuple3.so Tuple4.so Tuple5.so Tuple6.so Tuple7.so Tuple8.so Tuple9.so Tuple10.so Path.so Directory.so termios.so Job.so Command.so String.so File.so Class.so Field.so Method.so MethodParam.so Mutex.so Null.so Range.so Thread.so fd_set.so getopt_long_option.so timespec.so timeval.so tm.so hostent.so in_addr.so pthread_cond_t.so pthread_mutex_t.so servent.so sockaddr_in.so sockaddr_un.so stat.so | ||
jit-compile: Clover.so PcreOVec.so System.so Global.so Buffer.so Exception.so Byte.so UByte.so Short.so UShort.so Integer.so UInteger.so Long.so ULong.so Float.so Double.so Pointer.so Char.so Bool.so Array.so EqualableArray.so SortableArray.so HashItem.so Hash.so ListItem.so List.so EqualableList.so SortableList.so Tuple1.so Tuple2.so Tuple3.so Tuple4.so Tuple5.so Tuple6.so Tuple7.so Tuple8.so Tuple9.so Tuple10.so Path.so Directory.so termios.so Job.so Command.so String.so File.so Class.so Field.so Method.so MethodParam.so Mutex.so Null.so Range.so Thread.so fd_set.so getopt_long_option.so timespec.so timeval.so tm.so hostent.so in_addr.so pthread_cond_t.so pthread_mutex_t.so servent.so sockaddr_in.so sockaddr_un.so stat.so CLang.so CLangVariable.so CLangFunc.so | ||
|
||
Clover.so: Clover.oclcl | ||
if test $(JIT) = 1; then ./bclover2 -core Clover; fi | ||
|
@@ -329,6 +332,16 @@ timeval.so: timeval.oclcl | |
Null.so: Null.oclcl | ||
if test $(JIT) = 1; then ./bclover2 -core Null; fi | ||
|
||
CLang.so: CLang.oclcl | ||
if test $(JIT) = 1; then ./bclover2 -core CLang; fi | ||
|
||
CLangVariable.so: CLangVariable.oclcl | ||
if test $(JIT) = 1; then ./bclover2 -core CLangVariable; fi | ||
|
||
CLangFunc.so: CLangFunc.oclcl | ||
if test $(JIT) = 1; then ./bclover2 -core CLangFunc; fi | ||
|
||
|
||
######################################################### | ||
# install | ||
######################################################### | ||
|
@@ -557,6 +570,15 @@ install: | |
if test -e C.oclcl; then $(INSTALL) -m 644 ./C.oclcl $(DESTDIR)/share/clover2; fi | ||
if test -e [email protected]; then $(INSTALL) -m 644 ./[email protected] $(DESTDIR)/share/clover2; fi | ||
|
||
if test -e CLangVariable.oclcl; then $(INSTALL) -m 644 ./CLangVariable.oclcl $(DESTDIR)/share/clover2; fi | ||
if test -e CLangVariable.so; then $(INSTALL) -m 755 ./CLangVariable.so.1.0.0 $(DESTDIR)/share/clover2; cp -a ./CLangVariable.so $(DESTDIR)/share/clover2; fi | ||
|
||
if test -e CLangFunc.oclcl; then $(INSTALL) -m 644 ./CLangFunc.oclcl $(DESTDIR)/share/clover2; fi | ||
if test -e CLangFunc.so; then $(INSTALL) -m 755 ./CLangFunc.so.1.0.0 $(DESTDIR)/share/clover2; cp -a ./CLangFunc.so $(DESTDIR)/share/clover2; fi | ||
|
||
if test -e CLang.oclcl; then $(INSTALL) -m 644 ./CLang.oclcl $(DESTDIR)/share/clover2; fi | ||
if test -e CLang.so; then $(INSTALL) -m 755 ./CLang.so.1.0.0 $(DESTDIR)/share/clover2; cp -a ./CLang.so $(DESTDIR)/share/clover2; fi | ||
|
||
$(INSTALL) -m 644 ./Object.oclcl $(DESTDIR)/share/clover2 | ||
$(INSTALL) -m 644 ./IEqualable.oclcl $(DESTDIR)/share/clover2 | ||
$(INSTALL) -m 644 ./IHashKey.oclcl $(DESTDIR)/share/clover2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# clover2 computer language | ||
|
||
version 10.4.0 | ||
version 10.4.1 | ||
|
||
サポートしている機能 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,2 @@ | ||
|
||
initscr(); | ||
def_prog_mode(); | ||
start_color(); | ||
init_pair(1, COLOR_BLUE, COLOR_BLACK); | ||
clear(); | ||
attron(COLOR_PAIR(1)); | ||
addstr("ABC"); | ||
addstr("あいう"); | ||
attroff(COLOR_PAIR(1)); | ||
refresh(); | ||
getch(); | ||
|
||
clear(); | ||
box(stdscr, '|', '-'); | ||
refresh(); | ||
|
||
getch(); | ||
|
||
clear(); | ||
border('|', '|', '+', '+', '|', '|', '+', '+'); | ||
refresh(); | ||
|
||
getch(); | ||
|
||
beep(); | ||
|
||
getch(); | ||
|
||
endwin(); | ||
header := CLang.include("code/CStruct.h") | ||
header.pasteHeader().println(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
class ClassB { | ||
params:List<Integer>; | ||
|
||
def initialize() { | ||
params = list { 1, 2, 3 }; | ||
} | ||
} | ||
|
||
|
||
class ClassA | ||
{ | ||
def method():static { | ||
a:long = 0x02; | ||
def main():static { | ||
b := ClassB(); | ||
|
||
if((a & 0x02).to_bool) { | ||
println("TRUE"); | ||
} | ||
else { | ||
println("FALSE"); | ||
for(it in b.params) { | ||
it.toString().println(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extern void fun3(int a, int b); |
Oops, something went wrong.