Permalink
Browse files

Merge pull request #86 from hoelzro/master

Expose errno and POSIX errno values to NQP
  • Loading branch information...
2 parents 5400ed8 + 8e1e040 commit 737636f670ec6f567781e402118cfe2a37ef05dd @masak masak committed Mar 20, 2013
Showing with 94 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +1 −0 src/HLL/Compiler.pm
  3. +1 −0 src/QAST/Operations.nqp
  4. +15 −0 src/ops/nqp.ops
  5. +26 −0 t/nqp/67-errno.t
  6. +7 −1 tools/build/Makefile.in
  7. +43 −0 tools/build/generate-constants.pl
View
@@ -39,3 +39,4 @@ config.status
config.default
3rdparty/dyncall/ConfigVars
3rdparty/dyncall/*/*.a
+/nqp_const.pir
View
@@ -105,6 +105,7 @@ class HLL::Backend::Parrot {
~ ".include 'stat.pasm'\n"
~ ".include 'datatypes.pasm'\n"
~ ".include 'libpaths.pasm'\n"
+ ~ ".include 'nqp_const.pir'\n"
}
method pir($source, *%adverbs) {
View
@@ -1750,6 +1750,7 @@ QAST::Operations.add_core_pirop_mapping('tonum_I', 'nqp_bigint_to_num', 'NP', :i
QAST::Operations.add_core_pirop_mapping('buildnativecall', 'nqp_native_call_build', 'vPsssPP');
QAST::Operations.add_core_pirop_mapping('nativecall', 'nqp_native_call', 'PPPP');
QAST::Operations.add_core_pirop_mapping('nativecallrefresh', 'nqp_native_call_wb', 'vP');
+QAST::Operations.add_core_pirop_mapping('x_posixerrno', 'nqp_posixerrno', 'I');
# boolean opcodes
QAST::Operations.add_core_pirop_mapping('not_i', 'not', 'Ii', :inlinable(1));
View
@@ -1,5 +1,7 @@
BEGIN_OPS_PREAMBLE
+#include <errno.h>
+
/* Parroty includes. */
#include "parrot/parrot.h"
#include "parrot/extend.h"
@@ -2906,6 +2908,19 @@ inline op nqp_fresh_stub(out PMC, invar PMC) :base_core {
/*
+=item nqp_posixerrno
+
+Returns the value of errno.
+
+=cut
+
+*/
+inline op nqp_posixerrno(out INT) :base_core {
+ $1 = errno;
+}
+
+/*
+
=item captureposprimspec
Takes a CallContext in $2 and an index in $3, and returns the primitive
View
@@ -0,0 +1,26 @@
+plan(3);
+
+sub mkdir($filename) {
+ pir::new__PS('OS').mkdir($filename, 0o777);
+ return True;
+ CATCH {
+ return False;
+ }
+}
+
+sub rmdir($filename) {
+ pir::new__PS('OS').rmdir($filename);
+ return True;
+ CATCH {
+ return False;
+ }
+}
+
+my $test-dir := 'errno-test-dir';
+
+rmdir($test-dir);
+ok(mkdir($test-dir) eq True, 'mkdir should succeed');
+ok(mkdir($test-dir) eq False, 'mkdir of an existing directory should fail');
+ok(nqp::x_posixerrno() == pir::const::POSIX_EEXIST, 'errno should be equal to EEXIST');
+
+rmdir($test-dir);
View
@@ -493,6 +493,8 @@ DYNCALL_BIN = 3rdparty/dyncall/dyncall/libdyncall_s$(A) \
DYNCALL_OPS = nqp_dyncall_ops
DYNCALL_OPS_SOURCE = nqp_dyncall.ops
+NQP_CONST_PIR = nqp_const.pir
+
CLEANUPS = \
*.manifest \
*.pdb \
@@ -534,6 +536,7 @@ CLEANUPS = \
3rdparty/libtommath/*$(O) \
3rdparty/sha1/*$(O) \
$(DYNEXT_DIR)/*$(LOAD_EXT) \
+ $(NQP_CONST_PIR) \
all: $(NQP_EXE) $(P5QREGEX_PBC)
@@ -577,7 +580,7 @@ $(STAGE0_PBCS): $(DYNEXT_TARGET) $(STAGE0_SOURCES)
$(STAGE1): $(STAGE1_PBCS)
-$(STAGE1)/$(NQP_MO_PBC): $(STAGE0_PBCS) $(NQP_MO_SOURCES)
+$(STAGE1)/$(NQP_MO_PBC): $(NQP_CONST_PIR) $(STAGE0_PBCS) $(NQP_MO_SOURCES)
$(MKPATH) $(STAGE1)/gen
$(PERL) tools/build/gen-cat.pl $(NQP_MO_SOURCES) > $(STAGE1)/$(NQP_MO_COMBINED)
$(PARROT) --library=$(STAGE0) $(STAGE0)/$(NQP_PBC) \
@@ -1063,6 +1066,9 @@ $(OPS_DIR)/$(DYNCALL_OPS)$(LOAD_EXT): $(OPS_DIR)/$(DYNCALL_OPS_SOURCE) $(DYNCALL
cd src/6model/reprs && $(CC) -c @cc_o_out@CStr$(O) -I../../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) CStr.c
cd $(OPS_DIR) && $(LD) @ld_out@$(DYNCALL_OPS)$(LOAD_EXT) $(DYNCALL_OPS)$(O) ../6model/reprs/NativeCall$(O) ../6model/reprs/CStruct$(O) ../6model/reprs/CPointer$(O) ../6model/reprs/CArray$(O) ../6model/reprs/CStr$(O) ../../3rdparty/dyncall/dyncall/libdyncall_s$(A) ../../3rdparty/dyncall/dyncallback/libdyncallback_s$(A) ../../3rdparty/dyncall/dynload/libdynload_s$(A) $(LINKARGS)
+$(NQP_CONST_PIR):
+ perl tools/build/generate-constants.pl > $@
+
bootstrap-files: $(STAGE2_PBCS) src/stage2/$(CORE_SETTING_NQP)
$(PERL) tools/build/gen-bootstrap.pl src/stage2/$(NQP_MO_PIR) >src/stage0/NQPMO-s0.pir
$(PERL) tools/build/gen-bootstrap.pl src/stage2/gen/module_loader.pir >src/stage0/ModuleLoader-s0.pir
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use POSIX;
+
+print <<"END_HEADER";
+# DO NOT EDIT THIS FILE.
+#
+# This file is generated automatically from
+# $0
+#
+# Any changes made here will be lost.
+#
+END_HEADER
+
+my @errno_values;
+
+my $max_errno_name_len = 0;
+foreach my $name (sort grep { /^E[A-Z]+$/ } keys %POSIX::) {
+ my $code = POSIX->can($name);
+
+ next unless $code;
+
+ my $value = eval { $code->() };
+
+ next unless defined $value;
+
+ push @errno_values, [ $name, $value ];
+
+ if(length($name) > $max_errno_name_len) {
+ $max_errno_name_len = length($name);
+ }
+}
+
+my $format = ".macro_const POSIX_%-${max_errno_name_len}s %d\n";
+
+foreach my $pair (@errno_values) {
+ my ( $name, $value ) = @$pair;
+
+ printf $format, $name, $value;
+}

0 comments on commit 737636f

Please sign in to comment.