Skip to content
Browse files

Added more stdlib functions

  • Loading branch information...
1 parent 484e1b0 commit 1da57323ca7016238e9678f385d8d12fec82576b @anibali committed
Showing with 60 additions and 6 deletions.
  1. +50 −6 lib/libjit/libc.rb
  2. +10 −0 lib/libjit/type.rb
View
56 lib/libjit/libc.rb
@@ -23,14 +23,14 @@ class LibC
[:fopen, [:stringz, :stringz], :pointer],
[:freopen, [:stringz, :stringz, :pointer], :pointer],
[:setbuf, [:pointer, :stringz], :void],
- #[:setvbuf, [:pointer, :stringz, :int32, :size_t], :void],
+ [:setvbuf, [:pointer, :stringz, :int32, :size_t], :void],
# Formatted input/output functions
[:fprintf, [:pointer, :stringz, :varargs], :int32],
[:fscanf, [:pointer, :stringz, :varargs], :int32],
[:printf, [:stringz, :varargs], :int32],
[:scanf, [:stringz, :varargs], :int32],
- #[:snprintf, [:stringz, :size_t, :stringz, :varargs], :int32],
+ [:snprintf, [:stringz, :size_t, :stringz, :varargs], :int32],
[:sprintf, [:stringz, :stringz, :varargs], :int32],
[:sscanf, [:stringz, :stringz, :varargs], :int32],
#vprintf
@@ -53,8 +53,8 @@ class LibC
[:ungetc, [:int32, :pointer], :int32],
# Direct input/output functions
- #[:fread, [:pointer, :size_t, :size_t, :pointer], :size_t],
- #[:fwrite, [:pointer, :size_t, :size_t, :pointer], :size_t],
+ [:fread, [:pointer, :size_t, :size_t, :pointer], :size_t],
+ [:fwrite, [:pointer, :size_t, :size_t, :pointer], :size_t],
# File positioning functions
[:fgetpos, [:pointer, :pointer], :int32],
@@ -73,16 +73,60 @@ class LibC
# stdlib #
##########
+ # Numeric conversion functions
+ [:atof, [:stringz], :float64],
+ [:atoi, [:stringz], :int32],
+ [:atol, [:stringz], :intn],
+ [:atoll, [:stringz], :int64],
+ [:strtod, [:stringz, [:pointer, :stringz]], :float64],
+ [:strtof, [:stringz, [:pointer, :stringz]], :float32],
+ #[:strtold, [:stringz, [:pointer, :stringz]], :floatn],
+ [:strtol, [:stringz, [:pointer, :stringz]], :intn],
+ [:strtoll, [:stringz, [:pointer, :stringz]], :int64],
+ [:strtoul, [:stringz, [:pointer, :stringz]], :uintn],
+ [:strtoull, [:stringz, [:pointer, :stringz]], :uint64],
+
+ # Pseudo-random sequence generation functions
[:rand, [], :int32],
[:srand, [:uint32], :void],
- [:malloc, [:uint32], :pointer],
- [:realloc, [:pointer, :uintn], :pointer],
+
+ # Memory management functions
+ [:calloc, [:size_t, :size_t], :pointer],
[:free, [:pointer], :void],
+ [:malloc, [:size_t], :pointer],
+ [:realloc, [:pointer, :size_t], :pointer],
+
+ # Communication with the environment
+ [:abort, [], :void],
+ #[:atexit, [:pointer], :int32],
+ [:exit, [:int32], :void],
+ [:_Exit, [:int32], :void],
+ [:getenv, [:stringz], :stringz],
+ [:system, [:stringz], :int32],
+
+ # Searching and sorting utilities
+ [:bsearch, [:pointer, :pointer, :size_t, :size_t, :pointer], :pointer],
+ [:qsort, [:pointer, :size_t, :size_t, :pointer], :void],
+
+ # Integer arithmetic functions
[:abs, [:int32], :int32],
+ [:labs, [:intn], :intn],
+ [:llabs, [:int64], :int64],
+ #div, ldiv, lldiv
+
+ # Multibyte/wide character conversion functions
+ [:mblen, [:stringz, :size_t], :int32],
+ #mbtowc
+ #wctomb
+
+ # Multibyte/wide string conversion functions
+ #mbstowcs
+ #wcstombs
########
# time #
########
+
[:time, [:pointer], :int64],
].each do |name, param_types, return_type|
View
10 lib/libjit/type.rb
@@ -25,8 +25,18 @@ class Type
# @see StructType#initialize
# @see SignatureType#initialize
def self.create *args
+ args = args[0] if args.one? and args[0].is_a? Array
+
return args.first if args.first.is_a? Type
+ # TODO: typdef elsewhere?
+ args = case args
+ when [:size_t]
+ [:intn]
+ else
+ args
+ end
+
case args.first.to_sym
when :stringz
StringzType.new(*args[1..-1])

0 comments on commit 1da5732

Please sign in to comment.
Something went wrong with that request. Please try again.